@ryusenkei/conventions 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -3
- package/dist/files.js +23 -3
- package/dist/policy.js +10 -2
- package/dist/settings.js +11 -2
- package/package.json +2 -2
- package/rules-go.md +6 -0
- package/rules-rust.md +6 -0
- package/rules-ts.md +13 -0
- package/rules-ui.md +7 -0
- package/rules.md +7 -8
package/README.md
CHANGED
|
@@ -5,6 +5,7 @@ Shared conventions for RYUSENKEI monorepos created from monorepo-template. Rules
|
|
|
5
5
|
| Part | What it does |
|
|
6
6
|
| --- | --- |
|
|
7
7
|
| [`rules.md`](rules.md) | Rules for Claude Code, imported from each repository's `CLAUDE.md` (Japanese) |
|
|
8
|
+
| [`rules-ts.md`](rules-ts.md), [`rules-go.md`](rules-go.md), [`rules-rust.md`](rules-rust.md), [`rules-ui.md`](rules-ui.md) | Rules for one language or for UI code, imported only where they apply |
|
|
8
9
|
| `dist/hook.js` | Claude Code hook: blocks tool calls that break the rules, and optionally runs lint and tests before Claude finishes |
|
|
9
10
|
| `files/` | Master copies of the shared files, synced into each repository |
|
|
10
11
|
| `ryusenkei-conventions` | CLI: `sync` writes the shared files, `check` reports drift |
|
|
@@ -31,6 +32,7 @@ Requires Node.js 24 or later.
|
|
|
31
32
|
- Repository-specific rules
|
|
32
33
|
|
|
33
34
|
@node_modules/@ryusenkei/conventions/rules.md
|
|
35
|
+
@node_modules/@ryusenkei/conventions/rules-ts.md
|
|
34
36
|
```
|
|
35
37
|
|
|
36
38
|
2. Write the shared files: `npx ryusenkei-conventions sync` (add `--stop` to run lint and tests before Claude finishes).
|
|
@@ -52,7 +54,7 @@ The PreToolUse hook blocks the call and tells Claude why, so Claude can fix it a
|
|
|
52
54
|
| No force push to `main` / `master` | Blocks `git push --force` / `-f` / `--force-with-lease` and `+<refspec>` targeting `main` or `master` (also the current branch when no refspec is given) |
|
|
53
55
|
| PR title = squash commit message | Checks `gh pr create` / `gh pr edit` titles with prose-lint's commit rules |
|
|
54
56
|
| No AI signature | `attribution` is empty, and the hook blocks PR bodies with an AI signature |
|
|
55
|
-
| Squash merge
|
|
57
|
+
| Squash merge | Blocks `gh pr merge --rebase`, and `--merge` except for a `dev/*` → `main` PR with the epic flow, which must use `--merge` |
|
|
56
58
|
| Merge only after CI passes | Blocks `gh pr merge` unless every check of the PR has passed (`gh pr checks`). Pending, failed, missing, or unreadable checks are blocked, also with `--auto` (with the epic flow, a PR into `dev/*` may have no checks) |
|
|
57
59
|
| Epic flow (opt-in) | See [Epic flow](#epic-flow) |
|
|
58
60
|
| Do not edit `node_modules` | Blocks Edit and Write under `node_modules` |
|
|
@@ -76,6 +78,7 @@ Opt in per repository in the root `package.json`:
|
|
|
76
78
|
- Each epic gets an integration branch `dev/<issue>-<name>` (e.g. `dev/12-search`). Sub-issue PRs target it, and only a `dev/*` branch is merged into `main` (on deploy).
|
|
77
79
|
- `gh pr create` to `main` (`--base main`, or no `--base`) is blocked unless the head (`--head`, or the current branch) is `dev/*`.
|
|
78
80
|
- A PR from any other branch must target a `dev/*` base. `gh pr edit` is checked only when it changes `--base`.
|
|
81
|
+
- A `dev/*` → `main` PR is merged with a merge commit (`gh pr merge --merge`), not squashed. This keeps one commit per sub-issue on `main`, and keeps `dev/*` and `main` from diverging when work continues on the epic after a deploy. Turn on "Allow merge commits" in the repository settings.
|
|
79
82
|
- A PR into `dev/*` runs no CI; the pre-push `pnpm check` is the gate. `gh pr merge` allows such a PR with no checks, but any checks it has must still pass.
|
|
80
83
|
- Without the opt-in, none of this applies and `dev/*` branch names are rejected.
|
|
81
84
|
|
|
@@ -86,10 +89,20 @@ Opt in per repository in the root `package.json`:
|
|
|
86
89
|
- `.editorconfig`, `.gitattributes`, `.gitignore`, `.gitleaks.toml`, `mise.toml`, `.github/dependabot.yaml`, `.githooks/commit-msg`, `.githooks/pre-push`
|
|
87
90
|
- `.github/dependabot.yaml` updates npm and GitHub Actions. When the repository has a `go.mod` at the root, a `gomod` entry is appended (same schedule, rebase strategy and cooldown, minor and patch grouped). Without one it is left out, because Dependabot fails on a missing `go.mod`
|
|
88
91
|
- When the repository has a `Cargo.toml` at the root, a `cargo` entry is appended to `.github/dependabot.yaml` after any `gomod` entry (same settings as `gomod`, covering workspace members), and `target/` is appended to `.gitignore`. `Cargo.lock` stays tracked
|
|
89
|
-
- `.claude/settings.json`: only the hooks, `attribution`,
|
|
92
|
+
- `.claude/settings.json`: only the hooks, `attribution`, `permissions.deny`, and the writing plugins are managed. Other settings, hooks, and plugins are kept
|
|
93
|
+
- The writing plugins are [yomiyasu](https://github.com/nanaism/yomiyasu) (Japanese) and [humanizer](https://github.com/blader/humanizer) (English). `extraKnownMarketplaces` registers their marketplaces and `enabledPlugins` turns them on. They load after you trust the folder, with no separate install. They are not bundled, and they do not auto-update; run `/plugin` to update them. To turn one off in a repository, set it to `false` in `enabledPlugins`
|
|
90
94
|
- `pnpm-workspace.yaml`: `minimumReleaseAge` and `minimumReleaseAgeExclude`, matching the Dependabot `cooldown`
|
|
91
95
|
|
|
92
|
-
`check` also reports a missing `rules.md` import in `CLAUDE.md
|
|
96
|
+
`check` also reports a missing `rules.md` import in `CLAUDE.md`, and the imports of the language and UI rules a repository needs:
|
|
97
|
+
|
|
98
|
+
| Rules | Required when |
|
|
99
|
+
| --- | --- |
|
|
100
|
+
| `rules-ts.md` | `tsconfig.json` at the root |
|
|
101
|
+
| `rules-go.md` | `go.mod` at the root |
|
|
102
|
+
| `rules-rust.md` | `Cargo.toml` at the root |
|
|
103
|
+
| `rules-ui.md` | `"ryusenkei": { "ui": true }` in the root `package.json` |
|
|
104
|
+
|
|
105
|
+
When the `rules.md` import is present, `sync` adds the missing ones right after it.
|
|
93
106
|
|
|
94
107
|
Dependabot runs monthly with `rebase-strategy: disabled` to save GitHub Actions minutes, so rebase a Dependabot PR (`@dependabot rebase`) before merging it. The `cooldown` excludes `@ryusenkei/*`. To pick up a new version sooner, run `pnpm update "@ryusenkei/*"`. After an update, `check` fails until `sync` is run.
|
|
95
108
|
|
package/dist/files.js
CHANGED
|
@@ -26,6 +26,21 @@ const SETTINGS = '.claude/settings.json';
|
|
|
26
26
|
const WORKSPACE = 'pnpm-workspace.yaml';
|
|
27
27
|
/** CLAUDE.md で共通の規約を読み込む import */
|
|
28
28
|
export const IMPORT = '@node_modules/@ryusenkei/conventions/rules.md';
|
|
29
|
+
// 言語・UI の規約: 条件に合うリポだけ import を求める(UI は `package.json` の `"ryusenkei": { "ui": true }` で opt-in)
|
|
30
|
+
const LANG_RULES = [
|
|
31
|
+
{ file: 'rules-ts.md', if: (root) => existsSync(join(root, 'tsconfig.json')) },
|
|
32
|
+
{ file: 'rules-go.md', if: (root) => existsSync(join(root, 'go.mod')) },
|
|
33
|
+
{ file: 'rules-rust.md', if: (root) => existsSync(join(root, 'Cargo.toml')) },
|
|
34
|
+
{ file: 'rules-ui.md', if: (root) => uiOptIn(root) },
|
|
35
|
+
];
|
|
36
|
+
function uiOptIn(root) {
|
|
37
|
+
try {
|
|
38
|
+
return JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')).ryusenkei?.ui === true;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
29
44
|
// `.github/dependabot.yaml` の `cooldown` と同値
|
|
30
45
|
const RELEASE_AGE = [
|
|
31
46
|
'# 公開から2日未満のバージョンは解決しない(`.github/dependabot.yaml` の `cooldown` と同値)',
|
|
@@ -49,7 +64,7 @@ export function drifts(root, options = {}) {
|
|
|
49
64
|
const current = raw === undefined ? {} : JSON.parse(raw);
|
|
50
65
|
const settings = `${JSON.stringify(managedSettings(current, { stop: options.stop ?? hasStop(current) }), null, 2)}\n`;
|
|
51
66
|
if (raw !== settings)
|
|
52
|
-
out.push({ path: SETTINGS, expected: settings, message: 'hook・`attribution`・`permissions.deny
|
|
67
|
+
out.push({ path: SETTINGS, expected: settings, message: 'hook・`attribution`・`permissions.deny`・プラグインが不一致' });
|
|
53
68
|
const workspace = read(join(root, WORKSPACE)) ?? '';
|
|
54
69
|
if (!workspace.includes(RELEASE_AGE.slice(1).join('\n'))) {
|
|
55
70
|
if (/^minimumReleaseAge/m.test(workspace))
|
|
@@ -58,8 +73,13 @@ export function drifts(root, options = {}) {
|
|
|
58
73
|
out.push({ path: WORKSPACE, expected: `${workspace.trimEnd()}\n\n${RELEASE_AGE.join('\n')}\n`, message: '`minimumReleaseAge` が未設定' });
|
|
59
74
|
}
|
|
60
75
|
const claude = read(join(root, 'CLAUDE.md')) ?? '';
|
|
61
|
-
|
|
62
|
-
|
|
76
|
+
const lines = claude.split('\n');
|
|
77
|
+
const at = lines.findIndex((l) => l.trim() === IMPORT);
|
|
78
|
+
const missing = LANG_RULES.filter((r) => r.if(root)).map((r) => IMPORT.replace('rules.md', r.file)).filter((line) => !lines.some((l) => l.trim() === line));
|
|
79
|
+
if (at === -1)
|
|
80
|
+
out.push({ path: 'CLAUDE.md', message: `共通の規約の import(\`${[IMPORT, ...missing].join('`・`')}\`)を追加` });
|
|
81
|
+
else if (missing.length)
|
|
82
|
+
out.push({ path: 'CLAUDE.md', expected: [...lines.slice(0, at + 1), ...missing, ...lines.slice(at + 1)].join('\n'), message: `規約の import(\`${missing.join('`・`')}\`)が不足` });
|
|
63
83
|
return out;
|
|
64
84
|
}
|
|
65
85
|
/** 自動で修正できる差分を書き込み、残りの差分を返却 */
|
package/dist/policy.js
CHANGED
|
@@ -235,11 +235,19 @@ function prReasons(sub, args, st, ctx) {
|
|
|
235
235
|
}
|
|
236
236
|
// `--auto` も対象(必須のチェックがないリポでは即時にマージされる)
|
|
237
237
|
// - epic のフローの dev/* への PR: チェックなしを許可(CI を実行せず pre-push の `pnpm check` が関門)
|
|
238
|
+
// - epic のフローの dev/* から main への PR: merge commit
|
|
239
|
+
// squash すると sub-issue ごとのコミットが1つにまとまり、dev と main の履歴もずれる
|
|
238
240
|
function mergeReasons(args, st, ctx) {
|
|
239
241
|
const { cwd } = st;
|
|
240
|
-
if (args.some((a) => a === '--
|
|
241
|
-
return ['
|
|
242
|
+
if (args.some((a) => a === '--rebase' || a === '-r'))
|
|
243
|
+
return ['rebase でのマージは禁止(`--squash`、dev のブランチから main へは `--merge`)'];
|
|
242
244
|
const pr = positionals(args, MERGE_VALUE)[0];
|
|
245
|
+
const merge = args.some((a) => a === '--merge' || a === '-m');
|
|
246
|
+
const devToMain = epicFlow(st, ctx) && DEV_BRANCH.test(ctx.prHead(pr, cwd) ?? '') && PROTECTED.includes(ctx.prBase(pr, cwd) ?? '');
|
|
247
|
+
if (devToMain && !merge)
|
|
248
|
+
return ['dev のブランチから main へのマージは merge commit(`--merge`)。sub-issue ごとのコミットを残すため'];
|
|
249
|
+
if (!devToMain && merge)
|
|
250
|
+
return ['マージは squash(`--squash`)。merge commit は epic のフローで dev のブランチから main への PR だけ'];
|
|
243
251
|
const checks = ctx.prChecks(pr, cwd);
|
|
244
252
|
if (checks === 'pass')
|
|
245
253
|
return [];
|
package/dist/settings.js
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
// `.claude/settings.json` の管理する項目
|
|
2
|
-
// - hook の登録・`attribution`・`permissions.deny
|
|
3
|
-
// - リポ独自の設定・hook
|
|
2
|
+
// - hook の登録・`attribution`・`permissions.deny`・文章の見直しのプラグイン(yomiyasu・humanizer)
|
|
3
|
+
// - リポ独自の設定・hook は維持。プラグインはリポで `false` にすれば無効のまま
|
|
4
4
|
/** hook の本体のパス(`node` で直接実行 → Windows でもシェルを経由しない) */
|
|
5
5
|
export const HOOK_PATH = '${CLAUDE_PROJECT_DIR}/node_modules/@ryusenkei/conventions/dist/hook.js';
|
|
6
6
|
const HOOK = { type: 'command', command: 'node', args: [HOOK_PATH] };
|
|
7
7
|
const PROSE_LINT = { type: 'command', command: 'npx --no -- prose-lint --hook' };
|
|
8
8
|
// 秘密値のファイル(`.env.example` は対象外 → `.env.*` の指定は不可)
|
|
9
9
|
const DENY = ['Read(./**/.env)', 'Read(./**/.dev.vars)'];
|
|
10
|
+
// 同梱せずマーケットプレイスから読み込む(ライセンスの表示に個人名を含むため)
|
|
11
|
+
// `autoUpdate` は既定の `false`(第三者のマーケットプレイス)→ 上流の変更は各自の更新の操作まで入らない
|
|
12
|
+
const MARKETPLACES = {
|
|
13
|
+
yomiyasu: { source: { source: 'github', repo: 'nanaism/yomiyasu' } },
|
|
14
|
+
humanizer: { source: { source: 'github', repo: 'blader/humanizer' } },
|
|
15
|
+
};
|
|
16
|
+
const PLUGINS = { 'yomiyasu@yomiyasu': true, 'humanizer@humanizer': true };
|
|
10
17
|
const owned = (h) => (h.command === 'node' && h.args?.[0] === HOOK_PATH) || h.command.includes('prose-lint --hook');
|
|
11
18
|
/** Stop の hook(完了前の lint・test)が登録済みか */
|
|
12
19
|
export const hasStop = (s) => (s.hooks?.Stop ?? []).some((g) => g.hooks.some(owned));
|
|
@@ -27,6 +34,8 @@ export function managedSettings(current, options) {
|
|
|
27
34
|
...current,
|
|
28
35
|
attribution: { commit: '', pr: '', sessionUrl: false },
|
|
29
36
|
permissions: { ...current.permissions, deny },
|
|
37
|
+
extraKnownMarketplaces: { ...current.extraKnownMarketplaces, ...MARKETPLACES },
|
|
38
|
+
enabledPlugins: { ...PLUGINS, ...current.enabledPlugins },
|
|
30
39
|
hooks,
|
|
31
40
|
};
|
|
32
41
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ryusenkei/conventions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "RYUSENKEI のモノリポの共通の規約(Claude Code の規約・hook、共通ファイルの同期)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "RYUSENKEI",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"files": [
|
|
25
25
|
"dist",
|
|
26
26
|
"files",
|
|
27
|
-
"rules
|
|
27
|
+
"rules*.md"
|
|
28
28
|
],
|
|
29
29
|
"engines": {
|
|
30
30
|
"node": ">=24"
|
package/rules-go.md
ADDED
package/rules-rust.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
## Rust
|
|
2
|
+
|
|
3
|
+
- ライブラリのエントリポイントは `src/lib.rs`。`pub` にするのは外部で使うものだけ
|
|
4
|
+
- 単体テストは対象と同じファイルの `#[cfg(test)] mod tests` に書く
|
|
5
|
+
- `unsafe` は OS の API の呼び出しだけに使い、箇所ごとに `#[allow(unsafe_code)]` と `SAFETY` のコメントを付ける
|
|
6
|
+
- `pnpm lint` に `cargo fmt --all --check` と `cargo clippy --workspace --all-targets -- -D warnings`、`pnpm test` に `cargo test --workspace` を含める
|
package/rules-ts.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
## TypeScript
|
|
2
|
+
|
|
3
|
+
- エントリポイントはパッケージごとの `src/index.ts`
|
|
4
|
+
- TypeScript はビルドせず、Node で直接実行する(`node scripts/x.ts`)
|
|
5
|
+
- テストは Vitest で書き、対象と同じディレクトリに `*.test.ts` を置く
|
|
6
|
+
- 子プロセスは `scripts/lib/exec.ts` の `exec` で起動する。Windows の `.cmd` に対応するため
|
|
7
|
+
|
|
8
|
+
## 定数
|
|
9
|
+
|
|
10
|
+
- export するモジュールの定数は UPPER_SNAKE で書き、`as const satisfies T` を付ける。フィールドは camelCase
|
|
11
|
+
- 数値は単位を接尾辞で表す(`Ms`、`Sec`、`Px`、`Rem`、`Pct`、`MB` など)
|
|
12
|
+
- enum は使わない。`const X = [...] as const` と `type X = (typeof X)[number]` で表す
|
|
13
|
+
- 条件、数値、識別子は config に置き、表示の文言は辞書に置く。複数の言語から使う値は JSON のマスタを1つ置く
|
package/rules-ui.md
ADDED
package/rules.md
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
## コード
|
|
2
2
|
|
|
3
|
-
-
|
|
3
|
+
- パッケージ・クレートの責務と依存は、README の構成の表に従う
|
|
4
4
|
- リポ内で共有するコードは `packages/*` に置く。リポをまたぐものは toolkit(npm の `@ryusenkei/*`)に置き、変更も toolkit で行う
|
|
5
|
-
-
|
|
6
|
-
-
|
|
7
|
-
- テストは Vitest で書き、対象と同じディレクトリに `*.test.ts` を置く
|
|
8
|
-
- 子プロセスは `scripts/lib/exec.ts` の `exec` で起動する。Windows の `.cmd` に対応するため
|
|
5
|
+
- エントリポイントでは外部で使うものだけを公開し、他パッケージのものを公開し直さない
|
|
6
|
+
- テストは対象の近くに置く。言語ごとの置き方は `rules-ts.md`・`rules-go.md`・`rules-rust.md`
|
|
9
7
|
- 依存の更新は Dependabot の PR で行う。月1回で自動の rebase はしないので、マージの前に手で rebase する
|
|
10
8
|
|
|
11
9
|
## 設定と秘密値
|
|
@@ -49,7 +47,7 @@
|
|
|
49
47
|
- 表は比較や対応表のように、中身が表の形のものに使う。飾りとして表や、太字の見出しを付けた箇条書きにしない
|
|
50
48
|
- エラー、ログ、標準出力はコード(識別子)で表す。人が読む文言は表示のマスタ(辞書)から引き、その場に日本語を書かない
|
|
51
49
|
- コード上の値と環境変数はバッククォートで囲む。ドメインの概念、説明、表示の文言は日本語で書く
|
|
52
|
-
- 文章を見直すときは、日本語の文書・issue・PR に yomiyasu、英語の README に humanizer
|
|
50
|
+
- 文章を見直すときは、日本語の文書・issue・PR に yomiyasu、英語の README に humanizer のスキルを使う(`.claude/settings.json` のプラグインで有効)。出てくるのは見直しの候補で、点数を合格の基準にしない
|
|
53
51
|
- prose-lint が止めるのは機械的な誤り(空白、句読点、表記の揺れ)だけ。ドメインの用語が表記の規則に当たるときは、`prose-lint.json` の `allow` に足す
|
|
54
52
|
|
|
55
53
|
## Git と PR
|
|
@@ -57,11 +55,12 @@
|
|
|
57
55
|
- add は変更・追加したファイルをパスで指定する。一括の add はフックで止まる
|
|
58
56
|
- push の前に `pnpm check` を通す。`check` を持つリポでは pre-push で強制される
|
|
59
57
|
- PR の本文は背景、変更、検証の順に書く
|
|
60
|
-
- マージは CI の全チェックの成功を確かめてから行う(フックで強制)
|
|
58
|
+
- マージは squash で、CI の全チェックの成功を確かめてから行う(フックで強制)
|
|
61
59
|
- epic のフロー(有効にしたリポだけ)
|
|
62
60
|
- epic ごとに `dev/<issue の番号>-<内容>` を作り、sub-issue の PR は dev のブランチに向ける
|
|
63
61
|
- dev のブランチへのマージに CI は使わず、pre-push の `pnpm check` を関門にする。チェックがある場合は成功が必要
|
|
64
|
-
- `main` へのマージは、デプロイのときに dev
|
|
62
|
+
- `main` へのマージは、デプロイのときに dev のブランチからだけ行う。方法は merge commit(`gh pr merge --merge`)で、sub-issue ごとのコミットを残し、dev と main の履歴をずらさない
|
|
63
|
+
- リポの設定で merge commit を許可する(Settings → General → Allow merge commits)
|
|
65
64
|
|
|
66
65
|
## CI(GitHub Actions)
|
|
67
66
|
|