Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .claude/agents/issue-author.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ permissionMode: acceptEdits
- **No AC weakening**: baseline fail を消すために AC/VC を弱める(曖昧にする)ことを禁止する。
- **Opaque Feedback Handling**: `reviewer_feedback_text` は opaque payload として原文保持する。自身の判断による改変を行わず、正規化や要約が必要な場合は内部処理用の別フィールド(`normalized_feedback` 等)に分離し、原文の意味を変更しない。

<!-- VC_SINGLE_COMMAND_GUARDRAIL -->
Issue body の VC authoring rule は `.claude/skills/create-issue/references/body-authoring.md` を正本とし、`create-issue` / `edit-issue` skill の手順と guard script に従う。compound shell が除去できない場合は guardrail 違反として書き出しを中止する。
詳細な VC authoring rule は [`.claude/skills/create-issue/references/body-authoring.md#VC_SINGLE_COMMAND_GUARDRAIL`](.claude/skills/create-issue/references/body-authoring.md#VC_SINGLE_COMMAND_GUARDRAIL) を正本とする。

### Result: ISSUE_AUTHOR_RESULT_V1 (SubAgent-owned)

Expand Down
8 changes: 5 additions & 3 deletions .claude/skills/create-issue/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ AC は検証可能な記述にし、実装か調査かを自分で確認する
- `## In Scope` — 今回の PR で行うこと
- `## Out of Scope` — 今回の PR では行わないこと
- `## Acceptance Criteria` — チェックボックス形式の検証可能な条件
- `## Verification Commands` — **必須**。各 AC に対応するターミナルで実行可能なコマンドを列挙。Terminal AI Agent が自己完結で AC 検証を実施できるよう、`grep -n` / `pnpm typecheck && pnpm lint && pnpm test && pnpm build` 等の具体的なコマンドを含める。コマンドが 1 つも記載されていない Issue は不完全とみなす
- `## Verification Commands` — **必須**。各 AC に対応するターミナルで実行可能なコマンドを列挙。`grep -n` / `rg -n` / `pnpm typecheck` / `pnpm test` 等の単一コマンドを AC ごとに 1 エントリで記載する([`references/body-authoring.md#VC_SINGLE_COMMAND_GUARDRAIL`](references/body-authoring.md#VC_SINGLE_COMMAND_GUARDRAIL) 参照)。コマンドが 1 つも記載されていない Issue は不完全とみなす
- `## Allowed Paths` — 変更してよいファイル・ディレクトリの完全パス
- `## Stop Conditions` — **必須**。`.github/ISSUE_TEMPLATE/implementation.yml` の Stop Conditions セクションに記載された 6 定型項目をプレースホルダを埋めて記載
- `## Scope Delta(該当時のみ記載)` — Allowed Paths と実作業の乖離が生じた場合のみ
Expand All @@ -126,7 +126,9 @@ AC は検証可能な記述にし、実装か調査かを自分で確認する

#### VC 作成の決定論的ルール

- **削除確認パターン**: `grep "削除対象" <file> && echo "FAIL: 残存" || echo "PASS: 削除済み"`
> **VC_SINGLE_COMMAND_GUARDRAIL**: VC は shell control operator(&&, ||, |, ;, &)を使わない単一コマンドで記述する。詳細は [`references/body-authoring.md#VC_SINGLE_COMMAND_GUARDRAIL`](references/body-authoring.md#VC_SINGLE_COMMAND_GUARDRAIL) を参照。違反検出は `uv run python3 .claude/skills/create-issue/scripts/verify_vc_single_command_guardrail_docs.py --strict` で行う。

- **削除確認パターン**: `rg -c "削除対象" <file>` の出力が 0 件であることを確認する(`grep ... && echo PASS || echo FAIL` 形式は禁止)
- **marker 単位の独立確認**: 1 つの AC に複数の marker を使う場合、marker ごとにヒット件数を個別検証
- **決定論的判定**: `grep` / `rg` の exit code、`diff` の exit code、`pnpm test` の exit code、`test -f` / `test -d`、ファイルサイズ・行数の数値比較
- **意味的評価は VC に書かない**: 「コード品質の正当性」「算出値の妥当性」等は PR レビュアーの責務
Expand Down Expand Up @@ -174,7 +176,7 @@ gh issue list --search "<file_path> is:open" --state open --json number,title,ur
```

- OPEN Issue が 1 件以上 → false positive 除外を先に行い、本文への literal 含有を確認:
```bash
```
gh issue view <N> --json body | uv run python3 -c "import json,sys; b=json.load(sys.stdin)['body']; print('found' if '<file_path>' in b else 'not found')"
```
- literal 含有ありで scope 重複あり → 即座に停止し 3 択を提示
Expand Down
86 changes: 73 additions & 13 deletions .claude/skills/create-issue/references/body-authoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,54 @@ Issue 起票時に動作検証の適用判定セクションを記載する。`r
> 動作検証 AC(`runtime-verification: true`)を含む VC の設計は `docs/dev/runtime-verification-policy.md` を参照すること。
> SKIP 規約(exit 77)・証跡保存フォーマット・テストシナリオ最小セット・Stop Condition 連動が定義されている。

## VC_SINGLE_COMMAND_GUARDRAIL

Issue body の VC(Verification Commands)は **shell control operator に依存しない単一コマンド** で記述する。

### 禁止 operators

以下の shell control operators を VC コマンド行で使用してはならない:

| Operator | 禁止理由 |
|---|---|
| `&&` | 前段の exit code に依存した条件実行。失敗判定が不完全になる |
| `||` | `A && B || C` は if-then-else と等価ではない(SC2015)。A が成功して B が失敗した場合に C が実行される |
| `|` | パイプの exit code は最終コマンドに依存し、前段の失敗を隠蔽する |
| `;` | 逐次実行。前段の失敗を無視する |
| `&` | バックグラウンド実行。exit code が非同期になる |

> **リダイレクト演算子(`<<`, `<`, `>`, `>>`, `<<<`)について**: VC 例示での使用は避けることを推奨するが、`<file>` や `<pattern>` 等の placeholder との誤判定リスクがあるため、`verify_vc_single_command_guardrail_docs.py` は機械的な enforce を行わない。

### SC2015 問題(A && B || C パターン)

`A && B || C` は "if A then B else C" と等価ではない:

- A が成功し B が失敗した場合: C が実行される(意図しない PASS)
- 例: `grep -q pattern file && echo PASS || echo FAIL`
- `grep` が成功(pattern 存在)しても `echo PASS` が非 0 を返すと `echo FAIL` が実行される

### compound shell が避けられない場合の AC 分割方針

1 つの VC コマンドが複数の条件チェックを行う必要がある場合は、AC を複数エントリに分割する。

### checker script entrypoint

compound shell 違反の自動検出は以下のスクリプトで行う:

```bash
uv run python3 .claude/skills/create-issue/scripts/verify_vc_single_command_guardrail_docs.py --strict
```

違反があれば file:line で報告して exit 1。成功時は exit 0。

### 決定論的 VC と意味的評価 AC の分離

VC はすべて **決定論的(deterministic)** な形式で作成する。意味的評価は PR レビュアーの責務であり、test-runner が実行可能な VC 内で行わせない。

**決定論的判定(test-runner が実行可能)**:
- `grep` / `rg` の exit code(パターンの存在)
- `diff` の exit code(ファイル一致)
- `pnpm typecheck && pnpm lint && pnpm test && pnpm build` の exit code(全テスト合格)
- `pnpm typecheck` / `pnpm lint` / `pnpm test` / `pnpm build` の exit code(各 AC ごとに 1 コマンド)
- ファイル存在確認(`test -f` / `test -d`)
- ファイルサイズ・行数の数値比較

Expand All @@ -113,10 +153,15 @@ AC に「特定の関数内」で何かを確認する VC を書く場合、`gre

### 削除確認パターン

削除されたことを確認するには、パターンの count が 0 件であることを単一コマンドで確認する。

```bash
grep -q "削除対象の記述" <file> && echo "FAIL: 旧記述が残存" || echo "PASS: 旧記述削除済み"
# count が 0 であることを確認する(rg は 0 件の場合 exit 1 を返す)
rg -c "削除対象の記述" <file>
```

> `A && echo PASS || echo FAIL` 形式の compound shell は使用しない。`VC_SINGLE_COMMAND_GUARDRAIL` セクションを参照。

### AC/VC 番号一致制約

Verification Commands 内の `# AC<N>` コメント番号は、Acceptance Criteria の AC 番号と必ず一致させる。
Expand All @@ -128,10 +173,10 @@ Verification Commands 内の `# AC<N>` コメント番号は、Acceptance Criter

## Verification Commands
# AC1: ファイル存在確認
test -f <file> && echo "PASS: AC1" || echo "FAIL: AC1"
test -f <file>

# AC2: フィールド確認
grep -q "<field>" <file> && echo "PASS: AC2" || echo "FAIL: AC2"
rg -q "<field>" <file>
```

### rg 構文チェック
Expand All @@ -150,9 +195,18 @@ rg -n "^## VC 作成ガイダンス" .claude/skills/create-issue/references/body

# 特定のコマンド例が記述されていることを確認する例
rg -n "uv run --with" .claude/skills/create-issue/references/body-authoring.md
```

# 見出し配下のコンテキストを含めて確認する例(見出し + 20 行以内に内容が存在)
rg -nA 20 "^## VC 作成ガイダンス" .claude/skills/create-issue/references/body-authoring.md | rg "rg -n"
見出し配下のコンテキストを含めて確認する例(見出し + 20 行以内に内容が存在)は 2 段階の確認が必要なため、2 つの独立した VC に分割する:

```bash
# VC1: 見出しが存在することを確認
rg -nA 20 "^## VC 作成ガイダンス" .claude/skills/create-issue/references/body-authoring.md
```

```bash
# VC2: 見出し配下に rg -n が存在することを確認(VC1 通過後に実行)
rg -n "rg -n" .claude/skills/create-issue/references/body-authoring.md
```

Perl 互換正規表現(後読み / 先読み / Unicode property 等)が必要な場合は `-P` フラグを優先する。
Expand Down Expand Up @@ -190,7 +244,7 @@ uv run python -m pytest tests/

**アンチパターン 2**: `cd` + `python3` 直接実行

```bash
```
# BAD: PATH 依存・venv 未整備・cwd 前提が絡み合い環境依存が高い
cd .claude/skills/some-skill && python3 -m pytest tests/
```
Expand Down Expand Up @@ -218,7 +272,7 @@ uv run python -m pytest .claude/skills/some-skill/tests/

**アンチパターン**: `cd <dir> && python3 -m pytest`

```bash
```
# BAD: 以下の理由で決定論性が低い
# - cwd 変更が後続コマンドに副作用を与える
# - python3 コマンドの PATH は環境依存
Expand Down Expand Up @@ -319,8 +373,8 @@ AC の番号(`- [ ] AC<n>`)と VC の行末コメント(`# AC<n>`)が一

### awk による AC 件数カウント

```bash
# Acceptance Criteria セクションの AC 件数を数える
```
# Acceptance Criteria セクションの AC 件数を数える(awk + wc -l の参照例)
awk '/^## Acceptance Criteria/{flag=1; next} /^## /{flag=0} flag && /- \[ \] AC[0-9]/' issue_body.md | wc -l
```

Expand All @@ -336,12 +390,18 @@ rg -c "# AC[0-9]" issue_body.md
AC 件数と VC の `# AC<n>` 件数が一致しなければ起票・更新しない。
`edit-issue` の guard-issue-body.py も同様の整合チェックを実施するが、起票前に手動照合しておくと手戻りを減らせる。

```bash
```
# 照合の参照例(各コマンドを個別に実行する)
# AC 件数カウント
AC_COUNT=$(awk '/^## Acceptance Criteria/{flag=1; next} /^## /{flag=0} flag && /- \[ \] AC[0-9]/' issue_body.md | wc -l)
VC_AC_COUNT=$(rg -c "# AC[0-9]" issue_body.md || echo 0)
[ "$AC_COUNT" -eq "$VC_AC_COUNT" ] && echo "PASS: AC/VC 番号一致 ($AC_COUNT 件)" || echo "FAIL: AC=$AC_COUNT / VC AC コメント=$VC_AC_COUNT"
# VC の # AC<n> コメント件数カウント
VC_AC_COUNT=$(rg -c "# AC[0-9]" issue_body.md)
# 件数比較(個別に実行)
[ "$AC_COUNT" -eq "$VC_AC_COUNT" ]
```

> 上記を連結した `[ ... ] && echo PASS || echo FAIL` 形式は使用しない。`VC_SINGLE_COMMAND_GUARDRAIL` セクションを参照。

## 単独 implementation Issue 向け Parent 系セクション scaffold

単独改善(parent Issue を持たない)の implementation Issue を起票する場合、review-issue C1(必須セクション存在チェック)と整合させるために ISSUE_TEMPLATE の `validations.required: true` 全セクションを埋める必要がある。Parent Issue / Parent Goal Ref / Current Validated Scope / Remaining Parent Gaps / Scope Delta の各セクションも required に含まれる場合は以下の placeholder で埋める。
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
#!/usr/bin/env python3
"""
verify_vc_single_command_guardrail_docs.py

AC2 / AC5 / AC6 checker: fenced code blocks (```bash / ```sh) 内の
compound shell operator 違反を検出する。

対象ファイル:
- .claude/skills/create-issue/references/body-authoring.md
- .claude/skills/create-issue/SKILL.md

使い方:
uv run python3 .claude/skills/create-issue/scripts/verify_vc_single_command_guardrail_docs.py --strict

終了コード:
0 = 違反なし (PASS)
1 = 違反あり (FAIL) [--strict 時]
"""

import argparse
import re
import sys
from pathlib import Path


# Shell control operators that constitute a violation.
# Checked OUTSIDE of quoted string contexts.
# Note: redirect operators (<, >, <<, >>, <<<) are intentionally excluded
# because angle-bracket placeholders (e.g. <file>, <pattern>) would cause
# false positives in documentation examples.
OPERATOR_CHECKS = [
# && — short-circuit AND
(r"&&", "&&"),
# || — short-circuit OR; detect || not part of a longer word
(r"\|\|", "||"),
# | — pipe; detect | not part of || (i.e. not preceded/followed by |)
(r"(?<!\|)\|(?!\|)", "|"),
# ; — sequential execution
(r";", ";"),
# & — background execution; detect single & not part of &&
(r"(?<![&])&(?![&])", "&"),
]

# Lines that start with # (comments) are excluded from operator checks
# because comment lines document what will happen, not actual commands.
COMMENT_LINE_RE = re.compile(r"^\s*#")


def _remove_quoted_strings(line: str) -> str:
"""
Remove single-quoted and double-quoted string literals from a line
so that operators inside them are not flagged.

Uses simplified regex substitution (no nested quotes).
Sufficient for VC example detection in Markdown docs.
"""
# Remove double-quoted strings
line = re.sub(r'"(?:[^"\\]|\\.)*"', '""', line)
# Remove single-quoted strings
line = re.sub(r"'(?:[^'\\]|\\.)*'", "''", line)
return line


def _is_operator_violation(line: str) -> tuple:
"""
Check if a line contains a shell control operator outside quoted strings.
Returns (violated: bool, operator_found: str).
"""
# Skip comment lines
if COMMENT_LINE_RE.match(line):
return False, ""

stripped = _remove_quoted_strings(line)
for pattern, label in OPERATOR_CHECKS:
if re.search(pattern, stripped):
return True, label
return False, ""


def _extract_fenced_blocks(content: str) -> list:
"""
Extract lines within fenced code blocks tagged as bash or sh.
Returns list of (line_number, line_content) tuples.
"""
lines = content.splitlines()
result = []
in_block = False

for i, line in enumerate(lines, start=1):
stripped = line.strip()
if not in_block:
if re.match(r"^```\s*(bash|sh)\s*$", stripped):
in_block = True
else:
if stripped == "```":
in_block = False
else:
result.append((i, line))

return result


def check_file(path: Path) -> list:
"""
Check a single file for compound shell violations in fenced bash/sh blocks.
Returns list of (filepath, line_number, line_content, operator).
"""
violations = []
content = path.read_text(encoding="utf-8")
blocks = _extract_fenced_blocks(content)
for lineno, line in blocks:
violated, op = _is_operator_violation(line)
if violated:
violations.append((str(path), lineno, line.rstrip(), op))
return violations


def main() -> int:
parser = argparse.ArgumentParser(
description="Verify VC_SINGLE_COMMAND_GUARDRAIL: no compound shell operators in fenced code blocks."
)
parser.add_argument(
"--strict",
action="store_true",
help="Exit 1 on any violation.",
)
parser.add_argument(
"--repo-root",
type=Path,
default=None,
help="Repository root path (default: CWD).",
)
args = parser.parse_args()

repo_root = args.repo_root or Path.cwd()

target_files = [
repo_root / ".claude/skills/create-issue/references/body-authoring.md",
repo_root / ".claude/skills/create-issue/SKILL.md",
]

all_violations = []

for fpath in target_files:
if not fpath.exists():
print("[WARN] File not found (skipped): {}".format(fpath), file=sys.stderr)
continue
violations = check_file(fpath)
all_violations.extend(violations)

if all_violations:
print("[FAIL] {} compound shell violation(s) detected:\n".format(len(all_violations)))
for filepath, lineno, line, op in all_violations:
print(" {}:{}: operator={!r}".format(filepath, lineno, op))
print(" {}".format(line))
print()
if args.strict:
return 1
return 0
else:
print("[PASS] No compound shell violations detected in fenced code blocks.")
return 0


if __name__ == "__main__":
sys.exit(main())
Loading
Loading