Add derivation cross sheet
Portable, AI-native data sheets.
npx -y skills add nyuta01/folio --skill add-derivation-cross-sheetAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Wire up a Folio `kind: cross_sheet` derivation — pull a field from a sibling Folio sheet that shares the same primary key (the 1:1 sidecar pattern). Invoke when the user wants to "join two sheets", "pull revenue from the finance sheet into customers", or otherwise copy values keyed by PK from one sheet to another.
SKILL.md
6.5 KB, ~1.6k tokens by cl100k_base, as published. Nobody here has run it
Add a cross_sheet derivation to a Folio sheet
Author a derivations/<target>.yaml of kind: cross_sheet that joins
this sheet 1:1 with a sibling sheet on the calling sheet's primary
key, and verify with one materialize.
When this skill applies
- Two Folio sheets exist side by side, share an identifier 1:1, and the user wants one of them to pull a field from the other.
- The classic shape: a
customers/sheet next to acustomer-revenue/sheet, both keyed byid.customerswantscurrent_revenue_usdcopied in fromcustomer-revenue. - The user wants Folio's contract on the foreign sheet enforced (so bad foreign data fails validation rather than poisoning the join).
This skill does not apply when:
- The foreign source is not a Folio sheet (CSV, JSON file, HTTP
endpoint) — use
kind: importinstead. - The join key is not the calling sheet's primary key — the
built-in
cross_sheetonly matches the foreignkey_fieldagainst the calling sheet's PK. Useimportor apythonderivation that does the lookup explicitly. - The relationship is 1:N or M:N —
cross_sheetwrites one cell per calling-sheet record. Aggregations needkind: sqlorkind: python.
Prerequisites
- The calling sheet exists, validates, and has the target field
declared
x-derived: trueincontract.yaml. - The foreign sheet exists at a path resolvable from the calling
sheet (typically
../<sibling>), validates, and contains the field you want to copy. - Both sheets agree on the PK value space (identical strings, same case, no leading/trailing whitespace).
Procedure
-
Confirm the sidecar layout. Folio resolves
source_sheetrelative to the calling sheet's root. The conventional layout:customers/ customer-revenue/ ├── contract.yaml ──→ ├── contract.yaml ├── records.jsonl ├── records.jsonl │ (id, revenue_usd, ...) └── derivations/ └── revenue.yaml ◀── reads from ../customer-revenue -
Add the target field to
contract.yamlof the calling sheet, marked derived:- name: current_revenue_usd logicalType: number x-derived: true x-inputs: [] # join is by PK, no other inputs -
Write
derivations/<target>.yamlin the calling sheet. Single-target skeleton:# customers/derivations/revenue.yaml targets: [current_revenue_usd] inputs: [] # join is by PK, no other inputs kind: cross_sheet source_sheet: ../customer-revenue # path relative to this sheet key_field: id # field on the foreign sheet value_field: revenue_usd # field whose value to copyMulti-target (all updated atomically, share one
input_hash):targets: [current_revenue_usd, contract_value_usd, finance_as_of] inputs: [] kind: cross_sheet source_sheet: ../customer-revenue key_field: id value_fields: # mutually exclusive with value_field current_revenue_usd: revenue_usd contract_value_usd: contract_value_usd finance_as_of: as_of -
Validate both sheets, then materialize the calling one.
folio validateruns against the foreign sheet too — broken foreign data shows up here, not silently in the join.folio validate ./customers folio validate ./customer-revenue folio materialize ./customers current_revenue_usd --actor agent:demoThe derivation target is a positional argument to
folio materialize; omit it to materialize every derivation.The §10.6 envelope:
{"materialized": 2, "skipped": 0, "failures": [], "total_cost": 0.0} -
Spot-check a row.
folio query ./customers \ "SELECT id, current_revenue_usd FROM records ORDER BY id LIMIT 5"
Verify
folio validate <sheet>
folio validate <foreign_sheet>
folio materialize <sheet> <field> --actor agent:demo
All three should exit 0. The materialize envelope's failures should
be []. Records with no foreign match keep the field null and are
not counted as failures (see below).
Cache behaviour
input_hash for a cross_sheet cell includes:
- the canonical JSON of every input value (often empty),
- the calling sheet's primary key value,
- the SHA-256 of the foreign sheet's
records.jsonl, - the SHA-256 of the derivation file.
That third item is load-bearing: edit the foreign records.jsonl,
every calling-side row's hash changes, and the next materialize
re-joins everything. Right behaviour when you don't know which
foreign rows changed.
If the foreign sheet is huge and changes constantly, prefer a
snapshot via kind: import instead.
"No match" semantics
If the foreign sheet has no row whose <key_field> equals the
calling sheet's PK, Folio writes nothing for that cell, the value
stays null, and nothing is reported on the envelope. Missing
foreign rows are an expected case for cross_sheet.
If you want a failure in that case, layer a kind: python
derivation downstream that asserts the field is non-null after
cross_sheet runs.
Common mistakes (don't make them)
- Joining by a non-PK field.
cross_sheetmatches the foreignkey_fieldagainst the calling sheet's PK, not against an arbitrary calling-side input. If you need lookup by an input, reach forimportorpython. - Both
value_fieldandvalue_fieldsset. They are mutually exclusive. Folio rejects. - Wrong relative path on
source_sheet. Paths are relative to the calling sheet's root, not toderivations/. Most sidecar setups use../<other_sheet>. - PK mismatch. Trailing whitespace, case differences, or numeric-vs-string discrepancies will silently produce no match (see "No match" above). Normalize on the source side.
- Foreign records edited but the calling sheet not re-materialized.
The cache flips correctly on the next run; what's wrong is letting
agents read the stale
current_revenue_usdin between. Re-run materialize after foreign updates, or schedule it.