writing-pivot-stages
Use when writing Pivot pipeline stages, seeing annotation errors (Dep, Out, Annotated), loader mismatches, "cannot pickle" errors, DirectoryOut validation failures, or IncrementalOut path mismatches
What this skill does
# Writing Pivot Stages
## Overview
Pivot stages are pure Python functions declaring file I/O via type annotations. The framework handles loading, saving, caching, and DAG construction.
**Core principle:** Annotations handle all file I/O. Functions receive pre-loaded data and return data to be saved.
## Imports
```python
import pivot # Single import — access everything via pivot.*
from typing import Annotated, TypedDict
```
All Pivot types are accessed via the `pivot` namespace:
| What | Access |
|------|--------|
| Dependencies | `pivot.Dep`, `pivot.PlaceholderDep` |
| Outputs | `pivot.Out`, `pivot.Metric`, `pivot.Plot`, `pivot.IncrementalOut`, `pivot.DirectoryOut` |
| Loaders | `pivot.loaders.CSV()`, `pivot.loaders.JSON()`, `pivot.loaders.YAML()`, etc. |
| Base classes | `pivot.loaders.Reader`, `pivot.loaders.Writer`, `pivot.loaders.Loader` |
| Params | `pivot.StageParams` |
| Pipeline | `pivot.Pipeline` |
| Decorators | `pivot.no_fingerprint` |
## Stage Anatomy
```python
import pivot
class MyParams(pivot.StageParams):
threshold: float = 0.5
class MyOutputs(TypedDict):
result: Annotated[pd.DataFrame, pivot.Out("output.csv", pivot.loaders.CSV())]
metrics: Annotated[dict, pivot.Metric("metrics.json")]
def my_stage(
params: MyParams,
data: Annotated[pd.DataFrame, pivot.Dep("input.csv", pivot.loaders.CSV())],
) -> MyOutputs:
filtered = data[data["score"] > params.threshold]
return {"result": filtered, "metrics": {"count": len(filtered)}}
pipeline = pivot.Pipeline("my_pipeline")
pipeline.register(my_stage, params=MyParams(threshold=0.3))
```
**Single output:** Annotate return directly instead of TypedDict:
```python
def transform(
data: Annotated[pd.DataFrame, pivot.Dep("input.csv", pivot.loaders.CSV())],
) -> Annotated[pd.DataFrame, pivot.Out("output.csv", pivot.loaders.CSV())]:
return data.dropna()
```
## Loader Hierarchy
| Base Class | Methods | Use Case |
|------------|---------|----------|
| `Reader[R]` | `load() -> R` | Read-only (dependencies) |
| `Writer[W]` | `save(data: W, ...)` | Write-only (outputs) |
| `Loader[W, R]` | Both `load()` and `save()` | Bidirectional (incremental outputs) |
**Type constraints:**
- `Dep.loader` accepts `Reader[R]` (or `Loader`, which extends `Reader`)
- `Out.loader` accepts `Writer[W]` (or `Loader`, which extends `Writer`)
- `IncrementalOut.loader` requires `Loader[W, R]` (needs both read and write)
- `DirectoryOut.loader` accepts `Writer[T]`
## Built-in Loaders
| Loader | Base | Data Type | Options | `empty()` |
|--------|------|-----------|---------|-----------|
| `CSV()` | `Loader` | DataFrame | `index_col`, `sep`, `dtype` | Yes |
| `JSON()` | `Loader` | dict/list | `indent=2`, `empty_factory=dict` | Yes |
| `JSONL()` | `Loader` | list[dict] | — | Yes |
| `DataFrameJSONL()` | `Loader` | DataFrame | — | Yes |
| `YAML()` | `Loader` | dict/list | `empty_factory=dict` | Yes |
| `Text()` | `Loader` | str | — | Yes |
| `Pickle()` | `Loader` | Any | `protocol` | No |
| `PathOnly()` | `Loader` | Path | — | No |
| `MatplotlibFigure()` | `Writer` | Figure | `dpi=150`, `bbox_inches`, `transparent` | N/A |
**Notes:**
- `DataFrameJSONL()` reads/writes DataFrames as JSON Lines (orient=records). Preferred over `CSV()` for non-trivial DataFrames (preserves types, handles nested data).
- Loaders with `empty()` support are required for `IncrementalOut`.
- `MatplotlibFigure` is `Writer[Figure]` (write-only) — images can't be loaded back as Figure objects.
## Output Types
| Type | Default Cache | Git-Tracked | Use Case |
|------|---------------|-------------|----------|
| `Out` | True | No | Standard outputs |
| `Metric` | False | Yes | Small YAML/JSON metrics |
| `Plot` | True | No | Visualizations |
| `IncrementalOut` | True | No | Builds on previous run's output |
| `DirectoryOut` | True | No | Dynamic set of files in directory |
## Multi-File Dependencies/Outputs
```python
# Variable-length list (count can change between runs)
shards: Annotated[list[pd.DataFrame], pivot.Dep(["a.csv", "b.csv"], pivot.loaders.CSV())]
# Fixed-length tuple (exact count enforced)
pair: Annotated[tuple[pd.DataFrame, pd.DataFrame], pivot.Dep(("x.csv", "y.csv"), pivot.loaders.CSV())]
```
## IncrementalOut
Previous output restored from cache before stage runs. Use for append-only state:
```python
class CacheOutputs(TypedDict):
cache: Annotated[dict, pivot.IncrementalOut("cache.json", pivot.loaders.JSON())]
def incremental_stage(
cache: Annotated[dict | None, pivot.IncrementalOut("cache.json", pivot.loaders.JSON())],
) -> CacheOutputs:
existing = cache or {}
existing["new_key"] = "value"
return {"cache": existing}
```
**Rules:** Same path in input and output annotations. Loader must support `empty()`.
## DirectoryOut
For dynamic file sets determined at runtime:
```python
class TaskOutputs(TypedDict):
results: Annotated[dict[str, dict], pivot.DirectoryOut("results/", pivot.loaders.JSON())]
def process_tasks(...) -> TaskOutputs:
return {"results": {
"task_a.json": {"accuracy": 0.95},
"task_b.json": {"accuracy": 0.87},
}}
```
**Rules:**
- Path must end with `/`
- Keys must have extensions, no path traversal (`../`), no absolute paths
- Dict must be non-empty
## PlaceholderDep
Dependency with no default path — must be overridden at registration:
```python
def compare(
baseline: Annotated[pd.DataFrame, pivot.PlaceholderDep(pivot.loaders.CSV())],
) -> CompareOutputs: ...
pipeline.register(compare, dep_path_overrides={"baseline": "model_a/results.csv"})
```
## Matplotlib Plots
Plots require all three parts in the annotation:
```python
Annotated[
matplotlib.figure.Figure, # 1. Type (must be Figure, not Axes)
pivot.Plot("plots/my_plot.png", # 2. Output type (Plot, not Out)
pivot.loaders.MatplotlibFigure()) # 3. Writer (handles save/close)
]
```
**Full example:**
```python
import matplotlib.figure
import matplotlib.pyplot as plt
import pivot
class PlotOutputs(TypedDict):
plot: Annotated[matplotlib.figure.Figure, pivot.Plot("plots/my.png", pivot.loaders.MatplotlibFigure())]
def make_plot(
data: Annotated[pd.DataFrame, pivot.Dep("input.csv", pivot.loaders.CSV())],
) -> PlotOutputs:
fig, ax = plt.subplots()
ax.plot(data["x"], data["y"])
return {"plot": fig} # Return Figure, not Axes. Framework saves and closes.
```
## Path Overrides and Variants
Override paths at registration time — useful for running same stage with different inputs/outputs:
```python
# Simple override
pipeline.register(my_stage, name="my_stage@v2", out_path_overrides={"result": "v2/output.csv"})
# Variant pattern: register same function multiple times with different paths
for variant, suffix in [("current", ""), ("legacy", "_legacy")]:
pipeline.register(
merge_data,
name=f"merge_data@{variant}",
dep_path_overrides={"input": f"data/raw/input{suffix}.jsonl"},
out_path_overrides={"output": f"data/processed/output{suffix}.jsonl"},
params=MergeParams(suffix=suffix),
)
```
## Path Resolution
- Paths in annotations are **relative to the pipeline root** (defaults to directory of the file calling `Pipeline()`)
- Parent references (`..`) are resolved during registration — `Dep("../shared/data.csv")` works
- Resolved path must stay within the **project root** (the top-most directory with `.pivot/`)
- Dependencies may use absolute paths (reduces portability). Outputs must resolve within project root.
- For multi-pipeline projects, set `root=pivot.project.get_project_root()` to share a common base:
```python
pipeline = pivot.Pipeline("my_pipeline", root=pivot.project.get_project_root())
```
## Custom Loaders
Extend the appropriate base class. Use `@dataclasses.dataclass(frozen=True)` for immutability and pickling.
```python
import dataclasses
import pathlib
import pivot
# Reader (read-only) — for Dep
@dataclasses.dataclass(frozen=TrRelated in Writing & Docs
jax-development
IncludedUse this skill when the user is writing, debugging, profiling, refactoring, reviewing, benchmarking, parallelising, exporting, or explaining JAX code, or when they mention JAX, jax.numpy, jit, grad, value_and_grad, vmap, scan, lax, random keys, pytrees, jax.Array, sharding, Mesh, PartitionSpec, NamedSharding, pmap, shard_map, Pallas, XLA, StableHLO, checkify, profiler, or the JAX repo. It helps turn NumPy or PyTorch-style code into pure functional JAX, fix tracer/control-flow/shape/PRNG bugs, remove recompiles and host-device syncs, choose transforms and sharding strategies, inspect jaxpr/lowering/IR, and benchmark compiled code correctly.
nature-article-writer
IncludedDrafts, rewrites, diagnostically critiques, and style-calibrates primary research manuscripts for Nature and Nature Portfolio journals. Use when the user wants a Nature-style title, summary paragraph or abstract, introduction, results, discussion, methods, figure legends, presubmission enquiry, cover letter, reviewer response, or when a scientific draft sounds generic, jargon-heavy, structurally weak, or AI-ish and needs precise, broad-reader-friendly prose without inventing data, analyses, or references. Best for primary research articles and letters rather than reviews or press releases unless explicitly adapting one.
deckrd
IncludedDocument-driven framework that derives requirements, specifications, implementation plans, and executable tasks from goals through structured AI dialogue. Use when user says "write requirements", "create spec", "plan implementation", "derive tasks", "structure this feature", "break down into tasks", or "document this module". Also use for reverse engineering existing code into docs (/deckrd rev). Do NOT use for direct code writing — use /deckrd-coder after tasks are generated. Do NOT use when the user only wants to run or fix existing code without planning.
clinical-decision-support
IncludedGenerate professional clinical decision support (CDS) documents for pharmaceutical and clinical research settings, including patient cohort analyses (biomarker-stratified with outcomes) and treatment recommendation reports (evidence-based guidelines with decision algorithms). Supports GRADE evidence grading, statistical analysis (hazard ratios, survival curves, waterfall plots), biomarker integration, and regulatory compliance. Outputs publication-ready LaTeX/PDF format optimized for drug development, clinical research, and evidence synthesis.
handling-sf-data
IncludedSalesforce data operations with 130-point scoring. Use this skill to create, update, delete, bulk import/export, generate test data, and clean up org records using sf CLI and anonymous Apex. TRIGGER when: user creates test data, performs bulk import/export, uses sf data CLI commands, needs data factory patterns for Apex tests, or needs to seed/clean records in a Salesforce org. DO NOT TRIGGER when: SOQL query writing only (use querying-soql), Apex test execution (use running-apex-tests), or metadata deployment (use deploying-metadata).
accelint-ac-to-playwright
IncludedConvert and validate acceptance criteria for Playwright test automation. Use when user asks to (1) review/evaluate/check if AC are ready for automation, (2) assess if AC can be converted as-is, (3) validate AC quality for Playwright, (4) turn AC into tests, (5) generate tests from acceptance criteria, (6) convert .md bullets or .feature Gherkin files to Playwright specs, (7) create test automation from requirements. Handles both bullet-style markdown and Gherkin syntax with JSON test plan generation and validation.