|
1 | 1 | # AGENTS.md |
2 | 2 |
|
3 | | -このリポジトリで作業する AI エージェント向けのガイド。リポジトリ固有のハマりどころを集約する。 |
4 | | - |
5 | | -## シェル / 実行環境 |
6 | | - |
7 | | -- **デフォルトシェルは zsh**(エージェントの Bash ツールも zsh で動く)。スクリプト内で |
8 | | - `status` を変数名に使わないこと — zsh では `status` は読み取り専用で `read-only variable` |
9 | | - エラーになる。`st` などに置き換える。 |
10 | | -- `jq` のフィルタで `!=` を使うと zsh が `\!=` にエスケープしてパースエラーになる。 |
11 | | - `select(.x | . == null | not)` のように `| not` パターンで書く。 |
12 | | - |
13 | | -## シェルスクリプトの構文チェック / lint |
14 | | - |
15 | | -- `env.sh` と `env.d/**/*.sh` は **shebang を持たない**。シェル起動時に source される断片で、 |
16 | | - bash/zsh 構文(関数定義・`[[ ]]` 等)を含む。したがって `sh -n`(dash)では誤検知する。 |
17 | | - これらは `bash -n` で検査する。 |
18 | | -- CI(`.github/workflows/ci.yml` の lint ジョブ)は追跡対象の全 `*.sh` を `git ls-files` で |
19 | | - 列挙し、shebang で判定する: `*bash*` → `bash -n`、`#!...sh` → `sh -n`、**shebang なし → |
20 | | - `bash -n`**(上記の source 断片のため)。 |
21 | | - |
22 | | -## *env(言語ランタイム) |
23 | | - |
24 | | -- バージョンのピン留めは `setup.d/ubuntu/00X-*.sh` の `VERSION=` に一元化されている |
25 | | - (nodenv=002 / rbenv=003 / pyenv=004 / goenv=005)。変更はこのファイルだけを書き換える。 |
26 | | -- CI はインストール結果がこのピン留め値と一致するかをアサートする(不一致で fail)。期待値は |
27 | | - 各 setup スクリプトの `VERSION=` から抽出するのでハードコードしない。 |
28 | | -- **バージョン検証時は shims を PATH 先頭に置くこと。** `rbenv init -` / `goenv init -` は |
29 | | - shims を PATH 先頭に入れない実装があり、ランナー同梱の system ruby/go が優先されてしまう。 |
30 | | - `export PATH="$HOME/.rbenv/shims:$HOME/.goenv/shims:...:$PATH"` のように明示する |
31 | | - (nodenv/pyenv は `init -` だけで効く)。 |
32 | | -- リポジトリ更新は `git clone` 以外(パッケージ・手動展開・symlink)で配置された場合に備え、 |
33 | | - `[ -d ~/.Xenv/.git ]` ガードで囲み `git pull --ff-only`(意図しない merge を作らない)。 |
| 3 | +Guide for AI agents working in this repository. It collects repo-specific |
| 4 | +gotchas. |
| 5 | + |
| 6 | +## Shell / execution environment |
| 7 | + |
| 8 | +- **The default shell is zsh** (the agent's Bash tool runs under zsh too). Do not |
| 9 | + use `status` as a variable name in scripts — in zsh `status` is read-only and |
| 10 | + assigning to it raises a `read-only variable` error. Use `st` or similar. |
| 11 | +- Using `!=` in a `jq` filter gets escaped by zsh to `\!=` and causes a parse |
| 12 | + error. Write it with the `| not` pattern, e.g. `select(.x | . == null | not)`. |
| 13 | + |
| 14 | +## Shell script syntax checking / linting |
| 15 | + |
| 16 | +- `env.sh` and `env.d/**/*.sh` have **no shebang**. They are fragments sourced at |
| 17 | + shell startup and contain bash/zsh syntax (function definitions, `[[ ]]`, etc.), |
| 18 | + so `sh -n` (dash) false-flags them. Check these with `bash -n`. |
| 19 | +- CI (the lint job in `.github/workflows/ci.yml`) enumerates every tracked `*.sh` |
| 20 | + via `git ls-files` and decides the interpreter from the shebang: `*bash*` → |
| 21 | + `bash -n`, `#!...sh` → `sh -n`, **no shebang → `bash -n`** (for the sourced |
| 22 | + fragments above). |
| 23 | + |
| 24 | +## *env (language runtimes) |
| 25 | + |
| 26 | +- Version pins are centralized in the `VERSION=` line of each |
| 27 | + `setup.d/ubuntu/00X-*.sh` (nodenv=002 / rbenv=003 / pyenv=004 / goenv=005). |
| 28 | + Change only that file. |
| 29 | +- CI asserts that the installed result matches this pin (and fails on mismatch). |
| 30 | + The expected value is extracted from each setup script's `VERSION=` line, so do |
| 31 | + not hardcode it. |
| 32 | +- **When verifying versions, run from a neutral directory and don't rely on |
| 33 | + PATH/shims.** `rbenv init -` / `goenv init -` may not prepend shims to PATH, so |
| 34 | + the runner's system ruby/go can win. Also, *env honors a directory-local pin |
| 35 | + (e.g. `.ruby-version`) over the global one — and this repo's root has |
| 36 | + `.ruby-version = system`. CI therefore runs `*env exec` from `$HOME` to check |
| 37 | + the global version that setup installed. |
| 38 | +- For repo updates, guard with `[ -d ~/.Xenv/.git ]` and use `git pull --ff-only` |
| 39 | + so a non-git install (package / manual extraction / symlink) doesn't break and |
| 40 | + no unintended merge commit is created. |
34 | 41 |
|
35 | 42 | ## GnuPG |
36 | 43 |
|
37 | | -- `~/.gnupg` は `rc.d/gnupg` への symlink。`gpg-agent.conf` は **生成物で gitignore 対象**。 |
38 | | - ソースは `rc.d/gnupg/gpg-agent.conf.linux` / `.darwin` で、`setup.d/dotfiles.sh` が |
39 | | - プラットフォーム別にコピー生成する。設定変更は生成物ではなく `.linux` / `.darwin` を編集する。 |
40 | | - キャッシュ TTL は 1 年(一度 unlock すれば保持)。 |
41 | | -- コミットは GPG 署名される(鍵 `036459B1`)。エージェントの非 tty シェルでは対話的 pinentry が |
42 | | - 動かずコミットがハングする。**セッション開始時に一度ユーザーが** |
43 | | - `echo | gpg --clearsign -u 036459B1 -o /dev/null` を実行してパスフレーズを agent に |
44 | | - キャッシュさせてから、コミット系の作業を進める。 |
| 44 | +- `~/.gnupg` is a symlink to `rc.d/gnupg`. `gpg-agent.conf` is a **generated file |
| 45 | + and is gitignored**. Its sources are `rc.d/gnupg/gpg-agent.conf.linux` / |
| 46 | + `.darwin`, which `setup.d/dotfiles.sh` copies into place per platform. Edit the |
| 47 | + `.linux` / `.darwin` sources, not the generated file. The cache TTL is one year |
| 48 | + (unlock once and it stays cached). |
| 49 | +- Commits are GPG-signed (key `036459B1`). The agent's non-tty shell can't run an |
| 50 | + interactive pinentry, so a commit would hang. **At the start of a session, have |
| 51 | + the user run** `echo | gpg --clearsign -u 036459B1 -o /dev/null` **once** to |
| 52 | + cache the passphrase in the agent before doing any commit work. |
45 | 53 |
|
46 | | -## dotfiles の symlink 規約 |
| 54 | +## dotfiles symlink conventions |
47 | 55 |
|
48 | | -- プラットフォーム固有ファイルは `*.darwin` / `*.linux` サフィックスで管理し、 |
49 | | - `setup.d/dotfiles.sh` の `resolve_os_name` が OS に応じて実体名へ解決する。 |
50 | | -- push は必ず `git push origin <current-branch>`(bare push 禁止)。 |
| 56 | +- Platform-specific files are managed with a `*.darwin` / `*.linux` suffix; |
| 57 | + `resolve_os_name` in `setup.d/dotfiles.sh` resolves them to the real name per OS. |
| 58 | +- Always push with `git push origin <current-branch>` (no bare push). |
51 | 59 |
|
52 | | -## このファイルと CLAUDE.md |
| 60 | +## This file and CLAUDE.md |
53 | 61 |
|
54 | | -- `CLAUDE.md` はこの `AGENTS.md` への symlink。内容は AGENTS.md 側を編集する。 |
| 62 | +- `CLAUDE.md` is a symlink to this `AGENTS.md`. Edit the content on the AGENTS.md |
| 63 | + side. |
0 commit comments