Skip to content

Claude Code guide in three levels, Beginner to Advanced: hands-on lessons with checked exercises, every volatile fact cited to its source. Independent community guide.

ci: validate config and examples, keep examples inert, run their smoke tests (#53)

Wesam Abousaidadf7d99e1da9
diff --git a/.github/scripts/fixtures/agent-missing-name/fixture.json b/.github/scripts/fixtures/agent-missing-name/fixture.json
new file mode 100644
index 0000000..2bf5280
--- /dev/null
+++ b/.github/scripts/fixtures/agent-missing-name/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "static-validation",
+ "expect": "fail",
+ "about": "An example subagent whose frontmatter has a description but no name."
+}
diff --git a/.github/scripts/fixtures/agent-missing-name/tree/examples/intermediate/06-subagents/dot-claude/agents/code-reviewer.md b/.github/scripts/fixtures/agent-missing-name/tree/examples/intermediate/06-subagents/dot-claude/agents/code-reviewer.md
new file mode 100644
index 0000000..b58c30e
--- /dev/null
+++ b/.github/scripts/fixtures/agent-missing-name/tree/examples/intermediate/06-subagents/dot-claude/agents/code-reviewer.md
@@ -0,0 +1,6 @@
+---
+description: Reviews a diff for correctness
+tools: Read, Grep, Glob
+---
+
+Review the diff.
diff --git a/.github/scripts/fixtures/audit-workflow-with-syntax-error/fixture.json b/.github/scripts/fixtures/audit-workflow-with-syntax-error/fixture.json
new file mode 100644
index 0000000..490660d
--- /dev/null
+++ b/.github/scripts/fixtures/audit-workflow-with-syntax-error/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "static-validation",
+ "expect": "fail",
+ "about": "A copy of the repo's stale-docs-audit workflow with an injected syntax error, generated under .claude/workflows/ because a committed copy would be live."
+}
diff --git a/.github/scripts/fixtures/audit-workflow-with-syntax-error/generate.mjs b/.github/scripts/fixtures/audit-workflow-with-syntax-error/generate.mjs
new file mode 100644
index 0000000..1d0a7da
--- /dev/null
+++ b/.github/scripts/fixtures/audit-workflow-with-syntax-error/generate.mjs
@@ -0,0 +1,12 @@
+import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
+import { dirname, join } from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const repo = join(dirname(fileURLToPath(import.meta.url)), '..', '..', '..', '..');
+
+export default function generate(root) {
+ const source = readFileSync(join(repo, '.claude', 'workflows', 'stale-docs-audit.js'), 'utf8');
+ const dir = join(root, '.claude', 'workflows');
+ mkdirSync(dir, { recursive: true });
+ writeFileSync(join(dir, 'stale-docs-audit.js'), `${source}\nconst broken = {;\n`);
+}
diff --git a/.github/scripts/fixtures/audit-workflow-with-syntax-error/tree/README.md b/.github/scripts/fixtures/audit-workflow-with-syntax-error/tree/README.md
new file mode 100644
index 0000000..ca69e6d
--- /dev/null
+++ b/.github/scripts/fixtures/audit-workflow-with-syntax-error/tree/README.md
@@ -0,0 +1 @@
+# Fixture
diff --git a/.github/scripts/fixtures/failing-smoke-test/fixture.json b/.github/scripts/fixtures/failing-smoke-test/fixture.json
new file mode 100644
index 0000000..daac4ba
--- /dev/null
+++ b/.github/scripts/fixtures/failing-smoke-test/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "smoke-tests",
+ "expect": "fail",
+ "about": "An example whose Claude-free smoke test exits non-zero."
+}
diff --git a/.github/scripts/fixtures/failing-smoke-test/tree/examples/intermediate/05-hooks/test.sh b/.github/scripts/fixtures/failing-smoke-test/tree/examples/intermediate/05-hooks/test.sh
new file mode 100644
index 0000000..1916621
--- /dev/null
+++ b/.github/scripts/fixtures/failing-smoke-test/tree/examples/intermediate/05-hooks/test.sh
@@ -0,0 +1,4 @@
+#!/usr/bin/env bash
+# Smoke test: the hook must block .env.
+echo "expected exit 2, got 0" >&2
+exit 1
diff --git a/.github/scripts/fixtures/invalid-json-settings-snippet/fixture.json b/.github/scripts/fixtures/invalid-json-settings-snippet/fixture.json
new file mode 100644
index 0000000..3bce257
--- /dev/null
+++ b/.github/scripts/fixtures/invalid-json-settings-snippet/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "static-validation",
+ "expect": "fail",
+ "about": "An example settings snippet that is not valid JSON."
+}
diff --git a/.github/scripts/fixtures/invalid-json-settings-snippet/tree/examples/intermediate/05-hooks/settings.snippet.json b/.github/scripts/fixtures/invalid-json-settings-snippet/tree/examples/intermediate/05-hooks/settings.snippet.json
new file mode 100644
index 0000000..21785f9
--- /dev/null
+++ b/.github/scripts/fixtures/invalid-json-settings-snippet/tree/examples/intermediate/05-hooks/settings.snippet.json
@@ -0,0 +1,3 @@
+{
+ "permissions": { "deny": ["Read(.env)",] }
+}
diff --git a/.github/scripts/fixtures/invalid-yaml-issue-form/fixture.json b/.github/scripts/fixtures/invalid-yaml-issue-form/fixture.json
new file mode 100644
index 0000000..be08447
--- /dev/null
+++ b/.github/scripts/fixtures/invalid-yaml-issue-form/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "static-validation",
+ "expect": "fail",
+ "about": "An issue form that is not valid YAML."
+}
diff --git a/.github/scripts/fixtures/invalid-yaml-issue-form/tree/.github/ISSUE_TEMPLATE/bug.yml b/.github/scripts/fixtures/invalid-yaml-issue-form/tree/.github/ISSUE_TEMPLATE/bug.yml
new file mode 100644
index 0000000..3a7dca3
--- /dev/null
+++ b/.github/scripts/fixtures/invalid-yaml-issue-form/tree/.github/ISSUE_TEMPLATE/bug.yml
@@ -0,0 +1,6 @@
+name: Bug
+description: Report a broken link
+body:
+ - type: input
+ attributes:
+ label: [Page
diff --git a/.github/scripts/fixtures/live-config-under-examples/fixture.json b/.github/scripts/fixtures/live-config-under-examples/fixture.json
new file mode 100644
index 0000000..d1fe15f
--- /dev/null
+++ b/.github/scripts/fixtures/live-config-under-examples/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "inertness",
+ "expect": "fail",
+ "about": "A real .claude/ folder under examples/, which Claude Code can load. Generated, never committed."
+}
diff --git a/.github/scripts/fixtures/live-config-under-examples/generate.mjs b/.github/scripts/fixtures/live-config-under-examples/generate.mjs
new file mode 100644
index 0000000..fd605e6
--- /dev/null
+++ b/.github/scripts/fixtures/live-config-under-examples/generate.mjs
@@ -0,0 +1,8 @@
+import { mkdirSync, writeFileSync } from 'node:fs';
+import { join } from 'node:path';
+
+export default function generate(root) {
+ const dir = join(root, 'examples', 'intermediate', '01-first-skill', '.claude', 'skills', 'five-whys');
+ mkdirSync(dir, { recursive: true });
+ writeFileSync(join(dir, 'SKILL.md'), '---\ndescription: Ask why five times\n---\n\nAsk why five times.\n');
+}
diff --git a/.github/scripts/fixtures/live-config-under-examples/tree/README.md b/.github/scripts/fixtures/live-config-under-examples/tree/README.md
new file mode 100644
index 0000000..ca69e6d
--- /dev/null
+++ b/.github/scripts/fixtures/live-config-under-examples/tree/README.md
@@ -0,0 +1 @@
+# Fixture
diff --git a/.github/scripts/fixtures/shell-script-syntax-error/fixture.json b/.github/scripts/fixtures/shell-script-syntax-error/fixture.json
new file mode 100644
index 0000000..2e7bb43
--- /dev/null
+++ b/.github/scripts/fixtures/shell-script-syntax-error/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "static-validation",
+ "expect": "fail",
+ "about": "An example hook script that bash -n rejects."
+}
diff --git a/.github/scripts/fixtures/shell-script-syntax-error/tree/examples/intermediate/05-hooks/protect-files.sh b/.github/scripts/fixtures/shell-script-syntax-error/tree/examples/intermediate/05-hooks/protect-files.sh
new file mode 100644
index 0000000..2607538
--- /dev/null
+++ b/.github/scripts/fixtures/shell-script-syntax-error/tree/examples/intermediate/05-hooks/protect-files.sh
@@ -0,0 +1,4 @@
+#!/usr/bin/env bash
+set -euo pipefail
+if [ -n "${1:-}" ]; then
+ echo "blocked"
diff --git a/.github/scripts/fixtures/skill-missing-description/fixture.json b/.github/scripts/fixtures/skill-missing-description/fixture.json
new file mode 100644
index 0000000..10be5dc
--- /dev/null
+++ b/.github/scripts/fixtures/skill-missing-description/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "static-validation",
+ "expect": "fail",
+ "about": "An example skill whose frontmatter has a name but no description."
+}
diff --git a/.github/scripts/fixtures/skill-missing-description/tree/examples/intermediate/01-first-skill/dot-claude/skills/five-whys/SKILL.md b/.github/scripts/fixtures/skill-missing-description/tree/examples/intermediate/01-first-skill/dot-claude/skills/five-whys/SKILL.md
new file mode 100644
index 0000000..63b15e3
--- /dev/null
+++ b/.github/scripts/fixtures/skill-missing-description/tree/examples/intermediate/01-first-skill/dot-claude/skills/five-whys/SKILL.md
@@ -0,0 +1,5 @@
+---
+name: five-whys
+---
+
+Ask why five times.
diff --git a/.github/scripts/fixtures/smoke-tests-skip-untouched-examples/base/README.md b/.github/scripts/fixtures/smoke-tests-skip-untouched-examples/base/README.md
new file mode 100644
index 0000000..4942177
--- /dev/null
+++ b/.github/scripts/fixtures/smoke-tests-skip-untouched-examples/base/README.md
@@ -0,0 +1,3 @@
+# Fixture
+
+Old text.
diff --git a/.github/scripts/fixtures/smoke-tests-skip-untouched-examples/base/examples/intermediate/05-hooks/test.sh b/.github/scripts/fixtures/smoke-tests-skip-untouched-examples/base/examples/intermediate/05-hooks/test.sh
new file mode 100644
index 0000000..8fd0f93
--- /dev/null
+++ b/.github/scripts/fixtures/smoke-tests-skip-untouched-examples/base/examples/intermediate/05-hooks/test.sh
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+# Smoke test that would fail if it ran.
+exit 1
diff --git a/.github/scripts/fixtures/smoke-tests-skip-untouched-examples/fixture.json b/.github/scripts/fixtures/smoke-tests-skip-untouched-examples/fixture.json
new file mode 100644
index 0000000..4d41ff8
--- /dev/null
+++ b/.github/scripts/fixtures/smoke-tests-skip-untouched-examples/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "smoke-tests",
+ "expect": "pass",
+ "about": "On a pull request that does not touch examples/, smoke tests do not run, even if one would fail."
+}
diff --git a/.github/scripts/fixtures/smoke-tests-skip-untouched-examples/tree/README.md b/.github/scripts/fixtures/smoke-tests-skip-untouched-examples/tree/README.md
new file mode 100644
index 0000000..145431a
--- /dev/null
+++ b/.github/scripts/fixtures/smoke-tests-skip-untouched-examples/tree/README.md
@@ -0,0 +1,3 @@
+# Fixture
+
+New text.
diff --git a/.github/scripts/fixtures/smoke-tests-skip-untouched-examples/tree/examples/intermediate/05-hooks/test.sh b/.github/scripts/fixtures/smoke-tests-skip-untouched-examples/tree/examples/intermediate/05-hooks/test.sh
new file mode 100644
index 0000000..8fd0f93
--- /dev/null
+++ b/.github/scripts/fixtures/smoke-tests-skip-untouched-examples/tree/examples/intermediate/05-hooks/test.sh
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+# Smoke test that would fail if it ran.
+exit 1
diff --git a/.github/scripts/fixtures/unparsable-workflow-script/fixture.json b/.github/scripts/fixtures/unparsable-workflow-script/fixture.json
new file mode 100644
index 0000000..d596bab
--- /dev/null
+++ b/.github/scripts/fixtures/unparsable-workflow-script/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "static-validation",
+ "expect": "fail",
+ "about": "An example workflow script with a syntax error in its body."
+}
diff --git a/.github/scripts/fixtures/unparsable-workflow-script/tree/examples/advanced/03-dynamic-workflows/dot-claude/workflows/todo-audit.js b/.github/scripts/fixtures/unparsable-workflow-script/tree/examples/advanced/03-dynamic-workflows/dot-claude/workflows/todo-audit.js
new file mode 100644
index 0000000..255a610
--- /dev/null
+++ b/.github/scripts/fixtures/unparsable-workflow-script/tree/examples/advanced/03-dynamic-workflows/dot-claude/workflows/todo-audit.js
@@ -0,0 +1,4 @@
+export const meta = { name: 'todo-audit', description: 'List TODOs per folder' }
+const folders = args?.folders ?? ['src']
+const reports = await Promise.all(folders.map((f) => agent(`List TODOs in ${f}`))
+return reports.join('\n')
diff --git a/.github/scripts/fixtures/valid-example-kit/fixture.json b/.github/scripts/fixtures/valid-example-kit/fixture.json
new file mode 100644
index 0000000..fc31143
--- /dev/null
+++ b/.github/scripts/fixtures/valid-example-kit/fixture.json
@@ -0,0 +1,5 @@
+{
+ "rule": "static-validation,inertness,smoke-tests",
+ "expect": "pass",
+ "about": "An inert example kit: a skill without a name (it is optional), an agent, a workflow script, a settings snippet, a hook script and a passing smoke test."
+}
diff --git a/.github/scripts/fixtures/valid-example-kit/tree/examples/advanced/03-dynamic-workflows/dot-claude/workflows/todo-audit.js b/.github/scripts/fixtures/valid-example-kit/tree/examples/advanced/03-dynamic-workflows/dot-claude/workflows/todo-audit.js
new file mode 100644
index 0000000..1de7694
--- /dev/null
+++ b/.github/scripts/fixtures/valid-example-kit/tree/examples/advanced/03-dynamic-workflows/dot-claude/workflows/todo-audit.js
@@ -0,0 +1,4 @@
+export const meta = { name: 'todo-audit', description: 'List TODOs per folder' }
+const folders = args?.folders ?? ['src']
+const reports = await Promise.all(folders.map((f) => agent(`List TODOs in ${f}`)))
+return reports.join('\n')
diff --git a/.github/scripts/fixtures/valid-example-kit/tree/examples/intermediate/01-first-skill/dot-claude/skills/five-whys/SKILL.md b/.github/scripts/fixtures/valid-example-kit/tree/examples/intermediate/01-first-skill/dot-claude/skills/five-whys/SKILL.md
new file mode 100644
index 0000000..3667aab
--- /dev/null
+++ b/.github/scripts/fixtures/valid-example-kit/tree/examples/intermediate/01-first-skill/dot-claude/skills/five-whys/SKILL.md
@@ -0,0 +1,5 @@
+---
+description: Find the root cause of a bug by asking why five times
+---
+
+Ask why five times.
diff --git a/.github/scripts/fixtures/valid-example-kit/tree/examples/intermediate/05-hooks/protect-files.sh b/.github/scripts/fixtures/valid-example-kit/tree/examples/intermediate/05-hooks/protect-files.sh
new file mode 100644
index 0000000..11cdb19
--- /dev/null
+++ b/.github/scripts/fixtures/valid-example-kit/tree/examples/intermediate/05-hooks/protect-files.sh
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+# Blocks edits to .env files. Reads the PreToolUse JSON on stdin.
+set -euo pipefail
+path=$(jq -r ".tool_input.file_path // empty")
+case "$path" in
+ */.env|*/.env.*) echo "Blocked: $path" >&2; exit 2 ;;
+esac
+exit 0
diff --git a/.github/scripts/fixtures/valid-example-kit/tree/examples/intermediate/05-hooks/settings.snippet.json b/.github/scripts/fixtures/valid-example-kit/tree/examples/intermediate/05-hooks/settings.snippet.json
new file mode 100644
index 0000000..505c8b0
--- /dev/null
+++ b/.github/scripts/fixtures/valid-example-kit/tree/examples/intermediate/05-hooks/settings.snippet.json
@@ -0,0 +1,3 @@
+{
+ "permissions": { "deny": ["Read(.env)", "Read(.env.*)"] }
+}
diff --git a/.github/scripts/fixtures/valid-example-kit/tree/examples/intermediate/05-hooks/test.sh b/.github/scripts/fixtures/valid-example-kit/tree/examples/intermediate/05-hooks/test.sh
new file mode 100644
index 0000000..2595f6c
--- /dev/null
+++ b/.github/scripts/fixtures/valid-example-kit/tree/examples/intermediate/05-hooks/test.sh
@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+# Smoke test: pipe sample input to the hook and check its exit code.
+set -u
+cd "$(dirname "$0")" || exit 1
+echo "{\"tool_input\":{\"file_path\":\"$PWD/.env\"}}" | bash protect-files.sh 2>/dev/null
+[ $? -eq 2 ] || { echo "expected exit 2" >&2; exit 1; }
+echo ok
diff --git a/.github/scripts/fixtures/valid-example-kit/tree/examples/intermediate/06-subagents/dot-claude/agents/code-reviewer.md b/.github/scripts/fixtures/valid-example-kit/tree/examples/intermediate/06-subagents/dot-claude/agents/code-reviewer.md
new file mode 100644
index 0000000..ed39913
--- /dev/null
+++ b/.github/scripts/fixtures/valid-example-kit/tree/examples/intermediate/06-subagents/dot-claude/agents/code-reviewer.md
@@ -0,0 +1,7 @@
+---
+name: code-reviewer
+description: Reviews a diff for correctness
+tools: Read, Grep, Glob
+---
+
+Review the diff.
diff --git a/.github/scripts/lib/git.mjs b/.github/scripts/lib/git.mjs
index ea227b0..0db1c9f 100644
--- a/.github/scripts/lib/git.mjs
+++ b/.github/scripts/lib/git.mjs
@@ -76,3 +76,11 @@ export function addedLines(root, sha) {
for (const path of [...added.keys()]) if (isExcluded(path)) added.delete(path);
return added;
}
+
+// Files added, changed or deleted relative to the base, untracked included.
+// A rename that git detects lists only its new path.
+export function changedFiles(root, sha) {
+ const tracked = git(root, ['diff', '--name-only', sha, '--']).split('\n');
+ const untracked = git(root, ['ls-files', '--others', '--exclude-standard']).split('\n');
+ return [...tracked, ...untracked].filter((f) => f && !isExcluded(f));
+}
diff --git a/.github/scripts/lib/yaml.mjs b/.github/scripts/lib/yaml.mjs
new file mode 100644
index 0000000..d71746b
--- /dev/null
+++ b/.github/scripts/lib/yaml.mjs
@@ -0,0 +1,31 @@
+// Parses YAML with Ruby's standard library, which GitHub's Ubuntu runners
+// ship, so the checks need no npm packages. Takes { key: text } and returns
+// { key: { value } | { error } }.
+import { spawnSync } from 'node:child_process';
+
+const RUBY = `
+require "yaml"; require "json"; require "date"
+out = {}
+JSON.parse(STDIN.read).each do |key, text|
+ begin
+ out[key] = { "value" => YAML.safe_load(text, permitted_classes: [Date, Time], aliases: true) }
+ rescue Exception => e
+ out[key] = { "error" => e.message.gsub(/\\s+/, " ") }
+ end
+end
+print JSON.generate(out)
+`;
+
+export function parseYaml(docs) {
+ if (Object.keys(docs).length === 0) return {};
+ const result = spawnSync('ruby', ['-e', RUBY], { input: JSON.stringify(docs), encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
+ if (result.error?.code === 'ENOENT') throw new Error('ruby not found: the YAML checks need Ruby 2.6 or later, with its standard library');
+ if (result.status !== 0) throw new Error(`ruby exited ${result.status}: ${result.stderr.trim()}`);
+ return JSON.parse(result.stdout);
+}
+
+// The YAML between the opening and closing --- of a Markdown file, or null.
+export function frontmatter(markdown) {
+ const m = markdown.match(/^---\r?\n([\s\S]*?)\r?\n---\s*(\r?\n|$)/);
+ return m ? m[1] : null;
+}
diff --git a/.github/scripts/rules/index.mjs b/.github/scripts/rules/index.mjs
index 89a4a41..38087ef 100644
--- a/.github/scripts/rules/index.mjs
+++ b/.github/scripts/rules/index.mjs
@@ -8,5 +8,8 @@ import * as expiry from './expiry.mjs';
import * as emDash from './em-dash.mjs';
import * as images from './images.mjs';
import * as lessonLint from './lesson-lint.mjs';
+import * as staticValidation from './static-validation.mjs';
+import * as inertness from './inertness.mjs';
+import * as smokeTests from './smoke-tests.mjs';
-export const rules = [internalLinks, anchorDiff, stubPaths, stamps, editionGate, expiry, emDash, images, lessonLint];
+export const rules = [internalLinks, anchorDiff, stubPaths, stamps, editionGate, expiry, emDash, images, lessonLint, staticValidation, inertness, smokeTests];
diff --git a/.github/scripts/rules/inertness.mjs b/.github/scripts/rules/inertness.mjs
new file mode 100644
index 0000000..7fd6440
--- /dev/null
+++ b/.github/scripts/rules/inertness.mjs
@@ -0,0 +1,28 @@
+// Nothing under examples/ sits at a path Claude Code can load on its own:
+// no .claude/ folder, .mcp.json, CLAUDE.md, CLAUDE.local.md or AGENTS.md.
+// Examples use dot-claude/, dot-mcp.json and CLAUDE.example.md instead. The
+// folder is read from disk, so files git ignores are caught too.
+import { existsSync, readdirSync, statSync } from 'node:fs';
+import { join } from 'node:path';
+
+export const id = 'inertness';
+export const modes = ['pr', 'release'];
+
+const LIVE = new Set(['.claude', '.mcp.json', 'CLAUDE.md', 'CLAUDE.local.md', 'AGENTS.md']);
+const RENAME = { '.claude': 'dot-claude/', '.mcp.json': 'dot-mcp.json', 'CLAUDE.md': 'CLAUDE.example.md', 'CLAUDE.local.md': 'CLAUDE.example.md', 'AGENTS.md': 'AGENTS.example.md' };
+
+function walk(root, rel, out) {
+ for (const entry of readdirSync(join(root, rel))) {
+ const path = `${rel}/${entry}`;
+ if (LIVE.has(entry)) out.push(`${path}: Claude Code can load this; rename it to ${RENAME[entry]}`);
+ else if (statSync(join(root, path)).isDirectory()) walk(root, path, out);
+ }
+ return out;
+}
+
+export function run(ctx) {
+ if (!existsSync(join(ctx.root, 'examples'))) return { status: 'pass', summary: 'no examples/ folder' };
+ const problems = walk(ctx.root, 'examples', []);
+ if (problems.length) return { status: 'fail', problems };
+ return { status: 'pass', summary: 'examples/ is inert' };
+}
diff --git a/.github/scripts/rules/smoke-tests.mjs b/.github/scripts/rules/smoke-tests.mjs
new file mode 100644
index 0000000..e98e113
--- /dev/null
+++ b/.github/scripts/rules/smoke-tests.mjs
@@ -0,0 +1,27 @@
+// Each example's Claude-free smoke test, examples/**/test.sh, passes. On a
+// pull request they run only when the change touches examples/.
+import { spawnSync } from 'node:child_process';
+import { join, posix } from 'node:path';
+import { changedFiles } from '../lib/git.mjs';
+
+export const id = 'smoke-tests';
+export const modes = ['pr', 'release'];
+
+const TIMEOUT_MS = 120_000;
+
+export function run(ctx) {
+ const tests = ctx.files.filter((f) => f.startsWith('examples/') && f.endsWith('/test.sh'));
+ if (ctx.mode === 'pr' && ctx.base.sha && !changedFiles(ctx.root, ctx.base.sha).some((f) => f.startsWith('examples/'))) {
+ return { status: 'pass', summary: 'no change under examples/' };
+ }
+ const problems = [];
+ for (const test of tests) {
+ const result = spawnSync('bash', ['test.sh'], { cwd: join(ctx.root, posix.dirname(test)), encoding: 'utf8', timeout: TIMEOUT_MS });
+ if (result.status !== 0) {
+ const tail = `${result.stdout}${result.stderr}`.trim().split('\n').slice(-5).join(' | ');
+ problems.push(`${test}: ${result.error ? result.error.message : `exited ${result.status}`}${tail ? `: ${tail}` : ''}`);
+ }
+ }
+ if (problems.length) return { status: 'fail', problems };
+ return { status: 'pass', summary: `${tests.length} smoke tests` };
+}
diff --git a/.github/scripts/rules/static-validation.mjs b/.github/scripts/rules/static-validation.mjs
new file mode 100644
index 0000000..e11c3fb
--- /dev/null
+++ b/.github/scripts/rules/static-validation.mjs
@@ -0,0 +1,91 @@
+// Config and example files parse before they merge:
+// - JSON files, and YAML files (workflows, issue forms);
+// - skill frontmatter has a description (name is optional);
+// - agent frontmatter has a name and a description;
+// - workflow scripts compile, once `export const meta =` becomes
+// `const meta =`, as the body of an async function (node --check gives
+// different answers on different Node versions);
+// - shell scripts pass bash -n and shellcheck.
+// This covers the live .claude/ folder and the inert dot-claude/ folders
+// under examples/ alike.
+import { spawnSync } from 'node:child_process';
+import { join } from 'node:path';
+import { readText } from '../lib/tree.mjs';
+import { frontmatter, parseYaml } from '../lib/yaml.mjs';
+
+export const id = 'static-validation';
+export const modes = ['pr', 'release'];
+
+const SKILL = /(^|\/)(\.claude|dot-claude)\/skills\/[^/]+\/SKILL\.md$/;
+const AGENT = /(^|\/)(\.claude|dot-claude)\/agents\/[^/]+\.md$/;
+const WORKFLOW = /(^|\/)(\.claude|dot-claude)\/workflows\/[^/]+\.m?js$/;
+const SHEBANG = /^#!\s*\/(usr\/)?bin\/(env\s+)?(ba)?sh\b/;
+
+const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
+
+function isShell(ctx, path) {
+ if (path.endsWith('.sh')) return true;
+ if (/\.[^/]+$/.test(path.split('/').pop())) return false;
+ if (!path.startsWith('examples/') && !path.startsWith('.claude/')) return false;
+ return SHEBANG.test(readText(ctx.root, path).split('\n', 1)[0]);
+}
+
+function tool(command, args, cwd) {
+ const result = spawnSync(command, args, { cwd, encoding: 'utf8' });
+ if (result.error?.code === 'ENOENT') return { missing: true };
+ return { code: result.status, output: `${result.stdout}${result.stderr}`.trim() };
+}
+
+export function run(ctx) {
+ const problems = [];
+ const yamlDocs = {};
+ const fm = {};
+ let counts = { json: 0, yaml: 0, skills: 0, agents: 0, workflows: 0, shell: 0 };
+
+ for (const path of ctx.files) {
+ if (path.endsWith('.json')) {
+ counts.json += 1;
+ try { JSON.parse(readText(ctx.root, path)); } catch (e) { problems.push(`${path}: not valid JSON: ${e.message}`); }
+ } else if (/\.ya?ml$/.test(path)) {
+ counts.yaml += 1;
+ yamlDocs[path] = readText(ctx.root, path);
+ }
+ if (SKILL.test(path) || AGENT.test(path)) {
+ const kind = SKILL.test(path) ? 'skill' : 'agent';
+ counts[`${kind}s`] += 1;
+ const text = frontmatter(readText(ctx.root, path));
+ if (text === null) problems.push(`${path}: ${kind} file has no frontmatter`);
+ else fm[path] = { kind, text };
+ }
+ if (WORKFLOW.test(path)) {
+ counts.workflows += 1;
+ const body = readText(ctx.root, path).replace(/^(\s*)export\s+const\s+meta\s*=/m, '$1const meta =');
+ try { new AsyncFunction(body); } catch (e) { problems.push(`${path}: workflow script does not parse: ${e.message}`); }
+ }
+ if (isShell(ctx, path)) {
+ counts.shell += 1;
+ const syntax = tool('bash', ['-n', path], ctx.root);
+ if (syntax.code !== 0) { problems.push(`${path}: bash -n: ${syntax.output}`); continue; }
+ const lint = tool(process.env.SHELLCHECK || 'shellcheck', ['--format=gcc', path], ctx.root);
+ if (lint.missing) problems.push(`${path}: shellcheck not found: install shellcheck or set SHELLCHECK to its path`);
+ else if (lint.code !== 0) problems.push(...lint.output.split('\n').map((l) => `shellcheck: ${l}`));
+ }
+ }
+
+ const parsed = parseYaml({ ...yamlDocs, ...Object.fromEntries(Object.entries(fm).map(([p, f]) => [`fm:${p}`, f.text])) });
+ for (const path of Object.keys(yamlDocs)) {
+ if (parsed[path].error) problems.push(`${path}: not valid YAML: ${parsed[path].error}`);
+ }
+ for (const [path, { kind }] of Object.entries(fm)) {
+ const r = parsed[`fm:${path}`];
+ if (r.error) { problems.push(`${path}: frontmatter is not valid YAML: ${r.error}`); continue; }
+ const value = r.value && typeof r.value === 'object' ? r.value : {};
+ const need = kind === 'skill' ? ['description'] : ['name', 'description'];
+ for (const field of need) {
+ if (typeof value[field] !== 'string' || !value[field].trim()) problems.push(`${path}: ${kind} frontmatter needs a "${field}"`);
+ }
+ }
+
+ if (problems.length) return { status: 'fail', problems };
+ return { status: 'pass', summary: Object.entries(counts).map(([k, v]) => `${v} ${k}`).join(', ') };
+}
diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml
index acbc8d8..3a27cef 100644
--- a/.github/workflows/checks.yml
+++ b/.github/workflows/checks.yml
@@ -21,6 +21,8 @@ jobs:
node-version: lts/*
- name: Install lychee
run: .github/scripts/install-lychee.sh
+ - name: Show the other tools the checks use
+ run: ruby --version && shellcheck --version && jq --version
- name: Self-test the checks against their fixtures
run: node --test '.github/scripts/test/**/*.test.mjs'
- name: Run the checks
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index fdd53aa..2b1e16f 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -204,7 +204,22 @@ Before you open a pull request, run the guide's checks on your working tree, fro
node .github/scripts/check.mjs
```
-It needs Node.js LTS and [lychee](https://github.com/lycheeverse/lychee) 0.24 on your `PATH` (or set `LYCHEE` to its path). Each rule prints `PASS`, `FAIL` or `SKIP` with its name, and the command exits non-zero if any rule fails. Pull request CI runs the same command with `--base` set to the target branch; diff-scoped rules compare against `origin/main` locally.
+It needs Node.js LTS, git, Ruby (for YAML), jq (for the examples' smoke tests), [shellcheck](https://github.com/koalaman/shellcheck) and [lychee](https://github.com/lycheeverse/lychee) 0.24 on your `PATH`; set `LYCHEE` or `SHELLCHECK` to point at a binary elsewhere. Each rule prints `PASS`, `FAIL`, `WARN` or `SKIP` with its name, and the command exits non-zero if any rule fails. Pull request CI runs the same command with `--base` set to the target branch; diff-scoped rules compare against `origin/main` locally.
+
+| Rule | Fails when |
+|---|---|
+| `internal-links` | A link or fragment inside the repo does not resolve |
+| `anchor-diff` | An anchor in `anchors.txt`, or on the base branch, is gone |
+| `stub-paths` | A page path in `paths.txt` is gone |
+| `stamps` | A stamped page's Stamp is missing or malformed, or the trust strip disagrees with the CHANGELOG |
+| `edition-gate` | On a release tag only: a stamped page does not match the release |
+| `expiry` | Never on a pull request, where it warns about markers due within 30 days |
+| `em-dash` | An added line has an em dash outside code and double quotes |
+| `images` | An image lacks alt text, a Mermaid block lacks its accessibility lines, or a file under `assets/` breaks the naming, reference or size rules |
+| `lesson-lint` | A lesson or Elective breaks the [lesson anatomy](#lessons) |
+| `static-validation` | JSON, YAML, skill or agent frontmatter, a workflow script or a shell script does not parse or lint |
+| `inertness` | `examples/` holds a path Claude Code can load on its own |
+| `smoke-tests` | An example's `test.sh` fails (only when the change touches `examples/`) |
Each rule has known-bad fixtures under `.github/scripts/fixtures/`, one folder per case: `fixture.json` names the rule and the expected result, `tree/` holds the files, `base/` the state before a change, and `generate.mjs` writes anything that would be live Claude Code config if committed. If you change a rule, run the self-test too: