for another one
+```
+
+A placed skill carries a `` line and is updated on upgrades. Remove
+that line to keep your own edits (only `--force` overwrites it then). `DAFKE_EID_SKILL=0` turns the
+postinstall off. Details (Dutch): [docs/claude-skill.md](docs/claude-skill.md).
+
Five-minute quick start (Next.js + NestJS, Dutch): https://github.com/DafkeDD/ProjectX-eID/blob/main/packages/eid/docs/aan-de-slag.md
Documentation (Dutch): https://github.com/DafkeDD/ProjectX-eID/tree/main/packages/eid/docs
diff --git a/packages/eid/docs/claude-skill.md b/packages/eid/docs/claude-skill.md
new file mode 100644
index 0000000..502e4dc
--- /dev/null
+++ b/packages/eid/docs/claude-skill.md
@@ -0,0 +1,57 @@
+# Claude Code-skill
+
+Het pakket bevat een [Claude Code-skill](https://code.claude.com/docs/en/skills) die uitlegt hoe
+`@dafkedd/eid` werkt: de kaart lezen met `EidProvider`/`useEid`, aanmelden met PIN en het token
+controleren op de server, de bridge en het commando `dafke-eid`, welke websites toegelaten zijn,
+de installer voor eindgebruikers en de beveiligingsregels. Claude gebruikt hem vanzelf zodra je in
+dat project iets met de eID vraagt.
+
+De skill komt in je project terecht als `.claude/skills/dafkedd-eid/SKILL.md`. Commit dat bestand
+mee, dan heeft iedereen in het team hem.
+
+## Hoe komt hij in je project?
+
+**Automatisch bij `npm install @dafkedd/eid`.** De postinstall van het pakket zet de skill in de map
+waar je `npm install` startte. Er verschijnt niets als hij er al stond.
+
+**Of expliciet:**
+
+```bash
+npx dafke-eid skill # in de map van je project
+npx dafke-eid skill --dir ../app # een andere map
+npx dafke-eid skill --force # ook een eigen versie overschrijven
+```
+
+Gebruik het commando als de postinstall niet draait:
+
+| Situatie | Waarom geen postinstall |
+| --- | --- |
+| pnpm 10+, bun | Voeren scripts van pakketten standaard niet uit |
+| `npm install --ignore-scripts`, `ignore-scripts=true` in `.npmrc` | Scripts staan uit |
+| CI (`CI=true`) | Bewust overgeslagen: CI hoort je repo niet te wijzigen. Toch wel: `DAFKE_EID_SKILL=1` |
+| Globale installatie (`npm i -g`) | Er is geen project |
+
+Nooit automatisch: zet de omgevingsvariabele `DAFKE_EID_SKILL=0`.
+
+## Waarom zowel postinstall als een commando?
+
+Een postinstall is het enige dat echt "vanzelf" gaat, maar hij is niet betrouwbaar: steeds meer
+pakketbeheerders en bedrijven zetten scripts van afhankelijkheden uit, omdat ze een bekend
+aanvalspad zijn. Daarom doet de postinstall alleen het veilige minimum (één bestand in `.claude/`
+schrijven, nooit falen, niets downloaden) en is `npx dafke-eid skill` de weg die altijd werkt.
+
+## Bijwerken en eigen aanpassingen
+
+Na de frontmatter staat een regel ``.
+
+- **Met** die regel: het bestand hoort bij het pakket. Een nieuwe versie van `@dafkedd/eid` werkt
+ het bij (postinstall of `npx dafke-eid skill`).
+- **Zonder** die regel: het is jouw versie en wordt nooit overschreven, behalve met `--force`.
+
+Wil je iets toevoegen voor je eigen project, zet het dan liever in een aparte skill of in
+`CLAUDE.md`, zodat de pakketversie gewoon kan bijwerken.
+
+## Waar de skill vandaan komt
+
+De bron staat in [`packages/eid/skill/SKILL.md`](../skill/SKILL.md) en wordt mee gepubliceerd naar
+npmjs.com en GitHub Packages. Pas je de werking van het pakket aan, werk dan ook dat bestand bij.
diff --git a/packages/eid/package.json b/packages/eid/package.json
index 24ce098..c86f10f 100755
--- a/packages/eid/package.json
+++ b/packages/eid/package.json
@@ -94,7 +94,9 @@
}
},
"files": [
- "dist"
+ "dist",
+ "skill",
+ "scripts/postinstall.mjs"
],
"engines": {
"node": ">=20"
@@ -110,7 +112,8 @@
"test": "vitest run",
"test:integration": "vitest run --config vitest.integration.mts",
"fetch-roots": "node scripts/fetch-belgium-roots.mjs",
- "test-pki": "bash scripts/make-test-pki.sh"
+ "test-pki": "bash scripts/make-test-pki.sh",
+ "postinstall": "node scripts/postinstall.mjs"
},
"peerDependencies": {
"@nestjs/common": ">=10",
diff --git a/packages/eid/scripts/postinstall.mjs b/packages/eid/scripts/postinstall.mjs
new file mode 100644
index 0000000..9abdff9
--- /dev/null
+++ b/packages/eid/scripts/postinstall.mjs
@@ -0,0 +1,27 @@
+// Postinstall van @dafkedd/eid: zet de Claude Code-skill in het project dat het pakket installeert
+// (.claude/skills/dafkedd-eid/SKILL.md). Best effort: faalt nooit en zwijgt als er niets te doen is.
+//
+// Niet uitgevoerd? (pnpm 10, bun, --ignore-scripts, CI) → `npx dafke-eid skill`.
+// Uitzetten: DAFKE_EID_SKILL=0. In CI alleen met DAFKE_EID_SKILL=1.
+import { existsSync } from "node:fs";
+import { dirname, resolve } from "node:path";
+import { fileURLToPath, pathToFileURL } from "node:url";
+
+try {
+ const packageDir = resolve(dirname(fileURLToPath(import.meta.url)), "..");
+ const skillModule = resolve(packageDir, "dist", "skill.js");
+ // In de eigen monorepo bestaat dist/ pas na het bouwen; dan is er ook geen project om te bedienen.
+ if (existsSync(skillModule)) {
+ const skill = await import(pathToFileURL(skillModule).href);
+ const env = process.env;
+ const projectDir = skill.postinstallSkipReason(env) ? undefined : skill.projectDirForPostinstall(packageDir, env);
+ if (projectDir) {
+ const result = skill.installSkill({ projectDir });
+ if (result.action === "created" || result.action === "updated") {
+ process.stdout.write(`@dafkedd/eid: ${skill.describeSkillResult(result)}`);
+ }
+ }
+ }
+} catch (error) {
+ process.stderr.write(`@dafkedd/eid: Claude-skill niet geplaatst (${error instanceof Error ? error.message : String(error)}). Doe het zelf met "npx dafke-eid skill".\n`);
+}
diff --git a/packages/eid/skill/SKILL.md b/packages/eid/skill/SKILL.md
new file mode 100644
index 0000000..bb6a0be
--- /dev/null
+++ b/packages/eid/skill/SKILL.md
@@ -0,0 +1,163 @@
+---
+name: dafkedd-eid
+description: How to use @dafkedd/eid in this project to read Belgian eID cards and log in with the eID PIN. Use when adding or changing eID reading (EidProvider, useEid), PIN login (useEidLogin plus EidAuthenticator or EidAuthModule on the server), the dafke-eid bridge/CLI, which websites the bridge allows, the end-user installer, or when debugging "no-bridge", origin or OCSP errors.
+---
+
+# @dafkedd/eid in this project
+
+`@dafkedd/eid` reads Belgian eID cards in hosted Next.js/React apps and verifies eID logins on the
+server. Source, docs (Dutch) and the Windows setup: https://github.com/DafkeDD/ProjectX-eID
+(package in `packages/eid`, docs in `packages/eid/docs`). The typed API in
+`node_modules/@dafkedd/eid/dist/*.d.ts` is the source of truth; check it before inventing options.
+
+Answer the user in their own language (the maintainer writes Dutch).
+
+## How it fits together
+
+A browser cannot talk to a card reader. Every end user therefore runs a small local program,
+**DafkeDD eID** (`dafke-eid`, the "bridge"), on `http://127.0.0.1:47820`. It serves the card only to
+websites on its allowlist. The web app talks to that bridge from the browser.
+
+```
+card reader ──PC/SC── dafke-eid (127.0.0.1:47820) ──HTTP/SSE── browser (EidProvider/useEid)
+ └─ PIN login token ──> your server (EidAuthenticator)
+```
+
+| Import | Runs in | Use for |
+| --- | --- | --- |
+| `@dafkedd/eid` | anywhere | types (`EidCardData`, `EidIdentity`, `EidAddress`), `EidError`, constants |
+| `@dafkedd/eid/react` | browser | `EidProvider`, `useEid`, `useEidLogin`, `EidReader`, `EidClient`, formatters |
+| `@dafkedd/eid/mock` | anywhere | `MockEidClient`, `VirtualCard`, test PKI (`TEST_ROOT_CA`, `TEST_CITIZEN_CA`) |
+| `@dafkedd/eid/server` | Node | `EidAuthenticator`, `verifyEidToken`, `EidVerifyError`, `NonceStore` |
+| `@dafkedd/eid/nestjs` | Node | `EidAuthModule.forRoot/forRootAsync`, `EidAuthService` |
+| `@dafkedd/eid/node` | Node | PC/SC reader, `startBridge`; the `dafke-eid` command |
+
+Never import `/node`, `/server` or `/nestjs` into client components. `/react` already carries
+`"use client"`.
+
+## Reading the card (React / Next.js)
+
+```tsx
+"use client";
+import { EidProvider, useEid, fullName, formatNationalNumber } from "@dafkedd/eid/react";
+
+function Card() {
+ const eid = useEid();
+ if (eid.phase === "no-bridge") return Start or install the eID program (DafkeDD eID).
;
+ if (eid.phase === "bridge-outdated") return Update the eID program.
;
+ if (eid.phase === "no-reader") return Connect a card reader.
;
+ if (eid.phase === "no-card") return Insert your eID.
;
+ if (eid.phase === "error") return Error: {eid.error?.code}
;
+ if (eid.phase !== "done" || !eid.card) return Reading…
;
+ const { identity, address } = eid.card;
+ return {fullName(identity)} ({formatNationalNumber(identity.nationalNumber)}), {address.municipality}
;
+}
+
+export default function EidSection() {
+ return ;
+}
+```
+
+- `phase`: `connecting` → `no-bridge` | `bridge-outdated` | `no-reader` | `no-card` → `reading` →
+ `done` | `error` (or `ready` when `autoRead={false}`). The card is read once per insertion and
+ cleared when it is removed.
+- `` props: `url` (default `http://127.0.0.1:47820`), `token`, `autoRead` (default
+ `true`), `photo` (default `true`), `reader`, or a custom `client`. Options are read once.
+- Formatters: `fullName`, `formatNationalNumber`, `formatDate`, `formatAddress`, `photoDataUrl`,
+ `ageOn`.
+- `no-bridge` also appears when the bridge runs but **this website is not allowed** (no CORS on
+ purpose). Check the allowlist first; run the bridge with `--debug` to see refused requests.
+- Without a bridge (demos, tests, Storybook): `` from
+ `@dafkedd/eid/mock`; `insertCard()`, `removeCard()`, `setBridgeAvailable(false)` drive every phase.
+
+The card holds personal data (national number, address, photo). Do not log it, do not store it
+unless the feature needs it, and mask it in UIs and logs where possible.
+
+## Logging in with the PIN
+
+1. Server creates a nonce: `const { nonce } = await authenticator.createChallenge()`. Bind it to the
+ browser with an httpOnly, SameSite=strict cookie (5 min).
+2. Browser: `const token = await useEidLogin().login({ nonce, pin })`, then clear the PIN state and
+ POST the token to the server. Errors: `pin-incorrect` (`triesLeft`), `pin-blocked`,
+ `auth-not-allowed` (site not in the bridge's `authOrigins`), `unsupported-card`, `bad-request`.
+ Each call is one PIN attempt; the card blocks after 3.
+3. Server: `const who = await authenticator.verify(token, nonceFromCookie)` returns
+ `{ nationalNumber, firstNames, lastName, ... }` or throws `EidVerifyError` with `code`
+ (`nonce-invalid`, `signature-invalid`, `chain-untrusted`, `certificate-revoked`,
+ `revocation-unavailable`, ...). Answer 401 with only the code.
+
+```ts
+// lib/eid.ts (Next.js): one shared instance, nonces live in memory
+import { EidAuthenticator } from "@dafkedd/eid/server";
+const g = globalThis as typeof globalThis & { __dafkeEid?: EidAuthenticator };
+export const eid = (g.__dafkeEid ??= new EidAuthenticator({ origin: process.env.APP_ORIGIN ?? "http://localhost:3000" }));
+```
+
+NestJS: `imports: [EidAuthModule.forRoot({ origin: process.env.APP_ORIGIN! })]` and inject
+`EidAuthService` (same `createChallenge`/`verify`). If the API runs on another origin, enable CORS
+with `credentials: true` and use `fetch(..., { credentials: "include" })`.
+
+Rules that matter:
+- `origin` is the **website's** origin exactly as in the address bar (not the API's). The bridge
+ signs the browser's Origin header, so a wrong `origin` gives `signature-invalid`.
+- Several server instances: pass a shared `nonceStore` (e.g. Redis) instead of the in-memory one.
+- OCSP is fail-closed: the server must reach `http://ocsp.eidpki.belgium.be` and
+ `http://ocsp.eid.belgium.be`, otherwise every login fails with `revocation-unavailable`.
+- Virtual card logins are signed by a test PKI. Trust it **only** in dev/test, behind a flag:
+ `new EidAuthenticator({ origin, trust: { roots: [TEST_ROOT_CA], intermediates: [TEST_CITIZEN_CA] }, revocation: false })`.
+ Never ship `TEST_ROOT_CA` or `revocation: false` to production.
+- Never log, persist or prefill the PIN; use `type="password" inputMode="numeric" autoComplete="off"`.
+
+## The bridge during development (CLI)
+
+```bash
+npx dafke-eid --mock --auth-origin http://localhost:3000 # virtual card, PIN 1234
+npx dafke-eid --auth-origin http://localhost:3000 # real reader
+npx dafke-eid readers # list readers
+npx dafke-eid read [--full|--json] [--mock] # read the card (masked by default)
+npx dafke-eid diag # PC/SC state, no personal data
+npx dafke-eid test # open the bridge's test page
+```
+
+`http://localhost:*` and `http://127.0.0.1:*` may read by default. PIN login must be allowed per
+site with `--auth-origin`. If the installed program already holds port 47820, start with
+`--port 47821` and pass ``. `koffi` (native PC/SC binding)
+is only loaded by the CLI/`/node`, never in the browser bundle.
+
+## Which websites the bridge allows
+
+Settings are layered: command line → environment (`DAFKE_EID_ORIGINS`, `DAFKE_EID_AUTH_ORIGINS`,
+`DAFKE_EID_PORT`, `DAFKE_EID_TOKEN`, `DAFKE_EID_TESTPAGE`) → `config.json` in the install folder →
+values baked into the program → defaults.
+
+- `origins`: may read the card. `authOrigins`: may ask for the PIN; a site only in `authOrigins`
+ cannot read card data. Patterns like `https://*.example.be` work; `*` alone is refused.
+- Production: add the real https origin(s). For the ProjectX setup they are baked in from
+ `installer/eid-installer.json` in the ProjectX-eID repo (`npm run build:installer`, or via the
+ release pipeline). A different website must either be added there and get a new setup, or be set
+ per PC via `config.json` / `DAFKE_EID_ORIGINS`.
+- Never bake a `token` into a downloadable program or setup: it is not secret there. If a token is
+ needed, hand it out per PC (silent install `/TOKEN=...`) and pass it to ``.
+
+## End users
+
+End users install DafkeDD eID once (no admin rights): the Windows setup
+`projectx-eid-setup-.exe` is attached to every release at
+https://github.com/DafkeDD/ProjectX-eID/releases/latest. It starts with Windows and has a test page at
+http://127.0.0.1:47820/. IT can deploy it silently with `/VERYSILENT /SUPPRESSMSGBOXES`.
+When `phase` is `no-bridge` or `bridge-outdated`, show a clear "install the eID program" button that
+points to that setup (ProjectX uses `NEXT_PUBLIC_EID_SETUP_URL`).
+
+## Security checklist for changes
+
+- Bridge listens on 127.0.0.1 only and checks Host, Origin and `Sec-Fetch-Site`; keep the allowlist
+ as short as possible.
+- Personal data: no logging, no caching to disk, mask by default.
+- Login: nonce single-use and bound to the browser (cookie), origin exact, OCSP on, test PKI off.
+- Do not weaken these checks to "make it work"; find the misconfigured origin instead.
+
+## Keeping this skill current
+
+This file was placed by `npx dafke-eid skill` (or the package's postinstall). Run that command again
+after upgrading `@dafkedd/eid`. Remove the `` line to keep your own edits;
+the command then leaves the file alone unless you pass `--force`.
diff --git a/packages/eid/src/node/cli.ts b/packages/eid/src/node/cli.ts
index 872ea33..ba5ca55 100755
--- a/packages/eid/src/node/cli.ts
+++ b/packages/eid/src/node/cli.ts
@@ -17,7 +17,8 @@ import { configFromEnv, readConfigFile, resolveConfig, type BridgeConfig } from
import { install, uninstall, openInBrowser, defaultInstallDeps, type InstallResult, type UninstallResult } from "./install";
import { Logbook } from "./logbook";
import { appDir, embeddedConfig, isSea, runningInstalled } from "./runtime";
-import { join } from "node:path";
+import { join, resolve } from "node:path";
+import { describeSkillResult, installSkill } from "./skill";
export const HELP = `dafke-eid ${VERSION}
@@ -34,6 +35,7 @@ Commando's:
diag Toon de ruwe PC/SC-toestand (zonder persoonsgegevens)
install Installeer voor deze gebruiker, met autostart en snelkoppeling
uninstall Verwijder de installatie
+ skill Zet de Claude Code-skill in dit project (.claude/skills/dafkedd-eid)
Opties voor serve:
--port Poort op 127.0.0.1 (standaard ${DEFAULT_BRIDGE_PORT}, of DAFKE_EID_PORT)
@@ -53,6 +55,10 @@ Opties voor install / uninstall:
--from-setup (install, Windows) aangeroepen door de setup: geen eigen Apps-vermelding
--keep-files (uninstall) bestanden laten staan; alleen autostart en snelkoppeling weg
+Opties voor skill:
+ --dir Projectmap (standaard de huidige map)
+ --force Ook een eigen versie (zonder markering) overschrijven
+
Opties voor read:
--reader Gebruik deze kaartlezer (standaard: de eerste met een kaart)
--full Toon alle gegevens, niet gemaskeerd
@@ -103,6 +109,10 @@ export interface CliDeps {
createReader(options: { mock: boolean; debug?: boolean; onError?: (error: unknown) => void }): Promise;
createBackend?(options: { mock: boolean }): Promise;
system?: Partial;
+ /** Huidige map (tests). */
+ cwd?(): string;
+ /** Bron van de skill (tests: de map skill/ in de broncode). */
+ skillTemplate?: string;
}
export const MOCK_READER_NAME = "DafkeDD Virtuele Lezer";
@@ -145,12 +155,14 @@ interface ParsedArgs {
silent: boolean;
fromSetup: boolean;
keepFiles: boolean;
+ dir: string | undefined;
+ force: boolean;
version: boolean;
help: boolean;
}
function parseArgs(argv: readonly string[]): ParsedArgs | string {
- const args: ParsedArgs = { command: undefined, reader: undefined, full: false, json: false, photo: true, mock: false, debug: false, port: undefined, origins: [], authOrigins: [], token: undefined, testpage: undefined, logFile: undefined, configFile: undefined, silent: false, fromSetup: false, keepFiles: false, version: false, help: false };
+ const args: ParsedArgs = { command: undefined, reader: undefined, full: false, json: false, photo: true, mock: false, debug: false, port: undefined, origins: [], authOrigins: [], token: undefined, testpage: undefined, logFile: undefined, configFile: undefined, silent: false, fromSetup: false, keepFiles: false, dir: undefined, force: false, version: false, help: false };
for (let i = 0; i < argv.length; i++) {
const arg = argv[i]!;
switch (arg) {
@@ -189,11 +201,16 @@ function parseArgs(argv: readonly string[]): ParsedArgs | string {
case "--keep-files":
args.keepFiles = true;
break;
+ case "--force":
+ args.force = true;
+ break;
case "--log-file":
- case "--config": {
+ case "--config":
+ case "--dir": {
const value = argv[++i];
if (value === undefined || value.startsWith("--")) return `${arg} verwacht een pad`;
if (arg === "--log-file") args.logFile = value;
+ else if (arg === "--dir") args.dir = value;
else args.configFile = value;
break;
}
@@ -418,6 +435,16 @@ async function testCommand(args: ParsedArgs, deps: CliDeps, env: Record/.claude/skills/dafkedd-eid/SKILL.md` kopiëren, zodat Claude in dat project weet hoe
+ * @dafkedd/eid werkt.
+ *
+ * Twee wegen, dezelfde code:
+ * - `npx dafke-eid skill` (expliciet, werkt altijd, ook met pnpm/bun/--ignore-scripts);
+ * - de postinstall van het pakket (scripts/postinstall.mjs), best effort.
+ *
+ * Een geplaatste skill draagt een markering met de versie. Alleen een bestand MET markering wordt
+ * bijgewerkt; haal je de markering weg, dan is het bestand van jou en blijft het staan.
+ */
+import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
+import { dirname, join, resolve, sep } from "node:path";
+import { fileURLToPath } from "node:url";
+import { VERSION } from "../version";
+
+export const SKILL_NAME = "dafkedd-eid";
+export const SKILL_MARKER = "`;
+ const match = /^---\r?\n[\s\S]*?\r?\n---\r?\n/.exec(template);
+ if (!match) return `${marker}\n\n${template}`;
+ return `${match[0]}${marker}\n${template.slice(match[0].length)}`;
+}
+
+export function skillPath(projectDir: string): string {
+ return join(projectDir, ".claude", "skills", SKILL_NAME, "SKILL.md");
+}
+
+export function installSkill(options: InstallSkillOptions): SkillResult {
+ const version = options.version ?? VERSION;
+ const template = options.template ?? defaultTemplatePath();
+ if (!existsSync(template)) throw new Error(`De skill zit niet bij deze versie van het programma (${template} ontbreekt). Gebruik "npx dafke-eid skill" vanuit een project met @dafkedd/eid.`);
+ const content = renderSkill(readFileSync(template, "utf8"), version);
+ const path = skillPath(options.projectDir);
+
+ if (existsSync(path)) {
+ const current = readFileSync(path, "utf8");
+ const previousVersion = MARKER_RE.exec(current)?.[1];
+ if (previousVersion === undefined && !options.force) return { action: "kept-own", path };
+ if (current === content) return { action: "unchanged", path, ...(previousVersion ? { previousVersion } : {}) };
+ writeFileSync(path, content);
+ return { action: "updated", path, ...(previousVersion ? { previousVersion } : {}) };
+ }
+
+ mkdirSync(dirname(path), { recursive: true });
+ writeFileSync(path, content);
+ return { action: "created", path };
+}
+
+/**
+ * Projectmap voor de postinstall: INIT_CWD (npm, yarn en pnpm zetten die op de map waar
+ * `install` gestart werd), anders alles vóór de eerste node_modules in het pad van het pakket.
+ * Geeft undefined als het pakket niet in een node_modules zit (bv. in zijn eigen monorepo).
+ */
+export function projectDirForPostinstall(packageDir: string, env: Record): string | undefined {
+ const marker = `${sep}node_modules${sep}`;
+ const index = packageDir.indexOf(marker);
+ if (index < 0) return undefined;
+ const fromPath = packageDir.slice(0, index);
+ const initCwd = env.INIT_CWD;
+ const dir = initCwd && existsSync(join(initCwd, "package.json")) ? initCwd : fromPath;
+ return existsSync(join(dir, "package.json")) ? dir : undefined;
+}
+
+/** Redenen om bij postinstall niets te doen (dan geen enkele uitvoer). */
+export function postinstallSkipReason(env: Record): string | undefined {
+ const flag = (env.DAFKE_EID_SKILL ?? "").toLowerCase();
+ if (flag === "0" || flag === "false" || flag === "off") return "DAFKE_EID_SKILL=0";
+ if (env.npm_config_global === "true") return "globale installatie";
+ if (env.CI && env.CI !== "0" && env.CI.toLowerCase() !== "false" && flag !== "1") return "CI";
+ return undefined;
+}
+
+export function describeSkillResult(result: SkillResult, version: string = VERSION): string {
+ switch (result.action) {
+ case "created":
+ return `Claude-skill geplaatst: ${result.path}\n`;
+ case "updated":
+ return `Claude-skill bijgewerkt${result.previousVersion ? ` van ${result.previousVersion}` : ""} naar ${version}: ${result.path}\n`;
+ case "unchanged":
+ return `Claude-skill is al up-to-date (${version}): ${result.path}\n`;
+ case "kept-own":
+ return `Claude-skill niet aangeraakt: ${result.path} is een eigen versie (geen markering). Overschrijven met --force.\n`;
+ }
+}
diff --git a/packages/eid/tests/node/skill.test.ts b/packages/eid/tests/node/skill.test.ts
new file mode 100644
index 0000000..dcf4bc9
--- /dev/null
+++ b/packages/eid/tests/node/skill.test.ts
@@ -0,0 +1,117 @@
+import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join, resolve } from "node:path";
+import { afterEach, beforeEach, describe, expect, it } from "vitest";
+import { runCli } from "../../src/node/cli";
+import { installSkill, postinstallSkipReason, projectDirForPostinstall, renderSkill, skillPath } from "../../src/node/skill";
+
+const TEMPLATE = resolve("skill/SKILL.md");
+const { version } = JSON.parse(readFileSync("package.json", "utf8")) as { version: string };
+
+let dir: string;
+beforeEach(() => {
+ dir = mkdtempSync(join(tmpdir(), "eid-skill-"));
+ writeFileSync(join(dir, "package.json"), "{}");
+});
+afterEach(() => rmSync(dir, { recursive: true, force: true }));
+
+describe("skill/SKILL.md", () => {
+ it("heeft frontmatter met name en description", () => {
+ const text = readFileSync(TEMPLATE, "utf8");
+ expect(text).toMatch(/^---\nname: dafkedd-eid\ndescription: .{40,1024}\n---\n/);
+ });
+
+ it("noemt alleen subpaden die in exports staan", () => {
+ const pkg = JSON.parse(readFileSync("package.json", "utf8")) as { exports: Record };
+ const used = new Set(readFileSync(TEMPLATE, "utf8").match(/@dafkedd\/eid\/[a-z]+(?![a-z/.])/g));
+ for (const sub of used) expect(Object.keys(pkg.exports), sub).toContain(`./${sub.slice("@dafkedd/eid/".length)}`);
+ });
+
+ it("wordt meegepubliceerd", () => {
+ const pkg = JSON.parse(readFileSync("package.json", "utf8")) as { files: string[]; scripts: Record };
+ expect(pkg.files).toEqual(expect.arrayContaining(["dist", "skill", "scripts/postinstall.mjs"]));
+ expect(pkg.scripts.postinstall).toBe("node scripts/postinstall.mjs");
+ });
+});
+
+describe("renderSkill", () => {
+ it("zet de markering na de frontmatter", () => {
+ const out = renderSkill("---\nname: x\n---\n# Titel\n", "1.2.3");
+ expect(out.startsWith("---\nname: x\n---\n