farseer-cli 1.24.0 → 1.26.0

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 (75) hide show
  1. package/README.md +1 -1
  2. package/dist/commands/dashboards.js +2 -0
  3. package/dist/commands/dashboards.js.map +1 -1
  4. package/dist/commands/login.js +18 -7
  5. package/dist/commands/login.js.map +1 -1
  6. package/dist/commands/logout.js +28 -12
  7. package/dist/commands/logout.js.map +1 -1
  8. package/dist/commands/run.js +2 -3
  9. package/dist/commands/run.js.map +1 -1
  10. package/dist/commands/sheets.js +5 -3
  11. package/dist/commands/sheets.js.map +1 -1
  12. package/dist/commands/whoami.js +12 -5
  13. package/dist/commands/whoami.js.map +1 -1
  14. package/dist/mcp/tools/authTools.js +2 -1
  15. package/dist/mcp/tools/authTools.js.map +1 -1
  16. package/dist/mcp/tools/dashboardTools.js +3 -1
  17. package/dist/mcp/tools/dashboardTools.js.map +1 -1
  18. package/dist/mcp/tools/runTools.js +2 -3
  19. package/dist/mcp/tools/runTools.js.map +1 -1
  20. package/dist/mcp/utils/helpers.js +8 -6
  21. package/dist/mcp/utils/helpers.js.map +2 -2
  22. package/dist/mcp/utils/session.js +6 -2
  23. package/dist/mcp/utils/session.js.map +1 -1
  24. package/dist/operations/dashboards.js +1 -1
  25. package/dist/operations/dashboards.js.map +1 -1
  26. package/dist/pipeline/generated-reference.json +8 -8
  27. package/dist/services/codefirst/layoutReadback.js +95 -0
  28. package/dist/services/codefirst/layoutReadback.js.map +2 -2
  29. package/dist/services/configService.js +33 -18
  30. package/dist/services/configService.js.map +1 -1
  31. package/dist/services/credentials.js +26 -11
  32. package/dist/services/credentials.js.map +1 -1
  33. package/dist/services/farseerService.js +34 -32
  34. package/dist/services/farseerService.js.map +1 -1
  35. package/dist/services/keycloak.js +44 -0
  36. package/dist/services/keycloak.js.map +6 -0
  37. package/dist/services/preflight.js +1 -2
  38. package/dist/services/preflight.js.map +1 -1
  39. package/dist/services/realms.js +67 -15
  40. package/dist/services/realms.js.map +1 -1
  41. package/dist/utils/serverUrl.js +42 -0
  42. package/dist/utils/serverUrl.js.map +6 -0
  43. package/docs/pipeline-reference.md +13 -3
  44. package/package.json +2 -2
  45. package/skills/farseer-build-model/SKILL.md +1 -1
  46. package/skills/farseer-code-tiles/SKILL.md +153 -0
  47. package/skills/farseer-code-tiles/anti-patterns.md +183 -0
  48. package/skills/farseer-code-tiles/api.md +237 -0
  49. package/skills/farseer-code-tiles/check-tile.mjs +521 -0
  50. package/skills/farseer-code-tiles/design.md +159 -0
  51. package/skills/farseer-code-tiles/echarts-look.md +110 -0
  52. package/skills/farseer-code-tiles/examples/board-deck.js +695 -0
  53. package/skills/farseer-code-tiles/examples/data-checks.js +475 -0
  54. package/skills/farseer-code-tiles/examples/kpi-cards.js +374 -0
  55. package/skills/farseer-code-tiles/examples/map-countries.js +377 -0
  56. package/skills/farseer-code-tiles/examples/month-plan.js +443 -0
  57. package/skills/farseer-code-tiles/examples/new-location.js +581 -0
  58. package/skills/farseer-code-tiles/examples/open-forecast.js +598 -0
  59. package/skills/farseer-code-tiles/examples/pl-sankey.js +402 -0
  60. package/skills/farseer-code-tiles/examples/ranked-bars.js +337 -0
  61. package/skills/farseer-code-tiles/examples/request-form.js +464 -0
  62. package/skills/farseer-code-tiles/farseer-table.md +98 -0
  63. package/skills/farseer-code-tiles/known-mistakes.md +178 -0
  64. package/skills/farseer-code-tiles/maps/europe.geo.json +1 -0
  65. package/skills/farseer-code-tiles/maps/pick-map.mjs +59 -0
  66. package/skills/farseer-code-tiles/maps/world.geo.json +1 -0
  67. package/skills/farseer-dashboards/SKILL.md +3 -2
  68. package/skills/farseer-dashboards/check.md +3 -2
  69. package/skills/farseer-dashboards/measures.md +3 -1
  70. package/skills/farseer-dashboards/reporting-period.md +1 -1
  71. package/skills/farseer-modify-model/SKILL.md +1 -1
  72. package/skills/farseer-modify-model/model-validation-pattern.md +3 -3
  73. package/skills/farseer-optimize-model/SKILL.md +9 -1
  74. package/skills/farseer-pnl/SKILL.md +3 -3
  75. package/skills/pipeline-authoring/SKILL.md +2 -2
@@ -0,0 +1,153 @@
1
+ ---
2
+ name: farseer-code-tiles
3
+ description: How to write a Code tile on a Farseer dashboard, a tile whose JavaScript queries the model and draws what no chart or table tile can (a P&L sankey, a map, a treemap, cards in one colour per company, a form or planner that writes to the model). Covers when a Code tile is the right answer at all, which tile to build first when the user only wants something useful, the code's contract (reading, the filter bar, charts, writing cells and members), the Farseer look on top of the dashboards skill's notation, saving and checking the tile with the CLI, and the mistakes that leave a tile blank. Use when asked for a Code tile, a custom visual, a custom chart type or a custom UI on a dashboard.
4
+ metadata:
5
+ version: "1"
6
+ ---
7
+
8
+ # Code tiles
9
+
10
+ A Code tile is a dashboard tile written in JavaScript. Its code reads numbers from the model through `ctx` and draws them with plain HTML, Farseer's own charts or any echarts chart. It runs in a sandboxed frame with no network, so it can't fetch, load a script or reach Farseer except through `ctx`. Everything it reads or writes, it does as the viewer, with the viewer's own rights. A form in it can write cells and add members after a click; it can't run an App.
11
+
12
+ ## Non-negotiables
13
+
14
+ Every tile, no exceptions. Read these before writing code. `check-tile.mjs` fails the tile on most of them; the rest show only when you look at it.
15
+
16
+ 1. Button text never wraps (`white-space: nowrap`); when the controls don't fit, the layout wraps, never the label.
17
+ 2. Nothing is cut or reaches past the tile's edge at its own width, at 600 px or at 400 px, focus rings included.
18
+ 3. Every chart is drawn by `ctx.charts.farseer` or `ctx.charts.echarts`, never by hand in SVG, canvas or HTML.
19
+ 4. The look is Farseer's: square bars, the tile header style, and every table through `farseerTable()`.
20
+ 5. AC is the AC colour of the `farseer-dashboards` skill: `#323232`, or the company's darkest brand colour when it is dark enough, never red or green, never one copied from an example (section 2, The AC colour).
21
+ 6. Every variable in a formula sits inside `sum()`, so the filter bar reaches it, and every table of numbers is read with `readTable`.
22
+ 7. A write runs only from a click handler, writes exactly the cells the form shows, and the tile says what it wrote or why it couldn't.
23
+ 8. A button and the text beside it always tell the same state: while the form can't run, the button is disabled and the text says what is missing.
24
+ 9. Totals, averages and ratios shown to the reader come from the model, never from adding or dividing cells in the code; the code may only take the difference or ratio of two cells shown side by side (a variance), and a simulation says it is one.
25
+ 10. Every number on the tile follows the dashboard's filter bar, unless the title says it doesn't.
26
+
27
+ Files next to this one:
28
+
29
+ | File | What it answers |
30
+ |---|---|
31
+ | `api.md` | The code's contract: the module, `ctx`, reading and `readTable`, the filter bar, charts, writing, and saving a tile |
32
+ | `design.md` | How a Code tile looks: Farseer's colours and their jobs, which form, composition, text and numbers, interaction, states |
33
+ | `echarts-look.md` | The base echarts option every custom chart starts from, mark specs, and recipes for ranked bars, gauge, map, treemap, sankey, heatmap |
34
+ | `farseer-table.md` | A table in the table tile's exact look, measured from it: the values, the CSS and the `farseerTable` helper |
35
+ | `anti-patterns.md` | What makes a correct tile look like a sketch, each with a fix and a detector |
36
+ | `known-mistakes.md` | Mistakes that leave a tile blank or its numbers wrong, each with a symptom, a fix and a detector |
37
+ | `check-tile.mjs` | The check after saving: the detectors on the code (section 5) |
38
+ | `maps/` | Real country outlines (Natural Earth, public domain) and `pick-map.mjs`, which cuts out the countries a map needs |
39
+ | `examples/` | Working tiles in the Farseer look, each with the base option and its tile size: a P&L sankey, KPI cards against plan, a map of countries, ranked bars, a planner that writes a plan by month, a request form that adds to the budget, a forecast opener that adds a version and copies a company's P&L into it, a new location staffed like another, a board deck, data checks before a month is reported |
40
+
41
+ ## The first tile on a workspace
42
+
43
+ Someone who opens Code tiles for the first time often asks for "something useful" or "show me what this can do". Don't answer with questions. Read the model (section 2), then build the one tile from this list that the model can fill and that no tile on their dashboards already shows, and offer the next two by name in the hand-back:
44
+
45
+ | The model has | Build | From |
46
+ |---|---|---|
47
+ | Actual and a plan version for the P&L | KPI cards against the plan, the period and company in the title | `examples/kpi-cards.js` |
48
+ | A P&L from net sales down to net profit | Where net sales go: the sankey with the chain to net profit beside it | `examples/pl-sankey.js` |
49
+ | Companies in countries | Net sales by country on a map | `examples/map-countries.js` |
50
+ | Regions, products or customers with sales | The ranking with each member's change against plan or last year | `examples/ranked-bars.js` |
51
+ | An input variable people plan in, with departments | A request form that adds to the department's budget, or a month planner for the open forecast months | `examples/request-form.js`, `examples/month-plan.js` |
52
+ | Versions people open every cycle (a forecast from the budget) | A forecast opener: a new version with one company's P&L copied in, changed by a %, read before the click and written in parts cut by size | `examples/open-forecast.js` |
53
+ | Locations, branches or projects with a plan by member | A new member set up like an existing one: added under the same parent, its plan copied from the month it starts | `examples/new-location.js` |
54
+ | A management team that meets monthly | A board deck of the year, live from the plan | `examples/board-deck.js` |
55
+ | A balance sheet, cash and a P&L that must tie out, a month about to be reported | Data checks: each control a difference the model must keep at zero (the balance sheet balances, its result is the P&L's net profit, cash ties out, sales agree, every company is loaded), month by month for the version the filter bar picks | `examples/data-checks.js` |
56
+
57
+ Put it on the dashboard the user is looking at, or on a new one named for what it answers when they have none. It follows that dashboard's filter bar from the first draw, so picking a company or a month changes it at once. Say in two lines what it shows and which filter changes it.
58
+
59
+ **Language.** Every title, label, button, message and footnote on the tile is in the model's language, the one its variable and member names are in, as on the dashboards (the `farseer-dashboards` skill, Language), whatever language the user writes to you in. Month names, units and scenario codes (AC, PL, FC, PY, Δ) follow the same rule. A Croatian question about an English model gets an English tile and a Croatian answer.
60
+
61
+ Writing a Code tile needs the `FEATURE.CODE_TILES` permission. When the CLI refuses with a permission error, say that a super user grants it in Users & groups, and stop there.
62
+
63
+ **A tile with a form is a dashboard build, not a model change.** Saving the tile writes nothing to the model: the code is stored on the dashboard, and its button writes later, when a viewer clicks it, as that viewer and with their permissions. So build a form that adds members or writes cells (an investment form, a forecast opener, a planner) wherever you may build a dashboard, a chat limited to dashboard builds included, and never refuse it as a change you can't make. Where the chat may not change the model, add no members and write no cells yourself while building, and say in the hand-back that the form's write is untested and the user's first click is its test. Everywhere else, test it as `api.md` (Testing a write) says, on a copy or with the user's yes. `check-tile.mjs` doesn't test a form's write: its made-up run types nothing into the fields, so a form that checks them first stops before it writes.
64
+
65
+ ## 1. Is a Code tile the right answer?
66
+
67
+ Tiles come first. A chart, table, single value or sheet tile keeps the IBCS look, the tile's own settings, export and drill, and anyone can change it without code. Build a Code tile only for what no tile has a setting for:
68
+
69
+ - a chart type Farseer has no tile for (sankey, map, treemap, heatmap, radar)
70
+ - one fixed colour per member across several charts, or layouts tiles can't make (cards, a matrix of small charts, a table with bars in its cells)
71
+ - a form or a planner that writes cells or adds members
72
+ - text built from several numbers that a text tile's values can't express
73
+
74
+ Never a pie or donut, a 3D chart, a gauge or a traffic light, as in the `farseer-dashboards` skill: a ratio against its target is a bar against a PL outline, a mix is a ranked comparison. Only when the user insists on a gauge, use the recipe in `echarts-look.md` and say it departs from IBCS.
75
+
76
+ **Beyond one visual.** A Code tile can also hold a board deck (one claim and one figure per slide, back and forward by buttons, arrow keys and dots, speaker notes that fold out: `examples/board-deck.js`), or a what-if simulator whose button saves the assumptions into the model (`design.md` on what a simulation may compute). A deck or a whole page is shown in the tile's focus view, `#/dashboard/{dashboardId}/{tileId}`, which fills the dashboard's area with that one tile; size every type from `element.clientWidth` and `clientHeight` so it grows there. Full screen from inside the frame is refused (the frame has no fullscreen permission), so offer the focus view's link instead.
77
+
78
+ Build a deck by copying `examples/board-deck.js` and changing what it reads, never from scratch: `cp <this skill's folder>/examples/board-deck.js tile.js`, then swap its measures for the model's own (the lead measure, its margin, EBITDA, the main costs, the outlook) and keep the rest. A deck is a cover with the headline figures and their variance, then one slide per result, each a claim built from the numbers ("Net sales are 8% above last year and in line with plan"), the figure and a chart against plan and last year, never a slide that is only a variance number. The example also carries the dots, Farseer's chevrons on Back and Next, the speaker notes and the sizing for the focus view. A deck takes its period from the dashboard's `Year to date` filter and ignores the timeline, so a dashboard that holds a deck has the timeline off (`columns.intervalToolbar.enabled: false` through `farseer dashboards update`, starting from `farseer dashboards show <dashboard> --json`): a timeline that changes nothing on the page only misleads.
79
+
80
+ Data checks start the same way, from a copy of `examples/data-checks.js`: change the checks to the model's own ties (which balance sheet, cash and sales inputs must agree), keep one row per check for the companies the filter bar leaves (not a row per company and check), the month columns, and Farseer's icons with the difference on hover, split by company where the filter bar leaves several. The hover is where the detail lives: no list of exceptions under the grid repeating it.
81
+
82
+ A deck for a board carries the company's brand: its logo, and its colour on the title and the progress dots. Ask the user for the brand colour and the logo, or take them from the client's own Farseer: the colour of their branded dashboards' chart tiles, the tenant's `custom_colors` picks (`GET /api/v3/settings`), an image on one of their text tiles. Look the brand up on the web only when you have web access, and say where each colour came from. The logo goes into the code as a data URI the client gave (the frame has no network); never draw a logo or a wordmark yourself, and with no logo the title slide has none. AC on the slides follows the same rule as on every tile (section 2, The AC colour). A brand colour too light or too bright for AC goes to the logo, the title and the progress dots. Scenarios keep IBCS notation in AC: AC solid, PL outlined, FC hatched, PY its light tint, variances green and red. A slide's claim is its headline (about 26 px semibold) and its one figure is large; the tile rules about one heading style are for tiles, not slides. Lines of very different size (revenue beside EBITDA) never share one value axis on a slide: give each line its own small chart, or the small ones become hairlines. Mark the deck's element with `aria-roledescription="slides"` (the example does), so the check treats it as slides. The title slide already says the result (the two or three headline figures with their variance), since it is what the dashboard shows before anyone opens the deck. No decorative rails or bars on a slide. The last slide is the outlook: the full-year forecast against the plan, or, when the model has no forecast, the full-year plan and how much of it the year to date reached, saying there is no forecast. A slide about a measure the filter bar can't narrow says "whole group" on the slide itself, not only in the notes.
83
+
84
+ If a tile can show it, say so and build the tile instead, with the `farseer-dashboards` skill. If the model lacks the number (a measure, a ratio, a flag), that is a model change and goes through the model's own process, never into the tile's code.
85
+
86
+ ## 2. Read the model first
87
+
88
+ When the workspace has an `ANALYST.md`, its definitions come first: take the measures and versions it names for revenue, bookings, the plan. Find the exact names the code will use. Those are variables (`farseer variables list`), tables and their members (`farseer dimensions members TABLE`), and the versions and periods the dashboard compares (Actual, the plan version, the current forecast, Current year and Prior year in `Reporting period` where the model has one). Evaluate each formula once (`farseer formula eval`) before it goes into code, so a wrong name fails here and not in the tile.
89
+
90
+ Read the dashboard the tile goes on with `farseer dashboards show <dashboard> --json`: its filters are `rows.filters` (which tables and which members are picked). They are the client's: never change a filter it has, its picks or the other tiles. When the saved picks leave the tile empty, the tile says which pick it needs, and so does your hand-back. `farseer dashboards tiles <dashboard>` lists its tiles, and `farseer dashboards show-tile <dashboard> <tileId> --json` shows one. The client's other dashboards (`farseer dashboards list --json`) show which measures, versions and periods the client already reads; use the same ones, so the tile agrees with the tiles beside it. A chart, table or value tile is backed by a sheet (`data.sheet.id`), and `farseer sheets lines <sheet id>` names each line's variable and members. Never guess a measure from a tile's title: read its lines. When two variables look alike (`OPEX Report` and `OPEX Reporting -1`), count which one the client's dashboards read across their tiles and take that one; say in the hand-back which you took and why.
91
+
92
+ Which measure leads, which member is the plan, how costs are signed and which unit to show follow the `farseer-dashboards` skill (Settle and probe before any write), so a Code tile and the tiles beside it show the same number for the same thing.
93
+
94
+ Paths under `/api/v3` in this skill are the few requests the CLI has no command for, sent to the API base your environment gives (`https://<org>.farseer.io/api/v3`) with the header `X-TENANT-ID: <tenant>`. An API key goes in `X-API-KEY`, not as a bearer token. Where the environment gives you no credential, skip that step and say so in your report; never read one from the CLI's config.
95
+
96
+ A variable is split only by the tables in its `tableGids`, but a table can still filter it through the links (foreign keys) of the members it is split by: a country filters net sales through the cost centres that belong to it. So a missing table in `tableGids` doesn't mean the split is missing. Evaluate a sum that names one member (`sum("EBITDA", "Country">"Croatia")`) and compare it with the total before saying the model can't split it.
97
+
98
+ Keep to the measure the client already reads for the thing asked (the one on their other dashboards). If it can't be split the way the request asks, say so and show the split it has. Never switch to another measure because that one splits: its total differs from every other tile on the page, and the reader can't tell why. When you evaluate a measure to see what it holds, name the version and the period as the tile will, or the number you judge it by is several years added up.
99
+
100
+ **The AC colour.** A Code tile draws in the same AC as the dashboard's other tiles, by the rule of the `farseer-dashboards` skill (The AC colour): `#323232`, or the company's darkest brand colour when it is dark enough to read as the darkest thing on the page (relative luminance under about 0.06: dark purple, navy and dark brown pass, bright blue, orange and teal don't). Never red or green, those are the variance colours. The brand colour comes from the user, or from the client's own Farseer (the tenant's `default_palette` and `custom_colors` in `GET /api/v3/settings`). Write AC and AC light (the PY tint) into the code as the two constants at the top of the base block. Everything else (the ramp, the light tints) is derived from AC by the block's `tint()`, so nothing else is copied. `check-tile.mjs` fails an AC that is too light, red or green.
101
+
102
+ Write formulas and tables with names (`sum("Net sales", "Versions">"Actual")`, `rows: { table: 'Entity' }`), never gids. Names travel with the dashboard to another tenant that has the same model, as the standard dashboards do.
103
+
104
+ ## 3. Agree what it shows
105
+
106
+ Ask at most three questions, and only where the answer changes the tile. Ask which numbers and comparisons (AC against PL, PY or FC), which members as rows, and what a button does. Don't ask about the look; `design.md` decides it. Write down in two or three lines what the tile will show and query, and work from that. When nobody can answer, a question of how the business is doing ("where are we", "how is the year going") compares AC with the plan and with last year, both, as the client's own summary dashboards do; leave one out only when the model has no number for it, and say so on the tile.
107
+
108
+ ## 4. Design it, then write it
109
+
110
+ Work in this order. Most tiles that look wrong picked colours or a chart type before they knew what the reader had to do.
111
+
112
+ 1. **The form.** What does the reader do with it: read one number, rank members, see a trend, see where a total goes, compare with a target? `design.md` (Form first) picks the form from that; sometimes it is cards or a table, not a chart. Standard chart types go through `ctx.charts.farseer`; every other chart through `ctx.charts.echarts`. Never draw a chart by hand.
113
+ 2. **Colour by its job.** Scenario (IBCS notation), variance (green and red by polarity), identity (`PALETTE`, fixed by member), magnitude (`RAMP`, one hue). `design.md` (Colour by its job).
114
+ 3. **Only the listed colours.** The block in `design.md` holds every colour a tile needs; never type a new list.
115
+ 4. **Marks and spacing.** Start every echarts option from the base in `echarts-look.md` and apply its mark specs: square bars as on Farseer's chart tiles, 2 px lines, quiet solid gridlines, a 2 px surface gap between fills, labels on the marks that matter only. Lay out the tile with the composition rules in `design.md`: one type scale and hierarchy, grid and gap, cards only where something must stand apart, dense rather than stretched. Tables go through `farseerTable` (`farseer-table.md`). Count the tile's height from its content (`design.md`, Fit the tile to its content); every example states its own size.
116
+ 5. **Hover.** Every mark has a tooltip from the base option; nothing is readable only by hovering.
117
+ 6. **Reading without colour.** A legend for two series or more, a swatch beside every coloured name, a table or labels for the exact values.
118
+ 7. **The code.** Start from the closest file in `examples/`; each carries the base option. Read `api.md` for the contract. In short:
119
+ - `export default function (ctx) { … return (element) => { … } }`. Reads are opened once in the body (`readTable`); the returned function draws and runs again whenever data, size, theme or filters change. Writes go in click handlers.
120
+ - Every variable sits inside `sum(...)`, so the dashboard's filters and timeline reach it.
121
+ - Surfaces, text and lines take the theme tokens; only data marks take typed colours.
122
+ 8. **Check against both lists.** Go through every entry of `known-mistakes.md` and `anti-patterns.md`. Then write down every part the request asks for (each measure, each comparison and its variance, the heading, the button) and check each is on the screen. A part the model can't give stays on the list as open, with the reason.
123
+ 9. **Look at it** (section 5). The detectors check code; only looking shows a chart that looks unfinished.
124
+
125
+ ## 5. Save and check
126
+
127
+ Write the code to `tile.js` in parts. One reply of yours holds about 4,000 tokens, roughly 250 lines, and a tile with a form and the Farseer look runs to 500 lines or more: written in one go it is cut off and the turn fails. Start from the closest example (`cp <this skill's folder>/examples/request-form.js tile.js`) and change it with small edits, or write the file in parts of at most 200 lines (`cat > tile.js` for the first, `cat >> tile.js` for the rest). Then build `tile.json` from the file with a short script (`jq -Rs` or `node -e`), never by pasting the code into JSON by hand.
128
+
129
+ 1. Write the tile to a file and create it with `farseer dashboards create-tile <dashboard> --input tile.json --json` (the new id is `.tile.id`):
130
+
131
+ ```json
132
+ {"name": "Where net sales go", "gridPlacements": {"absolute": {"x": 0, "y": 0, "w": 36, "h": 14}},
133
+ "data": {"type": "CODE", "code": "export default function (ctx) { … }"}}
134
+ ```
135
+
136
+ Change the code with `farseer dashboards update-tile <dashboard> <tileId> --input change.json`, the file holding `{"data": {"code": "…"}}`. Writing code needs the `FEATURE.CODE_TILES` permission; a refusal without it is expected, so tell the user rather than work around it. Placement and title: `api.md`, Saving.
137
+ Use Farseer as code (`farseer code`) instead when the tile comes with other changes to the model's structure (a new dashboard with its tiles, a variable the tile reads), so they plan and apply as one, or when the workspace's AI Hub switch tells you to. The tile goes into the dashboard's file in the checkout: the same object as above in its `tiles`, with `data.code` as one JSON string. Keep the code in a `.js` file beside the checkout and run `check-tile.mjs --code` on it before you paste it, then plan and apply once. A tile alone on an existing dashboard, and every change to a tile's code, goes through the CLI as above. When `farseer code` answers that it is not available (it is experimental, and data access may restrict the user), use the CLI.
138
+ 2. Read the tile back and run this folder's `check-tile.mjs` on it, from your working folder (never from the skill's own folder, so the files it writes stay out of the installed skill). It runs the detectors from `known-mistakes.md` and `anti-patterns.md` on the saved code, then runs the code once with made-up data and clicks every button, so a name that was never declared fails here and not in front of the viewer:
139
+
140
+ ```
141
+ farseer dashboards show-tile <dashboard> <tileId> --json > tile.json
142
+ node <this skill's folder>/check-tile.mjs --tile-json tile.json
143
+ ```
144
+
145
+ 3. Fix every ERROR and every warning. Leave a warning only when you can say why it doesn't apply to this tile, and say so in the hand-back.
146
+ 4. Compare one or two cells of each table with `farseer formula eval` under the same filters: add the dashboard's saved picks (`rows.filters`, e.g. `"Year to date">"M8"`) to the formula you evaluate, since the tile's reads get them and a bare formula doesn't. The check reads no data, so this is the only check of the numbers. A number that is right for the whole year but shown beside a year-to-date number is wrong. A measure that evaluates empty without the picks (a closing balance over a whole year) may be fine with them: evaluate it with them before dropping it. The numbers in your hand-back are the ones evaluated with the picks, so they match what the user sees.
147
+ 5. Look at the tile. The check reads code and numbers, not the picture. Open the dashboard if you can see it, or ask the user to look, at the tile's own width and in a narrow window, as the client's finance director would: would they put this on their dashboard next to Farseer's own chart tiles? Anything that looks like a prototype, a sketch, a grey block or something drawn by hand is not done, however right the numbers are. Most mistakes only show there: an empty or squashed chart, a label that runs over, a tile that scrolls or is half empty, the wrong chart orientation, a card row that doesn't fit. Don't call the tile done before someone has looked.
148
+
149
+ Stop every background command before you hand back, so your hand-back is the last thing you say. Hand back what the tile shows, the queries it runs, the numbers you checked, and anything left open (a number the model lacks, a write nobody has tried yet).
150
+
151
+ ## Changing a tile
152
+
153
+ Read its saved code first (`farseer dashboards show-tile <dashboard> <tileId> --json`, `data.code`); the user may have edited it. Change only what was asked, then run section 5 again. When a fix doesn't hold, don't repeat it: find a different cause.
@@ -0,0 +1,183 @@
1
+ # Anti-patterns: tiles that look wrong
2
+
3
+ `known-mistakes.md` lists what makes a tile blank or its numbers wrong. This file lists what makes a correct tile look like a sketch next to Farseer's chart tiles. Each entry has what it looks like, the fix, and a detector: a rule you check on the code or by looking at the tile. A tile that matches one fails, however right its numbers are. `check-tile.mjs` runs the detectors it can read from the code; the rest are for your eyes on the screenshot.
4
+
5
+ ## A chart drawn by hand
6
+
7
+ - **Looks like.** Bars made of `<div>`s, arcs or country shapes drawn as SVG paths, a map of squares, a flow drawn with lines, or a second gauge series bent into a marker shape echarts has no component for.
8
+ - **Fix.** Every chart goes through `ctx.charts.farseer` (standard types) or `ctx.charts.echarts` with the base option from `echarts-look.md`. HTML only for cards, tables, forms, buttons and text. No HTML bars, not even inside a table cell: draw the ranking as a chart beside the table.
9
+ - **Detector.** The code creates no `svg`, `path`, `polygon`, `canvas` or `getContext`, and no element sized from a value (`style.width = …%` from a cell value) outside a table cell. A gauge series has no `pointer.icon` other than the default or `rect`.
10
+
11
+ ## A made-up map
12
+
13
+ - **Looks like.** Squares or blobs standing for regions, or outlines sketched by hand.
14
+ - **Fix.** Real outlines from `maps/` with `ctx.charts.registerMap`. No outlines for the area asked: ranked bars and a note saying why.
15
+ - **Detector.** Every `series` of `type: 'map'` names a map registered from `pick-map.mjs` output (`const MAP = …` with the Natural Earth comment). No `registerMap` with `{ svg }` drawn in the code.
16
+
17
+ ## A grey tile
18
+
19
+ - **Looks like.** Everything in black and greys: a gauge, map, treemap or sankey in the AC colour and its tints, which reads as unfinished.
20
+ - **Fix.** Single-series charts take the dashboard's AC colour (a graphite AC is fine there, as on the chart tiles); identity takes `PALETTE`, magnitude takes `RAMP` (steps of AC, Farseer blue when AC is a grey), large areas take `FILL` (`design.md`, Colour by its job).
21
+ - **Detector.** A treemap, map or heatmap option uses `PALETTE`, `FILL` or `RAMP`, not only greys.
22
+
23
+ ## Chrome Farseer's tiles don't have
24
+
25
+ - **Looks like.** Bars as wide as their slot, dark or dashed gridlines, a frame around every block, each KPI in a bordered rounded box, emoji, a gradient, a decorative icon, words like "Awesome insights".
26
+ - **Fix.** A finished management report: bars as the chart tile draws them (`echarts-look.md`, Marks), space and a 1 px divider between KPIs, a title that says what it answers, a quiet note with unit and scope, nothing else.
27
+ - **Detector.** No `type: 'dashed'`, no `splitLine` shown on a value axis, no element with both a full `border` and a `border-radius` except form controls, no emoji, `linear-gradient`, `box-shadow` or exclamation marks.
28
+
29
+ ## A bar that doesn't look like Farseer's
30
+
31
+ - **Looks like.** Rounded bar ends, thin capped bars, grey gridlines, a muted axis: the general look of a charting library, beside Farseer's square bars with an ink axis.
32
+ - **Fix.** The base option and marks of `echarts-look.md`, measured from the chart tile.
33
+ - **Detector.** `check-tile.mjs` fails `borderRadius` on bars, `barMaxWidth`, `splitLine` shown, and `showValueAxis: true` on a `ctx.charts.farseer` chart (a stacked bar labels its totals instead of drawing a value axis).
34
+
35
+ ## A number on everything
36
+
37
+ - **Looks like.** A label on every bar of several series, every point of every line, every segment of a stack.
38
+ - **Fix.** Label the one series or point the reader needs; the axis, legend and tooltip carry the rest.
39
+ - **Detector.** With two series or more, at most one series has `label.show: true`.
40
+
41
+ ## Colour that does the wrong job
42
+
43
+ - **Looks like.** Red and green as company colours, a rainbow for magnitude, cost categories in a stack in teal, orange and violet, treemap boxes in shades in no order, colours that change when a filter removes a member.
44
+ - **Fix.** `design.md`, Colour by its job: identity `PALETTE` in the model's member order, parts of one whole in steps of AC (the largest part deepest), magnitude `RAMP` with one hue and its scale, variance green and red only.
45
+ - **Detector.** Green and red appear only on variances. A `visualMap` uses `RAMP` or the diverging pair. Identity colours are looked up by member name in a fixed object, not by the row's index. `check-tile.mjs` fails a stack coloured from `PALETTE`, and warns on `colorSaturation` or `colorAlpha` on a treemap without a `visualMap`.
46
+
47
+ ## Text in the series colour
48
+
49
+ - **Looks like.** A company's name or value printed in its orange or aqua, unreadable on white.
50
+ - **Fix.** Text in ink or muted ink; a swatch, dot or short line beside it carries the colour.
51
+ - **Detector.** No `color` on a label, legend text or table text set from `PALETTE`; variance numbers are the only coloured text.
52
+
53
+ ## A missing legend, or a lonely one
54
+
55
+ - **Looks like.** Two or more series with no legend, so the reader matches colours by guessing; or a legend box with one swatch that repeats the title.
56
+ - **Fix.** A legend (echarts `legend`, or swatches in the table's first column) for two series or more; none for one.
57
+ - **Detector.** Charts with two series or more have `legend.show` not false or a swatch per row; single-series charts have no legend.
58
+
59
+ ## Two scales on one chart
60
+
61
+ - **Looks like.** A second y-axis so net sales and margin share a plot.
62
+ - **Fix.** Two charts side by side, or one indexed to a common base.
63
+ - **Detector.** No `yAxis` array with two entries.
64
+
65
+ ## Values only in the tooltip
66
+
67
+ - **Looks like.** A map or chart where the only way to read a number is to hover.
68
+ - **Fix.** Labels on the marks that matter, or a ranked list or table beside the chart.
69
+ - **Detector.** A map, treemap or heatmap has a list, table or labels beside it carrying the values, or labels on its marks.
70
+
71
+ ## Clipped, crowded or half empty
72
+
73
+ - **Looks like.** A label cut by its bar, axis labels outside the chart's box, a chart drawn over its neighbour, a scrollbar inside the tile, a small chart in a wide empty tile, a form in the left half with the right half and the bottom empty, a table spread across 1,000 px.
74
+ - **Fix.** Size charts from the tile with the axis band included and draw them after the layout. Fit the tile to the content (the size the example states, rows × row height), put things side by side on a wide tile, or make the tile narrower. Keep tables `max-content` wide and truncate long names with an ellipsis.
75
+ - **Detector.** Look at the tile, or ask the user to: nothing cut, nothing scrolls, and no third of it empty at its own width (a deck is exempt). Every `table` is built by `farseerTable`.
76
+
77
+ ## A table styled by eye
78
+
79
+ - **Looks like.** Uppercase grey headers, 13 or 14 px rows, padding that differs from the table tiles beside it.
80
+ - **Fix.** `farseerTable` from `farseer-table.md`, or a table tile.
81
+ - **Detector.** The code creates a `table` only through `farseerTable` (its class `fs-table`).
82
+
83
+ ## A legend that doesn't match the marks
84
+
85
+ - **Looks like.** Grey or blue squares for "This year" and "Last year" next to bars coloured per company.
86
+ - **Fix.** Make the swatches look like the marks, or drop the legend and say what the shades mean in the subtitle.
87
+ - **Detector.** When a series' `data` items carry their own `itemStyle.color`, that chart's `legend.show` is false.
88
+
89
+ ## A ranking out of order
90
+
91
+ - **Looks like.** A bar chart or a list of companies where the second is smaller than the third.
92
+ - **Fix.** Sort by the value the title ranks by, largest first, and keep that order in the table beside it.
93
+ - **Detector.** A chart or table of members has a `.sort(` on the value it shows before it is drawn, unless the model's own order is the point (months, P&L lines).
94
+
95
+ ## Text with no contrast on a fill
96
+
97
+ - **Looks like.** White labels on orange, aqua or a light ramp step.
98
+ - **Fix.** Ink on the light fills, white on the dark ones (`design.md`, Text and numbers).
99
+ - **Detector.** A label colour set inside a fill comes from a lookup by the fill colour, not one constant for every fill.
100
+
101
+ ## A form out of a template
102
+
103
+ - **Looks like.** Inputs of different heights, a bold "Pick one" that reads as chosen, a placeholder "10000" that reads as typed, a field alone in a row, a full-width button.
104
+ - **Fix.** `design.md`, Forms.
105
+ - **Detector.** Every `select` starts on an empty-valued prompt option and is styled muted while empty; no `placeholder` is a number; fields sit in a grid of equal columns.
106
+
107
+ ## A heading Farseer's tiles don't have
108
+
109
+ - **Looks like.** A 15 px bold title with 16 px of padding next to chart tiles whose names are 12 px regular, a bold panel heading, a grey caption over a table, an uppercase label: more text levels than a Farseer tile has.
110
+ - **Fix.** The tile header style (`design.md`, Composition): title 12 px ink weight 400, an 11 px muted note, no outer padding. Title, body, footnote; a panel is named by a table-style header.
111
+ - **Detector.** The title is drawn at `font-size:12px`, weight 400; the outermost element has no padding; no `font-weight:600` or `700` except on a KPI value, a total row or a variance; no `text-transform:uppercase`. `check-tile.mjs` fails a title joined with a middle dot. A deck slide is exempt (SKILL.md section 1).
112
+
113
+ ## Notes about the build, not the numbers
114
+
115
+ - **Looks like.** A subtitle that explains the tile ("drawn with farseerTable()", "ranked bars, since there are no outlines", "each company keeps its colour").
116
+ - **Fix.** One short line with scope, version, period and unit; a substitution in a few words.
117
+ - **Detector.** No note mentions the code, the chart type or how colours are assigned.
118
+
119
+ ## Pale text
120
+
121
+ - **Looks like.** Labels, field names, sub-panel headers and the names beside a chart all in the muted slate, so the tile looks washed out beside a chart tile, whose labels are ink.
122
+ - **Fix.** Ink for every label and header; muted ink only for units beside a value, footnotes, empty prompts and the end values of a scale (`design.md`, Composition).
123
+ - **Detector.** `--code-tile-muted` or `MUTED()` is set on a label, a `th`, a form `label` or a legend name; it appears only on units, footnotes and prompts.
124
+
125
+ ## Table headers out of line
126
+
127
+ - **Looks like.** Scenario headers (AC, PL) sit higher than the others, since a 3 px border pushes their text up.
128
+ - **Fix.** `farseerTable` paints the scenario rules as backgrounds, so every header keeps the same line box. Don't add borders to `th` or `td` of your own.
129
+ - **Detector.** No `border-bottom` on `.fs-table th` or `td` outside the helper.
130
+
131
+ ## An AC that isn't the dashboards' AC
132
+
133
+ - **Looks like.** A tile in an example's colour, or in a bright brand teal or orange, beside chart tiles in `#323232` or a dark brand colour, so the tile looks borrowed.
134
+ - **Fix.** The AC colour of the `farseer-dashboards` skill (SKILL.md section 2, The AC colour); everything else comes from `tint()`.
135
+ - **Detector.** `check-tile.mjs` fails a `const AC` that is red, green, or lighter than a relative luminance of about 0.06.
136
+
137
+ ## A form cut at the edge
138
+
139
+ - **Looks like.** A focus ring cut off on one side, a side table running past the tile, a choice cut mid-word, a button label on two lines, a button that looks ready while the hint says a field is missing.
140
+ - **Fix.** `design.md`, Forms that fit any width: the block's `control()`, a field grid with `auto-fit`, a wrapping row for the form and its table, the ring inside the control, `title` on a select, the button disabled while the hint names something.
141
+ - **Detector.** `check-tile.mjs` fails a button without `white-space: nowrap`. The rest shows only on the tile: look at it at its own width and in a narrow window, with a control focused, or ask the user to.
142
+
143
+ ## Hairline bars
144
+
145
+ - **Looks like.** A waterfall or bar chart where one bar sets the scale and the results that matter are lines a pixel high.
146
+ - **Fix.** `echarts-look.md`, Waterfall: chart the big steps, put the small tail in a table.
147
+ - **Detector.** Look at the tile: every bar the title talks about is at least a few pixels high.
148
+
149
+ ## Pill buttons for choices
150
+
151
+ - **Looks like.** Rounded pill buttons, one per option, wrapping onto two rows, the chosen one in a heavy black outline.
152
+ - **Fix.** `design.md`, Forms: a select, or one row of underlined tabs.
153
+ - **Detector.** `check-tile.mjs` fails a button with a border radius of 12 px or more.
154
+
155
+ ## A footnote that renames the client's measures
156
+
157
+ - **Looks like.** "Net sales is the model's Revenue; net profit is Net income", or "Product groups are the model's division groups".
158
+ - **Fix.** Label the tile with the client's own names (Revenue, Division group); a footnote only for what the reader needs (a balance at the period's end, a slide that ignores the filter).
159
+ - **Detector.** The reviewer reads every footnote: none of them maps a requested word to a model name.
160
+
161
+ ## A crowded flow
162
+
163
+ - **Looks like.** A sankey with five or six columns, labels running into the next column's nodes.
164
+ - **Fix.** `echarts-look.md`, Sankey: two columns (three at most) and the rest of the chain as a table beside it.
165
+ - **Detector.** Count the node columns in the option: more than three fails. Then look at the tile for labels that cross a node.
166
+
167
+ ## A decorative rail
168
+
169
+ - **Looks like.** A thick coloured bar down the left of a title slide or a card, a generic deck device no Farseer tile uses.
170
+ - **Fix.** Let the logo, the type and the space carry the title; colour goes on data and on the one figure that matters.
171
+ - **Detector.** No `border-left` wider than 1 px outside a table.
172
+
173
+ ## A minus zero
174
+
175
+ - **Looks like.** `-0`, `-0,1 %` or `−0 pp` where the value rounds to nothing.
176
+ - **Fix.** `design.md`, Text and numbers: a value that rounds to zero shows 0 with no sign.
177
+ - **Detector.** Every number goes through one format helper that turns a value rounding to zero into 0 before it formats it. Look at the tile for a `-0`.
178
+
179
+ ## A title that disagrees with its form
180
+
181
+ - **Looks like.** "Request a cost for Commercial" above a Domain field still reading "Choose a domain".
182
+ - **Fix.** Prefill the field from the filter bar (`picks()`), or keep the member out of the title (`design.md`, Forms).
183
+ - **Detector.** A title that names a member takes it from the same state as the field (`picks()` or the select's value), never typed into the title. Empty rows have no placeholder text. Look at the tile with nothing filled in.
@@ -0,0 +1,237 @@
1
+ # The Code tile contract
2
+
3
+ What the code gets and what it may ask for. `ctx` is kept small on purpose, since saved code outlives the runtime it was written for. Use only what is here.
4
+
5
+ ## The module
6
+
7
+ ```js
8
+ export default function (ctx) {
9
+ // runs once per run of the code: open reads and state here
10
+ const sales = readTable({ /* … */ });
11
+
12
+ return (element) => {
13
+ // runs on every draw: when data arrives, the tile resizes, the theme or filters change, or after ctx.render()
14
+ element.replaceChildren(/* … */);
15
+ };
16
+ }
17
+ ```
18
+
19
+ - The body runs once each time the code runs (on save, on Run in the editor, when the tile mounts). Everything it opened is closed before the next run, whether the code cleaned up or not.
20
+ - The returned function draws into `element`, the tile's container (full height of the tile, `overflow: auto`). It must be safe to call any number of times. Build the content from scratch or update nodes it keeps, never append to what is there.
21
+ - A body that returns nothing draws nothing.
22
+
23
+ ## `ctx`
24
+
25
+ | Member | What it is |
26
+ |---|---|
27
+ | `query(queries, options?)` | Reads from the model as the viewer; returns a live handle (Reading). Open it in the body, or through `readTable` |
28
+ | `read(queries, options?)` | The same read once, as a Promise: for a click that needs the value now (Writing) |
29
+ | `getEntities(keys)` | Variables, tables and members by id (`{ type: 'VAR' \| 'DTAB' \| 'DMEM', id }`), answered again when they change |
30
+ | `write(cells, options?)` | Sets cells as the viewer and returns a handle (Writing). Only in a click or key handler |
31
+ | `addMembers(table, members)`, `updateMembers(table, members)` | Adds or changes members of a table and returns a handle (Writing). Only in a click or key handler |
32
+ | `charts.farseer(table, element, settings?)` | Draws a `{ columns, rows }` table with the chart tile's own code and settings |
33
+ | `charts.echarts(element, option)` | Any echarts chart, in Farseer's theme and the viewer's palette unless `option.color` is set |
34
+ | `charts.registerMap(name, source)` | A map for echarts, given as GeoJSON or `{ svg: '<svg…>' }` |
35
+ | `format(value, numberFormat?)` | A number in the viewer's locale with an Excel-style format (`'#,##0,'` is thousands); empty text for null |
36
+ | `theme` | `{ tokens, palette, numberLocale, colorBlind }`: the colour tokens `text`, `background`, `muted`, `border` and `focus` (also CSS variables `--code-tile-<name>`, `design.md`), the viewer's palette, number locale (`'en-US'`, `'de-DE'`) and colour-blind setting |
37
+ | `frame` | `{ width, height }` of the tile's frame |
38
+ | `loading(show)` | Shows or hides Farseer's own loader over the tile, e.g. `ctx.loading(sales.loading)` at the top of the draw function |
39
+ | `state(key, initial)` | `{ value, set(next) }` kept for this viewer across reloads (JSON, 64 KB per tile); `set` doesn't redraw |
40
+ | `snapshot(key, initial)` | `{ value, set(next) }` that survives a re-run of the code, for a selected tab |
41
+ | `render()` | Draw again after the code's own state changed (a click picked a tab). Data, size, theme, filters and writes already redraw |
42
+ | `onCleanup(fn)` | Runs when this run is closed: remove a listener added to `window` or `document`, stop a timer |
43
+ | `signal` | An `AbortSignal` for the same moment, for `addEventListener(…, { signal: ctx.signal })` |
44
+
45
+ A tile can't run an App. Anything a form changes, it writes itself (Writing).
46
+
47
+ ## Reading
48
+
49
+ `ctx.query` takes a list of queries and answers each with one value:
50
+
51
+ ```js
52
+ const kpi = ctx.query([
53
+ { type: 'VARIABLE', formula: 'sum("Net sales", "Versions">"Actual")' }, // value: a number or null
54
+ { type: 'DTABLE', table: 'Department' }, // value: the members' names
55
+ ]);
56
+ kpi.loading // true until the first answer, and while a new one is on its way
57
+ kpi.error // null, or { reason, message }; reason is refused, too_large, rate_limited, timeout or failed
58
+ kpi.current // [{ type, formula, value }, …] in the order asked, kept after a failure
59
+ kpi.close() // stops this read; every read closes by itself when the code runs again
60
+ ```
61
+
62
+ A handle is read in the draw function, which runs again whenever it gets an answer. It can't be awaited: `await` or `.then` on it throws. For a value you need right now, in a click, use `ctx.read` (Writing).
63
+
64
+ - **`VARIABLE`** answers one number for the whole formula: one cell, not a row of them. A table of numbers is one query per cell, which `readTable` builds for you.
65
+ - **`DTABLE`** lists a table's members by name, the table named as in the model. Without `formula` it lists every member, its `NULL (…)` member included (skip it); a `formula` such as `"Department">"Marketing"` narrows the list. `columns: ['name', 'Department']` adds a column per member, flattened into one list (`['Digital marketing', [5], 'Trade marketing', [5]]`); a link column gives the linked member's position in its own table's list, counting its `NULL (…)` member as 0. Never more than two columns: three crash the server's engine.
66
+ - **Variables inside `sum(...)`.** The dashboard's filter bar is added to every `sum(...)` as a filter, so a name outside one ignores it. `sum("A") / sum("B")` is fine; `"A" / "B"` is not.
67
+ - **Filter bar and timeline.** Every read follows both, lists included. `{ includeDashboardFilters: false }` or `{ includeDashboardTimeline: false }` as the second argument leaves one out; say so on the tile ("Full year, whole group"). A formula that names a period (`"Years">"Y2025"`, a member of Months or Year to date) keeps its own period instead of the timeline's.
68
+ - **A period filter is a filter, not the timeline.** A filter bar on `Year to date`, `Months` or `Years` narrows every `sum(...)` like any other filter. Naming a period in the formula doesn't escape it, the two intersect.
69
+ - **Live.** The tile reads again when the filters, sort or timeline change, when someone changes model data, and after a write. Reads are rate limited to a burst of 20 and then one every 500 ms, with at most 10 open reads per tile.
70
+ - **Built at runtime is fine.** A formula may be put together in the code (`"Entity">"${name}"`). The server answers every read as the viewer, with the viewer's own data permissions.
71
+
72
+ ### `readTable` and `picks`
73
+
74
+ Every example carries `readTable`, `picks`, `withFilter` and `namesOf` at the top of its body (copy them from `examples/kpi-cards.js`). `readTable` reads a table of numbers in the shape `ctx.charts.farseer` and `farseerTable` draw:
75
+
76
+ ```js
77
+ // formulas as columns over the members of a table, one row per member
78
+ const sales = readTable({
79
+ rows: { table: 'Entity' }, // every member, listed live; members: ['M1', …] fixes them instead
80
+ columns: [
81
+ { label: 'AC', formula: 'sum("Net sales", "Versions">"Actual")', numberFormat: '#,##0,' },
82
+ { label: 'PL', formula: 'sum("Net sales", "Versions">"Budget 2026")', numberFormat: '#,##0,' },
83
+ ],
84
+ });
85
+ // lines as rows with a member filter per column, the shape of a P&L
86
+ const pl = readTable({
87
+ rows: [
88
+ { label: 'Net sales', formula: 'sum("Net sales")', numberFormat: '#,##0,' },
89
+ { label: 'EBITDA', formula: 'sum("EBITDA")', numberFormat: '#,##0,' },
90
+ ],
91
+ columns: [
92
+ { label: 'AC', filter: '"Versions">"Actual"' },
93
+ { label: 'PL', filter: '"Versions">"Budget 2026"' },
94
+ ],
95
+ });
96
+ ```
97
+
98
+ `current` is `{ columns: [{ label, numberFormat }], rows: [{ label, numberFormat, cells: [{ value }] }] }`, with `loading` and `error` as above. Find rows and columns by `label`, never by position.
99
+
100
+ - Member rows come in the table's order, and only the members the filter bar leaves: picking Acme Croatia leaves its own row, and a table linked to the one picked (its locations, a department's cost centres) keeps only the linked members.
101
+ - `rows: { table: 'Cost centre', includeDashboardFilters: true }` lists by the filter bar even when the numbers ignore it (`includeDashboardFilters: false` on the spec): a department's cost centres with their full-year budget.
102
+ - A new member shows up by itself: the list is read live, and the numbers are read again for the new list.
103
+ - One read per cell: 30 members by 4 columns is 120 cells in one request. Keep a table under about 2,000 cells; a planner over a table with thousands of members needs its rows narrowed first.
104
+
105
+ ## The dashboard's filters
106
+
107
+ A tile sees the filter bar through its reads: a list of a table's members follows the bar like every number does. `picks(tables)` turns that into what a title or a form needs:
108
+
109
+ ```js
110
+ const bar = picks(['Entity', 'Year to date', 'Department']); // in the body
111
+ // in the draw function
112
+ const department = bar.current.Department; // { members: ['Marketing'], all: false }
113
+ if (department.all || department.members.length !== 1) { /* say which department to pick */ }
114
+ ```
115
+
116
+ - `members` are the names the bar leaves on that table, `all` is true when the bar doesn't narrow it (nothing picked, or every member).
117
+ - Read it in the draw function or in a click handler: when the selection changes, the reads answer again and the tile redraws.
118
+ - Reads already follow the filters by themselves; never add the selection to a formula yourself.
119
+ - Use it for what reads can't do: which department a form writes for, or a title that says what the numbers are for ("Plan for Marketing", "January to August").
120
+ - One member picked is the usual case for a form. When none or several are picked, say what to pick and disable the button rather than guess.
121
+
122
+ ## Charts
123
+
124
+ `ctx.charts.farseer(table, element, settings)` draws a `{ columns, rows }` table exactly as a chart tile would: a `readTable` result, or a copy with its rows filtered, sorted or cut to the top N (`{ ...table, rows }`). The chart draws the rows in the order given. `settings` is a chart tile's `visualization.chart`, partial; rows and columns are referred to by `label`:
125
+
126
+ ```js
127
+ ctx.charts.farseer(pl.current, chartElement, {
128
+ type: 'BAR_CHART', // also LINE_CHART, STACKED_BAR_CHART, AREA_CHART, WATERFALL_CHART, PIN_CHART, COMBO_CHART, PIE_CHART
129
+ layout: 'HORIZONTAL', // columns along the bottom; VERTICAL draws horizontal bars
130
+ series: { transposeData: false, keepEmptyValue: true }, // rows are series, columns the axis; keepEmptyValue keeps empty months
131
+ display: { showLegend: true, showValueAxis: false },
132
+ labels: { showLabels: true },
133
+ rowVisualizationByPath: {
134
+ AC: { color: { solid: '#323232', pattern: 'SOLID' } },
135
+ PL: { color: { pattern: 'NONE', border: '#323232', borderStyle: 'THIN' } },
136
+ },
137
+ });
138
+ ```
139
+
140
+ `ctx.charts.echarts(element, option)` takes any echarts option. Bundled beyond the chart tile's own types are sankey, gauge, map (with geo), treemap, sunburst, tree, graph, heatmap, radar, scatter, boxplot, funnel, parallel, theme river, and the calendar, polar, visual map, mark line and mark area components. Charts draw as SVG. The element must have a height in px before the call.
141
+
142
+ Every chart a tile draws goes through one of these two. Never draw a chart yourself in SVG, canvas or HTML (`anti-patterns.md`, A chart drawn by hand). `echarts-look.md` has the base option every echarts chart starts from.
143
+
144
+ ### Maps
145
+
146
+ The frame can't fetch a map, so the outlines travel in the code. `maps/` next to this file holds real country outlines from Natural Earth (public domain): `europe.geo.json` (1:50m: Europe, Turkey and the Caucasus) and `world.geo.json` (1:110m, every country). Don't paste a whole file; `pick-map.mjs` writes only the countries the tile needs as a constant:
147
+
148
+ ```
149
+ node <this skill's folder>/maps/pick-map.mjs --map europe --countries HR,SI,RS,BA --context AT,HU,IT,ME > map.js
150
+ ```
151
+
152
+ Paste its `const MAP = …` line into the body, register it once and draw it:
153
+
154
+ ```js
155
+ ctx.charts.registerMap('tile', MAP);
156
+ // in the draw function
157
+ ctx.charts.echarts(chartElement, merge(base, {
158
+ tooltip: { formatter: (p) => `${ctx.format(p.value, '#,##0,')} kEUR<br>${COUNTRY[p.name] ?? p.name}` },
159
+ visualMap: { min: 0, max, inRange: { color: RAMP }, /* … */ },
160
+ series: [{ type: 'map', map: 'tile', data: rows.map((r) => ({ name: ISO[r.label], value: r.value })) }],
161
+ }));
162
+ ```
163
+
164
+ - Each feature's `name` is the country's ISO code (or `--name-by name`). Map the model's member names to it in one explicit object (`const ISO = { Croatia: 'HR', 'Bosna i Hercegovina': 'BA' }`) and check every member is in it.
165
+ - `--context` adds neighbours drawn in the empty colour, so the shapes have a place on the page.
166
+ - Keep the map under about 60,000 characters (`--precision 1` halves it); saved code is capped at 200,000.
167
+ - The files have countries only. Regions, cities and sales territories have no outlines here: draw ranked bars instead, and say in the subtitle that the model's regions have no map.
168
+
169
+ ## Writing
170
+
171
+ ```js
172
+ // in a click handler, never in the body or the draw function
173
+ let sent = null; // in the body: the last request, read in the draw function
174
+ button.onclick = () => {
175
+ const cell = 'sum("Travel cost", "Versions">"Budget 2027", "Years">"Y2027", "Months">"M3", "Department">"Marketing")';
176
+ ctx.read([{ type: 'VARIABLE', formula: cell }], { includeDashboardFilters: false, includeDashboardTimeline: false })
177
+ .then(([now]) => {
178
+ sent = { before: now.value ?? 0, handle: ctx.write({ type: 'VARIABLE', formula: cell, value: (now.value ?? 0) + 1800 }) };
179
+ }, (failure) => { sent = { failed: failure.message }; ctx.render(); });
180
+ };
181
+ // in the draw function: sent.handle.loading while it saves, sent.handle.error if it was refused, else done
182
+ const added = ctx.addMembers('Location', [{ name: 'Split branch', Entity: 'Acme Croatia' }]); // added.current: [{ id, name }]
183
+ ```
184
+
185
+ - **Only after a click or key press in the tile**, from its handler or a `ctx.read` it started. A write while the code runs or draws throws, so a tile can never write in a loop. Writes in the same tick go as one request.
186
+ - **A write returns a handle, not a Promise.** Keep it, and read `loading` and `error` in the draw function: the tile redraws when the write starts and when it settles. `await` or `.then` on it throws. A write that was refused has `error.message`; show it beside the button.
187
+ - **As the viewer.** A write needs the viewer's own rights on those cells or that table.
188
+ - **A cell is a formula** like a read: the variable and every table it is split by, named as `Table>Member`, one version and a month. A write ignores the filter bar unless `{ includeDashboardFilters: true }` is passed, so name every member. A value written to a year, a quarter or a parent member is spread over the cells beneath it (by the variable's top-down mapping, otherwise in proportion to what is there), so write the leaf cell when the form means one month. Only input variables take a write; a calculated one answers "Cannot update dimensionless variable". `null` clears the cell.
189
+ - **Adding to what is there.** A request adds to the plan: `ctx.read` the cell in the same click, then write the old value plus the request.
190
+ - **Members.** `addMembers(table, [{ name, description, <column>: value }])` takes a link to another table by that table's member name (`Entity: 'Acme Croatia'`), and its handle's `current` gets the new `[{ id, name }]`. `updateMembers` needs each member's `id`.
191
+ - **A new member and its cells in one click** (an investment, a location, a version). The cells can only be written once the member exists, so keep the `addMembers` handle and write when it settles, from a timer the click started. The click's right to write lasts a few seconds, long enough for a member to be added:
192
+
193
+ ```js
194
+ let timer = null;
195
+ ctx.onCleanup(() => clearTimeout(timer));
196
+ button.onclick = () => {
197
+ sent = { member: ctx.addMembers('Investment', [{ name, Entity: company }]) };
198
+ let tries = 0;
199
+ const writeWhenAdded = () => {
200
+ if (sent.member.loading && ++tries < 40) return void (timer = setTimeout(writeWhenAdded, 100));
201
+ if (sent.member.error || sent.member.loading) return ctx.render(); // the draw function shows why
202
+ sent.cells = ctx.write(cellsOf(name), { includeDashboardFilters: false, includeDashboardTimeline: false });
203
+ };
204
+ timer = setTimeout(writeWhenAdded, 100);
205
+ ctx.render();
206
+ };
207
+ ```
208
+
209
+ Copying a plan to the new member (a location staffed like another, a version opened from the budget) reads the source **before the click**, whenever the form names a new source, so the click has only to add and write: every write checks that the click's activation is still live (about 5 s) and that the tile still has focus, and reading a large source first spends that time. Read the source at the leaf, month by month: a variable that rolls up as the closing state (headcount) answers a year with December alone. Remember a member the tile added until its cells are written (`ctx.state`), so a write that failed or was cut short is finished by the next click instead of the form answering that the name exists (`examples/open-forecast.js`, `examples/new-location.js`).
210
+ - **Many cells.** A message between the tile and Farseer holds at most 256 KB, and one it can't hold gets no answer at all: the read or write handle stays `loading` and the cells in it are never written. Cut reads and writes into parts by size, adding queries to a part while its JSON stays under about 200 KB, never by a count of cells: long member names make long formulas. Read the parts one after another (`await` each `ctx.read`), since a tile holds at most ten reads and lookups open at once, its own queries included. Writes have a budget of their own: a burst of ten, then one a second, and the click's right to write lasts about 5 s. With `addMembers` taking one, a click carries at most eight write parts; a part past the budget comes back `rate_limited` and a retry starts over from the first, so the form refuses a bigger copy before the click and says how to narrow it (fewer months, one company). Write each part from its own `setTimeout(…, 0)` so each goes as its own request, and show how many cells the click wrote. A whole version of a large model is beyond a tile; copy one company or one area at a time and say so on the tile.
211
+ - **After a write** every tile on the dashboard reads again, this one included, so the new numbers show without code.
212
+ - **Undo.** The model has no undo for a tile's write. A form that writes several cells says what it will write before the click and what it wrote after.
213
+
214
+ ### Testing a write
215
+
216
+ A form isn't done until it has written once. On a copy of the model, or with the user's yes on a live one, click it in the tile, check the cells with `farseer formula eval` (they moved by exactly what the form asked), then put them back with `farseer cells update --variable … --dimension Table=Member … --value <old> -y`. Without a browser, write the same cell the form names with `farseer cells update`, check it and put it back, and say the button itself is untested. Without a copy or a yes, say in the hand-back that the write is untested, and ask the user to try it once.
217
+
218
+ ## Saving a tile
219
+
220
+ Save with the CLI, as SKILL.md section 5 shows: `farseer dashboards create-tile <dashboard> --input tile.json` for a new tile, `farseer dashboards update-tile <dashboard> <tileId> --input change.json` to change its code. Writing a Code tile's code needs `FEATURE.CODE_TILES` (a super user grants it). Moving or restyling an existing Code tile doesn't.
221
+
222
+ ```json
223
+ {"name": "Where net sales go", "subtitle": "", "footnotes": "", "style": {},
224
+ "gridPlacements": {"absolute": {"x": 0, "y": 0, "w": 36, "h": 14}},
225
+ "data": {"type": "CODE", "code": "export default function (ctx) { … }"}}
226
+ ```
227
+
228
+ - **Placement.** Use `absolute`, the grid the dashboards are laid out on. Each unit is 30 px, so the code gets a frame about `30 × w − 24` px wide and `30 × h − 24` px high (w 36, h 14 is 1,056 × 396). A page is usually 36 wide. Read the other tiles' `gridPlacements.absolute` and put the tile under them (`y` = the lowest `y + h`). Never `large`: that is a 12-column grid, and a `w` meant for 36 columns makes the tile three times wider than the page.
229
+ - **Title.** A Code tile shows no title of its own, whatever its `name`. The code draws its title (`design.md`, Text). `name` is still what the editor lists.
230
+
231
+ Read a tile back with `farseer dashboards show-tile <dashboard> <tileId> --json`; its code is `data.code`. Code is capped at 200,000 characters.
232
+
233
+ `check-tile.mjs` next to this file checks the saved code (SKILL.md, Save and check). It needs no browser and reads no data, so it can't see the tile or its numbers: check a few cells with `farseer formula eval`, and look at the tile or ask the user to.
234
+
235
+ ## What the frame doesn't have
236
+
237
+ No network of any kind (fetch, XHR, WebSocket, images or fonts from a URL, `import()` from a CDN, WebRTC), no storage of its own (localStorage, cookies, IndexedDB; `ctx.state` keeps what the viewer chose), no forms that submit, no navigation, no access to the page around it. Everything the tile needs is in its code or comes through `ctx`. The tile stops with "stopped responding" when the frame is silent for 6 s, so long loops in the draw function freeze it.