Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 123 additions & 3 deletions docs/app/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,91 @@ html > body[data-scroll-locked] {
body {
overflow-wrap: anywhere;
}
table {
overflow-wrap: break-word;
}
}

/* Tables (components/table.tsx). One rounded box, a quiet header, a hairline
between rows and no lines between columns. Columns of short keys stay on
one line; columns of text get a minimum width from the component, so a
wide table scrolls inside its box (with a fade on the side that has more)
and the page never scrolls sideways. */
.ch-table {
--tbl-bg: var(--color-fd-background);
--tbl-fade: color-mix(in oklab, var(--color-fd-foreground) 14%, transparent);
position: relative;
max-width: 100%;
margin: 1.5rem 0;
overflow-x: auto;
overscroll-behavior-x: contain;
border: 1px solid var(--color-fd-border);
border-radius: 0.75rem;
/* Shadows at the edges that only show while there is more to scroll: the
covers move with the content, the shadows stay with the box. */
background:
linear-gradient(to right, var(--tbl-bg) 30%, transparent) left / 2.5rem 100% no-repeat local,
linear-gradient(to left, var(--tbl-bg) 30%, transparent) right / 2.5rem 100% no-repeat local,
radial-gradient(farthest-side at 0 50%, var(--tbl-fade), transparent) left / 0.875rem 100% no-repeat scroll,
radial-gradient(farthest-side at 100% 50%, var(--tbl-fade), transparent) right / 0.875rem 100% no-repeat scroll,
var(--tbl-bg);
}
.ch-table:focus-visible {
outline: 2px solid var(--color-fd-ring);
outline-offset: 2px;
}
.ch-table table {
width: 100%;
margin: 0;
border: 0;
border-radius: 0;
border-collapse: separate;
border-spacing: 0;
background: transparent;
overflow: visible;
font-size: 0.875rem;
line-height: 1.55;
overflow-wrap: break-word;
}
.ch-table th,
.ch-table td {
padding: 0.625rem 0.875rem;
border-inline-start: 0;
text-align: start;
vertical-align: top;
}
.ch-table th {
background: color-mix(in oklab, var(--color-fd-muted) 70%, transparent);
border-bottom: 1px solid var(--color-fd-border);
color: var(--color-fd-muted-foreground);
font-size: 0.8125rem;
font-weight: 600;
white-space: nowrap;
}
.ch-table tbody tr:not(:last-child) td {
border-bottom: 1px solid color-mix(in oklab, var(--color-fd-border) 75%, transparent);
}
/* The first column names the row: a little heavier than the cells beside it. */
.ch-table td:first-child {
color: var(--color-fd-foreground);
font-weight: 500;
}
.ch-table td:not(:first-child) {
color: color-mix(in oklab, var(--color-fd-foreground) 86%, var(--color-fd-muted-foreground));
}
.ch-table [data-fit='key'] {
white-space: nowrap;
}
/* Code in a cell is a chip that wraps at its separators (components/table.tsx
puts break points after . / - _ and the like), never mid-word. */
.ch-table code {
font-size: 0.8125em;
padding: 0.0625rem 0.3rem;
white-space: normal;
overflow-wrap: break-word;
word-break: normal;
box-decoration-break: clone;
-webkit-box-decoration-break: clone;
}
.ch-table [data-fit='key'] code {
white-space: nowrap;
}

::selection {
Expand Down Expand Up @@ -250,3 +332,41 @@ h1 > .ch-badge {
.ch-dg-text[open] summary {
margin-bottom: 0.25rem;
}

/* Definition lists: a list whose items open with a bold term and a line
break (a setting, a check, an error code, then what it means). Written in
plain Markdown, so the self-host guides read the same on GitHub:
- **`retainData`** *boolean, default `true`*\
Keep tables ... when stacks are deleted.
Here they lose the bullets and get a hairline between items, like a
parameter list. The italic part is muted metadata (a type, a default, a
label such as "Fix:"). */
.prose ul:has(> li > strong:first-child ~ br) {
list-style: none;
padding-inline-start: 0;
margin-block: 1.25rem 1.5rem;
border-top: 1px solid var(--color-fd-border);
}
.prose ul:has(> li > strong:first-child ~ br) > li {
margin: 0;
padding: 0.75rem 0 0.8rem;
padding-inline-start: 0;
border-bottom: 1px solid color-mix(in oklab, var(--color-fd-border) 75%, transparent);
font-size: 0.9375rem;
line-height: 1.65;
}
.prose ul:has(> li > strong:first-child ~ br) > li > strong:first-child {
color: var(--color-fd-foreground);
font-weight: 600;
}
.prose ul:has(> li > strong:first-child ~ br) > li > em {
font-style: normal;
font-size: 0.875em;
color: var(--color-fd-muted-foreground);
}
.prose ul:has(> li > strong:first-child ~ br) > li > strong:first-child {
font-size: 1rem;
}
.prose ul:has(> li > strong:first-child ~ br) > li > strong:first-child + em {
margin-inline-start: 0.35rem;
}
2 changes: 2 additions & 0 deletions docs/components/mdx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import type { MDXComponents } from 'mdx/types';
import { Badge } from '@/components/badge';
import { Path, Paths, Tile, Tiles } from '@/components/home';
import { Diagram } from '@/components/diagram';
import { Table } from '@/components/table';

export function getMDXComponents(components?: MDXComponents) {
return {
...defaultMdxComponents,
table: Table,
Tab,
Tabs,
Step,
Expand Down
132 changes: 132 additions & 0 deletions docs/components/table.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import { Children, cloneElement, isValidElement, type ComponentProps, type CSSProperties, type ReactElement, type ReactNode } from 'react';

/*
* Every Markdown table on the site (hand-written MDX and the imported
* self-host guides) renders through this. Styles are in app/global.css
* (.ch-table).
*
* The columns are sized from what is in them, the way a person laying the
* table out would do it:
* - a column whose cells are all short (a key, a type, "Yes") stays on one
* line, so `models.provider` or "Required" never breaks;
* - a column of longer text gets a minimum width, so on a phone it scrolls
* inside its box instead of squeezing into one word a line.
* The box scrolls sideways only when the table is wider than the page, with
* a fade on the side that has more.
*/

type El = ReactElement<{ children?: ReactNode; style?: CSSProperties; 'data-fit'?: string }>;

/** The text of a cell, as a reader sees it. */
export function textOf(node: ReactNode): string {
if (node == null || typeof node === 'boolean') return '';
if (typeof node === 'string' || typeof node === 'number') return String(node);
if (Array.isArray(node)) return node.map(textOf).join('');
if (isValidElement(node)) return textOf((node as El).props.children);
return '';
}

const elements = (children: ReactNode): El[] => Children.toArray(children).filter(isValidElement) as El[];

/** A cell that holds only identifiers: inline code, with commas or spaces between. */
function codeOnly(children: ReactNode): boolean {
const parts = Children.toArray(children);
return parts.length > 0 && parts.every((p) => (typeof p === 'string' ? /^[\s,]*$/.test(p) : isValidElement(p) && p.type === 'code'));
}

type Column = { length: number; code: boolean };

/** Per column: the longest cell (header included), and whether every body cell is code. */
function columns(sections: El[]): Column[] {
const cols: Column[] = [];
for (const section of sections) {
const body = section.type !== 'thead';
for (const row of elements(section.props.children)) {
elements(row.props.children).forEach((cell, i) => {
const col = (cols[i] ??= { length: 0, code: true });
const text = textOf(cell.props.children).trim();
col.length = Math.max(col.length, text.length);
if (body && text && !codeOnly(cell.props.children)) col.code = false;
});
}
}
return cols;
}

/** Short enough to keep on one line: keys, types, defaults, yes and no. */
const NOWRAP_MAX = 22;

/** How a column is laid out, from its longest cell. */
/** Identifiers up to this long stay whole when a column holds nothing else. */
const CODE_NOWRAP_MAX = 36;

export function columnFit({ length, code }: Column, columns: number): { fit: 'key' | 'text'; minWidth?: string } {
if (length <= NOWRAP_MAX || (code && length <= CODE_NOWRAP_MAX)) return { fit: 'key' };
// Two columns share the width well on their own; a minimum would only make
// a phone scroll.
if (columns < 3) return { fit: 'text' };
if (length > 90) return { fit: 'text', minWidth: '15rem' };
if (length > 50) return { fit: 'text', minWidth: '11rem' };
return { fit: 'text', minWidth: '8rem' };
}

export function Table({ children, ...props }: ComponentProps<'table'>) {
const sections = elements(children);
const cols = columns(sections);
const fits = cols.map((col) => columnFit(col, cols.length));
const laidOut = sections.map((section) =>
cloneElement(section, {
children: elements(section.props.children).map((row) =>
cloneElement(row, {
children: elements(row.props.children).map((cell, i) =>
cloneElement(cell, {
// Chrome breaks at <wbr> even under nowrap: key columns get none.
children: fits[i]?.fit === 'key' ? cell.props.children : withBreaks(cell.props.children),
'data-fit': fits[i]?.fit,
style: fits[i]?.minWidth ? { ...cell.props.style, minWidth: fits[i].minWidth } : cell.props.style,
}),
),
}),
),
}),
);
const header = textOf(sections[0]).trim();
return (
// Focusable so a keyboard can scroll a wide table (WCAG 2.1.1).
<div className="ch-table" role="region" tabIndex={0} aria-label={header ? `Table: ${header.slice(0, 80)}` : 'Table'}>
<table {...props}>{laidOut}</table>
</div>
);
}

/**
* Break points in a long identifier: before a dot, after a slash, hyphen,
* underscore and the like, and never in its first two characters. So
* `coderhelm-<stage>-data-<account>` wraps at a hyphen and `doctor.json` at
* its dot, never mid-word.
*/
const BREAKS = /(?<=..)(?=\.[^\s.])|(?<=..[/_\-:,=@])(?=\S)/g;

export function breakable(text: string): ReactNode[] {
if (text.length < 14) return [text];
const parts: ReactNode[] = [];
let last = 0;
for (const m of text.matchAll(BREAKS)) {
const at = m.index ?? 0;
if (at === last || at >= text.length) continue;
parts.push(text.slice(last, at), <wbr key={at} />);
last = at;
}
parts.push(text.slice(last));
return parts;
}

/** A cell's content with break points added to its inline code. */
function withBreaks(node: ReactNode): ReactNode {
return Children.map(node, (child) => {
if (!isValidElement(child)) return child;
const el = child as El;
if (el.type === 'code' && typeof el.props.children === 'string') return cloneElement(el, { children: breakable(el.props.children) });
return el.props.children === undefined ? el : cloneElement(el, { children: withBreaks(el.props.children) });
});
}
11 changes: 6 additions & 5 deletions docs/content/docs/api/errors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ A failed request answers with a `4xx` or `5xx` status and a JSON body:
}
```

| Field | Type | Description |
| --- | --- | --- |
| `error` | string | A sentence to show a person. Its wording can change. |
| `code` | string | What went wrong, for programs. Branch on this, not on `error`. |
| `scope` | string | Only with `missing_scope`: the scope the key would need. |
- **`error`** *string*\
A sentence to show a person. Its wording can change.
- **`code`** *string*\
What went wrong, for programs. Branch on this, not on `error`.
- **`scope`** *string*\
Only with `missing_scope`: the scope the key would need.

## Codes

Expand Down
14 changes: 8 additions & 6 deletions docs/content/docs/concepts/skills.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ description: How to write a database migration in this codebase. Read before cha
- Every migration has a down step...
```

| Field | Type | Default | Notes |
| --- | --- | --- | --- |
| `name` | string | The folder name (skills) or file name (agents, commands) | Lowercased; characters other than `a-z 0-9 - _ .` become `-`; up to 64 characters. |
| `description` | string | The first line of the body that is not a heading | Up to 240 characters. Agents choose skills by their description, so make it say when to use the skill. |
| `tools` or `allowed-tools` | list, or one string split by commas | none | Claude Code tool names, mapped to CoderHelm's own (below). |
| `model` | string | none | Agents only. A hint for which model answers. |
- **`name`** *string, default the folder name (skills) or file name (agents, commands)*\
Lowercased; characters other than `a-z 0-9 - _ .` become `-`; up to 64 characters.
- **`description`** *string, default the first line of the body that is not a heading*\
Up to 240 characters. Agents choose skills by their description, so make it say when to use the skill.
- **`tools`** or **`allowed-tools`** *list, or one string split by commas*\
Claude Code tool names, mapped to CoderHelm's own (below).
- **`model`** *string*\
Agents only. A hint for which model answers.

Claude Code tool names map to these abilities: `Read` to read files, `Edit` and `MultiEdit` to edit files, `Write` to write files, `Grep` to search code, and `Glob` and `LS` to list files. Others (shell, web, notebooks, sub-agents) have no equivalent and are reported as missing.

Expand Down
5 changes: 3 additions & 2 deletions docs/e2e/site.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ test('plugins have shipped: the manifest reference has no Coming soon badge, and
await page.goto('/plugins/manifest-reference/');
await expect(page.getByRole('heading', { level: 1 })).toContainText('Manifest reference');
await expect(page.locator('h1 .ch-badge')).toHaveCount(0);
await expect(page.getByRole('cell', { name: 'results', exact: true }).first()).toBeVisible();
await expect(page.getByRole('cell', { name: 'name', exact: true }).first()).toBeVisible();
// Every field is a definition list item: its name, then its type and what it does.
await expect(page.locator('#nd-page li > strong > code', { hasText: /^results$/ }).first()).toBeVisible();
await expect(page.locator('#nd-page li > strong > code', { hasText: /^name$/ }).first()).toBeVisible();
await expect(page.getByRole('link', { name: /edit on github/i })).toHaveAttribute('href', /CoderHelm\/coderhelm\/blob\/main\/docs\/schemas\/plugin-manifest\.schema\.json/);
// No plugin page is marked unreleased in the sidebar.
await expect(page.locator('aside a[href*="/plugins/"] .ch-badge')).toHaveCount(0);
Expand Down
Loading
Loading