codex/skills/kan/SKILL.md
Use when universalist or the user names a concrete world/boundary requiring Kan mechanics: Kan extensions/lifts, pre/postcomposition, Freyd/AFT free-builder diagnostics, Yoneda/Coyoneda boundary representations, defunctionalized boundary IRs, codensity/density and dense probes/duality, Exact Context Doctrine, context compilation, task-indexed exchange, Context Certificates, pointwise formulas, free/cofree completions, functorial data migration, compatibility facades, lifted implementations, residual obligations, Composition Certificates, Boundary Normal Form audits, or categorical law tests. Do not use for generic architecture unless worlds, boundary kind, known side, unknown location, witness slice, proof signal, and when applicable Composition Certificate are named or must be recovered.
npx skillsauth add tkersey/dotfiles kanInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use this skill for the detailed categorical mechanics behind universal architecture boundaries.
universalist chooses whether a seam deserves a canonical artifact. kan elaborates the selected artifact: Kan extension, Kan lift, Freyd/AFT diagnostic, Yoneda/Coyoneda representation, defunctionalized IR, codensity, data migration, context compilation, or law tests.
Core rule:
Primitives compute. Boundaries compose. Presentations compress. Contexts prepare. Witnesses certify.
Do not start with category labels. Start with worlds, boundary kind, known side, unknown location, witness, and law.
## Required Handoff Contract
Do not begin detailed Kan mechanics unless the prompt or prior analysis provides, or you first recover:
- signal / smell;
- seam;
- source and target worlds;
- boundary kind;
- known side;
- unknown location;
- candidate artifact;
- witness slice;
- proof signal;
- falsifier;
- Composition Certificate fields if the seam is already certified or being certified;
- Context Certificate fields if the seam is a semantic-consumption/context-compilation boundary.
- Verified Context Plane fields if schemas, mappings, constraints, provenance, publication, or CQL-like tooling are relevant.
If these are absent, first produce a short world/boundary inventory and ask whether to proceed, unless the user requested a best-effort implementation.
## Composition Certificate Elaboration
Use this skill in two modes:
1. **Recover mode**: no certificate exists yet, so produce a compact world/boundary inventory and identify the missing certificate fields.
2. **Elaboration mode**: a certificate exists, so refine its categorical mechanics without changing the selected boundary artifact unless the mechanics expose an obstruction.
For any Kan output, preserve this mapping:
| Certificate field | Kan elaboration |
| --- | --- |
| Worlds | candidate categories / indexed structures / posets / syntactic worlds |
| Boundary kind | `K`, `P`, interpreter, handler, serializer, view, migration, observer |
| Unknown location | extension axis, lift axis, representation axis, control-flow axis |
| Canonical artifact | `Lan`, `Ran`, `Delta`, `Lft`, `Rft`, Yoneda, Coyoneda, explicit IR, free builder, obstruction |
| Interpreter/projection/lowering | unit, counit, comparison cell, handler, `runObservation`, `lowerGenerated`, `apply` |
| Law witness | naturality, factorization, projection law, lowering law, handler law, defunctionalization equivalence |
| Falsifier | no colimit/limit/residual, lossy projection, incoherent observations, invalid path, missing constructor, no exact lift |
If the prompt asks for code, emit the certificate-aware implementation plan: artifact, interpreter/projection, law test, falsifier, and bypass policy.
## Exact Context / Context Compilation Mode
Use this mode when the selected boundary is a semantic-consumption boundary: a model, human, policy engine, workflow, scheduler, planner, ranker, classifier, compiler pass, deployment controller, BI dashboard, auditor, tool selector, or agent runtime is about to consume prepared information.
Recover:
- Task `q` and semantic consumer.
- Source worlds and source schema `S`.
- Candidate source instance `I_candidate`.
- Task-specific context schema `T_q`.
- Required observables `Obs_q`.
- Source-to-context mapping `M_q : S -> T_q` or source-to-target dependencies.
- Migration mode: restriction/projection, left pushforward/merge, right pushforward/join, or practical analogue.
- Chase/closure steps: deterministic constraint enforcement, equality propagation, entity resolution, unit/date normalization.
- Provenance graph: `Claim -> Evidence -> Source`, `DerivedFact -> Derivation -> Inputs`.
- Missingness, contradiction, ambiguity, and unsupported-claim representation.
- Observational core/minimization relative to `Obs_q`.
- Rendering law for prompt/report/dashboard/tool-argument/decision-packet output.
- Freshness law and invalidation triggers.
Use this formula:
```text
Context(q) = core_Obs(chase(migrate_{M_q}(I_candidate)))
DecisionPacket(q) = render(Context(q))
Do not treat retrieval as context. Retrieval is candidate source-instance generation.
Use this mode when context compilation requires verified canonicalization, integration, constraints, provenance, schema evolution, or source reconciliation.
Recover:
CQL/categorical databases are reference technologies when the hard problem is typed integration, schema mappings, constraints, colimits/pushouts, and provenance. Do not recommend CQL as the default primary live memory or low-latency mutable store. Pair verified context tooling with operational stores when mutation, concurrency, authorization, or streaming dominate.
Use this placement rule:
Operational stores own mutation.
Verified context planes own semantic publication.
Use this mode when a target monad/effect/behavior is too semantic, infinitary, observational, probabilistic, topological, or completion-like for a useful algebraic presentation by generators/equations.
Recover:
Use this slogan:
Algebraic presentations build by constructors.
Codensity presentations reconstruct from dense probes and dual observations.
Do not treat codensity only as optimization. It is also a presentation technology.
Use when the requested Kan mechanics concern exact context, semantic consumption, or categorical data exchange for a task.
Deliver:
q and semantic consumer;S and candidate source instance I_candidate;T_q;Obs_q;M_q;Before naming Lan, Ran, Lft, Rft, Yoneda, Coyoneda, or Freyd/AFT, record the worlds.
For each world:
World:
Objects:
Transformations:
Invariants:
Observations:
Primitives:
Composition rules:
Equality/coherence notion:
A world is too weak for Kan mechanics if it has only nouns, no transformations, no equality/coherence notion, no observations, unstable invariants, or no law test.
| Boundary kind | Software shape | Kan/categorical reading | First law |
| --- | --- | --- | --- |
| Embedding | old/core included in new/target | Lan, Ran, Delta | new(embed(old)) == old(old) |
| Projection | internals observed as public behavior | Kan lift, P_*, Freyd diagnostic | observe(P(internal)) == required |
| Forgetful map | rich structure erased to raw view | adjunction / free builder | forget(free(raw)) satisfies raw behavior |
| Interpreter | syntax/effect/program -> behavior | algebra, fold, handler | interpreter agrees on fixtures |
| Compiler/lowering | source syntax/IR -> target IR/code | transported semantics, Coyoneda path | lowering preserves semantics |
| Serializer/codec | internal model -> wire/storage | projection/restriction, possible lift obstruction | round-trip or invariant preservation |
| View/query | model -> report/client view | Ran, Yoneda observation | overlapping observations commute |
| Handler | effect syntax -> runtime behavior | free effects, handler, defunctionalized operations | handler satisfies operation observations |
| Observer | subject -> observation result | Yoneda / Ran / Rft | representation change preserves observation |
| Migration | old schema -> new schema | Delta, Lan/Sigma, Ran/Pi | old reports pass through migration |
| Context compiler | source worlds -> task context schema | data exchange, migration/chase/core, context compilation | context satisfies schema, observables, provenance, freshness |
| Semantic consumer | context -> decision/action/inference | Exact Context, Context Certificate, rendering law | rendered packet preserves required observables |
Use when known source semantics must be transported or completed across K.
C --K--> D
| |
F ?
v v
E
Recover:
C: source/core/legacy/specified world.D: target/ambient/expanded world.E: semantic/artifact/instance world.K : C -> D: embedding, schema map, API-version map, AST embedding, representation functor.F : C -> E: existing semantics, interpreter, instance, behavior, test oracle.Lan_K F: free/generative/push-forward extension.Ran_K F: coherent/conservative extension by observations.K* / Delta_K: restriction/precomposition.η : F -> Lan_K F · K.ε : Ran_K F · K -> F.d ∈ D and one law test.Use when public behavior is known and the implementation-side artifact must be solved behind P.
A --?--> B
| |
F P
v v
C0
Recover:
A: cases/contracts/tests/workflows/requirements.B: implementation/internal/runtime/resource world.C0: observable/public/external behavior world.P : B -> C0: projection, public API, view, handler, serializer, trace observer, compiler backend.F : A -> C0: required observable behavior.Lft_P F: realization behind P, comparison F -> P · Lft_P F.Rft_P F: residual/sound obligation behind P, comparison P · Rft_P F -> F.P_*: direct projection/checking when implementation is already known.a ∈ A and one projection law.Use local notation Lft_P and Rft_P because Kan lift notation varies.
Use when the boundary is observation-heavy: views, reports, public API projections, policy checks, contract assertions, test oracles, capability consumers, continuations.
Artifact:
data Observation = ...
runObservation : Observation -> Subject -> Result
Law:
runObservation(obs, repack(subject)) == runObservation(obs, subject)
Use when the boundary is generation-heavy: generated DTOs, plugin operations, migrations, AST extensions, workflow steps, candidate realizers.
Artifact:
data Generated = { payload, path }
lowerGenerated : Generated -> Target
Law:
lowerGenerated(payload,path) == directInterpret(path,payload)
Use when functions cross architecture boundaries: callbacks, continuations, observers, selectors, handlers, predicates, builders, maps, resumptions.
Artifact:
data BoundaryCase = ...captured fields...
apply/interpret/project : BoundaryCase -> Meaning
Law:
apply(encode(oldFunction), input) == oldFunction(input)
Run this only after a lift-shaped boundary appears.
Question:
Is P : B -> C0 disciplined enough to support a canonical free builder Free : C0 -> B?
Check:
P is concrete, not metaphorical.B can combine constraints: products, pullbacks, equalizers, policy meets, workflow composition, validations.P preserves those constraints enough to test.Free has a projection law:P(Free(required(case))) satisfies required(case)
If not, produce an obstruction report: lost evidence, vague projection, missing internal structure, unbounded templates, impossible observation, or required external dependency.
Use when the user already has or wants a Composition Certificate.
P : B -> C0 is concrete and there is a builder or obstruction report.scripts/emit_world_boundary_preamble.sh scripts/emit_composition_certificate_kan.sh scripts/emit_boundary_normal_form_kan.sh scripts/emit_codensity_presentation.sh scripts/emit_context_compilation_report.sh <focus> [language]scripts/emit_boundary_kind_map.sh [kind]scripts/emit_kan_stub.sh <kind> [language]scripts/emit_law_test_plan.sh <direction> [language]scripts/emit_yoneda_pass.sh <focus> [language]scripts/emit_defun_pass.sh <focus> [language]scripts/emit_freyd_pass.sh <focus> [language]scripts/emit_source_pack.sh <track> [focus]scripts/check_skill.shreferences/world-boundary-preamble.md references/composition-certificate-elaboration.mdreferences/boundary-kind-to-kan.mdreferences/foundations.mdreferences/kan-lifts.mdreferences/yoneda-coyoneda.mdreferences/defunctionalization.mdreferences/freyd-aft.mdreferences/architecture-transformation.mdreferences/law-tests.mdreferences/claim-map.mdreferences/sources.mdreferences/sources.ymltesting
Use before local patching when bugs, regressions, malformed state, crashes, parser failures, migrations, cache drift, protocol problems, compatibility requests, tolerant readers, fallbacks, coercions, retries, catch-and-continue logic, or local workarounds may broaden accepted invalid state.
testing
Use for bug reports, PR/issue prose, reviewer comments, user diagnoses, generated summaries, memories, retrieved context, public tracker context, claimed root causes, proposed fixes, fake-minimal repro risk, or any investigation where natural-language context could anchor the implementation scope.
development
Use when non-trivial work needs Challenge Escalation, latent-intelligence activation, frame-market selection, doctrine operators, dominant-move selection, ablation/surface-tax judgment, reification, review comment law, negative capability, route receipts, or proof-bearing refusal to mutate.
development
Apply Algebra-Driven Design. Use for ADD, denotational design, combinator models, law-driven architecture, domain algebra, property tests, codebase modeling, event sourcing, workflow design, or agentic skill design. If the canonical bundle is unavailable, use this wrapper as the minimal ADD kernel and report the missing bundle path.