farseer-cli 1.18.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.
- package/README.md +33 -10
- package/dist/commands/app.js +42 -3
- package/dist/commands/app.js.map +1 -2
- package/dist/commands/apps.js.map +0 -1
- package/dist/commands/cells.js +120 -85
- package/dist/commands/cells.js.map +1 -2
- package/dist/commands/code.js.map +0 -1
- package/dist/commands/config.js.map +0 -1
- package/dist/commands/dashboards.js +246 -12
- package/dist/commands/dashboards.js.map +1 -2
- package/dist/commands/diff.js.map +0 -1
- package/dist/commands/dimensions.js +52 -27
- package/dist/commands/dimensions.js.map +1 -2
- package/dist/commands/docs.js +82 -0
- package/dist/commands/docs.js.map +6 -0
- package/dist/commands/files.js +49 -0
- package/dist/commands/files.js.map +2 -3
- package/dist/commands/folders.js +76 -0
- package/dist/commands/folders.js.map +6 -0
- package/dist/commands/formula.js +38 -30
- package/dist/commands/formula.js.map +1 -2
- package/dist/commands/install.js +32 -30
- package/dist/commands/install.js.map +2 -3
- package/dist/commands/list.js.map +0 -1
- package/dist/commands/login.js +3 -3
- package/dist/commands/login.js.map +1 -2
- package/dist/commands/logout.js.map +0 -1
- package/dist/commands/mcp-server.js.map +0 -1
- package/dist/commands/model.js +30 -5
- package/dist/commands/model.js.map +2 -3
- package/dist/commands/pipeline.js.map +0 -1
- package/dist/commands/pull.js +1 -1
- package/dist/commands/pull.js.map +1 -2
- package/dist/commands/push.js +6 -4
- package/dist/commands/push.js.map +1 -2
- package/dist/commands/refresh.js.map +0 -1
- package/dist/commands/run.js.map +0 -1
- package/dist/commands/sheets.js +289 -52
- package/dist/commands/sheets.js.map +1 -2
- package/dist/commands/skills.js +157 -0
- package/dist/commands/skills.js.map +6 -0
- package/dist/commands/status.js.map +0 -1
- package/dist/commands/tool.js.map +0 -1
- package/dist/commands/variables.js +246 -82
- package/dist/commands/variables.js.map +1 -2
- package/dist/commands/whoami.js.map +0 -1
- package/dist/index.js +117 -23
- package/dist/index.js.map +1 -2
- package/dist/mcp/index.js.map +0 -1
- package/dist/mcp/prompts/workflows.js.map +0 -1
- package/dist/mcp/resources/documentation.js +19 -12
- package/dist/mcp/resources/documentation.js.map +1 -2
- package/dist/mcp/server.js.map +0 -1
- package/dist/mcp/skills.js.map +0 -1
- package/dist/mcp/tools/appTools.js +1 -7
- package/dist/mcp/tools/appTools.js.map +1 -2
- package/dist/mcp/tools/authTools.js +1 -1
- package/dist/mcp/tools/authTools.js.map +1 -2
- package/dist/mcp/tools/cellTools.js +6 -19
- package/dist/mcp/tools/cellTools.js.map +1 -2
- package/dist/mcp/tools/dashboardTools.js +30 -412
- package/dist/mcp/tools/dashboardTools.js.map +2 -3
- package/dist/mcp/tools/dataTools.js +15 -146
- package/dist/mcp/tools/dataTools.js.map +1 -2
- package/dist/mcp/tools/folderTools.js +12 -78
- package/dist/mcp/tools/folderTools.js.map +1 -2
- package/dist/mcp/tools/modelTools.js +23 -372
- package/dist/mcp/tools/modelTools.js.map +1 -2
- package/dist/mcp/tools/pipelineContract.js +5 -1
- package/dist/mcp/tools/pipelineContract.js.map +1 -2
- package/dist/mcp/tools/pipelineTools.js.map +0 -1
- package/dist/mcp/tools/runTools.js +8 -69
- package/dist/mcp/tools/runTools.js.map +1 -2
- package/dist/mcp/tools/sheetTools.js +14 -264
- package/dist/mcp/tools/sheetTools.js.map +1 -2
- package/dist/mcp/tools/syncTools.js +7 -3
- package/dist/mcp/tools/syncTools.js.map +1 -2
- package/dist/mcp/utils/helpers.js.map +0 -1
- package/dist/mcp/utils/launchPin.js.map +0 -1
- package/dist/mcp/utils/operationResponse.js +41 -0
- package/dist/mcp/utils/operationResponse.js.map +6 -0
- package/dist/mcp/utils/registerTool.js.map +0 -1
- package/dist/mcp/utils/session.js.map +0 -1
- package/dist/mcp/utils/tenantPin.js.map +0 -1
- package/dist/operations/cells.js +444 -0
- package/dist/operations/cells.js.map +6 -0
- package/dist/operations/dashboards.js +357 -0
- package/dist/operations/dashboards.js.map +6 -0
- package/dist/operations/data.js +206 -0
- package/dist/operations/data.js.map +6 -0
- package/dist/operations/errors.js +64 -0
- package/dist/operations/errors.js.map +6 -0
- package/dist/operations/exportModel.js +59 -0
- package/dist/operations/exportModel.js.map +6 -0
- package/dist/operations/folderPath.js +128 -0
- package/dist/operations/folderPath.js.map +6 -0
- package/dist/operations/folders.js +80 -0
- package/dist/operations/folders.js.map +6 -0
- package/dist/operations/install.js +109 -0
- package/dist/operations/install.js.map +6 -0
- package/dist/operations/model.js +271 -0
- package/dist/operations/model.js.map +6 -0
- package/dist/operations/sheets.js +428 -0
- package/dist/operations/sheets.js.map +6 -0
- package/dist/pipeline/compatibility.js.map +0 -1
- package/dist/pipeline/connect.js.map +0 -1
- package/dist/pipeline/create.js.map +0 -1
- package/dist/pipeline/errors.js.map +0 -1
- package/dist/pipeline/failStep.js +43 -0
- package/dist/pipeline/failStep.js.map +6 -0
- package/dist/pipeline/generated-reference.json +25 -13
- package/dist/pipeline/guide.js.map +0 -1
- package/dist/pipeline/init.js.map +0 -1
- package/dist/pipeline/operations.js.map +0 -1
- package/dist/pipeline/query.js.map +0 -1
- package/dist/pipeline/queryDownloads.js.map +0 -1
- package/dist/pipeline/queryWorker.js +3 -1
- package/dist/pipeline/queryWorker.js.map +1 -2
- package/dist/pipeline/readiness.js.map +0 -1
- package/dist/pipeline/reference.js.map +0 -1
- package/dist/pipeline/requests.js +3 -32
- package/dist/pipeline/requests.js.map +1 -2
- package/dist/pipeline/runArguments.js.map +0 -1
- package/dist/pipeline/runtime.js.map +0 -1
- package/dist/pipeline/service.js +46 -2
- package/dist/pipeline/service.js.map +1 -2
- package/dist/services/appSyncService.js +59 -9
- package/dist/services/appSyncService.js.map +1 -2
- package/dist/services/apps.js +10 -0
- package/dist/services/apps.js.map +1 -2
- package/dist/services/authErrors.js.map +0 -1
- package/dist/services/codefirst/api.js +38 -5
- package/dist/services/codefirst/api.js.map +1 -2
- package/dist/services/codefirst/binaryDisk.js.map +0 -1
- package/dist/services/codefirst/byteHashes.js +5 -0
- package/dist/services/codefirst/byteHashes.js.map +1 -2
- package/dist/services/codefirst/documents.js +41 -15
- package/dist/services/codefirst/documents.js.map +1 -2
- package/dist/services/codefirst/layoutBinaryProjection.js +24 -13
- package/dist/services/codefirst/layoutBinaryProjection.js.map +1 -2
- package/dist/services/codefirst/layoutCompose.js +44 -38
- package/dist/services/codefirst/layoutCompose.js.map +1 -2
- package/dist/services/codefirst/layoutCore.js +14 -1
- package/dist/services/codefirst/layoutCore.js.map +1 -2
- package/dist/services/codefirst/layoutPaths.js +80 -4
- package/dist/services/codefirst/layoutPaths.js.map +1 -2
- package/dist/services/codefirst/layoutProjection.js +73 -39
- package/dist/services/codefirst/layoutProjection.js.map +1 -2
- package/dist/services/codefirst/layoutReadback.js +357 -130
- package/dist/services/codefirst/layoutReadback.js.map +2 -3
- package/dist/services/codefirst/layoutReadbackPlacement.js +94 -57
- package/dist/services/codefirst/layoutReadbackPlacement.js.map +2 -3
- package/dist/services/codefirst/layoutReceipt.js +283 -243
- package/dist/services/codefirst/layoutReceipt.js.map +2 -3
- package/dist/services/codefirst/layoutScan.js +208 -110
- package/dist/services/codefirst/layoutScan.js.map +1 -2
- package/dist/services/codefirst/output.js +76 -10
- package/dist/services/codefirst/output.js.map +1 -2
- package/dist/services/codefirst/types.js.map +0 -1
- package/dist/services/codefirst/workflow.js +65 -29
- package/dist/services/codefirst/workflow.js.map +2 -3
- package/dist/services/codefirst/workspace.js.map +0 -1
- package/dist/services/codefirst/workspaceLock.js.map +0 -1
- package/dist/services/codefirst/workspaceRoot.js +2 -1
- package/dist/services/codefirst/workspaceRoot.js.map +1 -2
- package/dist/services/configService.js.map +0 -1
- package/dist/services/credentials.js.map +0 -1
- package/dist/services/farseerService.js +31 -7
- package/dist/services/farseerService.js.map +1 -2
- package/dist/services/httpError.js.map +0 -1
- package/dist/services/modelExport.js.map +0 -1
- package/dist/services/organisation.js.map +0 -1
- package/dist/services/preflight.js.map +0 -1
- package/dist/services/realms.js.map +0 -1
- package/dist/services/syncService.js +3 -3
- package/dist/services/syncService.js.map +1 -2
- package/dist/skills/bundled.js +106 -0
- package/dist/skills/bundled.js.map +6 -0
- package/dist/skills/install.js +257 -0
- package/dist/skills/install.js.map +6 -0
- package/dist/skills/pipeline.js +10 -18
- package/dist/skills/pipeline.js.map +1 -2
- package/dist/utils/agentSandbox.js +1 -1
- package/dist/utils/agentSandbox.js.map +0 -1
- package/dist/utils/cliOptions.js.map +0 -1
- package/dist/utils/constants.js.map +0 -1
- package/dist/utils/entityResolver.js +72 -25
- package/dist/utils/entityResolver.js.map +1 -2
- package/dist/utils/errorFormatter.js +72 -11
- package/dist/utils/errorFormatter.js.map +1 -2
- package/dist/utils/fileLogger.js.map +0 -1
- package/dist/utils/fileValidation.js.map +0 -1
- package/dist/utils/folderMatch.js.map +0 -1
- package/dist/utils/formulaFilters.js +11 -2
- package/dist/utils/formulaFilters.js.map +1 -2
- package/dist/utils/helpers.js.map +0 -1
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/nameResolver.js.map +0 -1
- package/dist/utils/operationCli.js +102 -0
- package/dist/utils/operationCli.js.map +6 -0
- package/dist/utils/packageManager.js.map +0 -1
- package/dist/utils/syncReporting.js.map +0 -1
- package/dist/utils/syncScope.js.map +0 -1
- package/dist/utils/updateCheck.js.map +0 -1
- package/dist/utils/variableValues.js.map +0 -1
- package/dist/utils/workspace.js.map +0 -1
- package/docs/cli-guide.md +182 -2
- package/docs/import-workflows.md +14 -14
- package/docs/new-app-template.md +1 -1
- package/docs/pipeline-client-guide.md +1 -1
- package/docs/pipeline-reference.md +304 -9
- package/docs/troubleshooting.md +18 -0
- package/package.json +2 -2
- package/skills/farseer-analysis/SKILL.md +132 -0
- package/skills/farseer-app-dev/SKILL.md +131 -0
- package/skills/farseer-app-dev/assignments.md +185 -0
- package/skills/farseer-app-dev/farseer-client-api-guide.md +907 -0
- package/skills/farseer-app-dev/farseer-client-release-notes.md +212 -0
- package/skills/farseer-app-dev/working-patterns.md +876 -0
- package/skills/farseer-authenticate-to-tenant/SKILL.md +60 -0
- package/skills/farseer-authenticate-to-tenant/app-authentication.md +91 -0
- package/skills/farseer-author-import-job/SKILL.md +114 -0
- package/skills/farseer-author-import-job/cell-writes.md +530 -0
- package/skills/farseer-author-import-job/deploying-a-farseer-app.md +383 -0
- package/skills/farseer-author-import-job/import-job-pattern.md +232 -0
- package/skills/farseer-build-model/SKILL.md +122 -0
- package/skills/farseer-build-model/formula-grain-alignment.md +612 -0
- package/skills/farseer-build-model/naming-conventions.md +435 -0
- package/skills/farseer-build-model/sparse-formulas-pattern.md +330 -0
- package/skills/farseer-build-pipeline/SKILL.md +190 -0
- package/skills/farseer-build-pipeline/erp-sales/README.md +108 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_invoice_lines.yaml +23 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_invoice_lines_raw.yaml +23 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_item_product_map.yaml +17 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_item_product_map_raw.yaml +11 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/gold/erp_sales_cells.yaml +40 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/silver/erp_sales_lines.yaml +35 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/silver/erp_sales_recon.yaml +43 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/silver/erp_sales_unmapped_items.yaml +28 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/main.py +49 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/Models/in/erp_sales_cells.yaml +17 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/Models/in/erp_sales_cells_raw.yaml +14 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/Models/load/erp_sales_to_model.yaml +47 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/main.py +44 -0
- package/skills/farseer-build-pipeline/erp-sales/item_to_product.csv +5 -0
- package/skills/farseer-build-pipeline/pipeline-app-failure-report-pattern.md +103 -0
- package/skills/farseer-build-pipeline/pipeline-source-encoding.md +68 -0
- package/skills/farseer-dashboards/SKILL.md +40 -0
- package/skills/farseer-formulas/SKILL.md +165 -0
- package/skills/farseer-help-center/SKILL.md +66 -0
- package/skills/farseer-model/SKILL.md +119 -0
- package/skills/farseer-modify-model/SKILL.md +158 -0
- package/skills/farseer-modify-model/model-validation-pattern.md +251 -0
- package/skills/farseer-optimize-model/SKILL.md +314 -0
- package/skills/farseer-optimize-model/stats-dump.ts +139 -0
- package/skills/farseer-pnl/SKILL.md +220 -0
- package/skills/farseer-review-model/SKILL.md +172 -0
- package/skills/farseer-run-apps/SKILL.md +102 -0
- package/skills/pipeline-authoring/SKILL.md +7 -5
- package/skills/pipeline-authoring/practices.md +21 -8
- package/dist/services/agentApprovalFetch.js +0 -86
- package/dist/services/agentApprovalFetch.js.map +0 -7
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stats collector for the farseer-optimize-model skill, steps (a) and (b).
|
|
3
|
+
*
|
|
4
|
+
* A `farseer run-script` that reads `c.evaluator.stats()` (per-variable
|
|
5
|
+
* calculation duration + cell counts from the engine's LAST full
|
|
6
|
+
* calculation), writes it to a JSON file, and prints two rankings: by
|
|
7
|
+
* duration, and by µs/cell against the model's own median.
|
|
8
|
+
*
|
|
9
|
+
* Run-scripts don't receive CLI arguments (`farseer run-script <tenant>
|
|
10
|
+
* <file>` passes nothing through), so configuration is via env vars.
|
|
11
|
+
* CJS-style: no top-level await, `main().catch(...)` at the bottom.
|
|
12
|
+
*
|
|
13
|
+
* Env:
|
|
14
|
+
* FULL=1 force a fresh recalc before reading stats, via
|
|
15
|
+
* `evaluator.invalidateCache()`. **Blocks until the whole model
|
|
16
|
+
* recalculates — minutes on a real model.** Without FULL=1 you
|
|
17
|
+
* get the last calc's numbers (fast, possibly stale). Never set
|
|
18
|
+
* FULL=1 against a production tenant during business hours — it
|
|
19
|
+
* locks the model for every concurrent user for the duration.
|
|
20
|
+
* OUT output path for the JSON (default: ./stats-dump-<UTC time>.json, so
|
|
21
|
+
* no run overwrites an earlier one; relative to `farseer-apps/<tenant>/`,
|
|
22
|
+
* where run-script runs the script).
|
|
23
|
+
* TOP rows in each ranking (default 15).
|
|
24
|
+
* MIN_CELLS
|
|
25
|
+
* fewest cells for a formula variable to count toward the µs/cell
|
|
26
|
+
* ranking and its median (default 1000; small variables give
|
|
27
|
+
* noisy µs/cell numbers). Inputs, which the engine reports with
|
|
28
|
+
* no calculated cells or a zero duration, never count.
|
|
29
|
+
*
|
|
30
|
+
* Usage:
|
|
31
|
+
* farseer pull <org> <tenant> # once: creates farseer-apps/<tenant>/
|
|
32
|
+
* cp stats-dump.ts farseer-apps/<tenant>/files/Scripts/ # run-script finds it there
|
|
33
|
+
* farseer install <tenant> # once, cold start
|
|
34
|
+
* farseer run-script <tenant> stats-dump.ts # last-calc numbers
|
|
35
|
+
* FULL=1 farseer run-script <tenant> stats-dump.ts # fresh full calc
|
|
36
|
+
* FULL=1 OUT=stats-2026-09-17.json farseer run-script <tenant> stats-dump.ts
|
|
37
|
+
*/
|
|
38
|
+
import { writeFileSync } from "node:fs";
|
|
39
|
+
import { FarseerClient } from "farseer-client";
|
|
40
|
+
|
|
41
|
+
const FULL = process.env.FULL === "1";
|
|
42
|
+
const OUT = process.env.OUT ?? `./stats-dump-${new Date().toISOString().replace(/[:.]/g, "-")}.json`;
|
|
43
|
+
const TOP = envNumber("TOP", 15);
|
|
44
|
+
const MIN_CELLS = envNumber("MIN_CELLS", 1000);
|
|
45
|
+
|
|
46
|
+
function log(...a: unknown[]) {
|
|
47
|
+
console.log(...a);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function envNumber(name: string, fallback: number) {
|
|
51
|
+
const n = Number(process.env[name] ?? fallback);
|
|
52
|
+
return Number.isFinite(n) ? n : fallback;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const fmt = (n: number | null | undefined) => (n == null ? "—" : Math.round(n).toLocaleString("en-US"));
|
|
56
|
+
|
|
57
|
+
function median(xs: number[]) {
|
|
58
|
+
const s = [...xs].sort((a, b) => a - b);
|
|
59
|
+
return s.length ? s[Math.floor(s.length / 2)] : 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Step (b): the top variables by duration, and by µs/cell against the median of the formula variables with MIN_CELLS
|
|
64
|
+
* cells or more. An input has no calculated cells, and on the C++ engine a zero duration: counting inputs would pull
|
|
65
|
+
* the median towards 0 on a data-heavy model.
|
|
66
|
+
*/
|
|
67
|
+
function printRankings(vars: any[]) {
|
|
68
|
+
const rows = vars.map((s: any) => {
|
|
69
|
+
const cells = (s.calculated ?? 0) + (s.nonCalculated ?? 0);
|
|
70
|
+
const duration: number = s.duration ?? 0;
|
|
71
|
+
const calculated: number = s.calculated ?? 0;
|
|
72
|
+
return { name: s.name as string, duration, calculated, cells, usPerCell: cells > 0 ? (duration * 1000) / cells : null };
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const total = rows.reduce((a, r) => a + r.duration, 0);
|
|
76
|
+
const byDuration = [...rows].sort((a, b) => b.duration - a.duration).slice(0, TOP);
|
|
77
|
+
const eligible = rows.filter((r) => r.calculated > 0 && r.duration > 0 && r.cells >= MIN_CELLS);
|
|
78
|
+
const byUs = [...eligible].sort((a, b) => b.usPerCell! - a.usPerCell!).slice(0, TOP);
|
|
79
|
+
const medUs = median(eligible.map((r) => r.usPerCell!));
|
|
80
|
+
log(` Σduration ${fmt(total)} ms · median µs/cell (formula variables, ≥${MIN_CELLS} cells) ${medUs.toFixed(2)}`);
|
|
81
|
+
|
|
82
|
+
const table = (list: typeof rows, title: string) => {
|
|
83
|
+
log(`\n## ${title}\n\n| # | variable | duration ms | % of Σ | cells | µs/cell | ×median |\n|---|---|---:|---:|---:|---:|---:|`);
|
|
84
|
+
list.forEach((r, i) => {
|
|
85
|
+
const pct = total > 0 ? ((100 * r.duration) / total).toFixed(1) : "0.0";
|
|
86
|
+
const us = r.usPerCell == null ? "—" : r.usPerCell.toFixed(2);
|
|
87
|
+
const ratio = r.usPerCell == null || medUs === 0 ? "—" : (r.usPerCell / medUs).toFixed(1);
|
|
88
|
+
log(`| ${i + 1} | ${r.name} | ${fmt(r.duration)} | ${pct} | ${fmt(r.cells)} | ${us} | ${ratio} |`);
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
table(byDuration, `Top ${TOP} by duration`);
|
|
92
|
+
table(byUs, `Top ${TOP} by µs/cell (formula variables, cells ≥ ${MIN_CELLS}) — the inefficiency index`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function main() {
|
|
96
|
+
log(`stats-dump.ts · FULL=${FULL ? "1 (invalidateCache first — this blocks)" : "0 (last calc)"} · OUT=${OUT}`);
|
|
97
|
+
const c = new FarseerClient();
|
|
98
|
+
|
|
99
|
+
if (FULL) {
|
|
100
|
+
log(" invalidateCache() — waiting for the full recalc to finish…");
|
|
101
|
+
const started = Date.now();
|
|
102
|
+
try {
|
|
103
|
+
await c.evaluator.invalidateCache();
|
|
104
|
+
} catch (e: any) {
|
|
105
|
+
// The SDK throws the Response on an HTTP error; a timeout or a dropped connection has no status.
|
|
106
|
+
if (typeof e?.status !== "number" || e.status >= 500) {
|
|
107
|
+
console.error(" invalidateCache() timed out or failed in transit. The recalculation continues on the server:");
|
|
108
|
+
console.error(" wait, then rerun WITHOUT FULL=1 to read its stats. Never rerun with FULL=1 after a timeout.");
|
|
109
|
+
}
|
|
110
|
+
throw e;
|
|
111
|
+
}
|
|
112
|
+
log(` recalc done in ${((Date.now() - started) / 1000).toFixed(1)}s (wall clock, incl. request overhead)`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const stats: any = await c.evaluator.stats();
|
|
116
|
+
const vars = stats.variables ?? [];
|
|
117
|
+
const totalCells = vars.reduce((a: number, v: any) => a + (v.calculated ?? 0) + (v.nonCalculated ?? 0), 0);
|
|
118
|
+
log(` calculationTime ${stats.calculationTime ?? "?"} ms · ${vars.length} variables · ${totalCells.toLocaleString()} cells`);
|
|
119
|
+
|
|
120
|
+
writeFileSync(OUT, JSON.stringify(stats, null, 2));
|
|
121
|
+
log(` wrote ${OUT}`);
|
|
122
|
+
if (vars.length === 0) {
|
|
123
|
+
console.error(" The stats hold no variables: nothing has calculated since the model loaded. Nothing to rank.");
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
printRankings(vars);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
main().catch(async (e: any) => {
|
|
130
|
+
if (typeof e?.text === "function") {
|
|
131
|
+
try {
|
|
132
|
+
console.error("error body:", await e.text());
|
|
133
|
+
} catch {
|
|
134
|
+
/* ignore */
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
console.error(e);
|
|
138
|
+
process.exit(1);
|
|
139
|
+
});
|
|
@@ -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.
|