@nurix/etna 0.19.66 → 0.19.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/etna.js +10 -1
- package/data/harness-index.json +1 -5
- package/data/harnesses/code/CLAUDE.md +2 -0
- package/data/harnesses/code/agents/maintenance.md +3 -1
- package/data/harnesses/code/harness.json +7 -2
- package/data/harnesses/code/hooks/compliance.mjs +1 -0
- package/data/harnesses/code/hooks/lib/frozen.mjs +3 -0
- package/data/harnesses/code/hooks/lib/ownership.mjs +3 -1
- package/data/harnesses/code/skills/documentation/scripts/doc-lint.mjs +1 -1
- package/data/harnesses/delivery/agents/maintenance.md +3 -1
- package/data/harnesses/delivery/harness.json +2 -2
- package/data/harnesses/delivery/skills/documentation/scripts/doc-lint.mjs +1 -1
- package/data/harnesses/etna/agents/maintenance.md +3 -1
- package/data/harnesses/etna/harness.json +2 -2
- package/data/harnesses/etna/skills/documentation/scripts/doc-lint.mjs +1 -1
- package/lib/install/materialize.mjs +51 -57
- package/package.json +2 -2
- package/data/harnesses/apollo/.mcp.json +0 -8
- package/data/harnesses/apollo/.prettierignore +0 -29
- package/data/harnesses/apollo/.prettierrc.json +0 -3
- package/data/harnesses/apollo/.vscode/settings.json +0 -19
- package/data/harnesses/apollo/CLAUDE.md +0 -162
- package/data/harnesses/apollo/agents/bookkeeper.md +0 -28
- package/data/harnesses/apollo/agents/brainstorm.md +0 -144
- package/data/harnesses/apollo/agents/change-review.md +0 -251
- package/data/harnesses/apollo/agents/lld-mode.md +0 -58
- package/data/harnesses/apollo/agents/maintenance.md +0 -234
- package/data/harnesses/apollo/agents/performance-review.md +0 -223
- package/data/harnesses/apollo/agents/retro.md +0 -46
- package/data/harnesses/apollo/codex/agents/bookkeeper.toml +0 -26
- package/data/harnesses/apollo/codex/agents/brainstorm.toml +0 -142
- package/data/harnesses/apollo/codex/agents/change-review.toml +0 -249
- package/data/harnesses/apollo/codex/agents/lld-mode.toml +0 -52
- package/data/harnesses/apollo/codex/agents/maintenance.toml +0 -228
- package/data/harnesses/apollo/codex/agents/performance-review.toml +0 -222
- package/data/harnesses/apollo/codex/agents/retro.toml +0 -45
- package/data/harnesses/apollo/harness.json +0 -19
- package/data/harnesses/apollo/hooks/approved-packages.md +0 -44
- package/data/harnesses/apollo/hooks/awareness.mjs +0 -405
- package/data/harnesses/apollo/hooks/check-bookkeeping-clean.mjs +0 -19
- package/data/harnesses/apollo/hooks/check-changelog-presence.mjs +0 -57
- package/data/harnesses/apollo/hooks/check-completion-integrity.mjs +0 -71
- package/data/harnesses/apollo/hooks/check-ownership.mjs +0 -22
- package/data/harnesses/apollo/hooks/compliance.mjs +0 -457
- package/data/harnesses/apollo/hooks/hooks.json +0 -23
- package/data/harnesses/apollo/hooks/lib/frozen.mjs +0 -58
- package/data/harnesses/apollo/hooks/lib/ownership.mjs +0 -242
- package/data/harnesses/apollo/hooks/lib/state.mjs +0 -170
- package/data/harnesses/apollo/rules/changelog.md +0 -27
- package/data/harnesses/apollo/rules/database.md +0 -34
- package/data/harnesses/apollo/rules/frontend.md +0 -30
- package/data/harnesses/apollo/rules/general.md +0 -40
- package/data/harnesses/apollo/rules/nomenclature.md +0 -30
- package/data/harnesses/apollo/rules/pnpm.md +0 -57
- package/data/harnesses/apollo/rules/testing.md +0 -64
- package/data/harnesses/apollo/skills/boundary/SKILL.md +0 -75
- package/data/harnesses/apollo/skills/boundary/references/index.md +0 -16
- package/data/harnesses/apollo/skills/boundary/references/mechanisms.md +0 -99
- package/data/harnesses/apollo/skills/boundary/references/packs/async-messaging.md +0 -81
- package/data/harnesses/apollo/skills/boundary/references/packs/auth.md +0 -93
- package/data/harnesses/apollo/skills/boundary/references/packs/build-config-runtime.md +0 -93
- package/data/harnesses/apollo/skills/boundary/references/packs/cloudflare.md +0 -93
- package/data/harnesses/apollo/skills/boundary/references/packs/frontend.md +0 -93
- package/data/harnesses/apollo/skills/boundary/references/packs/generic-tail.md +0 -55
- package/data/harnesses/apollo/skills/boundary/references/packs/persistence.md +0 -93
- package/data/harnesses/apollo/skills/boundary/references/packs/wire-api.md +0 -87
- package/data/harnesses/apollo/skills/brainstorm/README.md +0 -56
- package/data/harnesses/apollo/skills/brainstorm/SKILL.md +0 -173
- package/data/harnesses/apollo/skills/brainstorm/references/doctrine.md +0 -98
- package/data/harnesses/apollo/skills/brainstorm/references/harvest.md +0 -86
- package/data/harnesses/apollo/skills/brainstorm/references/session-schema.md +0 -186
- package/data/harnesses/apollo/skills/brainstorm/scripts/detector.mjs +0 -460
- package/data/harnesses/apollo/skills/design/SKILL.md +0 -121
- package/data/harnesses/apollo/skills/design/components/charts.md +0 -76
- package/data/harnesses/apollo/skills/design/components/collections.md +0 -132
- package/data/harnesses/apollo/skills/design/components/feedback.md +0 -47
- package/data/harnesses/apollo/skills/design/components/hooks.md +0 -35
- package/data/harnesses/apollo/skills/design/components/index.md +0 -143
- package/data/harnesses/apollo/skills/design/components/inputs.md +0 -327
- package/data/harnesses/apollo/skills/design/components/layout.md +0 -52
- package/data/harnesses/apollo/skills/design/components/media.md +0 -66
- package/data/harnesses/apollo/skills/design/components/motion.md +0 -82
- package/data/harnesses/apollo/skills/design/components/navigation.md +0 -29
- package/data/harnesses/apollo/skills/design/components/overlays.md +0 -72
- package/data/harnesses/apollo/skills/design/components/setup.md +0 -40
- package/data/harnesses/apollo/skills/design/components/typography.md +0 -46
- package/data/harnesses/apollo/skills/design/components/utils.md +0 -37
- package/data/harnesses/apollo/skills/design/data/blueprints/browse.md +0 -38
- package/data/harnesses/apollo/skills/design/data/blueprints/creation-flow.md +0 -38
- package/data/harnesses/apollo/skills/design/data/blueprints/dashboard.md +0 -38
- package/data/harnesses/apollo/skills/design/data/blueprints/grid.md +0 -38
- package/data/harnesses/apollo/skills/design/data/blueprints/queue.md +0 -38
- package/data/harnesses/apollo/skills/design/data/blueprints/record-detail.md +0 -38
- package/data/harnesses/apollo/skills/design/data/blueprints/settings.md +0 -38
- package/data/harnesses/apollo/skills/design/data/charts/census.csv +0 -58
- package/data/harnesses/apollo/skills/design/data/checklists/browse.md +0 -21
- package/data/harnesses/apollo/skills/design/data/checklists/creation-flow.md +0 -20
- package/data/harnesses/apollo/skills/design/data/checklists/dashboard.md +0 -21
- package/data/harnesses/apollo/skills/design/data/checklists/grid.md +0 -21
- package/data/harnesses/apollo/skills/design/data/checklists/queue.md +0 -21
- package/data/harnesses/apollo/skills/design/data/checklists/record-detail.md +0 -21
- package/data/harnesses/apollo/skills/design/data/checklists/settings.md +0 -21
- package/data/harnesses/apollo/skills/design/data/chrome/board-column.md +0 -68
- package/data/harnesses/apollo/skills/design/data/chrome/data-table.md +0 -63
- package/data/harnesses/apollo/skills/design/data/chrome/side-panel.md +0 -60
- package/data/harnesses/apollo/skills/design/data/chrome/sidebar.md +0 -78
- package/data/harnesses/apollo/skills/design/data/chrome/stat-cards.md +0 -62
- package/data/harnesses/apollo/skills/design/data/chrome/topbar.md +0 -65
- package/data/harnesses/apollo/skills/design/data/elevation/ant-design-directional-shadow.md +0 -19
- package/data/harnesses/apollo/skills/design/data/elevation/apple-liquid-glass-material.md +0 -18
- package/data/harnesses/apollo/skills/design/data/elevation/atlassian-surface-shadow-pairing.md +0 -20
- package/data/harnesses/apollo/skills/design/data/elevation/fluent-2-key-ambient-ramp.md +0 -20
- package/data/harnesses/apollo/skills/design/data/elevation/github-primer-sparing-shadow.md +0 -19
- package/data/harnesses/apollo/skills/design/data/elevation/ibm-carbon-layer-and-border.md +0 -19
- package/data/harnesses/apollo/skills/design/data/elevation/linear-dark-surface-ladder.md +0 -17
- package/data/harnesses/apollo/skills/design/data/elevation/material-2-key-ambient-dp-ramp.md +0 -19
- package/data/harnesses/apollo/skills/design/data/elevation/material-3-tonal-elevation.md +0 -21
- package/data/harnesses/apollo/skills/design/data/elevation/neobrutalist-hard-offset.md +0 -19
- package/data/harnesses/apollo/skills/design/data/elevation/neumorphic-soft-dual-shadow.md +0 -18
- package/data/harnesses/apollo/skills/design/data/elevation/notion-warm-minimal-hairline.md +0 -17
- package/data/harnesses/apollo/skills/design/data/elevation/polaris-elevation-inset-bevel.md +0 -21
- package/data/harnesses/apollo/skills/design/data/elevation/radix-themes-alpha-ring-scale.md +0 -19
- package/data/harnesses/apollo/skills/design/data/elevation/shadcn-neutral-derived-radius.md +0 -19
- package/data/harnesses/apollo/skills/design/data/elevation/stripe-brand-tinted-dual-shadow.md +0 -18
- package/data/harnesses/apollo/skills/design/data/elevation/tailwind-default-utility-scale.md +0 -19
- package/data/harnesses/apollo/skills/design/data/elevation/vercel-geist-shadow-as-border.md +0 -20
- package/data/harnesses/apollo/skills/design/data/iconography.md +0 -199
- package/data/harnesses/apollo/skills/design/data/motion/accordion-expand.md +0 -18
- package/data/harnesses/apollo/skills/design/data/motion/destructive-hold-confirm.md +0 -18
- package/data/harnesses/apollo/skills/design/data/motion/drag-dismiss-momentum.md +0 -18
- package/data/harnesses/apollo/skills/design/data/motion/empty-state-arrive.md +0 -18
- package/data/harnesses/apollo/skills/design/data/motion/hover-lift.md +0 -18
- package/data/harnesses/apollo/skills/design/data/motion/modal-center-arrive.md +0 -18
- package/data/harnesses/apollo/skills/design/data/motion/number-ticker-roll.md +0 -18
- package/data/harnesses/apollo/skills/design/data/motion/onboarding-bounce.md +0 -18
- package/data/harnesses/apollo/skills/design/data/motion/panel-slide.md +0 -18
- package/data/harnesses/apollo/skills/design/data/motion/press-feedback.md +0 -18
- package/data/harnesses/apollo/skills/design/data/motion/progress-linear-loop.md +0 -18
- package/data/harnesses/apollo/skills/design/data/motion/route-crossfade.md +0 -18
- package/data/harnesses/apollo/skills/design/data/motion/rubber-band-overscroll.md +0 -18
- package/data/harnesses/apollo/skills/design/data/motion/skeleton-shimmer.md +0 -18
- package/data/harnesses/apollo/skills/design/data/motion/stagger-arrive.md +0 -18
- package/data/harnesses/apollo/skills/design/data/motion/toast-enter-stack.md +0 -18
- package/data/harnesses/apollo/skills/design/data/motion/tooltip-chain-instant.md +0 -18
- package/data/harnesses/apollo/skills/design/data/motion/trigger-anchored-reveal.md +0 -18
- package/data/harnesses/apollo/skills/design/data/tells.csv +0 -34
- package/data/harnesses/apollo/skills/design/data/voices/bright-collaborator.md +0 -29
- package/data/harnesses/apollo/skills/design/data/voices/direct-operator.md +0 -29
- package/data/harnesses/apollo/skills/design/data/voices/earnest-helper.md +0 -29
- package/data/harnesses/apollo/skills/design/data/voices/editorial-composed.md +0 -29
- package/data/harnesses/apollo/skills/design/data/voices/quiet-concierge.md +0 -29
- package/data/harnesses/apollo/skills/design/data/voices/warm-guide.md +0 -29
- package/data/harnesses/apollo/skills/design/references/compose.md +0 -23
- package/data/harnesses/apollo/skills/design/references/content.md +0 -28
- package/data/harnesses/apollo/skills/design/references/emission.md +0 -21
- package/data/harnesses/apollo/skills/design/references/existing-apps.md +0 -27
- package/data/harnesses/apollo/skills/design/references/foundations.md +0 -57
- package/data/harnesses/apollo/skills/design/references/intake.md +0 -40
- package/data/harnesses/apollo/skills/design/references/object-pass.md +0 -24
- package/data/harnesses/apollo/skills/design/references/ship-gate.md +0 -29
- package/data/harnesses/apollo/skills/design/references/ux-patterns/Readme.md +0 -195
- package/data/harnesses/apollo/skills/design/references/ux-patterns/ai-layer.md +0 -49
- package/data/harnesses/apollo/skills/design/references/ux-patterns/attributes-lifecycle.md +0 -43
- package/data/harnesses/apollo/skills/design/references/ux-patterns/container-choice.md +0 -44
- package/data/harnesses/apollo/skills/design/references/ux-patterns/creation-paths.md +0 -46
- package/data/harnesses/apollo/skills/design/references/ux-patterns/dashboards.md +0 -42
- package/data/harnesses/apollo/skills/design/references/ux-patterns/modes.md +0 -42
- package/data/harnesses/apollo/skills/design/references/ux-patterns/object-model.md +0 -46
- package/data/harnesses/apollo/skills/design/references/ux-patterns/page-archetype.md +0 -48
- package/data/harnesses/apollo/skills/design/references/ux-patterns/promotion-demotion.md +0 -37
- package/data/harnesses/apollo/skills/design/references/ux-patterns/settings.md +0 -42
- package/data/harnesses/apollo/skills/design/references/ux-patterns/standard-pages.md +0 -46
- package/data/harnesses/apollo/skills/design/references/ux-patterns/state-matrix.md +0 -41
- package/data/harnesses/apollo/skills/design/references/ux-patterns/table-mechanics.md +0 -48
- package/data/harnesses/apollo/skills/design/references/ux-patterns/verbs.md +0 -45
- package/data/harnesses/apollo/skills/design/references/ux-patterns/viewer-context.md +0 -40
- package/data/harnesses/apollo/skills/design/scripts/README-validator.md +0 -27
- package/data/harnesses/apollo/skills/design/scripts/select-chart.mjs +0 -622
- package/data/harnesses/apollo/skills/design/scripts/validate-design-md.mjs +0 -1198
- package/data/harnesses/apollo/skills/documentation/SKILL.md +0 -135
- package/data/harnesses/apollo/skills/documentation/references/examples.md +0 -279
- package/data/harnesses/apollo/skills/documentation/references/frontmatter.md +0 -44
- package/data/harnesses/apollo/skills/documentation/references/instruction-style.md +0 -50
- package/data/harnesses/apollo/skills/documentation/references/style-guide.md +0 -384
- package/data/harnesses/apollo/skills/documentation/references/untemplated.md +0 -38
- package/data/harnesses/apollo/skills/documentation/scripts/doc-lint.mjs +0 -140
- package/data/harnesses/apollo/skills/documentation/templates/Readme.md +0 -35
- package/data/harnesses/apollo/skills/documentation/templates/api-reference.md +0 -20
- package/data/harnesses/apollo/skills/documentation/templates/architecture-decision.md +0 -121
- package/data/harnesses/apollo/skills/documentation/templates/backlog.md +0 -33
- package/data/harnesses/apollo/skills/documentation/templates/behavioral-checklist.md +0 -81
- package/data/harnesses/apollo/skills/documentation/templates/bookkeeping.md +0 -18
- package/data/harnesses/apollo/skills/documentation/templates/changelog-entry.md +0 -57
- package/data/harnesses/apollo/skills/documentation/templates/changelog-index.md +0 -41
- package/data/harnesses/apollo/skills/documentation/templates/docs-readme.md +0 -72
- package/data/harnesses/apollo/skills/documentation/templates/domain-model.md +0 -30
- package/data/harnesses/apollo/skills/documentation/templates/environment-registry.md +0 -15
- package/data/harnesses/apollo/skills/documentation/templates/feature.md +0 -150
- package/data/harnesses/apollo/skills/documentation/templates/glossary.md +0 -11
- package/data/harnesses/apollo/skills/documentation/templates/implementation-map.md +0 -42
- package/data/harnesses/apollo/skills/documentation/templates/journal.md +0 -13
- package/data/harnesses/apollo/skills/documentation/templates/memory-main.md +0 -25
- package/data/harnesses/apollo/skills/documentation/templates/migration-runbook.md +0 -34
- package/data/harnesses/apollo/skills/documentation/templates/non-goals.md +0 -11
- package/data/harnesses/apollo/skills/documentation/templates/operations-procedure.md +0 -36
- package/data/harnesses/apollo/skills/documentation/templates/plan.md +0 -88
- package/data/harnesses/apollo/skills/documentation/templates/protected-files.md +0 -37
- package/data/harnesses/apollo/skills/documentation/templates/root-readme.md +0 -104
- package/data/harnesses/apollo/skills/documentation/templates/security-overview.md +0 -27
- package/data/harnesses/apollo/skills/documentation/templates/structure.md +0 -65
- package/data/harnesses/apollo/skills/documentation/templates/system-overview.md +0 -32
- package/data/harnesses/apollo/skills/documentation/templates/testing-strategy.md +0 -29
- package/data/harnesses/apollo/skills/schema-design/SKILL.md +0 -141
- package/data/harnesses/apollo/skills/test/SKILL.md +0 -104
- package/data/harnesses/apollo/skills/testing/SKILL.md +0 -166
- package/data/harnesses/apollo/skills/workflow-mapper/SKILL.md +0 -451
- package/data/harnesses/apollo/skills/workflow-mapper/references/patterns.md +0 -214
- /package/data/harnesses/{apollo → code}/docs/README.md +0 -0
- /package/data/harnesses/{apollo → code}/docs/history/CHANGELOG.md +0 -0
- /package/data/harnesses/{apollo → code}/docs/history/backlog.md +0 -0
- /package/data/harnesses/{apollo → code}/docs/memory/main.md +0 -0
- /package/data/harnesses/{apollo → code}/docs/structure.md +0 -0
- /package/data/harnesses/{apollo → code}/rules/cloudflare.md +0 -0
|
@@ -1,622 +0,0 @@
|
|
|
1
|
-
// skills/design/scripts/select-chart.mjs - B1 chart-selection engine: eliminate, rank, refuse
|
|
2
|
-
//
|
|
3
|
-
// One graph question per call. The model authors the data-signature JSON (the judgment
|
|
4
|
-
// half); this script computes elimination, scoring, ranking, and refusal (the mechanical
|
|
5
|
-
// half) over the chart-leaf census at ../data/charts/census.csv — the census and this
|
|
6
|
-
// engine are one designed artifact and ship together (dimension-placement chapter 12).
|
|
7
|
-
// Callers may pass explicit census rows (module arg or the signature's `census` array);
|
|
8
|
-
// the local CSV is the default. Deterministic: same signature + census in, same output
|
|
9
|
-
// out. No network, stdlib only.
|
|
10
|
-
//
|
|
11
|
-
// OUTPUT CONTRACT (docs/features/design-skill/07-evaluation-integrity.md §B1 — exact):
|
|
12
|
-
// {
|
|
13
|
-
// "admissible": ["chart-id"],
|
|
14
|
-
// "eliminated": [{ "id": "chart-id", "reasonCode": "elimination-code" }],
|
|
15
|
-
// "ranking": [{ "id": "chart-id", "score": 0, "reasonCodes": ["reason-code"] }],
|
|
16
|
-
// "recommendation": "chart-id-or-null",
|
|
17
|
-
// "refusal": "refusal-code-or-null"
|
|
18
|
-
// }
|
|
19
|
-
//
|
|
20
|
-
// INPUT SIGNATURE (fixed schema; the fuzzy question->schema derivation is the caller's job):
|
|
21
|
-
// {
|
|
22
|
-
// question: string (audit only — no rule reads it),
|
|
23
|
-
// questions: [string] — optional; >1 entries signals a compound question (refusal),
|
|
24
|
-
// structure: "flat|tree|edges|matrix|geo|interval|grid|scalar|text" (default flat;
|
|
25
|
-
// scalar is derived when dimensions are empty and a measure exists),
|
|
26
|
-
// granularity: "raw-observations|pre-aggregated" (default pre-aggregated),
|
|
27
|
-
// rows: number — dataset row count (drives the overplotting regime),
|
|
28
|
-
// measures: [{ id, kind, unit, sign: "positive|signed|fraction", integer, isId, ambiguous }],
|
|
29
|
-
// dimensions: [{ id, kind: "nominal|ordinal|temporal|geo", ordered, cardinality,
|
|
30
|
-
// spacing: "regular|irregular", ambiguous }],
|
|
31
|
-
// target: { value, source } — optional explicit target,
|
|
32
|
-
// semantics: { targetExists, partsFormWhole, orderedProgression, temporalSubject,
|
|
33
|
-
// negativeValues, wholeUnits, uncertainty, mixedUnits },
|
|
34
|
-
// task: { primary, secondary: [<=2] } — optional; derived from schema defaults
|
|
35
|
-
// when absent (explicit caller cues always win over the defaults),
|
|
36
|
-
// ambiguities: [{ field, alternatives }] — optional; non-empty signals refusal,
|
|
37
|
-
// constraints: { viewport: "mobile|tablet|desktop|wide" (default desktop),
|
|
38
|
-
// interactionAllowed, colorVisionSafe, guardOverrides }
|
|
39
|
-
// }
|
|
40
|
-
//
|
|
41
|
-
// REFUSAL CONTRACT — four codes (graph-selection research 02 §7), checked in this order:
|
|
42
|
-
// 1. "unmappable-structure" (R-UNMAPPABLE) structure fits no signature: free prose,
|
|
43
|
-
// a lone non-numeric fact, or an empty signature (no fields at all).
|
|
44
|
-
// 2. "compound-question" (R-COMPOUND) input.questions carries >1 disjoint graph
|
|
45
|
-
// questions; decomposition is the invoker's job — the engine never charts two at once.
|
|
46
|
-
// 3. "ambiguous-schema" (R-AMBIGUOUS) the schema derives two ways that land in
|
|
47
|
-
// different families (any field marked ambiguous, or input.ambiguities non-empty).
|
|
48
|
-
// 4. "no-quantitative-measure" (R-NO-MEASURE) no measure and no countable structure —
|
|
49
|
-
// a bare entity list is a table row-set, not a chart; the engine refuses rather than
|
|
50
|
-
// inventing a count.
|
|
51
|
-
//
|
|
52
|
-
// FIXED OPEN PARAMETERS (the research left these open; fixed here, per 01 §B1):
|
|
53
|
-
// * Scoring constants (research §5 M-table, rescaled to reduce clamp saturation at 100
|
|
54
|
-
// while preserving every ordering relationship: M1 dominant, |M3 match| > |M2|,
|
|
55
|
-
// over-cap ~ -M3): BASE 50, clamp [0,100];
|
|
56
|
-
// M1 native fit: family anchor +20, native +16, fallback (table family) +6
|
|
57
|
-
// M2 encoding: position/length +8, angle/area/color-only -8, else 0
|
|
58
|
-
// M3 primary-task match +12 / mismatch -8 (leaves with no native task: 0)
|
|
59
|
-
// M4 secondary-task match +4 each (<=2)
|
|
60
|
-
// M5 cardinality: comfortable +4, near cap -4, over cap -12 (+ facet escape code)
|
|
61
|
-
// M6 dataset size: rows>=10000 binned +8 / point -8; rows>=1000 hexbin +4
|
|
62
|
-
// M7 decorative/low-precision -8 (pictogram, gauge, streamgraph, radar)
|
|
63
|
-
// M8 flag synergy +6 (temporalSubject->line family; partsFormWhole->part-to-whole
|
|
64
|
-
// family; targetExists->target-native leaves; uncertainty->error-bands)
|
|
65
|
-
// Threshold constants (research §6, fixed by decision inside the evidenced bands):
|
|
66
|
-
// K1 pie slices 6 · K2 bar categories 12 · K3 line series 6 · K4 stacked totals 10
|
|
67
|
-
// K5 overplot 1000 offered / 10000 mandatory · K6 facet panels 20 · K7 grouped
|
|
68
|
-
// series 4 · K8 waffle 10x10 · K9 SPLOM vars 8 · K10 network nodes 300.
|
|
69
|
-
// Hard elimination sits at 2x the comfort cap ("cardinality-exceeded"); between
|
|
70
|
-
// comfort and 2x the leaf is demoted, never killed (T-H: membership is decided only
|
|
71
|
-
// in elimination, so only 2x-destructive overflow counts as an expressiveness kill).
|
|
72
|
-
// * Task facets (research open question 3): primary + <=2 secondary facets are accepted
|
|
73
|
-
// on explicit input.task; schema-default derivation supplies a primary only. Rationale:
|
|
74
|
-
// one question can carry compound facets ("compare regions over time"), but the engine
|
|
75
|
-
// never invents a secondary the caller didn't assert.
|
|
76
|
-
// * Ambiguity handling (research open question 4): R-AMBIGUOUS stays a refusal variant,
|
|
77
|
-
// not a third response type — two response types keep the invoker contract simple
|
|
78
|
-
// (the research's own recommendation, adopted).
|
|
79
|
-
// * Guard overrides (research open question 5): guard variants (dual axes, truncated
|
|
80
|
-
// bar axes, broken axes, 3D) are census-level exclusions — they are design variants,
|
|
81
|
-
// not chart leaves, so there is nothing in the 57-leaf universe to resurrect.
|
|
82
|
-
// constraints.guardOverrides is accepted for forward compatibility and is currently a
|
|
83
|
-
// no-op on this closed output contract; overrides remain a rendering-layer concern
|
|
84
|
-
// recorded by the caller (per the ruling: overridable by explicit flag, logged).
|
|
85
|
-
// * The research's "conditional section" (options that unlock if a flag flips) folds
|
|
86
|
-
// into `eliminated` with flag-gate reason codes ("parts-form-whole-not-asserted",
|
|
87
|
-
// "target-not-asserted", ...) because the ratified 07 §B1 contract is closed — the
|
|
88
|
-
// unlock flag is recoverable from the reason code.
|
|
89
|
-
//
|
|
90
|
-
// CENSUS FLAG SEMANTICS (requires_flags / excludes_flags, |-separated):
|
|
91
|
-
// Flags fall into three classes; requires_flags evaluates per class:
|
|
92
|
-
// ordering class {temporal, ordered-progression} — OR (any one satisfies)
|
|
93
|
-
// structure class {tree, edges, matrix, geo, interval, scalar, grid} — OR
|
|
94
|
-
// semantic class (everything else) — AND (each required)
|
|
95
|
-
// excludes_flags: any listed flag present in the derived input flags eliminates the leaf.
|
|
96
|
-
// Elimination emits one reasonCode per leaf, first match in this fixed precedence:
|
|
97
|
-
// structure-incompatible -> excluded-flag codes -> missing-required-flag codes
|
|
98
|
-
// ("ordered-x-required" for the ordering class, "structure-required" for the structure
|
|
99
|
-
// class, "<flag>-not-asserted"/"-required" for semantic flags) -> signature-mismatch
|
|
100
|
-
// -> cardinality-exceeded -> viewport-too-small.
|
|
101
|
-
|
|
102
|
-
import fs from 'node:fs';
|
|
103
|
-
import path from 'node:path';
|
|
104
|
-
import process from 'node:process';
|
|
105
|
-
import { fileURLToPath } from 'node:url';
|
|
106
|
-
|
|
107
|
-
const VIEWPORT_ORDER = ['mobile', 'tablet', 'desktop', 'wide'];
|
|
108
|
-
const ORDER_FLAGS = new Set(['temporal', 'ordered-progression']);
|
|
109
|
-
const STRUCTURE_FLAGS = new Set(['tree', 'edges', 'matrix', 'geo', 'interval', 'scalar', 'grid']);
|
|
110
|
-
const REFUSING_STRUCTURES = new Set(['text', 'prose', 'text-weights', 'none', 'unknown']);
|
|
111
|
-
|
|
112
|
-
const EXCLUDE_REASON_BY_FLAG = {
|
|
113
|
-
temporal: 'temporal-series-incompatible',
|
|
114
|
-
'negative-values': 'negative-values-incompatible',
|
|
115
|
-
'irregular-temporal': 'irregular-temporal-incompatible',
|
|
116
|
-
'mixed-units': 'mixed-units-incompatible',
|
|
117
|
-
'no-color-encoding': 'color-encoding-inaccessible',
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
const REQUIRE_REASON_BY_FLAG = {
|
|
121
|
-
'parts-form-whole': 'parts-form-whole-not-asserted',
|
|
122
|
-
'target-exists': 'target-not-asserted',
|
|
123
|
-
'negative-values': 'negative-values-not-asserted',
|
|
124
|
-
'raw-observations': 'raw-observations-required',
|
|
125
|
-
'whole-units': 'whole-units-required',
|
|
126
|
-
uncertainty: 'uncertainty-not-asserted',
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
// EL-4: a non-flat structure admits only these leaves (plus any leaf that requires it).
|
|
130
|
-
const STRUCTURE_COMPAT = {
|
|
131
|
-
tree: ['treemap', 'sunburst', 'tree-diagram', 'table', 'table-hybrid'],
|
|
132
|
-
edges: ['sankey', 'chord', 'network-graph', 'table', 'table-hybrid'],
|
|
133
|
-
matrix: ['heatmap', 'chord', 'table', 'table-hybrid'],
|
|
134
|
-
geo: ['choropleth', 'symbol-map', 'flow-map', 'point-map', 'table', 'table-hybrid'],
|
|
135
|
-
interval: ['gantt', 'event-timeline', 'table', 'table-hybrid'],
|
|
136
|
-
scalar: ['kpi-card', 'gauge', 'progress-bar', 'bullet', 'table', 'table-hybrid'],
|
|
137
|
-
grid: ['heatmap', 'table', 'table-hybrid'],
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
// M1 tiers: the settled core mappings (research 00 §C-1) anchor each family.
|
|
141
|
-
const FAMILY_ANCHORS = new Set([
|
|
142
|
-
'bar', 'line-basic', 'pie', 'histogram', 'scatter', 'ordered-bar', 'sankey',
|
|
143
|
-
'network-graph', 'choropleth', 'event-timeline', 'kpi-card', 'heatmap', 'candlestick',
|
|
144
|
-
]);
|
|
145
|
-
const FALLBACK_LEAVES = new Set(['table', 'table-hybrid']);
|
|
146
|
-
|
|
147
|
-
// M2: position/length reads most accurately; angle/area/color-only reads worst.
|
|
148
|
-
const POSITION_LEAVES = new Set([
|
|
149
|
-
'bar', 'grouped-bar', 'stacked-bar', 'diverging-bar', 'lollipop', 'dot-plot', 'dumbbell',
|
|
150
|
-
'line-basic', 'line-multi', 'line-with-target', 'slope', 'bump', 'sparkline', 'ordered-bar',
|
|
151
|
-
'pareto', 'waterfall', 'scatter', 'histogram', 'box-plot', 'strip-plot', 'bullet',
|
|
152
|
-
'progress-bar', 'gantt', 'candlestick', 'error-bands',
|
|
153
|
-
]);
|
|
154
|
-
const LOW_PRECISION_LEAVES = new Set([
|
|
155
|
-
'pie', 'waffle', 'treemap', 'sunburst', 'marimekko', 'funnel', 'streamgraph', 'bubble',
|
|
156
|
-
'radar', 'pictogram', 'gauge', 'chord', 'heatmap', 'calendar-heatmap', 'choropleth',
|
|
157
|
-
'symbol-map',
|
|
158
|
-
]);
|
|
159
|
-
|
|
160
|
-
// M7: decorative/low-precision forms named by the research.
|
|
161
|
-
const DECORATIVE_LEAVES = new Set(['pictogram', 'gauge', 'streamgraph', 'radar']);
|
|
162
|
-
|
|
163
|
-
// M3/M4 native-task table (research §5, Amar-10 + trend/compare/overview).
|
|
164
|
-
const NATIVE_TASKS = {
|
|
165
|
-
correlate: ['scatter', 'hexbin', 'splom', 'parallel-coordinates', 'bubble'],
|
|
166
|
-
trend: ['line-basic', 'line-multi', 'line-with-target', 'area', 'sparkline'],
|
|
167
|
-
distribution: ['histogram', 'density', 'box-plot', 'violin', 'strip-plot'],
|
|
168
|
-
'retrieve-value': ['table', 'table-hybrid', 'kpi-card'],
|
|
169
|
-
filter: ['table', 'table-hybrid'],
|
|
170
|
-
extremum: ['bar', 'ordered-bar', 'pareto'],
|
|
171
|
-
sort: ['ordered-bar', 'pareto', 'bar'],
|
|
172
|
-
compare: ['bar', 'grouped-bar', 'dot-plot', 'slope'],
|
|
173
|
-
cluster: ['scatter', 'heatmap'],
|
|
174
|
-
anomalies: ['scatter', 'box-plot'],
|
|
175
|
-
range: ['dumbbell', 'box-plot', 'gantt'],
|
|
176
|
-
derive: ['table', 'waterfall'],
|
|
177
|
-
overview: ['bar', 'line-basic', 'heatmap'],
|
|
178
|
-
};
|
|
179
|
-
const NATIVE_TASKS_BY_LEAF = (() => {
|
|
180
|
-
const byLeaf = new Map();
|
|
181
|
-
for (const [task, leaves] of Object.entries(NATIVE_TASKS)) {
|
|
182
|
-
for (const leaf of leaves) {
|
|
183
|
-
if (!byLeaf.has(leaf)) byLeaf.set(leaf, new Set());
|
|
184
|
-
byLeaf.get(leaf).add(task);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
return byLeaf;
|
|
188
|
-
})();
|
|
189
|
-
|
|
190
|
-
// M5 cardinality rules per leaf: comfort cap (K constants), hard kill at 2x comfort
|
|
191
|
-
// unless the census constraint is itself hard (slope's 2-3 x positions).
|
|
192
|
-
const CARDINALITY_RULES = {
|
|
193
|
-
pie: { kind: 'categories', comfort: 6 }, // K1
|
|
194
|
-
waffle: { kind: 'categories', comfort: 6 }, // mirrors K1
|
|
195
|
-
bar: { kind: 'categories', comfort: 12, demoteOnly: true }, // K2
|
|
196
|
-
'ordered-bar': { kind: 'categories', comfort: 12, demoteOnly: true },
|
|
197
|
-
lollipop: { kind: 'categories', comfort: 12, demoteOnly: true },
|
|
198
|
-
'dot-plot': { kind: 'categories', comfort: 12, demoteOnly: true },
|
|
199
|
-
'grouped-bar': { kind: 'series', comfort: 4 }, // K7
|
|
200
|
-
'stacked-bar': { kind: 'series', comfort: 10 }, // K4
|
|
201
|
-
'line-multi': { kind: 'series', comfort: 6 }, // K3
|
|
202
|
-
bump: { kind: 'series', comfort: 6 },
|
|
203
|
-
slope: { kind: 'x-positions', comfort: 3, hard: 3 },
|
|
204
|
-
radar: { kind: 'categories', comfort: 3 },
|
|
205
|
-
'network-graph': { kind: 'nodes', comfort: 150, hard: 300 }, // K10
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
// M6 dataset-size regimes (K5).
|
|
209
|
-
const BINNED_LEAVES = new Set(['hexbin', 'histogram', 'density', 'box-plot', 'heatmap', 'calendar-heatmap']);
|
|
210
|
-
const POINT_LEAVES = new Set(['scatter', 'strip-plot', 'bubble']);
|
|
211
|
-
const OVERPLOT_OFFERED = 1000;
|
|
212
|
-
const OVERPLOT_MANDATORY = 10000;
|
|
213
|
-
|
|
214
|
-
// M8 synergy targets beyond the family-level ones.
|
|
215
|
-
const TARGET_NATIVE_LEAVES = new Set(['progress-bar', 'bullet', 'gauge', 'line-with-target']);
|
|
216
|
-
|
|
217
|
-
const SCORE = {
|
|
218
|
-
base: 50,
|
|
219
|
-
m1Anchor: 20,
|
|
220
|
-
m1Native: 16,
|
|
221
|
-
m1Fallback: 6,
|
|
222
|
-
m2Position: 8,
|
|
223
|
-
m2LowPrecision: -8,
|
|
224
|
-
m3Match: 12,
|
|
225
|
-
m3Mismatch: -8,
|
|
226
|
-
m4Secondary: 4,
|
|
227
|
-
m5Comfortable: 4,
|
|
228
|
-
m5NearCap: -4,
|
|
229
|
-
m5OverCap: -12,
|
|
230
|
-
m6Binned: 8,
|
|
231
|
-
m6Overplot: -8,
|
|
232
|
-
m6HexbinOffered: 4,
|
|
233
|
-
m7Decorative: -8,
|
|
234
|
-
m8Synergy: 6,
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
// Parses one CSV line honoring double-quoted fields.
|
|
238
|
-
function parseCsvLine(line) {
|
|
239
|
-
const cells = [];
|
|
240
|
-
let cell = '';
|
|
241
|
-
let inQuotes = false;
|
|
242
|
-
for (let i = 0; i < line.length; i += 1) {
|
|
243
|
-
const ch = line[i];
|
|
244
|
-
if (inQuotes) {
|
|
245
|
-
if (ch === '"' && line[i + 1] === '"') { cell += '"'; i += 1; }
|
|
246
|
-
else if (ch === '"') inQuotes = false;
|
|
247
|
-
else cell += ch;
|
|
248
|
-
} else if (ch === '"') inQuotes = true;
|
|
249
|
-
else if (ch === ',') { cells.push(cell); cell = ''; }
|
|
250
|
-
else cell += ch;
|
|
251
|
-
}
|
|
252
|
-
cells.push(cell);
|
|
253
|
-
return cells;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
export function parseCensusCsv(text) {
|
|
257
|
-
const lines = text.split(/\r?\n/).filter((line) => line.trim() !== '');
|
|
258
|
-
const header = parseCsvLine(lines[0]).map((h) => h.trim());
|
|
259
|
-
const expected = ['id', 'family', 'min_measures', 'max_measures', 'min_dims', 'max_dims', 'requires_flags', 'excludes_flags', 'viewport_min', 'notes'];
|
|
260
|
-
if (header.join(',') !== expected.join(',')) {
|
|
261
|
-
throw new Error(`census header mismatch: expected "${expected.join(',')}" got "${header.join(',')}"`);
|
|
262
|
-
}
|
|
263
|
-
return lines.slice(1).map((line, index) => {
|
|
264
|
-
const cells = parseCsvLine(line);
|
|
265
|
-
const row = {};
|
|
266
|
-
header.forEach((key, i) => { row[key] = (cells[i] ?? '').trim(); });
|
|
267
|
-
return {
|
|
268
|
-
id: row.id,
|
|
269
|
-
family: row.family,
|
|
270
|
-
minMeasures: Number(row.min_measures),
|
|
271
|
-
maxMeasures: Number(row.max_measures),
|
|
272
|
-
minDims: Number(row.min_dims),
|
|
273
|
-
maxDims: Number(row.max_dims),
|
|
274
|
-
requiresFlags: row.requires_flags === '' ? [] : row.requires_flags.split('|').map((f) => f.trim()),
|
|
275
|
-
excludesFlags: row.excludes_flags === '' ? [] : row.excludes_flags.split('|').map((f) => f.trim()),
|
|
276
|
-
viewportMin: row.viewport_min === '' ? 'mobile' : row.viewport_min,
|
|
277
|
-
notes: row.notes,
|
|
278
|
-
order: index,
|
|
279
|
-
};
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
export function loadDefaultCensus() {
|
|
284
|
-
const censusPath = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'data', 'charts', 'census.csv');
|
|
285
|
-
return parseCensusCsv(fs.readFileSync(censusPath, 'utf8'));
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// Accepts census rows in the engine's leaf shape (or a row shape with snake_case columns
|
|
289
|
-
// and pipe-joined flag strings) and normalizes onto the leaf shape.
|
|
290
|
-
export function normalizeCensusRows(rows) {
|
|
291
|
-
if (!Array.isArray(rows) || rows.length === 0) {
|
|
292
|
-
throw new Error('census rows are required — the shipped census at data/charts/census.csv is the default');
|
|
293
|
-
}
|
|
294
|
-
const toFlagList = (value) =>
|
|
295
|
-
Array.isArray(value) ? value : value == null || value === '' ? [] : String(value).split('|').map((f) => f.trim());
|
|
296
|
-
return rows.map((row, index) => ({
|
|
297
|
-
id: row.id ?? row.slug,
|
|
298
|
-
family: row.family,
|
|
299
|
-
minMeasures: Number(row.minMeasures ?? row.min_measures),
|
|
300
|
-
maxMeasures: Number(row.maxMeasures ?? row.max_measures),
|
|
301
|
-
minDims: Number(row.minDims ?? row.min_dims),
|
|
302
|
-
maxDims: Number(row.maxDims ?? row.max_dims),
|
|
303
|
-
requiresFlags: toFlagList(row.requiresFlags ?? row.requires_flags),
|
|
304
|
-
excludesFlags: toFlagList(row.excludesFlags ?? row.excludes_flags),
|
|
305
|
-
viewportMin: row.viewportMin ?? row.viewport_min ?? 'mobile',
|
|
306
|
-
notes: row.notes ?? '',
|
|
307
|
-
order: row.order ?? row.ord ?? index,
|
|
308
|
-
}));
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// Normalizes loose dimension-kind aliases onto the N/O/Q/T backbone.
|
|
312
|
-
function dimensionKind(dim) {
|
|
313
|
-
const kind = dim.kind || 'nominal';
|
|
314
|
-
if (kind === 'categorical') return 'nominal';
|
|
315
|
-
return kind;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
function effectiveMeasures(input) {
|
|
319
|
-
return (input.measures || []).filter((m) => m.isId !== true);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
// Derives the auditable flag set the census rows are gated on.
|
|
323
|
-
function deriveFlags(input) {
|
|
324
|
-
const dims = input.dimensions || [];
|
|
325
|
-
const measures = effectiveMeasures(input);
|
|
326
|
-
const semantics = input.semantics || {};
|
|
327
|
-
const constraints = input.constraints || {};
|
|
328
|
-
const structure = deriveStructure(input);
|
|
329
|
-
const flags = new Set();
|
|
330
|
-
|
|
331
|
-
if (dims.some((d) => dimensionKind(d) === 'temporal')) flags.add('temporal');
|
|
332
|
-
if (semantics.orderedProgression === true || dims.some((d) => d.ordered === true && dimensionKind(d) !== 'temporal')) {
|
|
333
|
-
flags.add('ordered-progression');
|
|
334
|
-
}
|
|
335
|
-
if (semantics.partsFormWhole === true) flags.add('parts-form-whole');
|
|
336
|
-
if (semantics.targetExists === true || input.target != null) flags.add('target-exists');
|
|
337
|
-
if (semantics.negativeValues === true || measures.some((m) => m.sign === 'signed')) flags.add('negative-values');
|
|
338
|
-
if ((input.granularity || 'pre-aggregated') === 'raw-observations') flags.add('raw-observations');
|
|
339
|
-
if (semantics.wholeUnits === true
|
|
340
|
-
|| (measures.length > 0 && measures.every((m) => m.kind === 'count' || m.unit === 'count' || m.integer === true))) {
|
|
341
|
-
flags.add('whole-units');
|
|
342
|
-
}
|
|
343
|
-
if (dims.some((d) => dimensionKind(d) === 'temporal' && d.spacing === 'irregular')) flags.add('irregular-temporal');
|
|
344
|
-
if (semantics.uncertainty === true || semantics.uncertaintyExists === true) flags.add('uncertainty');
|
|
345
|
-
if (semantics.mixedUnits === true
|
|
346
|
-
|| (measures.length > 1 && new Set(measures.map((m) => m.unit ?? m.kind ?? '')).size > 1)) {
|
|
347
|
-
flags.add('mixed-units');
|
|
348
|
-
}
|
|
349
|
-
const accessibility = constraints.accessibility;
|
|
350
|
-
if (constraints.colorVisionSafe === true
|
|
351
|
-
|| accessibility === 'color-independent'
|
|
352
|
-
|| (Array.isArray(accessibility) && accessibility.includes('color-independent'))) {
|
|
353
|
-
flags.add('no-color-encoding');
|
|
354
|
-
}
|
|
355
|
-
if (STRUCTURE_FLAGS.has(structure)) flags.add(structure);
|
|
356
|
-
return { flags, structure };
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
function deriveStructure(input) {
|
|
360
|
-
if (input.structure) return input.structure;
|
|
361
|
-
const dims = input.dimensions || [];
|
|
362
|
-
const measures = effectiveMeasures(input);
|
|
363
|
-
if (dims.length === 0 && measures.length > 0) return 'scalar';
|
|
364
|
-
return 'flat';
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
// Refusal check — fires instead of a ranking; order is part of the contract (header).
|
|
368
|
-
function deriveRefusal(input, structure) {
|
|
369
|
-
const dims = input.dimensions || [];
|
|
370
|
-
const measures = effectiveMeasures(input);
|
|
371
|
-
const allFields = [...(input.measures || []), ...dims];
|
|
372
|
-
if (REFUSING_STRUCTURES.has(structure)) return 'unmappable-structure';
|
|
373
|
-
if (structure === 'flat' && measures.length === 0 && dims.length === 0 && input.target == null) {
|
|
374
|
-
return 'unmappable-structure';
|
|
375
|
-
}
|
|
376
|
-
if (Array.isArray(input.questions) && input.questions.length > 1) return 'compound-question';
|
|
377
|
-
if ((Array.isArray(input.ambiguities) && input.ambiguities.length > 0)
|
|
378
|
-
|| allFields.some((f) => f.ambiguous === true)) {
|
|
379
|
-
return 'ambiguous-schema';
|
|
380
|
-
}
|
|
381
|
-
if (measures.length === 0 && structure === 'flat'
|
|
382
|
-
&& !dims.some((d) => ['temporal', 'geo'].includes(dimensionKind(d)))) {
|
|
383
|
-
return 'no-quantitative-measure';
|
|
384
|
-
}
|
|
385
|
-
return null;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
// Schema-default task derivation (the engine's half of the two-stage derivation;
|
|
389
|
-
// explicit query-cue extraction is the caller's half and arrives as input.task).
|
|
390
|
-
function deriveTask(input, flags) {
|
|
391
|
-
if (input.task && input.task.primary) {
|
|
392
|
-
return {
|
|
393
|
-
primary: input.task.primary,
|
|
394
|
-
secondary: (input.task.secondary || []).slice(0, 2),
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
|
-
const dims = input.dimensions || [];
|
|
398
|
-
const measures = effectiveMeasures(input);
|
|
399
|
-
const catDims = dims.filter((d) => ['nominal', 'ordinal'].includes(dimensionKind(d)));
|
|
400
|
-
let primary;
|
|
401
|
-
if (dims.length === 0) primary = flags.has('target-exists') ? 'compare' : 'retrieve-value';
|
|
402
|
-
else if (measures.length >= 2 && flags.has('raw-observations')) primary = 'correlate';
|
|
403
|
-
else if (flags.has('temporal') && measures.length >= 1) primary = 'trend';
|
|
404
|
-
else if (measures.length === 1 && flags.has('raw-observations') && catDims.length <= 1) primary = 'distribution';
|
|
405
|
-
else if (measures.length >= 2) primary = 'correlate';
|
|
406
|
-
else if (catDims.length >= 1 && measures.length >= 1) primary = 'compare';
|
|
407
|
-
else primary = 'overview';
|
|
408
|
-
return { primary, secondary: [] };
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
// Resolves the cardinality the leaf's M5 rule inspects.
|
|
412
|
-
function cardinalityFor(rule, input) {
|
|
413
|
-
const dims = input.dimensions || [];
|
|
414
|
-
const catDims = dims.filter((d) => ['nominal', 'ordinal'].includes(dimensionKind(d)));
|
|
415
|
-
const orderedDims = dims.filter((d) => dimensionKind(d) === 'temporal' || d.ordered === true);
|
|
416
|
-
const cards = (list) => list.map((d) => d.cardinality).filter((c) => Number.isFinite(c));
|
|
417
|
-
switch (rule.kind) {
|
|
418
|
-
case 'categories': {
|
|
419
|
-
const c = cards(catDims.length > 0 ? catDims : dims);
|
|
420
|
-
return c.length > 0 ? c[0] : undefined;
|
|
421
|
-
}
|
|
422
|
-
case 'series': {
|
|
423
|
-
const nonOrdered = dims.filter((d) => !(dimensionKind(d) === 'temporal' || d.ordered === true));
|
|
424
|
-
if (orderedDims.length > 0 && nonOrdered.length > 0) {
|
|
425
|
-
const c = cards(nonOrdered);
|
|
426
|
-
return c.length > 0 ? Math.max(...c) : undefined;
|
|
427
|
-
}
|
|
428
|
-
const c = cards(catDims);
|
|
429
|
-
return c.length >= 2 ? Math.min(...c) : c[0];
|
|
430
|
-
}
|
|
431
|
-
case 'x-positions': {
|
|
432
|
-
const c = cards(orderedDims);
|
|
433
|
-
return c.length > 0 ? c[0] : undefined;
|
|
434
|
-
}
|
|
435
|
-
case 'nodes': {
|
|
436
|
-
const c = cards(dims);
|
|
437
|
-
return c.length > 0 ? Math.max(...c) : undefined;
|
|
438
|
-
}
|
|
439
|
-
default:
|
|
440
|
-
return undefined;
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
// Elimination — one reasonCode per leaf, fixed precedence (see header).
|
|
445
|
-
function eliminationReason(leaf, input, flags, structure, viewport) {
|
|
446
|
-
const measures = effectiveMeasures(input);
|
|
447
|
-
const dims = input.dimensions || [];
|
|
448
|
-
|
|
449
|
-
if (structure !== 'flat' && STRUCTURE_COMPAT[structure]
|
|
450
|
-
&& !STRUCTURE_COMPAT[structure].includes(leaf.id)
|
|
451
|
-
&& !leaf.requiresFlags.includes(structure)) {
|
|
452
|
-
return 'structure-incompatible';
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
for (const flag of leaf.excludesFlags) {
|
|
456
|
-
if (flags.has(flag)) return EXCLUDE_REASON_BY_FLAG[flag] || `${flag}-incompatible`;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
const orderingRequired = leaf.requiresFlags.filter((f) => ORDER_FLAGS.has(f));
|
|
460
|
-
if (orderingRequired.length > 0 && !orderingRequired.some((f) => flags.has(f))) {
|
|
461
|
-
return 'ordered-x-required';
|
|
462
|
-
}
|
|
463
|
-
const structureRequired = leaf.requiresFlags.filter((f) => STRUCTURE_FLAGS.has(f));
|
|
464
|
-
if (structureRequired.length > 0 && !structureRequired.some((f) => flags.has(f))) {
|
|
465
|
-
return 'structure-required';
|
|
466
|
-
}
|
|
467
|
-
for (const flag of leaf.requiresFlags) {
|
|
468
|
-
if (ORDER_FLAGS.has(flag) || STRUCTURE_FLAGS.has(flag)) continue;
|
|
469
|
-
if (!flags.has(flag)) return REQUIRE_REASON_BY_FLAG[flag] || `${flag}-not-asserted`;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
if (measures.length < leaf.minMeasures || measures.length > leaf.maxMeasures
|
|
473
|
-
|| dims.length < leaf.minDims || dims.length > leaf.maxDims) {
|
|
474
|
-
return 'signature-mismatch';
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
const rule = CARDINALITY_RULES[leaf.id];
|
|
478
|
-
if (rule && !rule.demoteOnly) {
|
|
479
|
-
const card = cardinalityFor(rule, input);
|
|
480
|
-
const hard = rule.hard ?? rule.comfort * 2;
|
|
481
|
-
if (card !== undefined && card > hard) return 'cardinality-exceeded';
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
if (VIEWPORT_ORDER.indexOf(viewport) < VIEWPORT_ORDER.indexOf(leaf.viewportMin)) {
|
|
485
|
-
return 'viewport-too-small';
|
|
486
|
-
}
|
|
487
|
-
return null;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
// Scoring — additive over the fixed M-table; every weight is a constant (header).
|
|
491
|
-
function scoreLeaf(leaf, input, flags, task) {
|
|
492
|
-
let score = SCORE.base;
|
|
493
|
-
const reasonCodes = [];
|
|
494
|
-
|
|
495
|
-
if (FAMILY_ANCHORS.has(leaf.id)) { score += SCORE.m1Anchor; reasonCodes.push('m1-native-anchor'); }
|
|
496
|
-
else if (FALLBACK_LEAVES.has(leaf.id)) { score += SCORE.m1Fallback; reasonCodes.push('m1-fallback'); }
|
|
497
|
-
else { score += SCORE.m1Native; reasonCodes.push('m1-native-fit'); }
|
|
498
|
-
|
|
499
|
-
if (POSITION_LEAVES.has(leaf.id)) { score += SCORE.m2Position; reasonCodes.push('m2-position-encoding'); }
|
|
500
|
-
else if (LOW_PRECISION_LEAVES.has(leaf.id)) { score += SCORE.m2LowPrecision; reasonCodes.push('m2-low-precision-encoding'); }
|
|
501
|
-
|
|
502
|
-
const nativeTasks = NATIVE_TASKS_BY_LEAF.get(leaf.id);
|
|
503
|
-
if (nativeTasks && task.primary) {
|
|
504
|
-
if (nativeTasks.has(task.primary)) { score += SCORE.m3Match; reasonCodes.push(`m3-task-match:${task.primary}`); }
|
|
505
|
-
else { score += SCORE.m3Mismatch; reasonCodes.push('m3-task-mismatch'); }
|
|
506
|
-
for (const secondary of task.secondary) {
|
|
507
|
-
if (nativeTasks.has(secondary)) { score += SCORE.m4Secondary; reasonCodes.push(`m4-secondary-task-match:${secondary}`); }
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
const rule = CARDINALITY_RULES[leaf.id];
|
|
512
|
-
if (rule) {
|
|
513
|
-
const card = cardinalityFor(rule, input);
|
|
514
|
-
if (card !== undefined) {
|
|
515
|
-
if (card <= rule.comfort) { score += SCORE.m5Comfortable; reasonCodes.push('m5-cardinality-comfortable'); }
|
|
516
|
-
else if (card <= (rule.hard ?? rule.comfort * 2)) { score += SCORE.m5NearCap; reasonCodes.push('m5-cardinality-near-cap'); }
|
|
517
|
-
else { score += SCORE.m5OverCap; reasonCodes.push('m5-cardinality-over-cap', 'op-facet-suggested'); }
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
const rows = Number.isFinite(input.rows) ? input.rows : undefined;
|
|
522
|
-
if (rows !== undefined) {
|
|
523
|
-
if (rows >= OVERPLOT_MANDATORY) {
|
|
524
|
-
if (BINNED_LEAVES.has(leaf.id)) { score += SCORE.m6Binned; reasonCodes.push('m6-binned-boost'); }
|
|
525
|
-
if (POINT_LEAVES.has(leaf.id)) { score += SCORE.m6Overplot; reasonCodes.push('m6-overplot-penalty'); }
|
|
526
|
-
} else if (rows >= OVERPLOT_OFFERED && leaf.id === 'hexbin') {
|
|
527
|
-
score += SCORE.m6HexbinOffered;
|
|
528
|
-
reasonCodes.push('m6-binned-boost');
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
if (DECORATIVE_LEAVES.has(leaf.id)) { score += SCORE.m7Decorative; reasonCodes.push('m7-decorative-penalty'); }
|
|
533
|
-
|
|
534
|
-
const semantics = input.semantics || {};
|
|
535
|
-
if (semantics.temporalSubject === true && leaf.family === 'line') {
|
|
536
|
-
score += SCORE.m8Synergy; reasonCodes.push('m8-flag-synergy:temporal-subject');
|
|
537
|
-
}
|
|
538
|
-
if (flags.has('parts-form-whole') && leaf.family === 'part-to-whole') {
|
|
539
|
-
score += SCORE.m8Synergy; reasonCodes.push('m8-flag-synergy:parts-form-whole');
|
|
540
|
-
}
|
|
541
|
-
if (flags.has('target-exists') && TARGET_NATIVE_LEAVES.has(leaf.id)) {
|
|
542
|
-
score += SCORE.m8Synergy; reasonCodes.push('m8-flag-synergy:target-exists');
|
|
543
|
-
}
|
|
544
|
-
if (flags.has('uncertainty') && leaf.id === 'error-bands') {
|
|
545
|
-
score += SCORE.m8Synergy; reasonCodes.push('m8-flag-synergy:uncertainty');
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
return { score: Math.max(0, Math.min(100, score)), reasonCodes };
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
// The B1 decision function — one engine, two callers (CLI here, contract runner imports).
|
|
552
|
-
export function selectChart(input, censusRows) {
|
|
553
|
-
if (input == null || typeof input !== 'object' || Array.isArray(input)) {
|
|
554
|
-
throw new Error('selectChart: input must be a data-signature object');
|
|
555
|
-
}
|
|
556
|
-
const census = normalizeCensusRows(censusRows ?? input.census ?? loadDefaultCensus());
|
|
557
|
-
const { flags, structure } = deriveFlags(input);
|
|
558
|
-
|
|
559
|
-
const refusal = deriveRefusal(input, structure);
|
|
560
|
-
if (refusal !== null) {
|
|
561
|
-
return { admissible: [], eliminated: [], ranking: [], recommendation: null, refusal };
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
const viewport = (input.constraints && input.constraints.viewport) || 'desktop';
|
|
565
|
-
const task = deriveTask(input, flags);
|
|
566
|
-
|
|
567
|
-
const admissibleLeaves = [];
|
|
568
|
-
const eliminated = [];
|
|
569
|
-
for (const leaf of census) {
|
|
570
|
-
const reasonCode = eliminationReason(leaf, input, flags, structure, viewport);
|
|
571
|
-
if (reasonCode !== null) eliminated.push({ id: leaf.id, reasonCode });
|
|
572
|
-
else admissibleLeaves.push(leaf);
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
const ranking = admissibleLeaves
|
|
576
|
-
.map((leaf) => ({ leaf, ...scoreLeaf(leaf, input, flags, task) }))
|
|
577
|
-
.sort((a, b) => (b.score - a.score) || (a.leaf.order - b.leaf.order))
|
|
578
|
-
.map((entry) => ({ id: entry.leaf.id, score: entry.score, reasonCodes: entry.reasonCodes }));
|
|
579
|
-
|
|
580
|
-
return {
|
|
581
|
-
admissible: admissibleLeaves.map((leaf) => leaf.id),
|
|
582
|
-
eliminated,
|
|
583
|
-
ranking,
|
|
584
|
-
recommendation: ranking.length > 0 ? ranking[0].id : null,
|
|
585
|
-
refusal: null,
|
|
586
|
-
};
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
// Reads the whole of stdin (used when no input path is given).
|
|
590
|
-
function readStdin() {
|
|
591
|
-
return fs.readFileSync(0, 'utf8');
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
function main() {
|
|
595
|
-
const inputPath = process.argv[2];
|
|
596
|
-
let raw;
|
|
597
|
-
try {
|
|
598
|
-
raw = inputPath ? fs.readFileSync(inputPath, 'utf8') : readStdin();
|
|
599
|
-
} catch (error) {
|
|
600
|
-
console.error(`select-chart: cannot read input: ${error.message}`);
|
|
601
|
-
process.exit(1);
|
|
602
|
-
}
|
|
603
|
-
let input;
|
|
604
|
-
try {
|
|
605
|
-
input = JSON.parse(raw);
|
|
606
|
-
} catch (error) {
|
|
607
|
-
console.error(`select-chart: input is not valid JSON: ${error.message}`);
|
|
608
|
-
process.exit(1);
|
|
609
|
-
}
|
|
610
|
-
let output;
|
|
611
|
-
try {
|
|
612
|
-
output = selectChart(input);
|
|
613
|
-
} catch (error) {
|
|
614
|
-
console.error(`select-chart: ${error.message}`);
|
|
615
|
-
process.exit(1);
|
|
616
|
-
}
|
|
617
|
-
process.stdout.write(`${JSON.stringify(output, null, 2)}\n`);
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
621
|
-
main();
|
|
622
|
-
}
|