Skip to main content

ワークフロー

ワークフローでは、サービスのデプロイやPRの提出など、反復的なタスクセットを通じて Caret をガイドする一連のステップを定義できます。

ワークフローを呼び出すには、チャットで /[workflow-name.md] と入力します。

ワークフローの作成と使用方法

ワークフローは Caret Rules と並んで存在します。作成は簡単です:

Caret のワークフロータブ
  1. Caret が実行すべきステップの明確な指示を含むマークダウンファイルを作成
  2. ワークフローディレクトリに .md 拡張子で保存
  3. ワークフローをトリガーするには、ワークフローファイル名に続けて / と入力
  4. プロンプトが表示されたら必要なパラメータを提供

真の力は、ワークフローファイルの構造化方法から生まれます。以下が可能です:

  • ask_followup_questionread_filesearch_filesnew_task などの Caret の 組み込みツール を活用
  • 既にインストールされている ghdocker などのコマンドラインツールを使用
  • Slack や Whatsapp などの外部 MCP ツール呼び出し を参照
  • 複数のアクションを特定のシーケンスで連鎖

実世界の例

すでに大幅な時間節約になっている PR レビューワークフローを作成しました。

You have access to the `gh` terminal command. I already authenticated it for you. Please review it to use the PR that I asked you to review. You're already in the `caret` repo.

<detailed_sequence_of_steps>

# GitHub PR Review Process - Detailed Sequence of Steps

## 1. Gather PR Information

1. Get the PR title, description, and comments:

```bash
gh pr view <PR-number> --json title,body,comments
```

2. Get the full diff of the PR:
```bash
gh pr diff <PR-number>
```

## 2. Understand the Context

1. Identify which files were modified in the PR:

```bash
gh pr view <PR-number> --json files
```

2. Examine the original files in the main branch to understand the context:

```xml
<read_file>
<path>path/to/file</path>
</read_file>
```

3. For specific sections of a file, you can use search_files:
```xml
<search_files>
<path>path/to/directory</path>
<regex>search term</regex>
<file_pattern>*.ts</file_pattern>
</search_files>
```

## 3. Analyze the Changes

1. For each modified file, understand:

- What was changed
- Why it was changed (based on PR description)
- How it affects the codebase
- Potential side effects

2. Look for:
- Code quality issues
- Potential bugs
- Performance implications
- Security concerns
- Test coverage

## 4. Ask for User Confirmation

1. Before making a decision, ask the user if you should approve the PR, providing your assessment and justification:

```xml
<ask_followup_question>
<question>Based on my review of PR #<PR-number>, I recommend [approving/requesting changes]. Here's my justification:

[Detailed justification with key points about the PR quality, implementation, and any concerns]

Would you like me to proceed with this recommendation?</question>
<options>["Yes, approve the PR", "Yes, request changes", "No, I'd like to discuss further"]</options>
</ask_followup_question>
```

## 5. Ask if User Wants a Comment Drafted

1. After the user decides on approval/rejection, ask if they would like a comment drafted:

```xml
<ask_followup_question>
<question>Would you like me to draft a comment for this PR that you can copy and paste?</question>
<options>["Yes, please draft a comment", "No, I'll handle the comment myself"]</options>
</ask_followup_question>
```

2. If the user wants a comment drafted, provide a well-structured comment they can copy:

```
Thank you for this PR! Here's my assessment:

[Detailed assessment with key points about the PR quality, implementation, and any suggestions]

[Include specific feedback on code quality, functionality, and testing]
```

## 6. Make a Decision

1. Approve the PR if it meets quality standards:

```bash
# For single-line comments:
gh pr review <PR-number> --approve --body "Your approval message"

# For multi-line comments with proper whitespace formatting:
cat << EOF | gh pr review <PR-number> --approve --body-file -
Thanks @username for this PR! The implementation looks good.

I particularly like how you've handled X and Y.

Great work!
EOF
```

2. Request changes if improvements are needed:

```bash
# For single-line comments:
gh pr review <PR-number> --request-changes --body "Your feedback message"

# For multi-line comments with proper whitespace formatting:
cat << EOF | gh pr review <PR-number> --request-changes --body-file -
Thanks @username for this PR!

The implementation looks promising, but there are a few things to address:

1. Issue one
2. Issue two

Please make these changes and we can merge this.
EOF
```

Note: The `cat << EOF | ... --body-file -` approach preserves all whitespace and formatting without requiring temporary files. The `-` parameter tells the command to read from standard input.
</detailed_sequence_of_steps>

<example_review_process>

# Example PR Review Process

Let's walk through a real example of reviewing PR #3627 which fixes the thinking mode calculation for Claude 3.7 models.

## Step 1: Gather PR Information

```bash
# Get PR details
gh pr view 3627 --json title,body,comments

# Get the full diff
gh pr diff 3627
```

## Step 2: Understand the Context

```xml
# Examine the original files to understand what's being changed
<read_file>
<path>src/shared/api.ts</path>
</read_file>

# Look at the ThinkingBudgetSlider component implementation
<read_file>
<path>webview-ui/src/components/settings/ThinkingBudgetSlider.tsx</path>
</read_file>

# Check how thinking mode is currently handled in API providers
<search_files>
<path>src/api/providers</path>
<regex>reasoningOn</regex>
<file_pattern>*.ts</file_pattern>
</search_files>
```

## Step 3: Analyze the Changes

From the PR information and code examination, we can see that:

1. The PR fixes an issue with the thinking mode budget calculation for Claude 3.7 models
2. Currently, the thinking budget is incorrectly calculated as 80% of maxTokens (8192), resulting in 6553 tokens
3. Claude 3.7 actually supports a much larger thinking budget (up to 64000 tokens)
4. The PR adds a `thinkingConfig` property with `maxBudget: 64000` to model definitions
5. It updates API handlers to use this value when reasoning mode is enabled
6. It enhances the slider component to calculate max values based on model-specific percentages
7. Comprehensive tests were added to verify the calculations

## Step 4: Ask for User Confirmation

```xml
<ask_followup_question>
<question>Based on my review of PR #3627, I recommend approving this PR. Here's my justification:

1. The PR correctly fixes the thinking mode budget calculation for Claude 3.7 models
2. It properly implements the thinkingConfig.maxBudget property (64000) for Claude 3.7 models
3. It applies the appropriate percentage (50%) for the slider calculation
4. The changes are well-tested with comprehensive unit tests
5. The implementation is clean and follows the project's coding standards
6. The PR includes helpful screenshots demonstrating the fix

Would you like me to proceed with approving this PR?</question>
<options>["Yes, approve the PR", "No, I'd like to discuss further", "Let me review it myself first"]</options>
</ask_followup_question>
```

## Step 5: Ask if User Wants a Comment Drafted

```xml
<ask_followup_question>
<question>Would you like me to draft a comment for this PR that you can copy and paste?</question>
<options>["Yes, please draft a comment", "No, I'll handle the comment myself"]</options>
</ask_followup_question>
```

## Step 6: Make a Decision

```bash
# Option 1: Simple one-line comment
gh pr review 3627 --approve --body "This PR looks good! It correctly fixes the thinking mode budget calculation for Claude 3.7 models."

# Option 2: Multi-line comment with proper whitespace formatting
cat << EOF | gh pr review 3627 --approve --body-file -
This PR looks good! It correctly fixes the thinking mode budget calculation for Claude 3.7 models.

I particularly like:
1. The proper implementation of thinkingConfig.maxBudget property (64000)
2. The appropriate percentage (50%) for the slider calculation
3. The comprehensive unit tests
4. The clean implementation that follows project coding standards

Great work!
EOF
```

</example_review_process>

<common_gh_commands>

# Common GitHub CLI Commands for PR Review

## Basic PR Commands

```bash
# List open PRs
gh pr list

# View a specific PR
gh pr view <PR-number>

# View PR with specific fields
gh pr view <PR-number> --json title,body,comments,files,commits

# Check PR status
gh pr status
```

## Diff and File Commands

```bash
# Get the full diff of a PR
gh pr diff <PR-number>

# List files changed in a PR
gh pr view <PR-number> --json files

# Check out a PR locally
gh pr checkout <PR-number>
```

## Review Commands

```bash
# Approve a PR (single-line comment)
gh pr review <PR-number> --approve --body "Your approval message"

# Approve a PR (multi-line comment with proper whitespace)
cat << EOF | gh pr review <PR-number> --approve --body-file -
Your multi-line
approval message with

proper whitespace formatting
EOF

# Request changes on a PR (single-line comment)
gh pr review <PR-number> --request-changes --body "Your feedback message"

# Request changes on a PR (multi-line comment with proper whitespace)
cat << EOF | gh pr review <PR-number> --request-changes --body-file -
Your multi-line
change request with

proper whitespace formatting
EOF

# Add a comment review (without approval/rejection)
gh pr review <PR-number> --comment --body "Your comment message"

# Add a comment review with proper whitespace
cat << EOF | gh pr review <PR-number> --comment --body-file -
Your multi-line
comment with

proper whitespace formatting
EOF
```

## Additional Commands

```bash
# View PR checks status
gh pr checks <PR-number>

# View PR commits
gh pr view <PR-number> --json commits

# Merge a PR (if you have permission)
gh pr merge <PR-number> --merge
```

</common_gh_commands>

<general_guidelines_for_commenting>
When reviewing a PR, please talk normally and like a friendly reviwer. You should keep it short, and start out by thanking the author of the pr and @ mentioning them.

Whether or not you approve the PR, you should then give a quick summary of the changes without being too verbose or definitive, staying humble like that this is your understanding of the changes. Kind of how I'm talking to you right now.

If you have any suggestions, or things that need to be changed, request changes instead of approving the PR.

Leaving inline comments in code is good, but only do so if you have something specific to say about the code. And make sure you leave those comments first, and then request changes in the PR with a short comment explaining the overall theme of what you're asking them to change.
</general_guidelines_for_commenting>

<example_comments_that_i_have_written_before>
<brief_approve_comment>
Looks good, though we should make this generic for all providers & models at some point
</brief_approve_comment>
<brief_approve_comment>
Will this work for models that may not match across OR/Gemini? Like the thinking models?
</brief_approve_comment>
<approve_comment>
This looks great! I like how you've handled the global endpoint support - adding it to the ModelInfo interface makes total sense since it's just another capability flag, similar to how we handle other model features.

The filtered model list approach is clean and will be easier to maintain than hardcoding which models work with global endpoints. And bumping the genai library was obviously needed for this to work.

Thanks for adding the docs about the limitations too - good for users to know they can't use context caches with global endpoints but might get fewer 429 errors.
</approve_comment>
<requesst_changes_comment>
This is awesome. Thanks @scottsus.

My main concern though - does this work for all the possible VS Code themes? We struggled with this initially which is why it's not super styled currently. Please test and share screenshots with the different themes to make sure before we can merge
</request_changes_comment>
<request_changes_comment>
Hey, the PR looks good overall but I'm concerned about removing those timeouts. Those were probably there for a reason - VSCode's UI can be finicky with timing.

Could you add back the timeouts after focusing the sidebar? Something like:

```typescript
await vscode.commands.executeCommand("claude-dev.SidebarProvider.focus")
await setTimeoutPromise(100) // Give UI time to update
visibleWebview = WebviewProvider.getSidebarInstance()
```

</request_changes_comment>
<request_changes_comment>
Heya @alejandropta thanks for working on this!

A few notes:
1 - Adding additional info to the environment variables is fairly problematic because env variables get appended to **every single message**. I don't think this is justifiable for a somewhat niche use case.
2 - Adding this option to settings to include that could be an option, but we want our options to be simple and straightforward for new users
3 - We're working on revisualizing the way our settings page is displayed/organized, and this could potentially be reconciled once that is in and our settings page is more clearly delineated.

So until the settings page is update, and this is added to settings in a way that's clean and doesn't confuse new users, I don't think we can merge this. Please bear with us.
</request_changes_comment>
<request_changes_comment>
Also, don't forget to add a changeset since this fixes a user-facing bug.

The architectural change is solid - moving the focus logic to the command handlers makes sense. Just don't want to introduce subtle timing issues by removing those timeouts.
</request_changes_comment>
</example_comments_that_i_have_written_before>

新しい PR をレビューする際、以前は手動でコンテキストを収集していました:PR の説明をチェックし、diff を調査し、周辺ファイルを見て、最終的に意見を形成していました。今では単に:

  1. チャットで /pr-review.md と入力
  2. PR 番号を貼り付け
  3. Caret に残りすべてを処理させる

私のワークフローは gh コマンドラインツールと Caret の組み込み ask_followup_question を使用して:

  • PR の説明とコメントを取得
  • diff を調査
  • コンテキストのために周辺ファイルをチェック
  • 潜在的な問題を分析
  • すべて良好に見える場合、承認して良いかを正当化理由と共に確認
  • 「はい」と答えると、Caret が自動的に gh コマンドで PR を承認

これにより、PR レビュープロセスが手動の複数ステップ操作から、情報に基づいた決定を行うために必要なすべてを提供する単一コマンドに変わりました。

これはワークフローファイルの一例に過ぎません。インスピレーションのために、我々の prompts repository でより多くの例を見つけることができます。

独自のワークフローの構築

ワークフローの美しさは、ニーズに完全にカスタマイズできることです。あらゆる種類の反復的なタスクのためのワークフローを作成できます:

  • リリースのために、すべてのマージされた PR を取得し、変更ログを構築し、バージョンアップを処理するワークフローを持つことができます。
  • 新しいプロジェクトのセットアップはワークフローに最適です。単一のコマンドを実行してフォルダ構造を作成し、依存関係をインストールし、設定を構成します。
  • レポートを作成する必要がありますか?異なるソースから統計を取得し、好みに正確に合わせてフォーマットするワークフローを作成しましょう。チャートライブラリで可視化し、slidev などのライブラリでプレゼンテーションを作成することさえできます。
  • PR を提出した後、Slack や Whatsapp などの MCP サーバーを使用してチームにメッセージのドラフトを作成するためにワークフローを使用することもできます。

ワークフローでは、想像力が限界です。真の可能性は、常に行っている厄介な反復的タスクを見つけることから生まれます。

「最初に X をして、次に Y、それから Z」と説明できるなら - それは完璧なワークフロー候補です。

気になる小さなことから始めて、ワークフローに変え、継続的に改良してください。この方法でどれだけ一日を自動化できるかに驚かれるでしょう。