# tools/core/generators/binding.generator.ts

> 102 lines of code and 16 definitions.

Tree: Coordination tree
Language: typescript
Canonical: https://banes-lab.com/anatomy/coordination#file-coordination-tools-core-generators-binding-generator-ts
Source text: https://banes-lab.com/assets/sources/source.8d3f67b7c7bfbbb4fd53dc0c5cbe905a038047578be3730e0fad4b7fa90b99a9.generated.txt

## Definitions

- `renderRow` (lexical_declaration, line 33)
- `writeBinding` (lexical_declaration, line 112, exported)
- `renderValue` (lexical_declaration, line 17)
- `renderBinding` (lexical_declaration, line 37, exported)
- `SECTIONS` (lexical_declaration, line 5)
- `HEADING` (lexical_declaration, line 7)
- `MARKER` (lexical_declaration, line 15)
- `lines` (lexical_declaration, line 38, exported)
- `names` (lexical_declaration, line 73, exported)
- `slot` (lexical_declaration, line 80, exported)
- `counts` (lexical_declaration, line 89, exported)
- `slots` (lexical_declaration, line 90, exported)
- `values` (lexical_declaration, line 91, exported)
- `resolved` (lexical_declaration, line 92, exported)
- `absent` (lexical_declaration, line 93, exported)
- `deferred` (lexical_declaration, line 94, exported)

## Uses

- [tools/core/writers/repair.writer.ts](https://banes-lab.com/source/coordination/tools/core/writers/repair.writer.ts.md)

## Used by

- [tools/rules/binding.rule.ts](https://banes-lab.com/source/coordination/tools/rules/binding.rule.ts.md)

## Source

```typescript
import { type Slot, type SlotValue, type SurfaceConfig, config } from "../../../config/surface.config.ts";
import { BINDING_PATH } from "../constants/binding.constants.ts";
import { writeRepair } from "../writers/repair.writer.ts";

const SECTIONS: readonly (keyof SurfaceConfig)[] = ["project", "surface", "convention", "limits", "execution"];

const HEADING: Readonly<Record<string, string>> = {
    convention: "Convention slots",
    execution: "Execution",
    limits: "Limits",
    project: "Project slots — what the host supplies",
    surface: "Surface slots — what this package owns",
};

const MARKER = "<!-- GENERATED from the surface configuration. Edit the configuration, never this file. -->";

const renderValue = function renderValue(value: SlotValue): string {
    if (value === null) {
        return "—";
    }
    if (typeof value === "number") {
        return `\`${String(value)}\``;
    }
    if (typeof value === "string") {
        return `\`${value}\``;
    }
    if (value.length === 0) {
        return "`[]` — declared and empty";
    }
    return value.map((entry) => `\`${entry}\``).join(" · ");
};

const renderRow = function renderRow(section: string, name: string, slot: Slot): string {
    return `| \`{${section}.${name}}\` | ${slot.state} | ${renderValue(slot.value)} | ${slot.note} |`;
};

export const renderBinding = function renderBinding(): string {
    const lines: string[] = [
        MARKER,
        "---",
        "name: adapter-project-binding",
        "type: binding",
        "summary: Resolves every abstract slot the reasoning templates and the placement standard declare, against this deployment. A slot is RESOLVED, ABSENT or DEFERRED — never silently faked.",
        "concern: binding",
        "status: current",
        "---",
        "",
        "# Adapter — project binding",
        "",
        "The reasoning templates and the placement standard are runtime-neutral cores. They carry no paths,",
        "no commands and no model, and instead declare `{slots}` an adapter resolves against the host. This",
        "document is that adapter, and it is RENDERED from the surface configuration — the values live there,",
        "so a hand edit here is a second truth that disagrees the moment one of them moves.",
        "",
        "## Resolution states",
        "",
        "Every slot resolves to exactly one of three states. The third is the one that matters.",
        "",
        "| state | meaning | consequence |",
        "|---|---|---|",
        "| `RESOLVED` | a real value exists here | the branch using it runs |",
        "| `ABSENT` | this deployment has no analogue | **the branch using it does not run, and that is declared** |",
        "| `DEFERRED` | it will exist; it does not yet | the branch is blocked, not skipped |",
        "",
        "`ABSENT` is a first-class answer. A consumer gating on a build command in a deployment with no build",
        "reports that it cannot gate, never invents a substitute and never quietly passes. **An adapter that",
        "resolves everything is an adapter that is lying about something.**",
        "",
    ];

    for (const section of SECTIONS) {
        const slots = config[section];
        const names = Object.keys(slots).toSorted((left, right) => left.localeCompare(right, "en"));
        if (names.length === 0) {
            continue;
        }

        lines.push(`## ${HEADING[section] ?? section}`, "", "| slot | state | value | why |", "|---|---|---|---|");
        for (const name of names) {
            const slot = slots[name];
            if (slot === undefined) {
                continue;
            }
            lines.push(renderRow(section, name, slot));
        }
        lines.push("");
    }

    const counts = SECTIONS.map((section) => {
        const slots = config[section];
        const values = Object.values(slots);
        const resolved = values.filter((slot) => slot.state === "RESOLVED").length;
        const absent = values.filter((slot) => slot.state === "ABSENT").length;
        const deferred = values.filter((slot) => slot.state === "DEFERRED").length;
        return `| \`${section}\` | ${String(resolved)} | ${String(absent)} | ${String(deferred)} |`;
    });

    lines.push(
        "## Resolution census",
        "",
        "Derived on render, so it cannot disagree with the table above.",
        "",
        "| section | RESOLVED | ABSENT | DEFERRED |",
        "|---|---|---|---|",
        ...counts,
        "",
    );

    return `${lines.join("\n")}\n`;
};

export const writeBinding = function writeBinding(repoRoot: string, rendered: string, declared = ""): string | null {
    return writeRepair({ declared, repoRoot }, BINDING_PATH, rendered).refusal;
};
```
