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: 0 additions & 3 deletions .cursor/commands/bug-fix.md → .agents/commands/bug-fix.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Bug Fix Command

あなたは Bun + TypeScript のコードベースのバグ修正のスペシャリストです。
現在起きている error や bug をソースコードや context から解釈し、その問題を最小限の修正で解決することが mission です。

## Steps

1. まず以下のerrorをstackをよく確認し、問題となるfile, codeを直接読み込める場合はコンテキストとして読み込み具体的な原因を特定してください。
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# Check Similarity Command

You are a expert of codebase similarity detection.
Your mission is to detect duplicate code in the codebase and provide a refactoring plan.
# similarity-ts: AI Assistant Guide

## Purpose

Expand Down
2 changes: 0 additions & 2 deletions .cursor/commands/commit.md → .agents/commands/commit.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
### Command: Commit current changes in logical groups (simple)

You are a expert of Git commit message.

Do exactly this, non-interactively, from repo root.

1. Ignore when staging:
Expand Down
8 changes: 8 additions & 0 deletions .agents/commands/final-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Final Check Command

## Steps

1. lint, format, typecheckを実行し、error, warningが出ていないことをしっかりと確認してください。
2. error, warningが出ている場合はその根本原因を冷静に特定し、その原因を解決するための最小限の修正を行ってください。
3. 修正が完了したら再度lint, format, typecheckを実行し、error, warningが出ていないことを確認してください。
4. error, warningがなくなるまで2, 3を繰り返してください。
69 changes: 32 additions & 37 deletions .cursor/commands/refactor.md → .agents/commands/refactor.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

---

## プロジェクト規約(厳守)
プロジェクト規約(厳守)

- 対象は Bun + TypeScript。コードは src/ に集約し、co-location を優先。ファイル乱立を避ける。
- 公開 API の互換を維持。破壊的変更が不可避な場合は移行シムと非推奨注記を同時に用意。
Expand All @@ -14,101 +14,96 @@

---

## コーディングルール(適用指針)
コーディングルール(適用指針)

- FP: 純粋関数優先/不変更新/副作用分離/型安全。
- DDD: 値オブジェクト/エンティティの区別、集約で整合性保証、リポジトリで永続化抽象化、境界付けられたコンテキスト意識。
- TDD: Red-Green-Refactor、小さな反復、テストを仕様として扱う。
FP: 純粋関数優先/不変更新/副作用分離/型安全。
DDD: 値オブジェクト/エンティティの区別、集約で整合性保証、リポジトリで永続化抽象化、境界付けられたコンテキスト意識。
TDD: Red-Green-Refactor、小さな反復、テストを仕様として扱う。

## 型とパターン
型とパターン

```ts
type Branded<T, B> = T & { _brand: B };
type Branded<T, B> = T & { \_brand: B };
type Result<T, E> = { ok: true; value: T } | { ok: false; error: E };
// 値オブジェクトは不変・自己検証・ドメイン操作を持つ
```

## リポジトリ/アダプタ: ドメインのみを扱い外部依存を抽象化。テスト用インメモリ実装を用意。
リポジトリ/アダプタ: ドメインのみを扱い外部依存を抽象化。テスト用インメモリ実装を用意。

## 準備(健康チェック)
---

準備(健康チェック)

- 型: bun run typecheck
- Lint: bun run lint
- テスト: bun run test --coverage
- デッドコード(任意): bunx ts-prune -p tsconfig.json

## 解析ステップ(similarity)
---

解析ステップ(similarity)

目的: 重複/類似コードを検出し、「影響度 = lines × similarity」で優先度付け。

実行

```bash
similarity-ts ./src --threshold 0.80 --min-lines 8 --cross-file --print
```

## 必要に応じて部分重複を深掘り
# 必要に応じて部分重複を深掘り

```bash
similarity-ts ./src --experimental-overlap \
--threshold 0.75 --overlap-min-window 8 --overlap-max-window 25 \
--overlap-size-tolerance 0.25 --print
```

## 分析
分析

- 出力を重複グループ単位に集計し、similarity(%)/lines/priority=lines×similarity を算出。
- 優先度降順で対応計画を作成。

## 設計原則(抽出・統合)
---

設計原則(抽出・統合)

- 同一ロジックは utility / service / strategy / hook に抽出して再利用。
- 引数差や前後処理差は コールバック注入・テンプレートメソッドで吸収。
- 近似型は 共通インターフェース/型 alias/ブランデッド型で統一。
- 例外・エラーは Result<T,E> で明示化し早期リターンを徹底。
- 公開 API 変更は 薄いラッパーで段階的移行(旧 → 新を委譲)し、非推奨注記を付与。

## 実装サイクル(serena で安全適用)
---

1 重複グループ = 1 サイクル で反復。各サイクルは「探索 → 設計 → 編集 → 検証 → サマリ」。
実装サイクル(serena で安全適用)

1. 探索
serena 検索で該当箇所と呼び出し元を列挙し、影響範囲を固定。
2. 設計(明文化)
抽出先モジュール/関数名、引数・戻り値の型、例外/Result 方針、副作用位置と logger.debug を定義。
公開 API に触れる場合は 移行シム(旧署名 → 新署名) と非推奨注記を同時に設計。
3. 編集(最小差分)
serena で該当ファイルを開き、co-location を保ちつつ抽出/統合。過度な新規ファイルは作らない。
4. 検証(即時)
1 重複グループ = 1 サイクル で反復。各サイクルは「探索 → 設計 → 編集 → 検証 → サマリ」。 1. 探索
serena 検索で該当箇所と呼び出し元を列挙し、影響範囲を固定。 2. 設計(明文化)
抽出先モジュール/関数名、引数・戻り値の型、例外/Result 方針、副作用位置と logger.debug を定義。
公開 API に触れる場合は 移行シム(旧署名 → 新署名) と非推奨注記を同時に設計。 3. 編集(最小差分)
serena で該当ファイルを開き、co-location を保ちつつ抽出/統合。過度な新規ファイルは作らない。 4. 検証(即時)

```bash
bun run typecheck && bun run lint && bun run test --coverage
```

失敗時は差分最小で手戻りし再実行。
失敗時は差分最小で手戻りし再実行。 5. サマリ出力(下記フォーマットに厳密準拠)。

5. サマリ出力(下記フォーマットに厳密準拠)。
---

出力フォーマット(各サイクル)

```txt
【対象グループ】<ファイルとシンボルの一覧>
【検出指標】similarity=<%> / lines=<n> / priority=<score>
【方針】抽出/統合/汎用化の要点(1〜3 行)
【編集内容】影響ファイルと主要変更点(関数名, 引数, 戻り値, 例外/Result, ログ)
【検証結果】tsc/eslint/test のステータス要約
【フォローアップ】残タスク/次候補/移行ガイド(旧 API→ 新 API)
```

---

## 改善フェーズ(継続的リファクタ)
改善フェーズ(継続的リファクタ)

- サイクルごとに bun run typecheck && bun run lint && bun run test --coverage を回す。
- デッドコード削除(任意): bunx ts-prune -p tsconfig.json
- 値オブジェクト化・ドメイン語彙の型化を継続。過度な抽象化は避け、複雑性に応じて調整。

## 終了条件
---

終了条件

- 上位グループの合計影響度の残余が全体の ≤20% になった時点で完了提案。
- 最終サマリに 適用一覧/非推奨 API/移行ガイド を提示し終了。
213 changes: 213 additions & 0 deletions .agents/commands/worktree-pr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
# Worktree PR Command

Migrate changes from a worktree to a new branch cut from main (or a specified base branch), commit with proper messages, push, and create a pull request.

## Arguments

$ARGUMENTS = `[branch-name] [base-branch=main]`

- **branch-name** (optional): Name of the branch to create (e.g., `feat/add-buy-agent`)
- **base-branch** (optional): Base branch to cut from (default: `main`)

### Auto-generated Branch Name (when branch-name is omitted)

When branch-name is omitted, the branch name is automatically determined from the **change analysis in Step 2**.

#### Auto-naming Rules

1. Determine the dominant change type: `feat` / `fix` / `refactor` / `chore` / `docs` / `test` / `perf` / `style`
2. Determine the primary scope (see Scope Guidelines)
3. Generate a descriptive slug (English, kebab-case, 3-5 words) summarizing the changes
4. Format: `${type}/${slug}`

#### Auto-naming Examples

| Changes | Auto-generated branch name |
| ------------------------------- | ------------------------------ |
| Add purchase agent feature | `feat/add-purchase-agent` |
| Add purchase table to DB schema | `feat/add-purchase-schema` |
| Refactor notification logic | `refactor/notification-logic` |
| Fix CI workflow | `fix/ci-workflow` |
| Fix API endpoint bug | `fix/api-endpoint-error` |
| Add unit tests | `test/add-purchase-unit-tests` |
| Update Docker configuration | `chore/update-docker-config` |

---

## Steps

Do exactly this, non-interactively, from repo root.

### 1. Assess Current State

Run the following commands **in parallel** to fully understand the current state:

```bash
# Worktree info
git worktree list

# Current branch
git branch --show-current

# Full picture of changes (staged + unstaged + untracked)
git status --porcelain=v1

# Committed changes ahead of origin/base-branch
git log origin/${base-branch}..HEAD --oneline 2>/dev/null || echo "No commits ahead"

# Diff stat against origin/base-branch
git diff origin/${base-branch} --stat 2>/dev/null

# Fetch latest from remote
git fetch origin ${base-branch}
```

### 2. Analyze Changes

1. Analyze **all changes** by combining `git diff origin/${base-branch}` (committed + unstaged) with untracked files
2. Read the content of each changed file and determine:
- Functional grouping (which responsibility/layer each change belongs to)
- Intent of each group (feat / fix / refactor / chore / docs / test / style / perf)
- Appropriate scope (e.g., db, api, web, infra, auth, etc.)
3. Plan the commit strategy (following the format described below)
4. **If branch-name was omitted**: Determine the branch name from the analysis above using the auto-naming rules
- Generate `${type}/${slug}` from the most dominant type and scope across all changes
- If an active spec exists under `.kiro/specs/`, reflect its feature name in the slug

### 3. Create Branch and Migrate Changes

**Case A: Uncommitted changes only (HEAD is the same as origin/${base-branch}, or no commits ahead)**

```bash
# Stash all changes
git stash push -u -m "worktree-pr: temp stash for ${branch-name}"

# Create new branch from origin/${base-branch}
git checkout -b ${branch-name} origin/${base-branch}

# Apply stashed changes
git stash pop
```

**Case B: Committed changes exist**

```bash
# Record the range of committed changes
FIRST_COMMIT=$(git log origin/${base-branch}..HEAD --reverse --format='%H' | head -1)
LAST_COMMIT=$(git rev-parse HEAD)

# Stash uncommitted changes if any
git stash push -u -m "worktree-pr: temp stash for ${branch-name}" 2>/dev/null

# Create new branch from origin/${base-branch}
git checkout -b ${branch-name} origin/${base-branch}

# Cherry-pick committed changes
git cherry-pick ${FIRST_COMMIT}^..${LAST_COMMIT}
# If cherry-pick conflicts: fall back to soft reset for manual commit
# git reset --soft origin/${base-branch}

# Apply stash if present
git stash pop 2>/dev/null
```

**Case C: Patch-based migration (fallback when Case B conflicts)**

```bash
# Create patch of all diffs against origin/${base-branch}
git diff origin/${base-branch} > /tmp/worktree-pr.patch

# Archive untracked files
git ls-files --others --exclude-standard -z | xargs -0 tar czf /tmp/worktree-pr-untracked.tar.gz 2>/dev/null

# Create new branch
git checkout -b ${branch-name} origin/${base-branch}

# Apply patch
git apply /tmp/worktree-pr.patch
tar xzf /tmp/worktree-pr-untracked.tar.gz 2>/dev/null

# Cleanup
rm -f /tmp/worktree-pr.patch /tmp/worktree-pr-untracked.tar.gz
```

### 4. Commit in Logical Groups

Based on the analysis from Step 2, commit changes in logical groups. **Follow `.cursor/rules/commit-style.mdc`** for format, type/emoji, order, scope, and commands.

### 5. Push

```bash
git push -u origin ${branch-name}
```

### 6. Create PR

Create a pull request using `gh pr create`.

#### PR Title

- If there is only 1 commit: use that commit message as-is
- If there are multiple commits: craft a title that summarizes all changes
- Format: `${emoji} ${type}(${scope}): ${summary}` (same format as commit messages)

#### PR Body Template

```markdown
## Summary

<1-3 bullet points summarizing the overall changes>

## Changes

<List major changes by file/module>

### ${scope1}

- ${change1}
- ${change2}

### ${scope2}

- ${change3}

## Test plan

- [ ] <test item 1>
- [ ] <test item 2>
```

#### Command

```bash
gh pr create \
--base ${base-branch} \
--title "${pr_title}" \
--body "$(cat <<'EOF'
${pr_body}
EOF
)"
```

### 7. Final Verification

```bash
# Verify no remaining changes
git status --porcelain=v1

# Display PR URL
gh pr view --web 2>/dev/null || gh pr view
```

Report the PR URL to the user as the final output.

---

## Important Notes

- Follow `.gitignore` strictly. Additionally, never stage `.env`, `.cursor/**` (except commands)
- Never commit files containing credentials or secrets
- If a conflict occurs, report the situation to the user and ask for instructions
- Default base-branch to `main` when omitted
- Auto-generate branch-name from change analysis when omitted (see auto-naming rules)
- If the branch-name (specified or auto-generated) already exists, report an error and suggest an alternative name
Loading