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
202 changes: 118 additions & 84 deletions .claude/skills/capability-matrix/SKILL.md

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions .githooks/format-staged.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Formats staged files with oxfmt and stages the result. Run by pre-commit,
// which picks the runtime (Node or bun) and passes the oxfmt launcher path.
//
// Paths come from git NUL-delimited and are passed on as argument arrays,
// never through a shell, so names with spaces, glob characters or non-ASCII
// characters reach oxfmt and git exactly as staged.
import { spawnSync } from "node:child_process";

const oxfmt = process.argv[2];

function git(...args) {
const result = spawnSync("git", ["--literal-pathspecs", ...args], {
encoding: "utf8",
});
if (result.status !== 0) {
process.stderr.write(result.stderr);
process.exit(result.status ?? 1);
}
return result.stdout;
}

function paths(output) {
return output.split("\0").filter(Boolean);
}

// `./` keeps oxfmt from reading a name that starts with `-` as an option, or
// one that starts with `!` as an exclude pattern.
function runOxfmt(args, files, stdout) {
const result = spawnSync(
process.execPath,
[
oxfmt,
"--no-error-on-unmatched-pattern",
...args,
...files.map((file) => `./${file}`),
],
{ stdio: ["ignore", stdout, "inherit"] },
);
return result.status ?? 1;
}
Comment thread
cmelchior marked this conversation as resolved.
Resolved

const staged = paths(
git("diff", "--cached", "--name-only", "-z", "--diff-filter=ACMR"),
);

// A file with unstaged changes is only checked: formatting it and adding it
// again would also stage the changes that were deliberately left out.
const partial = new Set(paths(git("diff", "--name-only", "-z")));
const toFormat = staged.filter((file) => !partial.has(file));
const toCheck = staged.filter((file) => partial.has(file));

// Never call oxfmt without files: with no paths it formats the whole directory.
if (toFormat.length > 0) {
if (runOxfmt([], toFormat, "ignore") !== 0) {
process.exit(1);
}
git("add", "--", ...toFormat);
}

if (toCheck.length > 0 && runOxfmt(["--check"], toCheck, "inherit") !== 0) {
console.error(
"pre-commit: the files above are partly staged and not formatted.",
);
console.error(
"Run `bun run format` at the repo root, stage the result, and commit again.",
);
process.exit(1);
}
41 changes: 41 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/sh
# Formats staged files with oxfmt, using the repo-wide .oxfmtrc.json.
# Turned on by `bun install` or `npm install` at the repo root (the `prepare`
# script sets core.hooksPath), or by hand with `git config core.hooksPath .githooks`.
# Skip it once with `git commit --no-verify`.
set -eu

root=$(git rev-parse --show-toplevel)
oxfmt="$root/node_modules/.bin/oxfmt"
cd "$root"

# Nothing to format when the commit only deletes files.
if git diff --cached --quiet --diff-filter=ACMR; then
exit 0
fi

# Formatting is a convenience here: the Format workflow enforces it on every
# PR. So a missing install never blocks a commit, which matters for worktrees:
# core.hooksPath is shared by all of them, but each needs its own install.
skip() {
echo "pre-commit: $1" >&2
echo "pre-commit: committing without formatting; the Format check on the PR will catch it." >&2
exit 0
}

if [ ! -e "$oxfmt" ]; then
skip "oxfmt is not installed. Run \`bun install\` (or \`npm install\`) at the repo root."
fi

# The oxfmt launcher is a Node script; bun can run it too.
if command -v node >/dev/null 2>&1; then
runtime=node
elif command -v bun >/dev/null 2>&1; then
runtime=bun
else
skip "neither Node nor bun is on PATH, so oxfmt cannot run."
fi

# The file handling lives in JavaScript, which gets paths from git exactly
# and never passes them through a shell.
exec "$runtime" "$root/.githooks/format-staged.mjs" "$oxfmt"
19 changes: 19 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Format

on:
push:
branches: [main]
pull_request:

jobs:
check:
name: oxfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version: latest
- run: bun install --frozen-lockfile
- run: bun run format:check
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@

# Python bytecode caches
__pycache__/

# Root formatting toolchain (each package ignores its own node_modules)
node_modules/

# IntelliJ IDE's
.idea/

# npm install also works at the root; bun.lock is the lockfile we commit
package-lock.json
11 changes: 10 additions & 1 deletion packages/capability-matrix/.oxfmtrc.json → .oxfmtrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,14 @@
"arrowParens": "always",
"bracketSameLine": false,
"bracketSpacing": true,
"ignorePatterns": ["**/*.md", "**/*.yml", "**/*.yaml", "**/*.toml"]
"ignorePatterns": ["**/CHANGELOG.md", "**/*.yml", "**/*.yaml", "**/*.toml"],
"overrides": [
{
"files": ["**/*.md"],
"options": {
"embeddedLanguageFormatting": "off",
"proseWrap": "always"
}
}
]
}
Loading
Loading