diff --git a/.agents/README.md b/.agents/agents.readme.md similarity index 99% rename from .agents/README.md rename to .agents/agents.readme.md index 222a11e..b1e8342 100644 --- a/.agents/README.md +++ b/.agents/agents.readme.md @@ -8,7 +8,7 @@ This directory (`.agents/`) maintains modular configuration, skills, and guideli ``` .agents/ -├── README.md # This document: architecture & trigger policy +├── agents.readme.md # This document: architecture & trigger policy ├── skills.json # Declarative skill path and exclusion filters ├── skills/ # Project-level skills │ └── repo-gh/ # GitHub CLI & Git Markdown-First operations diff --git a/.githooks/pre-commit b/.githooks/pre-commit index e90c38e..8ddf0a5 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -130,4 +130,8 @@ if printf '%s\n' "$staged" | grep -qE "^skills/seal-use/(SKILL\.md|references/[^ bun run verify:skill-md || exit 1 fi +if printf '%s\n' "$staged" | grep -qiE "(^|/)readme"; then + bun run verify:readme-naming || exit 1 +fi + exit 0 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d80197b..fd9e88a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,6 +53,9 @@ jobs: - name: Embedded Skill Sync run: bun run verify:embedded-skill + - name: README Naming Checks + run: bun run verify:readme-naming + - name: Colocated Unit Tests run: bun test diff --git a/AGENTS.md b/AGENTS.md index 9b844d0..fe5abe8 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -6,7 +6,7 @@ This is a Bun + TypeScript toolkit for the `seal-use` CLI and a local stdio MCP The repository doubles as a ZCode plugin: `.zcode-plugin/plugin.json` declares a skills-only plugin manifest and the agent skill lives under `skills/seal-use/`. The plugin ships no MCP surface; the local MCP runs from the CLI (`seal-use mcp`, or the `mcp-config` snippet for Cursor/Claude Desktop). The in-repo `.agents/skills/seal-use` symlink has been dropped; workspace and Codex skill loading use the global `~/.agents/skills/seal-use` copy installed by `seal-use skill install`. -Engineering toolchain, code generators, build pipelines, and governance gate scripts live under `scripts/`. Scripts under `scripts/` are offline harnesses, not application runtime code — never import them into `src/`. Governance gates are grouped under `scripts/governance/` (`check-agents-md.ts`, `check-skill-md.ts`, `check-readme.ts`, `doc-md-common.ts`). Destructive release scripts (`scripts/release.ts`, `scripts/bump-version.ts`) must never be triggered autonomously by agents without explicit human instruction. +Engineering toolchain, code generators, build pipelines, and governance gate scripts live under `scripts/`. Scripts under `scripts/` are offline harnesses, not application runtime code — never import them into `src/`. Governance gates are grouped under `scripts/governance/` (`check-agents-md.ts`, `check-skill-md.ts`, `check-readme.ts`, `check-readme-naming.ts`, `doc-md-common.ts`). Destructive release scripts (`scripts/release.ts`, `scripts/bump-version.ts`) must never be triggered autonomously by agents without explicit human instruction. Within `src/domains/seal/`, the root contains only shared protocol boundaries (`api.ts`, `api.test.ts`, `types.ts`) and the public capability export (`capabilities.ts`). Business implementations belong in their feature directories: `rules/`, `approval-runs/`, `insight/`, `replay/`, `outbound/`, `enterprise/`, `search/`, and `testing/`; existing `reports/`, `linter/`, `material-pack/`, `doctor/`, and `regression/` retain their own boundaries. Put new Seal implementations and their tests in the matching feature directory (for example `rules/recode.ts` and `rules/recode.test.ts`), rather than adding business files or legacy forwarding stubs to the domain root. The registry-wide tests live in `capabilities/capabilities.test.ts`. @@ -25,6 +25,7 @@ Tests are colocated as `*.test.ts` files in `src/`. - `bun run verify:agents-md`: validate the root `AGENTS.md` developer contract (structure, required sections, `.agents/rules/` reference integrity and reverse coverage); wired into pre-commit (staged docs only) and CI. - `bun run verify:skill-md`: validate the `skills/seal-use/SKILL.md` routing hub (structure and bidirectional `references/` routing); wired into pre-commit (staged docs only) and CI. - `bun run verify:readme`: lightweight hygiene and structure checks for `README.md` (warnings only, never blocks). +- `bun run verify:readme-naming`: enforce the root `README.md` and subdirectory `.readme.md` naming rule (leading dots stripped, e.g. `src/src.readme.md`); wired into pre-commit (staged README files) and CI. - `bun run bump `: bump version across all manifest and skill files. - `bun run dev:override`: compile the host binary with Git dev version metadata, macOS sign, atomically override the existing global command found on PATH (falling back to a standalone bin directory), and sync the local Agent Skill. diff --git a/README.md b/README.md index a6cb196..2c257e9 100644 --- a/README.md +++ b/README.md @@ -154,6 +154,7 @@ Three layers of documentation serve distinct audiences and boundaries, each vali - **`README.md` — the user/evaluator entry point.** High-level overview, quick installation, architecture, and governance outline (`bun run verify:readme`). - **`AGENTS.md` — the developer contract.** How contributors (human or agent) change this codebase: module boundaries, CLI stream/exit-code protocol, testing, release rules (`bun run verify:agents-md`). - **`skills/seal-use/SKILL.md` — the user/agent routing hub.** How an agent session uses the shipped skill: bootstrap, credential boundaries, and the terminal `## 参考文档路由` table that routes intents to `skills/seal-use/references/*.md`, which stay the single source of truth for operational detail (`bun run verify:skill-md`). +- **Subdirectory readmes — `.readme.md`.** The root keeps `README.md`; every other README carries its directory name as a prefix, such as `src/src.readme.md` and `host-infra/host-infra.readme.md` (`bun run verify:readme-naming`). Workflow rules live in `.agents/rules/*.md`; the root `AGENTS.md` indexes them and carries the enforced contract. Engineering and governance scripts live under `scripts/`, partitioned into `scripts/governance/` (automated gates) and root build/release pipelines. @@ -354,4 +355,4 @@ bun run bump 0.8.5 **CI & Promotion Pipeline:** - GitHub Actions triggers automatically upon pushing a `v*` tag to `origin`; - Cross-compiles standalone binaries for 5 target platforms (macOS Apple Silicon/Intel, Linux x86_64/ARM64, Windows x64) and publishes them to **[GitHub Releases](https://github.com/yunyingk/seal-use/releases)**; -- WSL `seal-use-release-sync.timer` polls the latest GitHub Release and promotes all assets to **[Gitea Releases](https://git.ying-qing.cn/gitea/seal-use/releases)** (`host-infra/README.md`). +- WSL `seal-use-release-sync.timer` polls the latest GitHub Release and promotes all assets to **[Gitea Releases](https://git.ying-qing.cn/gitea/seal-use/releases)** (`host-infra/host-infra.readme.md`). diff --git a/host-infra/README.md b/host-infra/host-infra.readme.md similarity index 73% rename from host-infra/README.md rename to host-infra/host-infra.readme.md index 012cda3..cce9e94 100644 --- a/host-infra/README.md +++ b/host-infra/host-infra.readme.md @@ -49,19 +49,3 @@ It emits JSON checks for mac15, the Mac15-to-WSL Tailscale/SSH path, WSL, Windows, mac13, and Aliyun, including the release-sync timer state and the last successful Gitea promotion. The script is read-only; a failed check does not restart or mutate any service. - -## Workspace backups - -The repository is the source of truth. After the host-infra changes are committed to -`main`, back up the tracked `host-infra/` directory to each machine's global workspace: - -```sh -./host-infra/backup-workspace-scripts.sh -``` - -Each run creates a commit-named snapshot under -`~/Workspace/ops-backups/seal-use/` on mac15 and mac13, and under -`~/workspace/ops-backups/seal-use/` on WSL and Aliyun. Each snapshot includes a -manifest with its source commit and backup time. Only tracked `host-infra/` files are -copied; private runtime configuration and credentials are excluded. Run the -backup command again after changing operational scripts or service templates. diff --git a/package.json b/package.json index 83fa0b6..485e608 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,8 @@ "verify:cli-md": "bun run scripts/check-cli-md.mjs", "verify:agents-md": "bun run scripts/governance/check-agents-md.ts", "verify:skill-md": "bun run scripts/governance/check-skill-md.ts", - "verify:readme": "bun run scripts/governance/check-readme.ts" + "verify:readme": "bun run scripts/governance/check-readme.ts", + "verify:readme-naming": "bun run scripts/governance/check-readme-naming.ts" }, "dependencies": { "@modelcontextprotocol/server": "^2.0.0", diff --git a/scripts/governance/check-readme-naming.test.ts b/scripts/governance/check-readme-naming.test.ts new file mode 100644 index 0000000..ab1d835 --- /dev/null +++ b/scripts/governance/check-readme-naming.test.ts @@ -0,0 +1,106 @@ +import { describe, expect, test } from "bun:test" +import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs" +import { tmpdir } from "node:os" +import { join } from "node:path" +import { + checkReadmeNaming, + expectedReadmeName, + isReadmeLike, + validateReadmePaths +} from "./check-readme-naming.js" + +describe("isReadmeLike", () => { + test("matches README variants", () => { + for (const name of ["README.md", "readme.md", "README.txt", "src.readme.md"]) { + expect(isReadmeLike(name)).toBe(true) + } + }) + + test("ignores unrelated files", () => { + for (const name of ["index.md", "readme-assets.ts", "README_GUIDE.md"]) { + expect(isReadmeLike(name)).toBe(false) + } + }) +}) + +describe("expectedReadmeName", () => { + test("prefixes with the directory name", () => { + expect(expectedReadmeName("src")).toBe("src.readme.md") + expect(expectedReadmeName("host-infra")).toBe("host-infra.readme.md") + }) + + test("strips leading dots from dot-directories", () => { + expect(expectedReadmeName(".agents")).toBe("agents.readme.md") + }) +}) + +describe("validateReadmePaths", () => { + test("accepts the conventional layout", () => { + const issues = validateReadmePaths([ + "README.md", + "src/src.readme.md", + ".agents/agents.readme.md", + "host-infra/host-infra.readme.md", + "src/domains/seal/reports/reports.readme.md" + ]) + expect(issues).toEqual([]) + }) + + test("rejects a plain README.md in a subdirectory", () => { + const issues = validateReadmePaths(["README.md", "src/README.md"]) + expect(issues).toHaveLength(1) + expect(issues[0].file).toBe("src/README.md") + expect(issues[0].rule).toBe("subdir-readme-name") + }) + + test("rejects a subdirectory README with the wrong prefix", () => { + const issues = validateReadmePaths(["README.md", "src/docs.readme.md"]) + expect(issues).toHaveLength(1) + expect(issues[0].rule).toBe("subdir-readme-name") + expect(issues[0].message).toContain("src.readme.md") + }) + + test("rejects a lowercase root readme", () => { + const issues = validateReadmePaths(["readme.md"]) + expect(issues.some((issue) => issue.rule === "root-readme-name")).toBe(true) + expect(issues.some((issue) => issue.rule === "missing-root-readme")).toBe(true) + }) + + test("requires a root README", () => { + const issues = validateReadmePaths(["src/src.readme.md"]) + expect(issues.some((issue) => issue.rule === "missing-root-readme")).toBe(true) + }) + + test("accepts nested directories with matching prefixes", () => { + const issues = validateReadmePaths([ + "README.md", + "src/domains/seal/reports/reports.readme.md", + "src/domains/seal/reports/templates/templates.readme.md" + ]) + expect(issues).toEqual([]) + }) +}) + +describe("checkReadmeNaming", () => { + test("skips the local root reports directory but checks nested ones", () => { + const root = mkdtempSync(join(tmpdir(), "readme-naming-")) + try { + writeFileSync(join(root, "README.md"), "# Root") + mkdirSync(join(root, "reports")) + writeFileSync(join(root, "reports", "README.md"), "# Local-only") + mkdirSync(join(root, "src")) + writeFileSync(join(root, "src", "README.md"), "# Wrong") + + const issues = checkReadmeNaming(root) + expect(issues).toHaveLength(1) + expect(issues[0].file).toBe("src/README.md") + } finally { + rmSync(root, { recursive: true, force: true }) + } + }) + + test("the committed repository passes the naming rule", () => { + const root = join(import.meta.dirname, "../..") + expect(checkReadmeNaming(root)).toEqual([]) + }) +}) diff --git a/scripts/governance/check-readme-naming.ts b/scripts/governance/check-readme-naming.ts new file mode 100644 index 0000000..af45fe0 --- /dev/null +++ b/scripts/governance/check-readme-naming.ts @@ -0,0 +1,149 @@ +#!/usr/bin/env bun +/** + * Governance check for README naming. + * + * Rule: the repository root keeps the conventional `README.md`; every + * subdirectory README must carry its directory name as a prefix, e.g. + * `src/src.readme.md`, `.agents/agents.readme.md` (leading dots are stripped + * so the file stays visible). + * + * Invoked as `bun run verify:readme-naming` (CI + pre-commit) and with + * `--soft` from the ZCode SessionStart hook. + */ +import { readdirSync } from "node:fs" +import { join, relative, sep } from "node:path" + +export const ROOT_README = "README.md" + +/** Directories whose contents are generated, vendored, or local-only. */ +export const SKIP_DIRS: ReadonlySet = new Set([ + "node_modules", + ".git", + "dist", + "build", + "coverage", + ".cache", + "tmp", + ".local", + ".drafts", + ".workbuddy", + ".mimosa", + ".apifox" +]) + +/** + * Only the repository-root copy is local-only; a nested `reports/` directory + * (e.g. `src/domains/seal/reports/`) is tracked and must still be checked. + */ +export const ROOT_ONLY_SKIP_DIRS: ReadonlySet = new Set(["reports"]) + +export type ReadmeNamingIssue = { + file: string + rule: string + message: string +} + +/** `README.md`, `readme.txt`, `src.readme.md` — any file named like a README. */ +export function isReadmeLike(name: string): boolean { + const lower = name.toLowerCase() + return lower === "readme" || lower.startsWith("readme.") || lower.endsWith(".readme.md") +} + +/** Directory name → required README prefix, stripping leading dots. */ +export function expectedReadmeName(dirName: string): string { + const prefix = dirName.replace(/^\.+/, "") || dirName + return `${prefix}.readme.md` +} + +/** + * Pure validation over repo-relative paths so tests do not need a temp tree. + */ +export function validateReadmePaths(paths: readonly string[]): ReadmeNamingIssue[] { + const issues: ReadmeNamingIssue[] = [] + const normalized = paths.map((path) => path.split(sep).join("/")) + + if (!normalized.includes(ROOT_README)) { + issues.push({ + file: ROOT_README, + rule: "missing-root-readme", + message: "repository root must keep README.md" + }) + } + + for (const path of normalized) { + const parts = path.split("/") + const name = parts.pop() ?? "" + if (!isReadmeLike(name)) continue + + if (parts.length === 0) { + if (name !== ROOT_README) { + issues.push({ + file: path, + rule: "root-readme-name", + message: `root README must be named ${ROOT_README}, found ${name}` + }) + } + continue + } + + const dirName = parts[parts.length - 1] + const expected = expectedReadmeName(dirName) + if (name !== expected) { + issues.push({ + file: path, + rule: "subdir-readme-name", + message: `subdirectory README must be named ${expected} (directory "${dirName}"), found ${name}` + }) + } + } + + return issues +} + +function collectFiles(rootDir: string, dir = rootDir, files: string[] = []): string[] { + for (const entry of readdirSync(dir, { withFileTypes: true })) { + if (entry.isDirectory()) { + if (SKIP_DIRS.has(entry.name)) continue + const relDir = relative(rootDir, join(dir, entry.name)).split(sep).join("/") + if (ROOT_ONLY_SKIP_DIRS.has(entry.name) && relDir === entry.name) continue + collectFiles(rootDir, join(dir, entry.name), files) + } else if (entry.isFile()) { + files.push(relative(rootDir, join(dir, entry.name)).split(sep).join("/")) + } + } + return files +} + +export function checkReadmeNaming(rootDir: string): ReadmeNamingIssue[] { + return validateReadmePaths(collectFiles(rootDir)) +} + +function main(): void { + const root = join(import.meta.dirname, "../..") + const issues = checkReadmeNaming(root) + + if (process.argv.includes("--soft")) { + if (issues.length > 0) { + const summary = issues.map((issue) => issue.message).join("; ") + console.log( + JSON.stringify({ + additionalContext: `README 命名检查发现 ${issues.length} 项问题:${summary}。本地运行 bun run verify:readme-naming 查看详情。` + }) + ) + } + return + } + + if (issues.length > 0) { + for (const issue of issues) { + console.error(`✗ ${issue.file}: ${issue.message} [${issue.rule}]`) + } + console.error(`README naming checks failed (${issues.length} issue(s)).`) + process.exitCode = 1 + return + } + + console.log("README naming checks passed.") +} + +if (import.meta.main) main() diff --git a/scripts/README.md b/scripts/scripts.readme.md similarity index 96% rename from scripts/README.md rename to scripts/scripts.readme.md index db0319e..a734783 100644 --- a/scripts/README.md +++ b/scripts/scripts.readme.md @@ -13,6 +13,7 @@ scripts/ │ ├── check-agents-md.ts # AGENTS.md 开发者契约校验器 │ ├── check-skill-md.ts # SKILL.md 路由中枢与 references 双向路由校验器 │ ├── check-readme.ts # README.md 结构与卫生巡检器(警告级别) +│ ├── check-readme-naming.ts # 子目录 README 命名规范校验器(目录名前缀) │ ├── doc-md-common.ts # 共享 fence 感知 Markdown 解析纯函数库 │ └── *.test.ts # 逻辑 fixture 与真实文档现状双覆盖测试 │ diff --git a/src/domains/seal/reports/README.md b/src/domains/seal/reports/reports.readme.md similarity index 97% rename from src/domains/seal/reports/README.md rename to src/domains/seal/reports/reports.readme.md index edbbafc..fe79df1 100644 --- a/src/domains/seal/reports/README.md +++ b/src/domains/seal/reports/reports.readme.md @@ -38,5 +38,5 @@ src/domains/seal/reports/ │ ├── resources.ts # Bun 编译期静态资源嵌入定义 │ └── assets/ # 内置图 1 矢量图表资产 ├── index.ts # 报告域对外统一门面出口 (Barrel) -└── README.md # 架构与开发指南 +└── reports.readme.md # 架构与开发指南 ``` diff --git a/src/domains/seal/reports/templates/README.md b/src/domains/seal/reports/templates/templates.readme.md similarity index 100% rename from src/domains/seal/reports/templates/README.md rename to src/domains/seal/reports/templates/templates.readme.md diff --git a/src/src.readme.md b/src/src.readme.md new file mode 100644 index 0000000..8b28001 --- /dev/null +++ b/src/src.readme.md @@ -0,0 +1,17 @@ +# Source Layout & Module Organization + +`src/` is split into three layers. Dependencies flow in one direction only: +`cli → domains → core`. + +``` +src/ +├── cli/ # CLI surface: parse args, dispatch commands, render JSON on stdout +├── core/ # Cross-domain infrastructure: config, auth, HTTP, search, diagnostics +└── domains/ # Business domains: seal, hose, enterprise, langfuse +``` + +Entry points: `cli.ts` (CLI), `server.ts` (MCP stdio server), `probe.ts` (local +connectivity probe). + +The full contract, including where new code belongs, lives in the root +[`AGENTS.md`](../AGENTS.md) under "Project Structure & Module Organization".