farseer-cli 1.19.0 → 1.21.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 (165) hide show
  1. package/README.md +32 -9
  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 +72 -31
  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 +474 -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 +102 -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 +33 -371
  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 +275 -0
  73. package/dist/operations/model.js.map +6 -0
  74. package/dist/operations/sheets.js +766 -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 +11 -11
  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/dimensionMembers.js +54 -0
  99. package/dist/utils/dimensionMembers.js.map +6 -0
  100. package/dist/utils/entityResolver.js +74 -25
  101. package/dist/utils/entityResolver.js.map +1 -1
  102. package/dist/utils/errorFormatter.js +13 -0
  103. package/dist/utils/errorFormatter.js.map +1 -1
  104. package/dist/utils/formulaFilters.js +11 -2
  105. package/dist/utils/formulaFilters.js.map +1 -1
  106. package/dist/utils/operationCli.js +102 -0
  107. package/dist/utils/operationCli.js.map +6 -0
  108. package/docs/cli-guide.md +195 -1
  109. package/docs/pipeline-reference.md +138 -24
  110. package/docs/troubleshooting.md +18 -0
  111. package/package.json +2 -2
  112. package/skills/farseer-app-dev/SKILL.md +131 -0
  113. package/skills/farseer-app-dev/assignments.md +185 -0
  114. package/skills/farseer-app-dev/farseer-client-api-guide.md +907 -0
  115. package/skills/farseer-app-dev/farseer-client-release-notes.md +212 -0
  116. package/skills/farseer-app-dev/working-patterns.md +876 -0
  117. package/skills/farseer-authenticate-to-tenant/SKILL.md +60 -0
  118. package/skills/farseer-authenticate-to-tenant/app-authentication.md +91 -0
  119. package/skills/farseer-author-import-job/SKILL.md +114 -0
  120. package/skills/farseer-author-import-job/cell-writes.md +530 -0
  121. package/skills/farseer-author-import-job/deploying-a-farseer-app.md +383 -0
  122. package/skills/farseer-author-import-job/import-job-pattern.md +232 -0
  123. package/skills/farseer-build-model/SKILL.md +122 -0
  124. package/skills/farseer-build-model/formula-grain-alignment.md +612 -0
  125. package/skills/farseer-build-model/naming-conventions.md +435 -0
  126. package/skills/farseer-build-model/sparse-formulas-pattern.md +330 -0
  127. package/skills/farseer-build-pipeline/SKILL.md +190 -0
  128. package/skills/farseer-build-pipeline/erp-sales/README.md +108 -0
  129. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_invoice_lines.yaml +23 -0
  130. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_invoice_lines_raw.yaml +23 -0
  131. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_item_product_map.yaml +17 -0
  132. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_item_product_map_raw.yaml +11 -0
  133. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/gold/erp_sales_cells.yaml +40 -0
  134. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/silver/erp_sales_lines.yaml +35 -0
  135. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/silver/erp_sales_recon.yaml +43 -0
  136. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/silver/erp_sales_unmapped_items.yaml +28 -0
  137. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/main.py +49 -0
  138. package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/Models/in/erp_sales_cells.yaml +17 -0
  139. package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/Models/in/erp_sales_cells_raw.yaml +14 -0
  140. package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/Models/load/erp_sales_to_model.yaml +47 -0
  141. package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/main.py +44 -0
  142. package/skills/farseer-build-pipeline/erp-sales/item_to_product.csv +5 -0
  143. package/skills/farseer-build-pipeline/pipeline-app-failure-report-pattern.md +103 -0
  144. package/skills/farseer-build-pipeline/pipeline-source-encoding.md +68 -0
  145. package/skills/farseer-dashboards/SKILL.md +222 -20
  146. package/skills/farseer-dashboards/cards.md +59 -0
  147. package/skills/farseer-dashboards/charts.md +245 -0
  148. package/skills/farseer-dashboards/check.md +91 -0
  149. package/skills/farseer-dashboards/measures.md +88 -0
  150. package/skills/farseer-dashboards/page.md +99 -0
  151. package/skills/farseer-dashboards/reporting-period.md +82 -0
  152. package/skills/farseer-dashboards/standard-set.md +182 -0
  153. package/skills/farseer-dashboards/tables.md +174 -0
  154. package/skills/farseer-help-center/SKILL.md +66 -0
  155. package/skills/farseer-modify-model/SKILL.md +158 -0
  156. package/skills/farseer-modify-model/model-validation-pattern.md +251 -0
  157. package/skills/farseer-optimize-model/SKILL.md +314 -0
  158. package/skills/farseer-optimize-model/stats-dump.ts +139 -0
  159. package/skills/farseer-pnl/SKILL.md +220 -0
  160. package/skills/farseer-review-model/SKILL.md +172 -0
  161. package/skills/farseer-run-apps/SKILL.md +102 -0
  162. package/skills/pipeline-authoring/SKILL.md +4 -4
  163. package/skills/pipeline-authoring/practices.md +17 -4
  164. package/dist/services/agentApprovalFetch.js +0 -90
  165. package/dist/services/agentApprovalFetch.js.map +0 -6
@@ -0,0 +1,60 @@
1
+ ---
2
+ name: farseer-authenticate-to-tenant
3
+ description: >-
4
+ Use when a Farseer tenant call fails on authentication (stale/expired token, "not authenticated", 401/403), when the `farseer` MCP server has no active session (reads return empty/unauthenticated), or when you need to (re)connect to a tenant before inspecting a model, building dashboards, or pushing. YOU run `farseer login` yourself — it is OAuth and opens the user's browser to complete sign-in, then returns; do NOT ask the user to run login. Also covers per-call tenant selection (`farseer checkout` was removed in farseer-cli ≥ 1.10 — pass the tenant per call) and the read-session vs write-API-key distinction. Triggers: "not authenticated", "auth failed", "token expired", "log me in", "connect to the tenant", "reconnect", an empty `farseer whoami`, or MCP reads coming back unauthenticated. Match by MEANING, not literal words — any language maps here.
5
+ metadata:
6
+ version: "1"
7
+ domain: modeling, tooling
8
+ ---
9
+
10
+ # Authenticate to Tenant
11
+
12
+ ## When this skill applies
13
+
14
+ - A `farseer …` command or an MCP tool returns an **auth error** (401, "not authenticated", expired/stale token). A 403 can be one too, but it also answers a tenant the organisation does not have or an account without access to it; logging in again fixes neither.
15
+ - The `farseer` MCP server is present but has **no session** (reads return empty or unauthenticated).
16
+ - You need a tenant connection **before** model inspection, dashboard work, or a push.
17
+
18
+ **You own authentication.** Run login yourself; do not delegate it to the user.
19
+
20
+ ## Procedure
21
+
22
+ 1. **Confirm the gap** — `farseer whoami`. It prints each browser login's realm **and the
23
+ token expiry** (`Token expires: <time>`); `Browser login expired` or
24
+ `Not logged in via browser` → not authenticated.
25
+ 2. **Expired token ≠ dead session — refresh before re-login.** If `whoami`
26
+ shows an expired/near-expiry token, run any `farseer` binary command
27
+ (e.g. `farseer variables list <tenant>`) — the binary refreshes the token
28
+ itself (`Token expired, refreshing...`). Only fall through to step 3 when
29
+ the refresh token itself is dead.
30
+ 3. **Run `farseer login --org <org>` yourself**, with the tenant's organisation: a bare `farseer login` signs in to the default (master) realm only, so a tenant whose organisation has its own realm stays unauthenticated. It is OAuth and **opens the user's browser**. Tell the user once: *"a browser window will open — complete the sign-in."* The command returns when they finish; you do not type credentials.
31
+ 4. **Confirm** — `farseer whoami` shows `Logged in via browser` for that realm (it names the realm, not the account).
32
+ 5. **Name the tenant per call** — there is no machine-wide default tenant (`farseer checkout` was removed in farseer-cli ≥ 1.10). Pass the trailing `[org] [tenant]` arguments on each command that needs one, or `export FARSEER_TENANT=<tenant>` (with `FARSEER_ORG=<org>` when the organisation differs) for the shell.
33
+ 6. **Retry** the originally blocked call.
34
+
35
+ ## Read session vs write key
36
+
37
+ - `farseer login` grants the OAuth session — and that session covers **both
38
+ reads and writes**: model inspection, MCP reads, `farseer model --json`,
39
+ AND pushes.
40
+ - The **per-tenant API key** (`farseer config set <tenant> --api-key … --org …`)
41
+ is an **optional tier** — for non-interactive CI flows and SDK scripts
42
+ that want auth independent of a browser session. It is NOT a prerequisite
43
+ for write work, and "pushes fail" is not evidence it is missing. See [`app-authentication.md`](app-authentication.md).
44
+
45
+ ## Tools to invoke
46
+
47
+ - `Bash`: `farseer whoami`, `farseer login --org <org>`, and (for non-interactive runs) `farseer config set …`. The tenant is passed per call (trailing `[org] [tenant]` args, or `FARSEER_TENANT` for the shell) — `farseer checkout` was removed in farseer-cli ≥ 1.10.
48
+
49
+ ## Expected output
50
+
51
+ An authenticated session (`farseer whoami` resolves) on the correct tenant, and the originally-blocked call retried and succeeding.
52
+
53
+ ## Constraints
54
+
55
+ - Do **not** ask the user to run `farseer login` — **you** run it; the user only completes the browser sign-in.
56
+ - `farseer login` is interactive (browser) but **not destructive** — no confirmation gate is needed to start it.
57
+ - Do **not** invent or hardcode credentials, and never write tokens into `.mcp.json` or any committed file. Auth lives in the CLI's own cache (browser session) and per-tenant `farseer config`.
58
+ - If `farseer login` "opens the browser but never returns" → likely a firewall/VPN blocking the OAuth callback; surface that to the user instead of looping.
59
+ - `farseer login` needs a browser. Where none is available (a sandbox, CI, a remote shell), don't start it: report the auth failure and point to a per-tenant API key (`farseer config set <tenant> --api-key … --org …`) instead.
60
+ - **CLI freshness:** if any `farseer` output shows the CLI's update notice (or a feature needs a newer version — e.g. MCP tenant autobind needs ≥ 1.9.0), **ask the user for permission, then** run `npm install -g farseer-cli@latest`. Never upgrade silently; remind the user about their other machines.
@@ -0,0 +1,91 @@
1
+ # App authentication — modern pattern
2
+
3
+ Farseer apps authenticate to the tenant through the **Farseer CLI's stored credentials**, not through `.env` files in your code. The credentials live under `~/.farseer/` and are populated by `farseer config set <tenant> --api-key <key> --org <org>` (the API key comes from the Farseer UI for tenants you admin, or from the customer's admin for client tenants). When `farseer run` invokes the app, it sets `TENANT_ID`, `FARSEER_URL` and either the API-key variable (a key saved with `farseer config set`, used first) or `FARSEER_TOKEN` (the browser login) in the subprocess; the app's code calls `new farseer.FarseerClient()` with no arguments and the SDK reads those env vars internally. The `.env` + API-key-variable approach described in earlier drafts is **legacy** at the app-runtime layer — what changed in 2026 is that the API key now lives in `~/.farseer/` (CLI-managed, gitignored, never in your code), not in a `.env` file you maintain by hand.
4
+
5
+ **Read-side CLI inspection (`farseer model --json`, `farseer app list --details`, `farseer status`) works on the browser session alone (`farseer login`, tenant passed on each call — there's no global default tenant since `farseer checkout` was removed in farseer-cli ≥ 1.10), without an API key.** Write-side workflows — apps that mutate, anything that calls `client.model.load()` or bulk-cell APIs — work on the browser session too: `farseer run` hands the app the browser token when no API key is saved. A per-tenant key from `farseer config set` is optional, for runs that must not depend on a browser session (CI, long scripts).
6
+
7
+ ---
8
+
9
+ ## How it works
10
+
11
+ ```bash
12
+ farseer login
13
+ # Opens a browser window, you sign in once, a token is cached under ~/.farseer/
14
+ ```
15
+
16
+ Once you're logged in:
17
+
18
+ - `farseer pull`, `farseer push`, `farseer status` work
19
+ - `farseer run <tenant> "<app-name>"` runs an app locally — the CLI sets `TENANT_ID` (the tenant slug), `FARSEER_URL`, and **either** `FARSEER_TOKEN` (after a browser `farseer login`) **or** the API-key variable (only in api-key mode) in the subprocess environment before invoking your script; the two are mutually exclusive (measured 2026-10-15). On the tenant, the job runner sets the API-key variable
20
+ - The app's code calls `new farseer.FarseerClient()` with no arguments; the SDK picks those env vars up internally
21
+ - The app's code never edits a `.env` file, never reads an API key, never sees the token directly — it just calls `new farseer.FarseerClient()` and the SDK reads the injected env vars. (One-time, when setting up access to a tenant you don't admin, you may paste a vendor-issued key into `farseer config set` — that's a one-shot store-it-locally step, not something the app's code touches.)
22
+
23
+ ## The SDK still uses env vars under the hood
24
+
25
+ The `farseer-client` npm package reads `TENANT_ID`, the API-key variable and `FARSEER_URL` from the environment at client-construction time. What changed in 2026 is **how those env vars get there** — previously a developer-maintained `.env` file + `dotenv.config()`, now the CLI sets them from the browser-login token.
26
+
27
+ If you run a script directly (`npx tsx app.ts`) without going through `farseer run`, those env vars are absent. Read the tenant from `TENANT_ID`; no runner sets `FARSEER_TENANT`.
28
+
29
+ ## What you no longer do
30
+
31
+ The following patterns are **legacy** and should be removed from new apps:
32
+
33
+ - ❌ The API-key variable / `SERVER_URL` / `FARSEER_TENANT` in a `.env` file
34
+ - ❌ `dotenv.config()` calls for Farseer credentials
35
+ - ❌ `check-env.ts` validation scripts for Farseer-side variables
36
+ - ❌ "Copy `.env.example` to `.env` and paste the API key from 1Password"
37
+
38
+ If you encounter an older app that still uses this pattern, it continues to work — migrate it the next time you touch it:
39
+
40
+ 1. Delete `.env` and `.env.example`
41
+ 2. Remove `dotenv` imports from `app.ts`
42
+ 3. Remove Farseer-credential reads (the API-key variable etc.)
43
+ 4. Replace with direct SDK usage — the SDK handles auth
44
+ 5. Run `farseer login` once on the dev machine
45
+ 6. Test with `farseer run <tenant> "<app-name>"`
46
+
47
+ ## Non-Farseer credentials
48
+
49
+ If a specific app needs credentials to a **third-party source system** (an ERP API key, an FTP password, an SMTP server), those still need to live somewhere. Options, in order of preference:
50
+
51
+ 1. **Farseer platform connector** — when the platform provides a managed connector for the source, use it. Credentials stay on the platform, the app reads them via the SDK.
52
+ 2. **Secret-typed app argument (`secret: true`)** — the preferred mechanism for an app-owned runtime secret. Declare an app argument and flag it `secret: true`; the platform **masks** the value in inputs + logs, stores it on the tenant tied to the app, and the app reads it at run time from the `FARSEER_ARGS` JSON object, by name (`JSON.parse(process.env.FARSEER_ARGS ?? "{}").<NAME>`). `FARSEER_SECRET_ARGS` only lists the secret arguments' names; there is no `process.env.<NAME>`. `farseer push`/`pull` round-trip the flag faithfully.
53
+
54
+ > ⚠️ **Agent note — how to set it.** The interactive `farseer app configure --add-arg Name=Value` flag **cannot** set the `secret` flag (it only takes `Name=DefaultValue`). To make an argument a secret, either:
55
+ > - **edit the app config JSON** (`farseer-apps/<tenant>/apps/<app>.json`) and add an `arguments[]` entry with `"secret": true` + `"defaultValue": ""`, then `farseer push`; or
56
+ > - use the **`farseer_create_app` / `farseer_configure_app`** MCP tools (`farseer mcp-server`), which accept `secret` directly.
57
+ >
58
+ > ```json
59
+ > { "name": "SOURCE_API_KEY", "dataType": "string", "defaultValue": "", "secret": true }
60
+ > ```
61
+ >
62
+ > The secret *value* is entered on the tenant (masked) — not committed, not in `defaultValue`.
63
+ 3. **Plain `farseer app configure <app-name> --add-arg`** — for **non-sensitive** per-app config values only (not secrets — `--add-arg` can't mask). See `farseer app configure --help`.
64
+ 4. **Tenant file `Files/secrets/<name>.json`** (legacy/fallback) — only for apps that already read it.
65
+ 5. **Local `.env` for dev only** — acceptable as a short-term fallback; the file is gitignored. Add a clear note in the app's README that production uses a platform mechanism, not `.env`.
66
+
67
+ **Never** put real source-system credentials in git, regardless of which approach.
68
+
69
+ ## Authentication troubleshooting
70
+
71
+ ### `farseer` command says "not authenticated"
72
+ ```bash
73
+ farseer login # re-authenticate (browser flow)
74
+ farseer whoami # verify
75
+ ```
76
+
77
+ ### Token cache location
78
+ The CLI stores its login tokens and saved API keys in `~/.farseer/config.json` (macOS/Linux) or `%USERPROFILE%\.farseer\config.json` (Windows). Never commit its contents.
79
+
80
+ ### "Authentication works locally but the app fails in production"
81
+ Production is managed by the Farseer platform itself — the app is `farseer run` from the tenant's scheduler, not from your laptop. Make sure your app code uses `new farseer.FarseerClient()` with no arguments — the SDK reads from env vars that the platform sets. Hardcoded reads of the API-key variable are legacy and brittle; remove them.
82
+
83
+ ## When you still see `.env.example` in the repo
84
+
85
+ A file called `.env.example` may legitimately appear if a specific app needs third-party source credentials (option 5 above). It should:
86
+
87
+ - List only non-Farseer credentials
88
+ - Include a comment block explaining why `.env` is used for this particular app
89
+ - Link back to this doc
90
+
91
+ If you see `.env.example` with the API-key variable or similar — that's legacy. Migrate it.
@@ -0,0 +1,114 @@
1
+ ---
2
+ name: farseer-author-import-job
3
+ description: >-
4
+ Use when the user asks to fix, extend, or review an EXISTING TypeScript import app — anything using `createImportJob` to push recurring data (GL actuals, source extracts, version copies) into a model, or double-counted / overwritten numbers after a re-import. NEW recurring imports are Simple Pipelines: use `farseer-build-pipeline` instead. Enforces locked `IMPORT_` targets, argument-driven design, and scope-encoding labels so re-runs are idempotent (revert-prior-then-apply). Does NOT cover one-off test seeding (use Insert) or app deployment mechanics (see deploying-a-farseer-app). Triggers (match by MEANING, in ANY language): "write an import job", "import GL actuals", "load data into the model".
5
+ metadata:
6
+ version: "1"
7
+ domain: modeling
8
+ ---
9
+
10
+ # Author Import Job
11
+
12
+ ## When this skill applies
13
+
14
+ Maintaining or reviewing an existing TypeScript import app: monthly GL
15
+ actuals, source-system extracts, version copies (Actual → Plan). Use also when
16
+ the user reports double-counted or overwritten numbers after a re-import —
17
+ that is almost always a labels problem.
18
+
19
+ **A new recurring import is a Simple Pipeline**, built with
20
+ [`farseer-build-pipeline`](../farseer-build-pipeline/SKILL.md), even when TypeScript is asked
21
+ for (matching the Farseer CLI's own routing). The
22
+ target, argument and label rules below apply there unchanged. Fixing or
23
+ extending an existing app here does not authorise migrating it; that needs an
24
+ explicit request.
25
+
26
+ Do **not** use for: seeding a handful of cells in a test (use an
27
+ INSERT, `model.updateCells` in [`cell-writes.md`](cell-writes.md): every grain dimension pinned, read back), or the app manifest / deploy step itself (that's
28
+ [`deploying-a-farseer-app.md`](deploying-a-farseer-app.md)).
29
+
30
+ ## Inputs to gather first
31
+
32
+ 1. **What is being imported** — variable(s), source shape (CSV / API / GL export),
33
+ and the grain (which dimensions identify a row).
34
+ 2. **The import target variables** — do they carry the `IMPORT_` prefix and is each
35
+ `@readonly true`? If not, note it for the rename/lock offer.
36
+ 3. **The bounded scope of one run** — period, year, version, source/target. These
37
+ become both the app arguments and the labels.
38
+ 4. **Reference material** — [`import-job-pattern.md`](import-job-pattern.md)
39
+ (design), [`cell-writes.md`](cell-writes.md)
40
+ and [`working-patterns.md`](../farseer-app-dev/working-patterns.md) (SDK shapes).
41
+ 5. **CLI session** — explicit-tenant reads (`farseer model --variables <tenant>`, `farseer app list --details`) to inspect the live model / existing jobs; MCP `farseer_*` last resort only.
42
+
43
+ ## Procedure
44
+
45
+ ### 1. Confirm (or fix) the import targets
46
+ - Each target variable: `IMPORT_` prefix + `@readonly true`. If the prefix is
47
+ missing, **offer a rename** — don't insist; the lock is what matters. If the
48
+ target is **unlocked**, surface it as a real risk (a planner can overwrite the
49
+ feed in a sheet) and recommend locking before going live.
50
+
51
+ ### 2. Make the job argument-driven
52
+ - The job must take period / year / version (and source→target for copies) as
53
+ **arguments**, never hardcoded. Declare them in the app manifest's `arguments`.
54
+ - The same argument values feed the labels in the next step — keep them aligned.
55
+
56
+ ### 3. Build labels that encode the run's scope
57
+ - Labels = exactly the slice this run owns. GL load for Jan 2025 → `["GL","2025","1"]`.
58
+ Version-specific / copy jobs add the version and source→target:
59
+ `["fc-preparation","Plan","Y2025","<src>2<tgt>"]`.
60
+ - These labels are the **idempotency key** — the re-run locates its own prior run
61
+ by label match. Get them wrong and re-imports duplicate.
62
+
63
+ ### 4. Write the idempotent re-run protocol
64
+ Prefer the **reversible** primitive so the scope is never left empty:
65
+ ```ts
66
+ const job = await c.createImportJob({ title, labels, columns /* or metadata */ });
67
+ await job.addRows(rows); await job.flushRows();
68
+ await job.detectDimensions(); await job.importDimensions();
69
+ // list() returns every job whose labels include these, newest first: keep the exact label set.
70
+ const same = (l: string[] = []) => l.length === labels.length && labels.every(x => l.includes(x));
71
+ const priorIds = (await c.importJobs.list(labels))
72
+ .filter(j => same(j.labels) && String(j.status) === "COMMITED").map(j => j.id);
73
+ const reverted: typeof priorIds = [];
74
+ try {
75
+ for (const id of priorIds) { await c.importJobs.revert(id); reverted.push(id); } // COMMITED → REVERTED (reversible)
76
+ await job.commit();
77
+ } catch (e) {
78
+ for (const id of reverted) await c.importJobs.commit(id); await job.delete(); throw e;
79
+ }
80
+ ```
81
+ Use `undoPrevious()` / `deleteById(id, {undoData:true})` only when the prior cells
82
+ genuinely should be destroyed — it cannot be rolled back.
83
+ - `addRow([...])` value order **must** match the `columns` array order — the #1 cause
84
+ of silently-wrong imports.
85
+
86
+ ### 5. Deployment — arguments + secret credentials
87
+ - Instantiate the run's arguments (period/year/version) rather than baking them in.
88
+ - Source credentials are **secret-typed app arguments** (`secret: true` in the
89
+ manifest), pasted once in the Farseer UI — not literals, not committed files.
90
+ - After deploying, **tell the user where in the Farseer interface to paste the
91
+ secret** (the app's argument field). The deploy isn't done until that's said.
92
+
93
+ ## Tools to invoke
94
+
95
+ - `Read` on the source script / app manifest and `import-job-pattern.md`
96
+ - `farseer model --variable "<Var>" <tenant>` — confirm target is `IMPORT_` + `@readonly`
97
+ - `farseer app list --details` — inspect existing import apps and their arguments
98
+ - `Bash` for the SDK script + `farseer run-script` / `farseer push` (after explicit confirmation)
99
+ - Import-job creation via the `farseer-client` SDK script (see `import-job-pattern.md`); `farseer_create_import_job` (MCP) last resort — either way, only after explicit confirmation
100
+
101
+ ## Expected output
102
+
103
+ - A job that writes only into locked `IMPORT_` targets, takes bounded arguments,
104
+ carries scope-encoding labels, and re-runs idempotently via revert-then-commit.
105
+ - For a review request: a per-variable OK / CRITICAL classification (CRITICAL =
106
+ unlocked target) + a labels-correctness check + the rename/lock offer.
107
+
108
+ ## Constraints
109
+
110
+ - Do **not** import into an unlocked variable without flagging it CRITICAL.
111
+ - Do **not** hardcode period/year/version — they are arguments.
112
+ - Do **not** ship labels that don't encode the run's full scope — re-runs will duplicate.
113
+ - Do **not** put credentials in the script or a committed file — use a secret argument.
114
+ - Do **not** push to a tenant without explicit confirmation; production stays per-action confirmed.