farseer-cli 1.19.0 → 1.20.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 (155) hide show
  1. package/README.md +31 -8
  2. package/dist/commands/app.js +42 -3
  3. package/dist/commands/app.js.map +1 -1
  4. package/dist/commands/cells.js +120 -85
  5. package/dist/commands/cells.js.map +1 -1
  6. package/dist/commands/dashboards.js +246 -12
  7. package/dist/commands/dashboards.js.map +1 -1
  8. package/dist/commands/dimensions.js +52 -27
  9. package/dist/commands/dimensions.js.map +1 -1
  10. package/dist/commands/docs.js +82 -0
  11. package/dist/commands/docs.js.map +6 -0
  12. package/dist/commands/files.js +49 -0
  13. package/dist/commands/files.js.map +2 -2
  14. package/dist/commands/folders.js +76 -0
  15. package/dist/commands/folders.js.map +6 -0
  16. package/dist/commands/formula.js +38 -30
  17. package/dist/commands/formula.js.map +1 -1
  18. package/dist/commands/install.js +32 -30
  19. package/dist/commands/install.js.map +2 -2
  20. package/dist/commands/model.js +30 -5
  21. package/dist/commands/model.js.map +2 -2
  22. package/dist/commands/push.js +5 -3
  23. package/dist/commands/push.js.map +1 -1
  24. package/dist/commands/sheets.js +289 -52
  25. package/dist/commands/sheets.js.map +1 -1
  26. package/dist/commands/skills.js +157 -0
  27. package/dist/commands/skills.js.map +6 -0
  28. package/dist/commands/variables.js +246 -82
  29. package/dist/commands/variables.js.map +1 -1
  30. package/dist/index.js +93 -13
  31. package/dist/index.js.map +1 -1
  32. package/dist/mcp/resources/documentation.js +19 -12
  33. package/dist/mcp/resources/documentation.js.map +1 -1
  34. package/dist/mcp/tools/appTools.js +1 -7
  35. package/dist/mcp/tools/appTools.js.map +1 -1
  36. package/dist/mcp/tools/cellTools.js +6 -19
  37. package/dist/mcp/tools/cellTools.js.map +1 -1
  38. package/dist/mcp/tools/dashboardTools.js +30 -412
  39. package/dist/mcp/tools/dashboardTools.js.map +2 -2
  40. package/dist/mcp/tools/dataTools.js +15 -146
  41. package/dist/mcp/tools/dataTools.js.map +1 -1
  42. package/dist/mcp/tools/folderTools.js +12 -78
  43. package/dist/mcp/tools/folderTools.js.map +1 -1
  44. package/dist/mcp/tools/modelTools.js +23 -372
  45. package/dist/mcp/tools/modelTools.js.map +1 -1
  46. package/dist/mcp/tools/pipelineContract.js +5 -1
  47. package/dist/mcp/tools/pipelineContract.js.map +1 -1
  48. package/dist/mcp/tools/runTools.js +8 -69
  49. package/dist/mcp/tools/runTools.js.map +1 -1
  50. package/dist/mcp/tools/sheetTools.js +14 -264
  51. package/dist/mcp/tools/sheetTools.js.map +1 -1
  52. package/dist/mcp/tools/syncTools.js +5 -1
  53. package/dist/mcp/tools/syncTools.js.map +1 -1
  54. package/dist/mcp/utils/operationResponse.js +41 -0
  55. package/dist/mcp/utils/operationResponse.js.map +6 -0
  56. package/dist/operations/cells.js +444 -0
  57. package/dist/operations/cells.js.map +6 -0
  58. package/dist/operations/dashboards.js +357 -0
  59. package/dist/operations/dashboards.js.map +6 -0
  60. package/dist/operations/data.js +206 -0
  61. package/dist/operations/data.js.map +6 -0
  62. package/dist/operations/errors.js +64 -0
  63. package/dist/operations/errors.js.map +6 -0
  64. package/dist/operations/exportModel.js +59 -0
  65. package/dist/operations/exportModel.js.map +6 -0
  66. package/dist/operations/folderPath.js +128 -0
  67. package/dist/operations/folderPath.js.map +6 -0
  68. package/dist/operations/folders.js +80 -0
  69. package/dist/operations/folders.js.map +6 -0
  70. package/dist/operations/install.js +109 -0
  71. package/dist/operations/install.js.map +6 -0
  72. package/dist/operations/model.js +271 -0
  73. package/dist/operations/model.js.map +6 -0
  74. package/dist/operations/sheets.js +428 -0
  75. package/dist/operations/sheets.js.map +6 -0
  76. package/dist/pipeline/failStep.js +43 -0
  77. package/dist/pipeline/failStep.js.map +6 -0
  78. package/dist/pipeline/generated-reference.json +10 -10
  79. package/dist/pipeline/queryWorker.js +3 -1
  80. package/dist/pipeline/queryWorker.js.map +1 -1
  81. package/dist/pipeline/requests.js +3 -32
  82. package/dist/pipeline/requests.js.map +1 -1
  83. package/dist/pipeline/service.js +46 -2
  84. package/dist/pipeline/service.js.map +1 -1
  85. package/dist/services/appSyncService.js +59 -9
  86. package/dist/services/appSyncService.js.map +1 -1
  87. package/dist/services/apps.js +10 -0
  88. package/dist/services/apps.js.map +1 -1
  89. package/dist/services/farseerService.js +28 -6
  90. package/dist/services/farseerService.js.map +1 -1
  91. package/dist/skills/bundled.js +106 -0
  92. package/dist/skills/bundled.js.map +6 -0
  93. package/dist/skills/install.js +257 -0
  94. package/dist/skills/install.js.map +6 -0
  95. package/dist/skills/pipeline.js +10 -18
  96. package/dist/skills/pipeline.js.map +1 -1
  97. package/dist/utils/agentSandbox.js +1 -1
  98. package/dist/utils/entityResolver.js +72 -25
  99. package/dist/utils/entityResolver.js.map +1 -1
  100. package/dist/utils/errorFormatter.js +13 -0
  101. package/dist/utils/errorFormatter.js.map +1 -1
  102. package/dist/utils/formulaFilters.js +11 -2
  103. package/dist/utils/formulaFilters.js.map +1 -1
  104. package/dist/utils/operationCli.js +102 -0
  105. package/dist/utils/operationCli.js.map +6 -0
  106. package/docs/cli-guide.md +181 -1
  107. package/docs/pipeline-reference.md +13 -7
  108. package/docs/troubleshooting.md +18 -0
  109. package/package.json +1 -1
  110. package/skills/farseer-app-dev/SKILL.md +131 -0
  111. package/skills/farseer-app-dev/assignments.md +185 -0
  112. package/skills/farseer-app-dev/farseer-client-api-guide.md +907 -0
  113. package/skills/farseer-app-dev/farseer-client-release-notes.md +212 -0
  114. package/skills/farseer-app-dev/working-patterns.md +876 -0
  115. package/skills/farseer-authenticate-to-tenant/SKILL.md +60 -0
  116. package/skills/farseer-authenticate-to-tenant/app-authentication.md +91 -0
  117. package/skills/farseer-author-import-job/SKILL.md +114 -0
  118. package/skills/farseer-author-import-job/cell-writes.md +530 -0
  119. package/skills/farseer-author-import-job/deploying-a-farseer-app.md +383 -0
  120. package/skills/farseer-author-import-job/import-job-pattern.md +232 -0
  121. package/skills/farseer-build-model/SKILL.md +122 -0
  122. package/skills/farseer-build-model/formula-grain-alignment.md +612 -0
  123. package/skills/farseer-build-model/naming-conventions.md +435 -0
  124. package/skills/farseer-build-model/sparse-formulas-pattern.md +330 -0
  125. package/skills/farseer-build-pipeline/SKILL.md +190 -0
  126. package/skills/farseer-build-pipeline/erp-sales/README.md +108 -0
  127. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_invoice_lines.yaml +23 -0
  128. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_invoice_lines_raw.yaml +23 -0
  129. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_item_product_map.yaml +17 -0
  130. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_item_product_map_raw.yaml +11 -0
  131. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/gold/erp_sales_cells.yaml +40 -0
  132. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/silver/erp_sales_lines.yaml +35 -0
  133. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/silver/erp_sales_recon.yaml +43 -0
  134. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/silver/erp_sales_unmapped_items.yaml +28 -0
  135. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/main.py +49 -0
  136. package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/Models/in/erp_sales_cells.yaml +17 -0
  137. package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/Models/in/erp_sales_cells_raw.yaml +14 -0
  138. package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/Models/load/erp_sales_to_model.yaml +47 -0
  139. package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/main.py +44 -0
  140. package/skills/farseer-build-pipeline/erp-sales/item_to_product.csv +5 -0
  141. package/skills/farseer-build-pipeline/pipeline-app-failure-report-pattern.md +103 -0
  142. package/skills/farseer-build-pipeline/pipeline-source-encoding.md +68 -0
  143. package/skills/farseer-dashboards/SKILL.md +1 -1
  144. package/skills/farseer-help-center/SKILL.md +66 -0
  145. package/skills/farseer-modify-model/SKILL.md +158 -0
  146. package/skills/farseer-modify-model/model-validation-pattern.md +251 -0
  147. package/skills/farseer-optimize-model/SKILL.md +314 -0
  148. package/skills/farseer-optimize-model/stats-dump.ts +139 -0
  149. package/skills/farseer-pnl/SKILL.md +220 -0
  150. package/skills/farseer-review-model/SKILL.md +172 -0
  151. package/skills/farseer-run-apps/SKILL.md +102 -0
  152. package/skills/pipeline-authoring/SKILL.md +4 -4
  153. package/skills/pipeline-authoring/practices.md +15 -3
  154. package/dist/services/agentApprovalFetch.js +0 -90
  155. package/dist/services/agentApprovalFetch.js.map +0 -6
@@ -0,0 +1,220 @@
1
+ ---
2
+ name: farseer-pnl
3
+ description: Structure of a profit and loss statement in a Farseer model. Recognise revenue, COGS, OPEX and subtotal variables by business type (banking, FMCG, pharma, trading, SaaS, manufacturing), check the sign convention, avoid double counting and mixed currencies, compute or create missing subtotals, and order and mark P&L rows with +/-/= prefixes and polarity, following reference cascades from revenue to gross margin, EBITDA, EBIT and net income. Use for a P&L dashboard or table, an income statement, an EBITDA or EBIT bridge or waterfall, or any cascade-style analysis.
4
+ metadata:
5
+ version: "1"
6
+ ---
7
+
8
+ # P&L structure: discovery and creation
9
+
10
+ A P&L's structure depends on the business type; there is no single universal cascade. This skill shows how to discover a model's P&L from its variables and dimension tables, map them to standard line items, create missing subtotals, and order and mark the rows of a P&L report.
11
+
12
+ ## Step 1: Identify the business type
13
+
14
+ Examine variable names, dimension table members, and any company context you were given.
15
+
16
+ | Signal in data model | Business type |
17
+ | ---------------------------------------------------------------------------------- | -------------------------------- |
18
+ | Interest Income/Expense as primary revenue, provisions for credit losses | **Banking / Financial Services** |
19
+ | Trade Spend / Gross-to-Net deductions, distribution costs, brand marketing | **FMCG / Consumer Goods** |
20
+ | R&D > 15% of costs, licensing/milestone revenue, regulatory costs | **Pharma / Life Sciences** |
21
+ | COGS = purchases + freight only, thin margins, FX prominent, commission lines | **Pure Trading / Sales** |
22
+ | Gross margin > 70%, hosting/infrastructure costs, subscription / recurring revenue | **SaaS / Services / OPEX-heavy** |
23
+ | COGS with manufacturing overhead + service / parts segments | **Manufacturing / Distributor** |
24
+
25
+ **If you cannot identify the business type from the data model alone**, follow "When the pattern doesn't fit" at the end: research, existing dashboards, or ask. Don't guess silently: the wrong cascade produces a polished, correctly formatted report that tells the wrong story.
26
+
27
+ ## Step 2: Map existing variables to the cascade
28
+
29
+ Search the model's variables for these common name patterns. **The patterns are illustrative, not literal names**: match them against the model's actual variable names, and read the members of a P&L-line dimension table from the live table. Never use a pattern as a member or variable name directly; the live name differs (for example `Gross margin` where the pattern says `Gross profit`).
30
+
31
+ - **Revenue**: `Revenue`, `Sales`, `Net sales`, `Turnover`, `Gross sales`, `Subscription`, `ARR`, `Fee income`, `Interest income`, `Licensing`, `Royalty`
32
+ - **Direct costs**: `COGS`, `Cost of sales`, `Cost of goods`, `Cost of revenue`, `Material costs`, `Purchase costs`, `Manufacturing costs`, `Freight-in`, `Service delivery`
33
+ - **Operating expenses**: `OPEX`, `SG&A`, `Payroll`, `Salary`, `Personnel`, `Rent`, `Marketing`, `Travel`, `Depreciation`, `D&A`, `R&D`, `Commission`, `Logistics`, `Distribution`, `Professional services`
34
+ - **Financial**: `Interest income/expense`, `Financial income/expense`, `FX gain/loss`
35
+ - **Tax & bottom line**: `CIT`, `Income tax`, `Net income`, `Net profit`, `EBT`
36
+ - **Subtotals (may already exist as calculated variables)**: `Gross profit`, `Gross margin`, `EBITDA`, `EBIT`, `Operating profit`, `NOPAT`, `Contribution margin`
37
+
38
+ ## Step 3: Identify gaps and create missing subtotals as measures
39
+
40
+ Compare the variables you found with the reference cascade for the business type (see "Reference cascades").
41
+
42
+ **When the user only wants an answer, do not write to the model:** compute a missing subtotal with a formula in the query itself, such as `SUM("Net Revenue") - SUM("COGS")`. Create measures only when you build a report the user asked for, and say which ones you will create before you write them: they land in the shared model, for everyone.
43
+
44
+ For a report, create each missing subtotal as a **measure**: a variable with `measure: true`, a formula and a number format. Through the API that is `POST /api/v3/entities/mutate` with:
45
+
46
+ ```json
47
+ {"created": [{"type": "VAR", "meta": {"name": "Gross Profit"}, "variable": {"measure": true},
48
+ "calculation": {"formula": "SUM(\"Net Revenue\") - SUM(\"COGS\")"},
49
+ "numberFormat": {"type": "NUMBER", "custom": false, "formatString": "#,##0.0,", "decimals": 1,
50
+ "polarity": "POSITIVE", "negatives": "SIGNED", "unit": "THOUSANDS", "currency": "EUR"},
51
+ "relations": {"folder": {"key": {"id": VARIABLES_FOLDER_ID, "type": "FOLD"}, "order": 1}}}]}
52
+ ```
53
+
54
+ `VARIABLES_FOLDER_ID` is the id of the root `Variables` folder. All eight `numberFormat` fields are required. The trailing comma in `formatString` scales to thousands (two commas: millions), and `unit` must agree with it. `currency` takes only `EUR`, `USD` or `HRK` and does not change how a `NUMBER` format renders (the `formatString` does): keep `EUR` unless the model is in USD or HRK.
55
+
56
+ **Formulas use quoted variable and member NAMES** (prefer names over the equivalent `$<gid>` form): `SUM("Net Revenue", "Versions">"Actual")`.
57
+
58
+ **Filter inside the formula when the underlying variable spans several versions and the measure should consider only one.** A subtotal like `SUM("Net Revenue") - SUM("COGS")` evaluated in a single-version context (the column of a sheet tagged with one version) is fine. But a measure like "AC – PL absolute" must filter inside: `SUM("Net Revenue", "Versions">"Actual") - SUM("Net Revenue", "Versions">"Plan")`. The rule of thumb: if the formula contains both `Actual` and `Plan` (or any cross-version arithmetic), filter; if it's a single-version sum that the column will scope, don't.
59
+
60
+ **Don't duplicate existing calculated variables.** If the model already has a hand-built `Gross Profit` / `EBITDA` / `EBIT` calculated variable (not a measure: a regular variable with `calculation.formula`), reuse it. A second `Gross Profit` next to a hand-authored one clutters the model and confuses users. Look the name up among the variables before you create any subtotal.
61
+
62
+ **Measure dimensional inheritance**: a measure has no dimensions of its own and inherits ALL dimensional context from the sheet row and column it is evaluated in. When a Gross Profit measure with formula `SUM("Net Revenue") - SUM("COGS")` is placed on a row in a column tagged `[Actual, Y2025]`, it computes `Revenue(Actual, 2025) - COGS(Actual, 2025)` automatically, which is why the filter-inside rule above only fires for cross-version arithmetic.
63
+
64
+ **Dimensionless measures and table expansion**: a measure with no dimensions in its formula can still be placed on a sheet row line whose `dimensionGenerationOptions.tableGids` names a table, such as countries (on legacy sheet rows, `tableTagId`). The sheet expands one row per member, and the measure evaluates within each member's context as long as the underlying variables (`Net Revenue`, `COGS`) have that dimension.
65
+
66
+ **If unsure which of two candidate variables fits, once the data checks are done (the sign of step 4, the magnitude, and that each compared version and period has data), just try one.** If it shows data, it works; if it is blank, swap. This is about picking between candidate variables, never a license to skip those checks.
67
+
68
+ ### Decision: existing variable vs new measure
69
+
70
+ - **Use an existing variable** if its name and dimensions match what you need. Confirm with its full definition (number format, measure flag) and, if you're unsure, a one-off evaluation of its magnitude.
71
+ - **Create a measure** only when no suitable variable exists or you need a derived subtotal (Gross Profit, EBITDA, EBIT, Net Income) for a report you are building; for an answer alone, use a formula.
72
+ - Don't overthink it: check, use if it exists, create if not. Move on.
73
+
74
+ ## Step 4: Validate the sign convention BEFORE building
75
+
76
+ This is the most important step in the whole flow. Get it wrong and the entire P&L is inverted.
77
+
78
+ **Check the expense sign.** Evaluate one expense variable (COGS is ideal) for an actual period with data, for example `SUM("COGS", "Versions">"Actual", "Years">"Y2025")`; the answer applies to every expense in the model. A positive result means expenses are stored as positive magnitudes, so subtotal formulas use **subtraction** (`SUM("Revenue") - SUM("COGS")`); a negative result means they are stored negative, so subtotals use **addition** (`SUM("Revenue") + SUM("COGS")`). Do this once per model. The sign convention is never itself a reason to stop: state the assumption in your answer. Ask only when the convention is MIXED within the same report: an existing subtotal formula that subtracts one cost row but adds another cannot be resolved silently.
79
+
80
+ **Avoid double-counting in hierarchies**: P&L position tables often have BOTH leaf items AND rollup parents (e.g. `Payroll`, `Rent`, `Marketing` as leaves AND `Total OPEX` as a parent rolling them up). In a single report or waterfall, **use one level only**: either the leaves OR the rollup, never both. Mixing them double-counts every leaf.
81
+
82
+ **Currency consistency**: in a multi-country model, use variables converted to one currency on cross-country reports. Never mix local currencies on the same chart. If no converted variable exists, create a measure: `SUM("<local var>") * SUM("<FX rate>")`.
83
+
84
+ ## Step 5: Order and mark the rows
85
+
86
+ Use `+` / `-` / `=` prefixes on row names: `+ Revenue` (income), `- COGS` (expense), `= Gross Profit` (subtotal). A line is `=` whenever it derives from lines above it in THIS cascade: if both `Gross sales` and `Net sales` appear, `Net sales` is `= Net sales` (it nets the discounts above), not `+`.
87
+
88
+ In a dashboard table, mark `=` rows as totals in the row's entry of the tile's `visualization.table.rowStyles`: `{"total": true, "bold": true, "showBorderTop": true, "borderTopColor": "#020810"}`.
89
+
90
+ **Prefix and polarity are two views of ONE decision: derive it from the cascade formula, then write both from it.** A row's polarity is `NEGATIVE` if an increase in its value worsens the bottom line, otherwise `POSITIVE`. The source of truth is the formula of the subtotal the row feeds: a row entering it with `-` is `NEGATIVE`; a row entering with `+` that is semantically a cost has its values stored negative and stays `POSITIVE`. Never derive polarity from the prefix you just wrote; that is circular. Final self-check before reporting: prefix and polarity must agree on every row, and a mismatch is a bug in your output.
91
+
92
+ | Prefix | Line type | `polarity` | Variance colour |
93
+ | ------ | ---------------------------------------------------------- | ------------ | ----------------------- |
94
+ | `+` | Revenue / income lines | `"POSITIVE"` | increase = green |
95
+ | `-` | Cost / expense lines AND cost-like deductions | `"NEGATIVE"` | increase = red (swap) |
96
+ | `=` | Subtotals (GP, EBITDA, EBIT, Net Income, Operating Profit) | `"POSITIVE"` | higher = better = green |
97
+ | `±` | Mixed lines (Net Adjustments, Financial Result) | `"POSITIVE"` | interpret in context |
98
+
99
+ - **Deductions that aren't named "cost"** are the rows most often missed: `Income tax`, minority interest, rebates / discounts / returns / credit notes inside net sales, provisions, write-offs, value adjustments. All are `-`; their polarity follows the rule below.
100
+ - **Totals are never `NEGATIVE`**, no matter how many costs compose them: more is always better on a subtotal.
101
+ - **`-` maps to `NEGATIVE` only when expenses are stored positive** (the sign check of step 4 is > 0). On a model that stores expenses negative, `NEGATIVE` would flip the colour twice and show a cost increase as green: keep `POSITIVE` there.
102
+ - **One row, one polarity**, identical across every variance and every tile of the report. A mix within one report is worse than no polarity at all, because the reader can't see it.
103
+ - **Where polarity lives**: on a measure you create, in its `numberFormat`. On an existing variable, set it per row on the tile (the row's `rowStyles` `numberFormat`), not on the variable: its model-level `numberFormat` is shared by every report that uses it. If the variable's own format should carry it, say so to the user rather than rewriting it.
104
+
105
+ Polarity never changes a displayed value, a formula or the data; it only decides which variance reads as good or bad. The one exception is an accumulating waterfall: there polarity flips each bar's sign for the bridge, measured from the first row, so start the bridge on a `POSITIVE` row and check the rendered bridge.
106
+
107
+ ---
108
+
109
+ ## Reference cascades
110
+
111
+ ### Manufacturing / Distributor
112
+
113
+ ```
114
+ + Net Revenue (often split: Product / Service / Parts)
115
+ - COGS (purchases, freight-in, warehousing, direct labor, service delivery)
116
+ = Gross Profit
117
+ - Selling Expenses (sales salaries, commissions, outbound freight, marketing)
118
+ - G&A (management, office, IT, insurance, professional fees)
119
+ - R&D (if applicable)
120
+ = EBIT
121
+ ± Financial Result (interest, FX gains/losses)
122
+ = EBT
123
+ - Income Tax
124
+ = Net Income
125
+ ```
126
+
127
+ Key KPIs: Gross margin by segment, COGS %, inventory turnover, service revenue %.
128
+
129
+ ### Pharma / Life Sciences
130
+
131
+ ```
132
+ + Product Revenue + Licensing/Royalty + Milestone/Collaboration
133
+ = Total Revenue
134
+ - Cost of Revenue (manufacturing, API, QC, packaging, royalties payable)
135
+ = Gross Profit (typically 65-85%)
136
+ - R&D (clinical trials, CRO costs, regulatory — often larger than COGS)
137
+ - SG&A (medical sales force, marketing, market access, G&A)
138
+ - Amortization of Intangible Assets (acquired drug IP)
139
+ = EBIT
140
+ ± Financial Result
141
+ = EBT → Net Income
142
+ ```
143
+
144
+ Key KPIs: R&D as % of revenue, gross margin, SG&A %, pipeline value.
145
+
146
+ ### FMCG / Consumer Goods
147
+
148
+ ```
149
+ + Gross Sales
150
+ - Trade Spend (listing fees, rebates, promotional allowances — 15-30% of gross)
151
+ = Net Revenue
152
+ - COGS (raw materials, packaging, manufacturing, co-packing)
153
+ = Gross Profit (typically 40-60%)
154
+ - Distribution & Logistics (warehousing, outbound freight, 3PL)
155
+ - Sales & Marketing (ATL/BTL, category management, sales force)
156
+ - G&A + R&D (small, 2-4%)
157
+ = EBIT
158
+ ± Financial → Tax → Net Income
159
+ ```
160
+
161
+ Key KPIs: Gross-to-Net ratio, gross margin, A&P %, distribution cost %, volume vs price/mix.
162
+
163
+ ### Pure Trading / Sales
164
+
165
+ ```
166
+ + Net Revenue
167
+ - Cost of Goods Purchased (purchase price, import duties, freight-in)
168
+ = Trading Margin (thin: 5-20%)
169
+ - Commission Expense
170
+ - Sales & Marketing
171
+ - G&A (credit insurance, banking/LC fees)
172
+ = EBIT (very thin: 2-5%)
173
+ ± Financial Result (FX gains/losses often material)
174
+ = EBT → Net Income
175
+ ```
176
+
177
+ Key KPIs: Trading margin, FX impact, commission %, working capital cycle.
178
+
179
+ ### SaaS / Services / OPEX-heavy
180
+
181
+ ```
182
+ + Subscription/Recurring Revenue + Professional Services + Usage/License
183
+ = Total Revenue
184
+ - Cost of Revenue (hosting, support, delivery — low)
185
+ = Gross Profit (typically 70-85%)
186
+ - R&D / Product Development (20-35% of revenue)
187
+ - Sales & Marketing (30-50% in growth phase)
188
+ - G&A
189
+ = EBIT (often negative in growth phase)
190
+ ± Financial → Tax → Net Income
191
+ ```
192
+
193
+ Key KPIs: Gross margin, R&D %, S&M %, Rule of 40, ARR growth.
194
+
195
+ ### Banking / Financial Services
196
+
197
+ ```
198
+ + Interest Income (loans, securities, interbank)
199
+ - Interest Expense (deposits, wholesale funding)
200
+ = Net Interest Income (NII)
201
+ + Non-Interest Income (fees, commissions, trading, wealth mgmt)
202
+ = Total Operating Income
203
+ - Provisions for Credit Losses
204
+ = Operating Income After Provisions
205
+ - Operating Expenses (personnel, IT, premises, regulatory levies)
206
+ = Operating Profit → Tax → Net Income
207
+ ```
208
+
209
+ Key KPIs: Net interest margin, cost-to-income ratio, ROE, NPL ratio, fee income %.
210
+
211
+ **Banking has NO traditional COGS.** Provisions for credit losses are the "cost of lending."
212
+
213
+ ---
214
+
215
+ ## When the pattern doesn't fit
216
+
217
+ 1. **Research the company**: search the web for `"<company name> annual report"` or `"<industry> income statement structure"`, if you have web access.
218
+ 2. **Look at the existing dashboards and sheets** for clues about the intended cascade, such as the variables on a flagship dashboard's tiles.
219
+ 3. **Ask the user** what P&L structure they expect.
220
+ 4. Build a custom cascade: the reference patterns are guides, not constraints.
@@ -0,0 +1,172 @@
1
+ ---
2
+ name: farseer-review-model
3
+ description: >-
4
+ Audit an existing Farseer model's structure against modelling rules, read-only, and report each finding with severity, location and fix: naming and locking (IN/OUT/IMPORT, readonly), module boundaries, the table graph and its diamonds, formula grain, hardcoded members and non-Actual versions, sparse formulas and dense cells, and, in a full audit, where computed values can be overwritten: unlocked formula variables on sheets, apps writing unlocked variables, FK-rewriting imports, and Constrained Light Top Down against sheet exposure. Use when the user asks to review, audit, QA or health-check a model, its naming, locking or structure. It changes nothing: the farseer-modify-model skill plans a fix, and questions about the numbers belong to farseer-analysis.
5
+ metadata:
6
+ version: "1"
7
+ domain: modeling
8
+ ---
9
+
10
+ # Review Farseer Model
11
+
12
+ ## When this skill applies
13
+
14
+ Before a model goes to its users, after a change, or as a periodic model health check. Do not use for writing or modifying the model — this skill is read-only.
15
+
16
+ A plain review runs Tier 1 (sections A–G). **A full audit** (the user asks for a full or deep audit, or where the model can be broken by use) runs Tier 1 **and** the Tier 2 risk-surface pass (section H), and produces the full report laid out under Expected output.
17
+
18
+ - Fixing what the review finds → the `farseer-modify-model` skill (risk tier, snapshot, impact, rollback). This skill writes nothing.
19
+ - Formula syntax → the `farseer-formulas` skill.
20
+ - Questions about the numbers themselves (a trend, a variance, its drivers) → the `farseer-analysis` skill.
21
+
22
+ ## Inputs to gather first
23
+
24
+ 1. **Tenant and session** — name the tenant on every call. Check that reads work: `farseer model --tables <tenant>`. If they don't, the `farseer-authenticate-to-tenant` skill reconnects. A saved `farseer model --json` file (for example a snapshot taken before a change) also works: run A–E, G and G2 on it, and mark F and H "not verified" unless live reads work too. #16 and the member counts of #35 need member rows, which a file holds only when it was taken with `--include-members`; otherwise mark them "not verified" too.
25
+ 2. **The model** — `farseer model --json <tenant> > model.json`, then search the file rather than printing it. Each variable carries `formula`, `tables` (its grain), `members` (its fixed members), `readonly`, `zConstraint`, `notes`, `description`, `folderPath`, `rollupType`, `dataType` and `numberFormat`; each table carries its columns, and an FK column names its target table in `foreignKeyTableName`. `folderPath` starts at the tenant's top-level folder.
26
+ - If the CLI prints `/model/export failed …; falling back to initTagMap`, that read has no fixed members, notes, folders or `zConstraint`: mark the checks that need them "not verified".
27
+ - If the read shows no formulas at all, read it again: the first export from a cold tenant can return every formula empty.
28
+ 3. **For a full audit, the sheets and the apps** — the sheet and app commands under Tools.
29
+ 4. **Reference material** — `naming-conventions.md`, `sparse-formulas-pattern.md` and `formula-grain-alignment.md` in the `farseer-build-model` skill hold these rules with their reasons.
30
+
31
+ In this skill a variable's grain is written `[Table, …]` and a fixed (pinned) member `[Table = Member]`; `farseer model --variable` prints fixed members as `Specific members:`.
32
+
33
+ ## Procedure
34
+
35
+ Walk through these checks. For each issue found, report **Severity** (Error / Warning / Info), **Location** (variable, table, sheet or app name), **Description**, **Fix**.
36
+
37
+ ### A. Structure (from the model export)
38
+ 1. Every variable's tables (`tables` in the export) are its grain; a variable with none holds a single cell, so confirm that is intended
39
+ 2. Links are FK columns on the tables: `farseer model --tables <tenant>` lists each table with the tables its FK columns point at
40
+
41
+ ### B. Naming convention — core
42
+ These naming and structure rules are recommended conventions, not platform rules: the platform does not check them, so the review applies them. A project with its own suffix convention (such as the underscore style, `_IN` / `_OUT` / `IMPORT_`) gets one "convention differs" note, not an Error per variable; read #6–8 with the project's own markers.
43
+
44
+ 5. `IMPORT` variables live in an `IMPORT` folder (`folderPath` ends in `IMPORT`; an existing `Import` folder is not a defect)
45
+ 6. Planner-writable variables end with ` IN` (space-separated)
46
+ 7. Only the model's final outputs end with ` OUT`
47
+ 8. Every variable without ` IN` has `readonly`
48
+ 9. Dimension tables are named by business meaning — **no** `S_` / `D_` prefix (retired 2026-W23; existing models still using it are NOT refactored, so an `S_…` table on an old model is not a finding). Per `naming-conventions.md` §6 in the `farseer-build-model` skill
49
+
50
+ ### C. Naming convention — recommended (flag, don't block)
51
+ 10. Functional prefix (`PL` / `EL` / `ASS` / `ASSG`) — not mandatory
52
+ 11. Folder set for UI tree placement
53
+
54
+ ### D. Module boundaries
55
+ 12. Folder/module structure of the model makes business sense
56
+ 13. Cross-folder references are intentional (read the formulas)
57
+ 14. ` OUT` suffix used only for model-level final outputs, not per-folder
58
+
59
+ ### E. Dimension graph (from the export)
60
+ 15. FK links form a sensible graph — no obvious cycles
61
+ 16. Cardinality (n:1) holds where known: each member's FK cell lists one target member; a cell listing several (as a year-to-date table does) makes the link n:m
62
+ 17. Flag multiple paths between two dimensions (diamond) for human review
63
+
64
+ ### F. Semantic checks (live, via explicit-tenant CLI reads)
65
+ 18. Variables referenced in formulas exist in the tenant
66
+ 19. Grains of referenced variables align with the using variable's grain
67
+ 20. No hardcoded dimension members in formulas — pin them in the grain with `[Dim = Member]` or expose as ` IN`-suffixed variable
68
+ 21. No circular calculation dependencies
69
+ 22. Notes on non-trivial variables — **recommendation, not a defect** (same posture as #27 below). Surface missing notes as advice, never as a failed check, and concentrate the advice where it earns its keep: ` IN` / ` OUT` variables and coded-ID names. **A variable that HAS a description is a real defect** — flag it: it renders as the row label. Owner: `naming-conventions.md` §2a in the `farseer-build-model` skill
70
+
71
+ ### G. Property hygiene
72
+ 23. Data type, rollup, number format consistent with what the formula produces
73
+ 24. Folder hierarchy reflects business structure, not technical
74
+
75
+ ### G2. Formula discipline (Tier 1)
76
+ 25. **No version other than `Actual` in formulas** — a formula referencing a specific non-Actual version (Plan, Budget, a named scenario) hardcodes version routing into a calculation. Flag it; version routing belongs in a version carrier read through a condition (`if(eq(carrier, 1), X)`, see #28), not in a formula that names the version.
77
+ 26. **Sparse discipline** — run the `sparse-formulas-pattern.md` checklist in the `farseer-build-model` skill (formulas that sow `0`/constants on null cells; bare comparators; removable `hasValue` guards).
78
+ 27. **Constrained Light Top Down (recommendation, not a defect)** — any **high-dimensionality** variable should have *Constrained Light Top Down* enabled so top-down entry doesn't materialize the full dense grid. Surface as a recommendation; it does not break the model.
79
+ 28. **Carrier products / broadcast+FK-in-one-product / dense-grain cap** — flag a `Versions`-carrier **product** (`X * carrier`) where the equivalent condition (`if(eq(carrier, 1), X)`) would do — the two are only equivalent when the carrier never stores a literal `0` (call that out if unverifiable from the model alone). Flag a single product that both broadcasts onto `Versions` **and** crosses an FK hop — split it (`formula-grain-alignment.md` §7, rules 1–2). Flag a `0 + X` used as a cross-grain lift where the result should stay sparse (phantom zeros — `sparse-formulas-pattern.md` "Cross-grain lifts"). For any variable whose grain looks wide, estimate the cells its formula will actually produce (operand cells × every member it broadcasts over, incl. `Versions` × periods) and flag any dense layout — tens of millions of cells is already the problem class, and the platform does not warn loudly (`formula-grain-alignment.md`, "Dense cell production"). Full catalogue + fix procedure: `formula-grain-alignment.md` §7 — route there instead of hand-fixing if several such findings appear together.
80
+
81
+ ### H. Risk surfaces (Tier 2 — only for a full audit)
82
+ Triggered when the model has a meaningful number of **unlocked, formula-bearing variables** (computes a value yet stays editable — the condition that makes overwrite damage possible). List those variables first, then:
83
+
84
+ 32. **Sheet vulnerability scan** — for each such variable, find every sheet it appears in and check the cell scope: row/column **locked** → ⚠️ WARNING (latent); **unlocked** → 🔴 DANGER (a planner can overwrite the computed value, bypassing the formula). Output a table of all WARNING + DANGER rows, one per (variable × sheet), **with each sheet's id and folder path**.
85
+ 33. **Import-job classification** — enumerate every app and the variables its import jobs write. Compare each job to the import-job bar (locked `IMPORT_` target, scope-encoding labels, argument-driven) and classify each written variable: **OK** (locked `IMPORT_`), 🔴 **CRITICAL** (writes into an unlocked variable — offer the lock fix), **Confusion risk** (`IMPORT_` left unlocked for sheet entry). One section per app.
86
+ 34. **Dimension-table FK posture** — for each import job touching dim tables: **additive** (append) is recommended; **FK-overwriting** is flagged, and **escalated** when a sheet also exposes that FK for editing.
87
+ 35. **Constrained Top Down check** — for every **input** variable (` IN` / entry), check `zConstraint` against its exposure. 🔴 **DANGER**: the variable is exposed for entry ABOVE its grain on any sheet (an aggregate/TD row, or a sheet that doesn't surface the full grain) and `zConstraint` is **false** — one aggregate write onto empty leaves fans a flat, even spread across the whole hidden grain (onto populated leaves it scales them proportionally — except at a node of a self-linked dimension, where it spreads evenly over the node and its descendants whatever they hold). ⚠️ **WARNING**: high dimensionality (many dims × many members — count the members) with `zConstraint` false, even if no sheet currently exposes it — the recommendation is flag ON for such variables. Also flag the inverse trap: `zConstraint` **true** but no sheet reaches the variable's full grain (drill or single-member filter pin) — constrained entry with nowhere to seed is **dead entry**, not safety. Output one row per (variable × sheet exposure) with the verdict and the fix (`zConstraint` on → the `farseer-modify-model` skill; grain exposure → the sheet's design).
88
+
89
+ See Expected output for the full report layout and table templates.
90
+
91
+ ## Tools to invoke
92
+
93
+ - Model (A–G2): `farseer model --json <tenant> > model.json` (Inputs). Search it for naming patterns (` IN"`, ` OUT"`, or the project's own markers, and `"readonly": false`) — **not** `S_`: the prefix is retired, so its absence is correct and its presence on an old model is legacy, not a defect. Search the formulas for a variable's name both quoted and bare: the export writes an identifier-shaped name without quotes
94
+ - One variable: `farseer model --variable "<Var>" <tenant>` — its tables, fixed members, rollup, data type, format, readonly flag and folder; `farseer model --variables <tenant>` lists them all
95
+ - Tables (§A, §E, #35): `farseer model --tables --include-members <tenant>` — each table with its member count and the tables its FK columns point at; `farseer model --table "<Table>" --json <tenant>` (or `FARSEER_TENANT=<tenant> farseer dimension details "<Table>" --json`) — one table's columns and member rows, where each FK cell lists its target members
96
+ - Sheets (§H): `farseer sheets list --json <tenant>` — every sheet's id, name and folder. Then per sheet, by its id (two sheets can share a name):
97
+ - `farseer sheets data <id> --json <tenant>` — columns (`variableId`, `readonly`), rows (`variable`, `readonly`) and each cell's `readonly` flag, which says whether a planner can type over the value (#32)
98
+ - `farseer sheets rows <id> --json <tenant>` — each row's variable, members, table and `readonly` flag (#32, #35)
99
+ - `farseer sheets show <id> --json <tenant>` — the custom columns (`accountTagId` is the variable's id, `tableColumnIds` the table columns a column shows, such as an FK open for editing) and `rows.filters` (each filter's `tableId` and selected `dimensionIds`) (#34, #35)
100
+ - A column names its variable only by id: `farseer variables list --json <tenant>` gives every variable's id as `gid`. If it warns `Variable ids unavailable`, report such a column by sheet, column name and variable id
101
+ - Apps (#33–34): `farseer app list --details <tenant>` — every app with its scripts and arguments; `farseer pull <org> <tenant>` downloads the scripts into `farseer-apps/<tenant>/` under the current folder, so run it in a scratch folder, then search the scripts for the variables and tables they write
102
+
103
+ ## Expected output
104
+
105
+ **Tier 1 (review):** ordered list of issues — Errors → Warnings → Info, each with severity, location, description, fix; summary counts.
106
+
107
+ **Tier 2 (full audit):** additionally, the full report below — the sheet vulnerability table (WARNING/DANGER with sheet ids), per-app import-job classification (OK/CRITICAL/Confusion), dimension-table FK posture, the Constrained Top Down table (Check 35: per input variable × sheet exposure), and a recommendations section (rename/lock offers, sparse fixes).
108
+
109
+ ### Report layout
110
+ 1. **Header** — tenant, read time, model size (variable / sheet / app counts).
111
+ 2. **Tier 1 summary** — counts per severity.
112
+ 3. **Tier 1 findings** — Errors → Warnings → Info.
113
+ 4. **Tier 2** (if triggered):
114
+ - 2a Sheet vulnerability table (all WARNING + DANGER, with sheet ids).
115
+ - 2b Import-job classification per app (OK / CRITICAL / Confusion).
116
+ - 2c Dimension-table FK posture.
117
+ - Check 35 Constrained Top Down table (per input variable × sheet exposure).
118
+ 5. **Recommendations** — Constrained Light Top Down candidates, rename/lock offers,
119
+ sparse fixes. Ordered by impact.
120
+
121
+ Read-only throughout — the report proposes fixes, it does not apply them.
122
+
123
+ ### 2a. Sheet vulnerability table
124
+
125
+ For each unlocked, formula-bearing variable, find **every sheet** where it appears,
126
+ and check whether the row/column it sits in is locked:
127
+
128
+ | Cell state in sheet | Severity | Why |
129
+ |---|---|---|
130
+ | Row/column **locked** | ⚠️ WARNING | the computed value is safe today, but the variable's lock is the only thing missing — a latent risk |
131
+ | Row/column **unlocked** | 🔴 DANGER | a planner can overwrite the computed value directly on this sheet; the formula is silently bypassed for that cell |
132
+
133
+ Output a table of **every WARNING and DANGER**, one row per (variable × sheet), with
134
+ each sheet's **id and folder path**. This table is a required section of the report.
135
+
136
+ | Variable | Sheet | Cell scope | Severity | Sheet id |
137
+ |---|---|---|---|---|
138
+ | `Gross Margin` | Sales plan by region (Sheets / Planning) | column "Plan" unlocked | 🔴 DANGER | 412 |
139
+ | `Gross Margin` | Group summary (Sheets / Reports) | row locked | ⚠️ WARNING | 377 |
140
+
141
+ ### 2b. Import-job variable classification (per app)
142
+
143
+ Enumerate every app and every variable its import jobs write. Compare each job
144
+ against the import-job
145
+ quality bar (locked `IMPORT_` target, scope-encoding labels, argument-driven) and
146
+ note deviations. Classify each written variable:
147
+
148
+ | Class | Condition |
149
+ |---|---|
150
+ | **OK** | locked `IMPORT_` target |
151
+ | 🔴 **CRITICAL** | import writes into an **unlocked** variable — a planner can overwrite the feed and re-imports fight the edit; offer a rationale + the fix (lock it) |
152
+ | **Confusion risk** | an `IMPORT_` variable left **unlocked for sheet entry** — it is both a feed and an input, which confuses ownership |
153
+
154
+ Output one section per app, listing all written variables with their class.
155
+
156
+ ### 2c. Dimension-table FK posture
157
+
158
+ For each import job that touches dimension tables, determine whether it is:
159
+
160
+ - **Additive** (appends new members) — the **recommended** posture; flag only if
161
+ noteworthy.
162
+ - **FK-overwriting** (rewrites foreign keys every run) — flag it. **Escalate** when
163
+ a sheet also exposes that same FK for editing: the job will silently rewrite a key
164
+ the planner just set (or vice-versa), and the two fight every cycle.
165
+
166
+ ## Constraints
167
+
168
+ - Do **not** modify the tenant or the user's files; write only scratch files (the export, the pulled scripts). Output only.
169
+ - Run only reads: no command that creates, updates, deletes, pushes or runs anything on the tenant. A fix goes to the `farseer-modify-model` skill.
170
+ - Do **not** invent symbols. If you don't see a variable in the model, say so — don't assume it exists.
171
+ - If live-tenant reads are unavailable (no CLI session), mark live-only checks (F.18–22, H) as "not verified" rather than skipping them silently.
172
+ - Recommendations (Constrained Light Top Down, missing notes, renames) are advisory — present them as such; do not present them as defects that fail a review.
@@ -0,0 +1,102 @@
1
+ ---
2
+ name: farseer-run-apps
3
+ description: Find, inspect and run Farseer apps, the configured imports, recalculations, exports and integrations that run on the tenant's job runner. Covers matching the app the user means, reading its expected arguments, collecting every required input before a run, starting the run, and reporting it without claiming it finished. Use when the user asks to run, start or launch something by name, or asks what an app needs; an app is not a variable or a table. To write a Simple Pipeline, or to run one you are building or changing, use the `pipeline-authoring` skill instead.
4
+ metadata:
5
+ version: "1"
6
+ ---
7
+
8
+ # Running Farseer apps
9
+
10
+ An app is a runnable unit configured in a Farseer workspace: an import, a recalculation, an export or an integration. It has a name, an optional description, the arguments it expects and a status. Someone starts it with values for its arguments; it then runs in the background on the tenant's job runner and writes its results back to Farseer. Paths below are under `/api/v3`.
11
+
12
+ **An app is not a model variable or table.** When the user names something that is not in the model but treats it as runnable, look it up among the apps (steps 1 and 2) before you call it unknown.
13
+
14
+ A request about an app is one of two kinds:
15
+
16
+ - **Inspect**: the user wants the list of apps, or what inputs an app needs. Do steps 1 and 2, report what you found, and stop. Start nothing.
17
+ - **Run**: the user wants the app run, started or launched. Do all five steps.
18
+
19
+ ## The rule that matters most: never start an app with a required input missing
20
+
21
+ **Do not start an app until every required input has a value.** A required input is an expected argument that is not `fixed` and has no usable `defaultValue`. If one is still missing after you have checked the user's request and the conversation, ask the user for it and stop: do not start the app, do not substitute a placeholder, do not pass an empty value, and do not report "inputs used: none". An app run with a wrong or missing input does real work, possibly destructive. This holds even where your other instructions tell you not to ask the user questions.
22
+
23
+ When inputs are missing, your whole turn is asking for them. The app is started only on a later turn, once the user has given the values. Never ask and start in the same turn.
24
+
25
+ ## 1. Find the app
26
+
27
+ List the apps (`GET /remoteJobs`; from the CLI, `farseer app list --details` lists them with their description and status) and match the request to one:
28
+
29
+ - Match on the `name`, and on the `description` when there is one. A shortened or paraphrased name should match the closest app.
30
+ - If exactly one app plausibly matches, use it.
31
+ - If **several** plausibly match, ask the user which one they mean and list the candidates; do not guess.
32
+ - If **none** matches, say you could not find an app by that name and, if it helps, name a few apps that exist.
33
+ - If the app's `status` is `UNAVAILABLE`, say it cannot run right now and stop.
34
+ - If its `status` is `QUEUED` or `RUNNING`, a run of it is already waiting or in progress. Another run would wait in the job runner's queue and then do the same work again. Tell the user, and start another only if they want one.
35
+
36
+ ## 2. Read its arguments
37
+
38
+ Read the full app: `GET /remoteJobs/{id}`, or from the CLI `farseer tool call farseer_get_app --tenant TENANT --args '{"appName": "APP"}'` (`appId` instead when names collide), which lists the inputs under `arguments` with the same fields except `hasSavedValue`. Each expected argument is one input:
39
+
40
+ - `name`: the argument's name.
41
+ - `dataType`: `"string"` or `"boolean"`.
42
+ - `defaultValue`: the value used when the user gives none; it may be absent.
43
+ - `options`: when present, a closed list of allowed string values. Treat it as a choice.
44
+ - `fixed`: when true, the workspace sets the value and the user cannot change it. **Never ask about a fixed argument** and never show it.
45
+ - `secret`: when true, the value is sensitive: a password, a token, a key. Never show its `options` or any value of it.
46
+ - `hasSavedValue`: on a secret, true when the workspace already stores a value for it. The value itself is never returned.
47
+
48
+ The full app keeps secrets in plain text: a secret argument's `options` can be the secret itself, and a preset's `runArguments` can pin one. When you read an app, print only what you need: filter out the `options` of every `secret` argument and every secret value inside a preset before printing (with `jq` or a short script), so no secret reaches your output, the conversation or the user.
49
+
50
+ An empty list of arguments means the app takes no input. Do not conclude "no inputs" from a read you are unsure of: read the app again, because running an app with the wrong inputs costs a lot.
51
+
52
+ An app may also have `predefinedActions`: named presets, each with `runArguments` that pin values by argument name. These can hold secret values in plain text: never show, repeat or copy one. When the user names a preset, use its values for the arguments it pins, unless it pins a secret: then do not start it yourself, because an empty slot would run with the app's own saved secret rather than the preset's. Ask the user to start that preset in Farseer.
53
+
54
+ ## 3. Decide each value, and stop to ask if a required one is missing
55
+
56
+ First check step 4 for whether you can start the run at all. If you cannot, still work out which inputs are missing, but do not ask for secret values: the user enters those when they start the app in Farseer.
57
+
58
+ Go through every expected argument, in order, and classify it:
59
+
60
+ - `fixed` → do not ask and do not infer. The workspace uses its own value whatever you send; put an empty string `""` in its slot.
61
+ - Otherwise, a value the user clearly gave, in the request or earlier in the conversation → use it.
62
+ - Otherwise, a `defaultValue` → you may use it without asking.
63
+ - Otherwise → the argument is **required and missing**. Add it to the list to ask for.
64
+ - `secret` and not given explicitly by the user → **always** add it to the list, even if something in the context looks like the value. Never infer a secret. The one exception: a secret whose `hasSavedValue` is true runs with its saved value when its slot is `""`, so ask for it only if the user wants a different value.
65
+
66
+ **Then branch. This is the gate:**
67
+
68
+ - **The list is not empty:** stop, and start nothing this turn. Ask the user for exactly those inputs, then end your turn and wait for the answer. Name each input by its purpose; for an argument with `options`, give the allowed choices, except for a secret, which you ask for by purpose only; for a `boolean` argument, ask a plain yes-or-no question. Do not start the app, do not build the argument list ahead, and do not say the app started. On the user's next turn, with the values in hand, go on from step 4.
69
+ - **The list is empty:** every input has a value; go on to step 4.
70
+
71
+ The server does not refuse an empty free-text value: it runs the app with an empty string. This gate is the only thing that stops a run with a missing input.
72
+
73
+ Validate before you start the app:
74
+
75
+ - A `boolean` value is the **string** `"true"` or `"false"`, in lowercase. Turn a yes or no answer into one of them.
76
+ - A value for an argument with `options` is exactly one of those options.
77
+
78
+ ## 4. Start the run
79
+
80
+ A run takes its arguments as a **positional list of strings in the order of the expected arguments**, one entry per expected argument, with `""` for a fixed argument and for a secret that keeps its saved value. It is a list, not a map from name to value.
81
+
82
+ How you start it depends on what your environment gives you:
83
+
84
+ - **With access to the Farseer API**, through an SDK client or a helper your environment provides: `POST /remoteJobs/{id}/run` with the body `{"arguments": ["...", "..."]}`. It answers `202` with a `runUuid` once the run is queued.
85
+ - **With only the `farseer` CLI**, the one command that starts a run on the tenant is `farseer pipeline run`, for a Simple Pipeline you are building (see the `pipeline-authoring` skill). For any other app you cannot start the run. `farseer run` and the `farseer_run_app` tool run the app's code on this machine with your own credentials, which is a different run from the job runner's; never use them in place of one. Give the user the app's name and the values you decided on, leaving out every secret, and ask them to start it in Farseer. Say plainly that you did not start it.
86
+
87
+ ## 5. Report back
88
+
89
+ A started app runs in the background and returns no result. Once the run is accepted:
90
+
91
+ - Tell the user the app has started, and restate the values it runs with. Leave out every `secret` and every `fixed` argument.
92
+ - Point the user to the app's run history to follow its progress and see the outcome. If the start gave you a run id, the run is in `GET /remoteJobs/{id}/remoteJobRuns` under that `uuid`, with a `status` of `QUEUED`, `RUNNING`, `FINISHED` or `ERROR`.
93
+ - Do **not** claim the app finished, and do not report results you do not have: you only know it started.
94
+
95
+ ## When the start fails
96
+
97
+ Read the error's message, then tell the user what happened in terms of the app and its inputs. Pass on what concerns them, such as a refused value or a part of the app's setup that is missing; for anything about the job runner, say only that apps cannot run right now.
98
+
99
+ - **Forbidden (403):** usually the user may not run that app. The same status also means the job runner is not connected: then no app can run right now, and it is not about the user's access. An app deleted since you listed it also answers 403, so when the message is not about the job runner, list the apps again before you tell the user they lack access.
100
+ - **Not found (404):** the app no longer exists. List the apps again and reconcile.
101
+ - **Bad request (400):** the app cannot run as it is configured, or one of the values was refused. Say what is wrong and stop. Do not start the app again, not even with a value you corrected yourself: a value that must change is the user's to give (step 3).
102
+ - **Anything else:** say the app could not be started right now and ask the user to try again later.
@@ -4,12 +4,12 @@ description: Author all new repeatable Farseer data pipelines with Simple Pipeli
4
4
  metadata:
5
5
  version: "1"
6
6
  minimum-cli: "1.14.2"
7
- engine-profile: "3.2"
7
+ engine-profile: "3.3"
8
8
  ---
9
9
 
10
10
  # Pipeline authoring
11
11
 
12
- Pipeline authoring for simple-pipelines 3.2, the engine line in the runner image this CLI was released with. Patch releases keep the grammar, so any 3.2 engine runs what this skill describes.
12
+ Pipeline authoring for simple-pipelines 3.3, the engine line in the runner image this CLI was released with. Patch releases keep the grammar, so any 3.3 engine runs what this skill describes.
13
13
 
14
14
  ## What this is
15
15
 
@@ -54,7 +54,7 @@ Submit once after sync and save the UUID receipt. Inspect that UUID after reconn
54
54
 
55
55
  The backend records each run before dispatch and answers with its run UUID. The tenant's jobrunner must be 3.6.0 or newer: an older one cannot keep the run id the backend assigns, so the backend refuses to send it the run and says so, and no run starts. A 3.0 pipeline keeps each extract's file for 30 days in the backend's payload area, which needs a backend that has it, storage that can sign download and upload links, and a runner key that is a super user's or holds CLASS.REMOTE_JOB.RUN_AS_SERVICE; without them the first extract fails. Reading datasets, their versions and download links needs the right to update jobs (CLASS.REMOTE_JOB.UPDATE) or the Data Hub permission (FEATURE.DATA_HUB); `init`, `check`, `query` and `versions` rely on it. `restore` needs the right to update jobs; creating or deleting datasets stays with super users and the runner. Download links, restores and other dataset changes made by a person are recorded in the audit log. A permission refusal from `check` is a setup issue to report to the setup owner.
56
56
 
57
- `check` reads the prepared job, its runner image, whether a newer CLI was released with the tenant's runner image (`cli-version`, pending means update before authoring), and the output manifests, then probes the first Parquet file using signed HTTPS access, or through the API when the CLI runs with an agent turn key, because an agent sandbox can reach only the API. This CLI authors for exactly one engine: the one inside the runner image it was released with. Only jobs already using a Simple Pipelines runner are eligible for image pinning. TypeScript, other runner families and an unknown or inherited image are refused by init, source sync and run; use the existing app tools and preserve the app. The CLI never changes a job's image on its own. A Simple Pipelines job on an older released image is reported as failed: `run`, `pull` and reads still work on its own image, but `push` is refused (`RUNTIME_UPGRADE_REQUIRED`) until the job is upgraded with `upgrade-runtime` (CLI: `farseer pipeline upgrade-runtime`), which moves it to this CLI's image and reports where it moved from. Upgrading changes the engine for everyone on that tenant and, on a scheduled job, for the next scheduled run, so ask the user before upgrading, then `run` once and fix whatever the newer engine's preflight rejects. A pipeline written for simple-pipelines 2.x never passes it: split every extract into `<name>_raw` and a parse step (Authoring rules below) and push the split right after the upgrade, before the job runs again, because every run from the upgrade on, scheduled ones included, uses this engine and fails until the split is pushed. A `main.py` that names no `store_type` writes to Farseer Files on older engines and to datasets on newer ones, so before upgrading such a job, add `store_type=StoreType.FARSEER_FILES` to the local `main.py` unless the user has confirmed it is ready for datasets, and push it right after the upgrade, before the job runs again; an explicit store works on every engine. A job on a moving tag such as `latest`, or on a digest, is reported as pending and left as it is: `upgrade-runtime` refuses it, and each run reports the engine it started on (`engine` in `inspect`). A job on a newer released image is reported as pending: it runs and accepts pushes, but update the CLI to author what the newer engine added. No job is ever moved down. A dataset declared under `Models/` is created by the engine on the first run, so init and check report a dataset that does not exist yet as pending, not as an error; an extract (`<name>_raw`) stores a payload and a load writes no dataset, so those two stay pending after the first run as well, which is expected; after the first run, rerun `init jobId=<id> force=true` to record the new dataset IDs (a rerun for the same job and folder keeps the setup record, declared config files and author), and the profile's `datasetIds` lists the outputs recorded so far. No published version means read verification stays pending until the first prepared run. The setup record (owner, evidence, checkedAt, retentionDays, otherWritersExcluded=true, runtimeVerified=true) is the owner's statement, not an API-verified fact: do not invent it, and reconfirm it after setup changes. `readyForAcceptance` does not establish source replay, reconciliation or real-client acceptance.
57
+ `check` reads the prepared job, its runner image, whether a newer CLI was released with the tenant's runner image (`cli-version`, pending means update before authoring), the step descriptions (`step-descriptions` warns, and never blocks, when a step has no `description:` or one over 300 characters), and the output manifests, then probes the first Parquet file using signed HTTPS access, or through the API when the CLI runs with an agent turn key, because an agent sandbox can reach only the API. This CLI authors for exactly one engine: the one inside the runner image it was released with. Only jobs already using a Simple Pipelines runner are eligible for image pinning. TypeScript, other runner families and an unknown or inherited image are refused by init, source sync and run; use the existing app tools and preserve the app. The CLI never changes a job's image on its own. A Simple Pipelines job on an older released image is reported as failed: `run`, `pull` and reads still work on its own image, but `push` is refused (`RUNTIME_UPGRADE_REQUIRED`) until the job is upgraded with `upgrade-runtime` (CLI: `farseer pipeline upgrade-runtime`), which moves it to this CLI's image and reports where it moved from. Upgrading changes the engine for everyone on that tenant and, on a scheduled job, for the next scheduled run, so ask the user before upgrading, then `run` once and fix whatever the newer engine's preflight rejects. A pipeline written for simple-pipelines 2.x never passes it: split every extract into `<name>_raw` and a parse step (Authoring rules below) and push the split right after the upgrade, before the job runs again, because every run from the upgrade on, scheduled ones included, uses this engine and fails until the split is pushed. A `main.py` that names no `store_type` writes to Farseer Files on older engines and to datasets on newer ones, so before upgrading such a job, add `store_type=StoreType.FARSEER_FILES` to the local `main.py` unless the user has confirmed it is ready for datasets, and push it right after the upgrade, before the job runs again; an explicit store works on every engine. A job on a moving tag such as `latest`, or on a digest, is reported as pending and left as it is: `upgrade-runtime` refuses it, and each run reports the engine it started on (`engine` in `inspect`). A job on a newer released image is reported as pending: it runs and accepts pushes, but update the CLI to author what the newer engine added. No job is ever moved down. A dataset declared under `Models/` is created by the engine on the first run, so init and check report a dataset that does not exist yet as pending, not as an error; an extract (`<name>_raw`) stores a payload and a load writes no dataset, so those two stay pending after the first run as well, which is expected; after the first run, rerun `init jobId=<id> force=true` to record the new dataset IDs (a rerun for the same job and folder keeps the setup record, declared config files and author), and the profile's `datasetIds` lists the outputs recorded so far. No published version means read verification stays pending until the first prepared run. The setup record (owner, evidence, checkedAt, retentionDays, otherWritersExcluded=true, runtimeVerified=true) is the owner's statement, not an API-verified fact: do not invent it, and reconfirm it after setup changes. `readyForAcceptance` does not establish source replay, reconciliation or real-client acceptance.
58
58
 
59
59
  ## Authoring rules
60
60
 
@@ -64,7 +64,7 @@ A source with no built-in type: a plain HTTP(S) API is `extract.type: http` (`Ht
64
64
 
65
65
  Parse: a `type: parse` step named `<name>` with `deps: [<the extract>]` reads the payload into the dataset. It names exactly one of `parse.format` (`csv`, `xlsx`, `json` or `parquet`; `parquet` for a source that hands back rows rather than a file, such as `sql_database`, `business_central` or `source: datasets`) or `parse.script` (an `@parse` function in `Code/`), with read options in the block named for the format, such as `csv: {decimal: ","}`. The parse step carries the dataset's `schema:`, quality rules and `write_mode`/`merge_keys`. Every extract must be read by a parse step, and only a parse step may read an extract: a transform, load or export with an extract in its `deps` fails the run before any step executes.
66
66
 
67
- Transform: choose SQL first (`engine: duckdb` with inline `transform.query`, never a SQL file), then `engine: ibis` with an `@ibis_transform` script when the logic needs Python to compose, and `engine: python` (`@transform`, pandas) only for work with no lazy form, because it is the one surface that holds whole frames in memory. Always write `engine:`; the default is `python`. Section 3 of `topic=practices` has the rules. A script transform names its `Code/` script in `transform.script`; missing code, compile errors and invalid definitions fail before extraction when the pipeline policy is enabled. Declare `deps`, add quality checks, and reconcile the agreed business scope. Folder names under `Models/` become dataset namespaces. Output versions are candidates until published, failed quality checks do not publish the failed candidate, and publication is per dataset, so a later failure can leave earlier effects in place.
67
+ Transform: choose SQL first (`engine: duckdb` with inline `transform.query`, never a SQL file), then `engine: ibis` with an `@ibis_transform` script when the logic needs Python to compose, and `engine: python` (`@transform`, pandas) only for work with no lazy form, because it is the one surface that holds whole frames in memory. Always write `engine:`; the default is `python`. Section 3 of `topic=practices` has the rules. When a SQL step should stop because the data isn't what it needs, call `fail_step('…')` with a message the client can act on, saying what is wrong and what to do, never `error()`: the client reads `fail_step`'s message as the step's failure, and `error()` only as "the app's own code failed". A script transform names its `Code/` script in `transform.script`; missing code, compile errors and invalid definitions fail before extraction when the pipeline policy is enabled. Declare `deps`, add quality checks, and reconcile the agreed business scope. Folder names under `Models/` become dataset namespaces. Output versions are candidates until published, failed quality checks do not publish the failed candidate, and publication is per dataset, so a later failure can leave earlier effects in place.
68
68
 
69
69
  Load: the engine's full surface is available, with `load.target: farseer` and `load.farseer.cells[].source_dataset` naming a dependency. Each `mapping.variables[]` entry has `source_column`, `target_variable` and `fixed_dimension_members`; `mapping.dimension_tables` maps a column onto a dimension. `options.overwrite_cells: true` repairs the same coordinates on a rerun; it does not erase omitted rows or old mappings. `undo_previous: true` (which requires at least one `labels` entry) undoes, after the new import commits, every earlier import job that carries all the same labels, so rows that left the source leave the model; a failed undo is logged as a warning, not raised. `create_missing_members: true` lets the import job create members that mapped columns name but the model lacks; it does not create `fixed_dimension_members`, which must already exist or be written by a dimension load earlier in the run. On a production model a created member is a permanent change, so say so before running. Dimension-table loads and exports are allowed. Statically, the only hard refusals are credentials in YAML and SQL files.
70
70
 
@@ -82,6 +82,8 @@ def sales_lines_clean(erp_sales_lines, *, args):
82
82
 
83
83
  Use a `LEFT JOIN` to a mapping and flag the rows that found no match. An `INNER JOIN` drops them silently. Keep mappings as data, a Files table or a model attribute, rather than a `CASE` copied into several queries.
84
84
 
85
+ **Stop a SQL step with `fail_step('…')`, never `error()`.** When the data isn't what the step needs, call `fail_step` saying what is wrong and what the client does next: `fail_step('No rate for APAC. Add it to the rates sheet and run again.')`. The client reads it as the step's failure; `error()` reads only "the app's own code failed". Put the call where the query reads it (section 5).
86
+
85
87
  ## 4. Writing schemas
86
88
 
87
89
  Declare a `schema:` on every parse step and transform, listing every column the dataset keeps, each with a `type`. The schema is the dataset's contract with whatever reads it. The one exception is a bronze parse step that deliberately captures a source whole.
@@ -131,7 +133,7 @@ quality_rules:
131
133
  - `isin` on the period columns set to the run's period.
132
134
  - **Reconcile in a transform.** A rule cannot compare two datasets, and `custom__sum_equals` and `custom__compare` work per row. Write a small transform that totals both sides per period into one row, assert it with `custom__compare`, and list it in the gold dataset's `deps`. A failed total then stops gold, and the load with it.
133
135
  - **Severity.** `error`, the default, is for structural garbage where loading is pointless; `warn` is for findings to report; the review gate (section 7) is for anything a person should decide.
134
- - **A SQL `error()` guard must be read.** DuckDB drops a column or CTE that the final `SELECT` never uses, and the `error()` inside it with it, so `... CROSS JOIN guard` alone never fails. Use the guard in the `WHERE` (`WHERE guard.g IS NULL`) or in a selected column. Prefer a quality rule when one can say it.
136
+ - **A SQL guard must be read.** DuckDB drops a column or CTE that the final `SELECT` never uses, and the `fail_step()` inside it with it, so `... CROSS JOIN guard` alone never fails. Use the guard in the `WHERE` (`WHERE guard.g IS NULL`) or in a selected column. Prefer a quality rule when one can say it.
135
137
  - **Regexes run on RE2:** no lookahead or backreferences.
136
138
  - **Any rule loads the whole dataset** to validate it.
137
139
 
@@ -316,7 +318,16 @@ Only a `sql_database` extract with `cursor_column`, on `ICEBERG`, reads incremen
316
318
  | Large immutable event log | `ICEBERG`, `append`, its own pipeline | Cursor on a sequence assigned at commit | A text or transaction-start timestamp cursor; `append` on a source that edits rows |
317
319
  | Large records that change, with `updated_at` | `ICEBERG`, `upsert` on a stable business id, its own pipeline | Cursor on a commit-time `updated_at`, plus a periodic rebuild to drop rows deleted at the source | `append`; wide composite keys; reading by position |
318
320
 
319
- ## 9. Verify
321
+ ## 9. What the client reads: descriptions and log lines
322
+
323
+ A client reads two things a pipeline's author writes: each step's description, and the run log. Both are written for them, not for the next engineer.
324
+
325
+ - **Every step has a `description:`.** The client reads it in the step's panel on the Pipeline tab. Say what the step does and any rule needed to judge its result, in plain words and at most about 300 characters: "Sums the monthly sales per cost centre; a centre with no sales that month is left out." Leave build details out: engines, joins, why the query is shaped as it is. Those go in comments. `check` warns on a step with no description or a longer one.
326
+ - **Log through the logger the package hands you:** `logger` in a transform or parse script, and `app_logger()` in `main.py`. What it logs at INFO, WARNING or ERROR is shown, as written, in the run log's plain view, which is the view the client reads, so write it for them: what happened and, for a warning, what to do. DEBUG is for engineers and shows only in the technical view, as do `print` and `logging.getLogger`.
327
+ - **A step that stops on purpose tells the client why:** `fail_step('…')` in SQL (section 3), `PipelineError(…, informative='…')` in a script.
328
+ - **Log a moment the client should know about, not progress.** The engine already says when each step starts and finishes and how many rows it read or prepared. A line of your own says what only your code knows: a rate it applied, rows it set aside and why.
329
+
330
+ ## 10. Verify
320
331
 
321
332
  - **Before the first run:** run `check`, confirm every model name with the model tools, and run the extracts and their parse steps once. Then test each SQL transform with `query` against the datasets the parse steps published, asking for shapes (`DESCRIBE`, `COUNT`, `SUM`, `GROUP BY ... HAVING count(*) > 1`) rather than rows.
322
333
  - **After every run:**
@@ -326,7 +337,7 @@ Only a `sql_database` extract with `cursor_column`, on `ICEBERG`, reads incremen
326
337
  - Rerun the same slice and confirm nothing changed.
327
338
  - Report what you verified, with run and version identifiers, and what you did not.
328
339
 
329
- ## 10. Anti-patterns
340
+ ## 11. Anti-patterns
330
341
 
331
342
  - A transform without `engine:`, or pandas doing set-based work.
332
343
  - Logic in the load step or in `main.py`; reading data or calling APIs from `main.py`.
@@ -338,3 +349,4 @@ Only a `sql_database` extract with `cursor_column`, on `ICEBERG`, reads incremen
338
349
  - Labels from unnormalised arguments, or two loads sharing labels.
339
350
  - Transforms that read the environment or the clock.
340
351
  - Comments carrying dates, people's names, ticket numbers or runner versions. Say what the code relies on.
352
+ - A step without a `description:`, or log lines through `print` that the client never sees.