From a4237c04623fe36703995ed56b3684959a64a6a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=A9=98?= Date: Fri, 8 May 2026 01:29:10 +0000 Subject: [PATCH] docs: add folder module discipline rules to CLAUDE.md Four rules: index.ts entry point, types.ts for types, single export source, index.ts is pure re-exports. Also fix stale build command reference. Refs #102 --- CLAUDE.md | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 89055e3..3ab7f87 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -97,6 +97,36 @@ type WorkflowEntry = { Workflow bundles (`.esm.js`) follow the same rule: export `const run` and `const descriptor`, not `export default`. +### Folder Module Discipline + +Every folder under `src/` is a **module boundary**. Four rules: + +| # | Rule | Rationale | +|---|------|-----------| +| 1 | **Every folder exports via `index.ts`** | Single entry point for the module | +| 2 | **Types live in `types.ts`** | Each folder's type definitions go in `/types.ts`, not scattered across files | +| 3 | **Single export source** | Only `index.ts` may re-export. No file may re-export from another module's internals. Cross-module imports must go through `index.ts` — never reach past it to import a specific file | +| 4 | **`index.ts` is pure re-exports** | No type definitions, no function implementations — only `export { ... } from` statements | + +```typescript +// ✅ Good — import through module boundary +import { createCasStore } from "../cas/index.js"; +import type { CasStore } from "../cas/index.js"; + +// ❌ Bad — reaching past index.ts +import { createCasStore } from "../cas/cas.js"; + +// ❌ Bad — re-exporting from non-index file +// in engine/engine.ts: +export { createCasStore } from "../cas/cas.js"; + +// ❌ Bad — types defined in index.ts +// in cas/index.ts: +export type CasStore = { ... }; // should be in cas/types.ts +``` + +**Exception**: The package-level `src/index.ts` is the public API surface and re-exports from folder `index.ts` files. Files that remain at `src/` root (e.g. `types.ts`, `workflow-as-agent.ts`) are not inside a folder module and follow normal rules. + ## Naming | Type | Style | Example | @@ -197,9 +227,8 @@ Test files (`__tests__/**`) are exempt. ### Commands ```bash -bun run check # biome check (lint + format) +bun run check # tsc --build + biome check bun run format # biome format --write -bun run build # full build bun test # run tests ```