@ryusenkei/conventions 0.8.1 → 0.9.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/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ ## 0.9.0
4
+
5
+ - `TEST_EXCLUDE` (`.claude/**`, `**/.terraform/**`): patterns to add to Vitest's default `exclude`.
6
+ - `check` reports a root Vitest config without them, or a repository that depends on `vitest` without a root config. Add `exclude: [...configDefaults.exclude, ...TEST_EXCLUDE]` to the root `vitest.config.ts`.
7
+ - The shared `.gitignore` ignores `.terraform/`. Run `ryusenkei-conventions sync`.
8
+ - `rules-ts.md` names `execSync` from `@ryusenkei/scripts` 0.4 (`exec` was renamed) and the Vitest exclude.
9
+ - The CLI exits with 2 for an unknown option (it crashed with 1) and takes `--help`.
10
+
11
+ ## 0.8.2 and earlier
12
+
13
+ See the git history of `packages/conventions`.
package/README.md CHANGED
@@ -9,6 +9,7 @@ Shared conventions for RYUSENKEI monorepos created from monorepo-template. Rules
9
9
  | `dist/hook.js` | Claude Code hook: blocks tool calls that break the rules, and optionally runs lint and tests before Claude finishes |
10
10
  | `files/` | Master copies of the shared files, synced into each repository |
11
11
  | `ryusenkei-conventions` | CLI: `sync` writes the shared files, `check` reports drift |
12
+ | `TEST_EXCLUDE` | Patterns to add to Vitest's default `exclude` |
12
13
 
13
14
  ## Install
14
15
 
@@ -37,6 +38,7 @@ Requires Node.js 24 or later.
37
38
 
38
39
  2. Write the shared files: `npx ryusenkei-conventions sync` (add `--stop` to run lint and tests before Claude finishes).
39
40
  3. Add `ryusenkei-conventions check` to the `lint` script.
41
+ 4. With Vitest, exclude `TEST_EXCLUDE` in the root `vitest.config.ts` (see [Vitest](#vitest)).
40
42
 
41
43
  - Claude Code expands the import when a session starts. Run `pnpm install` first, or the rules are not loaded.
42
44
  - The import resolves inside the working directory, so Claude Code does not ask for approval of external imports.
@@ -54,7 +56,7 @@ The PreToolUse hook blocks the call and tells Claude why, so Claude can fix it a
54
56
  | 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) |
55
57
  | PR title = squash commit message | Checks `gh pr create` / `gh pr edit` titles with prose-lint's commit rules |
56
58
  | No AI signature | `attribution` is empty, and the hook blocks PR bodies with an AI signature |
57
- | Squash merge | Blocks `gh pr merge --rebase`, and `--merge` except for a `dev/*` → `main` PR with the epic flow, which must use `--merge` |
59
+ | Squash merge | Blocks `gh pr merge --rebase` and `--merge`, also for a `dev/*` → `main` PR with the epic flow |
58
60
  | 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`. A PR may have no checks only when the repository has no enabled workflow that runs on `pull_request` (workflows disabled on GitHub with `gh workflow disable` don't count; the pre-push `pnpm check` is the gate), or with the epic flow when it targets `dev/*`. Right after a push, the checks may not be registered yet, so the hook points to `gh pr checks --watch` |
59
61
  | Epic flow (opt-in) | See [Epic flow](#epic-flow) |
60
62
  | Do not edit `node_modules` | Blocks Edit and Write under `node_modules` |
@@ -63,7 +65,7 @@ The PreToolUse hook blocks the call and tells Claude why, so Claude can fix it a
63
65
 
64
66
  The hook works out the target from the command itself. After `cd` or `git -C`, it checks against that repository (including its epic opt-in and `prose-lint.json`). After `git switch` or `git checkout`, it uses the new branch. Heredoc bodies are not parsed as commands.
65
67
 
66
- Commit messages are checked by `.githooks/commit-msg`, and edited files by prose-lint's PostToolUse hook. `.githooks/pre-push` runs `pnpm run --if-present check`, so a repository that defines a `check` script cannot push until it passes. It applies to people as well as Claude. When [Hostslot](https://github.com/ryusenkei-inc/hostslot) (`hostslot`) is on the `PATH` and the repository has a `check` script, the check runs through `hostslot run`, so pushes from parallel agents and repositories wait for free memory instead of exhausting it.
68
+ Commit messages are checked by `.githooks/commit-msg`, and edited files by prose-lint's PostToolUse hook. `.githooks/pre-push` runs `pnpm run --if-present check` without the repository variables git passes to hooks (`GIT_DIR`, `GIT_WORK_TREE`, `GIT_INDEX_FILE`, and the rest of `git rev-parse --local-env-vars`), so git commands in tests cannot write to the pushing repository. A repository that defines a `check` script cannot push until it passes. It applies to people as well as Claude. When [Hostslot](https://github.com/ryusenkei-inc/hostslot) (`hostslot`) is on the `PATH` and the repository has a `check` script, the check runs through `hostslot run`, so pushes from parallel agents and repositories wait for free memory instead of exhausting it.
67
69
 
68
70
  ### Epic flow
69
71
 
@@ -78,7 +80,7 @@ Opt in per repository in the root `package.json`:
78
80
  - 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).
79
81
  - `gh pr create` to `main` (`--base main`, or no `--base`) is blocked unless the head (`--head`, or the current branch) is `dev/*`.
80
82
  - 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.
83
+ - A `dev/*` → `main` PR is squashed like any other PR, so each deploy becomes one commit on `main`. The sub-issue commits stay in the merged sub-issue PRs. If the epic continues after a deploy, recreate `dev/*` from `main` and rebase the open sub-issue PRs onto it, as described in the `stacked-pr` skill.
82
84
  - 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.
83
85
  - Without the opt-in, none of this applies and `dev/*` branch names are rejected.
84
86
 
@@ -87,8 +89,9 @@ Opt in per repository in the root `package.json`:
87
89
  `sync` writes these files and `check` compares them, ignoring line endings:
88
90
 
89
91
  - `.editorconfig`, `.gitattributes`, `.gitignore`, `.gitleaks.toml`, `mise.toml`, `.github/dependabot.yaml`, `.githooks/commit-msg`, `.githooks/pre-push`
90
- - Skills in `.claude/skills/`: `stacked-pr` (cleaning up a stacked PR after its parent is squash-merged). Only these names are managed; other skills in the repository are kept
92
+ - Skills in `.claude/skills/`: `stacked-pr` (cleaning up a stacked PR after its parent is squash-merged, including sub-issue PRs after an epic's `dev/*` is squash-merged into `main`). Only these names are managed; other skills in the repository are kept
91
93
  - `.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`
94
+ - With `"ryusenkei": { "dependabot": false }` in the root `package.json`, `.github/dependabot.yaml` is not synced; `check` reports it if present and `sync` deletes it. Use this in private repositories to save GitHub Actions minutes, and update dependencies locally with `pnpm update`. Dependabot security updates are a separate repository setting
92
95
  - 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
93
96
  - `.claude/settings.json`: only the hooks, `attribution`, `permissions.deny`, and the writing plugins are managed. Other settings, hooks, and plugins are kept
94
97
  - 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`
@@ -105,8 +108,35 @@ Opt in per repository in the root `package.json`:
105
108
 
106
109
  When the `rules.md` import is present, `sync` adds the missing ones right after it.
107
110
 
111
+ `check` also reports a missing or incomplete root Vitest config when the root `package.json` depends on `vitest` (see [Vitest](#vitest)), and a root `package.json` without a `check` script, since the pre-push hook runs `pnpm check` and pushes unchecked without one. Add it by hand (for example `pnpm typecheck && pnpm test && pnpm lint:prose && ryusenkei-conventions check`).
112
+
108
113
  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.
109
114
 
115
+ ## Vitest
116
+
117
+ `TEST_EXCLUDE` is what every repository adds to Vitest's default `exclude`:
118
+
119
+ ```ts
120
+ // vitest.config.ts
121
+ import { TEST_EXCLUDE } from '@ryusenkei/conventions';
122
+ import { configDefaults, defineConfig } from 'vitest/config';
123
+
124
+ export default defineConfig({
125
+ test: {
126
+ exclude: [...configDefaults.exclude, ...TEST_EXCLUDE],
127
+ },
128
+ });
129
+ ```
130
+
131
+ | Pattern | Why |
132
+ | --- | --- |
133
+ | `.claude/**` | Agents' worktrees inside the repository would run the same tests twice |
134
+ | `**/.terraform/**` | `terraform init` downloads a Git module source as the whole repository (toolkit's tests included) into `.terraform/modules/` |
135
+
136
+ `check` reports a root `vitest.config.*` that neither uses `TEST_EXCLUDE` nor lists every pattern, and a repository that depends on `vitest` without one. It can't fix this by itself, since each repository's config differs. The shared `.gitignore` ignores `.terraform/` as well (`.terraform.lock.hcl` stays tracked).
137
+
138
+ `ryusenkei-conventions` exits with 0 when nothing drifts, 1 when something does, and 2 for a usage error; `--help` exits with 0.
139
+
110
140
  ## Dependency direction
111
141
 
112
142
  `runDepsCheck` checks imports in the sources and the dependencies in each `package.json` against the layer rules of the repository. Each repository keeps only its rules:
@@ -164,6 +194,29 @@ jobs:
164
194
  pnpm lint:deps
165
195
  ```
166
196
 
197
+ Go, with releases on `v*` tags:
198
+
199
+ ```yaml
200
+ # in .github/workflows/ci.yaml, next to the ci job
201
+ go:
202
+ uses: ryusenkei-inc/toolkit/.github/workflows/reusable-go.yaml@main
203
+ ```
204
+
205
+ ```yaml
206
+ # .github/workflows/release.yaml
207
+ name: Release
208
+ on:
209
+ push:
210
+ tags: ['v*']
211
+ permissions:
212
+ contents: write
213
+ jobs:
214
+ release:
215
+ uses: ryusenkei-inc/toolkit/.github/workflows/reusable-go-release.yaml@main
216
+ with:
217
+ checks: test "v$(node -p "require('./package.json').version")" = "$GITHUB_REF_NAME"
218
+ ```
219
+
167
220
  ```yaml
168
221
  # .github/workflows/pr-title.yaml
169
222
  name: PR title
@@ -185,9 +238,12 @@ jobs:
185
238
  | --- | --- |
186
239
  | `reusable-ci.yaml` | Checkout (full history), mise, pnpm, `pnpm install --frozen-lockfile`, `pnpm typecheck`, `pnpm test`, `pnpm lint:prose`, the `checks` input, the PR title with prose-lint's commit rules (not for Dependabot), and a gitleaks scan with `.gitleaks.toml` |
187
240
  | `reusable-pr-title.yaml` | Re-checks the PR title when it is edited, with the `@ryusenkei/prose-lint` version from `package.json` and no install |
241
+ | `reusable-go.yaml` | `go vet` and `go test` on each OS in `os` (Ubuntu, macOS, Windows by default), then `go build` for each `GOOS/GOARCH` in `targets` on Ubuntu. The Go version comes from `go.mod` |
242
+ | `reusable-go-release.yaml` | For a `v*` tag: `go test`, the `checks` input, then GoReleaser with the caller's `.goreleaser.yaml`. The caller grants `contents: write` |
188
243
 
189
244
  - `terraform`: space-separated directories to check with `terraform fmt -check` and `validate` (no backend, so no credentials). Terraform comes from the caller's `mise.toml`.
190
- - Language jobs (Go, Rust) stay in the calling workflow as extra jobs.
245
+ - Go uses `reusable-go.yaml` as a second job next to `ci`; on a private repository, set `os: '["ubuntu-latest"]'`, since macOS and Windows minutes count several times. Rust jobs stay in the calling workflow.
246
+ - npm license checks: add `pnpm exec ryusenkei-licenses` from `@ryusenkei/scripts` to `checks` (see its README).
191
247
  - PR title edits run in their own workflow. In the same workflow, the later `edited` run would overwrite the `ci` job's result with "skipped" and hide a failure.
192
248
  - `@main` follows toolkit's `main`, so fixes reach every repository at once. A breaking change gets a new file name instead of changing these.
193
249
 
@@ -196,3 +252,5 @@ jobs:
196
252
  - major: a rule is removed or reversed, or a synced file changes incompatibly
197
253
  - minor: a rule, a hook check, or a synced file is added
198
254
  - patch: fixes and wording
255
+
256
+ See the [CHANGELOG](CHANGELOG.md) for what each version changed.
package/dist/cli.js CHANGED
@@ -3,10 +3,24 @@
3
3
  // ryusenkei-conventions check マスタとの差分の検査(差分あり → 終了コード1)
4
4
  // ryusenkei-conventions sync [--stop] マスタに合わせて書き込み
5
5
  // --stop: 完了前の `pnpm lint`・`pnpm test` を Stop の hook に登録(省略時は現在の登録を維持)
6
+ // - 終了の状態: 差分なしは0、差分ありは1、使い方の誤りは2(`--help` は0)
6
7
  import { execFileSync } from 'node:child_process';
7
8
  import { parseArgs } from 'node:util';
8
9
  import { drifts, sync } from "./files.js";
9
- const { values, positionals } = parseArgs({ allowPositionals: true, options: { stop: { type: 'boolean' } } });
10
+ const USAGE = 'usage: ryusenkei-conventions <check|sync> [--stop]';
11
+ let parsed;
12
+ try {
13
+ parsed = parseArgs({ allowPositionals: true, options: { stop: { type: 'boolean' }, help: { type: 'boolean', short: 'h' } } });
14
+ }
15
+ catch (e) {
16
+ console.error(`${e instanceof Error ? e.message : String(e)}\n${USAGE}`);
17
+ process.exit(2);
18
+ }
19
+ const { values, positionals } = parsed;
20
+ if (values.help) {
21
+ console.log(USAGE);
22
+ process.exit(0);
23
+ }
10
24
  const root = execFileSync('git', ['rev-parse', '--show-toplevel'], { encoding: 'utf8' }).trim();
11
25
  const options = values.stop === undefined ? {} : { stop: values.stop };
12
26
  switch (positionals[0]) {
@@ -27,6 +41,6 @@ switch (positionals[0]) {
27
41
  break;
28
42
  }
29
43
  default:
30
- console.error('usage: ryusenkei-conventions <check|sync> [--stop]');
44
+ console.error(USAGE);
31
45
  process.exitCode = 2;
32
46
  }
package/dist/files.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  /** CLAUDE.md で共通の規約を読み込む import */
2
2
  export declare const IMPORT = "@node_modules/@ryusenkei/conventions/rules.md";
3
- /** 差分のあるファイル(`expected` が `undefined` = 自動で修正できない → `message` に対処) */
3
+ /** 差分のあるファイル(`expected` が `null` = 削除、`undefined` = 自動で修正できない → `message` に対処) */
4
4
  export type Drift = {
5
5
  path: string;
6
- expected?: string;
6
+ expected?: string | null;
7
7
  message: string;
8
8
  };
9
9
  /** マスタとの差分 */
package/dist/files.js CHANGED
@@ -2,9 +2,11 @@
2
2
  // - マスタ: パッケージの `files/`(npm は `.gitignore` を同梱しない → 先頭の `.` を除いた名前で格納)
3
3
  // - 比較は改行コードを LF に正規化(Windows の作業ツリーは CRLF になりうる)
4
4
  // - `append`: 条件のファイルがあるリポのみ、記載の順に末尾に追加(例: go.mod のないリポで gomod の更新はエラー)
5
- import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
5
+ // - `optOut`: `package.json` の `"ryusenkei"` のキーが `false` のリポでは配らず、残っていれば削除
6
+ import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
6
7
  import { dirname, join } from 'node:path';
7
8
  import { hasStop, managedSettings } from "./settings.js";
9
+ import { testExcludeProblem } from "./test-exclude.js";
8
10
  const FILES = [
9
11
  { from: 'editorconfig', to: '.editorconfig' },
10
12
  { from: 'gitattributes', to: '.gitattributes' },
@@ -18,6 +20,8 @@ const FILES = [
18
20
  { from: 'dependabot-gomod.yaml', if: 'go.mod' },
19
21
  { from: 'dependabot-cargo.yaml', if: 'Cargo.toml' },
20
22
  ],
23
+ // 非公開のリポで GitHub Actions の消費を抑える → 依存は手元でまとめて更新
24
+ optOut: 'dependabot',
21
25
  },
22
26
  { from: 'commit-msg', to: '.githooks/commit-msg', mode: 0o755 },
23
27
  { from: 'pre-push', to: '.githooks/pre-push', mode: 0o755 },
@@ -35,14 +39,16 @@ const LANG_RULES = [
35
39
  { file: 'rules-rust.md', if: (root) => existsSync(join(root, 'Cargo.toml')) },
36
40
  { file: 'rules-ui.md', if: (root) => uiOptIn(root) },
37
41
  ];
38
- function uiOptIn(root) {
42
+ /** ルートの `package.json` の `"ryusenkei"` の設定(読めない → 空) */
43
+ function config(root) {
39
44
  try {
40
- return JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')).ryusenkei?.ui === true;
45
+ return JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')).ryusenkei ?? {};
41
46
  }
42
47
  catch {
43
- return false;
48
+ return {};
44
49
  }
45
50
  }
51
+ const uiOptIn = (root) => config(root).ui === true;
46
52
  // `.github/dependabot.yaml` の `cooldown` と同値
47
53
  const RELEASE_AGE = [
48
54
  '# 公開から2日未満のバージョンは解決しない(`.github/dependabot.yaml` の `cooldown` と同値)',
@@ -56,7 +62,13 @@ const master = (name) => lf(readFileSync(new URL(`../files/${name}`, import.meta
56
62
  /** マスタとの差分 */
57
63
  export function drifts(root, options = {}) {
58
64
  const out = [];
65
+ const settingsOf = config(root);
59
66
  for (const f of FILES) {
67
+ if (f.optOut && settingsOf[f.optOut] === false) {
68
+ if (existsSync(join(root, f.to)))
69
+ out.push({ path: f.to, expected: null, message: `\`"${f.optOut}": false\` のため削除` });
70
+ continue;
71
+ }
60
72
  const appended = (f.append ?? []).filter((a) => existsSync(join(root, a.if))).map((a) => master(a.from));
61
73
  const expected = master(f.from) + appended.join('');
62
74
  if (read(join(root, f.to)) !== expected)
@@ -74,6 +86,18 @@ export function drifts(root, options = {}) {
74
86
  else
75
87
  out.push({ path: WORKSPACE, expected: `${workspace.trimEnd()}\n\n${RELEASE_AGE.join('\n')}\n`, message: '`minimumReleaseAge` が未設定' });
76
88
  }
89
+ // pre-push の関門は `pnpm check`(`check` がないと何も検査されずに push される)
90
+ let manifest = {};
91
+ try {
92
+ manifest = JSON.parse(read(join(root, 'package.json')) ?? '{}');
93
+ }
94
+ catch { }
95
+ if (typeof manifest.scripts?.check !== 'string')
96
+ out.push({ path: 'package.json', message: '`check` の script を追加(pre-push で動かす検査。型検査、テスト、lint など)' });
97
+ // Vitest の除外(作業用の worktree と、Terraform が取得したモジュールのテストを集めない)
98
+ const excludeProblem = testExcludeProblem(Object.keys({ ...manifest.dependencies, ...manifest.devDependencies }), (file) => read(join(root, file)));
99
+ if (excludeProblem)
100
+ out.push(excludeProblem);
77
101
  const claude = read(join(root, 'CLAUDE.md')) ?? '';
78
102
  const lines = claude.split('\n');
79
103
  const at = lines.findIndex((l) => l.trim() === IMPORT);
@@ -93,6 +117,10 @@ export function sync(root, options = {}) {
93
117
  continue;
94
118
  }
95
119
  const path = join(root, d.path);
120
+ if (d.expected === null) {
121
+ rmSync(path);
122
+ continue;
123
+ }
96
124
  mkdirSync(dirname(path), { recursive: true });
97
125
  writeFileSync(path, d.expected);
98
126
  const mode = FILES.find((f) => f.to === d.path)?.mode;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { drifts, sync, IMPORT, type Drift } from './files.ts';
2
2
  export { runDepsCheck } from './deps-check.ts';
3
3
  export type { Exception, Rule } from './deps.ts';
4
+ export { TEST_EXCLUDE } from './test-exclude.ts';
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export { drifts, sync, IMPORT } from "./files.js";
2
2
  export { runDepsCheck } from "./deps-check.js";
3
+ export { TEST_EXCLUDE } from "./test-exclude.js";
package/dist/policy.js CHANGED
@@ -234,20 +234,15 @@ function prReasons(sub, args, st, ctx) {
234
234
  return reasons;
235
235
  }
236
236
  // `--auto` も対象(必須のチェックがないリポでは即時にマージされる)
237
+ // - マージは常に squash(org のリポの設定が squash だけを許可。epic のフローの dev/* から main へも同じ)
237
238
  // - epic のフローの dev/* への PR: チェックなしを許可(CI を実行せず pre-push の `pnpm check` が関門)
238
- // - epic のフローの dev/* から main への PR: merge commit
239
- // squash すると sub-issue ごとのコミットが1つにまとまり、dev と main の履歴もずれる
240
239
  function mergeReasons(args, st, ctx) {
241
240
  const { cwd } = st;
242
241
  if (args.some((a) => a === '--rebase' || a === '-r'))
243
- return ['rebase でのマージは禁止(`--squash`、dev のブランチから main へは `--merge`)'];
242
+ return ['rebase でのマージは禁止(`--squash`)'];
243
+ if (args.some((a) => a === '--merge' || a === '-m'))
244
+ return ['マージは squash(`--squash`)。epic のフローの dev のブランチから main へも同じ'];
244
245
  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 だけ'];
251
246
  const checks = ctx.prChecks(pr, cwd);
252
247
  if (checks === 'pass')
253
248
  return [];
@@ -0,0 +1,11 @@
1
+ /** Vitest の既定の `exclude` に足すパターン */
2
+ export declare const TEST_EXCLUDE: readonly [".claude/**", "**/.terraform/**"];
3
+ /**
4
+ * ルートの Vitest の設定が除外を含むかの検査。問題がなければ `undefined`、あれば対処の文
5
+ * - `vitest` に依存しないリポは対象の外
6
+ * - 設定が `TEST_EXCLUDE` を使うか、すべてのパターンを書いていれば通す
7
+ */
8
+ export declare function testExcludeProblem(dependencies: readonly string[], read: (file: string) => string | undefined): {
9
+ path: string;
10
+ message: string;
11
+ } | undefined;
@@ -0,0 +1,22 @@
1
+ // Vitest の既定に足す除外(各リポの vitest.config で `[...configDefaults.exclude, ...TEST_EXCLUDE]` にする)
2
+ // - `.claude/**`: リポの中の作業用の worktree(同じテストを重複して集める)
3
+ // - `**/.terraform/**`: Terraform の作業のディレクトリ。git の Terraform のモジュールの取得で、toolkit などのリポ全体(テストを含む)が置かれる
4
+ /** Vitest の既定の `exclude` に足すパターン */
5
+ export const TEST_EXCLUDE = ['.claude/**', '**/.terraform/**'];
6
+ const CONFIG_FILES = ['vitest.config.ts', 'vitest.config.mts', 'vitest.config.js', 'vitest.config.mjs'];
7
+ /**
8
+ * ルートの Vitest の設定が除外を含むかの検査。問題がなければ `undefined`、あれば対処の文
9
+ * - `vitest` に依存しないリポは対象の外
10
+ * - 設定が `TEST_EXCLUDE` を使うか、すべてのパターンを書いていれば通す
11
+ */
12
+ export function testExcludeProblem(dependencies, read) {
13
+ if (!dependencies.includes('vitest'))
14
+ return undefined;
15
+ const found = CONFIG_FILES.map((file) => ({ file, text: read(file) })).find((c) => c.text !== undefined);
16
+ const usage = '`import { TEST_EXCLUDE } from \'@ryusenkei/conventions\'` を読み、`test.exclude` を `[...configDefaults.exclude, ...TEST_EXCLUDE]` にする';
17
+ if (!found)
18
+ return { path: 'vitest.config.ts', message: `Vitest の設定がない → ${usage}` };
19
+ if (found.text.includes('TEST_EXCLUDE') || TEST_EXCLUDE.every((p) => found.text.includes(p)))
20
+ return undefined;
21
+ return { path: found.file, message: `テストの除外(${TEST_EXCLUDE.map((p) => `\`${p}\``).join('・')})がない → ${usage}` };
22
+ }
package/files/gitignore CHANGED
@@ -11,6 +11,8 @@ coverage/
11
11
  *.tsbuildinfo
12
12
  .astro/
13
13
  .wrangler/
14
+ # Terraform の作業のディレクトリ(`.terraform.lock.hcl` は追跡する)
15
+ .terraform/
14
16
 
15
17
  # ---- 秘密値(コミット禁止。雛形の .env.example のみ追跡) ----
16
18
  .env
package/files/pre-push CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/bin/sh
2
2
  # push の前の検査(`check` のスクリプトを持つリポのみ。CI の失敗・Actions の消費を手元で防止)
3
+ # git がフックに渡す GIT_DIR などを外す(検査の中の git が push 元のリポを書き換えるのを防止)
4
+ unset $(git rev-parse --local-env-vars)
3
5
  # hostslot があれば資源の空きを待って実行(並行するエージェント・リポの重い検査によるメモリの枯渇を防止)
4
6
  # `check` のないリポは枠を待たない
5
7
  if grep -q '"check":' package.json 2>/dev/null && command -v hostslot >/dev/null 2>&1; then
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: stacked-pr
3
- description: 前の PR のブランチから作った PR(スタックした PR)を、前の PR のマージの後に整理する手順。親の PR を squash でマージした後、子の PR のベースの付け替え、rebase、親のブランチの削除をするときに使う
3
+ description: 前の PR のブランチから作った PR(スタックした PR)を、前の PR のマージの後に整理する手順。親の PR を squash でマージした後、子の PR のベースの付け替え、rebase、親のブランチの削除をするときに使う。epic のフローで dev のブランチを main へ squash でマージした後、epic を続けるときにも使う
4
4
  ---
5
5
 
6
6
  # スタックした PR の整理
@@ -56,3 +56,38 @@ description: 前の PR のブランチから作った PR(スタックした PR
56
56
 
57
57
  - 子の PR の差分に、子の変更だけが出ている(`gh pr diff <子の番号>`)
58
58
  - 子の PR の CI が通っている(`gh pr checks <子の番号> --watch`)
59
+
60
+ ## epic の dev のブランチを main へマージした後
61
+
62
+ epic のフローでは、デプロイのときに dev のブランチ(例: `dev/12-search`)を `main` へ squash でマージする。dev のブランチのコミットは `main` 上の1つのコミットになり、dev のブランチの履歴は `main` に残らない。epic がこれで終わるなら、追加の作業はない。デプロイの後も epic を続ける場合は、dev のブランチを親、開いている sub-issue の PR を子として、次を行う
63
+
64
+ 1. マージの前に、dev のブランチの先端のコミットを控える。手順4で `rebase --onto` の基準に使う
65
+
66
+ ```sh
67
+ git fetch origin
68
+ git rev-parse origin/dev/12-search
69
+ ```
70
+
71
+ 2. dev のブランチの PR を squash でマージする。リポの設定(マージの後にブランチを削除)で dev のブランチは消え、そこに向いていた sub-issue の PR のベースは GitHub が `main` に付け替える
72
+
73
+ ```sh
74
+ gh pr merge <dev の PR の番号> --squash
75
+ ```
76
+
77
+ 3. dev のブランチを最新の `main` から作り直して push する
78
+
79
+ ```sh
80
+ git fetch origin
81
+ git switch -C dev/12-search origin/main
82
+ git push -u origin dev/12-search
83
+ ```
84
+
85
+ 4. 開いている sub-issue の PR ごとに、ベースを dev のブランチに戻し、手順1のコミットより後のコミットだけを載せ直して push する。push していない手元の sub-issue のブランチも、同じ rebase で載せ直す
86
+
87
+ ```sh
88
+ gh pr edit <子の番号> --base dev/12-search
89
+ git rebase --onto origin/dev/12-search <手順1のコミット> feat/b
90
+ git push --force-with-lease origin feat/b
91
+ ```
92
+
93
+ 確認は上の「確認」と同じ。子の PR の差分に、すでに `main` に入った変更が出ていないことを見る
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ryusenkei/conventions",
3
- "version": "0.8.1",
3
+ "version": "0.9.0",
4
4
  "description": "RYUSENKEI のモノリポの共通の規約(Claude Code の規約・hook、共通ファイルの同期)",
5
5
  "license": "MIT",
6
6
  "author": "RYUSENKEI",
@@ -24,7 +24,8 @@
24
24
  "files": [
25
25
  "dist",
26
26
  "files",
27
- "rules*.md"
27
+ "rules*.md",
28
+ "CHANGELOG.md"
28
29
  ],
29
30
  "engines": {
30
31
  "node": ">=24"
package/rules-ts.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  - エントリポイントはパッケージごとの `src/index.ts`
4
4
  - TypeScript はビルドせず、Node で直接実行する(`node scripts/x.ts`)
5
- - テストは Vitest で書き、対象と同じディレクトリに `*.test.ts` を置く
6
- - 子プロセスは `@ryusenkei/scripts` の `exec` で起動する。Windows の `.cmd` に対応するため
5
+ - テストは Vitest で書き、対象と同じディレクトリに `*.test.ts` を置く。ルートの vitest.config の `test.exclude` は `[...configDefaults.exclude, ...TEST_EXCLUDE]`(`@ryusenkei/conventions`)
6
+ - 子プロセスは `@ryusenkei/scripts` の `execSync` などで起動する。Windows の `.cmd` に対応するため
7
7
  - 層の依存の向きは `scripts/lib/deps-rules.ts` に規則を書き、`@ryusenkei/conventions` の `runDepsCheck` で検査する(`pnpm lint` に含める)
8
8
 
9
9
  ## 定数
package/rules.md CHANGED
@@ -4,7 +4,9 @@
4
4
  - リポ内で共有するコードは `packages/*` に置く。リポをまたぐものは toolkit(npm の `@ryusenkei/*`)に置き、変更も toolkit で行う
5
5
  - エントリポイントでは外部で使うものだけを公開し、他パッケージのものを公開し直さない
6
6
  - テストは対象の近くに置く。言語ごとの置き方は `rules-ts.md`・`rules-go.md`・`rules-rust.md`
7
+ - テストで git を動かすときは、`GIT_DIR` などの git の環境変数を外す。フックから動くと、呼び出し元のリポを書き換える
7
8
  - 依存の更新は Dependabot の PR で行う。月1回で自動の rebase はしないので、マージの前に手で rebase する
9
+ - `package.json` に `"ryusenkei": { "dependabot": false }` を設定したリポでは、手元で `pnpm update` してまとめて更新する
8
10
 
9
11
  ## 設定と秘密値
10
12
 
@@ -54,15 +56,15 @@
54
56
  ## Git と PR
55
57
 
56
58
  - add は変更・追加したファイルをパスで指定する。一括の add はフックで止まる
57
- - push の前に `pnpm check` を通す。`check` を持つリポでは pre-push で強制される
59
+ - push の前に `pnpm check` を通す。pre-push で強制される(`check` の script はどのリポにも置く)
58
60
  - PR の本文は背景、変更、検証の順に書く
59
61
  - 前の PR のブランチから PR を重ねた場合は、親のマージの後にスキル `stacked-pr` の手順で整理する
60
62
  - マージは squash で、CI の全チェックの成功を確かめてから行う(フックで強制)
61
63
  - epic のフロー(有効にしたリポだけ)
62
64
  - epic ごとに `dev/<issue の番号>-<内容>` を作り、sub-issue の PR は dev のブランチに向ける
63
65
  - dev のブランチへのマージに CI は使わず、pre-push の `pnpm check` を関門にする。チェックがある場合は成功が必要
64
- - `main` へのマージは、デプロイのときに dev のブランチからだけ行う。方法は merge commit(`gh pr merge --merge`)で、sub-issue ごとのコミットを残し、dev と main の履歴をずらさない
65
- - リポの設定で merge commit を許可する(Settings → General → Allow merge commits)
66
+ - `main` へのマージは、デプロイのときに dev のブランチからだけ行う。方法はほかの PR と同じ squash で、sub-issue ごとのコミットは sub-issue の PR に残る
67
+ - デプロイの後も epic を続ける場合は、スキル `stacked-pr` の手順で dev のブランチを `main` から作り直し、開いている sub-issue の PR を載せ直す
66
68
 
67
69
  ## CI(GitHub Actions)
68
70