Adding a Window Operator
Run the site checklist first.
make sites ARGS="new-op window"prints every file and declaration a newWIN_*lands in — derived from where the existing ones appear — with the tests to rerun and the goldens to regenerate;make sites ARGS="op <NAME>"does the same for an existing one. See Finding Change Sites. This recipe explains each step.
Embedding Pulse, not contributing to it? This recipe adds a built-in in
internal/processing/, which embedders cannot import. To add your own operator, implement the matching contract in the publicextendpackage instead — see Extension Points.
Audience: Pulse internals contributors adding a new WIN_*
operator — a window-frame function that emits a per-row value derived
from a sliding or anchored frame around the current record
(WIN_LAG, WIN_LEAD, WIN_RANK, WIN_RUNNING_*, WIN_EWMA, …).
The recipe mirrors the aggregator recipe; the window-specific moving parts are the frame contract and the windows registry. Streamability is not one of them — see step 3.
1. Declare the type constant
Add the new constant to types/types.go and the slice returned by
types.AllWindowTypes():
const (
// ... existing constants ...
WIN_PERCENT_RANK WindowType = "WIN_PERCENT_RANK"
)
Append it to types.AllWindowTypes().
2. Implement and register
Window operators live under internal/processing/window/. Each file is one
operator; register the factory in the package’s init() via the
register(types.WIN_PERCENT_RANK, newPercentRank) call shape used by
sibling files (lag.go).
The frame semantics — anchored vs sliding, lookahead vs lookback — are part of the operator’s contract and ride in the operator’s struct parameters; the orchestrator’s window-pass invokes the implementation per row in declared order.
Slot validation is NOT the factory’s job alone. internal/windowparams is
the one reading of a window slot, shared by predict
(internal/descriptor/predict_window.go) and the engine (register wraps
every factory with it; applyWindows runs it for extension windows too):
add the operator to its fieldRequired / frameRequired /
frameRejected tables and put any params rule in paramsRefusal, so both
sides refuse with PULSE_WINDOW_INVALID and the same rule sentence. Then
add the operator’s row to windowParityRows in
internal/integration/window_refusal_parity_test.go — TestWindowRefusals_PredictMatchesRuntime
fails for a window type without one.
3. Streamability — nothing to do
No window operator streams. WindowType.Streamable() in
types/streamability.go is an unconditional return false, because every
WIN_* operator needs a sort over the row set:
func (t WindowType) Streamable() bool {
return false
}
There is no per-type case to add and no table row to write.
TestStreamability_WindowsKnown iterates types.AllWindowTypes() and asserts
every constant answers false, so a new operator is covered the moment step 1
lands.
4. Capability declaration
Add a row to internal/descriptor/capabilities_window_ops.go with the operator’s
params, accepted field types, and streamable hint.
TestManifestOperatorsComplete enforces a capability row per registered
window operator.
5. Tests
Add tests in internal/processing/window/<name>_test.go. Cover the empty-frame,
single-row, null-bearing, and order-sensitive cases.
6. Write the atomic skill
The gated target is the atomic skill skills/op-win-percent-rank.md (the operator name lowercased, _ → -: skills.OperatorStem), not a
section in skills/window-design.md — TestSkillsCoverAllWindowTypes and
TestOperatorHasAtomicSkill both key off that stem. Frontmatter name: must
equal the file stem; category: WIN; operator: the full constant. The
required ## sections are ## Params, ## Inputs, ## Output,
## Gotchas, ## See, and the body has a hard budget (the op-* tier in
.claude/reference/skill-pack.md; TestAtomicSkillHasRequiredSections,
TestSkillTokenBudget).
## Params is the one | Name | Type | Default | Description | table, one
row per declared param (partition_by / order_by / frame may sit beside
them), Default (required) / — / the declared value
(TestSkillParamsMatchManifest).
Add the operator to skills/window-design.md only where the topical prose
would otherwise be wrong (the frame-forbidden list, a family gotcha) — per-op
detail belongs in the atomic file.
7. The other per-operator tables
Every window also has an entry in builtinFeatures
(internal/descriptor/features.go), internal/descriptor/purposes_window.go
and internal/descriptor/interpretation_reading.go, and an example in
internal/examples/windows/ (NN_<name>.json, plus its README row) whose
_meta.operators names it (TestEveryOperatorHasAnExampleTag). make sites ARGS="new-op window" names each with an exemplar line. CLAUDE.md is not a
companion.
8. Run the gates
make sites ARGS="op WIN_PERCENT_RANK" prints the full gate set. At minimum:
go test -count=1 ./internal/skills/ -run 'TestSkillsCoverAllWindowTypes|TestOperatorHasAtomicSkill'
go test -count=1 ./internal/descriptor/ -run 'TestManifestOperatorsComplete|TestSkillParamsMatchManifest'
go test -count=1 ./internal/processing/window/... ./internal/windowparams/
go test -count=1 ./internal/integration/ -run TestWindowRefusals_PredictMatchesRuntime
go test -count=1 ./types/ -run TestStreamability_WindowsKnown
go test -count=1 ./descriptor/ -update && go test -count=1 ./descriptor/
make docs
See The Update Demand.