@malloy-publisher/skills 0.1.60 → 0.1.61

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.
Files changed (81) hide show
  1. package/package.json +1 -1
  2. package/skills/eval-answer/SKILL.md +1 -1
  3. package/skills/eval-diagnose/SKILL.md +1 -1
  4. package/skills/eval-import/SKILL.md +1 -1
  5. package/skills/eval-improve/SKILL.md +1 -1
  6. package/skills/eval-judge/SKILL.md +1 -1
  7. package/skills/eval-loop/SKILL.md +1 -1
  8. package/skills/eval-report/SKILL.md +1 -1
  9. package/skills/malloy-analysis/SKILL.md +1 -1
  10. package/skills/malloy-analysis-report/SKILL.md +1 -1
  11. package/skills/malloy-charts/SKILL.md +1 -1
  12. package/skills/malloy-classify/SKILL.md +1 -1
  13. package/skills/malloy-compliance-review/SKILL.md +1 -1
  14. package/skills/malloy-dashboards/SKILL.md +1 -1
  15. package/skills/malloy-define/SKILL.md +1 -1
  16. package/skills/malloy-define-agent/SKILL.md +1 -1
  17. package/skills/malloy-discover/SKILL.md +1 -1
  18. package/skills/malloy-document/SKILL.md +1 -1
  19. package/skills/malloy-excel-review/SKILL.md +1 -1
  20. package/skills/malloy-getting-started/SKILL.md +1 -1
  21. package/skills/malloy-gotchas-modeling/SKILL.md +1 -1
  22. package/skills/malloy-html-data-apps/SKILL.md +20 -11
  23. package/skills/malloy-html-data-apps/assets/data-app/app.js +140 -0
  24. package/skills/malloy-html-data-apps/assets/data-app/index.html +20 -0
  25. package/skills/malloy-html-data-apps/assets/data-app/kit/blocks.js +980 -0
  26. package/skills/malloy-html-data-apps/assets/data-app/kit/charts.css +187 -0
  27. package/skills/malloy-html-data-apps/assets/data-app/kit/charts.js +1903 -0
  28. package/skills/malloy-html-data-apps/assets/data-app/kit/controls.js +179 -0
  29. package/skills/malloy-html-data-apps/assets/data-app/kit/core.js +205 -0
  30. package/skills/malloy-html-data-apps/assets/data-app/kit/draw.js +259 -0
  31. package/skills/malloy-html-data-apps/assets/data-app/kit/fonts/archivo.css +2 -0
  32. package/skills/malloy-html-data-apps/assets/data-app/kit/fonts/fraunces.css +2 -0
  33. package/skills/malloy-html-data-apps/assets/data-app/kit/fonts/source-serif-4.css +2 -0
  34. package/skills/malloy-html-data-apps/assets/data-app/kit/fonts.css +2 -0
  35. package/skills/malloy-html-data-apps/assets/data-app/kit/format.js +100 -0
  36. package/skills/malloy-html-data-apps/assets/data-app/kit/kit.css +404 -0
  37. package/skills/malloy-html-data-apps/assets/data-app/kit/kit.js +19 -0
  38. package/skills/malloy-html-data-apps/assets/data-app/kit/period.js +185 -0
  39. package/skills/malloy-html-data-apps/assets/data-app/kit/shell.js +260 -0
  40. package/skills/malloy-html-data-apps/assets/data-app/kit/state.js +339 -0
  41. package/skills/malloy-html-data-apps/assets/data-app/kit/store.js +54 -0
  42. package/skills/malloy-html-data-apps/assets/data-app/kit/themes.css +1255 -0
  43. package/skills/malloy-html-data-apps/assets/data-app/kit/vendor/LICENSE-d3.txt +13 -0
  44. package/skills/malloy-html-data-apps/assets/data-app/kit/vendor/LICENSE-topojson-client.txt +13 -0
  45. package/skills/malloy-html-data-apps/assets/data-app/kit/vendor/d3.min.js +2 -0
  46. package/skills/malloy-html-data-apps/assets/data-app/kit/vendor/fonts/LICENSE-archivo.txt +93 -0
  47. package/skills/malloy-html-data-apps/assets/data-app/kit/vendor/fonts/LICENSE-fraunces.txt +93 -0
  48. package/skills/malloy-html-data-apps/assets/data-app/kit/vendor/fonts/LICENSE-geist-mono.txt +93 -0
  49. package/skills/malloy-html-data-apps/assets/data-app/kit/vendor/fonts/LICENSE-geist.txt +93 -0
  50. package/skills/malloy-html-data-apps/assets/data-app/kit/vendor/fonts/LICENSE-source-serif-4.txt +93 -0
  51. package/skills/malloy-html-data-apps/assets/data-app/kit/vendor/topojson-client.min.js +2 -0
  52. package/skills/malloy-html-data-apps/reference/app-frame.md +282 -0
  53. package/skills/malloy-html-data-apps/reference/archetypes.md +2 -0
  54. package/skills/malloy-html-data-apps/reference/charts.md +143 -0
  55. package/skills/malloy-html-data-apps/reference/data-app-design.md +188 -0
  56. package/skills/malloy-html-data-apps/reference/design.md +5 -3
  57. package/skills/malloy-html-data-apps/reference/embedding.md +22 -2
  58. package/skills/malloy-html-data-apps/reference/lazy-load.md +12 -1
  59. package/skills/malloy-html-data-apps/reference/maps.md +84 -0
  60. package/skills/malloy-html-data-apps/reference/performance.md +2 -0
  61. package/skills/malloy-html-data-apps/reference/runtime.md +17 -2
  62. package/skills/malloy-html-data-apps/reference/token-contract.md +2 -2
  63. package/skills/malloy-html-data-apps/reference/verification-harness.md +14 -1
  64. package/skills/malloy-html-data-apps/reference/visual-craft.md +3 -3
  65. package/skills/malloy-html-data-apps/scripts/themes.py +269 -0
  66. package/skills/malloy-html-data-apps/scripts/themes_test.py +51 -0
  67. package/skills/malloy-lookml-review/SKILL.md +1 -1
  68. package/skills/malloy-materialization/SKILL.md +1 -1
  69. package/skills/malloy-materialization/reference/refresh.md +1 -1
  70. package/skills/malloy-model/SKILL.md +1 -1
  71. package/skills/malloy-model-as-you-go/SKILL.md +1 -1
  72. package/skills/malloy-modeling/SKILL.md +1 -1
  73. package/skills/malloy-notebooks/SKILL.md +1 -1
  74. package/skills/malloy-phrase-detection/SKILL.md +1 -1
  75. package/skills/malloy-powerbi-review/SKILL.md +1 -1
  76. package/skills/malloy-publish/SKILL.md +1 -1
  77. package/skills/malloy-queries/SKILL.md +1 -1
  78. package/skills/malloy-reports/SKILL.md +1 -1
  79. package/skills/malloy-review/SKILL.md +1 -1
  80. package/skills/malloy-run-agent/SKILL.md +1 -1
  81. package/skills/malloy-source-unreachable/SKILL.md +1 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@malloy-publisher/skills",
3
3
  "description": "Agent skills for Malloy and the Malloy Publisher",
4
- "version": "0.1.60",
4
+ "version": "0.1.61",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: eval-answer
3
3
  description: 'Score one analytical answer against a verified golden, and score which of the entities the golden depends on retrieval delivered to the answerer. Run the contamination checklist, re-execute the submitted query yourself, then spawn a judge subagent per skill:eval-judge. Append attempt, tool_call, score, and retrieval_score events to the file ledger (reference/ledger-schema.md). Never explain the failure (eval-diagnose) or edit the model (eval-improve). Use when asked whether an answer was correct, to score a run, or to baseline a model.'
4
- version: 0.1.60
4
+ version: 0.1.61
5
5
  ---
6
6
 
7
7
  # Evaluate One Answer
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: eval-diagnose
3
3
  description: 'Diagnose why a scored answer failed and who owns the fix, then cluster the failures by shared root cause. Walk dataset, agent-call, get_context/model, get_context/retrieval, construction, then model-definition. Append issue events to the file ledger, linked by traceId, one per cluster. Use after eval-answer, when triaging a run, or before changing a model. Does not edit the model (eval-improve).'
4
- version: 0.1.60
4
+ version: 0.1.61
5
5
  ---
6
6
 
7
7
  # Diagnose One Answer
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: eval-import
3
3
  description: 'Turn a list of questions into an eval set, whatever shape it arrived in: a JSONL a customer sent, a CSV, a spreadsheet export, a markdown doc, an email thread, or a pull from production logs. Classify each item by what came WITH the question (a query, a number, prose criteria, or nothing), write cases.jsonl and set.json per reference/case-format.md, keep the file as it arrived, and seal each question so a later edit is detectable. Never marks a value-bearing golden verified and never invents a question. Use when questions arrive from outside and need to become a set, or before the first run against a set nobody here authored.'
4
- version: 0.1.60
4
+ version: 0.1.61
5
5
  ---
6
6
 
7
7
  # Import questions into an eval set
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: eval-improve
3
3
  description: 'Make the smallest safe edit that closes a diagnosed gap the model repo owns: a Malloy model edit, or a package skill under skills/. Every factual claim carries a probe receipt. Use after eval-diagnose, or when asked to fix a model so an agent can discover the right answer. Never accepts its own edit; the acceptance check belongs to eval-loop. Does not decide whether an answer was wrong (eval-answer) or why (eval-diagnose).'
4
- version: 0.1.60
4
+ version: 0.1.61
5
5
  ---
6
6
 
7
7
  # Improve the Model
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: eval-judge
3
3
  description: 'Decide whether ONE answer matches its golden, and say whether you believe the golden. Read this before emitting any verdict. Covers containment, column pairing, near_match, refusals, and the gold_status judgement. Use when scoring an attempt in an evaluation run; never to conduct a run (eval-loop), diagnose a failure (eval-diagnose) or edit a model (eval-improve).'
4
- version: 0.1.60
4
+ version: 0.1.61
5
5
  ---
6
6
 
7
7
  # The judge
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: eval-loop
3
3
  description: 'Conduct a local Publisher evaluation loop in five steps: scrape/run, eval, diagnose, improve, checkpoint. You are the conductor: import cases into the file ledger, spawn a blind answerer, then run eval-answer, eval-diagnose, and eval-improve. Persistence is plain files: the set in the model package''s evals/ directory, runs in the set''s workdir; checkpoints are git commits of the model repo. `eval.py` runs each step from the set''s eval.toml. Use to score a model, diagnose failures, improve behind an acceptance check, or roll back a bad direction.'
4
- version: 0.1.60
4
+ version: 0.1.61
5
5
  ---
6
6
 
7
7
  # The Evaluation Loop
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: eval-report
3
3
  description: 'Write the summary a person reads after an evaluation run: what ran, what it scored, which failures were the MODEL and which were the EVAL itself (out of turns, contaminated, unestablished golden, unreadable judge), what was learned, and what to do next. Every claim links to the artifact behind it. Use at the end of any run, before quoting a number to anyone. Never scores an answer (eval-answer) or decides who owns a failure (eval-diagnose).'
4
- version: 0.1.60
4
+ version: 0.1.61
5
5
  ---
6
6
 
7
7
  # Report a Run
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-analysis
3
3
  description: "Read before your first get_context call on any business or data question. The required workflow, not background: which source, which rows, how to verify. Skipping it causes confident wrong answers."
4
- version: 0.1.60
4
+ version: 0.1.61
5
5
  ---
6
6
 
7
7
  <!-- Copyright (c) Credible Data Inc. SPDX-License-Identifier: MIT -->
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-analysis-report
3
3
  description: Combine validated Malloy queries into a report (a linear report, read top to bottom). Use when the user asks to "create a report", "combine these into a report", or wants a persistent multi-query artifact.
4
- version: 0.1.60
4
+ version: 0.1.61
5
5
  ---
6
6
 
7
7
  <!--
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-charts
3
3
  description: Read before choosing a chart or adding a chart annotation. Chart types, tag syntax and scale rules, KPI cards, dashboards, sparklines, and the renderer mistakes that fail silently.
4
- version: 0.1.60
4
+ version: 0.1.61
5
5
  ---
6
6
  <!--
7
7
  Copyright (c) Credible Data Inc.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-classify
3
3
  description: 'Propose #(classification) annotations for a Malloy model from an access policy''s class scheme, backed by aggregate value evidence from the served data, and show them as a diff before writing anything. Use when the user asks to "classify the model", "tag PHI/PII", "label sensitive fields", or adds fields to a package that a policy governs, and before running malloy-compliance-review on a model nobody has classified.'
4
- version: 0.1.60
4
+ version: 0.1.61
5
5
  ---
6
6
 
7
7
  <!--
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-compliance-review
3
3
  description: 'Check a Malloy package and its controls against a written access policy: turn the policy''s prose into a control register, run compliance.py check against a served package (structure, access as each role, and the values themselves), judge what needs a person, and produce a report and a signable attestation. Use when the user asks whether a model "complies with", "satisfies" or "meets" a policy, HIPAA, SOC 2, PCI or the like, asks for a compliance review or attestation, or wants the review in CI.'
4
- version: 0.1.60
4
+ version: 0.1.61
5
5
  ---
6
6
 
7
7
  <!--
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-dashboards
3
3
  description: "Renamed to malloy-reports. A dashboard is now a report with layout=grid: a .malloy file with an ## artifact tag, written at the package root. Load malloy-reports instead when the user asks for a dashboard, a filterable view, or drill-through between views."
4
- version: 0.1.60
4
+ version: 0.1.61
5
5
  ---
6
6
 
7
7
  <!--
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-define
3
3
  description: Propose scope, a source plan and field definitions for a Malloy model. Which tables and questions, which sources at what grain, then renames, dimensions and measures, each backed by querying data.
4
- version: 0.1.60
4
+ version: 0.1.61
5
5
  ---
6
6
  <!--
7
7
  Copyright (c) Credible Data Inc.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-define-agent
3
3
  description: Define a package agent - a named brief, with its own skills, optional schedules and a run budget, declared in a package's publisher.json. Use when the user asks to create, add, change or fix an agent in a package, or wants a recurring or unattended job. Not for adopting an agent that already exists (that is malloy-run-agent), and not for a one-off question, which you just answer.
4
- version: 0.1.60
4
+ version: 0.1.61
5
5
  ---
6
6
  <!--
7
7
  Copyright (c) Credible Data Inc.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-discover
3
3
  description: Silent data discovery for Malloy modeling. Used at Step 1 of the modeling workflow. Scans tables, columns, distributions, and relationships without user interaction. The agent builds an internal picture before presenting anything.
4
- version: 0.1.60
4
+ version: 0.1.61
5
5
  ---
6
6
  <!--
7
7
  Copyright (c) Credible Data Inc.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-document
3
3
  description: 'Add documentation with #(doc) tags to Malloy models so fields and sources are described in plain language. Use when user asks to "add documentation", "add doc tags", "document the model", or wants fields and sources described for natural-language search and discovery. For runtime filters, declare given: parameters (see the malloy-model skill); #(filter) is deprecated. Filters are a runtime/modeling construct (governance, latency, correctness), not a documentation tag.'
4
- version: 0.1.60
4
+ version: 0.1.61
5
5
  ---
6
6
 
7
7
  <!--
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-excel-review
3
3
  description: Move an Excel workbook (.xlsx or .xlsm) onto Malloy - recover the model hiding in its cells, translate its formulas and pivots, and prove the numbers match against the values the file already stores. Use when a workbook is present, when a user wants to migrate or switch off a spreadsheet, and whenever a specific formula has to become Malloy - SUMIFS, COUNTIF, SUMPRODUCT, VLOOKUP, XLOOKUP, INDEX/MATCH, pivot tables, assumption cells, roll-forwards, circular references, Monte Carlo, or a Power Pivot model. Carries worked recipes, each labelled executed or semantics-cited in place, and states what each port costs. Works with or without a database connection.
4
- version: 0.1.60
4
+ version: 0.1.61
5
5
  ---
6
6
  <!--
7
7
  Copyright (c) Credible Data Inc.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-getting-started
3
3
  description: First steps for using a Malloy Publisher deployment through its MCP tools. Use when connecting to Publisher for the first time, when you do not yet know the available environments, packages, or models, or when a user asks what data they can explore. Also use for "malloy help" or which Malloy skill to read. Covers verifying the server, discovering data with get_context, and running a first grounded query.
4
- version: 0.1.60
4
+ version: 0.1.61
5
5
  ---
6
6
  <!--
7
7
  Copyright (c) Credible Data Inc.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-gotchas-modeling
3
3
  description: Malloy modeling mistakes and compile-error fixes. Read before writing sources, dimensions, measures or joins, and when a .malloy file will not compile. Reserved words, NULLs, dates, field access.
4
- version: 0.1.60
4
+ version: 0.1.61
5
5
  ---
6
6
  <!--
7
7
  Copyright (c) Credible Data Inc.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: malloy-html-data-apps
3
3
  description: "Build or modify an in-package HTML data app for a Malloy Publisher package (a public/ directory the package serves): design it, write its Publisher.query code, embed it. Hand-authored, no build step."
4
- version: 0.1.60
4
+ version: 0.1.61
5
5
  ---
6
6
  <!--
7
7
  Copyright (c) Credible Data Inc.
@@ -16,12 +16,17 @@ SPDX-License-Identifier: MIT
16
16
 
17
17
  | The user wants | Use |
18
18
  |---|---|
19
- | A hand-authored HTML/JS dashboard, no toolchain | this skill (an HTML data app) |
19
+ | A dashboard, a notebook, a report or a data story | a Malloy report (`<slug>.malloy` at the package root, `layout=grid` for a dashboard, `layout=linear` for a story; the `malloy-reports` skill) |
20
+ | An app or a page of its own: several pages a reader moves between, a page for each thing they open, its own design, HTML and JavaScript with no toolchain | this skill (an HTML data app) |
20
21
  | A React app with managed components | the Publisher React SDK (out of scope here) |
21
- | An analyst notebook or dashboard with charts | a Malloy report (`<slug>.malloy` at the package root, `layout=linear` or `layout=grid`; the `malloy-reports` skill) |
22
22
  | Point-and-click exploration, no code | the Publisher Explorer |
23
23
 
24
- Pick an HTML data app when the user wants full control of the markup and only plain web files.
24
+ **A dashboard and a data app are different things in Publisher.** A dashboard is a report: Malloy and layout tags,
25
+ no code, filters drawn from givens. A data app is a page you write in `public/`. When the user asks for a
26
+ dashboard, build a report. Build a data app when they ask for an app or a page, or when what they want is beyond a
27
+ report: pages that link to a page per entity, a chart form the renderer does not have, a design of its own. When you
28
+ build a data app for a request that said "dashboard", say in one line that it is a data app and why.
29
+ `docs/choosing-a-surface.md` has the full comparison.
25
30
 
26
31
  ## Package anatomy
27
32
 
@@ -43,11 +48,11 @@ Only `public/` is reachable over the web, at `/environments/<env>/packages/<pkg>
43
48
 
44
49
  The agent orchestrates these. Each query and chart step hands off to a focused skill.
45
50
 
46
- 1. DESIGN IT FIRST. Read `reference/design.md`: who opens it, the decision it serves, the archetype, the form each tile takes, and the depth plan. Skipping this is what produces an app that enumerates the model - a KPI row and a chart grid, whatever the domain - instead of one that answers a question. Hand the brief to the user before scaffolding.
51
+ 1. DESIGN IT FIRST. Read `reference/data-app-design.md`, then `reference/design.md`: who opens it, the subject that leads, the archetype, the entities a reader opens one at a time, the pages and the paths between them. Skipping this is what produces an app that enumerates the model - a KPI row and a chart grid, whatever the domain - instead of one that answers a question. Decide, do not stop to ask: write the plan at the top of `app.js` and in your hand-over, where the user can correct it in one reply.
47
52
  2. READ THE MODEL. Get the model's real source and view names, through your environment's context tool if it has one, or by opening the `.malloy` file directly. Never guess field or view names.
48
- 3. SCAFFOLD the package (template below).
53
+ 3. SCAFFOLD the package from this skill's `assets/data-app/`: the data app kit (blocks for the subject, ranked lists, shares, lines over time, tables, grids, watchlists and entity pages, drawn to one design) and a worked example app. `reference/app-frame.md` says what to copy and how to write the config and pages. Only when `assets/` is not on disk because the skill reached you only as text, use the minimal scaffold below, to the same design.
49
54
  4. WRITE THE QUERIES. Read `reference/runtime.md`. Validate each before pasting it into the page, using whatever query tool your environment provides or a running Publisher (see `reference/runtime.md`). Malloy syntax questions go to `skill:malloy-queries`.
50
- 5. CHOOSE CHARTS with `skill:malloy-charts` when rendering through `<malloy-render>`; otherwise it is your own chart library drawing the returned rows. Vendor any chart library into `public/` and load it locally, not from a CDN. Two reasons: embedded author JavaScript runs with the viewing user's data authority, and a blocked CDN (agent sandboxes and many corporate networks block them) is easy to miss, because the script never runs and the charts come up empty. The `storefront` example ships its chart library in `public/vendor/` and loads it from `public/index.html` as `./vendor/chart.umd.js`. Copy its vendoring, not its loading (it uses a plain `<script>`, which the next sentences rule out), and resolve the path against the page's own directory: a page in a subdirectory (`public/reports/index.html`) needs `../vendor/chart.umd.js`. A wrong relative path 404s and leaves the charts blank, which is the failure you are trying to avoid. Load it off the critical path (`<link rel="preload">`, then injected on the first chart), not as a plain `<script>` ahead of the app: it is usually most of the page's weight and would hold every query until it has parsed (`reference/performance.md`).
55
+ 5. CHOOSE CHARTS with `skill:malloy-charts` when rendering through `<malloy-render>`; otherwise it is your own chart library drawing the returned rows. Vendor any chart library into `public/` and load it locally, not from a CDN. Two reasons: embedded author JavaScript runs with the viewing user's data authority, and a blocked CDN (agent sandboxes and many corporate networks block them) is easy to miss, because the script never runs and the charts come up empty. The `storefront` example ships its chart library in `public/vendor/` and loads it from `public/index.html` as `./vendor/chart.umd.js`. Copy its vendoring, not its loading (it uses a plain `<script>`, which the next sentences rule out), and resolve the path against the page's own directory: a page in a subdirectory (`public/reports/index.html`) needs `../vendor/chart.umd.js`. A wrong relative path 404s and leaves the charts blank, which is the failure you are trying to avoid. Load it off the critical path (`<link rel="preload">`, then injected on the first chart), not as a plain `<script>` ahead of the app: it is usually most of the page's weight and would hold every query until it has parsed (`reference/performance.md`). With the kit from step 3, the chart library is d3 inside the kit, which it loads beside its first queries; the kit's blocks draw the common forms and `charts.js` the rest (`reference/charts.md`, maps in `reference/maps.md`).
51
56
  6. EMBED (optional). Read `reference/embedding.md`.
52
57
  7. PREVIEW with the local authoring loop (below).
53
58
  8. VERIFY before you call it done (see "What 'done' means" below). This step is not optional.
@@ -65,12 +70,16 @@ A data app you can defend has all of these. Build to this list, not to the scaff
65
70
  - **Every tile handles loading, empty, and error on its own.** One failing query must not blank the page. (`reference/runtime.md`.)
66
71
  - **Defensible numbers.** Missing ≠ zero (omit the point, don't plot a fake 0); show the latest non-null value for "current"; guard division with `nullif`; convert units explicitly. (`reference/runtime.md`.)
67
72
  - **Visible assumptions.** When you assume something (two sources joined by month, an in-month proxy that differs from a certified definition) or a metric is incomplete, say so *in the app*: a caption, a footnote, a placeholder card with the reason. The non-technical user cannot see your reasoning; bury a caveat and you have misled them. Don't silently drop a metric you couldn't model. Show a placeholder that names what's missing and why.
73
+ - **Several pages, with paths between them.** Never one long page. A first page that answers the first question, a page per area the reader works in, and a page per entity, reached by clicking it anywhere it appears, at least two levels deep for the main entity (`reference/data-app-design.md`).
74
+ - **Every chart does something when clicked, and every section explains itself.** A click opens an entity's page, filters the app, or zooms the period; "How it's made" says what the section shows, what it covers, what each number means and the query. The kit's blocks do both; a block of your own must too.
68
75
  - **Built to the design brief, not to the model's shape.** The app matches the archetype, forms, and depth plan from step 1 (`reference/design.md`), carries a real token contract (surfaces, text ramp, semantic colors, a categorical chart palette) that the chart code reads at runtime rather than hardcoding, and puts visible weight on the two or three numbers that lead. A uniform grid of same-size cards, or a tile per view, means the brief was skipped.
76
+ - **No sentence is typed.** A finding, a verdict, a count or a superlative on the page comes from the rows, and a claim the rows do not support is left out. No number goes in a static caption, sub-line or legend, where the next refresh would leave it wrong. Each finding is also a sentence, for readers who cannot see the chart. A change is coloured by what it means to the reader (a falling price is good for a buyer), not by its direction.
77
+ - **Colours from the kit.** The kit's paper, ink, accent and good and bad colours are checked for contrast in both modes. Choose the accent from the subject; never put a hex in a chart. A colour an app adds (a party's colour) must hold 4.5:1 as text and 3:1 as a mark, in light and dark.
69
78
  - **Vendored libraries.** Chart and helper libraries live in `public/`, loaded locally (step 5). When a package agent builds apps, every file it copies into one (a vendored library for `public/vendor/`, its own components, a template) lives in its skill's `assets/` and is copied from there, never pasted into the skill's Markdown (`skill:malloy-define-agent`).
70
- - **Light, and nothing waits on the chart library.** Pages that draw charts preload the library and load it on first use; a page that draws none never loads it. Trim it to the series types the app draws once it is big enough to matter, and verify a trimmed build by reading pixels, because a missing type draws an empty box without an error. One query text per resource, so any cache or prefetch actually hits. (`reference/performance.md`, which also has two opt-in recipes, answering from the last visit and starting a drawer's queries on intent, each with the conditions it needs.)
71
- - **Holds still while it loads.** Script-filled blocks reserve their final size in the HTML, skeletons are sized from what is coming, settled tile heights are remembered for the next visit, and a tile re-running for a new filter keeps its last answer dimmed instead of collapsing. Target: layout shift under 0.1 on a first visit and 0 on a repeat, embedded as well as standalone. (`reference/performance.md`.)
72
- - **Works embedded.** Inside an auto-sized frame there is no viewport: the frame never scrolls, nothing extends past the content, and anything that floats (a drawer, a tray) is placed over the slice of the page the reader can see, keeps its scroll to itself, and returns the reader exactly where they were. A drawer built the standalone way opens at the top of the document and drags the host page up to meet it. (`reference/embedding.md`, `reference/overlays.md`.)
73
- - **Lazy-load below the fold, once the page has more than about eight query-backed tiles.** ("Many" is not decidable; that is the threshold.) Tiles sitting below the fold is *why* the technique works, not a second trigger for it - almost every real data app scrolls, so reading it as one makes the rule "always" and contradicts the count. Under that threshold, firing every tile at once is cheaper than the machinery. Don't fire every tile's query on load. `reference/lazy-load.md` is the recipe: `IntersectionObserver` (rootMargin ~240px) + a small concurrency cap + reserve each tile's height so lazy tiles don't reflow. Includes the verification trap - on a short/tall-default viewport all tiles intersect at once and you get a false "everything deferred" pass, so test on a deliberately small viewport.
79
+ - **Light, and nothing waits on the chart library.** Pages that draw charts preload the library and load it on first use; a page that draws none never loads it. The kit loads d3 once, beside its first queries, on every page. Trim a library of your own to the series types the app draws once it is big enough to matter (not the kit, which is copied whole so a fix can be copied over it), and verify a trimmed build by reading pixels, because a missing type draws an empty box without an error. One query text per resource, so any cache or prefetch actually hits. (`reference/performance.md`, which also has two opt-in recipes, answering from the last visit and starting a drawer's queries on intent, each with the conditions it needs.)
80
+ - **Holds still while it loads.** Script-filled blocks reserve their final size in the HTML, skeletons are sized from what is coming, settled tile heights are remembered for the next visit (the kit reserves each block's drawn height instead), and a tile re-running for a new filter keeps its last answer dimmed instead of collapsing. Target: layout shift under 0.1 on a first visit and 0 on a repeat, embedded as well as standalone. (`reference/performance.md`.)
81
+ - **Works embedded.** Inside an auto-sized frame there is no viewport: the frame never scrolls, nothing extends past the content, and anything that floats (a drawer, a tray) is placed over the slice of the page the reader can see, keeps its scroll to itself, and returns the reader exactly where they were. A drawer built the standalone way opens at the top of the document and drags the host page up to meet it. (`reference/embedding.md`, `reference/overlays.md`.) The kit avoids the problem: each page and entity is a page at its own address, with nothing that floats but its menus.
82
+ - **Lazy-load below the fold, once the page has more than about eight query-backed tiles.** ("Many" is not decidable; that is the threshold.) Tiles sitting below the fold is *why* the technique works, not a second trigger for it - almost every real data app scrolls, so reading it as one makes the rule "always" and contradicts the count. Under that threshold, firing every tile at once is cheaper than the machinery. Don't fire every tile's query on load. The kit's blocks already do this. `reference/lazy-load.md` is the recipe: `IntersectionObserver` (rootMargin ~240px) + a small concurrency cap + reserve each tile's height so lazy tiles don't reflow. Includes the verification trap - on a short/tall-default viewport all tiles intersect at once and you get a false "everything deferred" pass, so test on a deliberately small viewport.
74
83
 
75
84
  ### Verify before you call it done
76
85
 
@@ -0,0 +1,140 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+ //
4
+ // ADAPT: a worked data app on the kit, over an online store's orders: the materialized `sales` source in reference/app-frame.md, "Make it fast". Keep its shape,
5
+ // replace everything in it: the brief, the config, the pages. reference/app-frame.md is the kit's reference and
6
+ // reference/data-app-design.md says what each page and block is for.
7
+ //
8
+ // Sales performance: how the store is selling, for whoever runs it, opened weekly.
9
+ // Brief: the reader decides where to push (categories, brands, channels) and checks whether the latest weeks beat
10
+ // the weeks before. Net revenue leads: the model's total_sales counts cancelled and returned items too.
11
+ // Pages: Overview (the subject and where it comes from), Products (categories and items), Customers (who buys and
12
+ // how they arrived); a page for each category, brand and customer, reached from any list that names one.
13
+ import { dataApp, subject, rank, share, trend, table, entityHead, pageHead, blocks, S } from './kit/kit.js'
14
+
15
+ const HEAD = ['net_sales', 'order_count', 'aov', 'user_count', 'margin_pct', 'return_rate']
16
+ const product = (s) => S.run('{ group_by: product is inventory_items.product_name, brand is inventory_items.product_brand, category is inventory_items.product_category; aggregate: net_sales, items, margin_pct, return_rate; order_by: net_sales desc; limit: 300 }', s)
17
+ const productCols = [
18
+ { key: 'product', label: 'Product' }, { key: 'brand', label: 'Brand' }, { key: 'category', label: 'Category' },
19
+ { key: 'net_sales', metric: 'net_sales', bar: true }, { key: 'items', metric: 'items' },
20
+ { key: 'margin_pct', metric: 'margin_pct' }, { key: 'return_rate', metric: 'return_rate' },
21
+ ]
22
+
23
+ dataApp({
24
+ title: 'Sales performance',
25
+ sub: 'Online store',
26
+ theme: 'bloom',
27
+ model: 'sales.malloy',
28
+ source: 'sales',
29
+ date: { field: 'order_date', label: 'Order date' },
30
+ recordNoun: 'order lines',
31
+ metrics: {
32
+ net_sales: { label: 'Net revenue', format: 'usd', good: 'up' },
33
+ order_count: { label: 'Orders', format: 'number', good: 'up' },
34
+ aov: { label: 'Average order', format: 'usd', good: 'up' },
35
+ user_count: { label: 'Customers', format: 'number', good: 'up' },
36
+ margin_pct: { label: 'Gross margin', format: 'percent', good: 'up' },
37
+ return_rate: { label: 'Return rate', format: 'percent', good: 'down' },
38
+ items: { label: 'Items sold', format: 'number', good: 'up' },
39
+ },
40
+ filters: [
41
+ { key: 'department', field: 'department', label: 'Department', plural: 'departments' },
42
+ { key: 'channel', field: 'channel', label: 'Channel', plural: 'channels' },
43
+ { key: 'country', field: 'country', label: 'Country', plural: 'countries' },
44
+ { key: 'state', field: 'state', label: 'State or region', plural: 'states and regions' },
45
+ { key: 'status', field: 'status', label: 'Order status', plural: 'statuses' },
46
+ ],
47
+ entities: {
48
+ category: { field: 'category', label: 'Category', plural: 'categories' },
49
+ brand: { field: 'brand', label: 'Brand', plural: 'brands' },
50
+ customer: { field: 'user_id', label: 'Customer', plural: 'customers', nameField: 'users.full_name' },
51
+ },
52
+ defaults: { period: 'last_91', compare: 'previous' },
53
+ pages: [
54
+ { id: 'overview', title: 'Overview', render: overview },
55
+ { id: 'products', title: 'Products', lists: 'category', render: products },
56
+ { id: 'customers', title: 'Customers', lists: 'customer', render: customers },
57
+ { id: 'category', title: 'Category', entity: 'category', render: category },
58
+ { id: 'brand', title: 'Brand', entity: 'brand', render: brand },
59
+ { id: 'customer', title: 'Customer', entity: 'customer', render: customer },
60
+ ],
61
+ footer: 'Order lines from the store’s order system. Net revenue leaves out cancelled and returned items.',
62
+ })
63
+
64
+ function overview() {
65
+ return blocks(
66
+ subject({ metrics: HEAD }),
67
+ rank({ entity: 'category', metric: 'net_sales', top: 10 }),
68
+ share({ field: 'channel', metric: 'net_sales', kicker: 'Net revenue by channel · how customers first found the store' }),
69
+ rank({ entity: 'brand', metric: 'net_sales', top: 10 }),
70
+ rank({ field: 'state', metric: 'net_sales', top: 10, kicker: 'Net revenue by state or region' }),
71
+ trend({ metric: 'net_sales', by: 'category', top: 5, kicker: 'Net revenue over time, the five largest categories' }),
72
+ )
73
+ }
74
+
75
+ function products() {
76
+ return [
77
+ pageHead('Products', 'Which categories and items earn the most, at what margin, and which come back.'),
78
+ blocks(
79
+ rank({ entity: 'category', metric: 'net_sales', top: 26, extra: ['margin_pct'], span: 12, kicker: 'Every category by net revenue' }),
80
+ rank({ entity: 'category', metric: 'margin_pct', top: 10, kicker: 'Gross margin by category, highest first' }),
81
+ rank({ entity: 'category', metric: 'return_rate', top: 10, kicker: 'Return rate by category, highest first' }),
82
+ table({ kicker: 'Top products', query: product, columns: productCols, sort: { key: 'net_sales', desc: true } }),
83
+ ),
84
+ ]
85
+ }
86
+
87
+ function customers() {
88
+ return [
89
+ pageHead('Customers', 'Who buys, how they found the store, and how much they are worth over time.'),
90
+ blocks(
91
+ subject({ metrics: ['user_count', 'aov', 'order_count'], layout: 'board' }),
92
+ share({ field: 'channel', metric: 'user_count', kicker: 'Customers by channel' }),
93
+ rank({ field: 'user_order_facts.spend_category', metric: 'net_sales', top: 4, kicker: 'Net revenue by lifetime spend', headline: (rows) => [{ b: rows[0].spend_category }, ` customers bring the most net revenue; the four tiers are set by what each customer has spent, all time.`] }),
94
+ table({
95
+ kicker: 'Top customers in the period', open: { entity: 'customer', key: 'user_id' }, sort: { key: 'net_sales', desc: true },
96
+ query: (s) => S.run('{ group_by: user_id, customer is users.full_name, state is users.state, channel is users.traffic_source; aggregate: net_sales, order_count, aov; order_by: net_sales desc; limit: 200 }', s),
97
+ columns: [{ key: 'customer', label: 'Customer' }, { key: 'state', label: 'State' }, { key: 'channel', label: 'Channel' }, { key: 'net_sales', metric: 'net_sales', bar: true }, { key: 'order_count', metric: 'order_count' }, { key: 'aov', metric: 'aov' }],
98
+ }),
99
+ ),
100
+ ]
101
+ }
102
+
103
+ function category() {
104
+ return [
105
+ entityHead({ metric: 'net_sales' }),
106
+ blocks(
107
+ subject({ metrics: ['net_sales', 'items', 'margin_pct', 'return_rate'] }),
108
+ rank({ entity: 'brand', metric: 'net_sales', top: 10, kicker: 'Its brands by net revenue' }),
109
+ share({ field: 'department', metric: 'net_sales', kicker: 'Net revenue by department' }),
110
+ table({ kicker: 'Its products', query: product, columns: productCols.filter((c) => c.key !== 'category'), sort: { key: 'net_sales', desc: true } }),
111
+ ),
112
+ ]
113
+ }
114
+
115
+ function brand() {
116
+ return [
117
+ entityHead({ metric: 'net_sales' }),
118
+ blocks(
119
+ subject({ metrics: ['net_sales', 'items', 'margin_pct', 'return_rate'] }),
120
+ rank({ entity: 'category', metric: 'net_sales', top: 10, kicker: 'Its categories by net revenue' }),
121
+ share({ field: 'channel', metric: 'net_sales', kicker: 'Its buyers by channel' }),
122
+ table({ kicker: 'Its products', query: product, columns: productCols.filter((c) => c.key !== 'brand'), sort: { key: 'net_sales', desc: true } }),
123
+ ),
124
+ ]
125
+ }
126
+
127
+ function customer() {
128
+ return [
129
+ entityHead({ metric: 'net_sales' }),
130
+ blocks(
131
+ rank({ entity: 'category', metric: 'net_sales', top: 8, kicker: 'What they buy', headline: null }),
132
+ rank({ entity: 'brand', metric: 'net_sales', top: 8, kicker: 'Their brands', headline: null }),
133
+ table({
134
+ kicker: 'Their order lines in the period', sort: { key: 'created_at', desc: true },
135
+ query: (s) => S.run('{ select: created_at, order_id, product is inventory_items.product_name, category is inventory_items.product_category, status, sale_price; order_by: created_at desc; limit: 500 }', s),
136
+ columns: [{ key: 'created_at', label: 'Ordered', format: (v) => String(v).slice(0, 10) }, { key: 'product', label: 'Product' }, { key: 'category', label: 'Category' }, { key: 'status', label: 'Status' }, { key: 'sale_price', label: 'Price', format: 'usd' }],
137
+ }),
138
+ ),
139
+ ]
140
+ }
@@ -0,0 +1,20 @@
1
+ <!doctype html>
2
+ <!-- Copyright (c) Credible Data Inc. SPDX-License-Identifier: MIT -->
3
+ <html lang="en">
4
+ <head>
5
+ <meta charset="utf-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1">
7
+ <title>Sales performance</title> <!-- ADAPT: the app's name -->
8
+ <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Crect width='16' height='16' rx='4' fill='%2321201c'/%3E%3Cpath d='M4 11l3-3 2 2 3-4' stroke='%23f8f7f4' stroke-width='1.6' fill='none'/%3E%3C/svg%3E">
9
+ <link rel="stylesheet" href="./kit/fonts.css">
10
+ <link rel="stylesheet" href="./kit/kit.css">
11
+ <link rel="stylesheet" href="./kit/themes.css">
12
+ <link rel="stylesheet" href="./kit/charts.css">
13
+ <link rel="preload" href="./kit/vendor/d3.min.js" as="script">
14
+ </head>
15
+ <body>
16
+ <div id="app"></div>
17
+ <script src="/sdk/publisher.js"></script>
18
+ <script type="module" src="./app.js"></script>
19
+ </body>
20
+ </html>