mirror of
https://github.com/cline/cline.git
synced 2026-09-02 07:42:19 +08:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 97769d5b71 |
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"claude-dev": patch
|
||||
---
|
||||
|
||||
Refactor Anthropic handler to use metadata for reasoning support
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"claude-dev": patch
|
||||
---
|
||||
|
||||
Prevent duplicate error messages during streaming for Diff Edit tool when Parallel Tool Calling is not enabled.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"claude-dev": patch
|
||||
---
|
||||
|
||||
fix: correct typos in gemini system prompt overrides
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
"claude-dev": minor
|
||||
---
|
||||
|
||||
expose `getAvailableSlashCommands` rpc endpoint to UI clients
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"claude-dev": minor
|
||||
---
|
||||
|
||||
show slash command autocompletion in the cli
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"claude-dev": patch
|
||||
---
|
||||
|
||||
fix: Fetch remote config values from the cache
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"claude-dev": patch
|
||||
---
|
||||
|
||||
Replace current diff edit tools with Apply Patch tool for GPT-5+ models
|
||||
@@ -1,194 +0,0 @@
|
||||
# Hotfix Release
|
||||
|
||||
Create a hotfix release by cherry-picking specific commits from main onto the latest release tag.
|
||||
|
||||
## Overview
|
||||
|
||||
This workflow helps you:
|
||||
1. Select specific commits from main to include in a hotfix
|
||||
2. Create a release notes commit on main (changelog + version bump)
|
||||
3. Cherry-pick everything onto the latest release tag
|
||||
4. Tag and push the new release
|
||||
|
||||
## Step 1: Setup and Gather Information
|
||||
|
||||
First, ensure we're on main and up to date:
|
||||
|
||||
```bash
|
||||
git checkout main && git pull origin main
|
||||
```
|
||||
|
||||
Get the latest release tag:
|
||||
|
||||
```bash
|
||||
git tag --sort=-v:refname | head -1
|
||||
```
|
||||
|
||||
## Step 2: Present Commits Since Last Release
|
||||
|
||||
Show all commits on main since the last release tag:
|
||||
|
||||
```bash
|
||||
LAST_TAG=$(git tag --sort=-v:refname | head -1)
|
||||
git log ${LAST_TAG}..HEAD --oneline --format="%h %s (%an)"
|
||||
```
|
||||
|
||||
Also get the commit messages already on the tag (to identify previously cherry-picked commits). Note: Run these as separate commands to avoid shell parsing issues with parentheses in author names:
|
||||
|
||||
```bash
|
||||
LAST_TAG=$(git tag --sort=-v:refname | head -1)
|
||||
PREV_TAG=$(git tag --sort=-v:refname | head -2 | tail -1)
|
||||
```
|
||||
|
||||
```bash
|
||||
git log $PREV_TAG..$LAST_TAG --oneline --format="%s"
|
||||
```
|
||||
|
||||
**Present the list** to the user in a numbered format with commit hash, subject, and author. For any commits whose subject line already appears in the tag's history (previously cherry-picked in an earlier hotfix) or are "Release Notes" commits, add `(already in previous hotfix)` or `(release notes - skip)` after them so the user knows to skip those.
|
||||
|
||||
Ask which commits to include in the hotfix.
|
||||
|
||||
Use the ask_followup_question tool to let the user specify which commits they want (by number or hash).
|
||||
|
||||
## Step 3: Analyze Selected Commits
|
||||
|
||||
For each selected commit:
|
||||
1. Get the full commit message: `git show --no-patch --format="%B" <hash>`
|
||||
2. Get the diff to understand the change: `git show <hash> --stat`
|
||||
3. Find the associated PR if any: `gh pr list --search "<hash>" --state merged --json number,title --jq '.[0]'`
|
||||
|
||||
Build a mental model of what these changes do for the changelog.
|
||||
|
||||
## Step 4: Determine New Version Number
|
||||
|
||||
Parse the current version from package.json and the last tag:
|
||||
|
||||
```bash
|
||||
LAST_TAG=$(git tag --sort=-v:refname | head -1)
|
||||
echo "Last release: $LAST_TAG"
|
||||
cat package.json | grep '"version"'
|
||||
```
|
||||
|
||||
Hotfixes always increment the patch version (e.g., 3.40.0 -> 3.40.1, or 3.40.1 -> 3.40.2).
|
||||
|
||||
**Ask the user to confirm the new version number.**
|
||||
|
||||
## Step 5: Create Release Notes Commit on Main
|
||||
|
||||
On the main branch, create a commit that updates:
|
||||
|
||||
1. **CHANGELOG.md** - Add a new section for the hotfix version at the top:
|
||||
```markdown
|
||||
## [3.40.1]
|
||||
|
||||
- Description of fix 1
|
||||
- Description of fix 2
|
||||
```
|
||||
|
||||
Write clear, user-friendly descriptions based on your analysis of the commits.
|
||||
|
||||
2. **package.json** - Update the version field to the new version
|
||||
|
||||
3. **Delete changesets** for the commits being included in the hotfix. This prevents the changeset bot from including duplicate entries in the next regular release.
|
||||
|
||||
Find and delete the changeset files associated with the selected commits:
|
||||
```bash
|
||||
ls .changeset/
|
||||
```
|
||||
|
||||
Each changeset file in `.changeset/` corresponds to a PR. Read them to identify which ones belong to the commits you're hotfixing, then delete those files.
|
||||
|
||||
**Skip running `npm run install:all`** - the automation handles outdated lockfiles.
|
||||
|
||||
Commit with message format: `v{VERSION} Release Notes (hotfix)`
|
||||
|
||||
In the commit body, mention:
|
||||
- This is for a hotfix release
|
||||
- List the cherry-picked commits that will be included
|
||||
|
||||
```bash
|
||||
git add CHANGELOG.md package.json .changeset/
|
||||
git commit -m "v3.40.1 Release Notes (hotfix)
|
||||
|
||||
Hotfix release including:
|
||||
- <commit1-hash>: <description>
|
||||
- <commit2-hash>: <description>
|
||||
"
|
||||
```
|
||||
|
||||
Push to main:
|
||||
|
||||
```bash
|
||||
git push origin main
|
||||
```
|
||||
|
||||
## Step 6: Build the Hotfix on the Tag
|
||||
|
||||
Checkout the last release tag (detached HEAD):
|
||||
|
||||
```bash
|
||||
LAST_TAG=$(git tag --sort=-v:refname | head -1)
|
||||
git checkout $LAST_TAG
|
||||
```
|
||||
|
||||
Cherry-pick the selected commits in order:
|
||||
|
||||
```bash
|
||||
git cherry-pick <commit1-hash>
|
||||
git cherry-pick <commit2-hash>
|
||||
# ... etc
|
||||
```
|
||||
|
||||
Finally, cherry-pick the release notes commit you just pushed to main:
|
||||
|
||||
```bash
|
||||
# Get the hash of the release notes commit (should be HEAD of main)
|
||||
RELEASE_NOTES_COMMIT=$(git rev-parse main)
|
||||
git cherry-pick $RELEASE_NOTES_COMMIT
|
||||
```
|
||||
|
||||
## Step 7: Tag and Push
|
||||
|
||||
After all cherry-picks are applied successfully:
|
||||
|
||||
```bash
|
||||
# Tag the new release
|
||||
git tag v{VERSION}
|
||||
|
||||
# Push the tag to remote
|
||||
git push origin v{VERSION}
|
||||
```
|
||||
|
||||
## Step 8: Return to Main and Summary
|
||||
|
||||
Return to main branch:
|
||||
|
||||
```bash
|
||||
git checkout main
|
||||
```
|
||||
|
||||
**Copy a Slack announcement message to clipboard** with the version and PR links for each included fix:
|
||||
|
||||
```
|
||||
VS Code Hotfix v{VERSION} Published
|
||||
|
||||
- Description of fix 1 https://github.com/cline/cline/pull/{PR_NUMBER}
|
||||
- Description of fix 2 https://github.com/cline/cline/pull/{PR_NUMBER}
|
||||
```
|
||||
|
||||
Present a final summary:
|
||||
- New version: v{VERSION}
|
||||
- Tag pushed: yes
|
||||
- Commits included: (list them)
|
||||
- Slack message copied to clipboard: yes
|
||||
|
||||
Remind the user to:
|
||||
1. Manually trigger the publish release GitHub Action at: https://github.com/cline/cline/actions/workflows/publish.yml (paste `v{VERSION}` as the tag)
|
||||
2. Post the Slack message to announce the hotfix
|
||||
|
||||
## Important Notes
|
||||
|
||||
- This workflow does NOT create a release branch - only tags
|
||||
- The release notes commit goes to main first, then gets cherry-picked to the tag
|
||||
- This keeps main's history accurate while allowing hotfix releases from tags
|
||||
- If cherry-pick conflicts occur, resolve them before continuing
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../.clinerules/workflows/hotfix-release.md
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../.clinerules/workflows/release.md
|
||||
@@ -1 +0,0 @@
|
||||
../../.claude/commands/hotfix-release.md
|
||||
@@ -0,0 +1,194 @@
|
||||
# Hotfix Release
|
||||
|
||||
Create a hotfix release by cherry-picking specific commits from main onto the latest release tag.
|
||||
|
||||
## Overview
|
||||
|
||||
This workflow helps you:
|
||||
1. Select specific commits from main to include in a hotfix
|
||||
2. Create a release notes commit on main (changelog + version bump)
|
||||
3. Cherry-pick everything onto the latest release tag
|
||||
4. Tag and push the new release
|
||||
|
||||
## Step 1: Setup and Gather Information
|
||||
|
||||
First, ensure we're on main and up to date:
|
||||
|
||||
```bash
|
||||
git checkout main && git pull origin main
|
||||
```
|
||||
|
||||
Get the latest release tag:
|
||||
|
||||
```bash
|
||||
git tag --sort=-v:refname | head -1
|
||||
```
|
||||
|
||||
## Step 2: Present Commits Since Last Release
|
||||
|
||||
Show all commits on main since the last release tag:
|
||||
|
||||
```bash
|
||||
LAST_TAG=$(git tag --sort=-v:refname | head -1)
|
||||
git log ${LAST_TAG}..HEAD --oneline --format="%h %s (%an)"
|
||||
```
|
||||
|
||||
Also get the commit messages already on the tag (to identify previously cherry-picked commits). Note: Run these as separate commands to avoid shell parsing issues with parentheses in author names:
|
||||
|
||||
```bash
|
||||
LAST_TAG=$(git tag --sort=-v:refname | head -1)
|
||||
PREV_TAG=$(git tag --sort=-v:refname | head -2 | tail -1)
|
||||
```
|
||||
|
||||
```bash
|
||||
git log $PREV_TAG..$LAST_TAG --oneline --format="%s"
|
||||
```
|
||||
|
||||
**Present the list** to the user in a numbered format with commit hash, subject, and author. For any commits whose subject line already appears in the tag's history (previously cherry-picked in an earlier hotfix) or are "Release Notes" commits, add `(already in previous hotfix)` or `(release notes - skip)` after them so the user knows to skip those.
|
||||
|
||||
Ask which commits to include in the hotfix.
|
||||
|
||||
Use the ask_followup_question tool to let the user specify which commits they want (by number or hash).
|
||||
|
||||
## Step 3: Analyze Selected Commits
|
||||
|
||||
For each selected commit:
|
||||
1. Get the full commit message: `git show --no-patch --format="%B" <hash>`
|
||||
2. Get the diff to understand the change: `git show <hash> --stat`
|
||||
3. Find the associated PR if any: `gh pr list --search "<hash>" --state merged --json number,title --jq '.[0]'`
|
||||
|
||||
Build a mental model of what these changes do for the changelog.
|
||||
|
||||
## Step 4: Determine New Version Number
|
||||
|
||||
Parse the current version from package.json and the last tag:
|
||||
|
||||
```bash
|
||||
LAST_TAG=$(git tag --sort=-v:refname | head -1)
|
||||
echo "Last release: $LAST_TAG"
|
||||
cat package.json | grep '"version"'
|
||||
```
|
||||
|
||||
Hotfixes always increment the patch version (e.g., 3.40.0 -> 3.40.1, or 3.40.1 -> 3.40.2).
|
||||
|
||||
**Ask the user to confirm the new version number.**
|
||||
|
||||
## Step 5: Create Release Notes Commit on Main
|
||||
|
||||
On the main branch, create a commit that updates:
|
||||
|
||||
1. **CHANGELOG.md** - Add a new section for the hotfix version at the top:
|
||||
```markdown
|
||||
## [3.40.1]
|
||||
|
||||
- Description of fix 1
|
||||
- Description of fix 2
|
||||
```
|
||||
|
||||
Write clear, user-friendly descriptions based on your analysis of the commits.
|
||||
|
||||
2. **package.json** - Update the version field to the new version
|
||||
|
||||
3. **Delete changesets** for the commits being included in the hotfix. This prevents the changeset bot from including duplicate entries in the next regular release.
|
||||
|
||||
Find and delete the changeset files associated with the selected commits:
|
||||
```bash
|
||||
ls .changeset/
|
||||
```
|
||||
|
||||
Each changeset file in `.changeset/` corresponds to a PR. Read them to identify which ones belong to the commits you're hotfixing, then delete those files.
|
||||
|
||||
**Skip running `npm run install:all`** - the automation handles outdated lockfiles.
|
||||
|
||||
Commit with message format: `v{VERSION} Release Notes (hotfix)`
|
||||
|
||||
In the commit body, mention:
|
||||
- This is for a hotfix release
|
||||
- List the cherry-picked commits that will be included
|
||||
|
||||
```bash
|
||||
git add CHANGELOG.md package.json .changeset/
|
||||
git commit -m "v3.40.1 Release Notes (hotfix)
|
||||
|
||||
Hotfix release including:
|
||||
- <commit1-hash>: <description>
|
||||
- <commit2-hash>: <description>
|
||||
"
|
||||
```
|
||||
|
||||
Push to main:
|
||||
|
||||
```bash
|
||||
git push origin main
|
||||
```
|
||||
|
||||
## Step 6: Build the Hotfix on the Tag
|
||||
|
||||
Checkout the last release tag (detached HEAD):
|
||||
|
||||
```bash
|
||||
LAST_TAG=$(git tag --sort=-v:refname | head -1)
|
||||
git checkout $LAST_TAG
|
||||
```
|
||||
|
||||
Cherry-pick the selected commits in order:
|
||||
|
||||
```bash
|
||||
git cherry-pick <commit1-hash>
|
||||
git cherry-pick <commit2-hash>
|
||||
# ... etc
|
||||
```
|
||||
|
||||
Finally, cherry-pick the release notes commit you just pushed to main:
|
||||
|
||||
```bash
|
||||
# Get the hash of the release notes commit (should be HEAD of main)
|
||||
RELEASE_NOTES_COMMIT=$(git rev-parse main)
|
||||
git cherry-pick $RELEASE_NOTES_COMMIT
|
||||
```
|
||||
|
||||
## Step 7: Tag and Push
|
||||
|
||||
After all cherry-picks are applied successfully:
|
||||
|
||||
```bash
|
||||
# Tag the new release
|
||||
git tag v{VERSION}
|
||||
|
||||
# Push the tag to remote
|
||||
git push origin v{VERSION}
|
||||
```
|
||||
|
||||
## Step 8: Return to Main and Summary
|
||||
|
||||
Return to main branch:
|
||||
|
||||
```bash
|
||||
git checkout main
|
||||
```
|
||||
|
||||
**Copy a Slack announcement message to clipboard** with the version and PR links for each included fix:
|
||||
|
||||
```
|
||||
VS Code Hotfix v{VERSION} Published
|
||||
|
||||
- Description of fix 1 https://github.com/cline/cline/pull/{PR_NUMBER}
|
||||
- Description of fix 2 https://github.com/cline/cline/pull/{PR_NUMBER}
|
||||
```
|
||||
|
||||
Present a final summary:
|
||||
- New version: v{VERSION}
|
||||
- Tag pushed: yes
|
||||
- Commits included: (list them)
|
||||
- Slack message copied to clipboard: yes
|
||||
|
||||
Remind the user to:
|
||||
1. Manually trigger the publish release GitHub Action at: https://github.com/cline/cline/actions/workflows/publish.yml (paste `v{VERSION}` as the tag)
|
||||
2. Post the Slack message to announce the hotfix
|
||||
|
||||
## Important Notes
|
||||
|
||||
- This workflow does NOT create a release branch - only tags
|
||||
- The release notes commit goes to main first, then gets cherry-picked to the tag
|
||||
- This keeps main's history accurate while allowing hotfix releases from tags
|
||||
- If cherry-pick conflicts occur, resolve them before continuing
|
||||
@@ -0,0 +1,232 @@
|
||||
# Release
|
||||
|
||||
Prepare and publish a release from the open changeset PR.
|
||||
|
||||
## Overview
|
||||
|
||||
This workflow helps you:
|
||||
1. Find and checkout the open changeset PR
|
||||
2. Clean up the changelog (fix version format, wordsmith entries)
|
||||
3. Push changes back to the PR branch
|
||||
4. Merge with proper commit message format
|
||||
5. Tag and push the release (after verifying the commit)
|
||||
6. Trigger the publish workflow
|
||||
7. Update GitHub release notes
|
||||
8. Provide final summary with Slack announcement
|
||||
|
||||
## Step 1: Find the Changeset PR
|
||||
|
||||
Look for the open changeset PR:
|
||||
|
||||
```bash
|
||||
gh pr list --search "Changeset version bump" --state open --json number,title,headRefName,url
|
||||
```
|
||||
|
||||
If no PR is found, inform the user there's no changeset PR ready. They may need to:
|
||||
- Merge PRs with changesets to main first
|
||||
- Manually trigger the Changeset Converter workflow at: https://github.com/cline/cline/actions/workflows/changeset-converter.yml
|
||||
|
||||
## Step 2: Gather PR Information
|
||||
|
||||
Get the PR details:
|
||||
|
||||
```bash
|
||||
PR_NUMBER=<number from step 1>
|
||||
gh pr view $PR_NUMBER --json body,files,headRefName
|
||||
```
|
||||
|
||||
Checkout the PR branch:
|
||||
|
||||
```bash
|
||||
git fetch origin changeset-release/main
|
||||
git checkout changeset-release/main
|
||||
```
|
||||
|
||||
If the branch has diverged from remote, reset to the remote version:
|
||||
|
||||
```bash
|
||||
git reset --hard origin/changeset-release/main
|
||||
```
|
||||
|
||||
## Step 3: Analyze the Changes
|
||||
|
||||
Read the current CHANGELOG.md to see what the automation generated:
|
||||
|
||||
```bash
|
||||
head -50 CHANGELOG.md
|
||||
```
|
||||
|
||||
Get the version from package.json:
|
||||
|
||||
```bash
|
||||
cat package.json | grep '"version"'
|
||||
```
|
||||
|
||||
**Present to the user:**
|
||||
- The version number that will be released
|
||||
- The raw changelog entries from the changeset PR
|
||||
- Whether this is a patch, minor, or major release
|
||||
|
||||
## Step 4: Clean Up the Changelog
|
||||
|
||||
The changelog needs these fixes:
|
||||
|
||||
1. **Add brackets to version number**: Change `## 3.44.1` to `## [3.44.1]`
|
||||
|
||||
2. **No category headers**: Don't use `### Added`, `### Fixed`, etc. Just a flat list of bullet points.
|
||||
|
||||
3. **Order entries from most important to least important**:
|
||||
- Lead with major new features or significant fixes users care about
|
||||
- End with minor fixes or internal changes
|
||||
|
||||
4. **Write user-friendly descriptions**:
|
||||
- This is for end users, not developers—explain what changed in plain language
|
||||
- Remove commit hashes from the beginning of lines (the automation adds these)
|
||||
- Look at the actual commit diffs (`git show <hash>`) and PRs to understand what changed
|
||||
- Write colorful descriptions that explain the value and impact, not just technical details
|
||||
- Consolidate related changes into single entries when appropriate
|
||||
|
||||
**Ask the user** to review the proposed changelog changes before applying them. Show them:
|
||||
- Current (raw) changelog section
|
||||
- Proposed (cleaned) changelog section
|
||||
|
||||
Once approved, apply the changes to CHANGELOG.md.
|
||||
|
||||
## Step 5: Commit and Push Changes
|
||||
|
||||
After making changelog edits:
|
||||
|
||||
```bash
|
||||
git add CHANGELOG.md
|
||||
git commit -m "Clean up changelog formatting"
|
||||
git push origin changeset-release/main
|
||||
```
|
||||
|
||||
## Step 6: Merge the PR
|
||||
|
||||
**Ask the user to confirm** they're ready to merge.
|
||||
|
||||
Merge the PR with the proper commit message format:
|
||||
|
||||
```bash
|
||||
VERSION=<version from package.json>
|
||||
gh pr merge $PR_NUMBER --squash --subject "v${VERSION} Release Notes" --body ""
|
||||
```
|
||||
|
||||
**If merge is blocked by branch protection:**
|
||||
- Users with admin privileges can add the `--admin` flag to bypass
|
||||
- Users without admin privileges need to get the PR approved through normal review first before merging
|
||||
|
||||
## Step 7: Tag the Release
|
||||
|
||||
After the merge completes, checkout main and pull:
|
||||
|
||||
```bash
|
||||
git checkout main
|
||||
git pull origin main
|
||||
```
|
||||
|
||||
**IMPORTANT: Verify the latest commit is the release commit before tagging:**
|
||||
|
||||
```bash
|
||||
git log -1 --oneline
|
||||
```
|
||||
|
||||
Confirm the commit message matches `v{VERSION} Release Notes` (e.g., `v3.44.1 Release Notes`). Do NOT blindly tag HEAD without verification.
|
||||
|
||||
Once verified, tag and push:
|
||||
|
||||
```bash
|
||||
VERSION=<version>
|
||||
git tag v${VERSION}
|
||||
git push origin v${VERSION}
|
||||
```
|
||||
|
||||
## Step 8: Trigger Publish Workflow
|
||||
|
||||
**Copy the tag to clipboard** so the user can easily paste it into the GitHub Actions workflow:
|
||||
|
||||
```bash
|
||||
echo -n "v{VERSION}" | pbcopy
|
||||
```
|
||||
|
||||
**Tell the user to trigger the publish workflow:**
|
||||
1. Go to: https://github.com/cline/cline/actions/workflows/publish.yml
|
||||
2. Select **"release"** for release-type
|
||||
3. Paste **`v{VERSION}`** as the tag (already in clipboard)
|
||||
|
||||
**Wait for the user** to confirm the publish workflow has completed before proceeding.
|
||||
|
||||
## Step 9: Update GitHub Release Notes
|
||||
|
||||
Once the user confirms the publish workflow is done, fetch the auto-generated release content:
|
||||
|
||||
```bash
|
||||
VERSION=<version>
|
||||
gh release view v${VERSION} --json body --jq '.body'
|
||||
```
|
||||
|
||||
The auto-generated release has:
|
||||
- `## What's Changed` - PR list (we'll replace this with our changelog)
|
||||
- `## New Contributors` - First-time contributors (keep this if present)
|
||||
- `**Full Changelog**` - Comparison link (keep this)
|
||||
|
||||
Build the new release body:
|
||||
1. Start with `## What's Changed` header
|
||||
2. Add our changelog content (from CHANGELOG.md for this version)
|
||||
3. Keep the `## New Contributors` section if it exists
|
||||
4. Keep the `**Full Changelog**` link
|
||||
|
||||
Update the release:
|
||||
|
||||
```bash
|
||||
gh release edit v${VERSION} --notes "<new body content>"
|
||||
```
|
||||
|
||||
Verify the release was updated:
|
||||
|
||||
```bash
|
||||
gh release view v${VERSION}
|
||||
```
|
||||
|
||||
## Step 10: Final Summary
|
||||
|
||||
**Copy a Slack announcement message to clipboard** (include the full changelog, not just highlights):
|
||||
|
||||
```bash
|
||||
echo "VS Code v{VERSION} Released
|
||||
|
||||
- Changelog entry 1
|
||||
- Changelog entry 2
|
||||
- Changelog entry 3" | pbcopy
|
||||
```
|
||||
|
||||
**Present a final summary:**
|
||||
- Version released: v{VERSION}
|
||||
- PR merged: #{PR_NUMBER}
|
||||
- Tag pushed: v{VERSION}
|
||||
- Release: https://github.com/cline/cline/releases/tag/v{VERSION}
|
||||
- Slack message copied to clipboard
|
||||
|
||||
**Final reminder:**
|
||||
Post the Slack message to announce the release
|
||||
|
||||
## Handling Edge Cases
|
||||
|
||||
### No changesets found
|
||||
If the changeset PR body shows no changes, inform the user they need to merge PRs with changesets first.
|
||||
|
||||
### Merge conflicts
|
||||
If there are conflicts on the changeset branch, help the user resolve them:
|
||||
```bash
|
||||
git fetch origin main
|
||||
git rebase origin/main
|
||||
# resolve conflicts
|
||||
git push origin changeset-release/main --force-with-lease
|
||||
```
|
||||
|
||||
### User wants to add more changes
|
||||
If the user wants to include additional PRs before releasing:
|
||||
1. Ask them to merge those PRs to main first
|
||||
2. The changeset automation will update the PR automatically
|
||||
3. Re-run this workflow after the PR is updated
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
/docs/
|
||||
/.github/ @saoudrizwan @garoth @sjf
|
||||
/README.md @saoudrizwan @nickbaumann98
|
||||
/src/core/storage/ @celestial-vault
|
||||
/src/core/storage/ @celestial-vault @abeatrix
|
||||
|
||||
Vendored
+16
-4
@@ -12,7 +12,10 @@
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceFolder}",
|
||||
"--disable-workspace-trust",
|
||||
"--disable-extensions", // Avoid conflicts with installed extensions
|
||||
"--disable-extension",
|
||||
"saoudrizwan.claude-dev", // Avoid conflicts with installed Cline
|
||||
"--disable-extension",
|
||||
"saoudrizwan.cline-nightly", // Avoid conflicts with installed Cline Nightly
|
||||
"${workspaceFolder}"
|
||||
],
|
||||
"outFiles": [
|
||||
@@ -33,7 +36,10 @@
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceFolder}",
|
||||
"--disable-workspace-trust",
|
||||
"--disable-extensions", // Avoid conflicts with installed extensions
|
||||
"--disable-extension",
|
||||
"saoudrizwan.claude-dev", // Avoid conflicts with installed Cline
|
||||
"--disable-extension",
|
||||
"saoudrizwan.cline-nightly", // Avoid conflicts with installed Cline Nightly
|
||||
"${workspaceFolder}"
|
||||
],
|
||||
"outFiles": [
|
||||
@@ -54,7 +60,10 @@
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceFolder}",
|
||||
"--disable-workspace-trust",
|
||||
"--disable-extensions", // Avoid conflicts with installed extensions
|
||||
"--disable-extension",
|
||||
"saoudrizwan.claude-dev", // Avoid conflicts with installed Cline
|
||||
"--disable-extension",
|
||||
"saoudrizwan.cline-nightly", // Avoid conflicts with installed Cline Nightly
|
||||
"${workspaceFolder}"
|
||||
],
|
||||
"outFiles": [
|
||||
@@ -77,7 +86,10 @@
|
||||
"--user-data-dir=${workspaceFolder}/dist/tmp/user",
|
||||
"--profile-temp",
|
||||
"--sync=off",
|
||||
"--disable-extensions", // Avoid conflicts with installed extensions
|
||||
"--disable-extension",
|
||||
"saoudrizwan.claude-dev", // Avoid conflicts with installed Cline
|
||||
"--disable-extension",
|
||||
"saoudrizwan.cline-nightly", // Avoid conflicts with installed Cline Nightly
|
||||
"--extensionDevelopmentPath=${workspaceFolder}",
|
||||
"${workspaceFolder}"
|
||||
],
|
||||
|
||||
Vendored
+3
-1
@@ -27,5 +27,7 @@
|
||||
"source.removeUnused.biome": "always",
|
||||
"source.removeUnusedImports": "always",
|
||||
"source.organizeImports.biome": "always"
|
||||
}
|
||||
},
|
||||
// Disable auto-forwarding ports to prevent Simple Browser from opening the Vite dev server
|
||||
"remote.autoForwardPorts": false
|
||||
}
|
||||
|
||||
+67
-1
@@ -1,24 +1,90 @@
|
||||
# Changelog
|
||||
|
||||
## [3.45.0]
|
||||
|
||||
- Added Gemini 3 Flash Preview model
|
||||
|
||||
## [3.44.2]
|
||||
|
||||
- Polished the model picker UI with checkmarks for selected models, tooltips on Plan/Act tabs, and consistent arrow pointers across all popup modals
|
||||
- Improved WhatsNew modal responsiveness and cleaned up redundant UI elements
|
||||
- Fixed GLM models outputting garbled text in thinking tags—reasoning is now properly disabled for these models
|
||||
|
||||
## [3.44.1]
|
||||
|
||||
- Fixed a critical bug where local MCP servers stopped connecting after v3.42.0—all user-configured stdio-based MCP servers should now work again
|
||||
- Fixed remotely configured API keys not being extracted correctly for enterprise users
|
||||
- Added support for dynamic tool instructions that adapt based on runtime context, laying groundwork for future context-aware features
|
||||
|
||||
## [3.44.0]
|
||||
|
||||
## Added
|
||||
|
||||
- Updating minor version to show a proper banner for the release
|
||||
|
||||
## [3.43.1]
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Fix GLM-4.6 Model reference id
|
||||
|
||||
## [3.43.0]
|
||||
|
||||
### Added
|
||||
|
||||
- GLM-4.6
|
||||
- kat-coder-pro
|
||||
- Add parsing of env variable patterns to the mcpconfig.json
|
||||
|
||||
### Fixed
|
||||
|
||||
- TLS Proxy support issues for VSCode
|
||||
- Add supportsReasoning flag to OpenAI reasoning models
|
||||
- Fix thinking not available for some models in the OpenAI provider
|
||||
- Fix invalid signature field issues when switching between Gemini and Anthropic providers
|
||||
- Extract OpenRouter model filtering into reusable utility and use it in different model pickers
|
||||
- Fix a11y for auto approve checkbox
|
||||
- Improve ModelPickerModal provider list layout
|
||||
|
||||
### Refactored
|
||||
|
||||
- Migrate WhatsNewModal to new shared dialogue component
|
||||
|
||||
## [3.42.0]
|
||||
|
||||
### Added
|
||||
|
||||
- Expose `getAvailableSlashCommands` rpc endpoint to UI clients
|
||||
- Made slash command menu and context menu accessible and screenreader-friendly
|
||||
- Made expanding/collapsing UI components accessible
|
||||
|
||||
### Fixed
|
||||
|
||||
- Devstral OpenRouter model ID and routing issues
|
||||
- Incorrect pricing display for Devstral model in the extension
|
||||
|
||||
## [3.41.0]
|
||||
|
||||
### Added
|
||||
|
||||
- OpenAI GPT-5.2
|
||||
- Devstral-2512 (formerly stealth model "Microwave")
|
||||
- Improvements to chat modal model picker
|
||||
- Amazon Nova 2 Lite
|
||||
- Amazon Nova 2 Lite
|
||||
- DeepSeek 3.2 to native tool calling allow list
|
||||
- Responses API support for Codex models in OpenAI provider (requires native tool calling)
|
||||
- Xmas Special Santa Cline
|
||||
- Welcome screen UI enhancements
|
||||
|
||||
### Fixed
|
||||
|
||||
- Initial checkpoint commit now non-blocking for improved responsiveness in large repositories
|
||||
- Gemini Vertex models erroring when thinking parameters are not supported
|
||||
- Restrictive file permissions for secrets.json
|
||||
- Ollama streaming requests not aborting when task is cancelled
|
||||
|
||||
### Refactored
|
||||
|
||||
- OpenAI provider to centralize temperature configuration and include missing GPT-5 model settings
|
||||
- OpenAI native handler to use metadata for model capabilities
|
||||
- Vertex provider to use metadata for model capabilities
|
||||
|
||||
@@ -70,3 +70,4 @@ Apache-2.0 - see [LICENSE](https://github.com/cline/cline/blob/main/LICENSE) for
|
||||
- Report issues: [GitHub Issues](https://github.com/cline/cline/issues)
|
||||
- Community: [GitHub Discussions](https://github.com/cline/cline/discussions)
|
||||
- Documentation: [docs.cline.bot](https://docs.cline.bot)
|
||||
- Cline CLI Architecture: [architecture.md](./architecture.md)
|
||||
|
||||
@@ -0,0 +1,292 @@
|
||||
# Cline CLI Architecture
|
||||
|
||||
The CLI is a **standalone terminal interface** for the Cline AI coding assistant, written in Go. It provides the same autonomous coding capabilities as the VS Code extension but runs entirely in the terminal.
|
||||
|
||||
## High-Level Architecture
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────────────────┐
|
||||
│ User Terminal │
|
||||
└─────────────────────────────────────────────────────────────────────────┘
|
||||
│
|
||||
▼
|
||||
┌─────────────────────────────────────────────────────────────────────────┐
|
||||
│ cline (Go binary) │
|
||||
│ cmd/cline/main.go │
|
||||
│ • Cobra CLI commands (task, auth, config, instance, etc.) │
|
||||
│ • Interactive input via Bubble Tea │
|
||||
│ • Streaming output with markdown rendering │
|
||||
└─────────────────────────────────────────────────────────────────────────┘
|
||||
│ gRPC (50052) │ starts subprocess
|
||||
▼ ▼
|
||||
┌─────────────────────────┐ ┌─────────────────────────┐
|
||||
│ cline-core │◄────────────────►│ cline-host │
|
||||
│ (Node.js) │ gRPC (51052) │ (Go binary) │
|
||||
│ │ │ cmd/cline-host/main.go│
|
||||
│ • AI/LLM orchestration │ │ │
|
||||
│ • Tool execution │ │ • Workspace paths │
|
||||
│ • Task state mgmt │ │ • File diff editing │
|
||||
│ • Message handling │ │ • Clipboard access │
|
||||
└─────────────────────────┘ │ • Environment info │
|
||||
│ └─────────────────────────┘
|
||||
│ SQLite (self-registration)
|
||||
▼
|
||||
┌─────────────────────────────────────────────────────────────────────────┐
|
||||
│ ~/.cline/data/locks/locks.db │
|
||||
│ (Instance registry - core self-registers on startup) │
|
||||
└─────────────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
## Entry Points (`cmd/`)
|
||||
|
||||
### `cmd/cline/main.go` - Main CLI
|
||||
|
||||
Cobra-based CLI with commands:
|
||||
|
||||
- **Root**: `cline [prompt]` - Start a task directly
|
||||
- **task**: Create, send, view, list, pause, restore tasks
|
||||
- **auth**: Authentication setup and provider configuration
|
||||
- **config**: Read/write settings
|
||||
- **instance**: Manage running Cline instances
|
||||
- **logs**: View and clean log files
|
||||
- **doctor**: System health check
|
||||
|
||||
### `cmd/cline-host/main.go` - Host Bridge Service
|
||||
|
||||
Separate gRPC server providing host environment operations to cline-core:
|
||||
|
||||
- Workspace paths
|
||||
- File diff editing
|
||||
- Clipboard access
|
||||
- Shutdown coordination
|
||||
|
||||
---
|
||||
|
||||
## `pkg/cli/` Subsystems
|
||||
|
||||
### 1. `auth/` - Authentication System
|
||||
|
||||
Handles authentication with Cline service and BYO (Bring Your Own) API providers.
|
||||
|
||||
| File | Purpose |
|
||||
| ------------------------- | ------------------------------------------------------------------------ |
|
||||
| `auth_cline_provider.go` | OAuth login flow - opens browser, subscribes to auth callback stream |
|
||||
| `auth_menu.go` | Interactive menu showing auth options based on current state |
|
||||
| `auth_subscription.go` | gRPC stream subscription for auth status updates |
|
||||
| `wizard_byo.go` | Interactive wizard for configuring BYO providers |
|
||||
| `wizard_byo_bedrock.go` | AWS Bedrock-specific credential setup |
|
||||
| `wizard_byo_oca.go` | Oracle Code Assist setup |
|
||||
| `providers_list.go` | Retrieves configured providers from core state |
|
||||
| `providers_byo.go` | Provider selection UI and field configuration |
|
||||
| `models_*.go` | Model listing (static lists + dynamic fetch from OpenRouter/OpenAI/Ollama) |
|
||||
|
||||
**Flow**: User runs `cline auth` → Menu shows options → For BYO: wizard guides through provider/key/model selection → Config saved via gRPC to core.
|
||||
|
||||
---
|
||||
|
||||
### 2. `clerror/` - Error Handling
|
||||
|
||||
Parses and classifies API errors from the Cline service.
|
||||
|
||||
**Error Types:**
|
||||
|
||||
- `ErrorTypeAuth` - 401, bad API key
|
||||
- `ErrorTypeBalance` - Insufficient credits
|
||||
- `ErrorTypeRateLimit` - 429, quota exceeded
|
||||
- `ErrorTypeNetwork` - Connection issues
|
||||
- `ErrorTypeUnknown` - Catch-all
|
||||
|
||||
Extracts billing details (balance, spent, buy credits URL) from error responses.
|
||||
|
||||
---
|
||||
|
||||
### 3. `config/` - Configuration Management
|
||||
|
||||
| File | Purpose |
|
||||
| --------------------- | -------------------------------------------------------------------------- |
|
||||
| `manager.go` | gRPC interface for reading/writing settings via `UpdateSettingsCli` RPC |
|
||||
| `settings_renderer.go`| Pretty-prints config values, censors sensitive fields (keys, secrets) |
|
||||
|
||||
Supports dot-notation paths: `cline config get auto-approval-settings.actions.read-files`
|
||||
|
||||
---
|
||||
|
||||
### 4. `display/` - Terminal Display System
|
||||
|
||||
The most complex subsystem - handles all visual output.
|
||||
|
||||
| File | Purpose |
|
||||
| ----------------------- | -------------------------------------------------------------------- |
|
||||
| `renderer.go` | Central coordinator with lipgloss styles, color methods, markdown delegation |
|
||||
| `streaming.go` | Real-time streaming display with deduplication |
|
||||
| `segment_streamer.go` | Streaming segments (header + body) with context-aware headers |
|
||||
| `typewriter.go` | Character-by-character animation with variable delays |
|
||||
| `markdown_renderer.go` | Glamour wrapper for terminal markdown rendering |
|
||||
| `tool_renderer.go` | Tool operation formatting ("Cline is editing `file.ts`") |
|
||||
| `tool_result_parser.go` | Parses structured tool results (file lists, search results) |
|
||||
| `banner.go` | Session startup banner with version/model/workspace |
|
||||
| `deduplicator.go` | MD5-based deduplication with 2-second window |
|
||||
| `system_renderer.go` | Rich error/warning boxes for balance errors, auth failures |
|
||||
| `ansi.go` | TTY detection, line clearing with escape codes |
|
||||
|
||||
---
|
||||
|
||||
### 5. `global/` - Global State Management
|
||||
|
||||
| File | Purpose |
|
||||
| ------------------ | -------------------------------------------------------------------------- |
|
||||
| `global.go` | Global config (paths, verbosity, output format), initialization |
|
||||
| `registry.go` | Instance discovery via SQLite, health checking, default instance management|
|
||||
| `cline-clients.go` | Starts cline-core + cline-host processes, port allocation, cleanup |
|
||||
|
||||
**Instance lifecycle:**
|
||||
|
||||
1. Find available port pair
|
||||
2. Start `cline-host` on port+1000
|
||||
3. Start `cline-core` on port
|
||||
4. Wait for core to self-register in SQLite
|
||||
5. Set as default if first instance
|
||||
|
||||
---
|
||||
|
||||
### 6. `handlers/` - Message Handlers
|
||||
|
||||
Routes incoming messages from cline-core to appropriate renderers.
|
||||
|
||||
| File | Purpose |
|
||||
| ------------------ | --------------------------------------------------------------------- |
|
||||
| `handler.go` | Handler registry with priority-based routing |
|
||||
| `ask_handlers.go` | Approval requests: tool, command, followup, api_req_failed, etc. |
|
||||
| `say_handlers.go` | Status messages: text, reasoning, command_output, tool, checkpoint, etc. |
|
||||
|
||||
Uses `DisplayContext` providing renderer access, state, and context flags (isLast, isPartial, isStreamingMode).
|
||||
|
||||
---
|
||||
|
||||
### 7. `output/` - Output Coordination
|
||||
|
||||
| File | Purpose |
|
||||
| --------------------- | ----------------------------------------------------------------------- |
|
||||
| `coordinator.go` | Coordinates streaming output with interactive input (saves/restores input state) |
|
||||
| `input_model.go` | Bubble Tea model for rich input (message, approval, feedback types) |
|
||||
| `slash_completion.go` | Autocomplete dropdown for slash commands |
|
||||
|
||||
**Key pattern:** When output needs to print while input is visible, the coordinator saves input state, clears the form, prints, then restores input.
|
||||
|
||||
---
|
||||
|
||||
### 8. `slash/` - Slash Command Registry
|
||||
|
||||
Central registry for commands like `/plan`, `/act`, `/cancel`:
|
||||
|
||||
- **CLI-local commands**: Handled directly by CLI
|
||||
- **Backend commands**: Fetched from core via gRPC, filtered by `CliCompatible` flag
|
||||
|
||||
---
|
||||
|
||||
### 9. `sqlite/` - Instance Locking
|
||||
|
||||
Manages the distributed locking system:
|
||||
|
||||
- **Instance locks**: Track running Cline instances by address
|
||||
- **File locks**: Coordinate file access across instances
|
||||
- SQLite database created by cline-core, CLI reads/writes for discovery
|
||||
|
||||
---
|
||||
|
||||
### 10. `task/` - Task Management
|
||||
|
||||
| File | Purpose |
|
||||
| ----------------------- | -------------------------------------------------------------------- |
|
||||
| `manager.go` | Core orchestrator: create, cancel, resume, restore tasks; stream handling |
|
||||
| `stream_coordinator.go` | Deduplication and turn management for dual streams |
|
||||
| `input_handler.go` | Interactive input during follow mode (polling, approval detection) |
|
||||
| `history_handler.go` | Direct disk access to `taskHistory.json` |
|
||||
| `settings_parser.go` | Parse settings from CLI flags |
|
||||
| `follow_options.go` | Configuration for follow behavior |
|
||||
|
||||
**Streaming:** Task manager subscribes to two gRPC streams:
|
||||
|
||||
1. `SubscribeToState` - Full state updates
|
||||
2. `SubscribeToPartialMessage` - Streaming AI responses
|
||||
|
||||
---
|
||||
|
||||
### 11. `terminal/` - Terminal Handling
|
||||
|
||||
Enhanced keyboard protocol support and terminal configuration:
|
||||
|
||||
- Enables modifyOtherKeys and Kitty keyboard protocol
|
||||
- Detects terminal type (VS Code, iTerm, Ghostty, Kitty, etc.)
|
||||
- Auto-configures shift+enter keybindings for various terminals
|
||||
|
||||
---
|
||||
|
||||
### 12. `types/` - Type Definitions
|
||||
|
||||
| File | Purpose |
|
||||
| -------------- | ----------------------------------------------------------------- |
|
||||
| `messages.go` | `ClineMessage`, `AskType`, `SayType`, `ToolType` enums, proto conversion |
|
||||
| `state.go` | `ConversationState` with thread-safe message access |
|
||||
| `history.go` | `HistoryItem` matching taskHistory.json format |
|
||||
|
||||
---
|
||||
|
||||
### 13. `updater/` - Auto-Update
|
||||
|
||||
Background auto-update checking:
|
||||
|
||||
- 24-hour check interval (cached)
|
||||
- Queries npm registry for newer versions
|
||||
- Supports `latest` and `nightly` channels
|
||||
- Runs `npm install -g cline` to update
|
||||
|
||||
---
|
||||
|
||||
## `pkg/common/` - Shared Types
|
||||
|
||||
| File | Purpose |
|
||||
| --------------- | ------------------------------------------------------------ |
|
||||
| `constants.go` | `SETTINGS_SUBFOLDER`, `DEFAULT_CLINE_CORE_PORT` |
|
||||
| `schema.go` | SQL queries for instance/file locks |
|
||||
| `types.go` | `CoreInstanceInfo`, `LockRow`, `DefaultCoreInstance` |
|
||||
| `utils.go` | Port checking, health checks, address normalization, retry logic |
|
||||
|
||||
---
|
||||
|
||||
## `pkg/generated/` - Auto-Generated
|
||||
|
||||
| File | Purpose |
|
||||
| --------------------- | -------------------------------------------------------------------------------------------------------------------- |
|
||||
| `providers.go` | Provider definitions (Anthropic, OpenAI, Bedrock, etc.) with field metadata and model specs - generated from TypeScript sources |
|
||||
| `field_overrides.go` | Manual overrides for field filtering |
|
||||
|
||||
---
|
||||
|
||||
## `pkg/hostbridge/` - CLI-to-Core Bridge
|
||||
|
||||
This is the **reverse bridge** allowing cline-core to request host environment operations:
|
||||
|
||||
| File | Purpose |
|
||||
| ----------------------- | ---------------------------------------------------- |
|
||||
| `grpc_server.go` | Main server registering all services |
|
||||
| `simple_workspace.go` | Workspace service: returns CWD as workspace path |
|
||||
| `diff.go` | In-memory file diff editing with line-based operations |
|
||||
| `env.go` | Clipboard access, version info, shutdown coordination |
|
||||
| `window.go` | UI stubs (no-ops or console output) |
|
||||
|
||||
**Why this exists:** The same cline-core logic runs in VS Code and CLI. In VS Code, the "host" is the extension with editor APIs. In CLI, hostbridge emulates these capabilities with terminal-appropriate implementations.
|
||||
|
||||
---
|
||||
|
||||
## Key Design Decisions
|
||||
|
||||
1. **Two-process model:** `cline` CLI manages instances; `cline-core` is the actual AI engine (Node.js). This allows reusing the same core as the VS Code extension.
|
||||
|
||||
2. **Self-registration via SQLite:** `cline-core` registers itself in a SQLite database on startup. The CLI discovers instances by reading this database, enabling multi-instance support.
|
||||
|
||||
3. **Host bridge abstraction:** The `cline-host` process provides platform-specific operations (clipboard, workspace paths) via gRPC, allowing `cline-core` to remain host-agnostic.
|
||||
|
||||
4. **Streaming-first UI:** The CLI uses gRPC streaming to display AI responses in real-time with typewriter-style rendering.
|
||||
|
||||
5. **Dual stream handling:** Task manager subscribes to both state updates and partial messages, using deduplication to prevent duplicate rendering.
|
||||
@@ -78,6 +78,28 @@ These options apply to all subcommands:
|
||||
|
||||
: Output format. Options: **rich** (default), **json**, **plain**
|
||||
|
||||
When you use **-F json**, the CLI prints each client message as JSON.
|
||||
|
||||
Each message is a **ClineMessage** object.
|
||||
|
||||
Required fields:
|
||||
|
||||
- **type**: "ask" or "say"
|
||||
- **text**: message text
|
||||
- **ts**: Unix epoch timestamp in milliseconds
|
||||
|
||||
Optional fields (omitted when empty):
|
||||
|
||||
- **reasoning**: reasoning text
|
||||
- **say**: say subtype (present when type is "say")
|
||||
- **ask**: ask subtype (present when type is "ask")
|
||||
- **partial**: streaming flag
|
||||
- **images**: list of image URIs
|
||||
- **files**: list of file paths
|
||||
- **lastCheckpointHash**: git checkpoint hash
|
||||
- **isCheckpointCheckedOut**: checkpoint checkout flag
|
||||
- **isOperationOutsideWorkspace**: workspace safety flag
|
||||
|
||||
**-h**, **\--help**
|
||||
|
||||
: Display help information for the command.
|
||||
|
||||
@@ -9,12 +9,13 @@ import (
|
||||
"github.com/charmbracelet/bubbles/textarea"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/cline/cli/pkg/cli/slash"
|
||||
)
|
||||
|
||||
// InputType represents the type of input being collected
|
||||
type InputType int
|
||||
|
||||
const INPUT_WIDTH = 46
|
||||
const INPUT_WIDTH = 46
|
||||
|
||||
const (
|
||||
InputTypeMessage InputType = iota
|
||||
@@ -24,11 +25,11 @@ const (
|
||||
|
||||
// InputSubmitMsg is sent when the user submits input
|
||||
type InputSubmitMsg struct {
|
||||
Value string
|
||||
InputType InputType
|
||||
Approved bool // For approval type
|
||||
NeedsFeedback bool // For approval type
|
||||
NoAskAgain bool // For approval type - indicates "don't ask again" was selected
|
||||
Value string
|
||||
InputType InputType
|
||||
Approved bool // For approval type
|
||||
NeedsFeedback bool // For approval type
|
||||
NoAskAgain bool // For approval type - indicates "don't ask again" was selected
|
||||
}
|
||||
|
||||
// InputCancelMsg is sent when the user cancels input (Ctrl+C)
|
||||
@@ -36,8 +37,8 @@ type InputCancelMsg struct{}
|
||||
|
||||
// ChangeInputTypeMsg changes the current input type
|
||||
type ChangeInputTypeMsg struct {
|
||||
InputType InputType
|
||||
Title string
|
||||
InputType InputType
|
||||
Title string
|
||||
Placeholder string
|
||||
}
|
||||
|
||||
@@ -57,7 +58,7 @@ type InputModel struct {
|
||||
placeholder string
|
||||
currentMode string // "plan" or "act"
|
||||
width int
|
||||
lastHeight int // Track height for cleanup on submit
|
||||
lastHeight int // Track height for cleanup on submit
|
||||
|
||||
// For approval type
|
||||
approvalOptions []string
|
||||
@@ -66,6 +67,9 @@ type InputModel struct {
|
||||
|
||||
// Styles (huh-inspired theme)
|
||||
styles fieldStyles
|
||||
|
||||
// Slash command autocomplete dropdown
|
||||
completion CompletionModel
|
||||
}
|
||||
|
||||
// fieldStyles holds the styling for the input field
|
||||
@@ -115,12 +119,17 @@ func newFieldStyles() fieldStyles {
|
||||
|
||||
// NewInputModel creates a new input model
|
||||
func NewInputModel(inputType InputType, title, placeholder, currentMode string) InputModel {
|
||||
return NewInputModelWithRegistry(inputType, title, placeholder, currentMode, nil)
|
||||
}
|
||||
|
||||
// NewInputModelWithRegistry creates a new input model with slash command autocomplete support
|
||||
func NewInputModelWithRegistry(inputType InputType, title, placeholder, currentMode string, registry *slash.Registry) InputModel {
|
||||
ta := textarea.New()
|
||||
ta.Placeholder = placeholder
|
||||
ta.Focus()
|
||||
ta.CharLimit = 0
|
||||
ta.ShowLineNumbers = false
|
||||
ta.Prompt = "" // Remove prompt prefix (this is what adds the inner border!)
|
||||
ta.Prompt = "" // Remove prompt prefix (this is what adds the inner border!)
|
||||
ta.SetHeight(5)
|
||||
// Don't set width here - let WindowSizeMsg handle it
|
||||
ta.SetWidth(INPUT_WIDTH)
|
||||
@@ -138,11 +147,11 @@ func NewInputModel(inputType InputType, title, placeholder, currentMode string)
|
||||
cursorColor = lipgloss.Color("39") // Blue for act
|
||||
}
|
||||
|
||||
ta.FocusedStyle.CursorLine = lipgloss.NewStyle() // No cursor line highlighting
|
||||
ta.FocusedStyle.EndOfBuffer = lipgloss.NewStyle() // No end-of-buffer styling
|
||||
ta.FocusedStyle.CursorLine = lipgloss.NewStyle() // No cursor line highlighting
|
||||
ta.FocusedStyle.EndOfBuffer = lipgloss.NewStyle() // No end-of-buffer styling
|
||||
ta.FocusedStyle.Placeholder = styles.placeholder
|
||||
ta.FocusedStyle.Text = styles.textArea
|
||||
ta.FocusedStyle.Prompt = lipgloss.NewStyle() // No prompt styling
|
||||
ta.FocusedStyle.Prompt = lipgloss.NewStyle() // No prompt styling
|
||||
ta.Cursor.Style = lipgloss.NewStyle().Foreground(cursorColor)
|
||||
ta.Cursor.TextStyle = styles.textArea
|
||||
|
||||
@@ -154,6 +163,7 @@ func NewInputModel(inputType InputType, title, placeholder, currentMode string)
|
||||
currentMode: currentMode,
|
||||
width: 0, // Will be set by first WindowSizeMsg
|
||||
styles: styles,
|
||||
completion: NewCompletionModel(registry),
|
||||
}
|
||||
|
||||
// For approval type, set up options
|
||||
@@ -217,13 +227,6 @@ func (m *InputModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
return m, nil
|
||||
|
||||
default:
|
||||
// Forward all other messages to textarea (including blink ticks)
|
||||
if !m.suspended && (m.inputType == InputTypeMessage || m.inputType == InputTypeFeedback) {
|
||||
m.textarea, cmd = m.textarea.Update(msg)
|
||||
return m, cmd
|
||||
}
|
||||
|
||||
case tea.KeyMsg:
|
||||
if m.suspended {
|
||||
return m, nil
|
||||
@@ -231,6 +234,31 @@ func (m *InputModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
|
||||
// Handle keys for text input types (Message/Feedback)
|
||||
if m.inputType == InputTypeMessage || m.inputType == InputTypeFeedback {
|
||||
// When completion menu is visible, let it handle navigation keys first
|
||||
if m.completion.Visible() {
|
||||
// ctrl+c always cancels, even with dropdown open
|
||||
if msg.String() == "ctrl+c" {
|
||||
return m, func() tea.Msg { return InputCancelMsg{} }
|
||||
}
|
||||
|
||||
var handled bool
|
||||
m.completion, cmd, handled = m.completion.Update(msg)
|
||||
if handled {
|
||||
// Check if a completion was selected
|
||||
if applied := m.completion.Apply(); applied != "" {
|
||||
m.textarea.SetValue(applied)
|
||||
m.textarea.CursorEnd()
|
||||
}
|
||||
return m, cmd
|
||||
}
|
||||
|
||||
// Key not handled by completion - pass to textarea and update completion
|
||||
m.textarea, cmd = m.textarea.Update(msg)
|
||||
m.completion.CheckInput(m.textarea.Value())
|
||||
return m, cmd
|
||||
}
|
||||
|
||||
// Normal key handling when completion menu is NOT visible
|
||||
switch msg.String() {
|
||||
case "ctrl+c":
|
||||
return m, func() tea.Msg { return InputCancelMsg{} }
|
||||
@@ -239,6 +267,11 @@ func (m *InputModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
// Open external editor (like huh does)
|
||||
return m, m.openEditor()
|
||||
|
||||
case "tab":
|
||||
// Tab without dropdown visible - do nothing special
|
||||
m.textarea, cmd = m.textarea.Update(msg)
|
||||
return m, cmd
|
||||
|
||||
case "enter":
|
||||
// Intercept enter for submit (textarea handles alt+enter and ctrl+j for newlines)
|
||||
return m.handleSubmit()
|
||||
@@ -249,8 +282,9 @@ func (m *InputModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return m, cmd
|
||||
}
|
||||
|
||||
// Pass all other keys to textarea (including alt+enter, ctrl+j for newlines)
|
||||
// Pass all other keys to textarea, then check for slash completion
|
||||
m.textarea, cmd = m.textarea.Update(msg)
|
||||
m.completion.CheckInput(m.textarea.Value())
|
||||
return m, cmd
|
||||
}
|
||||
|
||||
@@ -276,6 +310,13 @@ func (m *InputModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return m, nil
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
// Forward all other messages to textarea (including blink ticks)
|
||||
if !m.suspended && (m.inputType == InputTypeMessage || m.inputType == InputTypeFeedback) {
|
||||
m.textarea, cmd = m.textarea.Update(msg)
|
||||
return m, cmd
|
||||
}
|
||||
}
|
||||
|
||||
return m, nil
|
||||
@@ -365,6 +406,11 @@ func (m *InputModel) View() string {
|
||||
case InputTypeMessage, InputTypeFeedback:
|
||||
parts = append(parts, m.textarea.View())
|
||||
|
||||
// Render completion dropdown if visible
|
||||
if m.completion.Visible() {
|
||||
parts = append(parts, m.completion.View())
|
||||
}
|
||||
|
||||
case InputTypeApproval:
|
||||
var options []string
|
||||
for i, option := range m.approvalOptions {
|
||||
@@ -411,7 +457,7 @@ func (m *InputModel) Clone() *InputModel {
|
||||
ta.ShowLineNumbers = false
|
||||
ta.Prompt = ""
|
||||
ta.SetHeight(5)
|
||||
ta.SetWidth(INPUT_WIDTH)
|
||||
ta.SetWidth(INPUT_WIDTH)
|
||||
ta.Focus()
|
||||
|
||||
// Configure keybindings
|
||||
@@ -446,6 +492,7 @@ func (m *InputModel) Clone() *InputModel {
|
||||
selectedOption: m.selectedOption,
|
||||
pendingApproval: m.pendingApproval, // Preserve approval decision
|
||||
styles: m.styles,
|
||||
completion: NewCompletionModel(m.completion.registry), // Preserve registry, start fresh state
|
||||
}
|
||||
|
||||
return clone
|
||||
@@ -495,3 +542,8 @@ func (m *InputModel) openEditor() tea.Cmd {
|
||||
return editorFinishedMsg{content: content, err: err}
|
||||
})
|
||||
}
|
||||
|
||||
// SetSlashRegistry sets the slash command registry for autocomplete
|
||||
func (m *InputModel) SetSlashRegistry(registry *slash.Registry) {
|
||||
m.completion.SetRegistry(registry)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,265 @@
|
||||
package output
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/cline/cli/pkg/cli/slash"
|
||||
)
|
||||
|
||||
const maxVisibleCompletions = 7
|
||||
|
||||
// completionStyles holds the styling for the completion dropdown
|
||||
type completionStyles struct {
|
||||
menu lipgloss.Style
|
||||
selected lipgloss.Style
|
||||
normalName lipgloss.Style
|
||||
description lipgloss.Style
|
||||
scrollIndicator lipgloss.Style
|
||||
}
|
||||
|
||||
// newCompletionStyles creates the default styles for the completion dropdown
|
||||
func newCompletionStyles() completionStyles {
|
||||
return completionStyles{
|
||||
menu: lipgloss.NewStyle().
|
||||
Border(lipgloss.RoundedBorder()).
|
||||
BorderForeground(lipgloss.Color("238")).
|
||||
Padding(0, 1),
|
||||
selected: lipgloss.NewStyle().
|
||||
Background(lipgloss.Color("62")).
|
||||
Foreground(lipgloss.Color("230")),
|
||||
normalName: lipgloss.NewStyle().
|
||||
Foreground(lipgloss.AdaptiveColor{Light: "235", Dark: "252"}),
|
||||
description: lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("243")),
|
||||
scrollIndicator: lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("243")),
|
||||
}
|
||||
}
|
||||
|
||||
// CompletionModel is a Bubbletea model for slash command autocomplete dropdown
|
||||
type CompletionModel struct {
|
||||
registry *slash.Registry
|
||||
visible bool
|
||||
matches []slash.Command
|
||||
index int // selected item (0-based)
|
||||
scroll int // scroll offset for long lists
|
||||
styles completionStyles
|
||||
|
||||
// pendingApply holds the command to apply after selection
|
||||
pendingApply string
|
||||
}
|
||||
|
||||
// NewCompletionModel creates a new completion model with the given registry
|
||||
func NewCompletionModel(registry *slash.Registry) CompletionModel {
|
||||
return CompletionModel{
|
||||
registry: registry,
|
||||
styles: newCompletionStyles(),
|
||||
}
|
||||
}
|
||||
|
||||
// SetRegistry sets the slash command registry
|
||||
func (m *CompletionModel) SetRegistry(registry *slash.Registry) {
|
||||
m.registry = registry
|
||||
}
|
||||
|
||||
// Visible returns whether the completion dropdown is currently visible
|
||||
func (m CompletionModel) Visible() bool {
|
||||
return m.visible
|
||||
}
|
||||
|
||||
// Update handles key messages for the completion dropdown.
|
||||
// Returns the updated model, any commands, and whether the key was handled.
|
||||
// If handled is true, the parent should NOT pass the key to the textarea.
|
||||
func (m CompletionModel) Update(msg tea.Msg) (CompletionModel, tea.Cmd, bool) {
|
||||
if !m.visible {
|
||||
return m, nil, false
|
||||
}
|
||||
|
||||
keyMsg, ok := msg.(tea.KeyMsg)
|
||||
if !ok {
|
||||
return m, nil, false
|
||||
}
|
||||
|
||||
switch keyMsg.String() {
|
||||
case "up":
|
||||
m.navigateUp()
|
||||
return m, nil, true
|
||||
|
||||
case "down":
|
||||
m.navigateDown()
|
||||
return m, nil, true
|
||||
|
||||
case "tab", "enter":
|
||||
// Select the current completion
|
||||
if len(m.matches) > 0 {
|
||||
selected := m.matches[m.index]
|
||||
m.pendingApply = "/" + selected.Name + " "
|
||||
}
|
||||
m.Hide()
|
||||
return m, nil, true
|
||||
|
||||
case "esc":
|
||||
m.Hide()
|
||||
return m, nil, true
|
||||
}
|
||||
|
||||
// Key not handled by completion - let parent process it
|
||||
return m, nil, false
|
||||
}
|
||||
|
||||
// CheckInput updates the completion state based on the current input value.
|
||||
// Call this after each input change to show/hide/update the dropdown.
|
||||
func (m *CompletionModel) CheckInput(value string) {
|
||||
if m.registry == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Only activate if input starts with "/" (first character requirement)
|
||||
if !strings.HasPrefix(value, "/") {
|
||||
m.Hide()
|
||||
return
|
||||
}
|
||||
|
||||
// Extract the command being typed (everything after "/" until space/newline)
|
||||
rest := value[1:] // Everything after the "/"
|
||||
|
||||
// If there's whitespace, the command is complete - hide dropdown
|
||||
if idx := strings.IndexAny(rest, " \n\t"); idx != -1 {
|
||||
m.Hide()
|
||||
return
|
||||
}
|
||||
|
||||
// Update matches based on prefix
|
||||
m.updateMatches(rest)
|
||||
m.visible = len(m.matches) > 0
|
||||
}
|
||||
|
||||
// Apply returns the command string to insert (if any) and clears the pending state.
|
||||
// The parent should call this after Update returns handled=true for tab/enter.
|
||||
func (m *CompletionModel) Apply() string {
|
||||
result := m.pendingApply
|
||||
m.pendingApply = ""
|
||||
return result
|
||||
}
|
||||
|
||||
// Hide hides the completion dropdown and resets state
|
||||
func (m *CompletionModel) Hide() {
|
||||
m.visible = false
|
||||
m.matches = nil
|
||||
m.index = 0
|
||||
m.scroll = 0
|
||||
}
|
||||
|
||||
// View renders the completion dropdown
|
||||
func (m CompletionModel) View() string {
|
||||
if !m.visible || len(m.matches) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
var lines []string
|
||||
|
||||
// Calculate visible range
|
||||
endIdx := min(m.scroll+maxVisibleCompletions, len(m.matches))
|
||||
|
||||
// Show scroll indicator if there are items above
|
||||
if m.scroll > 0 {
|
||||
lines = append(lines, m.styles.scrollIndicator.Render(" ↑ more"))
|
||||
}
|
||||
|
||||
// Find the longest command name for alignment
|
||||
maxNameLen := 0
|
||||
for _, cmd := range m.matches {
|
||||
nameLen := len(cmd.Name) + 1 // +1 for the "/"
|
||||
if nameLen > maxNameLen {
|
||||
maxNameLen = nameLen
|
||||
}
|
||||
}
|
||||
// Cap at reasonable width
|
||||
if maxNameLen > 15 {
|
||||
maxNameLen = 15
|
||||
}
|
||||
|
||||
// Render visible items
|
||||
for i := m.scroll; i < endIdx; i++ {
|
||||
cmd := m.matches[i]
|
||||
name := "/" + cmd.Name
|
||||
desc := cmd.Description
|
||||
|
||||
// Truncate description if too long
|
||||
maxDescLen := 35
|
||||
if len(desc) > maxDescLen {
|
||||
desc = desc[:maxDescLen-3] + "..."
|
||||
}
|
||||
|
||||
// Pad name for alignment
|
||||
paddedName := fmt.Sprintf("%-*s", maxNameLen, name)
|
||||
|
||||
if i == m.index {
|
||||
// Selected item - highlight the entire line
|
||||
line := fmt.Sprintf("> %s %s", paddedName, desc)
|
||||
lines = append(lines, m.styles.selected.Render(line))
|
||||
} else {
|
||||
// Normal item
|
||||
line := fmt.Sprintf(" %s %s", m.styles.normalName.Render(paddedName), m.styles.description.Render(desc))
|
||||
lines = append(lines, line)
|
||||
}
|
||||
}
|
||||
|
||||
// Show scroll indicator if there are items below
|
||||
if endIdx < len(m.matches) {
|
||||
lines = append(lines, m.styles.scrollIndicator.Render(" ↓ more"))
|
||||
}
|
||||
|
||||
return m.styles.menu.Render(strings.Join(lines, "\n"))
|
||||
}
|
||||
|
||||
// updateMatches filters commands by prefix and updates the matches list
|
||||
func (m *CompletionModel) updateMatches(prefix string) {
|
||||
if m.registry == nil {
|
||||
m.matches = nil
|
||||
return
|
||||
}
|
||||
m.matches = m.registry.GetMatching(prefix)
|
||||
// Reset selection if out of bounds
|
||||
if m.index >= len(m.matches) {
|
||||
m.index = 0
|
||||
m.scroll = 0
|
||||
}
|
||||
m.adjustScroll()
|
||||
}
|
||||
|
||||
// navigateUp moves selection up in the dropdown
|
||||
func (m *CompletionModel) navigateUp() {
|
||||
if len(m.matches) == 0 {
|
||||
return
|
||||
}
|
||||
m.index--
|
||||
if m.index < 0 {
|
||||
m.index = len(m.matches) - 1
|
||||
}
|
||||
m.adjustScroll()
|
||||
}
|
||||
|
||||
// navigateDown moves selection down in the dropdown
|
||||
func (m *CompletionModel) navigateDown() {
|
||||
if len(m.matches) == 0 {
|
||||
return
|
||||
}
|
||||
m.index++
|
||||
if m.index >= len(m.matches) {
|
||||
m.index = 0
|
||||
}
|
||||
m.adjustScroll()
|
||||
}
|
||||
|
||||
// adjustScroll ensures the selected item is visible in the dropdown
|
||||
func (m *CompletionModel) adjustScroll() {
|
||||
if m.index < m.scroll {
|
||||
m.scroll = m.index
|
||||
} else if m.index >= m.scroll+maxVisibleCompletions {
|
||||
m.scroll = m.index - maxVisibleCompletions + 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package slash
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/cline/grpc-go/client"
|
||||
"github.com/cline/grpc-go/cline"
|
||||
)
|
||||
|
||||
// Command represents a slash command available for autocomplete
|
||||
type Command struct {
|
||||
Name string
|
||||
Description string
|
||||
Section string // "default", "custom", or "cli"
|
||||
CLICompatible bool
|
||||
}
|
||||
|
||||
// Registry holds available slash commands for autocomplete
|
||||
type Registry struct {
|
||||
mu sync.RWMutex
|
||||
commands []Command
|
||||
}
|
||||
|
||||
// CLI-local commands (handled by CLI, not sent to backend)
|
||||
var cliLocalCommands = []Command{
|
||||
{Name: "plan", Description: "Switch to plan mode", Section: "cli", CLICompatible: true},
|
||||
{Name: "act", Description: "Switch to act mode", Section: "cli", CLICompatible: true},
|
||||
{Name: "cancel", Description: "Cancel the current task", Section: "cli", CLICompatible: true},
|
||||
{Name: "exit", Description: "Exit follow mode", Section: "cli", CLICompatible: true},
|
||||
}
|
||||
|
||||
// NewRegistry creates a new slash command registry
|
||||
func NewRegistry() *Registry {
|
||||
return &Registry{
|
||||
commands: make([]Command, 0),
|
||||
}
|
||||
}
|
||||
|
||||
// FetchFromBackend fetches available commands from cline-core backend
|
||||
func (r *Registry) FetchFromBackend(ctx context.Context, c *client.ClineClient) error {
|
||||
resp, err := c.Slash.GetAvailableSlashCommands(ctx, &cline.EmptyRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
// Start with CLI-local commands
|
||||
r.commands = append([]Command{}, cliLocalCommands...)
|
||||
|
||||
// Add backend commands (only CLI-compatible ones)
|
||||
for _, cmd := range resp.Commands {
|
||||
if cmd.CliCompatible {
|
||||
r.commands = append(r.commands, Command{
|
||||
Name: cmd.Name,
|
||||
Description: cmd.Description,
|
||||
Section: cmd.Section,
|
||||
CLICompatible: cmd.CliCompatible,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetCommands returns all available commands
|
||||
func (r *Registry) GetCommands() []Command {
|
||||
r.mu.RLock()
|
||||
defer r.mu.RUnlock()
|
||||
|
||||
// Return a copy to avoid race conditions
|
||||
result := make([]Command, len(r.commands))
|
||||
copy(result, r.commands)
|
||||
return result
|
||||
}
|
||||
|
||||
// GetMatching returns commands that start with the given prefix (case-insensitive)
|
||||
func (r *Registry) GetMatching(prefix string) []Command {
|
||||
r.mu.RLock()
|
||||
defer r.mu.RUnlock()
|
||||
|
||||
prefix = strings.ToLower(prefix)
|
||||
var matches []Command
|
||||
for _, cmd := range r.commands {
|
||||
if strings.HasPrefix(strings.ToLower(cmd.Name), prefix) {
|
||||
matches = append(matches, cmd)
|
||||
}
|
||||
}
|
||||
return matches
|
||||
}
|
||||
|
||||
// IsValid checks if a command name is valid
|
||||
func (r *Registry) IsValid(name string) bool {
|
||||
r.mu.RLock()
|
||||
defer r.mu.RUnlock()
|
||||
|
||||
name = strings.ToLower(name)
|
||||
for _, cmd := range r.commands {
|
||||
if strings.ToLower(cmd.Name) == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCLILocal checks if a command is handled locally by CLI (not sent to backend)
|
||||
func (r *Registry) IsCLILocal(name string) bool {
|
||||
name = strings.ToLower(name)
|
||||
for _, cmd := range cliLocalCommands {
|
||||
if strings.ToLower(cmd.Name) == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// HasCommands returns true if the registry has any commands loaded
|
||||
func (r *Registry) HasCommands() bool {
|
||||
r.mu.RLock()
|
||||
defer r.mu.RUnlock()
|
||||
return len(r.commands) > 0
|
||||
}
|
||||
@@ -38,13 +38,13 @@ type InputHandler struct {
|
||||
// NewInputHandler creates a new input handler
|
||||
func NewInputHandler(manager *Manager, coordinator *StreamCoordinator, cancelFunc context.CancelFunc) *InputHandler {
|
||||
return &InputHandler{
|
||||
manager: manager,
|
||||
coordinator: coordinator,
|
||||
cancelFunc: cancelFunc,
|
||||
isRunning: false,
|
||||
pollTicker: time.NewTicker(500 * time.Millisecond),
|
||||
resultChan: make(chan output.InputSubmitMsg, 1),
|
||||
cancelChan: make(chan struct{}, 1),
|
||||
manager: manager,
|
||||
coordinator: coordinator,
|
||||
cancelFunc: cancelFunc,
|
||||
isRunning: false,
|
||||
pollTicker: time.NewTicker(500 * time.Millisecond),
|
||||
resultChan: make(chan output.InputSubmitMsg, 1),
|
||||
cancelChan: make(chan struct{}, 1),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,11 +281,12 @@ func determineAutoApprovalAction(msg *types.ClineMessage) (string, error) {
|
||||
func (ih *InputHandler) promptForInput(ctx context.Context) (string, bool, error) {
|
||||
currentMode := ih.manager.GetCurrentMode()
|
||||
|
||||
model := output.NewInputModel(
|
||||
model := output.NewInputModelWithRegistry(
|
||||
output.InputTypeMessage,
|
||||
"Cline is ready for your message...",
|
||||
"/plan or /act to switch modes\nctrl+e to open editor",
|
||||
"/plan or /act to switch modes\nctrl+e to open editor\ntab to autocomplete commands",
|
||||
currentMode,
|
||||
ih.manager.GetSlashRegistry(),
|
||||
)
|
||||
|
||||
return ih.runInputProgram(ctx, model)
|
||||
@@ -295,12 +296,13 @@ func (ih *InputHandler) promptForInput(ctx context.Context) (string, bool, error
|
||||
func (ih *InputHandler) promptForApproval(ctx context.Context, msg *types.ClineMessage) (bool, string, error) {
|
||||
// Store the approval message for later use in determining auto-approval action
|
||||
ih.approvalMessage = msg
|
||||
|
||||
model := output.NewInputModel(
|
||||
|
||||
model := output.NewInputModelWithRegistry(
|
||||
output.InputTypeApproval,
|
||||
"Let Cline use this tool?",
|
||||
"",
|
||||
ih.manager.GetCurrentMode(),
|
||||
ih.manager.GetSlashRegistry(), // Pass registry for feedback input after approval
|
||||
)
|
||||
|
||||
message, shouldSend, err := ih.runInputProgram(ctx, model)
|
||||
@@ -395,7 +397,7 @@ func (ih *InputHandler) runInputProgram(ctx context.Context, model output.InputM
|
||||
// Need to collect feedback - will be handled by model state change
|
||||
return "", false, nil
|
||||
}
|
||||
|
||||
|
||||
// Check if NoAskAgain was selected
|
||||
if result.NoAskAgain && result.Approved && ih.approvalMessage != nil {
|
||||
// Determine which auto-approval action to enable
|
||||
@@ -411,7 +413,7 @@ func (ih *InputHandler) runInputProgram(ctx context.Context, model output.InputM
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Store approval state for when feedback comes back
|
||||
ih.feedbackApproval = false
|
||||
ih.feedbackApproved = result.Approved
|
||||
@@ -441,6 +443,7 @@ func (w *inputProgramWrapper) Init() tea.Cmd {
|
||||
}
|
||||
|
||||
func (w *inputProgramWrapper) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
|
||||
switch msg := msg.(type) {
|
||||
case output.InputSubmitMsg:
|
||||
// Handle input submission - clear the screen before quitting
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/cline/cli/pkg/cli/display"
|
||||
"github.com/cline/cli/pkg/cli/global"
|
||||
"github.com/cline/cli/pkg/cli/handlers"
|
||||
"github.com/cline/cli/pkg/cli/slash"
|
||||
"github.com/cline/cli/pkg/cli/types"
|
||||
"github.com/cline/grpc-go/client"
|
||||
"github.com/cline/grpc-go/cline"
|
||||
@@ -36,6 +37,7 @@ type Manager struct {
|
||||
systemRenderer *display.SystemMessageRenderer
|
||||
streamingDisplay *display.StreamingDisplay
|
||||
handlerRegistry *handlers.HandlerRegistry
|
||||
slashRegistry *slash.Registry
|
||||
isStreamingMode bool
|
||||
isInteractive bool
|
||||
currentMode string // "plan" or "act"
|
||||
@@ -63,6 +65,7 @@ func NewManager(client *client.ClineClient) *Manager {
|
||||
systemRenderer: systemRenderer,
|
||||
streamingDisplay: streamingDisplay,
|
||||
handlerRegistry: registry,
|
||||
slashRegistry: slash.NewRegistry(),
|
||||
currentMode: "plan", // Default mode
|
||||
}
|
||||
}
|
||||
@@ -76,6 +79,10 @@ func NewManagerForAddress(ctx context.Context, address string) (*Manager, error)
|
||||
|
||||
manager := NewManager(client)
|
||||
manager.clientAddress = address
|
||||
|
||||
// Fetch slash commands from backend (non-blocking, errors are logged)
|
||||
manager.fetchSlashCommands(ctx)
|
||||
|
||||
return manager, nil
|
||||
}
|
||||
|
||||
@@ -93,9 +100,25 @@ func NewManagerForDefault(ctx context.Context) (*Manager, error) {
|
||||
manager.clientAddress = global.Clients.GetRegistry().GetDefaultInstance()
|
||||
}
|
||||
|
||||
// Fetch slash commands from backend (non-blocking, errors are logged)
|
||||
manager.fetchSlashCommands(ctx)
|
||||
|
||||
return manager, nil
|
||||
}
|
||||
|
||||
// fetchSlashCommands fetches available slash commands from the backend
|
||||
// This is non-blocking and errors are logged but don't prevent manager creation
|
||||
func (m *Manager) fetchSlashCommands(ctx context.Context) {
|
||||
if err := m.slashRegistry.FetchFromBackend(ctx, m.client); err != nil {
|
||||
if global.Config.Verbose {
|
||||
m.renderer.RenderDebug("Failed to fetch slash commands: %v", err)
|
||||
}
|
||||
// Non-fatal: CLI-local commands are still available
|
||||
} else if global.Config.Verbose {
|
||||
m.renderer.RenderDebug("Loaded %d slash commands", len(m.slashRegistry.GetCommands()))
|
||||
}
|
||||
}
|
||||
|
||||
// SwitchToInstance switches the manager to use a different Cline instance
|
||||
func (m *Manager) SwitchToInstance(ctx context.Context, address string) error {
|
||||
m.mu.Lock()
|
||||
@@ -1263,6 +1286,11 @@ func (m *Manager) GetCurrentMode() string {
|
||||
return m.currentMode
|
||||
}
|
||||
|
||||
// GetSlashRegistry returns the slash command registry
|
||||
func (m *Manager) GetSlashRegistry() *slash.Registry {
|
||||
return m.slashRegistry
|
||||
}
|
||||
|
||||
// extractModeFromState extracts the current mode from state JSON
|
||||
func (m *Manager) extractModeFromState(stateJson string) string {
|
||||
var rawState map[string]interface{}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
---
|
||||
title: "ACP Integration (Zed + Custom Clients)"
|
||||
description: "Run Cline as an Agent Client Protocol (ACP) server and connect it to Zed or any ACP-compatible client."
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
Cline ships an ACP-compatible stdio server so you can run it inside editors like Zed or any client that speaks the Agent Client Protocol.
|
||||
|
||||
The ACP entrypoint lives at `dist-standalone/cline-acp.js` after building the standalone bundle.
|
||||
|
||||
## Build the ACP server
|
||||
|
||||
From the Cline repo root:
|
||||
|
||||
```bash
|
||||
npm install
|
||||
npm run compile-standalone
|
||||
```
|
||||
|
||||
The ACP server will be available at:
|
||||
|
||||
```text
|
||||
dist-standalone/cline-acp.js
|
||||
```
|
||||
|
||||
## Run manually
|
||||
|
||||
```bash
|
||||
node dist-standalone/cline-acp.js --config ~/.cline
|
||||
```
|
||||
|
||||
Notes:
|
||||
|
||||
- `--config` sets the Cline data directory (same as `CLINE_DIR`). If omitted, Cline defaults to `~/.cline`.
|
||||
- Logs go to stderr to keep ACP JSON-RPC traffic clean on stdout.
|
||||
|
||||
## Connect to Zed
|
||||
|
||||
Add a custom ACP agent to your Zed `settings.json` (open with `zed: open settings`):
|
||||
|
||||
```json [settings]
|
||||
{
|
||||
"agent_servers": {
|
||||
"Cline (ACP)": {
|
||||
"type": "custom",
|
||||
"command": "node",
|
||||
"args": [
|
||||
"/absolute/path/to/cline/dist-standalone/cline-acp.js",
|
||||
"--config",
|
||||
"/absolute/path/to/.cline"
|
||||
],
|
||||
"env": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Then open the Agent Panel in Zed and start a new thread for **Cline (ACP)**.
|
||||
|
||||
Zed will:
|
||||
|
||||
- Provide the workspace `cwd` for each session.
|
||||
- Forward MCP servers you configured in Zed to Cline over ACP.
|
||||
|
||||
## Limitations
|
||||
|
||||
- Cline currently supports one ACP session at a time; starting a new session closes the previous one.
|
||||
- Some Cline UI affordances (like special buttons for "start new task") are represented as standard prompts in ACP clients.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
- Check Zed’s ACP logs (`Help` → `Open ACP Logs`) if the agent fails to start.
|
||||
- Ensure the path to `cline-acp.js` is absolute and your Node binary is on `PATH`.
|
||||
@@ -278,6 +278,29 @@ TASK SETTINGS
|
||||
|
||||
mode Starting mode (act/plan)
|
||||
|
||||
hooks_enabled
|
||||
Enable or disable hooks for the task (true/false)
|
||||
|
||||
HOOKS INTEGRATION
|
||||
Hooks let you inject custom logic into Cline's workflow at key moments.
|
||||
They can validate operations before they execute, monitor tool usage,
|
||||
and shape AI decisions. This allows you to integrate hooks into
|
||||
automated workflows, CI/CD pipelines, and headless task execution.
|
||||
|
||||
Enable hooks for a task:
|
||||
|
||||
cline "prompt" -s hooks_enabled=true
|
||||
|
||||
Configure hooks globally:
|
||||
|
||||
cline config set hooks-enabled=true
|
||||
cline config get hooks-enabled
|
||||
|
||||
Note: Hooks in the CLI are only supported on macOS and Linux.
|
||||
|
||||
For complete hooks documentation, see:
|
||||
<https://docs.cline.bot/features/hooks/index>
|
||||
|
||||
NOTES & EXAMPLES
|
||||
The cline task send and cline task new commands support reading from
|
||||
stdin, enabling powerful pipeline compositions:
|
||||
@@ -348,6 +371,43 @@ COPYRIGHT
|
||||
Copyright © 2025 Cline Bot Inc. Licensed under the Apache License 2.0.
|
||||
```
|
||||
|
||||
## JSON output (-F json)
|
||||
|
||||
When you run a command with `-F json` (or `--output-format json`), Cline prints each client message as JSON.
|
||||
|
||||
### ClineMessage schema
|
||||
|
||||
| Field | Type | Required | Notes |
|
||||
|-------|------|----------|-------|
|
||||
| `type` | `"ask" or "say"` | Yes | Top-level message category. |
|
||||
| `text` | `string` | Yes | Human-readable message content. |
|
||||
| `ts` | `number` | Yes | Unix epoch timestamp in milliseconds. |
|
||||
| `reasoning` | `string` | No | Omitted when empty. |
|
||||
| `say` | `string` | No | Omitted when empty. Present when `type` is `"say"`. |
|
||||
| `ask` | `string` | No | Omitted when empty. Present when `type` is `"ask"`. |
|
||||
| `partial` | `boolean` | No | Omitted when false. `true` for streaming updates. |
|
||||
| `images` | `string[]` | No | Omitted when empty. Image URIs when included with a message. |
|
||||
| `files` | `string[]` | No | Omitted when empty. File paths when attached to a message. |
|
||||
| `lastCheckpointHash` | `string` | No | Omitted when empty. Git checkpoint hash when available. |
|
||||
| `isCheckpointCheckedOut` | `boolean` | No | Omitted when false. `true` if Cline checked out a checkpoint. |
|
||||
| `isOperationOutsideWorkspace` | `boolean` | No | Omitted when false. `true` if an operation happened outside the workspace. |
|
||||
|
||||
<Note>
|
||||
Most fields are optional and omitted when empty. If you parse this output, treat missing fields as “not present”, not as empty strings.
|
||||
</Note>
|
||||
|
||||
### Example
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "say",
|
||||
"text": "Cline is about to run a command.",
|
||||
"ts": 1760501486669,
|
||||
"say": "command",
|
||||
"partial": false
|
||||
}
|
||||
```
|
||||
|
||||
### Shell Completion
|
||||
|
||||
Generate autocompletion scripts for various shells:
|
||||
|
||||
@@ -57,6 +57,20 @@ During installation, you'll authenticate and configure your preferred provider u
|
||||
- Create GitLab pipelines that generate migration scripts from schema changes
|
||||
- Build Jenkins jobs that use Cline to analyze test failures and suggest fixes
|
||||
|
||||
## Hooks integration
|
||||
|
||||
[Hooks](/features/hooks/index) let you inject custom logic into Cline's workflow to validate operations and enforce policies. You can enable hooks when running tasks from the command line:
|
||||
|
||||
```bash
|
||||
# Enable hooks for a task
|
||||
cline "What does this repo do?" -s hooks_enabled=true
|
||||
|
||||
# Configure hooks globally via CLI
|
||||
cline config set hooks-enabled=true
|
||||
```
|
||||
|
||||
This allows you to integrate hooks into automated workflows, CI/CD pipelines, and headless task execution for consistent enforcement across all environments.
|
||||
|
||||
## Learn more
|
||||
|
||||
<Columns cols={2}>
|
||||
|
||||
@@ -88,6 +88,7 @@
|
||||
"cline-cli/overview",
|
||||
"cline-cli/installation",
|
||||
"cline-cli/three-core-flows",
|
||||
"cline-cli/acp",
|
||||
{
|
||||
"group": "CLI Samples",
|
||||
"pages": [
|
||||
|
||||
@@ -1,59 +1,104 @@
|
||||
The Auto Approve menu lets you set fine-grained permissions on what you allow Cline to do in an automated way.
|
||||
---
|
||||
title: "Auto Approve"
|
||||
sidebarTitle: "Auto Approve"
|
||||
description: "Let Cline take specific actions without asking for approval every time."
|
||||
---
|
||||
|
||||
Auto Approve lets you decide which actions Cline can take without prompting you each time. It keeps you out of approval popups during routine work, while still letting you keep tight control over high-risk actions.
|
||||
|
||||
If you find yourself repeatedly clicking approve for the same safe operations, Auto Approve is the setting that fixes that. The goal is fewer interruptions without losing the ability to review changes when it matters.
|
||||
|
||||
<Frame>
|
||||
<img src="https://storage.googleapis.com/cline_public_images/docs/assets/auto-approve.png" alt="Auto Approve" />
|
||||
<video
|
||||
style={{ width: "100%" }}
|
||||
src="https://storage.googleapis.com/cline_public_images/autoapprove.mp4"
|
||||
autoPlay
|
||||
controls
|
||||
playsInline
|
||||
/>
|
||||
</Frame>
|
||||
|
||||
## How it works
|
||||
|
||||
By default, Cline will ask for your permission before calling any tool, including reading or writing files.
|
||||
Auto Approve is evaluated per tool call. When Cline is about to read a file, edit a file, run a command, or use the browser, Cline checks your Auto Approve settings for that category.
|
||||
|
||||
If you want to allow Cline to do something without asking, you can set the Auto Approve permission for that tool.
|
||||
A few details matter in practice:
|
||||
|
||||
## Permission Options
|
||||
- **Workspace vs outside your workspace**: “Read all files” and “Edit all files” only extend the base toggle. If the base toggle is off, the “all files” option does nothing.
|
||||
|
||||
- **Read project files**
|
||||
- **Terminal commands**: Cline treats terminal commands as either safe or requiring approval. “Execute safe commands” covers the first category. “Execute all commands” extends this to commands flagged as requiring approval.
|
||||
|
||||
- Allows Cline to read files within your current workspace without asking
|
||||
- **Read all files**
|
||||
- Extends read permission to files outside your workspace (system files, config files, etc.)
|
||||
- **Notifications**: If enabled, Cline sends OS-level notifications when approval is required, and when an auto-approved terminal command has been running for 30 seconds and may need attention.
|
||||
|
||||
- **Edit project files**
|
||||
<Note>
|
||||
[YOLO mode](/features/yolo-mode) bypasses these granular approvals.
|
||||
</Note>
|
||||
|
||||
- Allows Cline to modify files within your current workspace without confirmation
|
||||
- **Edit all files**
|
||||
- Extends modification permission to files outside your workspace
|
||||
## Permissions
|
||||
|
||||
- **Execute safe commands**
|
||||
These labels match what you see in the Auto Approve menu.
|
||||
|
||||
- Allows execution of terminal commands that the model deems non-destructive
|
||||
- **Execute all commands**
|
||||
- Permits execution of any terminal command without asking
|
||||
| Setting | What it allows | Notes |
|
||||
|--------|-----------------|------|
|
||||
| Read project files | Read files, list files, search in your workspace | Good default for most tasks |
|
||||
| Read all files | Read files outside your workspace | Requires “Read project files” |
|
||||
| Edit project files | Create and edit files in your workspace | Consider using checkpoints |
|
||||
| Edit all files | Edit files outside your workspace | Requires “Edit project files” |
|
||||
| Execute safe commands | Run terminal commands marked safe | Can still run long |
|
||||
| Execute all commands | Run commands marked as requiring approval | Requires “Execute safe commands” |
|
||||
| Use the browser | Allows use of the browser tool for web fetching and searching | Proxy issues can apply |
|
||||
| Use MCP servers | Use MCP tools and access MCP resources | Some servers also have per-tool auto-approve |
|
||||
| Enable notifications | Notifies you about long-running auto-approved commands | Helpful for terminal work |
|
||||
|
||||
- **Use the browser**
|
||||
<Warning>
|
||||
“Read all files” and “Edit all files” only matter if their base toggle is enabled. They extend access outside your workspace.
|
||||
</Warning>
|
||||
|
||||
- Allows Cline to use the browser tool to fetch web content
|
||||
<Card title="Networking & proxies" icon="globe" href="/troubleshooting/networking-and-proxies">
|
||||
If browser-based tools fail in corporate networks, this page covers the common fixes.
|
||||
</Card>
|
||||
|
||||
- **Use MCP servers**
|
||||
## Safe vs approval-required command examples
|
||||
|
||||
- Permits connection to and usage of MCP servers for extended functionality
|
||||
Cline does not use a fixed allowlist of safe or unsafe commands. The model marks each command with a `requires_approval` flag based on the command and its arguments, and Auto Approve uses that flag.
|
||||
|
||||
- **Maximum requests**
|
||||
- Sets the number of consecutive automated actions Cline can take before requiring your input
|
||||
These are examples, not guarantees.
|
||||
|
||||
## Best Practices
|
||||
### Commonly treated as safe
|
||||
|
||||
Personally, I like to keep auto-editing disabled because it gives me a chance to review changes every step of the way.
|
||||
| Example | Why it is usually safe |
|
||||
|--------|-------------------------|
|
||||
| `npm run build` | Build output, no direct file deletions |
|
||||
| `npm test` | Runs tests |
|
||||
| `git status` | Read-only |
|
||||
| `ls -la` | Read-only |
|
||||
| `cat package.json` | Read-only |
|
||||
|
||||
For most serious development workflows, I recommend starting with:
|
||||
### Commonly requires approval
|
||||
|
||||
- Auto-approving read access to project files
|
||||
- Setting a reasonable maximum request limit (10-20)
|
||||
| Example | Why it often needs approval |
|
||||
|--------|------------------------------|
|
||||
| `npm install <pkg>` | Modifies dependencies and lockfiles |
|
||||
| `rm -rf <path>` | Deletes files |
|
||||
| `mv <a> <b>` | Moves files (can overwrite) |
|
||||
| `sed -i ...` | In-place file edits |
|
||||
| `curl https://...` | Downloads and executes remote code |
|
||||
|
||||
This gives Cline enough freedom to explore your codebase without constant interruptions, while still requiring permission for edits or potentially destructive actions.
|
||||
<Note>
|
||||
Whether a command is treated as safe depends on the exact command, flags, and the current task. When in doubt, keep command auto-approval off and approve commands manually.
|
||||
</Note>
|
||||
|
||||
As you build more trust in Cline's capabilities with your specific projects, you can gradually increase the permissions to match your comfort level.
|
||||
## Enable notifications
|
||||
|
||||
Remember that you can always adjust these settings as your needs change - tighten permissions for critical production work, or loosen them when prototyping and exploring.
|
||||
Auto-approved actions can run for a while, especially long terminal commands. If you enable notifications, Cline can notify you when an auto-approved command has been running for a while and may need attention.
|
||||
|
||||
You can even use the quick "star" actions to quickly toggle your auto-approved selections on and off as you go.
|
||||
## Recommendations
|
||||
|
||||
A good default setup is:
|
||||
|
||||
- Enable **Read project files**
|
||||
- Leave **Edit project files**, **Execute safe commands**, **Use the browser**, and **Use MCP servers** off until you have a specific reason to enable them
|
||||
|
||||
If you enable edits, use [Checkpoints](/features/checkpoints) so you can roll back quickly.
|
||||
|
||||
If you’re working in a sensitive environment (production credentials, personal files, corporate devices), keep external file access and command execution locked down and approve actions manually as you go.
|
||||
|
||||
@@ -3,94 +3,192 @@ title: "Keyboard Shortcuts"
|
||||
sidebarTitle: "Keyboard Shortcuts"
|
||||
---
|
||||
|
||||
Cline's keyboard shortcuts let you access AI assistance without taking your hands off the keyboard. Speed up your workflow by using hotkeys for common Cline actions.
|
||||
Speed up your workflow by accessing Cline's AI assistance without taking your hands off the keyboard.
|
||||
|
||||
## Default Keyboard Shortcuts
|
||||
<Tip>
|
||||
**The One Shortcut You Need:** `Ctrl+'` (Windows/Linux) or `Cmd+'` (macOS)
|
||||
|
||||
Cline comes with the following built-in keyboard shortcuts to streamline your workflow:
|
||||
This context-aware shortcut handles your most common needs:
|
||||
- **With text selected:** Adds code to Cline chat
|
||||
- **Without selection:** Focuses the chat input
|
||||
|
||||
| Action | Windows/Linux | macOS | Condition | Description |
|
||||
| ----------------------- | ------------- | ------- | ---------------------------- | ----------------------------------------- |
|
||||
| Add to Cline | `Ctrl+'` | `Cmd+'` | When text is selected | Adds selected code to Cline chat |
|
||||
| Focus Chat Input | `Ctrl+'` | `Cmd+'` | When no text is selected | Focuses the Cline chat input field |
|
||||
| Generate Commit Message | (unset) | (unset) | When Git is the SCM provider | Available through the Source Control view |
|
||||
Master this one shortcut, and you're 90% there.
|
||||
</Tip>
|
||||
|
||||
## Available Commands for Custom Shortcuts
|
||||
## Default Shortcuts
|
||||
|
||||
While Cline has only a few default keyboard shortcuts, you can assign your own shortcuts to any of these commands:
|
||||
Cline has minimal default shortcuts by design, so they won't conflict with your existing VSCode setup:
|
||||
|
||||
| Command ID | Description |
|
||||
| ---------------------------------------------------------------------------------------- | --------------------------------------------- |
|
||||
| [`cline.addToChat`](/features/commands-and-shortcuts/code-commands) | Adds selected code to Cline chat |
|
||||
| [`cline.addTerminalOutputToChat`](/features/commands-and-shortcuts/terminal-integration) | Adds terminal output to Cline |
|
||||
| `cline.focusChatInput` | Focuses the Cline chat input field |
|
||||
| [`cline.generateGitCommitMessage`](/features/commands-and-shortcuts/git-integration) | Generates a commit message for staged changes |
|
||||
| [`cline.explainCode`](/features/commands-and-shortcuts/code-commands) | Explains selected code |
|
||||
| [`cline.improveCode`](/features/commands-and-shortcuts/code-commands) | Suggests improvements for selected code |
|
||||
| [`cline.fixWithCline`](/features/commands-and-shortcuts/code-commands) | Fixes code with errors |
|
||||
| `claude-dev.SidebarProvider.focus` | Opens and focuses the Cline sidebar |
|
||||
| Shortcut | Windows/Linux | macOS | What It Does |
|
||||
| -------- | ------------- | ----- | ------------ |
|
||||
| **Add to Chat / Focus Input** | `Ctrl+'` | `Cmd+'` | Context-aware: adds selected code or focuses chat |
|
||||
|
||||
## Customizing Keyboard Shortcuts
|
||||
That's it! Everything else is available for you to customize.
|
||||
|
||||
You can customize Cline's keyboard shortcuts to match your preferences:
|
||||
## Quick Workflow Examples
|
||||
|
||||
1. Open the Keyboard Shortcuts editor in VSCode:
|
||||
Here's how keyboard shortcuts fit into real coding workflows:
|
||||
|
||||
- Press `Ctrl+K Ctrl+S` (Windows/Linux) or `Cmd+K Cmd+S` (macOS)
|
||||
- Or go to File > Preferences > Keyboard Shortcuts
|
||||
### Debug & Fix Workflow
|
||||
|
||||
2. Search for "Cline" to see all available commands
|
||||
1. **Find error in code** → VSCode highlights it
|
||||
2. **Select the problematic code** → `Shift+Arrow` or `Ctrl+L` / `Cmd+L`
|
||||
3. **Send to Cline** → `Ctrl+'` / `Cmd+'`
|
||||
4. **Ask for help** → Type your question, hit `Enter`
|
||||
|
||||
3. Click on the pencil icon next to any command to change its shortcut
|
||||
### Code Review Workflow
|
||||
|
||||
4. Press the keys you want to assign to that command
|
||||
1. **Review a function** → Select it with `Ctrl+L` / `Cmd+L`
|
||||
2. **Get AI review** → `Ctrl+'` / `Cmd+'` then ask "Review this"
|
||||
3. **Iterate** → Apply suggestions and repeat
|
||||
|
||||
5. Press Enter to save the new shortcut
|
||||
### Terminal Integration Workflow
|
||||
|
||||
## Suggested Custom Shortcuts
|
||||
1. **Open terminal** → Press `` Ctrl+` `` / `` Cmd+` ``
|
||||
2. **Run your command** → Execute in terminal
|
||||
3. **Capture output** → Press `Alt+T` (after assigning shortcut)
|
||||
4. **Get help** → Ask Cline to interpret errors or output
|
||||
|
||||
Here are some suggested shortcuts you might find useful:
|
||||
<Info>
|
||||
**Pro Tip:** Assign `Alt+T` to the `cline.addTerminalOutputToChat` command for quick terminal output capture. Without a shortcut, you can still right-click in the terminal and select "Add to Cline" - but the keyboard approach is much faster for frequent debugging workflows.
|
||||
</Info>
|
||||
|
||||
| Action | Suggested Shortcut | Command ID | Description |
|
||||
| --------------------- | ------------------------------ | ----------------------------------------- | ----------------------------- |
|
||||
| Open Cline Sidebar | `Ctrl+Shift+C` / `Cmd+Shift+C` | `claude-dev.SidebarProvider.focus` | Opens the Cline sidebar panel |
|
||||
| New Task | `Alt+N` | `cline.plusButtonClicked` | Starts a new Cline task |
|
||||
| Add Terminal to Cline | `Alt+T` | `cline.addTerminalOutputToChat` | Adds terminal output to Cline |
|
||||
| Clear Current Task | `Alt+C` | (Requires custom keybinding to UI action) | Clears the current task |
|
||||
## Customizing Shortcuts
|
||||
|
||||
## Keyboard-Only Workflow
|
||||
Want to assign shortcuts to more Cline commands? Here's how:
|
||||
|
||||
With the right shortcuts, you can use Cline without ever touching the mouse:
|
||||
**Step 1:** Open VSCode's Keyboard Shortcuts editor
|
||||
- Press `Ctrl+K Ctrl+S` (Windows/Linux) or `Cmd+K Cmd+S` (macOS)
|
||||
- Or: **File → Preferences → Keyboard Shortcuts**
|
||||
|
||||
1. Select code with keyboard navigation (`Shift+Arrow` keys)
|
||||
2. Send to Cline with `Ctrl+'` / `Cmd+'`
|
||||
3. Type your question and press Enter
|
||||
4. Review the response and apply suggestions
|
||||
**Step 2:** Search for "Cline"
|
||||
|
||||
## Editor Integration Shortcuts
|
||||
**Step 3:** Click the ✏️ icon next to any command
|
||||
|
||||
Cline's keyboard shortcuts integrate seamlessly with VSCode's built-in shortcuts:
|
||||
**Step 4:** Press your desired key combo, then `Enter`
|
||||
|
||||
- Use VSCode's selection shortcuts (`Ctrl+L` / `Cmd+L` to select line, etc.) before sending code to Cline
|
||||
- Combine with VSCode's split editor shortcuts to view code and Cline side by side
|
||||
- Use VSCode's terminal focus shortcut (`` Ctrl+` `` / `` Cmd+` ``) before capturing terminal output
|
||||
<Warning>
|
||||
**Avoid Conflicts:** Check that your shortcut doesn't override important VSCode commands. The shortcuts editor will warn you about conflicts.
|
||||
</Warning>
|
||||
|
||||
## Tips for Effective Use
|
||||
## Available Commands Reference
|
||||
|
||||
- **Learn the default shortcut first**: The `Ctrl+'` / `Cmd+'` shortcut is versatile - it adds selected code to chat when text is selected, or focuses the chat input when nothing is selected
|
||||
- **Create muscle memory**: Use keyboard shortcuts consistently to build habits
|
||||
- **Customize for your workflow**: Assign shortcuts to commands you use frequently
|
||||
- **Consider ergonomics**: Choose shortcuts that are comfortable for your keyboard layout
|
||||
<Accordion title="Task Management Commands">
|
||||
|
||||
Keyboard shortcuts may seem like a small optimization, but they can significantly speed up your workflow when using Cline regularly. By keeping your hands on the keyboard, you maintain your coding flow while still getting AI assistance exactly when you need it.
|
||||
These commands help you navigate and manage Cline tasks:
|
||||
|
||||
## How to Find All Available Commands
|
||||
| Command ID | Description | Suggested Shortcut |
|
||||
| ---------- | ----------- | ------------------ |
|
||||
| `cline.plusButtonClicked` | Start a new task | `Ctrl+Shift+N` / `Cmd+Shift+N` |
|
||||
| `cline.historyButtonClicked` | Open task history | `Ctrl+Shift+H` / `Cmd+Shift+H` |
|
||||
| `claude-dev.SidebarProvider.focus` | Open Cline sidebar | `Ctrl+Shift+L` / `Cmd+Shift+L` |
|
||||
|
||||
To see all Cline commands that can be assigned shortcuts:
|
||||
**Note:** `claude-dev` prefix is for historical reasons - it works with Cline.
|
||||
|
||||
1. Open the Command Palette (`Ctrl+Shift+P` / `Cmd+Shift+P`)
|
||||
2. Type "Cline" to filter the list
|
||||
3. Browse the available commands
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Code Interaction Commands">
|
||||
|
||||
Work directly with your code:
|
||||
|
||||
| Command ID | Description | Suggested Shortcut |
|
||||
| ---------- | ----------- | ------------------ |
|
||||
| `cline.addToChat` | Add selected code to chat | `Ctrl+'` / `Cmd+'` ⭐ (default) |
|
||||
| `cline.focusChatInput` | Focus chat input | `Ctrl+'` / `Cmd+'` ⭐ (default) |
|
||||
| `cline.explainCode` | Explain selected code | `Ctrl+Shift+E` / `Cmd+Shift+E` |
|
||||
| `cline.improveCode` | Suggest code improvements | `Ctrl+Shift+I` / `Cmd+Shift+I` |
|
||||
|
||||
⭐ These share the same shortcut - it's context-aware!
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Terminal Integration Commands">
|
||||
|
||||
Connect Cline with your terminal:
|
||||
|
||||
| Command ID | Description | Suggested Shortcut |
|
||||
| ---------- | ----------- | ------------------ |
|
||||
| `cline.addTerminalOutputToChat` | Add terminal output to Cline | `Alt+T` |
|
||||
|
||||
**Tip:** Use this after running commands to get help interpreting output or fixing errors.
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Git Integration Commands">
|
||||
|
||||
Generate commit messages with AI:
|
||||
|
||||
| Command ID | Description | Suggested Shortcut |
|
||||
| ---------- | ----------- | ------------------ |
|
||||
| `cline.generateGitCommitMessage` | Generate commit message | `Ctrl+Shift+G` / `Cmd+Shift+G` |
|
||||
| `cline.abortGitCommitMessage` | Stop generation | `Ctrl+Shift+Esc` / `Cmd+Shift+Esc` |
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Settings & Configuration Commands (Advanced)">
|
||||
|
||||
These commands open Cline's configuration panels. Most users access these via the sidebar buttons, but keyboard shortcuts can be useful for:
|
||||
|
||||
- **Frequent MCP server developers** who constantly adjust server configurations
|
||||
- **Demo/presentation scenarios** where you need quick, keyboard-only navigation
|
||||
- **Accessibility workflows** where mouse usage is minimized
|
||||
|
||||
| Command ID | Description | Suggested Shortcut |
|
||||
| ---------- | ----------- | ------------------ |
|
||||
| `cline.settingsButtonClicked` | Open Cline settings | `Ctrl+Alt+,` / `Cmd+Opt+,` |
|
||||
| `cline.mcpButtonClicked` | Open MCP servers config | `Ctrl+Alt+M` / `Cmd+Opt+M` |
|
||||
| `cline.accountButtonClicked` | Open account settings | `Ctrl+Alt+A` / `Cmd+Opt+A` |
|
||||
| `cline.openWalkthrough` | Open walkthrough guide | (not recommended) |
|
||||
|
||||
**Our take:** Unless you're constantly tweaking settings or building MCP servers, the sidebar buttons are more convenient. But if you find yourself opening these panels frequently, shortcuts can save time.
|
||||
|
||||
</Accordion>
|
||||
|
||||
## What About "Fix with Cline"?
|
||||
|
||||
<Warning>
|
||||
**You CAN'T assign a keyboard shortcut to "Fix with Cline"**
|
||||
|
||||
This command only appears in the **lightbulb menu** (💡) when VSCode detects errors in your code. It needs the error context to work, so it's not available as a standalone command.
|
||||
|
||||
**Workarounds:**
|
||||
- Click the 💡 lightbulb icon that appears next to errors
|
||||
- Or select code with errors and use `Ctrl+'` / `Cmd+'` to ask Cline to fix them
|
||||
- Or right-click and select "Add to Cline"
|
||||
</Warning>
|
||||
|
||||
Learn more about code actions in our [Code Commands documentation](/features/commands-and-shortcuts/code-commands).
|
||||
|
||||
## Best Practices
|
||||
|
||||
<Tip>
|
||||
**Start Simple**
|
||||
|
||||
Don't try to memorize 20 shortcuts on day one. Start with:
|
||||
1. `Ctrl+'` / `Cmd+'` (the essential one)
|
||||
2. Add 1-2 more based on your actual usage patterns
|
||||
3. Build muscle memory over time
|
||||
</Tip>
|
||||
|
||||
**Choose Shortcuts Wisely:**
|
||||
- **Be ergonomic:** Use comfortable key combinations
|
||||
- **Create patterns:** Group related commands (e.g., all Cline shortcuts use `Ctrl+Shift+...`)
|
||||
- **Avoid conflicts:** Don't override VSCode essentials like `Ctrl+C` or `Ctrl+S`
|
||||
- **Use modifiers:** Combine `Ctrl`/`Cmd` + `Shift` + `Alt` to reduce conflicts
|
||||
|
||||
**Build the Habit:**
|
||||
- Use shortcuts consistently for a week to build muscle memory
|
||||
- Keep a note of your custom shortcuts until they're automatic
|
||||
- Review monthly to see if your workflow has changed
|
||||
|
||||
## Discovering Commands
|
||||
|
||||
Not sure what commands are available? Use VSCode's Command Palette:
|
||||
|
||||
1. Press `Ctrl+Shift+P` / `Cmd+Shift+P`
|
||||
2. Type "Cline" to filter
|
||||
3. Browse all available commands
|
||||
4. Assign shortcuts to your favorites
|
||||
|
||||
<Frame>
|
||||
<img
|
||||
@@ -99,4 +197,8 @@ To see all Cline commands that can be assigned shortcuts:
|
||||
/>
|
||||
</Frame>
|
||||
|
||||
This helps you discover features you might not have known about and assign shortcuts to the ones you use most frequently.
|
||||
---
|
||||
|
||||
<Info>
|
||||
**Remember:** The goal isn't to memorize every possible shortcut. Master `Ctrl+'` / `Cmd+'` first, then gradually add shortcuts for commands you use frequently. Quality over quantity!
|
||||
</Info>
|
||||
|
||||
@@ -3,11 +3,13 @@ title: "Explain Changes"
|
||||
sidebarTitle: "Explain Changes"
|
||||
---
|
||||
|
||||
<Note>
|
||||
This feature is only available in **VS Code**. The diff view with inline comments requires VS Code's native diff capabilities.
|
||||
</Note>
|
||||
|
||||
|
||||
Explain Changes is an AI-powered code review feature that adds inline explanations to your code changes. When Cline makes modifications to your codebase, you can click a button to get streaming, contextual explanations that appear directly in VS Code's diff view.
|
||||
|
||||
<Note>
|
||||
Explain Changes requires **[Checkpoints](/features/checkpoints)** to be enabled. Make sure to enable checkpoints in your Cline settings before using this feature.
|
||||
</Note>
|
||||
|
||||
<Frame>
|
||||
<video
|
||||
@@ -21,6 +23,9 @@ Explain Changes requires **[Checkpoints](/features/checkpoints)** to be enabled.
|
||||
|
||||
|
||||
## How It Works
|
||||
<Note>
|
||||
Explain Changes requires **[Checkpoints](/features/checkpoints)** to be enabled. Make sure to enable checkpoints in your Cline settings before using this feature.
|
||||
</Note>
|
||||
|
||||
After Cline completes a task that involves file changes, you'll see an "Explain Changes" button alongside the "View Changes" button in the completion message. Clicking this button:
|
||||
|
||||
|
||||
@@ -137,10 +137,30 @@ The key is combining hooks with external tools. A hook can be the glue between C
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## Related Features
|
||||
## CLI support
|
||||
|
||||
Hooks are also available in the [Cline CLI](/cline-cli/overview). You can enable or disable hooks when running tasks from the command line:
|
||||
|
||||
```bash
|
||||
# Enable hooks for a task
|
||||
cline "What does this repo do?" -s hooks_enabled=true
|
||||
|
||||
# Configure hooks globally via CLI
|
||||
cline config set hooks-enabled=true
|
||||
cline config get hooks-enabled
|
||||
```
|
||||
|
||||
This allows you to integrate hooks into automated workflows, CI/CD pipelines, and headless task execution.
|
||||
|
||||
<Note>
|
||||
Hooks in the CLI are only supported on macOS and Linux. Windows support is not yet available.
|
||||
</Note>
|
||||
|
||||
## Related features
|
||||
|
||||
Hooks complement other Cline features:
|
||||
|
||||
- [Cline Rules](/features/cline-rules) define high-level guidance that hooks can enforce
|
||||
- [Checkpoints](/features/checkpoints) let you roll back changes if a hook didn't catch an issue
|
||||
- [Auto-Approve](/features/auto-approve) works well with hooks as safety nets for automated operations
|
||||
- [Cline CLI](/cline-cli/overview) enables hooks in terminal-based and automated workflows
|
||||
|
||||
@@ -1,164 +1,260 @@
|
||||
---
|
||||
title: "Multiroot Workspace Support"
|
||||
sidebarTitle: "Multiroot Workspace"
|
||||
title: "Multi-Root Workspaces"
|
||||
sidebarTitle: "Multi-Root Workspaces"
|
||||
---
|
||||
|
||||
Cline's Multiroot feature works seamlessly with VSCode's multi-root workspaces, letting you manage multiple project folders in a single workspace.
|
||||
Cline works with VSCode's multi-root workspaces, letting you manage multiple project folders or repositories in a single window. Whether you're working with a monorepo or separate Git repositories, Cline can read files, write code, and run commands across all of them.
|
||||
|
||||
<Frame>
|
||||
<video
|
||||
src="https://storage.googleapis.com/cline_public_images/multiworkspace.mp4"
|
||||
autoPlay
|
||||
muted
|
||||
loop
|
||||
playsInline
|
||||
controls
|
||||
/>
|
||||
</Frame>
|
||||
|
||||
<Warning>
|
||||
Multi-root workspaces have two limitations:
|
||||
- **Cline rules** only work in the primary workspace folder
|
||||
- **Checkpoints** are disabled (restored when you return to a single folder)
|
||||
|
||||
See [Current Limitations](#current-limitations) for details.
|
||||
</Warning>
|
||||
|
||||
## Understanding Multi-Root Workspaces
|
||||
|
||||
Before diving in, it helps to understand the two common patterns for organizing related projects.
|
||||
|
||||
### Why Use Multi-Root Workspaces?
|
||||
|
||||
Cline can complete tasks that span multiple projects or repositories:
|
||||
|
||||
- **Refactoring**: Update an API contract and fix all consumers across repos
|
||||
- **Feature development**: Implement a feature that touches frontend, backend, and shared code
|
||||
- **Dependency updates**: Coordinate version bumps across related projects
|
||||
- **Documentation**: Generate docs that reference code from multiple repositories
|
||||
|
||||
**Example prompt:**
|
||||
```
|
||||
Update the User type in the contracts repo, then update both the frontend
|
||||
and backend to use the new fields. Make sure the API validates the new
|
||||
required field.
|
||||
```
|
||||
## Setting Up a Multi-Root Workspace
|
||||
|
||||
### Monorepos vs Multiple Repositories
|
||||
|
||||
**Monorepo**: One Git repository containing multiple projects or packages. All code shares the same version history.
|
||||
|
||||
```
|
||||
my-company/ # Single Git repo
|
||||
├── .git/
|
||||
├── packages/
|
||||
│ ├── web/ # React frontend
|
||||
│ ├── api/ # Node.js backend
|
||||
│ └── shared/ # Common utilities
|
||||
└── package.json
|
||||
```
|
||||
|
||||
**Multiple Repositories**: Separate Git repositories, each with their own history, opened together in one VSCode workspace.
|
||||
|
||||
```
|
||||
~/projects/
|
||||
├── fullstack.code-workspace # Workspace config file
|
||||
├── frontend/ # git@github.com:acme/frontend.git
|
||||
│ └── .git/
|
||||
├── backend/ # git@github.com:acme/backend.git
|
||||
│ └── .git/
|
||||
└── contracts/ # git@github.com:acme/api-contracts.git
|
||||
└── .git/
|
||||
```
|
||||
|
||||
Cline supports both patterns, as well as hybrid setups where some folders are Git repositories and others are not. The key difference: with multiple repositories, each folder has its own `.git` directory and Cline tracks them independently.
|
||||
|
||||
### Adding Folders to Your Workspace
|
||||
|
||||
You can add folders to your workspace in several ways:
|
||||
|
||||
- **File menu**: Use `File > Add Folder to Workspace` in VSCode
|
||||
- **Drag and drop**: Drag folders directly into VSCode's file explorer
|
||||
- **Workspace file**: Create a `.code-workspace` file (recommended for teams)
|
||||
- **Command palette**: Run `Workspaces: Add Folder to Workspace`
|
||||
|
||||
For detailed instructions, see [Microsoft's multi-root workspace guide](https://code.visualstudio.com/docs/editor/multi-root-workspaces).
|
||||
|
||||
## Working with Multiple Repositories
|
||||
|
||||
When you open separate Git repositories in one workspace, Cline treats each as an independent project with its own version control.
|
||||
|
||||
### What Cline Tracks Per Repository
|
||||
|
||||
For each workspace folder, Cline detects:
|
||||
|
||||
| Property | Description |
|
||||
|----------|-------------|
|
||||
| **Path** | Absolute path to the folder |
|
||||
| **Name** | Derived from folder name or workspace file |
|
||||
| **VCS Type** | Git, Mercurial, or None |
|
||||
| **Commit Hash** | Current HEAD commit (for Git/Mercurial repos) |
|
||||
|
||||
This means Cline understands that your frontend and backend might be at different commits, on different branches, or even use different version control systems.
|
||||
|
||||
<Note>
|
||||
**Important:** Multi-root workspaces are currently an experimental feature and have the following limitations:
|
||||
- **Cline rules** only work in the first workspace folder
|
||||
- **Checkpoints** are automatically disabled with a warning message
|
||||
- Both features are restored when you return to a single-folder workspace
|
||||
While Cline detects VCS information for all workspace folders, certain features only use the **primary workspace** (the first folder): [Cline rules](/features/cline-rules), [workflows](/features/slash-commands/workflows/index), and [Git-related features](/features/at-mentions/git-mentions) like `@git` mentions.
|
||||
</Note>
|
||||
|
||||
## What is multiroot workspace support?
|
||||
## Referencing Files Across Workspaces
|
||||
|
||||
Instead of being limited to one project folder, Cline can read files, write code, and run commands across all folders in your VSCode workspace. This is helpful when working with monorepos, microservices, or when you're working on related projects simultaneously.
|
||||
### Natural Language References
|
||||
|
||||
### How it works
|
||||
|
||||
When you open multiple workspace folders in VSCode, Cline automatically:
|
||||
- Designates one folder as the **primary workspace** (typically the first folder added)
|
||||
- Tracks all workspace folders and their paths
|
||||
- Resolves file paths intelligently across workspaces
|
||||
- Displays workspace information in the environment details for each API request
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Setting Up Multi-Root Workspaces
|
||||
|
||||
1. **Add folders to your workspace:**
|
||||
- Use `File > Add Folder to Workspace` in VSCode
|
||||
- Or create a `.code-workspace` file with multiple folder paths
|
||||
- Drag and drop folders to the File Explorer
|
||||
- Select multiple folders when opening a new workspace
|
||||
|
||||
2. **Start using Cline** - Cline will automatically detect all your workspace folders and interact with them as needed.
|
||||
|
||||
For detailed instructions on setting up multi-root workspaces in VS Code, see [Microsoft's official guide](https://code.visualstudio.com/docs/editing/workspaces/multi-root-workspaces).
|
||||
|
||||
### Technical behavior
|
||||
|
||||
**Workspace detection**
|
||||
- Cline detects all workspace folders when a task starts
|
||||
- The first workspace folder becomes the primary workspace by default
|
||||
- Each workspace can have its own VCS (Git, SVN, etc.)
|
||||
|
||||
**Path resolution**
|
||||
- Relative paths are resolved relative to the primary workspace
|
||||
- You can use workspace hints to target specific workspaces: `@workspaceName:path/to/file`
|
||||
- Cline attempts to intelligently determine which workspace a file belongs to
|
||||
|
||||
**Command execution**
|
||||
- Commands execute in the appropriate workspace context
|
||||
- The working directory is set based on where files are being accessed
|
||||
|
||||
## Working across workspaces
|
||||
|
||||
### Referencing specific workspaces
|
||||
|
||||
You can reference different workspaces naturally in your prompts:
|
||||
Cline understands natural references to your workspaces:
|
||||
|
||||
```
|
||||
"Read the package.json in my frontend folder and compare it with the backend dependencies"
|
||||
"Read the package.json in the frontend folder"
|
||||
```
|
||||
|
||||
```
|
||||
"Create a shared utility function and update both the client and server to use it"
|
||||
"Compare the user model in backend with the TypeScript types in contracts"
|
||||
```
|
||||
|
||||
```
|
||||
"Search for TODO comments across all my workspace folders"
|
||||
"Search for TODO comments across all workspaces"
|
||||
```
|
||||
|
||||
### Workspace hints
|
||||
### Workspace Hints Syntax
|
||||
|
||||
Use workspace hints to explicitly reference files in specific workspaces:
|
||||
For explicit references, use the `@workspace:path` syntax:
|
||||
|
||||
```
|
||||
@frontend:src/App.tsx
|
||||
@backend:server.ts
|
||||
```
|
||||
| Syntax | Description |
|
||||
|--------|-------------|
|
||||
| `@frontend:src/App.tsx` | File in the "frontend" workspace |
|
||||
| `@backend:server.ts` | File in the "backend" workspace |
|
||||
| `@contracts:types/` | Folder in the "contracts" workspace |
|
||||
|
||||
This syntax helps Cline resolve ambiguity when multiple workspaces contain similarly named files.
|
||||
This syntax is especially useful when:
|
||||
- Multiple workspaces have files with the same name
|
||||
- You want to be explicit about which project you mean
|
||||
- Cline needs to resolve ambiguity
|
||||
|
||||
### How Workspace Names Work
|
||||
|
||||
## Common use cases
|
||||
Workspace names are derived from:
|
||||
1. The `name` field in your `.code-workspace` file (if specified)
|
||||
2. The folder name (default)
|
||||
|
||||
If two folders have the same name, append numbers or use the workspace file to give them unique names.
|
||||
|
||||
## Common Configurations
|
||||
|
||||
### Monorepo Development
|
||||
|
||||
Perfect for when you have related projects in one repository:
|
||||
|
||||
```
|
||||
my-app.code-workspace
|
||||
~/projects/my-app/
|
||||
├── my-app.code-workspace # Workspace config file
|
||||
├── web/ (React frontend)
|
||||
├── api/ (Node.js backend)
|
||||
├── api/ (Node.js backend)
|
||||
├── mobile/ (React Native)
|
||||
└── shared/ (Common utilities)
|
||||
```
|
||||
|
||||
Ask Cline: *"Update the API endpoint in both web and mobile apps to match the new backend route"*
|
||||
All folders share one Git history. Changes across packages are atomic.
|
||||
|
||||
### Microservices Architecture
|
||||
**Example prompt:** *"Update the API endpoint in both web and mobile apps to match the new backend route"*
|
||||
|
||||
Manage multiple services from one workspace:
|
||||
### Microservices with Separate Repos
|
||||
|
||||
```
|
||||
services.code-workspace
|
||||
├── user-service/
|
||||
├── payment-service/
|
||||
├── notifications/
|
||||
└── infrastructure/
|
||||
~/projects/services/
|
||||
├── services.code-workspace # Workspace config file
|
||||
├── user-service/ (git: github.com/acme/user-service)
|
||||
├── payment-service/ (git: github.com/acme/payment-service)
|
||||
├── gateway/ (git: github.com/acme/api-gateway)
|
||||
└── proto/ (git: github.com/acme/service-protos)
|
||||
```
|
||||
|
||||
### Full-Stack Development
|
||||
Each service has its own repository. Cline can update the proto definitions and regenerate clients across all services.
|
||||
|
||||
Keep everything together while maintaining separation:
|
||||
**Example prompt:** *"Add a new field to the UserProfile message in proto, then update user-service and gateway to handle it"*
|
||||
|
||||
### Full-Stack with Shared Contracts
|
||||
|
||||
```
|
||||
fullstack.code-workspace
|
||||
├── client/ (Frontend)
|
||||
├── server/ (Backend API)
|
||||
├── docs/ (Documentation)
|
||||
└── deploy/ (Scripts & config)
|
||||
~/projects/fullstack/
|
||||
├── fullstack.code-workspace # Workspace config file
|
||||
├── client/ (git: github.com/acme/web-client)
|
||||
├── server/ (git: github.com/acme/api-server)
|
||||
└── types/ (git: github.com/acme/shared-types)
|
||||
```
|
||||
|
||||
The types repository defines interfaces used by both client and server. When you update a type, Cline can fix both consumers.
|
||||
|
||||
### Auto-Approve Integration
|
||||
### Hybrid Setup
|
||||
|
||||
Multiroot workspaces work with [Auto Approve](/features/auto-approve):
|
||||
```
|
||||
~/projects/project/
|
||||
├── project.code-workspace # Workspace config file
|
||||
├── main-app/ (git: github.com/acme/main-app)
|
||||
├── vendor/ (no VCS - vendored dependencies)
|
||||
└── scripts/ (no VCS - local automation)
|
||||
```
|
||||
|
||||
- Enable permissions for operations within workspace folders
|
||||
- Restrict auto-approve for files outside your workspace(s)
|
||||
- Configure different levels for different workspace folders
|
||||
Mix of repositories and plain folders. Cline adapts to each folder's configuration.
|
||||
|
||||
### Cross-Workspace Operations
|
||||
## Current Limitations
|
||||
|
||||
Cline can complete tasks spanning multiple workspaces:
|
||||
Two features have limitations in multi-root workspace mode:
|
||||
|
||||
- **Refactoring**: Update imports and references across projects
|
||||
- **Feature development**: Implement features requiring changes in multiple services
|
||||
- **Documentation**: Generate docs referencing code from multiple folders
|
||||
- **Testing**: Build & run tests across all workspaces and analyze results
|
||||
### Cline Rules
|
||||
|
||||
When working with large multiroot workspaces, start in [Plan mode](/features/plan-and-act) to let Cline understand your project structure before making changes.
|
||||
[Cline rules](/features/cline-rules) (`.clinerules/` directory) only work in the **primary workspace** (the first folder in your workspace). Rules in other workspace folders are ignored.
|
||||
|
||||
**Workaround:** Place shared rules in the primary workspace, or use global rules (`~/Documents/Cline/Rules/`) which apply everywhere.
|
||||
|
||||
### Checkpoints
|
||||
|
||||
[Checkpoints](/features/checkpoints) are disabled in multi-root workspace mode. Cline displays a warning when this happens.
|
||||
|
||||
**Why:** Checkpoints use a shadow Git repository to track changes. With multiple repositories, coordinating checkpoints across independent Git histories adds complexity that isn't yet supported.
|
||||
|
||||
**Workaround:** Use your normal Git workflow. Commit frequently, or create branches for experimental work.
|
||||
|
||||
Both limitations are restored when you return to a single-folder workspace.
|
||||
|
||||
## Best Practices
|
||||
|
||||
### Organizing Your Workspaces
|
||||
|
||||
1. **Group related projects** that often need coordinated changes
|
||||
2. **Use consistent folder structures** across workspaces when possible
|
||||
3. **Name folders clearly** so Cline can understand your project structure
|
||||
2. **Use a workspace file** for reproducible setups across your team
|
||||
3. **Name folders clearly** so workspace hints are intuitive
|
||||
4. **Consider the primary workspace** for Cline rules placement
|
||||
|
||||
### Effective Prompting & Tips
|
||||
### Effective Prompting
|
||||
|
||||
When working with multiroot workspaces, these approaches work best:
|
||||
- **Be specific** when it matters: *"Update the user model in the backend workspace"*
|
||||
- **Reference relationships**: *"The frontend uses types from the contracts workspace"*
|
||||
- **Describe cross-workspace changes**: *"This needs to update both web and mobile"*
|
||||
- **Scope searches** for large codebases: *"Search for 'TODO' only in the frontend workspace"*
|
||||
|
||||
- **Be specific** about which workspace when it matters: *"Update the user model in the backend workspace"*
|
||||
- **Reference relationships**: *"The frontend uses the API types from the shared workspace"*
|
||||
- **Describe cross-workspace operations**: *"This change needs to be reflected in both the web and mobile apps"*
|
||||
- **Scope your searches** when dealing with large codebases: *"Search for 'TODO' in just the frontend workspace"*
|
||||
- **Break down large tasks** into workspace-specific operations when possible
|
||||
- **Consider excluding large folders** like `node_modules` from your workspace search Scope
|
||||
### Working with Large Workspaces
|
||||
|
||||
- Break large tasks into workspace-specific operations when possible
|
||||
- Use [Plan mode](/features/plan-and-act) to let Cline understand structure first
|
||||
- Add a `.clineignore` file to reduce noise, speed up scanning, and keep Cline focused on source code:
|
||||
|
||||
```text
|
||||
# Dependencies
|
||||
**/node_modules/
|
||||
|
||||
# Build outputs
|
||||
**/dist/
|
||||
**/build/
|
||||
|
||||
# VCS metadata
|
||||
**/.git/
|
||||
```
|
||||
|
||||
For more patterns and gotchas, see the [.clineignore File Guide](/prompting/prompt-engineering-guide#clineignore-file-guide).
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
title: "Explain Changes Command"
|
||||
sidebarTitle: "/explain-changes"
|
||||
---
|
||||
<Note>
|
||||
This command is only available in **VS Code**. The diff view with inline comments requires VS Code's native diff capabilities.
|
||||
</Note>
|
||||
|
||||
`/explain-changes` is a slash command that generates AI-powered explanations for any git diff. Unlike the [Explain Changes button](/features/explain-changes) which explains changes from a completed task, this command lets you explain changes between any two git references - commits, branches, tags, PRs, staged changes, or your working directory.
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ Cline is an open source AI coding agent that brings frontier AI models directly
|
||||
Master Cline's powerful features and optimize your workflow
|
||||
</Card>
|
||||
|
||||
<Card title="Enterprise" icon="building" href="/enterprise-solutions/security-concerns">
|
||||
<Card title="Enterprise" icon="building" href="/enterprise-solutions/overview">
|
||||
Deploy Cline in your organization with confidence
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
+5
-2
@@ -204,8 +204,11 @@ const extensionConfig = {
|
||||
// Standalone-specific configuration
|
||||
const standaloneConfig = {
|
||||
...baseConfig,
|
||||
entryPoints: ["src/standalone/cline-core.ts"],
|
||||
outfile: `${destDir}/cline-core.js`,
|
||||
entryPoints: {
|
||||
"cline-core": "src/standalone/cline-core.ts",
|
||||
"cline-acp": "src/standalone/cline-acp.ts",
|
||||
},
|
||||
outdir: destDir,
|
||||
// These modules need to load files from the module directory at runtime,
|
||||
// so they cannot be bundled.
|
||||
external: ["vscode", "@grpc/reflection", "grpc-health-check", "better-sqlite3"],
|
||||
|
||||
Generated
+968
-14
File diff suppressed because it is too large
Load Diff
+3
-2
@@ -2,7 +2,7 @@
|
||||
"name": "claude-dev",
|
||||
"displayName": "Cline",
|
||||
"description": "Autonomous coding agent right in your IDE, capable of creating/editing files, running commands, using the browser, and more with your permission every step of the way.",
|
||||
"version": "3.41.0",
|
||||
"version": "3.45.0",
|
||||
"icon": "assets/icons/icon.png",
|
||||
"engines": {
|
||||
"vscode": "^1.84.0"
|
||||
@@ -378,7 +378,7 @@
|
||||
"pretest": "npm run compile && npm run compile-tests && npm run compile-standalone && npm run lint",
|
||||
"test": "npm-run-all test:unit test:integration",
|
||||
"test:integration": "vscode-test",
|
||||
"test:unit": "cross-env TS_NODE_PROJECT=./tsconfig.unit-test.json mocha # Use `UPDATE_SNAPSHOTS=true npm run test:unit` to rebuild prompt snapshots",
|
||||
"test:unit": "cross-env TS_NODE_PROJECT=./tsconfig.unit-test.json mocha",
|
||||
"test:coverage": "vscode-test --coverage",
|
||||
"test:sca-server": "npx tsx watch scripts/test-standalone-core-api-server.ts",
|
||||
"test:tp-orchestrator": "npx tsx scripts/testing-platform-orchestrator.ts",
|
||||
@@ -452,6 +452,7 @@
|
||||
"typescript": "^5.4.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@agentclientprotocol/sdk": "^0.11.0",
|
||||
"@anthropic-ai/sdk": "^0.37.0",
|
||||
"@anthropic-ai/vertex-sdk": "^0.6.4",
|
||||
"@aws-sdk/client-bedrock-runtime": "^3.922.0",
|
||||
|
||||
@@ -369,6 +369,7 @@ message UpdateSettingsRequest {
|
||||
optional OnboardingModelGroup onboarding_models = 33;
|
||||
optional bool cline_web_tools_enabled = 34;
|
||||
optional bool enable_parallel_tool_calling = 35;
|
||||
optional bool background_edit_enabled = 36;
|
||||
}
|
||||
|
||||
message UpdateTerminalConnectionTimeoutRequest {
|
||||
|
||||
@@ -55,8 +55,10 @@ enum Setting {
|
||||
}
|
||||
message GetTelemetrySettingsResponse {
|
||||
Setting is_enabled = 1;
|
||||
optional string error_level = 2;
|
||||
}
|
||||
|
||||
message TelemetrySettingsEvent {
|
||||
Setting is_enabled = 1;
|
||||
optional string error_level = 2;
|
||||
}
|
||||
|
||||
@@ -77,6 +77,7 @@ function createMockService<T extends grpc.UntypedServiceImplementation>(serviceN
|
||||
case "getTelemetrySettings":
|
||||
callback(null, {
|
||||
isEnabled: 2, // Setting.DISABLED
|
||||
errorLevel: "all",
|
||||
})
|
||||
return
|
||||
|
||||
|
||||
@@ -180,6 +180,8 @@ function createHandlerForProvider(
|
||||
openAiNativeApiKey: options.openAiNativeApiKey,
|
||||
reasoningEffort: mode === "plan" ? options.planModeReasoningEffort : options.actModeReasoningEffort,
|
||||
apiModelId: mode === "plan" ? options.planModeApiModelId : options.actModeApiModelId,
|
||||
thinkingBudgetTokens:
|
||||
mode === "plan" ? options.planModeThinkingBudgetTokens : options.actModeThinkingBudgetTokens,
|
||||
})
|
||||
case "deepseek":
|
||||
return new DeepSeekHandler({
|
||||
|
||||
@@ -56,87 +56,61 @@ export class AnthropicHandler implements ApiHandler {
|
||||
|
||||
// Tools are available only when native tools are enabled.
|
||||
const nativeToolsOn = tools?.length && tools?.length > 0
|
||||
const reasoningOn = !!(
|
||||
(modelId.includes("3-7") || modelId.includes("4-") || modelId.includes("4-5")) &&
|
||||
budget_tokens !== 0
|
||||
)
|
||||
const reasoningOn = (model.info.supportsReasoning ?? false) && budget_tokens !== 0
|
||||
|
||||
switch (modelId) {
|
||||
// 'latest' alias does not support cache_control
|
||||
case "claude-haiku-4-5@20251001":
|
||||
case "claude-sonnet-4-5@20250929":
|
||||
case "claude-sonnet-4@20250514":
|
||||
case "claude-opus-4-5@20251101":
|
||||
case "claude-opus-4-1@20250805":
|
||||
case "claude-opus-4@20250514":
|
||||
case "claude-haiku-4-5-20251001":
|
||||
case "claude-sonnet-4-5-20250929:1m":
|
||||
case "claude-sonnet-4-5-20250929":
|
||||
case "claude-sonnet-4-20250514":
|
||||
case "claude-3-7-sonnet-20250219":
|
||||
case "claude-3-5-sonnet-20241022":
|
||||
case "claude-3-5-haiku-20241022":
|
||||
case "claude-opus-4-5-20251101":
|
||||
case "claude-opus-4-20250514":
|
||||
case "claude-opus-4-1-20250805":
|
||||
case "claude-3-opus-20240229":
|
||||
case "claude-3-haiku-20240307": {
|
||||
const anthropicMessages = sanitizeAnthropicMessages(messages, true)
|
||||
if (model.info.supportsPromptCache) {
|
||||
const anthropicMessages = sanitizeAnthropicMessages(messages, true)
|
||||
|
||||
stream = await client.messages.create(
|
||||
{
|
||||
model: modelId,
|
||||
thinking: reasoningOn ? { type: "enabled", budget_tokens: budget_tokens } : undefined,
|
||||
max_tokens: model.info.maxTokens || 8192,
|
||||
// "Thinking isn’t compatible with temperature, top_p, or top_k modifications as well as forced tool use."
|
||||
// (https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking#important-considerations-when-using-extended-thinking)
|
||||
temperature: reasoningOn ? undefined : 0,
|
||||
system: [
|
||||
{
|
||||
text: systemPrompt,
|
||||
type: "text",
|
||||
cache_control: { type: "ephemeral" },
|
||||
},
|
||||
], // setting cache breakpoint for system prompt so new tasks can reuse it
|
||||
messages: anthropicMessages,
|
||||
// tools, // cache breakpoints go from tools > system > messages, and since tools dont change, we can just set the breakpoint at the end of system (this avoids having to set a breakpoint at the end of tools which by itself does not meet min requirements for haiku caching)
|
||||
stream: true,
|
||||
tools: nativeToolsOn ? tools : undefined,
|
||||
// tool_choice options:
|
||||
// - none: disables tool use, even if tools are provided. Claude will not call any tools.
|
||||
// - auto: allows Claude to decide whether to call any provided tools or not. This is the default value when tools are provided.
|
||||
// - any: tells Claude that it must use one of the provided tools, but doesn’t force a particular tool.
|
||||
// NOTE: Forcing tool use when tools are provided will result in error when thinking is also enabled.
|
||||
tool_choice: nativeToolsOn && !reasoningOn ? { type: "any" } : undefined,
|
||||
},
|
||||
(() => {
|
||||
// 1m context window beta header
|
||||
if (enable1mContextWindow) {
|
||||
return {
|
||||
headers: {
|
||||
"anthropic-beta": "context-1m-2025-08-07",
|
||||
},
|
||||
}
|
||||
} else {
|
||||
return undefined
|
||||
}
|
||||
})(),
|
||||
)
|
||||
break
|
||||
}
|
||||
default: {
|
||||
stream = await client.messages.create({
|
||||
stream = await client.messages.create(
|
||||
{
|
||||
model: modelId,
|
||||
thinking: reasoningOn ? { type: "enabled", budget_tokens: budget_tokens } : undefined,
|
||||
max_tokens: model.info.maxTokens || 8192,
|
||||
temperature: 0,
|
||||
system: [{ text: systemPrompt, type: "text" }],
|
||||
messages: sanitizeAnthropicMessages(messages, false),
|
||||
tools: nativeToolsOn ? tools : undefined,
|
||||
tool_choice: { type: "auto" },
|
||||
// "Thinking isn’t compatible with temperature, top_p, or top_k modifications as well as forced tool use."
|
||||
// (https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking#important-considerations-when-using-extended-thinking)
|
||||
temperature: reasoningOn ? undefined : 0,
|
||||
system: [
|
||||
{
|
||||
text: systemPrompt,
|
||||
type: "text",
|
||||
cache_control: { type: "ephemeral" },
|
||||
},
|
||||
], // setting cache breakpoint for system prompt so new tasks can reuse it
|
||||
messages: anthropicMessages,
|
||||
// tools, // cache breakpoints go from tools > system > messages, and since tools dont change, we can just set the breakpoint at the end of system (this avoids having to set a breakpoint at the end of tools which by itself does not meet min requirements for haiku caching)
|
||||
stream: true,
|
||||
})
|
||||
break
|
||||
}
|
||||
tools: nativeToolsOn ? tools : undefined,
|
||||
// tool_choice options:
|
||||
// - none: disables tool use, even if tools are provided. Claude will not call any tools.
|
||||
// - auto: allows Claude to decide whether to call any provided tools or not. This is the default value when tools are provided.
|
||||
// - any: tells Claude that it must use one of the provided tools, but doesn’t force a particular tool.
|
||||
// NOTE: Forcing tool use when tools are provided will result in error when thinking is also enabled.
|
||||
tool_choice: nativeToolsOn && !reasoningOn ? { type: "any" } : undefined,
|
||||
},
|
||||
(() => {
|
||||
// 1m context window beta header
|
||||
if (enable1mContextWindow) {
|
||||
return {
|
||||
headers: {
|
||||
"anthropic-beta": "context-1m-2025-08-07",
|
||||
},
|
||||
}
|
||||
} else {
|
||||
return undefined
|
||||
}
|
||||
})(),
|
||||
)
|
||||
} else {
|
||||
stream = await client.messages.create({
|
||||
model: modelId,
|
||||
max_tokens: model.info.maxTokens || 8192,
|
||||
temperature: 0,
|
||||
system: [{ text: systemPrompt, type: "text" }],
|
||||
messages: sanitizeAnthropicMessages(messages, false),
|
||||
tools: nativeToolsOn ? tools : undefined,
|
||||
tool_choice: { type: "auto" },
|
||||
stream: true,
|
||||
})
|
||||
}
|
||||
|
||||
const lastStartedToolCall = { id: "", name: "", arguments: "" }
|
||||
|
||||
@@ -199,7 +199,7 @@ export class ClineHandler implements ApiHandler {
|
||||
// @ts-ignore-next-line
|
||||
let totalCost = (chunk.usage.cost || 0) + (chunk.usage.cost_details?.upstream_inference_cost || 0)
|
||||
|
||||
if (["x-ai/grok-code-fast-1", "minimax/minimax-m2", "mistralai/devstral-2512"].includes(this.getModel().id)) {
|
||||
if (["x-ai/grok-code-fast-1", "minimax/minimax-m2"].includes(this.getModel().id)) {
|
||||
totalCost = 0
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,6 @@ import { RetriableError, withRetry } from "../retry"
|
||||
import { convertAnthropicMessageToGemini } from "../transform/gemini-format"
|
||||
import { ApiStream } from "../transform/stream"
|
||||
|
||||
// Define a default TTL for the cache (e.g., 15 minutes in seconds)
|
||||
const _DEFAULT_CACHE_TTL_SECONDS = 900
|
||||
|
||||
const rateLimitPatterns = [/got status: 429/i, /429 Too Many Requests/i, /rate limit exceeded/i, /too many requests/i]
|
||||
|
||||
interface GeminiHandlerOptions extends CommonApiHandlerOptions {
|
||||
|
||||
@@ -23,6 +23,7 @@ import { getOpenAIToolParams, ToolCallProcessor } from "../transform/tool-call-p
|
||||
interface OpenAiNativeHandlerOptions extends CommonApiHandlerOptions {
|
||||
openAiNativeApiKey?: string
|
||||
reasoningEffort?: string
|
||||
thinkingBudgetTokens?: number
|
||||
apiModelId?: string
|
||||
}
|
||||
|
||||
@@ -105,19 +106,18 @@ export class OpenAiNativeHandler implements ApiHandler {
|
||||
}
|
||||
|
||||
const systemRole = model.info.systemRole ?? "system"
|
||||
const includeReasoning = model.info.supportsReasoningEffort ?? false
|
||||
const includeReasoning = this.options.thinkingBudgetTokens && model.info.supportsReasoningEffort
|
||||
const includeTools = model.info.supportsTools ?? true
|
||||
const reasoningEffort = includeReasoning
|
||||
? (this.options.reasoningEffort as ChatCompletionReasoningEffort) || "medium"
|
||||
: undefined
|
||||
|
||||
const stream = await client.chat.completions.create({
|
||||
model: model.id,
|
||||
messages: [{ role: systemRole, content: systemPrompt }, ...convertToOpenAiMessages(messages)],
|
||||
stream: true,
|
||||
stream_options: { include_usage: true },
|
||||
...(includeReasoning
|
||||
? {
|
||||
reasoning_effort: (this.options.reasoningEffort as ChatCompletionReasoningEffort) || "medium",
|
||||
}
|
||||
: {}),
|
||||
reasoning_effort: reasoningEffort,
|
||||
...(model.info.temperature !== undefined ? { temperature: model.info.temperature } : {}),
|
||||
...(includeTools ? getOpenAIToolParams(tools, isGPT5ModelFamily(model.id)) : {}),
|
||||
})
|
||||
|
||||
@@ -2,6 +2,14 @@ import { Anthropic } from "@anthropic-ai/sdk"
|
||||
import { Content, GenerateContentResponse, Part } from "@google/genai"
|
||||
import { ClineStorageMessage } from "@/shared/messages/content"
|
||||
|
||||
// Source: https://ai.google.dev/gemini-api/docs/thought-signatures#faqs
|
||||
// While injecting custom function call blocks into the request is strongly discouraged,
|
||||
// in cases where it can't be avoided, e.g. providing information to the model on function
|
||||
// calls and responses that were executed deterministically by the client, or transferring a
|
||||
// trace from a different model that does not include thought signatures, you can set the following dummy signatures of either
|
||||
// "context_engineering_is_the_way_to_go" or "skip_thought_signature_validator" in the thought signature field to skip validation.
|
||||
const GEMINI_DUMMY_THOUGHT_SIGNATURE = "skip_thought_signature_validator"
|
||||
|
||||
export function convertAnthropicContentToGemini(content: string | ClineStorageMessage["content"]): Part[] {
|
||||
if (typeof content === "string") {
|
||||
return [{ text: content }]
|
||||
@@ -27,7 +35,8 @@ export function convertAnthropicContentToGemini(content: string | ClineStorageMe
|
||||
name: block.name,
|
||||
args: block.input as Record<string, unknown>,
|
||||
},
|
||||
thoughtSignature: block.signature,
|
||||
// Thought signature is required, so provide a dummy one if not present
|
||||
thoughtSignature: block.signature || GEMINI_DUMMY_THOUGHT_SIGNATURE,
|
||||
}
|
||||
case "tool_result":
|
||||
return {
|
||||
|
||||
@@ -35,7 +35,6 @@ import { getDistinctId } from "@/services/logging/distinctId"
|
||||
import { telemetryService } from "@/services/telemetry"
|
||||
import { getAxiosSettings } from "@/shared/net"
|
||||
import { ShowMessageType } from "@/shared/proto/host/window"
|
||||
import type { AuthState } from "@/shared/proto/index.cline"
|
||||
import { getLatestAnnouncementId } from "@/utils/announcements"
|
||||
import { getCwd, getDesktopDir } from "@/utils/path"
|
||||
import { BannerService } from "../../services/banner/BannerService"
|
||||
@@ -50,7 +49,6 @@ import {
|
||||
import { fetchRemoteConfig } from "../storage/remote-config/fetch"
|
||||
import { type PersistenceErrorEvent, StateManager } from "../storage/StateManager"
|
||||
import { Task } from "../task"
|
||||
import type { StreamingResponseHandler } from "./grpc-handler"
|
||||
import { sendMcpMarketplaceCatalogEvent } from "./mcp/subscribeToMcpMarketplaceCatalog"
|
||||
import { getClineOnboardingModels } from "./models/getClineOnboardingModels"
|
||||
import { appendClineStealthModels } from "./models/refreshOpenRouterModels"
|
||||
@@ -145,13 +143,6 @@ export class Controller {
|
||||
this.ocaAuthService = OcaAuthService.initialize(this)
|
||||
this.accountService = ClineAccountService.getInstance()
|
||||
|
||||
const authStatusHandler: StreamingResponseHandler<AuthState> = async (response, _isLast, _seqNumber): Promise<void> => {
|
||||
if (response.user) {
|
||||
fetchRemoteConfig(this)
|
||||
}
|
||||
}
|
||||
this.authService.subscribeToAuthStatusUpdate(this, {}, authStatusHandler, undefined)
|
||||
|
||||
this.authService.restoreRefreshTokenAndRetrieveAuthInfo().then(() => {
|
||||
this.startRemoteConfigTimer()
|
||||
})
|
||||
@@ -963,6 +954,7 @@ export class Controller {
|
||||
subagentsEnabled,
|
||||
nativeToolCallSetting: this.stateManager.getGlobalStateKey("nativeToolCallEnabled"),
|
||||
enableParallelToolCalling: this.stateManager.getGlobalSettingsKey("enableParallelToolCalling"),
|
||||
backgroundEditEnabled: this.stateManager.getGlobalSettingsKey("backgroundEditEnabled"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -320,6 +320,10 @@ export async function updateSettings(controller: Controller, request: UpdateSett
|
||||
}
|
||||
}
|
||||
|
||||
if (request.backgroundEditEnabled !== undefined) {
|
||||
controller.stateManager.setGlobalState("backgroundEditEnabled", !!request.backgroundEditEnabled)
|
||||
}
|
||||
|
||||
if (request.autoCondenseThreshold !== undefined) {
|
||||
const threshold = Math.min(1, Math.max(0, request.autoCondenseThreshold)) // Clamp to 0-1 range
|
||||
controller.stateManager.setGlobalState("autoCondenseThreshold", threshold)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { telemetryService } from "../../services/telemetry"
|
||||
import { getAllHooksDirs } from "../storage/disk"
|
||||
import { HookFactory, Hooks } from "./hook-factory"
|
||||
|
||||
@@ -56,8 +57,8 @@ export class HookDiscoveryCache {
|
||||
// Directories we've tried to watch (even if watcher creation failed)
|
||||
private watchedDirs = new Set<string>()
|
||||
|
||||
// Currently scanning (to prevent concurrent scans)
|
||||
private scanning = new Set<HookName>()
|
||||
// Currently scanning promises (to prevent concurrent scans)
|
||||
private scanningPromises = new Map<HookName, Promise<string[]>>()
|
||||
|
||||
// For disposal
|
||||
private context: ExtensionContext | null = null
|
||||
@@ -105,60 +106,95 @@ export class HookDiscoveryCache {
|
||||
this.log(`Getting hooks for ${hookName}`)
|
||||
|
||||
const cached = this.cache.get(hookName)
|
||||
if (cached) {
|
||||
const cacheHit = cached !== undefined
|
||||
|
||||
let scripts: string[]
|
||||
let initiatedScan = false // Track if this caller initiated the scan
|
||||
|
||||
if (cacheHit) {
|
||||
this.log(`Cache hit for ${hookName}: ${cached.scriptPaths.length} scripts`)
|
||||
return cached.scriptPaths
|
||||
scripts = cached.scriptPaths
|
||||
} else {
|
||||
this.log(`Cache miss for ${hookName}, scanning...`)
|
||||
|
||||
// Check if scan is already in progress
|
||||
const existingPromise = this.scanningPromises.get(hookName)
|
||||
if (existingPromise) {
|
||||
// Another caller is already scanning, reuse their promise
|
||||
this.log(`Reusing existing scan for ${hookName}`)
|
||||
scripts = await existingPromise
|
||||
} else {
|
||||
// This caller initiates the scan
|
||||
initiatedScan = true
|
||||
scripts = await this.scan(hookName)
|
||||
}
|
||||
}
|
||||
|
||||
this.log(`Cache miss for ${hookName}, scanning...`)
|
||||
return this.scan(hookName)
|
||||
// Only report telemetry if:
|
||||
// 1. It was a cache hit, OR
|
||||
// 2. This caller initiated the scan (not reusing another caller's promise)
|
||||
if (cacheHit || initiatedScan) {
|
||||
telemetryService.safeCapture(
|
||||
() => telemetryService.captureHookCacheAccess(hookName, cacheHit),
|
||||
"HookDiscoveryCache.get",
|
||||
)
|
||||
}
|
||||
|
||||
return scripts
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan for hook scripts and cache the result
|
||||
*/
|
||||
private async scan(hookName: HookName): Promise<string[]> {
|
||||
// Prevent concurrent scans of the same hook
|
||||
if (this.scanning.has(hookName)) {
|
||||
this.log(`Already scanning ${hookName}, waiting...`)
|
||||
await new Promise((resolve) => setTimeout(resolve, 50))
|
||||
return this.get(hookName)
|
||||
// Check if a scan is already in progress for this hook
|
||||
const existingPromise = this.scanningPromises.get(hookName)
|
||||
if (existingPromise) {
|
||||
this.log(`Already scanning ${hookName}, waiting for existing scan...`)
|
||||
return existingPromise
|
||||
}
|
||||
|
||||
this.scanning.add(hookName)
|
||||
// Create a new scan promise
|
||||
const scanPromise = (async () => {
|
||||
try {
|
||||
// Get all current hooks directories
|
||||
const hooksDirs = await getAllHooksDirs()
|
||||
this.log(`Scanning ${hooksDirs.length} directories for ${hookName}`)
|
||||
|
||||
try {
|
||||
// Get all current hooks directories
|
||||
const hooksDirs = await getAllHooksDirs()
|
||||
this.log(`Scanning ${hooksDirs.length} directories for ${hookName}`)
|
||||
// Ensure watchers are set up for each directory (lazy initialization)
|
||||
for (const dir of hooksDirs) {
|
||||
this.ensureWatcher(dir)
|
||||
}
|
||||
|
||||
// Ensure watchers are set up for each directory (lazy initialization)
|
||||
for (const dir of hooksDirs) {
|
||||
this.ensureWatcher(dir)
|
||||
// Scan each directory for this hook
|
||||
const scriptPromises = hooksDirs.map((dir) => HookFactory.findHookInHooksDir(hookName, dir))
|
||||
|
||||
const results = await Promise.all(scriptPromises)
|
||||
const scripts = results.filter((path): path is string => path !== undefined)
|
||||
|
||||
this.log(`Found ${scripts.length} scripts for ${hookName}`)
|
||||
|
||||
// Cache the result
|
||||
this.cache.set(hookName, {
|
||||
scriptPaths: scripts,
|
||||
timestamp: Date.now(),
|
||||
})
|
||||
|
||||
return scripts
|
||||
} catch (error) {
|
||||
console.error(`Error scanning for ${hookName} hooks:`, error)
|
||||
// Return empty array on error - don't break the whole system
|
||||
return []
|
||||
} finally {
|
||||
// Remove from scanning promises map
|
||||
this.scanningPromises.delete(hookName)
|
||||
}
|
||||
})()
|
||||
|
||||
// Scan each directory for this hook
|
||||
const scriptPromises = hooksDirs.map((dir) => HookFactory.findHookInHooksDir(hookName, dir))
|
||||
// Store the promise so concurrent calls can await it
|
||||
this.scanningPromises.set(hookName, scanPromise)
|
||||
|
||||
const results = await Promise.all(scriptPromises)
|
||||
const scripts = results.filter((path): path is string => path !== undefined)
|
||||
|
||||
this.log(`Found ${scripts.length} scripts for ${hookName}`)
|
||||
|
||||
// Cache the result
|
||||
this.cache.set(hookName, {
|
||||
scriptPaths: scripts,
|
||||
timestamp: Date.now(),
|
||||
})
|
||||
|
||||
return scripts
|
||||
} catch (error) {
|
||||
console.error(`Error scanning for ${hookName} hooks:`, error)
|
||||
// Return empty array on error - don't break the whole system
|
||||
return []
|
||||
} finally {
|
||||
this.scanning.delete(hookName)
|
||||
}
|
||||
return scanPromise
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -105,6 +105,8 @@ export async function executeHook<Name extends keyof Hooks>(options: HookExecuti
|
||||
hookName,
|
||||
streamCallback,
|
||||
isCancellable ? abortController.signal : undefined,
|
||||
taskId,
|
||||
options.toolName,
|
||||
)
|
||||
|
||||
const result = await hook.run({
|
||||
|
||||
@@ -2,6 +2,7 @@ import fs from "fs/promises"
|
||||
import path from "path"
|
||||
import { version as clineVersion } from "../../../package.json"
|
||||
import { getDistinctId } from "../../services/logging/distinctId"
|
||||
import { telemetryService } from "../../services/telemetry"
|
||||
import {
|
||||
HookInput,
|
||||
HookOutput,
|
||||
@@ -25,6 +26,9 @@ const HOOK_EXECUTION_TIMEOUT_MS = 30000
|
||||
// Maximum size for context modification (to prevent prompt overflow)
|
||||
const MAX_CONTEXT_MODIFICATION_SIZE = 50000 // ~50KB
|
||||
|
||||
// Exit code indicating cancellation/interruption (Unix SIGINT convention: 128 + signal 2)
|
||||
const EXIT_CODE_SIGINT = 130
|
||||
|
||||
/**
|
||||
* Validates hook output JSON structure.
|
||||
* Ensures required fields are present and have correct types.
|
||||
@@ -233,6 +237,7 @@ export type HookStreamCallback = (line: string, stream: "stdout" | "stderr") =>
|
||||
* - Parses JSON output from stdout, attempting to extract it even if mixed with debug output
|
||||
* - Truncates context modifications that exceed 50KB to prevent prompt overflow
|
||||
* - Handles both successful and failed executions gracefully
|
||||
* - Emits per-hook telemetry with source attribution (global or workspace)
|
||||
*
|
||||
* Error handling:
|
||||
* - Treats hooks as "fail-open": only shouldContinue:false blocks tool execution
|
||||
@@ -245,13 +250,31 @@ class StdioHookRunner<Name extends HookName> extends HookRunner<Name> {
|
||||
constructor(
|
||||
hookName: Name,
|
||||
public readonly scriptPath: string,
|
||||
private readonly source: "global" | "workspace",
|
||||
private readonly streamCallback?: HookStreamCallback,
|
||||
private readonly abortSignal?: AbortSignal,
|
||||
private readonly taskId?: string,
|
||||
private readonly toolName?: string,
|
||||
) {
|
||||
super(hookName)
|
||||
}
|
||||
|
||||
override async [exec](input: HookInput): Promise<HookOutput> {
|
||||
const startTime = performance.now()
|
||||
const taskId = this.taskId // Local const for type narrowing in closures
|
||||
|
||||
// Capture telemetry at the start of individual hook execution
|
||||
if (taskId) {
|
||||
telemetryService.safeCapture(
|
||||
() =>
|
||||
telemetryService.captureHookExecution(taskId, this.hookName, "started", {
|
||||
source: this.source,
|
||||
toolName: this.toolName,
|
||||
}),
|
||||
"HookFactory.exec.started",
|
||||
)
|
||||
}
|
||||
|
||||
// Check if already aborted before starting
|
||||
if (this.abortSignal?.aborted) {
|
||||
throw HookExecutionError.cancellation(this.scriptPath)
|
||||
@@ -398,6 +421,8 @@ class StdioHookRunner<Name extends HookName> extends HookRunner<Name> {
|
||||
|
||||
// If we have valid JSON, honor it regardless of exit code
|
||||
if (parsedOutput) {
|
||||
const durationMs = performance.now() - startTime
|
||||
|
||||
// Log warning if non-zero exit but valid JSON (for developers)
|
||||
if (exitCode !== 0) {
|
||||
console.warn(`[Hook ${this.hookName}] Exited with code ${exitCode} but provided valid JSON response`)
|
||||
@@ -406,6 +431,39 @@ class StdioHookRunner<Name extends HookName> extends HookRunner<Name> {
|
||||
}
|
||||
}
|
||||
|
||||
// Capture success/cancellation telemetry
|
||||
if (taskId) {
|
||||
if (parsedOutput.cancel) {
|
||||
telemetryService.safeCapture(
|
||||
() =>
|
||||
telemetryService.captureHookExecution(taskId, this.hookName, "completed", {
|
||||
source: this.source,
|
||||
toolName: this.toolName,
|
||||
durationMs,
|
||||
exitCode: exitCode ?? EXIT_CODE_SIGINT,
|
||||
cancelRequested: true,
|
||||
contextModified: !!parsedOutput.contextModification,
|
||||
contextSize: parsedOutput.contextModification?.length,
|
||||
}),
|
||||
"HookFactory.exec.completed.cancel",
|
||||
)
|
||||
} else {
|
||||
telemetryService.safeCapture(
|
||||
() =>
|
||||
telemetryService.captureHookExecution(taskId, this.hookName, "completed", {
|
||||
source: this.source,
|
||||
toolName: this.toolName,
|
||||
durationMs,
|
||||
exitCode: exitCode ?? 0,
|
||||
cancelRequested: false,
|
||||
contextModified: !!parsedOutput.contextModification,
|
||||
contextSize: parsedOutput.contextModification?.length,
|
||||
}),
|
||||
"HookFactory.exec.completed.success",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return parsedOutput
|
||||
}
|
||||
|
||||
@@ -413,6 +471,24 @@ class StdioHookRunner<Name extends HookName> extends HookRunner<Name> {
|
||||
if (exitCode === 0) {
|
||||
// Hook succeeded but didn't provide JSON - allow execution (no cancellation)
|
||||
console.warn(`[Hook ${this.hookName}] Completed successfully but no JSON response found`)
|
||||
const durationMs = performance.now() - startTime
|
||||
|
||||
// Capture success telemetry even without JSON
|
||||
if (taskId) {
|
||||
telemetryService.safeCapture(
|
||||
() =>
|
||||
telemetryService.captureHookExecution(taskId, this.hookName, "completed", {
|
||||
source: this.source,
|
||||
toolName: this.toolName,
|
||||
durationMs,
|
||||
exitCode: 0,
|
||||
cancelRequested: false,
|
||||
contextModified: false,
|
||||
}),
|
||||
"HookFactory.exec.completed.noJson",
|
||||
)
|
||||
}
|
||||
|
||||
return HookOutput.create({
|
||||
cancel: false,
|
||||
})
|
||||
@@ -421,8 +497,48 @@ class StdioHookRunner<Name extends HookName> extends HookRunner<Name> {
|
||||
throw HookExecutionError.execution(this.scriptPath, exitCode ?? 1, stderr, this.hookName)
|
||||
}
|
||||
} catch (error) {
|
||||
const durationMs = performance.now() - startTime
|
||||
|
||||
// If it's already a HookExecutionError, re-throw it
|
||||
if (HookExecutionError.isHookError(error)) {
|
||||
// Capture failure telemetry based on error type
|
||||
if (taskId) {
|
||||
if (error.errorInfo.type === "cancellation") {
|
||||
telemetryService.safeCapture(
|
||||
() =>
|
||||
telemetryService.captureHookExecution(taskId, this.hookName, "cancelled", {
|
||||
source: this.source,
|
||||
toolName: this.toolName,
|
||||
}),
|
||||
"HookFactory.exec.error.cancellation",
|
||||
)
|
||||
} else if (error.errorInfo.type === "timeout") {
|
||||
telemetryService.safeCapture(
|
||||
() =>
|
||||
telemetryService.captureHookExecution(taskId, this.hookName, "failed", {
|
||||
source: this.source,
|
||||
toolName: this.toolName,
|
||||
durationMs,
|
||||
errorType: "timeout",
|
||||
errorMessage: error.message,
|
||||
}),
|
||||
"HookFactory.exec.error.timeout",
|
||||
)
|
||||
} else {
|
||||
telemetryService.safeCapture(
|
||||
() =>
|
||||
telemetryService.captureHookExecution(taskId, this.hookName, "failed", {
|
||||
source: this.source,
|
||||
toolName: this.toolName,
|
||||
durationMs,
|
||||
exitCode: error.errorInfo.exitCode ?? 1,
|
||||
errorType: error.errorInfo.type as "execution" | "timeout" | "validation",
|
||||
errorMessage: error.message,
|
||||
}),
|
||||
"HookFactory.exec.error.failed",
|
||||
)
|
||||
}
|
||||
}
|
||||
throw error
|
||||
}
|
||||
|
||||
@@ -432,15 +548,52 @@ class StdioHookRunner<Name extends HookName> extends HookRunner<Name> {
|
||||
|
||||
// Check for timeout
|
||||
if (error instanceof Error && error.message.includes("timed out")) {
|
||||
if (taskId) {
|
||||
telemetryService.safeCapture(
|
||||
() =>
|
||||
telemetryService.captureHookExecution(taskId, this.hookName, "failed", {
|
||||
source: this.source,
|
||||
toolName: this.toolName,
|
||||
durationMs,
|
||||
errorType: "timeout",
|
||||
errorMessage: error.message,
|
||||
}),
|
||||
"HookFactory.exec.catch.timeout",
|
||||
)
|
||||
}
|
||||
throw HookExecutionError.timeout(this.scriptPath, HOOK_EXECUTION_TIMEOUT_MS, stderr, this.hookName)
|
||||
}
|
||||
|
||||
// Check for cancellation
|
||||
if (error instanceof Error && error.message.includes("cancelled")) {
|
||||
if (taskId) {
|
||||
telemetryService.safeCapture(
|
||||
() =>
|
||||
telemetryService.captureHookExecution(taskId, this.hookName, "cancelled", {
|
||||
source: this.source,
|
||||
toolName: this.toolName,
|
||||
}),
|
||||
"HookFactory.exec.catch.cancelled",
|
||||
)
|
||||
}
|
||||
throw HookExecutionError.cancellation(this.scriptPath, this.hookName)
|
||||
}
|
||||
|
||||
// Generic execution error - include hook name
|
||||
if (taskId) {
|
||||
telemetryService.safeCapture(
|
||||
() =>
|
||||
telemetryService.captureHookExecution(taskId, this.hookName, "failed", {
|
||||
source: this.source,
|
||||
toolName: this.toolName,
|
||||
durationMs,
|
||||
exitCode: exitCode ?? 1,
|
||||
errorType: "execution",
|
||||
errorMessage: error instanceof Error ? error.message : String(error),
|
||||
}),
|
||||
"HookFactory.exec.catch.execution",
|
||||
)
|
||||
}
|
||||
throw HookExecutionError.execution(this.scriptPath, exitCode ?? 1, stderr, this.hookName)
|
||||
}
|
||||
}
|
||||
@@ -546,8 +699,8 @@ export class HookFactory {
|
||||
/**
|
||||
* Create a hook runner without streaming support (backwards compatible)
|
||||
*/
|
||||
async create<Name extends HookName>(hookName: Name): Promise<HookRunner<Name>> {
|
||||
return this.createWithStreaming(hookName)
|
||||
async create<Name extends HookName>(hookName: Name, taskId?: string, toolName?: string): Promise<HookRunner<Name>> {
|
||||
return this.createWithStreaming(hookName, undefined, undefined, taskId, toolName)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -566,24 +719,94 @@ export class HookFactory {
|
||||
* @param hookName The type of hook to create (e.g., "PreToolUse", "PostToolUse")
|
||||
* @param streamCallback Optional callback for real-time output streaming
|
||||
* @param abortSignal Optional signal to cancel hook execution
|
||||
* @param taskId Optional task ID for telemetry context
|
||||
* @param toolName Optional tool name for telemetry context
|
||||
* @returns A HookRunner that executes the hook(s), or NoOpRunner if none found
|
||||
*/
|
||||
async createWithStreaming<Name extends HookName>(
|
||||
hookName: Name,
|
||||
streamCallback?: HookStreamCallback,
|
||||
abortSignal?: AbortSignal,
|
||||
taskId?: string,
|
||||
toolName?: string,
|
||||
): Promise<HookRunner<Name>> {
|
||||
// Use cache for hook discovery instead of direct file system scan
|
||||
const { HookDiscoveryCache } = await import("./HookDiscoveryCache")
|
||||
const scripts = await HookDiscoveryCache.getInstance().get(hookName)
|
||||
|
||||
const runners = scripts.map((script) => new StdioHookRunner(hookName, script, streamCallback, abortSignal))
|
||||
// Fetch hooks dirs once for source determination and telemetry
|
||||
const hooksDirs = await getAllHooksDirs()
|
||||
|
||||
// Capture hook discovery telemetry
|
||||
// Categorize scripts by location (global vs workspace)
|
||||
const { globalCount, workspaceCount } = this.categorizeHookScripts(scripts, hooksDirs)
|
||||
if (scripts.length > 0) {
|
||||
telemetryService.safeCapture(
|
||||
() => telemetryService.captureHookDiscovery(hookName, globalCount, workspaceCount),
|
||||
"HookFactory.createWithStreaming.discovery",
|
||||
)
|
||||
}
|
||||
|
||||
// Create runners with source determination for each script
|
||||
const runners = scripts.map((script) => {
|
||||
const source = this.determineScriptSource(script, hooksDirs)
|
||||
return new StdioHookRunner(hookName, script, source, streamCallback, abortSignal, taskId, toolName)
|
||||
})
|
||||
|
||||
if (runners.length === 0) {
|
||||
return new NoOpRunner(hookName)
|
||||
}
|
||||
return runners.length === 1 ? runners[0] : new CombinedHookRunner(hookName, runners)
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a hooks directory is a global hooks directory.
|
||||
* Global hooks are located in paths containing "Cline/Hooks" or "cline/hooks".
|
||||
*/
|
||||
private static isGlobalHooksDir(dir: string): boolean {
|
||||
return /[/\\][Cc]line[/\\][Hh]ooks/i.test(dir)
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a single script is from global or workspace location
|
||||
*/
|
||||
private determineScriptSource(scriptPath: string, hooksDirs: string[]): "global" | "workspace" {
|
||||
const containingDir = hooksDirs.find((dir) => scriptPath.startsWith(dir))
|
||||
if (containingDir && HookFactory.isGlobalHooksDir(containingDir)) {
|
||||
return "global"
|
||||
}
|
||||
return "workspace" // Default to workspace if uncertain
|
||||
}
|
||||
|
||||
/**
|
||||
* Categorizes hook scripts by their location (global vs workspace).
|
||||
* Global hooks are located in ~/Documents/Cline/Hooks/
|
||||
* Workspace hooks are located in workspace .clinerules/hooks/ directories
|
||||
*
|
||||
* @param scripts Array of hook script paths
|
||||
* @param hooksDirs Array of hooks directories (passed to avoid redundant fetches)
|
||||
* @returns Object with globalCount and workspaceCount
|
||||
*/
|
||||
private categorizeHookScripts(scripts: string[], hooksDirs: string[]): { globalCount: number; workspaceCount: number } {
|
||||
if (scripts.length === 0) {
|
||||
return { globalCount: 0, workspaceCount: 0 }
|
||||
}
|
||||
|
||||
let globalCount = 0
|
||||
let workspaceCount = 0
|
||||
|
||||
for (const script of scripts) {
|
||||
const containingDir = hooksDirs.find((dir) => script.startsWith(dir))
|
||||
if (containingDir && HookFactory.isGlobalHooksDir(containingDir)) {
|
||||
globalCount++
|
||||
} else {
|
||||
workspaceCount++
|
||||
}
|
||||
}
|
||||
|
||||
return { globalCount, workspaceCount }
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns A list of paths to scripts for the given hook name.
|
||||
* Includes both global hooks (from ~/Documents/Cline/Hooks/) and workspace hooks
|
||||
|
||||
+483
@@ -0,0 +1,483 @@
|
||||
[
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "ask_followup_question",
|
||||
"description": "Ask user a question for clarifying or gathering information needed to complete the task. For example, ask the user clarifying questions about a key implementation decision. You should only ask one question.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"question": {
|
||||
"type": "string",
|
||||
"description": "The single question to ask the user. E.g. \"How can I help you?\""
|
||||
},
|
||||
"options": {
|
||||
"type": "string",
|
||||
"description": "An array of 2-5 options (e.x: \"[\"Option 1\", \"Option 2\", \"Option 3\"]\") for the user to choose from. Each option should be a string describing a possible answer to the single question. You may not always need to provide options, but it may be helpful in many cases where it can save the user from having to type out a response manually. IMPORTANT: NEVER include an option to toggle to Act mode, as this would be something you need to direct the user to do manually themselves if needed."
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"question",
|
||||
"options"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "execute_command",
|
||||
"description": "Request to execute a CLI command on the system. Use this when you need to perform system operations or run specific commands to accomplish any step in the user's task.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"command": {
|
||||
"type": "string",
|
||||
"description": "The CLI command to execute. This should be valid for the current operating system. Do not use the ~ character or $HOME to refer to the home directory. Always use absolute paths. The command will be executed from the current workspace, you do not need to cd to the workspace."
|
||||
},
|
||||
"requires_approval": {
|
||||
"type": "boolean",
|
||||
"description": "To indicate whether this command requires explicit user approval or interaction before it should be executed. For system/file altering operations like installing/uninstalling packages, removing/overwriting files, system configuration changes, network operations, or any commands that are considered potentially dangerous must be set to true. False for safe operations like running development servers, building projects, and other non-destructive operations."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"command",
|
||||
"requires_approval"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "read_file",
|
||||
"description": "Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. Do NOT use this tool to list the contents of a directory. Only use this tool on files.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "string",
|
||||
"description": "The path of the file to read (relative to the current working directory {{CWD}}){{MULTI_ROOT_HINT}}"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"path"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "write_to_file",
|
||||
"description": "[IMPORTANT: Always output the absolutePath first] Request to write content to a file at the specified path. If the file exists, it will be overwritten with the provided content. If the file doesn't exist, it will be created. This tool will automatically create any directories needed to write the file.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"absolutePath": {
|
||||
"type": "string",
|
||||
"description": "The absolute path to the file to write to."
|
||||
},
|
||||
"content": {
|
||||
"type": "string",
|
||||
"description": "After providing the path so a file can be created, then use this to provide the content to write to the file."
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"absolutePath",
|
||||
"content"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "replace_in_file",
|
||||
"description": "[IMPORTANT: Always output the absolutePath first] Request to replace sections of content in an existing file using SEARCH/REPLACE blocks that define exact changes to specific parts of the file. This tool should be used when you need to make targeted changes to specific parts of a file.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"absolutePath": {
|
||||
"type": "string",
|
||||
"description": "The absolute path to the file to write to."
|
||||
},
|
||||
"diff": {
|
||||
"type": "string",
|
||||
"description": "One or more SEARCH/REPLACE blocks following this exact format:\n ```\n ------- SEARCH\n [exact content to find]\n =======\n [new content to replace with]\n +++++++ REPLACE\n ```\n Critical rules:\n 1. SEARCH content must match the associated file section to find EXACTLY:\n\t * Match character-for-character including whitespace, indentation, line endings\n\t * Include all comments, docstrings, etc.\n 2. SEARCH/REPLACE blocks will ONLY replace the first match occurrence.\n\t * Including multiple unique SEARCH/REPLACE blocks if you need to make multiple changes.\n\t * Include *just* enough lines in each SEARCH section to uniquely match each set of lines that need to change.\n\t * When using multiple SEARCH/REPLACE blocks, list them in the order they appear in the file.\n 3. Keep SEARCH/REPLACE blocks concise:\n\t * Break large SEARCH/REPLACE blocks into a series of smaller blocks that each change a small portion of the file.\n\t * Include just the changing lines, and a few surrounding lines if needed for uniqueness.\n\t * Do not include long runs of unchanging lines in SEARCH/REPLACE blocks.\n\t * Each line must be complete. Never truncate lines mid-way through as this can cause matching failures.\n 4. Special operations:\n\t * To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)\n\t * To delete code: Use empty REPLACE section"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"absolutePath",
|
||||
"diff"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "search_files",
|
||||
"description": "Request to perform a regex search across files in a specified directory, providing context-rich results. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "string",
|
||||
"description": "The path of the directory to search in (relative to the current working directory {{CWD}}){{MULTI_ROOT_HINT}}. This directory will be recursively searched."
|
||||
},
|
||||
"regex": {
|
||||
"type": "string",
|
||||
"description": "The regular expression pattern to search for. Uses Rust regex syntax."
|
||||
},
|
||||
"file_pattern": {
|
||||
"type": "string",
|
||||
"description": "Glob pattern to filter files (e.g., '*.ts' for TypeScript files). If not provided, it will search all files (*)."
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"path",
|
||||
"regex"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "list_files",
|
||||
"description": "Request to list files and directories within the specified directory. If recursive is true, it will list all files and directories recursively. If recursive is false or not provided, it will only list the top-level contents. Do not use this tool to confirm the existence of files you may have created, as the user will let you know if the files were created successfully or not.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "string",
|
||||
"description": "The path of the directory to list contents for."
|
||||
},
|
||||
"recursive": {
|
||||
"type": "boolean",
|
||||
"description": "Whether to list files recursively. Use true for recursive listing, false or omit for top-level only."
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"path"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "list_code_definition_names",
|
||||
"description": "Request to list definition names (classes, functions, methods, etc.) used in source code files at the top level of the specified directory. This tool provides insights into the codebase structure and important constructs, encapsulating high-level concepts and relationships that are crucial for understanding the overall architecture.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "string",
|
||||
"description": "The path of the directory (relative to the current working directory {{CWD}}){{MULTI_ROOT_HINT}} to list top level source code definitions for."
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"path"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "browser_action",
|
||||
"description": "Request to interact with a Puppeteer-controlled browser. Every action, except `close`, will be responded to with a screenshot of the browser's current state, along with any new console logs. You may only perform one browser action per message, and wait for the user's response including a screenshot and logs to determine the next action.\n- The sequence of actions **must always start with** launching the browser at a URL, and **must always end with** closing the browser. If you need to visit a new URL that is not possible to navigate to from the current webpage, you must first close the browser, then launch again at the new URL.\n- While the browser is active, only the `browser_action` tool can be used. No other tools should be called during this time. You may proceed to use other tools only after closing the browser. For example if you run into an error and need to fix a file, you must close the browser, then use other tools to make the necessary changes, then re-launch the browser to verify the result.\n- The browser window has a resolution of **1280x720** pixels. When performing any click actions, ensure the coordinates are within this resolution range.\n- Before clicking on any elements such as icons, links, or buttons, you must consult the provided screenshot of the page to determine the coordinates of the element. The click should be targeted at the **center of the element**, not on its edges.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"action": {
|
||||
"type": "string",
|
||||
"description": "The action to perform. The available actions are: \n\t* launch: Launch a new Puppeteer-controlled browser instance at the specified URL. This **must always be the first action**. \n\t\t- Use with the `url` parameter to provide the URL. \n\t\t- Ensure the URL is valid and includes the appropriate protocol (e.g. http://localhost:3000/page, file:///path/to/file.html, etc.) \n\t* click: Click at a specific x,y coordinate. \n\t\t- Use with the `coordinate` parameter to specify the location. \n\t\t- Always click in the center of an element (icon, button, link, etc.) based on coordinates derived from a screenshot. \n\t* type: Type a string of text on the keyboard. You might use this after clicking on a text field to input text. \n\t\t- Use with the `text` parameter to provide the string to type. \n\t* scroll_down: Scroll down the page by one page height. \n\t* scroll_up: Scroll up the page by one page height. \n\t* close: Close the Puppeteer-controlled browser instance. This **must always be the final browser action**. \n\t - Example: 'scroll_up'"
|
||||
},
|
||||
"url": {
|
||||
"type": "string",
|
||||
"description": "Use this for providing the URL for the `launch` action."
|
||||
},
|
||||
"coordinate": {
|
||||
"type": "string",
|
||||
"description": "x,y coordinates - The X and Y coordinates for the `click` action. Coordinates should be within the **1280x720** resolution. Example: '450,300'"
|
||||
},
|
||||
"text": {
|
||||
"type": "string",
|
||||
"description": "Use this for providing the text for the `type` action. Example: 'Hello, world!'"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"action"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "web_fetch",
|
||||
"description": "Fetches and analyzes content from a specified URL.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"url": {
|
||||
"type": "string",
|
||||
"description": "The URL to fetch content from"
|
||||
},
|
||||
"prompt": {
|
||||
"type": "string",
|
||||
"description": "Prompt for analyzing the webpage content"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"url",
|
||||
"prompt"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "web_search",
|
||||
"description": "Performs a web search and returns relevant results with titles and URLs.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"query": {
|
||||
"type": "string",
|
||||
"description": "The search query to use"
|
||||
},
|
||||
"allowed_domains": {
|
||||
"type": "string",
|
||||
"description": "JSON array of domains to restrict results to"
|
||||
},
|
||||
"blocked_domains": {
|
||||
"type": "string",
|
||||
"description": "JSON array of domains to exclude from results"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"query"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "access_mcp_resource",
|
||||
"description": "Request to access a resource provided by a connected MCP server. Resources represent data sources that can be used as context, such as files, API responses, or system information. You must only use this tool if you have been informed of the MCP server and the resource you are trying to access.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"server_name": {
|
||||
"type": "string",
|
||||
"description": "The name of the MCP server providing the resource"
|
||||
},
|
||||
"uri": {
|
||||
"type": "string",
|
||||
"description": "The URI identifying the specific resource to access"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"server_name",
|
||||
"uri"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "attempt_completion",
|
||||
"description": "Once you've completed the user's task, use this tool to present the final result to the user, including a brief and very short (1-2 paragraph) summary of the task and what was done to resolve it. Provide the basics, hitting the highlights, but do delve into the specifics. You should only call this tool when you have completed all tasks in the task_progress list, and completed all changes that are necessary to satisfy the user's request. You should not provide the contents of the task_progress list in the result parameter, it must be included in the task_progress parameter.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"result": {
|
||||
"type": "string",
|
||||
"description": "A clear, brief and very short (1-2 paragraph) summary of the final result of the task."
|
||||
},
|
||||
"command": {
|
||||
"type": "string",
|
||||
"description": "An actionable terminal command that is non-verbose that allows user to review the result of your work. For example, use `start localhost:3000` to start a locally running development server. Commands like `echo` or `cat` that merely print text or open a file are not allowed. Ensure the command is properly formatted for user's OS and does not contain any harmful instructions"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress with the latest status of each subtasks included previously, if any. If you are calling attempt completion, and all items in this list have been completed, they must be marked as completed in this response."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"result"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "plan_mode_respond",
|
||||
"description": "Respond to the user's inquiry in an effort to plan a solution to the user's task. This tool should ONLY be used when you have already explored the relevant files and are ready to present a concrete plan. DO NOT use this tool to announce what files you're going to read - just read them first. This tool is only available in PLAN MODE. The environment_details will specify the current mode; if it is not PLAN_MODE then you should not use this tool.\nHowever, if while writing your response you realize you actually need to do more exploration before providing a complete plan, you can add the optional needs_more_exploration parameter to indicate this. This allows you to acknowledge that you should have done more exploration first, and signals that your next message will use exploration tools instead.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"response": {
|
||||
"type": "string",
|
||||
"description": "The response to provide to the user."
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress with the latest status of each subtasks included previously if any."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"response"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "load_mcp_documentation",
|
||||
"description": "Load documentation about creating MCP servers. This tool should be used when the user requests to create or install an MCP server (the user may ask you something along the lines of \"add a tool\" that does some function, in other words to create an MCP server that provides tools and resources that may connect to external APIs for example. You have the ability to create an MCP server and add it to a configuration file that will then expose the tools and resources for you to use with `use_mcp_tool` and `access_mcp_resource`). The documentation provides detailed information about the MCP server creation process, including setup instructions, best practices, and examples.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {},
|
||||
"required": [],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "focus_chain",
|
||||
"description": "",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {},
|
||||
"required": [],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "generate_explanation",
|
||||
"description": "Opens a multi-file diff view and generates AI-powered inline comments explaining the changes between two git references. Use this tool to help users understand code changes from git commits, pull requests, branches, or any git refs. The tool uses git to retrieve file contents and displays a side-by-side diff view with explanatory comments.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"title": {
|
||||
"type": "string",
|
||||
"description": "A descriptive title for the diff view (e.g., 'Changes in commit abc123', 'PR #42: Add authentication', 'Changes between main and feature-branch')"
|
||||
},
|
||||
"from_ref": {
|
||||
"type": "string",
|
||||
"description": "The git reference for the 'before' state. Can be a commit hash, branch name, tag, or relative reference like HEAD~1, HEAD^, origin/main, etc."
|
||||
},
|
||||
"to_ref": {
|
||||
"type": "string",
|
||||
"description": "The git reference for the 'after' state. Can be a commit hash, branch name, tag, or relative reference. If not provided, compares to the current working directory (including uncommitted changes)."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"title",
|
||||
"from_ref"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "12345670mcp0test_tool",
|
||||
"description": "test-server: A test tool",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {},
|
||||
"required": [],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
+434
@@ -0,0 +1,434 @@
|
||||
[
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "execute_command",
|
||||
"description": "Request to execute a CLI command on the system. Use this when you need to perform system operations or run specific commands to accomplish any step in the user's task. You must tailor your command to the user's system and provide a clear explanation of what the command does. For command chaining, use the appropriate chaining syntax for the user's shell. Prefer to execute complex CLI commands over creating executable scripts, as they are more flexible and easier to run. Commands will be executed in the current working directory: {{CWD}}{{MULTI_ROOT_HINT}}",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"command": {
|
||||
"type": "string",
|
||||
"description": "The CLI command to execute. This should be valid for the current operating system. Ensure the command is properly formatted and does not contain any harmful instructions."
|
||||
},
|
||||
"requires_approval": {
|
||||
"type": "boolean",
|
||||
"description": "A boolean indicating whether this command requires explicit user approval before execution in case the user has auto-approve mode enabled. Set to 'true' for potentially impactful operations like installing/uninstalling packages, deleting/overwriting files, system configuration changes, network operations, or any commands that could have unintended side effects. Set to 'false' for safe operations like reading files/directories, running development servers, building projects, and other non-destructive operations."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"command",
|
||||
"requires_approval"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "read_file",
|
||||
"description": "Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. Do NOT use this tool to list the contents of a directory. Only use this tool on files.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "string",
|
||||
"description": "The path of the file to read (relative to the current working directory {{CWD}}){{MULTI_ROOT_HINT}}"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"path"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "apply_patch",
|
||||
"description": "This is a custom utility that makes it more convenient to add, remove, move, or edit code in a single file. `apply_patch` effectively allows you to execute a diff/patch against a file, but the format of the diff specification is unique to this task, so pay careful attention to these instructions. To use the `apply_patch` command, you should pass a message of the following structure as \"input\":\n\n%%bash\napply_patch <<\"EOF\"\n*** Begin Patch\n[YOUR_PATCH]\n*** End Patch\nEOF\n\nWhere [YOUR_PATCH] is the actual content of your patch, specified in the following V4A diff format.\n\n*** [ACTION] File: [path/to/file] -> ACTION can be one of Add, Update, or Delete. \n\nIn a Add File section, every line of the new file (including blank/empty lines) MUST start with a `+` prefix. Do not include any unprefixed lines inside an Add section\nIn a Update/Delete section, repeat the following for each snippet of code that needs to be changed:\n[context_before] -> See below for further instructions on context.\n- [old_code] -> Precede the old code with a minus sign.\n+ [new_code] -> Precede the new, replacement code with a plus sign.\n[context_after] -> See below for further instructions on context.\n\nFor instructions on [context_before] and [context_after]:\n- By default, show 3 lines of code immediately above and 3 lines immediately below each change. If a change is within 3 lines of a previous change, do NOT duplicate the first change’s [context_after] lines in the second change’s [context_before] lines.\n- If 3 lines of context is insufficient to uniquely identify the snippet of code within the file, use the @@ operator to indicate the class or function to which the snippet belongs. For instance, we might have:\n@@ class BaseClass\n[3 lines of pre-context]\n- [old_code]\n+ [new_code]\n[3 lines of post-context]\n\n- If a code block is repeated so many times in a class or function such that even a single @@ statement and 3 lines of context cannot uniquely identify the snippet of code, you can use multiple `@@` statements to jump to the right context. For instance:\n\n@@ class BaseClass\n@@ \tdef method():\n[3 lines of pre-context]\n- [old_code]\n+ [new_code]\n[3 lines of post-context]\n\nNote, then, that we do not use line numbers in this diff format, as the context is enough to uniquely identify code. An example of a message that you might pass as \"input\" to this function, in order to apply a patch, is shown below.\n\n%%bash\napply_patch <<\"EOF\"\n*** Begin Patch\n*** Update File: pygorithm/searching/binary_search.py\n@@ class BaseClass\n@@ def search():\n- pass\n+ raise NotImplementedError()\n\n@@ class Subclass\n@@ def search():\n- pass\n+ raise NotImplementedError()\n\n*** End Patch\nEOF",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"input": {
|
||||
"type": "string",
|
||||
"description": "The apply_patch command that you wish to execute."
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"input"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "search_files",
|
||||
"description": "Request to perform a regex search across files in a specified directory, providing context-rich results. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "string",
|
||||
"description": "The path of the directory to search in (relative to the current working directory {{CWD}}){{MULTI_ROOT_HINT}}. This directory will be recursively searched."
|
||||
},
|
||||
"regex": {
|
||||
"type": "string",
|
||||
"description": "The regular expression pattern to search for. Uses Rust regex syntax."
|
||||
},
|
||||
"file_pattern": {
|
||||
"type": "string",
|
||||
"description": "Glob pattern to filter files (e.g., '*.ts' for TypeScript files). If not provided, it will search all files (*)."
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"path",
|
||||
"regex"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "list_files",
|
||||
"description": "Request to list files and directories within the specified directory. If recursive is true, it will list all files and directories recursively. If recursive is false or not provided, it will only list the top-level contents. Do not use this tool to confirm the existence of files you may have created, as the user will let you know if the files were created successfully or not.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "string",
|
||||
"description": "The path of the directory to list contents for (relative to the current working directory {{CWD}}){{MULTI_ROOT_HINT}}"
|
||||
},
|
||||
"recursive": {
|
||||
"type": "boolean",
|
||||
"description": "Whether to list files recursively. Use true for recursive listing, false or omit for top-level only."
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"path"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "list_code_definition_names",
|
||||
"description": "Request to list definition names (classes, functions, methods, etc.) used in source code files at the top level of the specified directory. This tool provides insights into the codebase structure and important constructs, encapsulating high-level concepts and relationships that are crucial for understanding the overall architecture.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "string",
|
||||
"description": "The path of the directory (relative to the current working directory {{CWD}}){{MULTI_ROOT_HINT}} to list top level source code definitions for."
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"path"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "browser_action",
|
||||
"description": "Request to interact with a Puppeteer-controlled browser. Every action, except `close`, will be responded to with a screenshot of the browser's current state, along with any new console logs. You may only perform one browser action per message, and wait for the user's response including a screenshot and logs to determine the next action.\n- The sequence of actions **must always start with** launching the browser at a URL, and **must always end with** closing the browser. If you need to visit a new URL that is not possible to navigate to from the current webpage, you must first close the browser, then launch again at the new URL.\n- While the browser is active, only the `browser_action` tool can be used. No other tools should be called during this time. You may proceed to use other tools only after closing the browser. For example if you run into an error and need to fix a file, you must close the browser, then use other tools to make the necessary changes, then re-launch the browser to verify the result.\n- The browser window has a resolution of **1280x720** pixels. When performing any click actions, ensure the coordinates are within this resolution range.\n- Before clicking on any elements such as icons, links, or buttons, you must consult the provided screenshot of the page to determine the coordinates of the element. The click should be targeted at the **center of the element**, not on its edges.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"action": {
|
||||
"type": "string",
|
||||
"description": "The action to perform. The available actions are: \n\t* launch: Launch a new Puppeteer-controlled browser instance at the specified URL. This **must always be the first action**. \n\t\t- Use with the `url` parameter to provide the URL. \n\t\t- Ensure the URL is valid and includes the appropriate protocol (e.g. http://localhost:3000/page, file:///path/to/file.html, etc.) \n\t* click: Click at a specific x,y coordinate. \n\t\t- Use with the `coordinate` parameter to specify the location. \n\t\t- Always click in the center of an element (icon, button, link, etc.) based on coordinates derived from a screenshot. \n\t* type: Type a string of text on the keyboard. You might use this after clicking on a text field to input text. \n\t\t- Use with the `text` parameter to provide the string to type. \n\t* scroll_down: Scroll down the page by one page height. \n\t* scroll_up: Scroll up the page by one page height. \n\t* close: Close the Puppeteer-controlled browser instance. This **must always be the final browser action**. \n\t - Example: `<action>close</action>`"
|
||||
},
|
||||
"url": {
|
||||
"type": "string",
|
||||
"description": "Use this for providing the URL for the `launch` action. \n\t* Example: <url>https://example.com</url>"
|
||||
},
|
||||
"coordinate": {
|
||||
"type": "string",
|
||||
"description": "The X and Y coordinates for the `click` action. Coordinates should be within the **1280x720** resolution. \n\t* Example: <coordinate>450,300</coordinate>"
|
||||
},
|
||||
"text": {
|
||||
"type": "string",
|
||||
"description": "Use this for providing the text for the `type` action. \n\t* Example: <text>Hello, world!</text>"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"action"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "access_mcp_resource",
|
||||
"description": "Request to access a resource provided by a connected MCP server. Resources represent data sources that can be used as context, such as files, API responses, or system information.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"server_name": {
|
||||
"type": "string",
|
||||
"description": "The name of the MCP server providing the resource"
|
||||
},
|
||||
"uri": {
|
||||
"type": "string",
|
||||
"description": "The URI identifying the specific resource to access"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"server_name",
|
||||
"uri"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "ask_followup_question",
|
||||
"description": "Ask the user a question to gather additional information needed to complete the task. This tool should be used when you encounter ambiguities, need clarification, or require more details to proceed effectively. It allows for interactive problem-solving by enabling direct communication with the user. Use this tool judiciously to maintain a balance between gathering necessary information and avoiding excessive back-and-forth.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"question": {
|
||||
"type": "string",
|
||||
"description": "The question to ask the user. This should be a clear, specific question that addresses the information you need."
|
||||
},
|
||||
"options": {
|
||||
"type": "string",
|
||||
"description": "An array of 2-5 options for the user to choose from. Each option should be a string describing a possible answer. You may not always need to provide options, but it may be helpful in many cases where it can save the user from having to type out a response manually. IMPORTANT: NEVER include an option to toggle to Act mode, as this would be something you need to direct the user to do manually themselves if needed."
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"question"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "attempt_completion",
|
||||
"description": "After each tool use, the user will respond with the result of that tool use, i.e. if it succeeded or failed, along with any reasons for failure. Once you've received the results of tool uses and can confirm that the task is complete, use this tool to present the result of your work to the user. Optionally you may provide a CLI command to showcase the result of your work. The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again.\nIMPORTANT NOTE: This tool CANNOT be used until you've confirmed from the user that any previous tool uses were successful. Failure to do so will result in code corruption and system failure. Before using this tool, you must ask yourself in <thinking></thinking> tags if you've confirmed from the user that any previous tool uses were successful. If not, then DO NOT use this tool.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"result": {
|
||||
"type": "string",
|
||||
"description": "The result of the tool use. This should be a clear, specific description of the result."
|
||||
},
|
||||
"command": {
|
||||
"type": "string",
|
||||
"description": "A CLI command to execute to show a live demo of the result to the user. For example, use `open index.html` to display a created html website, or `open localhost:3000` to display a locally running development server. But DO NOT use commands like `echo` or `cat` that merely print text. This command should be valid for the current operating system. Ensure the command is properly formatted and does not contain any harmful instructions"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. (See 'Updating Task Progress' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"result"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "new_task",
|
||||
"description": "Request to create a new task with preloaded context covering the conversation with the user up to this point and key information for continuing with the new task. With this tool, you will create a detailed summary of the conversation so far, paying close attention to the user's explicit requests and your previous actions, with a focus on the most relevant information required for the new task.\nAmong other important areas of focus, this summary should be thorough in capturing technical details, code patterns, and architectural decisions that would be essential for continuing with the new task. The user will be presented with a preview of your generated context and can choose to create a new task or keep chatting in the current conversation. The user may choose to start a new task at any point.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"context": {
|
||||
"type": "string",
|
||||
"description": "The context to preload the new task with. If applicable based on the current task, this should include:\n 1. Current Work: Describe in detail what was being worked on prior to this request to create a new task. Pay special attention to the more recent messages / conversation.\n 2. Key Technical Concepts: List all important technical concepts, technologies, coding conventions, and frameworks discussed, which might be relevant for the new task.\n 3. Relevant Files and Code: If applicable, enumerate specific files and code sections examined, modified, or created for the task continuation. Pay special attention to the most recent messages and changes.\n 4. Problem Solving: Document problems solved thus far and any ongoing troubleshooting efforts.\n 5. Pending Tasks and Next Steps: Outline all pending tasks that you have explicitly been asked to work on, as well as list the next steps you will take for all outstanding work, if applicable. Include code snippets where they add clarity. For any next steps, include direct quotes from the most recent conversation showing exactly what task you were working on and where you left off. This should be verbatim to ensure there's no information loss in context between tasks. It's important to be detailed here."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"context"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "plan_mode_respond",
|
||||
"description": "Respond to the user's inquiry in an effort to plan a solution to the user's task. This tool should ONLY be used when you have already explored the relevant files and are ready to present a concrete plan. DO NOT use this tool to announce what files you're going to read - just read them first. This tool is only available in PLAN MODE. The environment_details will specify the current mode; if it is not PLAN_MODE then you should not use this tool.\nHowever, if while writing your response you realize you actually need to do more exploration before providing a complete plan, you can add the optional needs_more_exploration parameter to indicate this. This allows you to acknowledge that you should have done more exploration first, and signals that your next message will use exploration tools instead.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"response": {
|
||||
"type": "string",
|
||||
"description": "The response to provide to the user. Do not try to use tools in this parameter, this is simply a chat response. (You MUST use the response parameter, do not simply place the response text directly within <plan_mode_respond> tags.)"
|
||||
},
|
||||
"needs_more_exploration": {
|
||||
"type": "boolean",
|
||||
"description": "Set to true if while formulating your response that you found you need to do more exploration with tools, for example reading files. (Remember, you can explore the project with tools like read_file in PLAN MODE without the user having to toggle to ACT MODE.) Defaults to false if not specified."
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": " A checklist showing task progress after this tool use is completed. (See 'Updating Task Progress' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"response"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "act_mode_respond",
|
||||
"description": "Provide a progress update or preamble to the user during ACT MODE execution. This tool allows you to communicate your thought process and planned actions without interrupting the execution flow. After displaying your message, execution automatically continues, allowing you to proceed with subsequent tool calls immediately. This tool is only available in ACT MODE. This tool may not be called immediately after a previous act_mode_respond call.\n\nIMPORTANT: Use this tool frequently to create a better user experience. Since it's non-blocking, there's no performance penalty for frequent use.\n\nUse this tool when:\n- After reading files and before making any edits - explain your analysis and what changes you plan to make\n- When starting a new phase of work (e.g., transitioning from backend to frontend, or from one feature to another)\n- During long sequences of operations to provide progress updates\n- When your approach or strategy changes mid-task\n- Before executing complex or potentially risky operations\n- To explain why you're choosing one approach over another\n\nDo NOT use this tool when you have completed all required actions and are ready to present the final output; in that case, use the attempt_completion tool instead.\n\nCRITICAL CONSTRAINT: You MUST NOT call this tool more than once in a row. After using act_mode_respond, your next assistant message MUST either call a different tool or perform additional work without using act_mode_respond again. If you attempt to call act_mode_respond consecutively, the tool call will fail with an explicit error.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"response": {
|
||||
"type": "string",
|
||||
"description": "The message to provide to the user. This should explain what you're about to do, your current progress, or your reasoning. The response should be brief and conversational in tone, aiming to keep the user informed without overwhelming them with details."
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress with the latest status of each subtasks included previously if any."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"response"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "load_mcp_documentation",
|
||||
"description": "Load documentation about creating MCP servers. This tool should be used when the user requests to create or install an MCP server (the user may ask you something along the lines of \"add a tool\" that does some function, in other words to create an MCP server that provides tools and resources that may connect to external APIs for example. You have the ability to create an MCP server and add it to a configuration file that will then expose the tools and resources for you to use with `use_mcp_tool` and `access_mcp_resource`). The documentation provides detailed information about the MCP server creation process, including setup instructions, best practices, and examples.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {},
|
||||
"required": [],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "focus_chain",
|
||||
"description": "",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {},
|
||||
"required": [],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "generate_explanation",
|
||||
"description": "Opens a multi-file diff view and generates AI-powered inline comments explaining the changes between two git references. Use this tool to help users understand code changes from git commits, pull requests, branches, or any git refs. The tool uses git to retrieve file contents and displays a side-by-side diff view with explanatory comments.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"title": {
|
||||
"type": "string",
|
||||
"description": "A descriptive title for the diff view (e.g., 'Changes in commit abc123', 'PR #42: Add authentication', 'Changes between main and feature-branch')"
|
||||
},
|
||||
"from_ref": {
|
||||
"type": "string",
|
||||
"description": "The git reference for the 'before' state. Can be a commit hash, branch name, tag, or relative reference like HEAD~1, HEAD^, origin/main, etc."
|
||||
},
|
||||
"to_ref": {
|
||||
"type": "string",
|
||||
"description": "The git reference for the 'after' state. Can be a commit hash, branch name, tag, or relative reference. If not provided, compares to the current working directory (including uncommitted changes)."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"title",
|
||||
"from_ref"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "12345670mcp0test_tool",
|
||||
"description": "test-server: A test tool",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {},
|
||||
"required": [],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
+420
@@ -0,0 +1,420 @@
|
||||
[
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "execute_command",
|
||||
"description": "Request to execute a CLI command on the system. Use this when you need to perform system operations or run specific commands to accomplish any step in the user's task.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"command": {
|
||||
"type": "string",
|
||||
"description": "The CLI command to execute. This should be valid for the current operating system. Do not use the ~ character or $HOME to refer to the home directory. Always use absolute paths. The command will be executed from the current workspace, you do not need to cd to the workspace."
|
||||
},
|
||||
"requires_approval": {
|
||||
"type": "boolean",
|
||||
"description": "To indicate whether this command requires explicit user approval or interaction before it should be executed. For system/file altering operations like installing/uninstalling packages, removing/overwriting files, system configuration changes, network operations, or any commands that are considered potentially dangerous must be set to true. False for safe operations like running development servers, building projects, and other non-destructive operations."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"command",
|
||||
"requires_approval"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "read_file",
|
||||
"description": "Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. Do NOT use this tool to list the contents of a directory. Only use this tool on files.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "string",
|
||||
"description": "The path of the file to read (relative to the current working directory {{CWD}}){{MULTI_ROOT_HINT}}"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"path"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "write_to_file",
|
||||
"description": "[IMPORTANT: Always output the absolutePath first] Request to write content to a file at the specified path. If the file exists, it will be overwritten with the provided content. If the file doesn't exist, it will be created. This tool will automatically create any directories needed to write the file.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"absolutePath": {
|
||||
"type": "string",
|
||||
"description": "The absolute path to the file to write to."
|
||||
},
|
||||
"content": {
|
||||
"type": "string",
|
||||
"description": "After providing the path so a file can be created, then use this to provide the content to write to the file."
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"absolutePath",
|
||||
"content"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "replace_in_file",
|
||||
"description": "[IMPORTANT: Always output the absolutePath first] Request to replace sections of content in an existing file using SEARCH/REPLACE blocks that define exact changes to specific parts of the file. This tool should be used when you need to make targeted changes to specific parts of a file.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"absolutePath": {
|
||||
"type": "string",
|
||||
"description": "The absolute path to the file to write to."
|
||||
},
|
||||
"diff": {
|
||||
"type": "string",
|
||||
"description": "One or more SEARCH/REPLACE blocks following this exact format:\n ```\n ------- SEARCH\n [exact content to find]\n =======\n [new content to replace with]\n +++++++ REPLACE\n ```\n Critical rules:\n 1. SEARCH content must match the associated file section to find EXACTLY:\n\t * Match character-for-character including whitespace, indentation, line endings\n\t * Include all comments, docstrings, etc.\n 2. SEARCH/REPLACE blocks will ONLY replace the first match occurrence.\n\t * Including multiple unique SEARCH/REPLACE blocks if you need to make multiple changes.\n\t * Include *just* enough lines in each SEARCH section to uniquely match each set of lines that need to change.\n\t * When using multiple SEARCH/REPLACE blocks, list them in the order they appear in the file.\n 3. Keep SEARCH/REPLACE blocks concise:\n\t * Break large SEARCH/REPLACE blocks into a series of smaller blocks that each change a small portion of the file.\n\t * Include just the changing lines, and a few surrounding lines if needed for uniqueness.\n\t * Do not include long runs of unchanging lines in SEARCH/REPLACE blocks.\n\t * Each line must be complete. Never truncate lines mid-way through as this can cause matching failures.\n 4. Special operations:\n\t * To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)\n\t * To delete code: Use empty REPLACE section"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"absolutePath",
|
||||
"diff"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "search_files",
|
||||
"description": "Request to perform a regex search across files in a specified directory, providing context-rich results. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "string",
|
||||
"description": "The path of the directory to search in (relative to the current working directory {{CWD}}){{MULTI_ROOT_HINT}}. This directory will be recursively searched."
|
||||
},
|
||||
"regex": {
|
||||
"type": "string",
|
||||
"description": "The regular expression pattern to search for. Uses Rust regex syntax."
|
||||
},
|
||||
"file_pattern": {
|
||||
"type": "string",
|
||||
"description": "Glob pattern to filter files (e.g., '*.ts' for TypeScript files). If not provided, it will search all files (*)."
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"path",
|
||||
"regex"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "list_files",
|
||||
"description": "Request to list files and directories within the specified directory. If recursive is true, it will list all files and directories recursively. If recursive is false or not provided, it will only list the top-level contents. Do not use this tool to confirm the existence of files you may have created, as the user will let you know if the files were created successfully or not.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "string",
|
||||
"description": "The path of the directory to list contents for."
|
||||
},
|
||||
"recursive": {
|
||||
"type": "boolean",
|
||||
"description": "Whether to list files recursively. Use true for recursive listing, false or omit for top-level only."
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"path"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "list_code_definition_names",
|
||||
"description": "Request to list definition names (classes, functions, methods, etc.) used in source code files at the top level of the specified directory. This tool provides insights into the codebase structure and important constructs, encapsulating high-level concepts and relationships that are crucial for understanding the overall architecture.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "string",
|
||||
"description": "The path of the directory (relative to the current working directory {{CWD}}){{MULTI_ROOT_HINT}} to list top level source code definitions for."
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"path"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "browser_action",
|
||||
"description": "Request to interact with a Puppeteer-controlled browser. Every action, except `close`, will be responded to with a screenshot of the browser's current state, along with any new console logs. You may only perform one browser action per message, and wait for the user's response including a screenshot and logs to determine the next action.\n- The sequence of actions **must always start with** launching the browser at a URL, and **must always end with** closing the browser. If you need to visit a new URL that is not possible to navigate to from the current webpage, you must first close the browser, then launch again at the new URL.\n- While the browser is active, only the `browser_action` tool can be used. No other tools should be called during this time. You may proceed to use other tools only after closing the browser. For example if you run into an error and need to fix a file, you must close the browser, then use other tools to make the necessary changes, then re-launch the browser to verify the result.\n- The browser window has a resolution of **1280x720** pixels. When performing any click actions, ensure the coordinates are within this resolution range.\n- Before clicking on any elements such as icons, links, or buttons, you must consult the provided screenshot of the page to determine the coordinates of the element. The click should be targeted at the **center of the element**, not on its edges.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"action": {
|
||||
"type": "string",
|
||||
"description": "The action to perform. The available actions are: \n\t* launch: Launch a new Puppeteer-controlled browser instance at the specified URL. This **must always be the first action**. \n\t\t- Use with the `url` parameter to provide the URL. \n\t\t- Ensure the URL is valid and includes the appropriate protocol (e.g. http://localhost:3000/page, file:///path/to/file.html, etc.) \n\t* click: Click at a specific x,y coordinate. \n\t\t- Use with the `coordinate` parameter to specify the location. \n\t\t- Always click in the center of an element (icon, button, link, etc.) based on coordinates derived from a screenshot. \n\t* type: Type a string of text on the keyboard. You might use this after clicking on a text field to input text. \n\t\t- Use with the `text` parameter to provide the string to type. \n\t* scroll_down: Scroll down the page by one page height. \n\t* scroll_up: Scroll up the page by one page height. \n\t* close: Close the Puppeteer-controlled browser instance. This **must always be the final browser action**. \n\t - Example: `<action>close</action>`"
|
||||
},
|
||||
"url": {
|
||||
"type": "string",
|
||||
"description": "Use this for providing the URL for the `launch` action. \n\t* Example: <url>https://example.com</url>"
|
||||
},
|
||||
"coordinate": {
|
||||
"type": "string",
|
||||
"description": "The X and Y coordinates for the `click` action. Coordinates should be within the **1280x720** resolution. \n\t* Example: <coordinate>450,300</coordinate>"
|
||||
},
|
||||
"text": {
|
||||
"type": "string",
|
||||
"description": "Use this for providing the text for the `type` action. \n\t* Example: <text>Hello, world!</text>"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"action"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "access_mcp_resource",
|
||||
"description": "Request to access a resource provided by a connected MCP server. Resources represent data sources that can be used as context, such as files, API responses, or system information. You must only use this tool if you have been informed of the MCP server and the resource you are trying to access.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"server_name": {
|
||||
"type": "string",
|
||||
"description": "The name of the MCP server providing the resource"
|
||||
},
|
||||
"uri": {
|
||||
"type": "string",
|
||||
"description": "The URI identifying the specific resource to access"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"server_name",
|
||||
"uri"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "ask_followup_question",
|
||||
"description": "Ask user a question for clarifying or gathering information needed to complete the task. For example, ask the user clarifying questions about a key implementation decision. You should only ask one question.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"question": {
|
||||
"type": "string",
|
||||
"description": "The single question to ask the user. E.g. \"How can I help you?\""
|
||||
},
|
||||
"options": {
|
||||
"type": "string",
|
||||
"description": "An array of 2-5 options (e.x: \"[\"Option 1\", \"Option 2\", \"Option 3\"]\") for the user to choose from. Each option should be a string describing a possible answer to the single question. You may not always need to provide options, but it may be helpful in many cases where it can save the user from having to type out a response manually. IMPORTANT: NEVER include an option to toggle to Act mode, as this would be something you need to direct the user to do manually themselves if needed."
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress after this tool use is completed. The task_progress parameter must be included as a separate parameter inside of the parent tool call, it must be separate from other parameters such as content, arguments, etc. (See 'UPDATING TASK PROGRESS' section for more details)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"question",
|
||||
"options"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "attempt_completion",
|
||||
"description": "Once you've completed the user's task, use this tool to present the final result to the user, including a brief and very short (1-2 paragraph) summary of the task and what was done to resolve it. Provide the basics, hitting the highlights, but do delve into the specifics. You should only call this tool when you have completed all tasks in the task_progress list, and completed all changes that are necessary to satisfy the user's request. You should not provide the contents of the task_progress list in the result parameter, it must be included in the task_progress parameter.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"result": {
|
||||
"type": "string",
|
||||
"description": "A clear, brief and very short (1-2 paragraph) summary of the final result of the task."
|
||||
},
|
||||
"command": {
|
||||
"type": "string",
|
||||
"description": "An actionable terminal command that is non-verbose that allows user to review the result of your work. For example, use `start localhost:3000` to start a locally running development server. Commands like `echo` or `cat` that merely print text or open a file are not allowed. Ensure the command is properly formatted for user's OS and does not contain any harmful instructions"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress with the latest status of each subtasks included previously, if any. If you are calling attempt completion, and all items in this list have been completed, they must be marked as completed in this response."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"result"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "plan_mode_respond",
|
||||
"description": "Respond to the user's inquiry in an effort to plan a solution to the user's task. This tool should ONLY be used when you have already explored the relevant files and are ready to present a concrete plan. DO NOT use this tool to announce what files you're going to read - just read them first. This tool is only available in PLAN MODE. The environment_details will specify the current mode; if it is not PLAN_MODE then you should not use this tool.\nHowever, if while writing your response you realize you actually need to do more exploration before providing a complete plan, you can add the optional needs_more_exploration parameter to indicate this. This allows you to acknowledge that you should have done more exploration first, and signals that your next message will use exploration tools instead.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"response": {
|
||||
"type": "string",
|
||||
"description": "The response to provide to the user."
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "string",
|
||||
"description": "A checklist showing task progress with the latest status of each subtasks included previously if any."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"response"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "load_mcp_documentation",
|
||||
"description": "Load documentation about creating MCP servers. This tool should be used when the user requests to create or install an MCP server (the user may ask you something along the lines of \"add a tool\" that does some function, in other words to create an MCP server that provides tools and resources that may connect to external APIs for example. You have the ability to create an MCP server and add it to a configuration file that will then expose the tools and resources for you to use with `use_mcp_tool` and `access_mcp_resource`). The documentation provides detailed information about the MCP server creation process, including setup instructions, best practices, and examples.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {},
|
||||
"required": [],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "focus_chain",
|
||||
"description": "",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {},
|
||||
"required": [],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "generate_explanation",
|
||||
"description": "Opens a multi-file diff view and generates AI-powered inline comments explaining the changes between two git references. Use this tool to help users understand code changes from git commits, pull requests, branches, or any git refs. The tool uses git to retrieve file contents and displays a side-by-side diff view with explanatory comments.",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"title": {
|
||||
"type": "string",
|
||||
"description": "A descriptive title for the diff view (e.g., 'Changes in commit abc123', 'PR #42: Add authentication', 'Changes between main and feature-branch')"
|
||||
},
|
||||
"from_ref": {
|
||||
"type": "string",
|
||||
"description": "The git reference for the 'before' state. Can be a commit hash, branch name, tag, or relative reference like HEAD~1, HEAD^, origin/main, etc."
|
||||
},
|
||||
"to_ref": {
|
||||
"type": "string",
|
||||
"description": "The git reference for the 'after' state. Can be a commit hash, branch name, tag, or relative reference. If not provided, compares to the current working directory (including uncommitted changes)."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"title",
|
||||
"from_ref"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "12345670mcp0test_tool",
|
||||
"description": "test-server: A test tool",
|
||||
"strict": false,
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {},
|
||||
"required": [],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,364 @@
|
||||
[
|
||||
{
|
||||
"name": "execute_command",
|
||||
"description": "Request to execute a CLI command on the system. Use this when you need to perform system operations or run specific commands to accomplish any step in the user's task. When chaining commands, use the shell operator && (not the HTML entity &&). If using search/grep commands, be careful to not use vague search terms that may return thousands of results. When in PLAN MODE, you may use the execute_command tool, but only in a non-destructive manner and in a way that does not alter any files.",
|
||||
"parameters": {
|
||||
"type": "OBJECT",
|
||||
"properties": {
|
||||
"command": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"requires_approval": {
|
||||
"type": "BOOLEAN"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"command",
|
||||
"requires_approval"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "read_file",
|
||||
"description": "Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string. Do NOT use this tool to list the contents of a directory. Only use this tool on files.",
|
||||
"parameters": {
|
||||
"type": "OBJECT",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "STRING"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"path"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "write_to_file",
|
||||
"description": "Request to write content to a file at the specified path. If the file exists, it will be overwritten with the provided content. If the file doesn't exist, it will be created. This tool will automatically create any directories needed to write the file.",
|
||||
"parameters": {
|
||||
"type": "OBJECT",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"content": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "STRING"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"path",
|
||||
"content"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "replace_in_file",
|
||||
"description": "Request to replace sections of content in an existing file using SEARCH/REPLACE blocks that define exact changes to specific parts of the file. This tool should be used when you need to make targeted changes to specific parts of a file.",
|
||||
"parameters": {
|
||||
"type": "OBJECT",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"diff": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "STRING"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"path",
|
||||
"diff"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "search_files",
|
||||
"description": "Request to perform a regex search across files in a specified directory, providing context-rich results. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.",
|
||||
"parameters": {
|
||||
"type": "OBJECT",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"regex": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"file_pattern": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "STRING"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"path",
|
||||
"regex"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "list_files",
|
||||
"description": "Request to list files and directories within the specified directory. If recursive is true, it will list all files and directories recursively. If recursive is false or not provided, it will only list the top-level contents. Do not use this tool to confirm the existence of files you may have created, as the user will let you know if the files were created successfully or not.",
|
||||
"parameters": {
|
||||
"type": "OBJECT",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"recursive": {
|
||||
"type": "BOOLEAN"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "STRING"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"path"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "list_code_definition_names",
|
||||
"description": "Request to list definition names (classes, functions, methods, etc.) used in source code files at the top level of the specified directory. This tool provides insights into the codebase structure and important constructs, encapsulating high-level concepts and relationships that are crucial for understanding the overall architecture.",
|
||||
"parameters": {
|
||||
"type": "OBJECT",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "STRING"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"path"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "browser_action",
|
||||
"description": "Request to interact with a Puppeteer-controlled browser. Every action, except `close`, will be responded to with a screenshot of the browser's current state, along with any new console logs. You may only perform one browser action per message, and wait for the user's response including a screenshot and logs to determine the next action.\n- The sequence of actions **must always start with** launching the browser at a URL, and **must always end with** closing the browser. If you need to visit a new URL that is not possible to navigate to from the current webpage, you must first close the browser, then launch again at the new URL.\n- While the browser is active, only the `browser_action` tool can be used. No other tools should be called during this time. You may proceed to use other tools only after closing the browser. For example if you run into an error and need to fix a file, you must close the browser, then use other tools to make the necessary changes, then re-launch the browser to verify the result.\n- The browser window has a resolution of **1280x720** pixels. When performing any click actions, ensure the coordinates are within this resolution range.\n- Before clicking on any elements such as icons, links, or buttons, you must consult the provided screenshot of the page to determine the coordinates of the element. The click should be targeted at the **center of the element**, not on its edges.",
|
||||
"parameters": {
|
||||
"type": "OBJECT",
|
||||
"properties": {
|
||||
"action": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"url": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"coordinate": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"text": {
|
||||
"type": "STRING"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"action"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "use_mcp_tool",
|
||||
"description": "Request to use a tool provided by a connected MCP server. Each MCP server can provide multiple tools with different capabilities. Tools have defined input schemas that specify required and optional parameters.",
|
||||
"parameters": {
|
||||
"type": "OBJECT",
|
||||
"properties": {
|
||||
"server_name": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"tool_name": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"arguments": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "STRING"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"server_name",
|
||||
"tool_name",
|
||||
"arguments"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "access_mcp_resource",
|
||||
"description": "Request to access a resource provided by a connected MCP server. Resources represent data sources that can be used as context, such as files, API responses, or system information.",
|
||||
"parameters": {
|
||||
"type": "OBJECT",
|
||||
"properties": {
|
||||
"server_name": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"uri": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "STRING"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"server_name",
|
||||
"uri"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ask_followup_question",
|
||||
"description": "Ask the user a question to gather additional information needed to complete the task. This tool should be used when you encounter ambiguities, need clarification, or require more details to proceed effectively. It allows for interactive problem-solving by enabling direct communication with the user. Use this tool judiciously to maintain a balance between gathering necessary information and avoiding excessive back-and-forth.",
|
||||
"parameters": {
|
||||
"type": "OBJECT",
|
||||
"properties": {
|
||||
"question": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"options": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "STRING"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"question"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "attempt_completion",
|
||||
"description": "After each tool use, the user will respond with the result of that tool use, i.e. if it succeeded or failed, along with any reasons for failure. Once you've received the results of tool uses and can confirm that the task is complete, use this tool to present the result of your work to the user. Optionally you may provide a CLI command to showcase the result of your work. The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again.\nIMPORTANT NOTE: This tool CANNOT be used until you've confirmed from the user that any previous tool uses were successful. Failure to do so will result in code corruption and system failure. Before using this tool, you must ask yourself in <thinking></thinking> tags if you've confirmed from the user that any previous tool uses were successful. If not, then DO NOT use this tool.",
|
||||
"parameters": {
|
||||
"type": "OBJECT",
|
||||
"properties": {
|
||||
"result": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"command": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "STRING"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"result"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "new_task",
|
||||
"description": "Request to create a new task with preloaded context covering the conversation with the user up to this point and key information for continuing with the new task. With this tool, you will create a detailed summary of the conversation so far, paying close attention to the user's explicit requests and your previous actions, with a focus on the most relevant information required for the new task.\nAmong other important areas of focus, this summary should be thorough in capturing technical details, code patterns, and architectural decisions that would be essential for continuing with the new task. The user will be presented with a preview of your generated context and can choose to create a new task or keep chatting in the current conversation. The user may choose to start a new task at any point.",
|
||||
"parameters": {
|
||||
"type": "OBJECT",
|
||||
"properties": {
|
||||
"context": {
|
||||
"type": "STRING"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"context"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "plan_mode_respond",
|
||||
"description": "Respond with a plan that outlines a solution to the user's request. This tool should ONLY be used when you have already explored the relevant files and are ready to present a concrete plan. Only use this tool after you have explored relevant files and collected sufficient context to create a detailed, accurate plan. This tool is only available in PLAN MODE, as indicated by the environment_details.\nIf it becomes apparent that additional exploration is required while the plan_mode_respond response is being generated, the optional needs_more_exploration parameter can be toggled to enable further research. This allows you to acknowledge that more exploration is required before the final plan_mode_respond is generated, and signals that your next message will use exploration tools instead.",
|
||||
"parameters": {
|
||||
"type": "OBJECT",
|
||||
"properties": {
|
||||
"response": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"needs_more_exploration": {
|
||||
"type": "BOOLEAN"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "STRING"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"response"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "act_mode_respond",
|
||||
"description": "Provide a progress update or preamble to the user during ACT MODE execution. This tool allows you to communicate your thought process and planned actions without interrupting the execution flow. After displaying your message, execution automatically continues, allowing you to proceed with subsequent tool calls immediately. This tool is only available in ACT MODE. This tool may not be called immediately after a previous act_mode_respond call.\n\nIMPORTANT: Use this tool frequently to create a better user experience. Since it's non-blocking, there's no performance penalty for frequent use.\n\nUse this tool when:\n- After reading files and before making any edits - explain your analysis and what changes you plan to make\n- When starting a new phase of work (e.g., transitioning from backend to frontend, or from one feature to another)\n- During long sequences of operations to provide progress updates\n- When your approach or strategy changes mid-task\n- Before executing complex or potentially risky operations\n- To explain why you're choosing one approach over another\n\nDo NOT use this tool when you have completed all required actions and are ready to present the final output; in that case, use the attempt_completion tool instead.\n\nCRITICAL CONSTRAINT: You MUST NOT call this tool more than once in a row. After using act_mode_respond, your next assistant message MUST either call a different tool or perform additional work without using act_mode_respond again. If you attempt to call act_mode_respond consecutively, the tool call will fail with an explicit error.",
|
||||
"parameters": {
|
||||
"type": "OBJECT",
|
||||
"properties": {
|
||||
"response": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"task_progress": {
|
||||
"type": "STRING"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"response"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "load_mcp_documentation",
|
||||
"description": "Load documentation about creating MCP servers. This tool should be used when the user requests to create or install an MCP server (the user may ask you something along the lines of \"add a tool\" that does some function, in other words to create an MCP server that provides tools and resources that may connect to external APIs for example. You have the ability to create an MCP server and add it to a configuration file that will then expose the tools and resources for you to use with `use_mcp_tool` and `access_mcp_resource`). The documentation provides detailed information about the MCP server creation process, including setup instructions, best practices, and examples.",
|
||||
"parameters": {
|
||||
"type": "OBJECT",
|
||||
"properties": {},
|
||||
"required": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "focus_chain",
|
||||
"description": "",
|
||||
"parameters": {
|
||||
"type": "OBJECT",
|
||||
"properties": {},
|
||||
"required": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "generate_explanation",
|
||||
"description": "Opens a multi-file diff view and generates AI-powered inline comments explaining the changes between two git references. Use this tool to help users understand code changes from git commits, pull requests, branches, or any git refs. The tool uses git to retrieve file contents and displays a side-by-side diff view with explanatory comments.",
|
||||
"parameters": {
|
||||
"type": "OBJECT",
|
||||
"properties": {
|
||||
"title": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"from_ref": {
|
||||
"type": "STRING"
|
||||
},
|
||||
"to_ref": {
|
||||
"type": "STRING"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"title",
|
||||
"from_ref"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "12345670mcp0test_tool",
|
||||
"description": "test-server: A test tool",
|
||||
"parameters": {
|
||||
"type": "OBJECT",
|
||||
"properties": {},
|
||||
"required": []
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -24,14 +24,14 @@ Plan Mode is for deep analysis and strategic planning before implementation. You
|
||||
|
||||
### Phase 1: Silent Investigation
|
||||
|
||||
Perform comprehensive research to build complete understanding of the codebase. Work silently - execute targetted searcg commands and read files without explaining what you're doing. Only ask questions when truly necessary for planning. You must strongly incrporate key words and principles from the user's input into your targetted search patterns and strategy.
|
||||
Perform comprehensive research to build complete understanding of the codebase. Work silently - execute targeted search commands and read files without explaining what you're doing. Only ask questions when truly necessary for planning. You must strongly incorporate key words and principles from the user's input into your targeted search patterns and strategy.
|
||||
|
||||
**Research Activities:**
|
||||
- Use read_file, search_files, and list_code_definition_names extensively to understand architecture, patterns, and conventions
|
||||
- Execute targetted terminal commands to search and gather information about structure and dependencies.
|
||||
- Execute targeted terminal commands to search and gather information about structure and dependencies.
|
||||
- Identify technical constraints, existing patterns, and potential risks
|
||||
- Ask targeted clarifying questions only when they will directly influence your implementation approach
|
||||
- Ensure complete converage- before presenting a plan, you should identify all related functions, classes, calls, and methods that are involved or affected by the proposed changes.
|
||||
- Ensure complete coverage - before presenting a plan, you should identify all related functions, classes, calls, and methods that are involved or affected by the proposed changes.
|
||||
|
||||
### Phase 2: Plan Presentation
|
||||
|
||||
@@ -66,7 +66,7 @@ Engage with the user to discuss the plan, answer questions, and incorporate feed
|
||||
|
||||
### Phase 4: Transition to Implementation
|
||||
|
||||
Once the plan is finalized and approved, you MUST direct the user to switch to ACT MODE. In Act Mode, you'll execute the plan step-by-step as outlined. If you not specifically ask the user to switch to ACT MODE, you will not be able to implemnent the planned changes.
|
||||
Once the plan is finalized and approved, you MUST direct the user to switch to ACT MODE. In Act Mode, you'll execute the plan step-by-step as outlined. If you not specifically ask the user to switch to ACT MODE, you will not be able to implement the planned changes.
|
||||
|
||||
## Act Mode Workflow
|
||||
|
||||
@@ -215,7 +215,7 @@ RULES
|
||||
|
||||
- The current working directory is `/test/project` - this is the directory where all the tools will be executed from.
|
||||
- When executing terminal commands, new terminals always open in the workspace directory. Use relative paths or chain commands with proper shell operators (e.g., `cd path && command` to change directory and run a command together).
|
||||
- Whean searching, prefer the search_files tool over using grep in the terminal. If you are directly instruted to use grep, ensure your search patterns are targetted and not too vague to prevent extremely large outputs.
|
||||
- When searching, prefer the search_files tool over using grep in the terminal. If you are directly instructed to use grep, ensure your search patterns are targeted and not too vague to prevent extremely large outputs.
|
||||
- When using replace_in_file, pay careful attention to the EDITING FILES section above. The most common errors are:
|
||||
- Not matching content exactly (every character, space, and newline must match)
|
||||
- Using incomplete lines in SEARCH blocks (always include complete lines from start to end)
|
||||
|
||||
+5
-5
@@ -24,14 +24,14 @@ Plan Mode is for deep analysis and strategic planning before implementation. You
|
||||
|
||||
### Phase 1: Silent Investigation
|
||||
|
||||
Perform comprehensive research to build complete understanding of the codebase. Work silently - execute targetted searcg commands and read files without explaining what you're doing. Only ask questions when truly necessary for planning. You must strongly incrporate key words and principles from the user's input into your targetted search patterns and strategy.
|
||||
Perform comprehensive research to build complete understanding of the codebase. Work silently - execute targeted search commands and read files without explaining what you're doing. Only ask questions when truly necessary for planning. You must strongly incorporate key words and principles from the user's input into your targeted search patterns and strategy.
|
||||
|
||||
**Research Activities:**
|
||||
- Use read_file, search_files, and list_code_definition_names extensively to understand architecture, patterns, and conventions
|
||||
- Execute targetted terminal commands to search and gather information about structure and dependencies.
|
||||
- Execute targeted terminal commands to search and gather information about structure and dependencies.
|
||||
- Identify technical constraints, existing patterns, and potential risks
|
||||
- Ask targeted clarifying questions only when they will directly influence your implementation approach
|
||||
- Ensure complete converage- before presenting a plan, you should identify all related functions, classes, calls, and methods that are involved or affected by the proposed changes.
|
||||
- Ensure complete coverage - before presenting a plan, you should identify all related functions, classes, calls, and methods that are involved or affected by the proposed changes.
|
||||
|
||||
### Phase 2: Plan Presentation
|
||||
|
||||
@@ -66,7 +66,7 @@ Engage with the user to discuss the plan, answer questions, and incorporate feed
|
||||
|
||||
### Phase 4: Transition to Implementation
|
||||
|
||||
Once the plan is finalized and approved, you MUST direct the user to switch to ACT MODE. In Act Mode, you'll execute the plan step-by-step as outlined. If you not specifically ask the user to switch to ACT MODE, you will not be able to implemnent the planned changes.
|
||||
Once the plan is finalized and approved, you MUST direct the user to switch to ACT MODE. In Act Mode, you'll execute the plan step-by-step as outlined. If you not specifically ask the user to switch to ACT MODE, you will not be able to implement the planned changes.
|
||||
|
||||
## Act Mode Workflow
|
||||
|
||||
@@ -213,7 +213,7 @@ RULES
|
||||
|
||||
- The current working directory is `/test/project` - this is the directory where all the tools will be executed from.
|
||||
- When executing terminal commands, new terminals always open in the workspace directory. Use relative paths or chain commands with proper shell operators (e.g., `cd path && command` to change directory and run a command together).
|
||||
- Whean searching, prefer the search_files tool over using grep in the terminal. If you are directly instruted to use grep, ensure your search patterns are targetted and not too vague to prevent extremely large outputs.
|
||||
- When searching, prefer the search_files tool over using grep in the terminal. If you are directly instructed to use grep, ensure your search patterns are targeted and not too vague to prevent extremely large outputs.
|
||||
- When using replace_in_file, pay careful attention to the EDITING FILES section above. The most common errors are:
|
||||
- Not matching content exactly (every character, space, and newline must match)
|
||||
- Using incomplete lines in SEARCH blocks (always include complete lines from start to end)
|
||||
|
||||
+5
-5
@@ -24,14 +24,14 @@ Plan Mode is for deep analysis and strategic planning before implementation. You
|
||||
|
||||
### Phase 1: Silent Investigation
|
||||
|
||||
Perform comprehensive research to build complete understanding of the codebase. Work silently - execute targetted searcg commands and read files without explaining what you're doing. Only ask questions when truly necessary for planning. You must strongly incrporate key words and principles from the user's input into your targetted search patterns and strategy.
|
||||
Perform comprehensive research to build complete understanding of the codebase. Work silently - execute targeted search commands and read files without explaining what you're doing. Only ask questions when truly necessary for planning. You must strongly incorporate key words and principles from the user's input into your targeted search patterns and strategy.
|
||||
|
||||
**Research Activities:**
|
||||
- Use read_file, search_files, and list_code_definition_names extensively to understand architecture, patterns, and conventions
|
||||
- Execute targetted terminal commands to search and gather information about structure and dependencies.
|
||||
- Execute targeted terminal commands to search and gather information about structure and dependencies.
|
||||
- Identify technical constraints, existing patterns, and potential risks
|
||||
- Ask targeted clarifying questions only when they will directly influence your implementation approach
|
||||
- Ensure complete converage- before presenting a plan, you should identify all related functions, classes, calls, and methods that are involved or affected by the proposed changes.
|
||||
- Ensure complete coverage - before presenting a plan, you should identify all related functions, classes, calls, and methods that are involved or affected by the proposed changes.
|
||||
|
||||
### Phase 2: Plan Presentation
|
||||
|
||||
@@ -66,7 +66,7 @@ Engage with the user to discuss the plan, answer questions, and incorporate feed
|
||||
|
||||
### Phase 4: Transition to Implementation
|
||||
|
||||
Once the plan is finalized and approved, you MUST direct the user to switch to ACT MODE. In Act Mode, you'll execute the plan step-by-step as outlined. If you not specifically ask the user to switch to ACT MODE, you will not be able to implemnent the planned changes.
|
||||
Once the plan is finalized and approved, you MUST direct the user to switch to ACT MODE. In Act Mode, you'll execute the plan step-by-step as outlined. If you not specifically ask the user to switch to ACT MODE, you will not be able to implement the planned changes.
|
||||
|
||||
## Act Mode Workflow
|
||||
|
||||
@@ -193,7 +193,7 @@ RULES
|
||||
|
||||
- The current working directory is `/test/project` - this is the directory where all the tools will be executed from.
|
||||
- When executing terminal commands, new terminals always open in the workspace directory. Use relative paths or chain commands with proper shell operators (e.g., `cd path && command` to change directory and run a command together).
|
||||
- Whean searching, prefer the search_files tool over using grep in the terminal. If you are directly instruted to use grep, ensure your search patterns are targetted and not too vague to prevent extremely large outputs.
|
||||
- When searching, prefer the search_files tool over using grep in the terminal. If you are directly instructed to use grep, ensure your search patterns are targeted and not too vague to prevent extremely large outputs.
|
||||
- When using replace_in_file, pay careful attention to the EDITING FILES section above. The most common errors are:
|
||||
- Not matching content exactly (every character, space, and newline must match)
|
||||
- Using incomplete lines in SEARCH blocks (always include complete lines from start to end)
|
||||
|
||||
@@ -24,14 +24,14 @@ Plan Mode is for deep analysis and strategic planning before implementation. You
|
||||
|
||||
### Phase 1: Silent Investigation
|
||||
|
||||
Perform comprehensive research to build complete understanding of the codebase. Work silently - execute targetted searcg commands and read files without explaining what you're doing. Only ask questions when truly necessary for planning. You must strongly incrporate key words and principles from the user's input into your targetted search patterns and strategy.
|
||||
Perform comprehensive research to build complete understanding of the codebase. Work silently - execute targeted search commands and read files without explaining what you're doing. Only ask questions when truly necessary for planning. You must strongly incorporate key words and principles from the user's input into your targeted search patterns and strategy.
|
||||
|
||||
**Research Activities:**
|
||||
- Use read_file, search_files, and list_code_definition_names extensively to understand architecture, patterns, and conventions
|
||||
- Execute targetted terminal commands to search and gather information about structure and dependencies.
|
||||
- Execute targeted terminal commands to search and gather information about structure and dependencies.
|
||||
- Identify technical constraints, existing patterns, and potential risks
|
||||
- Ask targeted clarifying questions only when they will directly influence your implementation approach
|
||||
- Ensure complete converage- before presenting a plan, you should identify all related functions, classes, calls, and methods that are involved or affected by the proposed changes.
|
||||
- Ensure complete coverage - before presenting a plan, you should identify all related functions, classes, calls, and methods that are involved or affected by the proposed changes.
|
||||
|
||||
### Phase 2: Plan Presentation
|
||||
|
||||
@@ -66,7 +66,7 @@ Engage with the user to discuss the plan, answer questions, and incorporate feed
|
||||
|
||||
### Phase 4: Transition to Implementation
|
||||
|
||||
Once the plan is finalized and approved, you MUST direct the user to switch to ACT MODE. In Act Mode, you'll execute the plan step-by-step as outlined. If you not specifically ask the user to switch to ACT MODE, you will not be able to implemnent the planned changes.
|
||||
Once the plan is finalized and approved, you MUST direct the user to switch to ACT MODE. In Act Mode, you'll execute the plan step-by-step as outlined. If you not specifically ask the user to switch to ACT MODE, you will not be able to implement the planned changes.
|
||||
|
||||
## Act Mode Workflow
|
||||
|
||||
@@ -215,7 +215,7 @@ RULES
|
||||
|
||||
- The current working directory is `/test/project` - this is the directory where all the tools will be executed from.
|
||||
- When executing terminal commands, new terminals always open in the workspace directory. Use relative paths or chain commands with proper shell operators (e.g., `cd path && command` to change directory and run a command together).
|
||||
- Whean searching, prefer the search_files tool over using grep in the terminal. If you are directly instruted to use grep, ensure your search patterns are targetted and not too vague to prevent extremely large outputs.
|
||||
- When searching, prefer the search_files tool over using grep in the terminal. If you are directly instructed to use grep, ensure your search patterns are targeted and not too vague to prevent extremely large outputs.
|
||||
- When using replace_in_file, pay careful attention to the EDITING FILES section above. The most common errors are:
|
||||
- Not matching content exactly (every character, space, and newline must match)
|
||||
- Using incomplete lines in SEARCH blocks (always include complete lines from start to end)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* model families and context configurations using snapshot testing.
|
||||
*
|
||||
* Usage:
|
||||
* - Run tests normally: `npm run test:unit -- --update-snapshots`
|
||||
* - Run tests normally: `npm run test:unit`
|
||||
* Tests will fail if generated prompts don't match existing snapshots
|
||||
*
|
||||
* - Update snapshots: `npm run test:unit -- --update-snapshots`
|
||||
@@ -26,40 +26,31 @@ import { ModelFamily } from "@/shared/prompts"
|
||||
import { getSystemPrompt } from "../index"
|
||||
import type { SystemPromptContext } from "../types"
|
||||
|
||||
// Check if snapshots should be updated via process argument
|
||||
const UPDATE_SNAPSHOTS = process.argv.includes("--update-snapshots") || process.env.UPDATE_SNAPSHOTS === "true"
|
||||
// ============================================================================
|
||||
// Configuration
|
||||
// ============================================================================
|
||||
|
||||
// Helper to format snapshot mismatch error messages
|
||||
const formatSnapshotError = (snapshotName: string, differences: string): string => {
|
||||
return `
|
||||
const UPDATE_SNAPSHOTS = process.argv.includes("--update-snapshots") || process.env.UPDATE_SNAPSHOTS === "true"
|
||||
const SNAPSHOTS_DIR = path.join(__dirname, "__snapshots__")
|
||||
const TEST_TIMEOUT = 30000
|
||||
const MAX_DIFF_LINES = 10
|
||||
|
||||
// ============================================================================
|
||||
// Snapshot Helpers
|
||||
// ============================================================================
|
||||
|
||||
const formatSnapshotError = (snapshotName: string, details: string): string => `
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
❌ SNAPSHOT MISMATCH: ${snapshotName}
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
${differences}
|
||||
${details}
|
||||
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
🔧 HOW TO FIX:
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
1. 📋 Review the differences above to understand what changed
|
||||
2. 🤔 Determine if the changes are intentional:
|
||||
- ✅ Expected changes (prompt improvements, new features)
|
||||
- ❌ Unexpected changes (bugs, regressions)
|
||||
|
||||
3. 🔄 If changes are correct, update snapshots:
|
||||
npm run test:unit -- --update-snapshots
|
||||
|
||||
4. 🐛 If changes are unintentional, investigate:
|
||||
- Check recent changes to prompt generation logic
|
||||
- Verify context/configuration hasn't changed unexpectedly
|
||||
- Look for dependency updates that might affect output
|
||||
|
||||
🔧 To update snapshots: npm run test:unit -- --update-snapshots
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
`
|
||||
}
|
||||
|
||||
// Helper to compare two strings and return differences
|
||||
const compareStrings = (expected: string, actual: string): string | null => {
|
||||
if (expected === actual) {
|
||||
return null
|
||||
@@ -67,64 +58,69 @@ const compareStrings = (expected: string, actual: string): string | null => {
|
||||
|
||||
const expectedLines = expected.split("\n")
|
||||
const actualLines = actual.split("\n")
|
||||
const maxLines = Math.max(expectedLines.length, actualLines.length)
|
||||
const differences: string[] = []
|
||||
const diffs: string[] = []
|
||||
|
||||
for (let i = 0; i < maxLines; i++) {
|
||||
const expectedLine = expectedLines[i] || ""
|
||||
const actualLine = actualLines[i] || ""
|
||||
|
||||
if (expectedLine !== actualLine) {
|
||||
if (differences.length < 10) {
|
||||
// Limit to first 10 differences for readability
|
||||
differences.push(`Line ${i + 1}:`)
|
||||
if (expectedLine) {
|
||||
differences.push(` - Expected: ${expectedLine.substring(0, 100)}${expectedLine.length > 100 ? "..." : ""}`)
|
||||
}
|
||||
if (actualLine) {
|
||||
differences.push(` + Actual: ${actualLine.substring(0, 100)}${actualLine.length > 100 ? "..." : ""}`)
|
||||
}
|
||||
for (let i = 0; i < Math.max(expectedLines.length, actualLines.length) && diffs.length < MAX_DIFF_LINES; i++) {
|
||||
const exp = expectedLines[i] || ""
|
||||
const act = actualLines[i] || ""
|
||||
if (exp !== act) {
|
||||
diffs.push(`Line ${i + 1}:`)
|
||||
if (exp) {
|
||||
diffs.push(` - Expected: ${exp.substring(0, 100)}${exp.length > 100 ? "..." : ""}`)
|
||||
}
|
||||
if (act) {
|
||||
diffs.push(` + Actual: ${act.substring(0, 100)}${act.length > 100 ? "..." : ""}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (differences.length === 0) {
|
||||
return null
|
||||
}
|
||||
|
||||
const summary = [
|
||||
`Expected length: ${expected.length} characters`,
|
||||
`Actual length: ${actual.length} characters`,
|
||||
`Line count difference: ${expectedLines.length} vs ${actualLines.length}`,
|
||||
return [
|
||||
`Expected: ${expected.length} chars, ${expectedLines.length} lines`,
|
||||
`Actual: ${actual.length} chars, ${actualLines.length} lines`,
|
||||
"",
|
||||
"First differences:",
|
||||
...differences,
|
||||
]
|
||||
...diffs,
|
||||
diffs.length >= MAX_DIFF_LINES ? "... and more differences" : "",
|
||||
].join("\n")
|
||||
}
|
||||
|
||||
if (differences.length >= 10) {
|
||||
summary.push("... and more differences")
|
||||
async function assertSnapshot(name: string, content: string): Promise<void> {
|
||||
const snapshotPath = path.join(SNAPSHOTS_DIR, name)
|
||||
|
||||
if (UPDATE_SNAPSHOTS) {
|
||||
await fs.writeFile(snapshotPath, content, "utf-8")
|
||||
console.log(`Updated snapshot: ${name} (${content.length} chars)`)
|
||||
return
|
||||
}
|
||||
|
||||
return summary.join("\n")
|
||||
try {
|
||||
const existing = await fs.readFile(snapshotPath, "utf-8")
|
||||
const diff = compareStrings(existing, content)
|
||||
if (diff) {
|
||||
throw new Error(formatSnapshotError(name, diff))
|
||||
}
|
||||
console.log(`✓ Snapshot matches: ${name}`)
|
||||
} catch (error) {
|
||||
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
|
||||
throw new Error(formatSnapshotError(name, `Snapshot does not exist. Run with --update-snapshots to create it.`))
|
||||
}
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Test Context Helpers
|
||||
// ============================================================================
|
||||
|
||||
export const mockProviderInfo = {
|
||||
providerId: "test",
|
||||
model: {
|
||||
id: "fast",
|
||||
info: {
|
||||
supportsPromptCache: false,
|
||||
},
|
||||
},
|
||||
model: { id: "fast", info: { supportsPromptCache: false } },
|
||||
mode: "act" as const,
|
||||
}
|
||||
|
||||
const makeMockProviderInfo = (modelId: string, providerId: string = "test") => ({
|
||||
const makeProviderInfo = (modelId: string, providerId: string = "test") => ({
|
||||
providerId: modelId.includes("ollama") ? "ollama" : providerId,
|
||||
model: {
|
||||
...mockProviderInfo.model,
|
||||
id: modelId,
|
||||
},
|
||||
model: { ...mockProviderInfo.model, id: modelId },
|
||||
mode: "act" as const,
|
||||
customPrompt: providerId.includes("lmstudio") || providerId.includes("ollama") ? "compact" : undefined,
|
||||
})
|
||||
|
||||
@@ -136,31 +132,18 @@ const baseContext: SystemPromptContext = {
|
||||
mcpHub: {
|
||||
getServers: () => [
|
||||
{
|
||||
uid: "1234567",
|
||||
name: "test-server",
|
||||
status: "connected",
|
||||
config: '{"command": "test"}',
|
||||
tools: [
|
||||
{
|
||||
name: "test_tool",
|
||||
description: "A test tool",
|
||||
inputSchema: { type: "object", properties: {} },
|
||||
},
|
||||
],
|
||||
tools: [{ name: "test_tool", description: "A test tool", inputSchema: { type: "object", properties: {} } }],
|
||||
resources: [],
|
||||
resourceTemplates: [],
|
||||
},
|
||||
],
|
||||
} as unknown as McpHub,
|
||||
focusChainSettings: {
|
||||
enabled: true,
|
||||
remindClineInterval: 6,
|
||||
},
|
||||
browserSettings: {
|
||||
viewport: {
|
||||
width: 1280,
|
||||
height: 720,
|
||||
},
|
||||
},
|
||||
focusChainSettings: { enabled: true, remindClineInterval: 6 },
|
||||
browserSettings: { viewport: { width: 1280, height: 720 } },
|
||||
globalClineRulesFileInstructions: "Follow global rules",
|
||||
localClineRulesFileInstructions: "Follow local rules",
|
||||
preferredLanguageInstructions: "Prefer TypeScript",
|
||||
@@ -169,276 +152,151 @@ const baseContext: SystemPromptContext = {
|
||||
enableNativeToolCalls: false,
|
||||
}
|
||||
|
||||
describe("Prompt System Integration Tests", () => {
|
||||
beforeEach(() => {
|
||||
// Reset any necessary state before each test
|
||||
})
|
||||
const isNativeToolsFamily = (family: ModelFamily) =>
|
||||
[ModelFamily.NATIVE_NEXT_GEN, ModelFamily.NATIVE_GPT_5, ModelFamily.NATIVE_GPT_5_1, ModelFamily.GEMINI_3].includes(family)
|
||||
|
||||
// Show helpful information about snapshot testing mode
|
||||
before(() => {
|
||||
if (UPDATE_SNAPSHOTS) {
|
||||
console.log("🔄 SNAPSHOT UPDATE MODE: Will update all snapshot files with current output")
|
||||
type TestRunner = Mocha.Context & { skip(): void; timeout(ms: number): void }
|
||||
|
||||
async function runPromptTest(
|
||||
testCtx: TestRunner,
|
||||
context: SystemPromptContext,
|
||||
modelId: string,
|
||||
handler: (result: Awaited<ReturnType<typeof getSystemPrompt>>) => Promise<void>,
|
||||
): Promise<void> {
|
||||
testCtx.timeout(TEST_TIMEOUT)
|
||||
try {
|
||||
const result = await getSystemPrompt(context)
|
||||
await handler(result)
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message.includes("No prompt variant found")) {
|
||||
console.log(`Skipping ${modelId} - no variant available (expected)`)
|
||||
testCtx.skip()
|
||||
} else {
|
||||
console.log("✅ SNAPSHOT TEST MODE: Will compare against existing snapshots")
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Test Data
|
||||
// ============================================================================
|
||||
|
||||
const contextVariations: Array<{ name: string; override: Partial<SystemPromptContext> }> = [
|
||||
{ name: "basic", override: {} },
|
||||
{ name: "no-browser", override: { supportsBrowserUse: false } },
|
||||
{ name: "no-mcp", override: { mcpHub: { getServers: () => [] } as unknown as McpHub } },
|
||||
{ name: "no-focus-chain", override: { focusChainSettings: { enabled: false, remindClineInterval: 0 } } },
|
||||
]
|
||||
|
||||
const modelTestCases = [
|
||||
{ family: ModelFamily.GENERIC, modelId: "gpt-3", providerId: "openai" },
|
||||
{ family: ModelFamily.GLM, modelId: "glm-4.6", providerId: "zai" },
|
||||
{ family: ModelFamily.HERMES, modelId: "hermes-4", providerId: "test" },
|
||||
{ family: ModelFamily.DEVSTRAL, modelId: "devstral", providerId: "cline" },
|
||||
{ family: ModelFamily.NEXT_GEN, modelId: "claude-sonnet-4", providerId: "anthropic" },
|
||||
{ family: ModelFamily.XS, modelId: "qwen3_coder", providerId: "lmstudio" },
|
||||
{ family: ModelFamily.NATIVE_NEXT_GEN, modelId: "claude-4-5-sonnet", providerId: "cline" },
|
||||
{ family: ModelFamily.GPT_5, modelId: "gpt-5", providerId: "openai" },
|
||||
{ family: ModelFamily.NATIVE_GPT_5, modelId: "gpt-5-codex", providerId: "openai" },
|
||||
{ family: ModelFamily.NATIVE_GPT_5_1, modelId: "gpt-5-1", providerId: "openai" },
|
||||
{ family: ModelFamily.GEMINI_3, modelId: "gemini-3", providerId: "vertex" },
|
||||
]
|
||||
|
||||
// ============================================================================
|
||||
// Tests
|
||||
// ============================================================================
|
||||
|
||||
describe("Prompt System Integration Tests", () => {
|
||||
before(async () => {
|
||||
console.log(UPDATE_SNAPSHOTS ? "🔄 SNAPSHOT UPDATE MODE" : "✅ SNAPSHOT TEST MODE")
|
||||
await fs.mkdir(SNAPSHOTS_DIR, { recursive: true }).catch(() => {})
|
||||
})
|
||||
const contextVariations = [
|
||||
{ name: "basic", baseContext: { ...baseContext } },
|
||||
{
|
||||
name: "no-browser",
|
||||
baseContext: { ...baseContext, supportsBrowserUse: false },
|
||||
},
|
||||
{
|
||||
name: "no-mcp",
|
||||
baseContext: { ...baseContext, mcpHub: { getServers: () => [] } },
|
||||
},
|
||||
{
|
||||
name: "no-focus-chain",
|
||||
baseContext: { ...baseContext, focusChainSettings: { enabled: false } },
|
||||
},
|
||||
]
|
||||
|
||||
// Table-driven test cases for different model families
|
||||
const modelTestCases = [
|
||||
{
|
||||
modelGroup: ModelFamily.GENERIC,
|
||||
modelIds: ["gpt-3"],
|
||||
providerId: "openai",
|
||||
contextVariations,
|
||||
},
|
||||
{
|
||||
modelGroup: ModelFamily.GLM,
|
||||
modelIds: ["glm-4.6"],
|
||||
providerId: "zai",
|
||||
contextVariations,
|
||||
},
|
||||
{
|
||||
modelGroup: ModelFamily.HERMES,
|
||||
modelIds: ["hermes-4"],
|
||||
providerId: "test",
|
||||
contextVariations,
|
||||
},
|
||||
{
|
||||
modelGroup: ModelFamily.DEVSTRAL,
|
||||
modelIds: ["devstral"],
|
||||
providerId: "cline",
|
||||
contextVariations,
|
||||
},
|
||||
{
|
||||
modelGroup: ModelFamily.NEXT_GEN,
|
||||
modelIds: ["claude-sonnet-4"],
|
||||
providerId: "anthropic",
|
||||
contextVariations,
|
||||
},
|
||||
{
|
||||
modelGroup: ModelFamily.XS,
|
||||
modelIds: ["qwen3_coder"],
|
||||
providerId: "lmstudio",
|
||||
contextVariations,
|
||||
},
|
||||
{
|
||||
modelGroup: ModelFamily.NATIVE_NEXT_GEN,
|
||||
modelIds: ["claude-4-5-sonnet"],
|
||||
providerId: "cline",
|
||||
contextVariations,
|
||||
},
|
||||
{
|
||||
modelGroup: ModelFamily.GPT_5,
|
||||
modelIds: ["gpt-5"],
|
||||
providerId: "openai",
|
||||
contextVariations,
|
||||
},
|
||||
{
|
||||
modelGroup: ModelFamily.NATIVE_GPT_5,
|
||||
modelIds: ["gpt-5-codex"],
|
||||
providerId: "openai",
|
||||
contextVariations,
|
||||
},
|
||||
{
|
||||
modelGroup: ModelFamily.NATIVE_GPT_5_1,
|
||||
modelIds: ["gpt-5-1"],
|
||||
providerId: "openai",
|
||||
contextVariations,
|
||||
},
|
||||
{
|
||||
modelGroup: ModelFamily.GEMINI_3,
|
||||
modelIds: ["gemini-3"],
|
||||
providerId: "vertex",
|
||||
contextVariations,
|
||||
},
|
||||
]
|
||||
|
||||
// Generate snapshots for all model/context combinations
|
||||
describe("Snapshot Testing", () => {
|
||||
const snapshotsDir = path.join(__dirname, "__snapshots__")
|
||||
for (const { family, modelId, providerId } of modelTestCases) {
|
||||
describe(`${family} Model Group`, () => {
|
||||
const enableNativeToolCalls = isNativeToolsFamily(family)
|
||||
|
||||
before(async () => {
|
||||
// Ensure snapshots directory exists
|
||||
try {
|
||||
await fs.mkdir(snapshotsDir, { recursive: true })
|
||||
} catch {
|
||||
// Directory might already exist
|
||||
}
|
||||
})
|
||||
|
||||
for (const { modelGroup, modelIds, providerId, contextVariations } of modelTestCases) {
|
||||
describe(`${modelGroup} Model Group`, () => {
|
||||
for (const modelId of modelIds) {
|
||||
for (const { name: contextName, baseContext } of contextVariations) {
|
||||
const context = {
|
||||
...baseContext,
|
||||
providerInfo: makeMockProviderInfo(modelId, providerId),
|
||||
isTesting: true,
|
||||
enableNativeToolCalls:
|
||||
modelGroup === ModelFamily.NATIVE_NEXT_GEN ||
|
||||
modelGroup === ModelFamily.NATIVE_GPT_5 ||
|
||||
modelGroup === ModelFamily.NATIVE_GPT_5_1 ||
|
||||
modelGroup === ModelFamily.GEMINI_3,
|
||||
}
|
||||
it(`should generate consistent prompt for ${providerId}/${modelId} with ${contextName} context`, async function () {
|
||||
this.timeout(30000) // Allow more time for prompt generation
|
||||
|
||||
try {
|
||||
const { systemPrompt } = await getSystemPrompt(context as SystemPromptContext)
|
||||
|
||||
// Basic structure assertions
|
||||
expect(systemPrompt).to.be.a("string")
|
||||
expect(systemPrompt.length).to.be.greaterThan(100)
|
||||
expect(systemPrompt).to.not.include("{{TOOL_USE_SECTION}}") // Tools placeholder should be removed
|
||||
|
||||
// Snapshot testing logic
|
||||
const snapshotName = `${providerId}_${modelId.replace(/[^a-zA-Z0-9]/g, "_")}-${contextName}.snap`
|
||||
const snapshotPath = path.join(snapshotsDir, snapshotName)
|
||||
|
||||
if (UPDATE_SNAPSHOTS) {
|
||||
// Update mode: write new snapshot
|
||||
await fs.writeFile(snapshotPath, systemPrompt, "utf-8")
|
||||
console.log(`Updated snapshot: ${snapshotName} (${systemPrompt.length} chars)`)
|
||||
} else {
|
||||
// Test mode: compare with existing snapshot
|
||||
try {
|
||||
const existingSnapshot = await fs.readFile(snapshotPath, "utf-8")
|
||||
const differences = compareStrings(existingSnapshot, systemPrompt)
|
||||
|
||||
if (differences) {
|
||||
throw new Error(formatSnapshotError(snapshotName, differences))
|
||||
}
|
||||
|
||||
console.log(`✓ Snapshot matches: ${snapshotName}`)
|
||||
} catch (error) {
|
||||
if (error instanceof Error && (error as any).code === "ENOENT") {
|
||||
// Snapshot doesn't exist
|
||||
throw new Error(
|
||||
formatSnapshotError(
|
||||
snapshotName,
|
||||
`Snapshot file does not exist: ${snapshotPath}\n` +
|
||||
`This is a new test case. Run with --update-snapshots to create the initial snapshot.`,
|
||||
),
|
||||
)
|
||||
}
|
||||
// Re-throw comparison errors
|
||||
throw error
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// For missing variants, we expect errors - that's okay
|
||||
if (error instanceof Error && error.message.includes("No prompt variant found")) {
|
||||
console.log(`Skipping ${modelId} - no variant available (expected)`)
|
||||
this.skip()
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
})
|
||||
it(`should generate consistent native tools object when enabled`, async function () {
|
||||
const context: SystemPromptContext = {
|
||||
...baseContext,
|
||||
providerInfo: makeProviderInfo(modelId, providerId),
|
||||
enableNativeToolCalls,
|
||||
}
|
||||
|
||||
await runPromptTest(this, context, modelId, async ({ tools }) => {
|
||||
if (!enableNativeToolCalls) {
|
||||
expect(tools).to.be.undefined
|
||||
return
|
||||
}
|
||||
|
||||
expect(tools).to.be.an("array").that.is.not.empty
|
||||
const snapshotName = `${providerId}_${family.replace(/[^a-zA-Z0-9]/g, "_")}.tools.snap`
|
||||
await assertSnapshot(snapshotName, JSON.stringify(tools, null, 2))
|
||||
})
|
||||
})
|
||||
|
||||
for (const { name: contextName, override } of contextVariations) {
|
||||
it(`should generate consistent prompt for ${providerId}/${modelId} with ${contextName} context`, async function () {
|
||||
const context: SystemPromptContext = {
|
||||
...baseContext,
|
||||
...override,
|
||||
providerInfo: makeProviderInfo(modelId, providerId),
|
||||
enableNativeToolCalls,
|
||||
}
|
||||
|
||||
await runPromptTest(this, context, modelId, async ({ systemPrompt, tools }) => {
|
||||
if (enableNativeToolCalls) {
|
||||
expect(tools).to.be.an("array").that.is.not.empty
|
||||
} else {
|
||||
expect(tools).to.be.undefined
|
||||
}
|
||||
|
||||
expect(systemPrompt).to.be.a("string").with.length.greaterThan(100)
|
||||
expect(systemPrompt).to.not.include("{{TOOL_USE_SECTION}}")
|
||||
|
||||
const snapshotName = `${providerId}_${modelId.replace(/[^a-zA-Z0-9]/g, "_")}-${contextName}.snap`
|
||||
await assertSnapshot(snapshotName, systemPrompt)
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
describe("Context-Specific Features", () => {
|
||||
it("should include browser-specific content when browser is enabled", async function () {
|
||||
this.timeout(30000)
|
||||
const featureTests = [
|
||||
{ name: "browser-specific content when browser is enabled", context: { supportsBrowserUse: true }, check: "browser" },
|
||||
{ name: "MCP content when MCP servers are present", context: {}, check: "MCP" },
|
||||
{ name: "TODO content when focus chain is enabled", context: {}, check: "TODO" },
|
||||
{ name: "user instructions when provided", context: {}, check: "USER'S CUSTOM INSTRUCTIONS" },
|
||||
]
|
||||
|
||||
const contextWithBrowser = { ...baseContext, supportsBrowserUse: true }
|
||||
|
||||
try {
|
||||
const { systemPrompt } = await getSystemPrompt(contextWithBrowser)
|
||||
expect(systemPrompt.toLowerCase()).to.include("browser")
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message.includes("No prompt variant found")) {
|
||||
this.skip()
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it("should include MCP content when MCP servers are present", async function () {
|
||||
this.timeout(30000)
|
||||
|
||||
try {
|
||||
const { systemPrompt } = await getSystemPrompt(baseContext)
|
||||
expect(systemPrompt).to.include("MCP")
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message.includes("No prompt variant found")) {
|
||||
this.skip()
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it("should include TODO content when focus chain is enabled", async function () {
|
||||
this.timeout(30000)
|
||||
|
||||
try {
|
||||
const { systemPrompt } = await getSystemPrompt(baseContext)
|
||||
expect(systemPrompt).to.include("TODO")
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message.includes("No prompt variant found")) {
|
||||
this.skip()
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it("should include user instructions when provided", async function () {
|
||||
this.timeout(30000)
|
||||
|
||||
try {
|
||||
const { systemPrompt } = await getSystemPrompt(baseContext)
|
||||
expect(systemPrompt).to.include("USER'S CUSTOM INSTRUCTIONS")
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message.includes("No prompt variant found")) {
|
||||
this.skip()
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
})
|
||||
for (const { name, context, check } of featureTests) {
|
||||
it(`should include ${name}`, async function () {
|
||||
await runPromptTest(this, { ...baseContext, ...context }, "default", async ({ systemPrompt }) => {
|
||||
expect(systemPrompt.toLowerCase()).to.include(check.toLowerCase())
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
describe("Error Handling", () => {
|
||||
it("should handle completely invalid context gracefully", async function () {
|
||||
this.timeout(30000)
|
||||
|
||||
const invalidContext = {} as SystemPromptContext
|
||||
const { systemPrompt } = await getSystemPrompt(invalidContext)
|
||||
this.timeout(TEST_TIMEOUT)
|
||||
const { systemPrompt } = await getSystemPrompt({} as SystemPromptContext)
|
||||
expect(systemPrompt).to.be.a("string")
|
||||
})
|
||||
|
||||
it("should handle undefined context properties", async function () {
|
||||
this.timeout(30000)
|
||||
|
||||
this.timeout(TEST_TIMEOUT)
|
||||
const contextWithNulls: SystemPromptContext = {
|
||||
cwd: undefined,
|
||||
ide: "",
|
||||
supportsBrowserUse: undefined,
|
||||
mcpHub: undefined,
|
||||
focusChainSettings: undefined,
|
||||
providerInfo: baseContext.providerInfo,
|
||||
providerInfo: mockProviderInfo,
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -446,7 +304,6 @@ describe("Prompt System Integration Tests", () => {
|
||||
expect(systemPrompt).to.be.a("string")
|
||||
expect(systemPrompt).to.include("{{TOOL_USE_SECTION}}")
|
||||
} catch (error) {
|
||||
// Error is acceptable for invalid context
|
||||
expect(error).to.be.instanceOf(Error)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { ClineDefaultTool } from "@/shared/tools"
|
||||
import { ClineToolSet } from "../registry/ClineToolSet"
|
||||
import { type ClineToolSpec } from "../spec"
|
||||
import { type ClineToolSpec, resolveInstruction } from "../spec"
|
||||
import { STANDARD_PLACEHOLDERS } from "../templates/placeholders"
|
||||
import { TemplateEngine } from "../templates/TemplateEngine"
|
||||
import type { ComponentRegistry, PromptVariant, SystemPromptContext } from "../types"
|
||||
@@ -207,21 +207,22 @@ export class PromptBuilder {
|
||||
const sections = [
|
||||
title,
|
||||
description.join("\n"),
|
||||
PromptBuilder.buildParametersSection(filteredParams),
|
||||
PromptBuilder.buildParametersSection(filteredParams, context),
|
||||
PromptBuilder.buildUsageSection(config.id, filteredParams),
|
||||
]
|
||||
|
||||
return sections.filter(Boolean).join("\n")
|
||||
}
|
||||
|
||||
private static buildParametersSection(params: any[]): string {
|
||||
private static buildParametersSection(params: any[], context: SystemPromptContext): string {
|
||||
if (!params.length) {
|
||||
return "Parameters: None"
|
||||
}
|
||||
|
||||
const paramList = params.map((p) => {
|
||||
const requiredText = p.required ? "required" : "optional"
|
||||
return `- ${p.name}: (${requiredText}) ${p.instruction}`
|
||||
const instruction = resolveInstruction(p.instruction, context)
|
||||
return `- ${p.name}: (${requiredText}) ${instruction}`
|
||||
})
|
||||
|
||||
return ["Parameters:", ...paramList].join("\n")
|
||||
|
||||
@@ -19,7 +19,7 @@ export interface ClineToolSpec {
|
||||
interface ClineToolSpecParameter {
|
||||
name: string
|
||||
required: boolean
|
||||
instruction: string
|
||||
instruction: string | ((context: SystemPromptContext) => string)
|
||||
usage?: string
|
||||
dependencies?: ClineDefaultTool[]
|
||||
description?: string
|
||||
@@ -77,7 +77,7 @@ export function toolSpecFunctionDefinition(tool: ClineToolSpec, context: SystemP
|
||||
// Build parameter schema
|
||||
const paramSchema: any = {
|
||||
type: paramType,
|
||||
description: replacer(param.instruction, context),
|
||||
description: replacer(resolveInstruction(param.instruction, context), context),
|
||||
}
|
||||
|
||||
// Add items for array types
|
||||
@@ -170,7 +170,7 @@ export function toolSpecInputSchema(tool: ClineToolSpec, context: SystemPromptCo
|
||||
// Build parameter schema
|
||||
const paramSchema: any = {
|
||||
type: paramType,
|
||||
description: replacer(param.instruction, context),
|
||||
description: replacer(resolveInstruction(param.instruction, context), context),
|
||||
}
|
||||
|
||||
// Add items for array types
|
||||
@@ -278,7 +278,7 @@ export function toolSpecFunctionDeclarations(tool: ClineToolSpec, context: Syste
|
||||
}
|
||||
paramSchema.properties[key] = {
|
||||
type: GOOGLE_TOOL_PARAM_MAP[prop.type || "string"] || GoogleToolParamType.OBJECT,
|
||||
description: replacer(param.instruction, context),
|
||||
description: replacer(resolveInstruction(param.instruction, context), context),
|
||||
}
|
||||
|
||||
// Handle enum values
|
||||
@@ -399,3 +399,13 @@ function replacer(description: string, context: SystemPromptContext): string {
|
||||
|
||||
return description.replace("{{BROWSER_VIEWPORT_WIDTH}}", String(width)).replace("{{BROWSER_VIEWPORT_HEIGHT}}", String(height))
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves an instruction that may be a string or a function.
|
||||
*/
|
||||
export function resolveInstruction(
|
||||
instruction: string | ((context: SystemPromptContext) => string),
|
||||
context: SystemPromptContext,
|
||||
): string {
|
||||
return typeof instruction === "function" ? instruction(context) : instruction
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ const GEMINI_3_RULES_TEMPLATE = (_context: SystemPromptContext) => `RULES
|
||||
|
||||
- The current working directory is \`{{CWD}}\` - this is the directory where all the tools will be executed from.
|
||||
- When executing terminal commands, new terminals always open in the workspace directory. Use relative paths or chain commands with proper shell operators (e.g., \`cd path && command\` to change directory and run a command together).
|
||||
- Whean searching, prefer the search_files tool over using grep in the terminal. If you are directly instruted to use grep, ensure your search patterns are targetted and not too vague to prevent extremely large outputs.
|
||||
- When searching, prefer the search_files tool over using grep in the terminal. If you are directly instructed to use grep, ensure your search patterns are targeted and not too vague to prevent extremely large outputs.
|
||||
- When using replace_in_file, pay careful attention to the EDITING FILES section above. The most common errors are:
|
||||
- Not matching content exactly (every character, space, and newline must match)
|
||||
- Using incomplete lines in SEARCH blocks (always include complete lines from start to end)
|
||||
@@ -157,13 +157,13 @@ Plan Mode is for deep analysis and strategic planning before implementation. You
|
||||
|
||||
### Phase 1: Silent Investigation
|
||||
|
||||
Perform comprehensive research to build complete understanding of the codebase. Work silently - execute targetted searcg commands and read files without explaining what you're doing. Only ask questions when truly necessary for planning. You must strongly incrporate key words and principles from the user's input into your targetted search patterns and strategy.
|
||||
Perform comprehensive research to build complete understanding of the codebase. Work silently - execute targeted search commands and read files without explaining what you're doing. Only ask questions when truly necessary for planning. You must strongly incorporate key words and principles from the user's input into your targeted search patterns and strategy.
|
||||
|
||||
**Research Activities:**
|
||||
- Use read_file, search_files, and list_code_definition_names extensively to understand architecture, patterns, and conventions
|
||||
- Execute targetted terminal commands to search and gather information about structure and dependencies.
|
||||
- Execute targeted terminal commands to search and gather information about structure and dependencies.
|
||||
- Identify technical constraints, existing patterns, and potential risks${context.yoloModeToggled !== true ? "\n- Ask targeted clarifying questions only when they will directly influence your implementation approach" : ""}
|
||||
- Ensure complete converage- before presenting a plan, you should identify all related functions, classes, calls, and methods that are involved or affected by the proposed changes.
|
||||
- Ensure complete coverage - before presenting a plan, you should identify all related functions, classes, calls, and methods that are involved or affected by the proposed changes.
|
||||
|
||||
### Phase 2: Plan Presentation
|
||||
|
||||
@@ -198,7 +198,7 @@ Engage with the user to discuss the plan, answer questions, and incorporate feed
|
||||
|
||||
### Phase 4: Transition to Implementation
|
||||
|
||||
Once the plan is finalized and approved, you MUST direct the user to switch to ACT MODE. In Act Mode, you'll execute the plan step-by-step as outlined. If you not specifically ask the user to switch to ACT MODE, you will not be able to implemnent the planned changes.
|
||||
Once the plan is finalized and approved, you MUST direct the user to switch to ACT MODE. In Act Mode, you'll execute the plan step-by-step as outlined. If you not specifically ask the user to switch to ACT MODE, you will not be able to implement the planned changes.
|
||||
|
||||
## Act Mode Workflow
|
||||
|
||||
|
||||
@@ -10,6 +10,10 @@ export const baseTemplate = `{{${SystemPromptSection.AGENT_ROLE}}}
|
||||
|
||||
====
|
||||
|
||||
{{${SystemPromptSection.CLI_SUBAGENTS}}}
|
||||
|
||||
====
|
||||
|
||||
{{${SystemPromptSection.ACT_VS_PLAN}}}
|
||||
|
||||
====
|
||||
|
||||
@@ -53,9 +53,7 @@ export const config = createVariant(ModelFamily.NATIVE_GPT_5_1)
|
||||
ClineDefaultTool.BASH,
|
||||
ClineDefaultTool.FILE_READ,
|
||||
// Should disable FILE_NEW and FILE_EDIT when enabled
|
||||
// ClineDefaultTool.APPLY_PATCH,
|
||||
ClineDefaultTool.FILE_NEW,
|
||||
ClineDefaultTool.FILE_EDIT,
|
||||
ClineDefaultTool.APPLY_PATCH,
|
||||
ClineDefaultTool.SEARCH,
|
||||
ClineDefaultTool.LIST_FILES,
|
||||
ClineDefaultTool.LIST_CODE_DEF,
|
||||
|
||||
@@ -156,12 +156,7 @@ export class VariantValidator {
|
||||
|
||||
private validateBestPractices(variant: PromptVariant, warnings: string[]): void {
|
||||
// Check for recommended components
|
||||
const recommendedComponents = [
|
||||
SystemPromptSection.AGENT_ROLE,
|
||||
SystemPromptSection.TOOL_USE,
|
||||
SystemPromptSection.RULES,
|
||||
SystemPromptSection.SYSTEM_INFO,
|
||||
]
|
||||
const recommendedComponents = [SystemPromptSection.AGENT_ROLE, SystemPromptSection.RULES, SystemPromptSection.SYSTEM_INFO]
|
||||
|
||||
const missingRecommended = recommendedComponents.filter((c) => !variant.componentOrder.includes(c))
|
||||
if (missingRecommended.length > 0) {
|
||||
|
||||
@@ -1143,8 +1143,14 @@ export class StateManager {
|
||||
awsProfile: this.taskStateCache["awsProfile"] || this.globalStateCache["awsProfile"],
|
||||
awsUseProfile: this.taskStateCache["awsUseProfile"] || this.globalStateCache["awsUseProfile"],
|
||||
awsAuthentication: this.taskStateCache["awsAuthentication"] || this.globalStateCache["awsAuthentication"],
|
||||
vertexProjectId: this.taskStateCache["vertexProjectId"] || this.globalStateCache["vertexProjectId"],
|
||||
vertexRegion: this.taskStateCache["vertexRegion"] || this.globalStateCache["vertexRegion"],
|
||||
vertexProjectId:
|
||||
this.remoteConfigCache["vertexProjectId"] ||
|
||||
this.taskStateCache["vertexProjectId"] ||
|
||||
this.globalStateCache["vertexProjectId"],
|
||||
vertexRegion:
|
||||
this.remoteConfigCache["vertexRegion"] ||
|
||||
this.taskStateCache["vertexRegion"] ||
|
||||
this.globalStateCache["vertexRegion"],
|
||||
requestyBaseUrl: this.taskStateCache["requestyBaseUrl"] || this.globalStateCache["requestyBaseUrl"],
|
||||
openAiBaseUrl:
|
||||
this.remoteConfigCache["openAiBaseUrl"] ||
|
||||
@@ -1168,7 +1174,10 @@ export class StateManager {
|
||||
this.globalStateCache["azureApiVersion"],
|
||||
openRouterProviderSorting:
|
||||
this.taskStateCache["openRouterProviderSorting"] || this.globalStateCache["openRouterProviderSorting"],
|
||||
liteLlmBaseUrl: this.taskStateCache["liteLlmBaseUrl"] || this.globalStateCache["liteLlmBaseUrl"],
|
||||
liteLlmBaseUrl:
|
||||
this.remoteConfigCache["liteLlmBaseUrl"] ||
|
||||
this.taskStateCache["liteLlmBaseUrl"] ||
|
||||
this.globalStateCache["liteLlmBaseUrl"],
|
||||
liteLlmUsePromptCache: this.taskStateCache["liteLlmUsePromptCache"] || this.globalStateCache["liteLlmUsePromptCache"],
|
||||
qwenApiLine: this.taskStateCache["qwenApiLine"] || this.globalStateCache["qwenApiLine"],
|
||||
moonshotApiLine: this.taskStateCache["moonshotApiLine"] || this.globalStateCache["moonshotApiLine"],
|
||||
|
||||
@@ -143,10 +143,10 @@ async function fetchRemoteConfigForOrganization(organizationId: string): Promise
|
||||
async function fetchApiKeysForOrganization(organizationId: string): Promise<APIKeySettings> {
|
||||
try {
|
||||
// Fetch API keys string using helper
|
||||
const apiKeysString = await makeAuthenticatedRequest<string>(CLINE_API_ENDPOINT.API_KEYS, organizationId)
|
||||
const response = await makeAuthenticatedRequest<{ providerApiKeys: string }>(CLINE_API_ENDPOINT.API_KEYS, organizationId)
|
||||
|
||||
// Parse and return API keys
|
||||
return parseApiKeys(apiKeysString)
|
||||
return parseApiKeys(response?.providerApiKeys)
|
||||
} catch (error) {
|
||||
console.error(`Failed to fetch API keys for organization ${organizationId}:`, error)
|
||||
return {}
|
||||
@@ -230,7 +230,7 @@ async function ensureUserInOrgWithRemoteConfig(controller: Controller): Promise<
|
||||
|
||||
// Cache and apply the remote config
|
||||
await writeRemoteConfigToCache(organizationId, config)
|
||||
applyRemoteConfig(config)
|
||||
await applyRemoteConfig(config)
|
||||
controller.postStateToWebview()
|
||||
|
||||
return config
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { synchronizeRemoteRuleToggles } from "@core/context/instructions/user-instructions/rule-helpers"
|
||||
import { RemoteConfig } from "@shared/remote-config/schema"
|
||||
import { RemoteConfigFields } from "@shared/storage/state-keys"
|
||||
import { getTelemetryService } from "@/services/telemetry"
|
||||
import { OpenTelemetryClientProvider } from "@/services/telemetry/providers/opentelemetry/OpenTelemetryClientProvider"
|
||||
import { OpenTelemetryTelemetryProvider } from "@/services/telemetry/providers/opentelemetry/OpenTelemetryTelemetryProvider"
|
||||
import { type TelemetryService } from "@/services/telemetry/TelemetryService"
|
||||
import { OpenTelemetryClientValidConfig, remoteConfigToOtelConfig } from "@/shared/services/config/otel-config"
|
||||
import { StateManager } from "../StateManager"
|
||||
|
||||
/**
|
||||
@@ -21,6 +26,12 @@ export function transformRemoteConfigToStateShape(remoteConfig: RemoteConfig): P
|
||||
if (remoteConfig.allowedMCPServers !== undefined) {
|
||||
transformed.allowedMCPServers = remoteConfig.allowedMCPServers
|
||||
}
|
||||
if (remoteConfig.blockPersonalRemoteMCPServers !== undefined) {
|
||||
transformed.blockPersonalRemoteMCPServers = remoteConfig.blockPersonalRemoteMCPServers
|
||||
}
|
||||
if (remoteConfig.remoteMCPServers !== undefined) {
|
||||
transformed.remoteMCPServers = remoteConfig.remoteMCPServers
|
||||
}
|
||||
if (remoteConfig.yoloModeAllowed !== undefined) {
|
||||
// only set the yoloModeToggled field if yolo mode is not allowed. Otherwise, we let the user toggle it.
|
||||
if (remoteConfig.yoloModeAllowed === false) {
|
||||
@@ -71,6 +82,9 @@ export function transformRemoteConfigToStateShape(remoteConfig: RemoteConfig): P
|
||||
if (remoteConfig.openTelemetryLogMaxQueueSize !== undefined) {
|
||||
transformed.openTelemetryLogMaxQueueSize = remoteConfig.openTelemetryLogMaxQueueSize
|
||||
}
|
||||
if (remoteConfig.openTelemetryOtlpHeaders !== undefined) {
|
||||
transformed.openTelemetryOtlpHeaders = remoteConfig.openTelemetryOtlpHeaders
|
||||
}
|
||||
|
||||
// Map provider settings
|
||||
|
||||
@@ -168,16 +182,39 @@ export function transformRemoteConfigToStateShape(remoteConfig: RemoteConfig): P
|
||||
return transformed
|
||||
}
|
||||
|
||||
const REMOTE_CONFIG_OTEL_PROVIDER_ID = "OpenTelemetryRemoteConfiguredProvider"
|
||||
async function applyRemoteOTELConfig(transformed: Partial<RemoteConfigFields>, telemetryService: TelemetryService) {
|
||||
try {
|
||||
const otelConfig = remoteConfigToOtelConfig(transformed)
|
||||
if (otelConfig.enabled) {
|
||||
const client = new OpenTelemetryClientProvider(otelConfig as OpenTelemetryClientValidConfig)
|
||||
|
||||
if (client.meterProvider || client.loggerProvider) {
|
||||
telemetryService.addProvider(
|
||||
await new OpenTelemetryTelemetryProvider(client.meterProvider, client.loggerProvider, {
|
||||
name: REMOTE_CONFIG_OTEL_PROVIDER_ID,
|
||||
bypassUserSettings: true,
|
||||
}).initialize(),
|
||||
)
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("[REMOTE CONFIG DEBUG] Failed to apply remote OTEL config", err)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies remote config to the StateManager's remote config cache
|
||||
* @param remoteConfig The remote configuration object to apply
|
||||
*/
|
||||
export function applyRemoteConfig(remoteConfig?: RemoteConfig): void {
|
||||
export async function applyRemoteConfig(remoteConfig?: RemoteConfig): Promise<void> {
|
||||
const stateManager = StateManager.get()
|
||||
const telemetryService = await getTelemetryService()
|
||||
|
||||
// If no remote config provided, clear the cache and relevant state
|
||||
if (!remoteConfig) {
|
||||
stateManager.clearRemoteConfig()
|
||||
telemetryService.removeProvider(REMOTE_CONFIG_OTEL_PROVIDER_ID)
|
||||
// the remote config cline rules toggle state is stored in global state
|
||||
stateManager.setGlobalState("remoteRulesToggles", {})
|
||||
stateManager.setGlobalState("remoteWorkflowToggles", {})
|
||||
@@ -185,6 +222,8 @@ export function applyRemoteConfig(remoteConfig?: RemoteConfig): void {
|
||||
}
|
||||
|
||||
// Transform remote config to state shape
|
||||
// These are then set to the remote config cache in the StateManager
|
||||
// We need to ensure the cache is checked for new fields
|
||||
const transformed = transformRemoteConfigToStateShape(remoteConfig)
|
||||
|
||||
// Synchronize toggle state
|
||||
@@ -199,9 +238,12 @@ export function applyRemoteConfig(remoteConfig?: RemoteConfig): void {
|
||||
|
||||
// Clear existing remote config cache
|
||||
stateManager.clearRemoteConfig()
|
||||
telemetryService.removeProvider(REMOTE_CONFIG_OTEL_PROVIDER_ID)
|
||||
|
||||
// Populate remote config cache with transformed values
|
||||
for (const [key, value] of Object.entries(transformed)) {
|
||||
stateManager.setRemoteConfigField(key as keyof RemoteConfigFields, value)
|
||||
}
|
||||
|
||||
await applyRemoteOTELConfig(transformed, telemetryService)
|
||||
}
|
||||
|
||||
@@ -322,6 +322,8 @@ export async function readGlobalStateFromDisk(context: ExtensionContext): Promis
|
||||
const openTelemetryLogMaxQueueSize =
|
||||
context.globalState.get<GlobalStateAndSettings["openTelemetryLogMaxQueueSize"]>("openTelemetryLogMaxQueueSize")
|
||||
const subagentsEnabled = context.globalState.get<GlobalStateAndSettings["subagentsEnabled"]>("subagentsEnabled")
|
||||
const backgroundEditEnabled =
|
||||
context.globalState.get<GlobalStateAndSettings["backgroundEditEnabled"]>("backgroundEditEnabled")
|
||||
|
||||
// Get mode-related configurations
|
||||
const mode = context.globalState.get<GlobalStateAndSettings["mode"]>("mode")
|
||||
@@ -682,6 +684,7 @@ export async function readGlobalStateFromDisk(context: ExtensionContext): Promis
|
||||
qwenCodeOauthPath,
|
||||
customPrompt,
|
||||
autoCondenseThreshold: autoCondenseThreshold || 0.75, // default to 0.75 if not set
|
||||
backgroundEditEnabled: backgroundEditEnabled ?? false,
|
||||
// Hooks require explicit user opt-in and are only supported on macOS/Linux
|
||||
hooksEnabled: getHooksEnabledSafe(hooksEnabled),
|
||||
subagentsEnabled: subagentsEnabled ?? false,
|
||||
|
||||
+10
-17
@@ -69,7 +69,6 @@ import Mutex from "p-mutex"
|
||||
import pWaitFor from "p-wait-for"
|
||||
import * as path from "path"
|
||||
import { ulid } from "ulid"
|
||||
import * as vscode from "vscode"
|
||||
import type { SystemPromptContext } from "@/core/prompts/system-prompt"
|
||||
import { getSystemPrompt } from "@/core/prompts/system-prompt"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
@@ -1600,21 +1599,6 @@ export class Task {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrates the disableBrowserTool setting from VSCode configuration to browserSettings
|
||||
*/
|
||||
private async migrateDisableBrowserToolSetting(): Promise<void> {
|
||||
const config = vscode.workspace.getConfiguration("cline")
|
||||
const disableBrowserTool = config.get<boolean>("disableBrowserTool")
|
||||
|
||||
if (disableBrowserTool !== undefined) {
|
||||
const browserSettings = this.stateManager.getGlobalSettingsKey("browserSettings")
|
||||
browserSettings.disableToolUse = disableBrowserTool
|
||||
// Remove from VSCode configuration
|
||||
await config.update("disableBrowserTool", undefined, true)
|
||||
}
|
||||
}
|
||||
|
||||
private getCurrentProviderInfo(): ApiProviderInfo {
|
||||
const model = this.api.getModel()
|
||||
const apiConfig = this.stateManager.getApiConfiguration()
|
||||
@@ -1705,7 +1689,6 @@ export class Task {
|
||||
|
||||
const providerInfo = this.getCurrentProviderInfo()
|
||||
const ide = (await HostProvider.env.getHostVersion({})).platform || "Unknown"
|
||||
await this.migrateDisableBrowserToolSetting()
|
||||
const browserSettings = this.stateManager.getGlobalSettingsKey("browserSettings")
|
||||
const disableBrowserTool = browserSettings.disableToolUse ?? false
|
||||
// cline browser tool uses image recognition for navigation (requires model image support).
|
||||
@@ -2142,6 +2125,16 @@ export class Task {
|
||||
}
|
||||
|
||||
if (this.taskState.consecutiveMistakeCount >= this.stateManager.getGlobalSettingsKey("maxConsecutiveMistakes")) {
|
||||
// In yolo mode, don't wait for user input - fail the task
|
||||
if (this.stateManager.getGlobalSettingsKey("yoloModeToggled")) {
|
||||
const errorMessage =
|
||||
`[YOLO MODE] Task failed: Too many consecutive mistakes (${this.taskState.consecutiveMistakeCount}). ` +
|
||||
`The model may not be capable enough for this task. Consider using a more capable model.`
|
||||
await this.say("error", errorMessage)
|
||||
// End the task loop with failure
|
||||
return true // didEndLoop = true, signals task completion/failure
|
||||
}
|
||||
|
||||
const autoApprovalSettings = this.stateManager.getGlobalSettingsKey("autoApprovalSettings")
|
||||
if (autoApprovalSettings.enableNotifications) {
|
||||
showSystemNotification({
|
||||
|
||||
@@ -171,17 +171,6 @@ export class ApplyPatchHandler implements IFullyManagedTool {
|
||||
)
|
||||
.catch(() => {}) // sending true for partial even though it's not a partial, this shows the edit row before the content is streamed into the editor
|
||||
|
||||
const requiresOpen =
|
||||
!provider.isEditing || state.currentPreviewPath !== targetResolution.resolvedPath || provider.editType === undefined
|
||||
|
||||
const needsCreateEditor = actionType === PatchActionType.ADD || (actionType === PatchActionType.UPDATE && !!movePath)
|
||||
|
||||
if (requiresOpen) {
|
||||
provider.editType = needsCreateEditor ? "create" : "modify"
|
||||
await provider.open(targetResolution.absolutePath, { displayPath: targetResolution.resolvedPath })
|
||||
state.currentPreviewPath = targetResolution.resolvedPath
|
||||
}
|
||||
|
||||
const stream: { content: string | undefined } = { content: undefined }
|
||||
|
||||
switch (actionType) {
|
||||
@@ -336,7 +325,7 @@ export class ApplyPatchHandler implements IFullyManagedTool {
|
||||
if (result.finalContent) {
|
||||
responseLines.push(`\n<final_file_content path="${path}">`)
|
||||
responseLines.push(result.finalContent)
|
||||
responseLines.push(`\n</final_file_content>`)
|
||||
responseLines.push(`</final_file_content>`)
|
||||
}
|
||||
if (result.newProblemsMessage) {
|
||||
responseLines.push(`\n\n${result.newProblemsMessage}`)
|
||||
@@ -498,7 +487,7 @@ export class ApplyPatchHandler implements IFullyManagedTool {
|
||||
changes[path] = {
|
||||
type: PatchActionType.UPDATE,
|
||||
oldContent: originalFiles[path],
|
||||
newContent: this.applyChunks(originalFiles[path]!, action.chunks, path),
|
||||
newContent: this.applyChunks(originalFiles[path]!, action.chunks, path).trimEnd(),
|
||||
movePath: action.movePath,
|
||||
}
|
||||
break
|
||||
@@ -522,7 +511,6 @@ export class ApplyPatchHandler implements IFullyManagedTool {
|
||||
return content
|
||||
}
|
||||
|
||||
const endsWithNewline = content.endsWith("\n")
|
||||
const lines = content.split("\n")
|
||||
const result: string[] = []
|
||||
let currentIndex = 0
|
||||
@@ -558,9 +546,8 @@ export class ApplyPatchHandler implements IFullyManagedTool {
|
||||
|
||||
// Copy remaining lines
|
||||
result.push(...lines.slice(currentIndex))
|
||||
const joined = result.join("\n")
|
||||
|
||||
return endsWithNewline && !joined.endsWith("\n") ? `${joined}\n` : joined
|
||||
return result.join("\n")
|
||||
}
|
||||
|
||||
private async applyCommit(commit: Commit): Promise<Record<string, FileOpsResult>> {
|
||||
|
||||
@@ -40,6 +40,19 @@ export class AskFollowupQuestionToolHandler implements IToolHandler, IPartialBlo
|
||||
}
|
||||
config.taskState.consecutiveMistakeCount = 0
|
||||
|
||||
// In yolo mode, don't wait for user input - instruct AI to use tools instead
|
||||
if (config.yoloModeToggled) {
|
||||
// Log the question that was asked but auto-respond
|
||||
await config.callbacks.say(
|
||||
"info",
|
||||
`[YOLO MODE] Auto-responding to question: "${question.substring(0, 100)}${question.length > 100 ? "..." : ""}"`,
|
||||
)
|
||||
|
||||
return formatResponse.toolResult(
|
||||
`[YOLO MODE: User input is not available in non-interactive mode. You must use available tools (read_file, list_files, search_files, etc.) to gather the information you need instead of asking the user. Proceed with using tools to find the answer to your question: "${question}"]`,
|
||||
)
|
||||
}
|
||||
|
||||
// Show notification if enabled
|
||||
if (config.autoApprovalSettings.enableNotifications) {
|
||||
showSystemNotification({
|
||||
|
||||
@@ -415,6 +415,11 @@ export class WriteToFileToolHandler implements IFullyManagedTool {
|
||||
!block.partial, // Pass the partial flag correctly
|
||||
)
|
||||
} catch (error) {
|
||||
// As we set the didAlreadyUseTool flag when the tool has failed once, we don't want to add the error message to the
|
||||
// userMessages array again on each new streaming chunk received.
|
||||
if (!config.enableParallelToolCalling && config.taskState.didAlreadyUseTool) {
|
||||
return
|
||||
}
|
||||
// Full original behavior - comprehensive error handling even for partial blocks
|
||||
await config.callbacks.say("diff_error", relPath)
|
||||
|
||||
|
||||
+6
-2
@@ -1,11 +1,15 @@
|
||||
import * as vscode from "vscode"
|
||||
import { ErrorSettings } from "@/services/error"
|
||||
import { EmptyRequest } from "@/shared/proto/index.cline"
|
||||
import { GetTelemetrySettingsResponse, Setting } from "@/shared/proto/index.host"
|
||||
|
||||
export async function getTelemetrySettings(_: EmptyRequest): Promise<GetTelemetrySettingsResponse> {
|
||||
const config = vscode.workspace.getConfiguration("telemetry")
|
||||
const errorLevel = config?.get<ErrorSettings["level"]>("telemetryLevel") || "all"
|
||||
|
||||
if (vscode.env.isTelemetryEnabled) {
|
||||
return { isEnabled: Setting.ENABLED }
|
||||
return { isEnabled: Setting.ENABLED, errorLevel }
|
||||
} else {
|
||||
return { isEnabled: Setting.DISABLED }
|
||||
return { isEnabled: Setting.DISABLED, errorLevel }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Tests for BannerService
|
||||
* Tests API fetching, caching, and rule evaluation logic
|
||||
* Tests API fetching, caching, and client-side provider filtering
|
||||
*/
|
||||
|
||||
import type { BannerRules } from "@shared/ClineBanner"
|
||||
@@ -59,8 +59,6 @@ describe("BannerService", () => {
|
||||
severity: "info" as const,
|
||||
placement: "top" as const,
|
||||
rulesJson: "{}",
|
||||
activeFrom: new Date(Date.now() - 86400000).toISOString(),
|
||||
activeTo: new Date(Date.now() + 86400000).toISOString(),
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -127,92 +125,14 @@ describe("BannerService", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("Date Range Filtering", () => {
|
||||
it("should filter out expired banners", async () => {
|
||||
const mockResponse = {
|
||||
data: {
|
||||
data: {
|
||||
items: [
|
||||
{
|
||||
id: "bnr_expired",
|
||||
titleMd: "Expired",
|
||||
bodyMd: "Test",
|
||||
severity: "info" as const,
|
||||
placement: "top" as const,
|
||||
rulesJson: "{}",
|
||||
activeFrom: new Date(Date.now() - 172800000).toISOString(),
|
||||
activeTo: new Date(Date.now() - 86400000).toISOString(), // activeTo is in the Past
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
axiosGetStub.resolves(mockResponse)
|
||||
const banners = await bannerService.fetchActiveBanners()
|
||||
expect(banners).to.have.lengthOf(0)
|
||||
})
|
||||
|
||||
it("should filter out future banners", async () => {
|
||||
const mockResponse = {
|
||||
data: {
|
||||
data: {
|
||||
items: [
|
||||
{
|
||||
id: "bnr_future",
|
||||
titleMd: "Future",
|
||||
bodyMd: "Test",
|
||||
severity: "info" as const,
|
||||
placement: "top" as const,
|
||||
rulesJson: "{}",
|
||||
activeFrom: new Date(Date.now() + 86400000).toISOString(), // activeFrom is in the Future
|
||||
activeTo: new Date(Date.now() + 172800000).toISOString(),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
axiosGetStub.resolves(mockResponse)
|
||||
const banners = await bannerService.fetchActiveBanners()
|
||||
expect(banners).to.have.lengthOf(0)
|
||||
})
|
||||
|
||||
it("should include currently active banners", async () => {
|
||||
const mockResponse = {
|
||||
data: {
|
||||
data: {
|
||||
items: [
|
||||
{
|
||||
id: "bnr_active",
|
||||
titleMd: "Active",
|
||||
bodyMd: "Test",
|
||||
severity: "info" as const,
|
||||
placement: "top" as const,
|
||||
rulesJson: "{}",
|
||||
activeFrom: new Date(Date.now() - 86400000).toISOString(),
|
||||
activeTo: new Date(Date.now() + 86400000).toISOString(),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
axiosGetStub.resolves(mockResponse)
|
||||
const banners = await bannerService.fetchActiveBanners()
|
||||
expect(banners).to.have.lengthOf(1)
|
||||
expect(banners[0].id).to.equal("bnr_active")
|
||||
})
|
||||
})
|
||||
|
||||
describe("API Provider Rule Evaluation", () => {
|
||||
it("should show banner when user has the required API provider configured", async () => {
|
||||
describe("API Provider Rule Evaluation (Client-Side)", () => {
|
||||
it("should show banner when user has selected the required API provider in act mode", async () => {
|
||||
const controllerWithOpenAI: Partial<Controller> = {
|
||||
stateManager: {
|
||||
getApiConfiguration: () => ({
|
||||
openAiApiKey: "sk-test-key",
|
||||
actModeApiProvider: "openai",
|
||||
}),
|
||||
getGlobalSettingsKey: () => undefined,
|
||||
getGlobalSettingsKey: (key: string) => (key === "mode" ? "act" : undefined),
|
||||
getGlobalStateKey: () => [],
|
||||
} as any,
|
||||
}
|
||||
@@ -244,19 +164,57 @@ describe("BannerService", () => {
|
||||
expect(banners[0].id).to.equal("bnr_openai")
|
||||
})
|
||||
|
||||
it("should NOT show banner when user doesn't have the required API provider", async () => {
|
||||
const controllerWithoutOpenAI: Partial<Controller> = {
|
||||
it("should show banner when user has selected the required API provider in plan mode", async () => {
|
||||
const controllerWithAnthropic: Partial<Controller> = {
|
||||
stateManager: {
|
||||
getApiConfiguration: () => ({
|
||||
apiKey: "sk-ant-test", // Has Anthropic key but not OpenAI
|
||||
planModeApiProvider: "anthropic",
|
||||
}),
|
||||
getGlobalSettingsKey: () => undefined,
|
||||
getGlobalSettingsKey: (key: string) => (key === "mode" ? "plan" : undefined),
|
||||
getGlobalStateKey: () => [],
|
||||
} as any,
|
||||
}
|
||||
// Reinitialize with new controller
|
||||
BannerService.reset()
|
||||
bannerService = BannerService.initialize(controllerWithoutOpenAI as Controller)
|
||||
bannerService = BannerService.initialize(controllerWithAnthropic as Controller)
|
||||
|
||||
const mockResponse = {
|
||||
data: {
|
||||
data: {
|
||||
items: [
|
||||
{
|
||||
id: "bnr_anthropic",
|
||||
titleMd: "Anthropic Users",
|
||||
bodyMd: "For Anthropic API",
|
||||
severity: "info" as const,
|
||||
placement: "top" as const,
|
||||
rulesJson: JSON.stringify({ providers: ["anthropic"] } as BannerRules),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
axiosGetStub.resolves(mockResponse)
|
||||
const banners = await bannerService.fetchActiveBanners()
|
||||
|
||||
expect(banners).to.have.lengthOf(1)
|
||||
expect(banners[0].id).to.equal("bnr_anthropic")
|
||||
})
|
||||
|
||||
it("should NOT show banner when user has selected a different API provider", async () => {
|
||||
const controllerWithAnthropic: Partial<Controller> = {
|
||||
stateManager: {
|
||||
getApiConfiguration: () => ({
|
||||
actModeApiProvider: "anthropic",
|
||||
}),
|
||||
getGlobalSettingsKey: (key: string) => (key === "mode" ? "act" : undefined),
|
||||
getGlobalStateKey: () => [],
|
||||
} as any,
|
||||
}
|
||||
// Reinitialize with new controller
|
||||
BannerService.reset()
|
||||
bannerService = BannerService.initialize(controllerWithAnthropic as Controller)
|
||||
|
||||
const mockResponse = {
|
||||
data: {
|
||||
@@ -281,13 +239,13 @@ describe("BannerService", () => {
|
||||
expect(banners).to.have.lengthOf(0)
|
||||
})
|
||||
|
||||
it("should show banner if user has ANY of multiple specified providers", async () => {
|
||||
it("should show banner if user has selected ANY of multiple specified providers", async () => {
|
||||
const controllerWithAnthropic: Partial<Controller> = {
|
||||
stateManager: {
|
||||
getApiConfiguration: () => ({
|
||||
apiKey: "sk-ant-test", // Has Anthropic key
|
||||
actModeApiProvider: "anthropic",
|
||||
}),
|
||||
getGlobalSettingsKey: () => undefined,
|
||||
getGlobalSettingsKey: (key: string) => (key === "mode" ? "act" : undefined),
|
||||
getGlobalStateKey: () => [],
|
||||
} as any,
|
||||
}
|
||||
@@ -318,243 +276,30 @@ describe("BannerService", () => {
|
||||
expect(banners).to.have.lengthOf(1)
|
||||
expect(banners[0].id).to.equal("bnr_multi")
|
||||
})
|
||||
})
|
||||
|
||||
describe("Audience Targeting", () => {
|
||||
it("should show banner targeting all users", async () => {
|
||||
const mockResponse = {
|
||||
data: {
|
||||
data: {
|
||||
items: [
|
||||
{
|
||||
id: "bnr_all",
|
||||
titleMd: "All Users",
|
||||
bodyMd: "For everyone",
|
||||
severity: "info" as const,
|
||||
placement: "top" as const,
|
||||
rulesJson: JSON.stringify({ audience: ["all"] } as BannerRules),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
it("should NOT show banner when no provider is selected", async () => {
|
||||
const controllerWithNoProvider: Partial<Controller> = {
|
||||
stateManager: {
|
||||
getApiConfiguration: () => ({}),
|
||||
getGlobalSettingsKey: (key: string) => (key === "mode" ? "act" : undefined),
|
||||
getGlobalStateKey: () => [],
|
||||
} as any,
|
||||
}
|
||||
|
||||
axiosGetStub.resolves(mockResponse)
|
||||
const banners = await bannerService.fetchActiveBanners()
|
||||
|
||||
expect(banners).to.have.lengthOf(1)
|
||||
expect(banners[0].id).to.equal("bnr_all")
|
||||
})
|
||||
|
||||
it("should show team admin banner to admin users", async () => {
|
||||
const mockAuthService = {
|
||||
getUserOrganizations: () => [{ id: "org1", name: "Test Org", roles: ["admin"] }],
|
||||
getInfo: () => ({ user: { email: "test@example.com" } }),
|
||||
} as any
|
||||
|
||||
bannerService.setAuthService(mockAuthService)
|
||||
// Reinitialize with new controller
|
||||
BannerService.reset()
|
||||
bannerService = BannerService.initialize(controllerWithNoProvider as Controller)
|
||||
|
||||
const mockResponse = {
|
||||
data: {
|
||||
data: {
|
||||
items: [
|
||||
{
|
||||
id: "bnr_admin",
|
||||
titleMd: "Team Admins",
|
||||
bodyMd: "For team admins only",
|
||||
id: "bnr_openai",
|
||||
titleMd: "OpenAI Users",
|
||||
bodyMd: "For OpenAI API",
|
||||
severity: "info" as const,
|
||||
placement: "top" as const,
|
||||
rulesJson: JSON.stringify({ audience: ["team_admin_only"] } as BannerRules),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
axiosGetStub.resolves(mockResponse)
|
||||
const banners = await bannerService.fetchActiveBanners()
|
||||
|
||||
expect(banners).to.have.lengthOf(1)
|
||||
expect(banners[0].id).to.equal("bnr_admin")
|
||||
})
|
||||
|
||||
it("should show team admin banner to owner users", async () => {
|
||||
const mockAuthService = {
|
||||
getUserOrganizations: () => [{ id: "org1", name: "Test Org", roles: ["owner"] }],
|
||||
getInfo: () => ({ user: { email: "test@example.com" } }),
|
||||
} as any
|
||||
|
||||
bannerService.setAuthService(mockAuthService)
|
||||
|
||||
const mockResponse = {
|
||||
data: {
|
||||
data: {
|
||||
items: [
|
||||
{
|
||||
id: "bnr_admin",
|
||||
titleMd: "Team Admins",
|
||||
bodyMd: "For team admins only",
|
||||
severity: "info" as const,
|
||||
placement: "top" as const,
|
||||
rulesJson: JSON.stringify({ audience: ["team_admin_only"] } as BannerRules),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
axiosGetStub.resolves(mockResponse)
|
||||
const banners = await bannerService.fetchActiveBanners()
|
||||
|
||||
expect(banners).to.have.lengthOf(1)
|
||||
expect(banners[0].id).to.equal("bnr_admin")
|
||||
})
|
||||
|
||||
it("should NOT show team admin banner to non-admin users", async () => {
|
||||
const mockAuthService = {
|
||||
getUserOrganizations: () => [{ id: "org1", name: "Test Org", roles: ["member"] }],
|
||||
getInfo: () => ({ user: { email: "test@example.com" } }),
|
||||
} as any
|
||||
|
||||
bannerService.setAuthService(mockAuthService)
|
||||
|
||||
const mockResponse = {
|
||||
data: {
|
||||
data: {
|
||||
items: [
|
||||
{
|
||||
id: "bnr_admin",
|
||||
titleMd: "Team Admins",
|
||||
bodyMd: "For team admins only",
|
||||
severity: "info" as const,
|
||||
placement: "top" as const,
|
||||
rulesJson: JSON.stringify({ audience: ["team_admin_only"] } as BannerRules),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
axiosGetStub.resolves(mockResponse)
|
||||
const banners = await bannerService.fetchActiveBanners()
|
||||
|
||||
expect(banners).to.have.lengthOf(0)
|
||||
})
|
||||
|
||||
it("should show team members banner to users in organizations", async () => {
|
||||
const mockAuthService = {
|
||||
getUserOrganizations: () => [{ id: "org1", name: "Test Org", roles: ["member"] }],
|
||||
getInfo: () => ({ user: { email: "test@example.com" } }),
|
||||
} as any
|
||||
|
||||
bannerService.setAuthService(mockAuthService)
|
||||
|
||||
const mockResponse = {
|
||||
data: {
|
||||
data: {
|
||||
items: [
|
||||
{
|
||||
id: "bnr_team",
|
||||
titleMd: "Team Members",
|
||||
bodyMd: "For team members",
|
||||
severity: "info" as const,
|
||||
placement: "top" as const,
|
||||
rulesJson: JSON.stringify({ audience: ["team_members"] } as BannerRules),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
axiosGetStub.resolves(mockResponse)
|
||||
const banners = await bannerService.fetchActiveBanners()
|
||||
|
||||
expect(banners).to.have.lengthOf(1)
|
||||
expect(banners[0].id).to.equal("bnr_team")
|
||||
})
|
||||
|
||||
it("should NOT show team members banner to users without organizations", async () => {
|
||||
const mockAuthService = {
|
||||
getUserOrganizations: () => [],
|
||||
getInfo: () => ({ user: { email: "test@example.com" } }),
|
||||
} as any
|
||||
|
||||
bannerService.setAuthService(mockAuthService)
|
||||
|
||||
const mockResponse = {
|
||||
data: {
|
||||
data: {
|
||||
items: [
|
||||
{
|
||||
id: "bnr_team",
|
||||
titleMd: "Team Members",
|
||||
bodyMd: "For team members",
|
||||
severity: "info" as const,
|
||||
placement: "top" as const,
|
||||
rulesJson: JSON.stringify({ audience: ["team_members"] } as BannerRules),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
axiosGetStub.resolves(mockResponse)
|
||||
const banners = await bannerService.fetchActiveBanners()
|
||||
|
||||
expect(banners).to.have.lengthOf(0)
|
||||
})
|
||||
|
||||
it("should show personal banner to users without organizations", async () => {
|
||||
const mockAuthService = {
|
||||
getUserOrganizations: () => [],
|
||||
getInfo: () => ({ user: { email: "test@example.com" } }),
|
||||
} as any
|
||||
|
||||
bannerService.setAuthService(mockAuthService)
|
||||
|
||||
const mockResponse = {
|
||||
data: {
|
||||
data: {
|
||||
items: [
|
||||
{
|
||||
id: "bnr_personal",
|
||||
titleMd: "Personal Users",
|
||||
bodyMd: "For personal users",
|
||||
severity: "info" as const,
|
||||
placement: "top" as const,
|
||||
rulesJson: JSON.stringify({ audience: ["personal_only"] } as BannerRules),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
axiosGetStub.resolves(mockResponse)
|
||||
const banners = await bannerService.fetchActiveBanners()
|
||||
|
||||
expect(banners).to.have.lengthOf(1)
|
||||
expect(banners[0].id).to.equal("bnr_personal")
|
||||
})
|
||||
|
||||
it("should NOT show personal banner to users with organizations", async () => {
|
||||
const mockAuthService = {
|
||||
getUserOrganizations: () => [{ id: "org1", name: "Test Org", roles: ["member"] }],
|
||||
getInfo: () => ({ user: { email: "test@example.com" } }),
|
||||
} as any
|
||||
|
||||
bannerService.setAuthService(mockAuthService)
|
||||
|
||||
const mockResponse = {
|
||||
data: {
|
||||
data: {
|
||||
items: [
|
||||
{
|
||||
id: "bnr_personal",
|
||||
titleMd: "Personal Users",
|
||||
bodyMd: "For personal users",
|
||||
severity: "info" as const,
|
||||
placement: "top" as const,
|
||||
rulesJson: JSON.stringify({ audience: ["personal_only"] } as BannerRules),
|
||||
rulesJson: JSON.stringify({ providers: ["openai"] } as BannerRules),
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -649,4 +394,128 @@ describe("BannerService", () => {
|
||||
expect(axiosGetStub.calledTwice).to.be.true
|
||||
})
|
||||
})
|
||||
|
||||
describe("OS Parameter Integration", () => {
|
||||
it("should send OS parameter in API request", async () => {
|
||||
const mockResponse = {
|
||||
data: {
|
||||
data: {
|
||||
items: [
|
||||
{
|
||||
id: "bnr_test",
|
||||
titleMd: "Test Banner",
|
||||
bodyMd: "This is a test",
|
||||
severity: "info" as const,
|
||||
placement: "top" as const,
|
||||
rulesJson: "{}",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
axiosGetStub.resolves(mockResponse)
|
||||
await bannerService.fetchActiveBanners()
|
||||
|
||||
expect(axiosGetStub.calledOnce).to.be.true
|
||||
const call = axiosGetStub.getCall(0)
|
||||
const url = call.args[0]
|
||||
expect(url).to.include("os=")
|
||||
})
|
||||
|
||||
it("should handle OS detection errors gracefully", async () => {
|
||||
const originalPlatform = process.platform
|
||||
Object.defineProperty(process, "platform", {
|
||||
get: () => {
|
||||
throw new Error("Platform access denied")
|
||||
},
|
||||
configurable: true,
|
||||
})
|
||||
|
||||
const mockResponse = {
|
||||
data: {
|
||||
data: {
|
||||
items: [
|
||||
{
|
||||
id: "bnr_test",
|
||||
titleMd: "Test Banner",
|
||||
bodyMd: "This is a test",
|
||||
severity: "info" as const,
|
||||
placement: "top" as const,
|
||||
rulesJson: "{}",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
axiosGetStub.resolves(mockResponse)
|
||||
const banners = await bannerService.fetchActiveBanners()
|
||||
|
||||
Object.defineProperty(process, "platform", {
|
||||
value: originalPlatform,
|
||||
configurable: true,
|
||||
})
|
||||
|
||||
expect(banners).to.have.lengthOf(1)
|
||||
expect(axiosGetStub.calledOnce).to.be.true
|
||||
const call = axiosGetStub.getCall(0)
|
||||
const url = call.args[0]
|
||||
expect(url).to.include("os=unknown")
|
||||
})
|
||||
|
||||
it("should detect different OS types correctly", async () => {
|
||||
const testCases = [
|
||||
{ platform: "win32", expected: "windows" },
|
||||
{ platform: "darwin", expected: "macos" },
|
||||
{ platform: "linux", expected: "linux" },
|
||||
{ platform: "freebsd", expected: "unknown" },
|
||||
]
|
||||
|
||||
for (const { platform, expected } of testCases) {
|
||||
const originalPlatform = process.platform
|
||||
Object.defineProperty(process, "platform", {
|
||||
value: platform,
|
||||
configurable: true,
|
||||
})
|
||||
|
||||
const mockResponse = {
|
||||
data: {
|
||||
data: {
|
||||
items: [
|
||||
{
|
||||
id: "bnr_test",
|
||||
titleMd: "Test Banner",
|
||||
bodyMd: "This is a test",
|
||||
severity: "info" as const,
|
||||
placement: "top" as const,
|
||||
rulesJson: "{}",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
axiosGetStub.resolves(mockResponse)
|
||||
|
||||
// Clear cache to ensure fresh API call for each platform test
|
||||
bannerService.clearCache()
|
||||
|
||||
await bannerService.fetchActiveBanners()
|
||||
|
||||
expect(axiosGetStub.called).to.be.true
|
||||
const call = axiosGetStub.lastCall
|
||||
expect(call).to.not.be.null
|
||||
const url = call.args[0]
|
||||
expect(url).to.include(`os=${expected}`)
|
||||
|
||||
Object.defineProperty(process, "platform", {
|
||||
value: originalPlatform,
|
||||
configurable: true,
|
||||
})
|
||||
|
||||
axiosGetStub.resetHistory()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { Banner, BannerRules, BannersResponse } from "@shared/ClineBanner"
|
||||
import { isClineInternalTester } from "@shared/internal/account"
|
||||
import axios from "axios"
|
||||
import { ClineEnv } from "@/config"
|
||||
import type { Controller } from "@/core/controller"
|
||||
@@ -74,6 +73,8 @@ export class BannerService {
|
||||
|
||||
/**
|
||||
* Fetches active banners from the API
|
||||
* Backend handles all filtering based on ide and user context
|
||||
* Extension only filters by providers (API provider configuration)
|
||||
* @param forceRefresh If true, bypasses cache and fetches fresh data
|
||||
* @returns Array of banners that match current environment
|
||||
*/
|
||||
@@ -86,21 +87,36 @@ export class BannerService {
|
||||
return this._cachedBanners
|
||||
}
|
||||
|
||||
// Fetch from API
|
||||
let url: string
|
||||
try {
|
||||
url = new URL("/banners/v1/messages", this._baseUrl).toString()
|
||||
Logger.log(`BannerService: Fetching banners from ${url}`)
|
||||
} catch (urlError) {
|
||||
console.error("Error constructing URL:", urlError)
|
||||
throw urlError
|
||||
const ideType = await this.getIdeType()
|
||||
const extensionVersion = await this.getExtensionVersion()
|
||||
const osType = await this.getOSType()
|
||||
|
||||
const urlObj = new URL("/banners/v1/messages", this._baseUrl)
|
||||
urlObj.searchParams.set("ide", ideType)
|
||||
if (extensionVersion) {
|
||||
urlObj.searchParams.set("extension_version", extensionVersion)
|
||||
}
|
||||
urlObj.searchParams.set("os", osType)
|
||||
|
||||
const url = urlObj.toString()
|
||||
Logger.log(`BannerService: Fetching banners from ${url}`)
|
||||
|
||||
const authService = this.getAuthServiceInstance()
|
||||
let token: string | null = null
|
||||
if (authService) {
|
||||
token = await authService.getAuthToken()
|
||||
}
|
||||
|
||||
const headers: Record<string, string> = {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
if (token) {
|
||||
headers["Authorization"] = `Bearer ${token}`
|
||||
}
|
||||
|
||||
const response = await axios.get<BannersResponse>(url, {
|
||||
timeout: 10000, // 10 second timeout
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
timeout: 10000,
|
||||
headers,
|
||||
...getAxiosSettings(),
|
||||
})
|
||||
|
||||
@@ -109,17 +125,12 @@ export class BannerService {
|
||||
return []
|
||||
}
|
||||
|
||||
const allBanners = response.data.data.items
|
||||
Logger.log(`BannerService: Received ${allBanners.length} banners from API`)
|
||||
const backendFilteredBanners = response.data.data.items
|
||||
Logger.log(`BannerService: Received ${backendFilteredBanners.length} banners from backend (already filtered)`)
|
||||
|
||||
// Filter banners based on rules evaluation
|
||||
const matchingBanners = []
|
||||
for (const banner of allBanners) {
|
||||
if (await this.evaluateBannerRules(banner)) {
|
||||
matchingBanners.push(banner)
|
||||
}
|
||||
}
|
||||
Logger.log(`BannerService: ${matchingBanners.length} banners match current environment`)
|
||||
// Client-side filtering: Only filter by providers
|
||||
const matchingBanners = backendFilteredBanners.filter((banner) => this.matchesProviderRule(banner))
|
||||
Logger.log(`BannerService: ${matchingBanners.length} banners match provider requirements`)
|
||||
|
||||
// Update cache
|
||||
this._cachedBanners = matchingBanners
|
||||
@@ -134,164 +145,96 @@ export class BannerService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates banner rules against the current environment
|
||||
* @param banner Banner to evaluate
|
||||
* @returns true if banner should be displayed
|
||||
* Gets the current extension version
|
||||
* @returns Extension version string (e.g., "3.39.2")
|
||||
*/
|
||||
private async evaluateBannerRules(banner: Banner): Promise<boolean> {
|
||||
private async getExtensionVersion(): Promise<string> {
|
||||
try {
|
||||
// Check date range first (active_from and active_to)
|
||||
if (!this.isWithinActiveDateRange(banner)) {
|
||||
Logger.log(`BannerService: Banner ${banner.id} filtered out - outside active date range`)
|
||||
const hostVersion = await HostProvider.env.getHostVersion({})
|
||||
return hostVersion.clineVersion || ""
|
||||
} catch (error) {
|
||||
Logger.error("BannerService: Error getting extension version", error)
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Client-side filtering by providers rule only
|
||||
* Backend handles all other filtering (ide, employee_only, audience, org_type, version)
|
||||
* @param banner Banner to check
|
||||
* @returns true if banner matches provider requirements or has no provider restrictions
|
||||
*/
|
||||
private matchesProviderRule(banner: Banner): boolean {
|
||||
try {
|
||||
const rules: BannerRules = JSON.parse(banner.rulesJson || "{}")
|
||||
|
||||
if (!rules.providers || rules.providers.length === 0) {
|
||||
return true
|
||||
}
|
||||
|
||||
const apiConfiguration = this._controller.stateManager.getApiConfiguration()
|
||||
const currentMode = this._controller.stateManager.getGlobalSettingsKey("mode")
|
||||
const selectedProvider =
|
||||
currentMode === "plan" ? apiConfiguration?.planModeApiProvider : apiConfiguration?.actModeApiProvider
|
||||
|
||||
if (!selectedProvider) {
|
||||
Logger.log(`BannerService: Banner ${banner.id} filtered by client - no provider selected for ${currentMode} mode`)
|
||||
return false
|
||||
}
|
||||
|
||||
// Parse rules JSON
|
||||
const rules: BannerRules = JSON.parse(banner.rulesJson || "{}")
|
||||
|
||||
// Check IDE rule
|
||||
if (rules.ide && rules.ide.length > 0) {
|
||||
const currentIde = await this.getIdeType()
|
||||
if (currentIde && !rules.ide.includes(currentIde)) {
|
||||
Logger.log(
|
||||
`BannerService: Banner ${banner.id} filtered out by IDE rule (requires: ${rules.ide.join(", ")}, current: ${currentIde})`,
|
||||
)
|
||||
return false
|
||||
const hasMatchingProvider = rules.providers.some((provider) => {
|
||||
// Normalize provider names for comparison
|
||||
switch (provider) {
|
||||
case "anthropic":
|
||||
case "claude-code":
|
||||
return selectedProvider === "anthropic"
|
||||
case "openai":
|
||||
case "openai-native":
|
||||
return selectedProvider === "openai" || selectedProvider === "openai-native"
|
||||
case "qwen":
|
||||
case "qwen-code":
|
||||
return selectedProvider === "qwen"
|
||||
default:
|
||||
// For any other providers, do a direct string comparison
|
||||
return selectedProvider === provider
|
||||
}
|
||||
})
|
||||
|
||||
if (!hasMatchingProvider) {
|
||||
Logger.log(
|
||||
`BannerService: Banner ${banner.id} filtered by client - selected provider '${selectedProvider}' doesn't match any of these required providers: ${rules.providers.join(", ")}`,
|
||||
)
|
||||
}
|
||||
|
||||
// Check auth provider rule
|
||||
if (rules.auth && rules.auth.length > 0 && this._controller) {
|
||||
const authProvider = this.getAuthProvider()
|
||||
if (authProvider && !rules.auth.includes(authProvider)) {
|
||||
Logger.log(
|
||||
`BannerService: Banner ${banner.id} filtered out by auth rule (requires: ${rules.auth.join(", ")}, current: ${authProvider})`,
|
||||
)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Check API providers rule - show banner if user has ANY of the specified providers configured
|
||||
if (rules.providers && rules.providers.length > 0 && this._controller) {
|
||||
const apiConfiguration = this._controller.stateManager.getApiConfiguration()
|
||||
const hasAnyProvider = rules.providers.some((provider) => {
|
||||
switch (provider) {
|
||||
case "anthropic":
|
||||
case "claude-code":
|
||||
return !!apiConfiguration?.apiKey
|
||||
case "openai":
|
||||
case "openai-native":
|
||||
return !!apiConfiguration?.openAiApiKey || !!apiConfiguration?.openAiNativeApiKey
|
||||
case "openrouter":
|
||||
return !!apiConfiguration?.openRouterApiKey
|
||||
case "bedrock":
|
||||
return !!apiConfiguration?.awsAccessKey || !!apiConfiguration?.awsBedrockApiKey
|
||||
case "gemini":
|
||||
return !!apiConfiguration?.geminiApiKey
|
||||
case "deepseek":
|
||||
return !!apiConfiguration?.deepSeekApiKey
|
||||
case "qwen":
|
||||
case "qwen-code":
|
||||
return !!apiConfiguration?.qwenApiKey
|
||||
case "mistral":
|
||||
return !!apiConfiguration?.mistralApiKey
|
||||
case "ollama":
|
||||
return !!apiConfiguration?.ollamaApiKey
|
||||
case "xai":
|
||||
return !!apiConfiguration?.xaiApiKey
|
||||
case "cerebras":
|
||||
return !!apiConfiguration?.cerebrasApiKey
|
||||
case "groq":
|
||||
return !!apiConfiguration?.groqApiKey
|
||||
case "cline":
|
||||
return (
|
||||
apiConfiguration?.planModeApiProvider === "cline" ||
|
||||
apiConfiguration?.actModeApiProvider === "cline"
|
||||
)
|
||||
default:
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
if (!hasAnyProvider) {
|
||||
Logger.log(
|
||||
`BannerService: Banner ${banner.id} filtered out - user doesn't have any of these providers configured: ${rules.providers.join(", ")}`,
|
||||
)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Check employee only rule
|
||||
if (rules.employee_only && this._controller) {
|
||||
const isEmployee = this.isEmployee()
|
||||
if (!isEmployee) {
|
||||
Logger.log(`BannerService: Banner ${banner.id} filtered out - employee only`)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if (rules.audience && rules.audience.length > 0 && this._controller) {
|
||||
const matchesAnyAudience = rules.audience.some((audienceType) => {
|
||||
switch (audienceType) {
|
||||
case "all":
|
||||
return true
|
||||
|
||||
case "team_admin_only":
|
||||
const isTeamAdmin = this.isUserTeamAdmin()
|
||||
return isTeamAdmin
|
||||
|
||||
case "team_members":
|
||||
const hasOrganizations = this.hasOrganizations()
|
||||
return hasOrganizations
|
||||
|
||||
case "personal_only":
|
||||
const hasOrgs = this.hasOrganizations()
|
||||
return !hasOrgs
|
||||
|
||||
default:
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
if (!matchesAnyAudience) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Logger.log(`BannerService: Banner ${banner.id} passed all rules checks`)
|
||||
return true
|
||||
return hasMatchingProvider
|
||||
} catch (error) {
|
||||
// If rules can't be parsed or evaluated, show the banner (fail open)
|
||||
Logger.log(
|
||||
`BannerService: Error evaluating rules for banner ${banner.id}: ${error instanceof Error ? error.message : String(error)}`,
|
||||
`BannerService: Error parsing provider rules for banner ${banner.id}: ${error instanceof Error ? error.message : String(error)}`,
|
||||
)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the banner is within its active date range
|
||||
* @param banner Banner to check
|
||||
* @returns true if current date is within activeFrom and activeTo range
|
||||
* Gets the current Operating System
|
||||
* @returns OS type (windows, linux, macos or unknown)
|
||||
*/
|
||||
private isWithinActiveDateRange(banner: Banner): boolean {
|
||||
const now = new Date()
|
||||
|
||||
if (banner.activeFrom) {
|
||||
const activeFrom = new Date(banner.activeFrom)
|
||||
if (now < activeFrom) {
|
||||
return false
|
||||
private async getOSType(): Promise<string> {
|
||||
try {
|
||||
switch (process.platform) {
|
||||
case "win32":
|
||||
return "windows"
|
||||
case "linux":
|
||||
return "linux"
|
||||
case "darwin":
|
||||
return "macos"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
} catch (error) {
|
||||
Logger.error("BannerService: Error getting OS type", error)
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
if (banner.activeTo) {
|
||||
const activeTo = new Date(banner.activeTo)
|
||||
if (now > activeTo) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -322,108 +265,6 @@ export class BannerService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current auth provider name
|
||||
* @returns Auth provider name (firebase, workos, or unknown)
|
||||
*/
|
||||
private getAuthProvider(): string {
|
||||
try {
|
||||
// Get auth provider from AuthService
|
||||
const authService = this.getAuthServiceInstance()
|
||||
if (!authService) {
|
||||
return "unknown"
|
||||
}
|
||||
const authInfo = authService.getInfo()
|
||||
|
||||
// Check if user is authenticated
|
||||
if (!authInfo.user) {
|
||||
return "other"
|
||||
}
|
||||
|
||||
// Get provider name using public method
|
||||
const providerName = authService.getProviderName()
|
||||
if (providerName) {
|
||||
// Map provider names to expected values
|
||||
if (providerName === "cline") {
|
||||
return "workos"
|
||||
}
|
||||
return providerName
|
||||
}
|
||||
|
||||
return "unknown"
|
||||
} catch (error) {
|
||||
Logger.error("BannerService: Error getting auth provider", error)
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current user is a Cline employee
|
||||
* @returns true if user has a @cline.bot email or is a trusted tester
|
||||
*/
|
||||
private isEmployee(): boolean {
|
||||
try {
|
||||
const authService = this.getAuthServiceInstance()
|
||||
if (!authService) {
|
||||
return false
|
||||
}
|
||||
const authInfo = authService.getInfo()
|
||||
|
||||
if (!authInfo.user || !authInfo.user.email) {
|
||||
return false
|
||||
}
|
||||
|
||||
return isClineInternalTester(authInfo.user.email)
|
||||
} catch (error) {
|
||||
Logger.error("BannerService: Error checking employee status", error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current user is a team admin
|
||||
* @returns true if user is an admin or owner of any organization
|
||||
*/
|
||||
private isUserTeamAdmin(): boolean {
|
||||
try {
|
||||
const authService = this.getAuthServiceInstance()
|
||||
if (!authService) {
|
||||
return false
|
||||
}
|
||||
const organizations = authService.getUserOrganizations()
|
||||
|
||||
if (!organizations || organizations.length === 0) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Check if user has admin or owner role in any organization
|
||||
// Admin and owner roles have the same permissions
|
||||
return organizations.some((org: any) => org.roles && (org.roles.includes("admin") || org.roles.includes("owner")))
|
||||
} catch (error) {
|
||||
Logger.error("BannerService: Error checking team admin status", error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current user is part of any organization
|
||||
* @returns true if user has one or more organizations
|
||||
*/
|
||||
private hasOrganizations(): boolean {
|
||||
try {
|
||||
const authService = this.getAuthServiceInstance()
|
||||
if (!authService) {
|
||||
return false
|
||||
}
|
||||
const organizations = authService.getUserOrganizations()
|
||||
|
||||
return !!(organizations && organizations.length > 0)
|
||||
} catch (error) {
|
||||
Logger.error("BannerService: Error checking organizations", error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the AuthService instance
|
||||
* @returns AuthService instance or undefined if not available
|
||||
|
||||
@@ -11,7 +11,6 @@ import * as path from "path"
|
||||
// @ts-ignore
|
||||
import type { ConsoleMessage, ScreenshotOptions } from "puppeteer-core"
|
||||
import { Browser, connect, launch, Page, TimeoutError } from "puppeteer-core"
|
||||
import * as vscode from "vscode"
|
||||
import { StateManager } from "@/core/storage/StateManager"
|
||||
import { telemetryService } from "@/services/telemetry"
|
||||
import { discoverChromeInstances, isPortOpen, testBrowserConnection } from "./BrowserDiscovery"
|
||||
@@ -73,24 +72,9 @@ export class BrowserSession {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrates the chromeExecutablePath setting from VSCode configuration to browserSettings
|
||||
*/
|
||||
private async migrateChromeExecutablePathSetting(): Promise<void> {
|
||||
const config = vscode.workspace.getConfiguration("cline")
|
||||
const configPath = vscode.workspace.getConfiguration("cline").get<string>("chromeExecutablePath")
|
||||
|
||||
if (configPath !== undefined) {
|
||||
this.stateManager.getGlobalSettingsKey("browserSettings").chromeExecutablePath = configPath
|
||||
// Remove from VSCode configuration
|
||||
await config.update("chromeExecutablePath", undefined, true)
|
||||
}
|
||||
}
|
||||
|
||||
async getDetectedChromePath(): Promise<{ path: string; isBundled: boolean }> {
|
||||
// First check browserSettings (from UI, stored in global state)
|
||||
const browserSettings = this.stateManager.getGlobalSettingsKey("browserSettings")
|
||||
await this.migrateChromeExecutablePathSetting()
|
||||
if (browserSettings.chromeExecutablePath && (await fileExistsAtPath(browserSettings.chromeExecutablePath))) {
|
||||
return {
|
||||
path: browserSettings.chromeExecutablePath,
|
||||
|
||||
@@ -1,5 +1,20 @@
|
||||
import { ErrorSettings } from "./providers/IErrorProvider"
|
||||
|
||||
export { ClineError, ClineErrorType } from "./ClineError"
|
||||
export { type ErrorProviderConfig, ErrorProviderFactory, type ErrorProviderType } from "./ErrorProviderFactory"
|
||||
export { ErrorService } from "./ErrorService"
|
||||
export type { ErrorSettings, IErrorProvider } from "./providers/IErrorProvider"
|
||||
export { PostHogErrorProvider } from "./providers/PostHogErrorProvider"
|
||||
|
||||
export function getErrorLevelFromString(level: string | undefined): ErrorSettings["level"] {
|
||||
switch (level) {
|
||||
case "disabled":
|
||||
case "off":
|
||||
return "off"
|
||||
case "error":
|
||||
case "crash":
|
||||
return "error"
|
||||
default:
|
||||
return "all"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { PostHog } from "posthog-node"
|
||||
import * as vscode from "vscode"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { getDistinctId } from "@/services/logging/distinctId"
|
||||
import { PostHogClientProvider } from "@/services/telemetry/providers/posthog/PostHogClientProvider"
|
||||
import { Setting } from "@/shared/proto/index.host"
|
||||
import * as pkg from "../../../../package.json"
|
||||
import { PostHogClientValidConfig } from "../../../shared/services/config/posthog-config"
|
||||
import { getErrorLevelFromString } from ".."
|
||||
import { ClineError } from "../ClineError"
|
||||
import type { ErrorSettings, IErrorProvider } from "./IErrorProvider"
|
||||
|
||||
@@ -53,13 +53,8 @@ export class PostHogErrorProvider implements IErrorProvider {
|
||||
this.errorSettings.hostEnabled = false
|
||||
}
|
||||
|
||||
// Check extension-specific telemetry setting
|
||||
const config = vscode.workspace.getConfiguration("cline")
|
||||
if (config.get("telemetrySetting") === "disabled") {
|
||||
this.errorSettings.enabled = false
|
||||
}
|
||||
this.errorSettings.level = getErrorLevelFromString(hostSettings.errorLevel)
|
||||
|
||||
this.errorSettings.level = await this.getErrorLevel()
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -134,15 +129,6 @@ export class PostHogErrorProvider implements IErrorProvider {
|
||||
return { ...this.errorSettings }
|
||||
}
|
||||
|
||||
private async getErrorLevel(): Promise<ErrorSettings["level"]> {
|
||||
const hostSettings = await HostProvider.env.getTelemetrySettings({})
|
||||
if (hostSettings.isEnabled === Setting.DISABLED) {
|
||||
return "off"
|
||||
}
|
||||
const config = vscode.workspace.getConfiguration("telemetry")
|
||||
return config?.get<ErrorSettings["level"]>("telemetryLevel") || "all"
|
||||
}
|
||||
|
||||
private get distinctId(): string {
|
||||
return getDistinctId()
|
||||
}
|
||||
|
||||
+75
-20
@@ -1,6 +1,7 @@
|
||||
import { setTimeout as setTimeoutPromise } from "node:timers/promises"
|
||||
import { sendMcpServersUpdate } from "@core/controller/mcp/subscribeToMcpServers"
|
||||
import { GlobalFileNames } from "@core/storage/disk"
|
||||
import { StateManager } from "@core/storage/StateManager"
|
||||
import { UnauthorizedError } from "@modelcontextprotocol/sdk/client/auth.js"
|
||||
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
|
||||
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js"
|
||||
@@ -36,6 +37,7 @@ import { z } from "zod"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { fetch } from "@/shared/net"
|
||||
import { ShowMessageType } from "@/shared/proto/host/window"
|
||||
import { expandEnvironmentVariables } from "@/utils/envExpansion"
|
||||
import { getServerAuthHash } from "@/utils/mcpAuth"
|
||||
import { TelemetryService } from "../telemetry/TelemetryService"
|
||||
import { DEFAULT_REQUEST_TIMEOUT_MS } from "./constants"
|
||||
@@ -152,6 +154,10 @@ export class McpHub {
|
||||
return undefined
|
||||
}
|
||||
|
||||
// Expand environment variables before validation
|
||||
// This allows ${env:VAR_NAME} syntax in URLs, headers, env vars, etc.
|
||||
config = expandEnvironmentVariables(config)
|
||||
|
||||
// Validate against schema
|
||||
const result = McpSettingsSchema.safeParse(config)
|
||||
if (!result.success) {
|
||||
@@ -218,6 +224,47 @@ export class McpHub {
|
||||
// Remove existing connection if it exists (should never happen, the connection should be deleted beforehand)
|
||||
this.connections = this.connections.filter((conn) => conn.server.name !== name)
|
||||
|
||||
// Validate remote MCP server URL against remote config if blockPersonalRemoteMCPServers is enabled
|
||||
if (config.type !== "stdio" && "url" in config && config.url) {
|
||||
const stateManager = StateManager.get()
|
||||
const remoteConfig = stateManager.getRemoteConfigSettings()
|
||||
|
||||
if (remoteConfig.blockPersonalRemoteMCPServers === true) {
|
||||
const remoteMCPServers = remoteConfig.remoteMCPServers || []
|
||||
const allowedUrls = remoteMCPServers.map((server) => server.url)
|
||||
|
||||
if (!allowedUrls.includes(config.url)) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Validate local MCP servers based on remote config (enterprise feature)
|
||||
if (config.type === "stdio") {
|
||||
const stateManager = StateManager.get()
|
||||
const remoteConfig = stateManager.getRemoteConfigSettings()
|
||||
|
||||
// If marketplace is explicitly disabled by enterprise config, block all local servers
|
||||
if (remoteConfig.mcpMarketplaceEnabled === false) {
|
||||
return
|
||||
}
|
||||
|
||||
// Only apply allowlist restrictions if enterprise has configured an allowlist
|
||||
if (remoteConfig.allowedMCPServers && remoteConfig.allowedMCPServers.length > 0) {
|
||||
// Check if server is from GitHub marketplace
|
||||
if (name.startsWith("github.com/")) {
|
||||
const allowedIds = remoteConfig.allowedMCPServers.map((server: { id: string }) => server.id)
|
||||
|
||||
if (!allowedIds.includes(name)) {
|
||||
return
|
||||
}
|
||||
}
|
||||
// Non-GitHub local servers are allowed when there's an allowlist
|
||||
// (the allowlist only restricts marketplace servers)
|
||||
}
|
||||
// If no enterprise allowlist configured, allow all local servers (default behavior)
|
||||
}
|
||||
|
||||
if (config.disabled) {
|
||||
//console.log(`[MCP Debug] Creating disabled connection object for server "${name}"`)
|
||||
// Create a connection object for disabled server so it appears in UI
|
||||
@@ -236,6 +283,12 @@ export class McpHub {
|
||||
}
|
||||
|
||||
try {
|
||||
// Store unexpanded config for display/comparison (keeps credentials out of stored config)
|
||||
const configForStorage = JSON.stringify(config)
|
||||
|
||||
// Expand environment variables in config before using it
|
||||
const expandedConfig = expandEnvironmentVariables(config)
|
||||
|
||||
// Each MCP server requires its own transport connection and has unique capabilities, configurations, and error handling. Having separate clients also allows proper scoping of resources/tools and independent server management like reconnection.
|
||||
const client = new Client(
|
||||
{
|
||||
@@ -251,20 +304,19 @@ export class McpHub {
|
||||
|
||||
// Create OAuth provider for remote transports (SSE and HTTP)
|
||||
const authProvider =
|
||||
config.type === "sse" || config.type === "streamableHttp"
|
||||
? await this.mcpOAuthManager.getOrCreateProvider(name, config.url)
|
||||
expandedConfig.type === "sse" || expandedConfig.type === "streamableHttp"
|
||||
? await this.mcpOAuthManager.getOrCreateProvider(name, expandedConfig.url)
|
||||
: undefined
|
||||
|
||||
switch (config.type) {
|
||||
switch (expandedConfig.type) {
|
||||
case "stdio": {
|
||||
transport = new StdioClientTransport({
|
||||
command: config.command,
|
||||
args: config.args,
|
||||
cwd: config.cwd,
|
||||
command: expandedConfig.command,
|
||||
args: expandedConfig.args,
|
||||
cwd: expandedConfig.cwd,
|
||||
env: {
|
||||
// ...(config.env ? await injectEnv(config.env) : {}), // Commented out as injectEnv is not found
|
||||
...getDefaultEnvironment(),
|
||||
...(config.env || {}), // Use config.env directly or an empty object
|
||||
...(expandedConfig.env || {}), // Now has expanded environment variables
|
||||
},
|
||||
stderr: "pipe",
|
||||
})
|
||||
@@ -319,12 +371,12 @@ export class McpHub {
|
||||
const sseOptions = {
|
||||
authProvider,
|
||||
requestInit: {
|
||||
headers: config.headers,
|
||||
headers: expandedConfig.headers,
|
||||
},
|
||||
}
|
||||
const reconnectingEventSourceOptions = {
|
||||
max_retry_time: 5000,
|
||||
withCredentials: !!config.headers?.["Authorization"],
|
||||
withCredentials: !!expandedConfig.headers?.["Authorization"],
|
||||
// IMPORTANT: Custom fetch function is required for SSE with OAuth
|
||||
// When we provide eventSourceInit, we override the SDK's default fetch
|
||||
// The SDK's default would call _commonHeaders() for auth, but since we're
|
||||
@@ -346,7 +398,7 @@ export class McpHub {
|
||||
}
|
||||
// Use ReconnectingEventSource for auto-reconnection on connection drops
|
||||
global.EventSource = ReconnectingEventSource
|
||||
transport = new SSEClientTransport(new URL(config.url), {
|
||||
transport = new SSEClientTransport(new URL(expandedConfig.url), {
|
||||
...sseOptions,
|
||||
eventSourceInit: reconnectingEventSourceOptions,
|
||||
})
|
||||
@@ -364,10 +416,10 @@ export class McpHub {
|
||||
break
|
||||
}
|
||||
case "streamableHttp": {
|
||||
transport = new StreamableHTTPClientTransport(new URL(config.url), {
|
||||
transport = new StreamableHTTPClientTransport(new URL(expandedConfig.url), {
|
||||
authProvider,
|
||||
requestInit: {
|
||||
headers: config.headers ?? undefined,
|
||||
headers: expandedConfig.headers ?? undefined,
|
||||
},
|
||||
})
|
||||
transport.onerror = async (error) => {
|
||||
@@ -389,7 +441,7 @@ export class McpHub {
|
||||
const connection: McpConnection = {
|
||||
server: {
|
||||
name,
|
||||
config: JSON.stringify(config),
|
||||
config: configForStorage,
|
||||
status: "connecting",
|
||||
disabled: config.disabled,
|
||||
uid: this.getMcpServerKey(name),
|
||||
@@ -1118,11 +1170,6 @@ export class McpHub {
|
||||
throw new Error(`An MCP server with the name "${serverName}" already exists`)
|
||||
}
|
||||
|
||||
const urlValidation = z.string().url().safeParse(serverUrl)
|
||||
if (!urlValidation.success) {
|
||||
throw new Error(`Invalid server URL: ${serverUrl}. Please provide a valid URL.`)
|
||||
}
|
||||
|
||||
const serverConfig = {
|
||||
url: serverUrl,
|
||||
type: transportType,
|
||||
@@ -1130,7 +1177,15 @@ export class McpHub {
|
||||
autoApprove: [],
|
||||
}
|
||||
|
||||
const parsedConfig = ServerConfigSchema.parse(serverConfig)
|
||||
// Expand environment variables for validation
|
||||
const expandedConfig = expandEnvironmentVariables(serverConfig)
|
||||
|
||||
const urlValidation = z.string().url().safeParse(expandedConfig.url)
|
||||
if (!urlValidation.success) {
|
||||
throw new Error(`Invalid server URL: ${expandedConfig.url}. Please provide a valid URL.`)
|
||||
}
|
||||
|
||||
const parsedConfig = ServerConfigSchema.parse(expandedConfig)
|
||||
|
||||
settings.mcpServers[serverName] = parsedConfig
|
||||
const settingsPath = await this.getMcpSettingsFilePath()
|
||||
|
||||
@@ -47,7 +47,7 @@ export class TelemetryProviderFactory {
|
||||
providers.push(new NoOpTelemetryProvider())
|
||||
}
|
||||
|
||||
Logger.info("TelemetryProviderFactory: Created providers - " + providers.map((p) => p.name()).join(", "))
|
||||
Logger.info("TelemetryProviderFactory: Created providers - " + providers.map((p) => p.name).join(", "))
|
||||
return providers
|
||||
}
|
||||
|
||||
@@ -66,10 +66,15 @@ export class TelemetryProviderFactory {
|
||||
return new NoOpTelemetryProvider()
|
||||
}
|
||||
case "opentelemetry": {
|
||||
const meterProvider = OpenTelemetryClientProvider.getMeterProvider()
|
||||
const loggerProvider = OpenTelemetryClientProvider.getLoggerProvider()
|
||||
if (meterProvider || loggerProvider) {
|
||||
return await new OpenTelemetryTelemetryProvider().initialize()
|
||||
const otelConfig = getValidOpenTelemetryConfig()
|
||||
if (!otelConfig) {
|
||||
return new NoOpTelemetryProvider()
|
||||
}
|
||||
const client = new OpenTelemetryClientProvider(otelConfig)
|
||||
if (client.meterProvider || client.loggerProvider) {
|
||||
return await new OpenTelemetryTelemetryProvider(client.meterProvider, client.loggerProvider, {
|
||||
bypassUserSettings: false,
|
||||
}).initialize()
|
||||
}
|
||||
Logger.info("TelemetryProviderFactory: OpenTelemetry providers not available")
|
||||
return new NoOpTelemetryProvider()
|
||||
@@ -107,9 +112,7 @@ export class TelemetryProviderFactory {
|
||||
* or for testing purposes
|
||||
*/
|
||||
export class NoOpTelemetryProvider implements ITelemetryProvider {
|
||||
name(): string {
|
||||
return "NoOpTelemetryProvider"
|
||||
}
|
||||
readonly name = "NoOpTelemetryProvider"
|
||||
private isOptIn = true
|
||||
|
||||
log(_event: string, _properties?: TelemetryProperties): void {
|
||||
|
||||
@@ -16,7 +16,7 @@ import { TelemetryProviderFactory } from "./TelemetryProviderFactory"
|
||||
* When adding a new category, add it both here and to the initial values in telemetryCategoryEnabled
|
||||
* Ensure `if (!this.isCategoryEnabled('<category_name>')` is added to the capture method
|
||||
*/
|
||||
type TelemetryCategory = "checkpoints" | "browser" | "focus_chain" | "dictation" | "subagents"
|
||||
type TelemetryCategory = "checkpoints" | "browser" | "focus_chain" | "dictation" | "subagents" | "hooks"
|
||||
|
||||
/**
|
||||
* Enum for terminal output failure reasons
|
||||
@@ -89,6 +89,7 @@ export class TelemetryService {
|
||||
["dictation", true], // Dictation telemetry enabled
|
||||
["focus_chain", true], // Focus Chain telemetry enabled
|
||||
["subagents", true], // CLI Subagents telemetry enabled
|
||||
["hooks", true], // Hooks telemetry enabled
|
||||
])
|
||||
|
||||
private userId?: string
|
||||
@@ -126,6 +127,14 @@ export class TelemetryService {
|
||||
DURATION_SECONDS: "cline.api.duration.seconds",
|
||||
THROUGHPUT_TOKENS_PER_SECOND: "cline.api.throughput.tokens_per_second",
|
||||
},
|
||||
HOOKS: {
|
||||
EXECUTIONS_TOTAL: "cline.hooks.executions.total",
|
||||
DURATION_SECONDS: "cline.hooks.duration.seconds",
|
||||
FAILURES_TOTAL: "cline.hooks.failures.total",
|
||||
CANCELLATIONS_TOTAL: "cline.hooks.cancellations.total",
|
||||
CONTEXT_MODIFICATIONS_TOTAL: "cline.hooks.context_modifications.total",
|
||||
CACHE_ACCESSES_TOTAL: "cline.hooks.cache.accesses.total",
|
||||
},
|
||||
}
|
||||
// Event constants for tracking user interactions and system events
|
||||
private static readonly EVENTS = {
|
||||
@@ -267,6 +276,19 @@ export class TelemetryService {
|
||||
// Tracks when the rules menu button is clicked
|
||||
RULES_MENU_OPENED: "ui.rules_menu_opened",
|
||||
},
|
||||
// Hooks-related events for tracking hook execution
|
||||
HOOKS: {
|
||||
// Tracks when hooks feature is enabled
|
||||
ENABLED: "hooks.enabled",
|
||||
// Tracks when hooks feature is disabled
|
||||
DISABLED: "hooks.disabled",
|
||||
// Tracks when a hook requests task cancellation
|
||||
CANCEL_REQUESTED: "hooks.cancel_requested",
|
||||
// Tracks when a hook modifies context
|
||||
CONTEXT_MODIFIED: "hooks.context_modified",
|
||||
// Tracks when hook discovery completes
|
||||
DISCOVERY_COMPLETED: "hooks.discovery_completed",
|
||||
},
|
||||
}
|
||||
|
||||
public static async create(): Promise<TelemetryService> {
|
||||
@@ -296,6 +318,14 @@ export class TelemetryService {
|
||||
console.info(`[TelemetryService] Initialized with ${providers.length} telemetry provider(s)`)
|
||||
}
|
||||
|
||||
public addProvider(provider: ITelemetryProvider) {
|
||||
this.providers.push(provider)
|
||||
}
|
||||
|
||||
public removeProvider(name: string) {
|
||||
this.providers = this.providers.filter((p) => p.name !== name)
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the telemetry state based on user preferences and VSCode settings
|
||||
* Only enables telemetry if both VSCode global telemetry is enabled and user has opted in
|
||||
@@ -1926,6 +1956,171 @@ export class TelemetryService {
|
||||
})
|
||||
}
|
||||
|
||||
// Hooks telemetry methods
|
||||
|
||||
/**
|
||||
* Records hook discovery cache access (hit or miss)
|
||||
* @param hookName The type of hook being accessed
|
||||
* @param cacheHit Whether the cache had the result (true) or miss (false)
|
||||
*/
|
||||
public captureHookCacheAccess(hookName: string, cacheHit: boolean) {
|
||||
if (!this.isCategoryEnabled("hooks")) {
|
||||
return
|
||||
}
|
||||
|
||||
// Record cache access counter with hit/miss attribute
|
||||
// This allows deriving hit rate: hits / (hits + misses)
|
||||
this.recordCounter(TelemetryService.METRICS.HOOKS.CACHE_ACCESSES_TOTAL, 1, {
|
||||
hookName,
|
||||
cacheHit: cacheHit.toString(),
|
||||
})
|
||||
}
|
||||
|
||||
// Simplified Hook Telemetry API (following MCP pattern)
|
||||
|
||||
/**
|
||||
* Records hook execution events with a unified status-based approach.
|
||||
* This is the simplified API that consolidates multiple hook execution methods.
|
||||
*
|
||||
* @param ulid Task identifier
|
||||
* @param hookName Type of hook (PreToolUse, PostToolUse, etc.)
|
||||
* @param status Current execution status
|
||||
* @param metadata Optional execution metadata
|
||||
*/
|
||||
public captureHookExecution(
|
||||
ulid: string,
|
||||
hookName: string,
|
||||
status: "started" | "completed" | "failed" | "cancelled",
|
||||
metadata?: {
|
||||
source?: "global" | "workspace"
|
||||
toolName?: string
|
||||
durationMs?: number
|
||||
exitCode?: number
|
||||
errorType?: "timeout" | "execution" | "validation"
|
||||
errorMessage?: string
|
||||
cancelRequested?: boolean
|
||||
contextModified?: boolean
|
||||
contextSize?: number
|
||||
},
|
||||
) {
|
||||
if (!this.isCategoryEnabled("hooks")) {
|
||||
return
|
||||
}
|
||||
|
||||
const properties: TelemetryProperties = {
|
||||
ulid,
|
||||
hookName,
|
||||
status,
|
||||
timestamp: new Date().toISOString(),
|
||||
...(metadata?.source && { source: metadata.source }),
|
||||
...(metadata?.toolName && { toolName: metadata.toolName }),
|
||||
...(metadata?.durationMs !== undefined && { durationMs: metadata.durationMs }),
|
||||
...(metadata?.exitCode !== undefined && { exitCode: metadata.exitCode }),
|
||||
...(metadata?.errorType && { errorType: metadata.errorType }),
|
||||
...(metadata?.errorMessage && {
|
||||
errorMessage: metadata.errorMessage.substring(0, MAX_ERROR_MESSAGE_LENGTH),
|
||||
}),
|
||||
...(metadata?.cancelRequested !== undefined && { cancelRequested: metadata.cancelRequested }),
|
||||
...(metadata?.contextModified !== undefined && { contextModified: metadata.contextModified }),
|
||||
...(metadata?.contextSize !== undefined && { contextSize: metadata.contextSize }),
|
||||
}
|
||||
|
||||
// Single event for all statuses
|
||||
this.capture({
|
||||
event: "hooks.execution",
|
||||
properties,
|
||||
})
|
||||
|
||||
// Record metrics based on status
|
||||
const hookAttributes = {
|
||||
ulid,
|
||||
hookName,
|
||||
status,
|
||||
...(metadata?.source && { source: metadata.source }),
|
||||
...(metadata?.toolName && { toolName: metadata.toolName }),
|
||||
}
|
||||
|
||||
if (status === "started") {
|
||||
this.recordCounter(TelemetryService.METRICS.HOOKS.EXECUTIONS_TOTAL, 1, hookAttributes)
|
||||
} else if (status === "completed") {
|
||||
if (metadata?.durationMs !== undefined) {
|
||||
this.recordHistogram(TelemetryService.METRICS.HOOKS.DURATION_SECONDS, metadata.durationMs / 1000, hookAttributes)
|
||||
}
|
||||
if (metadata?.cancelRequested) {
|
||||
this.recordCounter(TelemetryService.METRICS.HOOKS.CANCELLATIONS_TOTAL, 1, hookAttributes)
|
||||
}
|
||||
if (metadata?.contextModified) {
|
||||
this.recordCounter(TelemetryService.METRICS.HOOKS.CONTEXT_MODIFICATIONS_TOTAL, 1, hookAttributes)
|
||||
}
|
||||
} else if (status === "failed") {
|
||||
this.recordCounter(TelemetryService.METRICS.HOOKS.FAILURES_TOTAL, 1, {
|
||||
...hookAttributes,
|
||||
errorType: metadata?.errorType || "unknown",
|
||||
})
|
||||
} else if (status === "cancelled") {
|
||||
this.recordCounter(TelemetryService.METRICS.HOOKS.CANCELLATIONS_TOTAL, 1, hookAttributes)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Records hook discovery results (simplified version).
|
||||
*
|
||||
* @param hookName The type of hook being discovered
|
||||
* @param globalCount Number of global hooks found
|
||||
* @param workspaceCount Number of workspace-specific hooks found
|
||||
*/
|
||||
public captureHookDiscovery(hookName: string, globalCount: number, workspaceCount: number) {
|
||||
if (!this.isCategoryEnabled("hooks")) {
|
||||
return
|
||||
}
|
||||
|
||||
this.capture({
|
||||
event: TelemetryService.EVENTS.HOOKS.DISCOVERY_COMPLETED,
|
||||
properties: {
|
||||
hookName,
|
||||
globalCount,
|
||||
workspaceCount,
|
||||
totalCount: globalCount + workspaceCount,
|
||||
timestamp: new Date().toISOString(),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely executes a telemetry call with error protection.
|
||||
*
|
||||
* Use for critical execution paths where telemetry errors could break functionality:
|
||||
* - Hook execution (during tool execution)
|
||||
* - Browser automation (during active sessions)
|
||||
* - Auth flows, task initialization
|
||||
* - MCP server operations
|
||||
*
|
||||
* Not needed for non-critical, fire-and-forget events:
|
||||
* - UI events (clicks, navigation)
|
||||
* - Post-completion events
|
||||
* - Background operations
|
||||
*
|
||||
* This wrapper protects against both pre-provider errors (parameter construction,
|
||||
* property access, calculations) and provider-level errors (network, API failures).
|
||||
*
|
||||
* @param telemetryFn The telemetry function to execute
|
||||
* @param context Optional context string for debugging (e.g., "HookFactory.exec")
|
||||
*
|
||||
* @example
|
||||
* telemetryService.safeCapture(
|
||||
* () => telemetryService.captureHookExecution(taskId, hookName, "started", {...}),
|
||||
* 'HookFactory.exec.started'
|
||||
* )
|
||||
*/
|
||||
public safeCapture(telemetryFn: () => void, context?: string): void {
|
||||
try {
|
||||
telemetryFn()
|
||||
} catch (error) {
|
||||
const contextStr = context ? ` [Context: ${context}]` : ""
|
||||
console.error(`[Telemetry] Failed to capture telemetry${contextStr}:`, error)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up resources when the service is disposed
|
||||
*/
|
||||
|
||||
@@ -3,9 +3,7 @@ import type { ITelemetryProvider, TelemetryProperties, TelemetrySettings } from
|
||||
import { TelemetryMetadata, TelemetryService } from "../TelemetryService"
|
||||
|
||||
class FakeProvider implements ITelemetryProvider {
|
||||
name(): string {
|
||||
return "FakeProvider"
|
||||
}
|
||||
readonly name = "FakeProvider"
|
||||
public counters: Array<{ name: string; value: number; attributes: TelemetryProperties; description?: string }> = []
|
||||
public histograms: Array<{ name: string; value: number; attributes: TelemetryProperties; description?: string }> = []
|
||||
public gauges = new Map<string, Map<string, { value: number; attributes: TelemetryProperties; description?: string }>>()
|
||||
|
||||
@@ -87,9 +87,9 @@ export interface ITelemetryProvider {
|
||||
getSettings(): TelemetrySettings
|
||||
|
||||
/**
|
||||
* Returns the name of the telemetry provider.
|
||||
* The name of the telemetry provider.
|
||||
*/
|
||||
name(): string
|
||||
readonly name: string
|
||||
|
||||
/**
|
||||
* Record a counter metric (cumulative value that only increases)
|
||||
|
||||
@@ -5,7 +5,7 @@ import { BatchLogRecordProcessor, LoggerProvider } from "@opentelemetry/sdk-logs
|
||||
import { MeterProvider } from "@opentelemetry/sdk-metrics"
|
||||
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from "@opentelemetry/semantic-conventions"
|
||||
import { ExtensionRegistryInfo } from "@/registry"
|
||||
import { getValidOpenTelemetryConfig, OpenTelemetryClientValidConfig } from "@/shared/services/config/otel-config"
|
||||
import { OpenTelemetryClientValidConfig } from "@/shared/services/config/otel-config"
|
||||
import {
|
||||
createConsoleLogExporter,
|
||||
createConsoleMetricReader,
|
||||
@@ -14,29 +14,12 @@ import {
|
||||
} from "./OpenTelemetryExporterFactory"
|
||||
|
||||
/**
|
||||
* Singleton provider for OpenTelemetry client instances.
|
||||
* OpenTelemetry client provider.
|
||||
* Manages meter and logger providers for telemetry collection.
|
||||
*/
|
||||
export class OpenTelemetryClientProvider {
|
||||
private static _instance: OpenTelemetryClientProvider | null = null
|
||||
|
||||
public static getInstance(): OpenTelemetryClientProvider {
|
||||
if (!OpenTelemetryClientProvider._instance) {
|
||||
OpenTelemetryClientProvider._instance = new OpenTelemetryClientProvider()
|
||||
}
|
||||
return OpenTelemetryClientProvider._instance
|
||||
}
|
||||
|
||||
public static getMeterProvider(): MeterProvider | null {
|
||||
return OpenTelemetryClientProvider.getInstance().meterProvider
|
||||
}
|
||||
|
||||
public static getLoggerProvider(): LoggerProvider | null {
|
||||
return OpenTelemetryClientProvider.getInstance().loggerProvider
|
||||
}
|
||||
|
||||
private readonly meterProvider: MeterProvider | null = null
|
||||
private readonly loggerProvider: LoggerProvider | null = null
|
||||
readonly meterProvider: MeterProvider | null = null
|
||||
readonly loggerProvider: LoggerProvider | null = null
|
||||
private readonly config: OpenTelemetryClientValidConfig | null
|
||||
|
||||
/**
|
||||
@@ -47,14 +30,8 @@ export class OpenTelemetryClientProvider {
|
||||
return process.env.TEL_DEBUG_DIAGNOSTICS === "true" || process.env.IS_DEV === "true"
|
||||
}
|
||||
|
||||
private constructor() {
|
||||
this.config = getValidOpenTelemetryConfig()
|
||||
|
||||
if (!this.config) {
|
||||
console.log("[OTEL DEBUG] OpenTelemetry is disabled or not configured")
|
||||
return
|
||||
}
|
||||
|
||||
constructor(config: OpenTelemetryClientValidConfig) {
|
||||
this.config = config
|
||||
const isDebugMode = this.isDebugEnabled()
|
||||
|
||||
// Only log endpoint in debug mode (security: avoid exposing infrastructure details)
|
||||
@@ -70,12 +47,16 @@ export class OpenTelemetryClientProvider {
|
||||
console.log(`[OTEL DEBUG] - Metric Export Interval: ${this.config.metricExportInterval || 60000}ms`)
|
||||
}
|
||||
|
||||
// Check for headers configuration (via environment variable)
|
||||
const hasHeaders = !!process.env.OTEL_EXPORTER_OTLP_HEADERS
|
||||
if (isDebugMode && hasHeaders) {
|
||||
// Check for headers configuration
|
||||
// This is only used for printing, only the config value should be passed down
|
||||
// so that the library can read and parse the env variable correclty if the config value is undefined
|
||||
const headers = config?.otlpHeaders || process.env.OTEL_EXPORTER_OTLP_HEADERS
|
||||
if (isDebugMode && headers) {
|
||||
const headerCount = config?.otlpHeaders
|
||||
? Object.keys(config.otlpHeaders).length
|
||||
: process.env.OTEL_EXPORTER_OTLP_HEADERS?.length
|
||||
// In debug mode, show that headers are configured and their total length
|
||||
const headerLength = process.env.OTEL_EXPORTER_OTLP_HEADERS!.length
|
||||
console.log(`[OTEL DEBUG] - OTLP Headers: configured (length: ${headerLength})`)
|
||||
console.log(`[OTEL DEBUG] - OTLP Headers: ${headerCount} headers configured`)
|
||||
console.log("[OTEL DEBUG] ================================================")
|
||||
}
|
||||
|
||||
@@ -119,9 +100,10 @@ export class OpenTelemetryClientProvider {
|
||||
const protocol = this.config!.otlpMetricsProtocol || this.config!.otlpProtocol || "grpc"
|
||||
const endpoint = this.config!.otlpMetricsEndpoint || this.config!.otlpEndpoint
|
||||
const insecure = this.config!.otlpInsecure || false
|
||||
const headers = this.config!.otlpHeaders
|
||||
|
||||
if (endpoint) {
|
||||
const reader = createOTLPMetricReader(protocol, endpoint, insecure, interval, timeout)
|
||||
const reader = createOTLPMetricReader(protocol, endpoint, insecure, interval, timeout, headers)
|
||||
if (reader) {
|
||||
readers.push(reader)
|
||||
console.log(`[OTEL] OTLP metrics reader created (${protocol}, interval: ${interval}ms)`)
|
||||
@@ -174,9 +156,10 @@ export class OpenTelemetryClientProvider {
|
||||
const protocol = this.config!.otlpLogsProtocol || this.config!.otlpProtocol || "grpc"
|
||||
const endpoint = this.config!.otlpLogsEndpoint || this.config!.otlpEndpoint
|
||||
const insecure = this.config!.otlpInsecure || false
|
||||
const headers = this.config!.otlpHeaders
|
||||
|
||||
if (endpoint) {
|
||||
exporter = createOTLPLogExporter(protocol, endpoint, insecure)
|
||||
exporter = createOTLPLogExporter(protocol, endpoint, insecure, headers)
|
||||
if (exporter) {
|
||||
console.log(`[OTEL] OTLP logs exporter created (${protocol})`)
|
||||
}
|
||||
|
||||
@@ -26,7 +26,12 @@ export function createConsoleLogExporter(): ConsoleLogRecordExporter {
|
||||
/**
|
||||
* Create an OTLP log exporter based on protocol
|
||||
*/
|
||||
export function createOTLPLogExporter(protocol: string, endpoint: string, insecure: boolean): LogRecordExporter | null {
|
||||
export function createOTLPLogExporter(
|
||||
protocol: string,
|
||||
endpoint: string,
|
||||
insecure: boolean,
|
||||
headers?: Record<string, string>,
|
||||
): LogRecordExporter | null {
|
||||
try {
|
||||
let exporter: any = null
|
||||
|
||||
@@ -38,17 +43,18 @@ export function createOTLPLogExporter(protocol: string, endpoint: string, insecu
|
||||
exporter = new OTLPLogExporterGRPC({
|
||||
url: grpcEndpoint,
|
||||
credentials: credentials,
|
||||
headers,
|
||||
})
|
||||
break
|
||||
}
|
||||
case "http/json": {
|
||||
const logsUrl = endpoint.endsWith("/v1/logs") ? endpoint : `${endpoint}/v1/logs`
|
||||
exporter = new OTLPLogExporterHTTP({ url: logsUrl })
|
||||
exporter = new OTLPLogExporterHTTP({ url: logsUrl, headers })
|
||||
break
|
||||
}
|
||||
case "http/protobuf": {
|
||||
const logsUrl = endpoint.endsWith("/v1/logs") ? endpoint : `${endpoint}/v1/logs`
|
||||
exporter = new OTLPLogExporterProto({ url: logsUrl })
|
||||
exporter = new OTLPLogExporterProto({ url: logsUrl, headers })
|
||||
break
|
||||
}
|
||||
default:
|
||||
@@ -89,6 +95,7 @@ export function createOTLPMetricReader(
|
||||
insecure: boolean,
|
||||
intervalMs: number,
|
||||
timeoutMs: number,
|
||||
headers?: Record<string, string>,
|
||||
): MetricReader | null {
|
||||
try {
|
||||
let exporter: any = null
|
||||
@@ -101,17 +108,18 @@ export function createOTLPMetricReader(
|
||||
exporter = new OTLPMetricExporterGRPC({
|
||||
url: grpcEndpoint,
|
||||
credentials: credentials,
|
||||
headers,
|
||||
})
|
||||
break
|
||||
}
|
||||
case "http/json": {
|
||||
const metricsUrl = endpoint.endsWith("/v1/metrics") ? endpoint : `${endpoint}/v1/metrics`
|
||||
exporter = new OTLPMetricExporterHTTP({ url: metricsUrl })
|
||||
exporter = new OTLPMetricExporterHTTP({ url: metricsUrl, headers })
|
||||
break
|
||||
}
|
||||
case "http/protobuf": {
|
||||
const metricsUrl = endpoint.endsWith("/v1/metrics") ? endpoint : `${endpoint}/v1/metrics`
|
||||
exporter = new OTLPMetricExporterProto({ url: metricsUrl })
|
||||
exporter = new OTLPMetricExporterProto({ url: metricsUrl, headers })
|
||||
break
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { Meter } from "@opentelemetry/api"
|
||||
import type { Logger as OTELLogger } from "@opentelemetry/api-logs"
|
||||
import * as vscode from "vscode"
|
||||
import { LoggerProvider } from "@opentelemetry/sdk-logs"
|
||||
import { MeterProvider } from "@opentelemetry/sdk-metrics"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { getErrorLevelFromString } from "@/services/error"
|
||||
import { getDistinctId, setDistinctId } from "@/services/logging/distinctId"
|
||||
import { Setting } from "@/shared/proto/index.host"
|
||||
import type { ClineAccountUserInfo } from "../../../auth/AuthService"
|
||||
import type { ITelemetryProvider, TelemetryProperties, TelemetrySettings } from "../ITelemetryProvider"
|
||||
import { OpenTelemetryClientProvider } from "./OpenTelemetryClientProvider"
|
||||
|
||||
/**
|
||||
* OpenTelemetry implementation of the telemetry provider interface.
|
||||
@@ -23,7 +24,17 @@ export class OpenTelemetryTelemetryProvider implements ITelemetryProvider {
|
||||
private gauges = new Map<string, ReturnType<Meter["createObservableGauge"]>>()
|
||||
private gaugeValues = new Map<string, Map<string, { value: number; attributes?: TelemetryProperties }>>()
|
||||
|
||||
constructor() {
|
||||
readonly name: string
|
||||
private bypassUserSettings: boolean
|
||||
|
||||
constructor(
|
||||
meterProvider: MeterProvider | null,
|
||||
loggerProvider: LoggerProvider | null,
|
||||
{ name, bypassUserSettings }: { name?: string; bypassUserSettings: boolean },
|
||||
) {
|
||||
this.name = name || "OpenTelemetryProvider"
|
||||
this.bypassUserSettings = bypassUserSettings
|
||||
|
||||
// Initialize telemetry settings
|
||||
this.telemetrySettings = {
|
||||
extensionEnabled: true,
|
||||
@@ -31,10 +42,6 @@ export class OpenTelemetryTelemetryProvider implements ITelemetryProvider {
|
||||
level: "all",
|
||||
}
|
||||
|
||||
// Get meter and logger from the shared client provider
|
||||
const meterProvider = OpenTelemetryClientProvider.getMeterProvider()
|
||||
const loggerProvider = OpenTelemetryClientProvider.getLoggerProvider()
|
||||
|
||||
if (meterProvider) {
|
||||
this.meter = meterProvider.getMeter("cline")
|
||||
}
|
||||
@@ -50,11 +57,12 @@ export class OpenTelemetryTelemetryProvider implements ITelemetryProvider {
|
||||
console.log(`[OTEL] Provider initialized - Logger: ${loggerReady}, Meter: ${meterReady}`)
|
||||
}
|
||||
}
|
||||
name(): string {
|
||||
return "OpenTelemetryProvider"
|
||||
}
|
||||
|
||||
public async initialize(): Promise<OpenTelemetryTelemetryProvider> {
|
||||
if (this.bypassUserSettings) {
|
||||
return this
|
||||
}
|
||||
|
||||
// Listen for host telemetry changes
|
||||
HostProvider.env.subscribeToTelemetrySettings(
|
||||
{},
|
||||
@@ -152,7 +160,7 @@ export class OpenTelemetryTelemetryProvider implements ITelemetryProvider {
|
||||
}
|
||||
|
||||
public isEnabled(): boolean {
|
||||
return this.telemetrySettings.extensionEnabled && this.telemetrySettings.hostEnabled
|
||||
return this.bypassUserSettings || (this.telemetrySettings.extensionEnabled && this.telemetrySettings.hostEnabled)
|
||||
}
|
||||
|
||||
public getSettings(): TelemetrySettings {
|
||||
@@ -296,8 +304,7 @@ export class OpenTelemetryTelemetryProvider implements ITelemetryProvider {
|
||||
if (hostSettings.isEnabled === Setting.DISABLED) {
|
||||
return "off"
|
||||
}
|
||||
const config = vscode.workspace.getConfiguration("telemetry")
|
||||
return config?.get<TelemetrySettings["level"]>("telemetryLevel") || "all"
|
||||
return getErrorLevelFromString(hostSettings.errorLevel)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { PostHog } from "posthog-node"
|
||||
import * as vscode from "vscode"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { getErrorLevelFromString } from "@/services/error"
|
||||
import { getDistinctId, setDistinctId } from "@/services/logging/distinctId"
|
||||
import { Setting } from "@/shared/proto/index.host"
|
||||
import { posthogConfig } from "../../../../shared/services/config/posthog-config"
|
||||
@@ -15,6 +15,8 @@ export class PostHogTelemetryProvider implements ITelemetryProvider {
|
||||
private telemetrySettings: TelemetrySettings
|
||||
private isSharedClient: boolean
|
||||
|
||||
readonly name = "PostHogTelemetryProvider"
|
||||
|
||||
constructor(sharedClient?: PostHog) {
|
||||
this.isSharedClient = !!sharedClient
|
||||
|
||||
@@ -59,9 +61,7 @@ export class PostHogTelemetryProvider implements ITelemetryProvider {
|
||||
this.telemetrySettings.level = await this.getTelemetryLevel()
|
||||
return this
|
||||
}
|
||||
name(): string {
|
||||
return "PostHogTelemetryProvider"
|
||||
}
|
||||
|
||||
public log(event: string, properties?: TelemetryProperties): void {
|
||||
if (!this.isEnabled() || this.telemetrySettings.level === "off") {
|
||||
return
|
||||
@@ -208,7 +208,6 @@ export class PostHogTelemetryProvider implements ITelemetryProvider {
|
||||
if (hostSettings.isEnabled === Setting.DISABLED) {
|
||||
return "off"
|
||||
}
|
||||
const config = vscode.workspace.getConfiguration("telemetry")
|
||||
return config?.get<TelemetrySettings["level"]>("telemetryLevel") || "all"
|
||||
return getErrorLevelFromString(hostSettings.errorLevel)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,10 @@ export interface BannerRules {
|
||||
providers?: string[]
|
||||
/** Target specific audience segment */
|
||||
audience?: BannerAudience[]
|
||||
/** Target team vs enterprise organizations */
|
||||
org_type?: "all" | "team_only" | "enterprise_only" | ""
|
||||
/** Minimum extension version required (e.g., "3.39.2") */
|
||||
min_extension_version?: string
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -106,6 +106,7 @@ export interface ExtensionState {
|
||||
subagentsEnabled?: boolean
|
||||
nativeToolCallSetting?: boolean
|
||||
enableParallelToolCalling?: boolean
|
||||
backgroundEditEnabled?: boolean
|
||||
}
|
||||
|
||||
export interface ClineMessage {
|
||||
|
||||
@@ -322,6 +322,7 @@ export const anthropicModels = {
|
||||
contextWindow: 200_000,
|
||||
supportsImages: true,
|
||||
supportsPromptCache: true,
|
||||
supportsReasoning: true,
|
||||
inputPrice: 3.0,
|
||||
outputPrice: 15.0,
|
||||
cacheWritesPrice: 3.75,
|
||||
@@ -332,6 +333,7 @@ export const anthropicModels = {
|
||||
contextWindow: 1_000_000,
|
||||
supportsImages: true,
|
||||
supportsPromptCache: true,
|
||||
supportsReasoning: true,
|
||||
inputPrice: 3.0,
|
||||
outputPrice: 15.0,
|
||||
cacheWritesPrice: 3.75,
|
||||
@@ -343,6 +345,7 @@ export const anthropicModels = {
|
||||
contextWindow: 200_000,
|
||||
supportsImages: true,
|
||||
supportsPromptCache: true,
|
||||
supportsReasoning: true,
|
||||
inputPrice: 1,
|
||||
outputPrice: 5.0,
|
||||
cacheWritesPrice: 1.25,
|
||||
@@ -353,6 +356,7 @@ export const anthropicModels = {
|
||||
contextWindow: 200_000,
|
||||
supportsImages: true,
|
||||
supportsPromptCache: true,
|
||||
supportsReasoning: true,
|
||||
inputPrice: 3.0,
|
||||
outputPrice: 15.0,
|
||||
cacheWritesPrice: 3.75,
|
||||
@@ -363,6 +367,7 @@ export const anthropicModels = {
|
||||
contextWindow: 1_000_000,
|
||||
supportsImages: true,
|
||||
supportsPromptCache: true,
|
||||
supportsReasoning: true,
|
||||
inputPrice: 3.0,
|
||||
outputPrice: 15.0,
|
||||
cacheWritesPrice: 3.75,
|
||||
@@ -374,6 +379,7 @@ export const anthropicModels = {
|
||||
contextWindow: 200_000,
|
||||
supportsImages: true,
|
||||
supportsPromptCache: true,
|
||||
supportsReasoning: true,
|
||||
inputPrice: 5.0,
|
||||
outputPrice: 25.0,
|
||||
cacheWritesPrice: 6.25,
|
||||
@@ -384,6 +390,7 @@ export const anthropicModels = {
|
||||
contextWindow: 200_000,
|
||||
supportsImages: true,
|
||||
supportsPromptCache: true,
|
||||
supportsReasoning: true,
|
||||
inputPrice: 15.0,
|
||||
outputPrice: 75.0,
|
||||
cacheWritesPrice: 18.75,
|
||||
@@ -394,6 +401,7 @@ export const anthropicModels = {
|
||||
contextWindow: 200_000,
|
||||
supportsImages: true,
|
||||
supportsPromptCache: true,
|
||||
supportsReasoning: true,
|
||||
inputPrice: 15.0,
|
||||
outputPrice: 75.0,
|
||||
cacheWritesPrice: 18.75,
|
||||
@@ -405,6 +413,7 @@ export const anthropicModels = {
|
||||
supportsImages: true,
|
||||
|
||||
supportsPromptCache: true,
|
||||
supportsReasoning: true,
|
||||
inputPrice: 3.0,
|
||||
outputPrice: 15.0,
|
||||
cacheWritesPrice: 3.75,
|
||||
@@ -900,6 +909,23 @@ export const vertexModels = {
|
||||
inputPrice: 2.0,
|
||||
outputPrice: 12.0,
|
||||
temperature: 1.0,
|
||||
supportsReasoning: true,
|
||||
thinkingConfig: {
|
||||
geminiThinkingLevel: "high",
|
||||
supportsThinkingLevel: true,
|
||||
},
|
||||
},
|
||||
"gemini-3-flash-preview": {
|
||||
maxTokens: 65536,
|
||||
contextWindow: 1_048_576,
|
||||
supportsImages: true,
|
||||
supportsPromptCache: true,
|
||||
supportsGlobalEndpoint: true,
|
||||
inputPrice: 0.5,
|
||||
outputPrice: 3.0,
|
||||
cacheWritesPrice: 0.05,
|
||||
temperature: 1.0,
|
||||
supportsReasoning: true,
|
||||
thinkingConfig: {
|
||||
geminiThinkingLevel: "high",
|
||||
supportsThinkingLevel: true,
|
||||
@@ -1302,6 +1328,35 @@ export const geminiModels = {
|
||||
},
|
||||
],
|
||||
},
|
||||
"gemini-3-flash-preview": {
|
||||
maxTokens: 65536,
|
||||
contextWindow: 1_048_576,
|
||||
supportsImages: true,
|
||||
supportsPromptCache: true,
|
||||
supportsGlobalEndpoint: true,
|
||||
inputPrice: 0.5,
|
||||
outputPrice: 3.0,
|
||||
cacheWritesPrice: 0.05,
|
||||
supportsReasoning: true,
|
||||
thinkingConfig: {
|
||||
geminiThinkingLevel: "low",
|
||||
supportsThinkingLevel: true,
|
||||
},
|
||||
tiers: [
|
||||
{
|
||||
contextWindow: 200000,
|
||||
inputPrice: 0.3,
|
||||
outputPrice: 2.5,
|
||||
cacheReadsPrice: 0.03,
|
||||
},
|
||||
{
|
||||
contextWindow: Infinity,
|
||||
inputPrice: 0.3,
|
||||
outputPrice: 2.5,
|
||||
cacheReadsPrice: 0.03,
|
||||
},
|
||||
],
|
||||
},
|
||||
"gemini-2.5-pro": {
|
||||
maxTokens: 65536,
|
||||
contextWindow: 1_048_576,
|
||||
@@ -1486,6 +1541,7 @@ export const openAiNativeModels = {
|
||||
cacheReadsPrice: 0.175,
|
||||
temperature: 1,
|
||||
systemRole: "developer",
|
||||
supportsReasoning: true,
|
||||
supportsReasoningEffort: true,
|
||||
},
|
||||
"gpt-5.1-2025-11-13": {
|
||||
@@ -1498,6 +1554,7 @@ export const openAiNativeModels = {
|
||||
cacheReadsPrice: 0.125,
|
||||
temperature: 1,
|
||||
systemRole: "developer",
|
||||
supportsReasoning: true,
|
||||
supportsReasoningEffort: true,
|
||||
},
|
||||
"gpt-5.1": {
|
||||
@@ -1510,6 +1567,7 @@ export const openAiNativeModels = {
|
||||
cacheReadsPrice: 0.125,
|
||||
temperature: 1,
|
||||
systemRole: "developer",
|
||||
supportsReasoning: true,
|
||||
supportsReasoningEffort: true,
|
||||
},
|
||||
"gpt-5.1-codex": {
|
||||
@@ -1523,6 +1581,7 @@ export const openAiNativeModels = {
|
||||
apiFormat: ApiFormat.OPENAI_RESPONSES,
|
||||
temperature: 1,
|
||||
systemRole: "developer",
|
||||
supportsReasoning: true,
|
||||
supportsReasoningEffort: true,
|
||||
},
|
||||
"gpt-5.1-chat-latest": {
|
||||
@@ -1535,6 +1594,7 @@ export const openAiNativeModels = {
|
||||
cacheReadsPrice: 0.125,
|
||||
temperature: 1,
|
||||
systemRole: "developer",
|
||||
supportsReasoning: true,
|
||||
supportsReasoningEffort: true,
|
||||
},
|
||||
"gpt-5-2025-08-07": {
|
||||
@@ -1547,6 +1607,7 @@ export const openAiNativeModels = {
|
||||
cacheReadsPrice: 0.125,
|
||||
temperature: 1,
|
||||
systemRole: "developer",
|
||||
supportsReasoning: true,
|
||||
supportsReasoningEffort: true,
|
||||
},
|
||||
"gpt-5-codex": {
|
||||
@@ -1560,6 +1621,7 @@ export const openAiNativeModels = {
|
||||
apiFormat: ApiFormat.OPENAI_RESPONSES,
|
||||
temperature: 1,
|
||||
systemRole: "developer",
|
||||
supportsReasoning: true,
|
||||
supportsReasoningEffort: true,
|
||||
},
|
||||
"gpt-5-mini-2025-08-07": {
|
||||
@@ -1572,6 +1634,7 @@ export const openAiNativeModels = {
|
||||
cacheReadsPrice: 0.025,
|
||||
temperature: 1,
|
||||
systemRole: "developer",
|
||||
supportsReasoning: true,
|
||||
supportsReasoningEffort: true,
|
||||
},
|
||||
"gpt-5-nano-2025-08-07": {
|
||||
@@ -1584,6 +1647,7 @@ export const openAiNativeModels = {
|
||||
cacheReadsPrice: 0.005,
|
||||
temperature: 1,
|
||||
systemRole: "developer",
|
||||
supportsReasoning: true,
|
||||
supportsReasoningEffort: true,
|
||||
},
|
||||
"gpt-5-chat-latest": {
|
||||
@@ -1596,6 +1660,7 @@ export const openAiNativeModels = {
|
||||
cacheReadsPrice: 0.125,
|
||||
temperature: 1,
|
||||
systemRole: "developer",
|
||||
supportsReasoning: true,
|
||||
supportsReasoningEffort: true,
|
||||
},
|
||||
o3: {
|
||||
@@ -1607,6 +1672,7 @@ export const openAiNativeModels = {
|
||||
outputPrice: 8.0,
|
||||
cacheReadsPrice: 0.5,
|
||||
systemRole: "developer",
|
||||
supportsReasoning: true,
|
||||
supportsReasoningEffort: true,
|
||||
supportsTools: false,
|
||||
},
|
||||
@@ -1619,6 +1685,7 @@ export const openAiNativeModels = {
|
||||
outputPrice: 4.4,
|
||||
cacheReadsPrice: 0.275,
|
||||
systemRole: "developer",
|
||||
supportsReasoning: true,
|
||||
supportsReasoningEffort: true,
|
||||
supportsTools: false,
|
||||
},
|
||||
@@ -1661,6 +1728,7 @@ export const openAiNativeModels = {
|
||||
outputPrice: 4.4,
|
||||
cacheReadsPrice: 0.55,
|
||||
systemRole: "developer",
|
||||
supportsReasoning: true,
|
||||
supportsReasoningEffort: true,
|
||||
supportsTools: false,
|
||||
},
|
||||
|
||||
@@ -115,9 +115,14 @@ export function convertClineStorageToAnthropicMessage(
|
||||
return { role, content }
|
||||
}
|
||||
|
||||
// Removes thinking block that has no signature (invalid thinking block that's incompatible with Anthropic API)
|
||||
const filteredContent = content.filter((b) => b.type !== "thinking" || !!b.signature)
|
||||
|
||||
// Handle array content - strip Cline-specific fields for non-reasoning_details providers
|
||||
const shouldCleanContent = !REASONING_DETAILS_PROVIDERS.includes(provider)
|
||||
const cleanedContent = shouldCleanContent ? content.map(cleanContentBlock) : (content as Anthropic.MessageParam["content"])
|
||||
const cleanedContent = shouldCleanContent
|
||||
? filteredContent.map(cleanContentBlock)
|
||||
: (filteredContent as Anthropic.MessageParam["content"])
|
||||
|
||||
return { role, content: cleanedContent }
|
||||
}
|
||||
@@ -131,21 +136,19 @@ export function cleanContentBlock(block: ClineContent): Anthropic.ContentBlock {
|
||||
"reasoning_details" in block ||
|
||||
"call_id" in block ||
|
||||
"summary" in block ||
|
||||
(block.type === "tool_use" && "signature" in block)
|
||||
(block.type !== "thinking" && "signature" in block)
|
||||
|
||||
if (!hasClineFields) {
|
||||
return block as Anthropic.ContentBlock
|
||||
}
|
||||
|
||||
// Remove Cline-specific fields (signature only for tool_use blocks)
|
||||
// Removes Cline-specific fields & the signature field that's added for Gemini.
|
||||
// biome-ignore lint/correctness/noUnusedVariables: intentional destructuring to remove properties
|
||||
const { reasoning_details, call_id, summary, ...rest } = block as any
|
||||
|
||||
// Remove signature only from tool_use blocks (used by Gemini)
|
||||
if (rest.type === "tool_use" && "signature" in rest) {
|
||||
// biome-ignore lint/correctness/noUnusedVariables: intentional destructuring to remove properties
|
||||
const { signature, ...cleanBlock } = rest
|
||||
return cleanBlock satisfies Anthropic.ContentBlock
|
||||
// Remove signature from non-thinking blocks that were added for Gemini
|
||||
if (block.type !== "thinking" && rest.signature) {
|
||||
rest.signature = undefined
|
||||
}
|
||||
|
||||
return rest satisfies Anthropic.ContentBlock
|
||||
|
||||
+3
-2
@@ -112,8 +112,9 @@ export const fetch: typeof globalThis.fetch = (() => {
|
||||
|
||||
let baseFetch: typeof globalThis.fetch = globalThis.fetch
|
||||
// Note: See esbuild.mjs, process.env.IS_STANDALONE is statically rewritten
|
||||
// 'true' in the JetBrains/CLI build.
|
||||
if (process.env.IS_STANDALONE) {
|
||||
// to "true" or "false" (as strings) in the JetBrains/CLI build.
|
||||
// We must use explicit string comparison because "false" is truthy in JS.
|
||||
if (process.env.IS_STANDALONE === "true") {
|
||||
// Configure undici with ProxyAgent
|
||||
const agent = new EnvHttpProxyAgent({})
|
||||
setGlobalDispatcher(agent)
|
||||
|
||||
@@ -331,6 +331,7 @@ describe("Remote Config Schema", () => {
|
||||
openTelemetryLogBatchSize: 512,
|
||||
openTelemetryLogBatchTimeout: 5000,
|
||||
openTelemetryLogMaxQueueSize: 2048,
|
||||
openTelemetryOtlpHeaders: { test: "string" },
|
||||
globalRules: [
|
||||
{
|
||||
alwaysEnabled: true,
|
||||
@@ -470,6 +471,7 @@ describe("Remote Config Schema", () => {
|
||||
expect(result.openTelemetryLogBatchSize).to.equal(512)
|
||||
expect(result.openTelemetryLogBatchTimeout).to.equal(5000)
|
||||
expect(result.openTelemetryLogMaxQueueSize).to.equal(2048)
|
||||
expect(result.openTelemetryOtlpHeaders).to.deep.equal({ test: "string" })
|
||||
|
||||
// Verify Global Instructions settings
|
||||
expect(result.globalRules).to.have.lengthOf(2)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { RemoteConfigFields } from "@/shared/storage/state-keys"
|
||||
|
||||
export interface OpenTelemetryClientConfig {
|
||||
/**
|
||||
* Whether telemetry is enabled via OTEL_TELEMETRY_ENABLED
|
||||
@@ -26,6 +28,11 @@ export interface OpenTelemetryClientConfig {
|
||||
*/
|
||||
otlpEndpoint?: string
|
||||
|
||||
/**
|
||||
* General OTLP headers
|
||||
*/
|
||||
otlpHeaders?: Record<string, string>
|
||||
|
||||
/**
|
||||
* Metrics-specific OTLP protocol
|
||||
*/
|
||||
@@ -90,6 +97,28 @@ const isTestEnv = process.env.E2E_TEST === "true" || process.env.IS_TEST === "tr
|
||||
*/
|
||||
let otelConfig: OpenTelemetryClientConfig | null = null
|
||||
|
||||
export function remoteConfigToOtelConfig(settings: Partial<RemoteConfigFields>): OpenTelemetryClientConfig {
|
||||
return {
|
||||
enabled: !!settings.openTelemetryEnabled,
|
||||
metricsExporter: settings.openTelemetryMetricsExporter,
|
||||
logsExporter: settings.openTelemetryLogsExporter,
|
||||
otlpProtocol: settings.openTelemetryOtlpProtocol,
|
||||
otlpEndpoint: settings.openTelemetryOtlpEndpoint,
|
||||
otlpHeaders: settings.openTelemetryOtlpHeaders,
|
||||
metricExportInterval: settings.openTelemetryMetricExportInterval,
|
||||
otlpInsecure: settings.openTelemetryOtlpInsecure,
|
||||
|
||||
otlpMetricsEndpoint: settings.openTelemetryOtlpMetricsEndpoint,
|
||||
otlpMetricsProtocol: settings.openTelemetryOtlpMetricsProtocol,
|
||||
otlpLogsEndpoint: settings.openTelemetryOtlpLogsEndpoint,
|
||||
otlpLogsProtocol: settings.openTelemetryOtlpLogsProtocol,
|
||||
|
||||
logBatchSize: settings.openTelemetryLogBatchSize,
|
||||
logBatchTimeout: settings.openTelemetryLogBatchTimeout,
|
||||
logMaxQueueSize: settings.openTelemetryLogMaxQueueSize,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets or creates the OpenTelemetry configuration from environment variables.
|
||||
* Configuration is cached after first access for performance.
|
||||
|
||||
@@ -27,8 +27,11 @@ export type GlobalStateAndSettings = GlobalState & Settings
|
||||
export interface RemoteConfigExtraFields {
|
||||
remoteConfiguredProviders: string[]
|
||||
allowedMCPServers: Array<{ id: string }>
|
||||
remoteMCPServers?: Array<{ name: string; url: string }>
|
||||
remoteGlobalRules?: GlobalInstructionsFile[]
|
||||
remoteGlobalWorkflows?: GlobalInstructionsFile[]
|
||||
blockPersonalRemoteMCPServers?: boolean
|
||||
openTelemetryOtlpHeaders: Record<string, string> | undefined
|
||||
}
|
||||
|
||||
export type RemoteConfigFields = GlobalStateAndSettings & RemoteConfigExtraFields
|
||||
@@ -127,8 +130,10 @@ export interface Settings {
|
||||
hooksEnabled: boolean
|
||||
subagentsEnabled: boolean
|
||||
enableParallelToolCalling: boolean
|
||||
hicapModelId: string | undefined
|
||||
backgroundEditEnabled: boolean
|
||||
|
||||
// Model-specific settings
|
||||
hicapModelId: string | undefined
|
||||
// Plan mode configurations
|
||||
planModeApiProvider: ApiProvider
|
||||
planModeApiModelId: string | undefined
|
||||
|
||||
@@ -0,0 +1,554 @@
|
||||
import { randomUUID } from "node:crypto"
|
||||
import * as path from "node:path"
|
||||
import { fileURLToPath } from "node:url"
|
||||
import {
|
||||
Agent,
|
||||
AgentSideConnection,
|
||||
CancelNotification,
|
||||
type ContentBlock,
|
||||
InitializeRequest,
|
||||
InitializeResponse,
|
||||
NewSessionRequest,
|
||||
NewSessionResponse,
|
||||
ndJsonStream,
|
||||
PromptRequest,
|
||||
PromptResponse,
|
||||
RequestError,
|
||||
type RequestPermissionResponse,
|
||||
type SessionNotification,
|
||||
SetSessionModeRequest,
|
||||
SetSessionModeResponse,
|
||||
} from "@agentclientprotocol/sdk"
|
||||
import type { ExtensionContext } from "vscode"
|
||||
import { initialize, tearDown } from "@/common"
|
||||
import { Controller } from "@/core/controller"
|
||||
import { getRequestRegistry } from "@/core/controller/grpc-handler"
|
||||
import { subscribeToState } from "@/core/controller/state/subscribeToState"
|
||||
import { subscribeToPartialMessage } from "@/core/controller/ui/subscribeToPartialMessage"
|
||||
import { AuthHandler } from "@/hosts/external/AuthHandler"
|
||||
import { ExternalCommentReviewController } from "@/hosts/external/ExternalCommentReviewController"
|
||||
import { ExternalDiffViewProvider } from "@/hosts/external/ExternalDiffviewProvider"
|
||||
import { ExternalWebviewProvider } from "@/hosts/external/ExternalWebviewProvider"
|
||||
import { ExternalHostBridgeClientManager } from "@/hosts/external/host-bridge-client-manager"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
import { StandaloneTerminalManager } from "@/integrations/terminal"
|
||||
import type { McpServerConfig } from "@/services/mcp/types"
|
||||
import type { ClineMessage, ExtensionState } from "@/shared/ExtensionMessage"
|
||||
import { EmptyRequest } from "@/shared/proto/cline/common"
|
||||
import { State } from "@/shared/proto/cline/state"
|
||||
import type { ClineMessage as ProtoClineMessage } from "@/shared/proto/cline/ui"
|
||||
import { convertProtoToClineMessage } from "@/shared/proto-conversions/cline-message"
|
||||
import { waitForHostBridgeReady } from "@/standalone/hostbridge-client"
|
||||
import { initializeContext } from "@/standalone/vscode-context"
|
||||
import packageJson from "../../../package.json"
|
||||
import {
|
||||
buildModeState,
|
||||
buildNotificationsForMessage,
|
||||
buildNotificationsForPartialMessage,
|
||||
buildPermissionToolCall,
|
||||
buildToolCallDetailsFromMessage,
|
||||
createAcpConversionState,
|
||||
isPermissionAskType,
|
||||
resolveClineModeId,
|
||||
shouldSkipStateMessage,
|
||||
} from "./convert"
|
||||
import { nodeToWebReadable, nodeToWebWritable } from "./stdio"
|
||||
|
||||
const PERMISSION_OPTIONS = [
|
||||
{ optionId: "allow", name: "Allow", kind: "allow_once" },
|
||||
{ optionId: "reject", name: "Reject", kind: "reject_once" },
|
||||
{ optionId: "allow_always", name: "Always Allow", kind: "allow_always" },
|
||||
]
|
||||
|
||||
type ClineAcpRuntime = {
|
||||
controller: Controller
|
||||
dispose: () => Promise<void>
|
||||
}
|
||||
|
||||
type SessionSubscriptions = {
|
||||
stateRequestId: string
|
||||
partialRequestId: string
|
||||
}
|
||||
|
||||
type ClineAcpSession = {
|
||||
sessionId: string
|
||||
controller: Controller
|
||||
conversionState: ReturnType<typeof createAcpConversionState>
|
||||
lastMessageCount: number
|
||||
lastModeId: "plan" | "act"
|
||||
awaitingUserInput: boolean
|
||||
pendingAsk?: ClineMessage
|
||||
permissionRequests: Set<number>
|
||||
promptInFlight: boolean
|
||||
cancelled: boolean
|
||||
subscriptions: SessionSubscriptions
|
||||
}
|
||||
|
||||
export class ClineAcpAgent implements Agent {
|
||||
private runtime?: ClineAcpRuntime
|
||||
private runtimePromise?: Promise<ClineAcpRuntime>
|
||||
private sessions = new Map<string, ClineAcpSession>()
|
||||
|
||||
constructor(private client: AgentSideConnection) {}
|
||||
|
||||
async initialize(request: InitializeRequest): Promise<InitializeResponse> {
|
||||
return {
|
||||
protocolVersion: 1,
|
||||
agentCapabilities: {
|
||||
promptCapabilities: {
|
||||
image: true,
|
||||
embeddedContext: true,
|
||||
audio: false,
|
||||
},
|
||||
mcpCapabilities: {
|
||||
http: true,
|
||||
sse: true,
|
||||
},
|
||||
sessionCapabilities: {},
|
||||
},
|
||||
agentInfo: {
|
||||
name: packageJson.name,
|
||||
title: "Cline",
|
||||
version: packageJson.version,
|
||||
},
|
||||
authMethods: [],
|
||||
_meta: request._meta ?? null,
|
||||
}
|
||||
}
|
||||
|
||||
async newSession(params: NewSessionRequest): Promise<NewSessionResponse> {
|
||||
const runtime = await this.ensureRuntime(params.cwd)
|
||||
|
||||
if (this.sessions.size > 0) {
|
||||
for (const sessionId of this.sessions.keys()) {
|
||||
await this.closeSession(sessionId)
|
||||
}
|
||||
}
|
||||
|
||||
await this.configureMcpServers(runtime.controller, params.mcpServers)
|
||||
|
||||
const sessionId = randomUUID()
|
||||
const initialMode = resolveClineModeId(runtime.controller.stateManager.getGlobalSettingsKey("mode"))
|
||||
const subscriptions = await this.attachSubscriptions(runtime.controller, sessionId)
|
||||
|
||||
this.sessions.set(sessionId, {
|
||||
sessionId,
|
||||
controller: runtime.controller,
|
||||
conversionState: createAcpConversionState(),
|
||||
lastMessageCount: 0,
|
||||
lastModeId: initialMode,
|
||||
awaitingUserInput: false,
|
||||
permissionRequests: new Set(),
|
||||
promptInFlight: false,
|
||||
cancelled: false,
|
||||
subscriptions,
|
||||
})
|
||||
|
||||
await this.warnIfCwdMismatch(params.cwd)
|
||||
|
||||
return {
|
||||
sessionId,
|
||||
modes: buildModeState(initialMode),
|
||||
}
|
||||
}
|
||||
|
||||
async prompt(params: PromptRequest): Promise<PromptResponse> {
|
||||
const session = this.getSession(params.sessionId)
|
||||
if (session.promptInFlight) {
|
||||
throw new Error("Prompt already in progress")
|
||||
}
|
||||
|
||||
session.promptInFlight = true
|
||||
session.cancelled = false
|
||||
|
||||
try {
|
||||
const { text, images, files } = extractPromptContent(params.prompt)
|
||||
const task = session.controller.task
|
||||
const isStreaming = task?.taskState.isStreaming || task?.taskState.isWaitingForFirstChunk
|
||||
|
||||
if (session.pendingAsk && task) {
|
||||
session.awaitingUserInput = false
|
||||
session.pendingAsk = undefined
|
||||
await task.handleWebviewAskResponse("messageResponse", text, images, files)
|
||||
} else if (!task || !isStreaming) {
|
||||
await session.controller.initTask(text, images, files)
|
||||
} else {
|
||||
throw new Error("Task is busy; wait for the current turn to finish")
|
||||
}
|
||||
|
||||
const stopReason = await this.waitForTurnCompletion(session)
|
||||
return { stopReason }
|
||||
} finally {
|
||||
session.promptInFlight = false
|
||||
}
|
||||
}
|
||||
|
||||
async cancel(params: CancelNotification): Promise<void> {
|
||||
const session = this.getSession(params.sessionId)
|
||||
session.cancelled = true
|
||||
await session.controller.cancelTask()
|
||||
}
|
||||
|
||||
async setSessionMode(params: SetSessionModeRequest): Promise<SetSessionModeResponse> {
|
||||
const session = this.getSession(params.sessionId)
|
||||
const modeId = params.modeId === "act" ? "act" : "plan"
|
||||
await session.controller.togglePlanActMode(modeId)
|
||||
session.lastModeId = modeId
|
||||
await this.client.sessionUpdate({
|
||||
sessionId: session.sessionId,
|
||||
update: {
|
||||
sessionUpdate: "current_mode_update",
|
||||
currentModeId: modeId,
|
||||
},
|
||||
})
|
||||
return {}
|
||||
}
|
||||
|
||||
private async ensureRuntime(cwd: string): Promise<ClineAcpRuntime> {
|
||||
if (this.runtime) {
|
||||
return this.runtime
|
||||
}
|
||||
if (!this.runtimePromise) {
|
||||
this.runtimePromise = this.createRuntime(cwd)
|
||||
}
|
||||
this.runtime = await this.runtimePromise
|
||||
return this.runtime
|
||||
}
|
||||
|
||||
private async createRuntime(cwd: string): Promise<ClineAcpRuntime> {
|
||||
process.chdir(path.dirname(fileURLToPath(import.meta.url)))
|
||||
await waitForHostBridgeReady()
|
||||
|
||||
const { extensionContext, DATA_DIR, EXTENSION_DIR } = initializeContext(undefined)
|
||||
this.setupHostProvider(extensionContext, EXTENSION_DIR, DATA_DIR)
|
||||
const webviewProvider = await initialize(extensionContext)
|
||||
AuthHandler.getInstance().setEnabled(true)
|
||||
|
||||
return {
|
||||
controller: webviewProvider.controller,
|
||||
dispose: async () => {
|
||||
await tearDown()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
private setupHostProvider(extensionContext: ExtensionContext, extensionDir: string, dataDir: string) {
|
||||
const createWebview = () => new ExternalWebviewProvider(extensionContext)
|
||||
const createDiffView = () => new ExternalDiffViewProvider()
|
||||
const createCommentReview = () => new ExternalCommentReviewController()
|
||||
const createTerminalManager = () => new StandaloneTerminalManager()
|
||||
const getCallbackUrl = async () => AuthHandler.getInstance().getCallbackUrl()
|
||||
const getBinaryLocation = async (name: string) => path.join(process.cwd(), name)
|
||||
|
||||
HostProvider.initialize(
|
||||
createWebview,
|
||||
createDiffView,
|
||||
createCommentReview,
|
||||
createTerminalManager,
|
||||
new ExternalHostBridgeClientManager(),
|
||||
(...args: unknown[]) => console.error(...args),
|
||||
getCallbackUrl,
|
||||
getBinaryLocation,
|
||||
extensionDir,
|
||||
dataDir,
|
||||
)
|
||||
}
|
||||
|
||||
private async configureMcpServers(controller: Controller, servers: NewSessionRequest["mcpServers"]) {
|
||||
if (!servers?.length) {
|
||||
return
|
||||
}
|
||||
const serverConfigs: Record<string, McpServerConfig> = {}
|
||||
for (const server of servers) {
|
||||
if ("type" in server && server.type && server.type !== "stdio") {
|
||||
const transportType = server.type === "http" ? "streamableHttp" : "sse"
|
||||
serverConfigs[server.name] = {
|
||||
type: transportType,
|
||||
url: server.url,
|
||||
headers: server.headers ? Object.fromEntries(server.headers.map((h) => [h.name, h.value])) : undefined,
|
||||
}
|
||||
} else {
|
||||
serverConfigs[server.name] = {
|
||||
type: "stdio",
|
||||
command: server.command,
|
||||
args: server.args,
|
||||
env: server.env ? Object.fromEntries(server.env.map((e) => [e.name, e.value])) : undefined,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await controller.mcpHub.updateServerConnectionsRPC(serverConfigs)
|
||||
}
|
||||
|
||||
private async warnIfCwdMismatch(cwd: string) {
|
||||
try {
|
||||
const workspacePaths = await HostProvider.workspace.getWorkspacePaths({})
|
||||
const primary = workspacePaths.paths[0]
|
||||
if (primary && path.resolve(primary) !== path.resolve(cwd)) {
|
||||
console.error(`[cline-acp] Warning: ACP session cwd (${cwd}) does not match host bridge workspace (${primary}).`)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("[cline-acp] Failed to check workspace paths:", error)
|
||||
}
|
||||
}
|
||||
|
||||
private async attachSubscriptions(controller: Controller, sessionId: string): Promise<SessionSubscriptions> {
|
||||
const stateRequestId = `cline-acp-state-${sessionId}`
|
||||
const partialRequestId = `cline-acp-partial-${sessionId}`
|
||||
|
||||
await subscribeToState(
|
||||
controller,
|
||||
EmptyRequest.create(),
|
||||
async (state: State) => {
|
||||
await this.handleStateUpdate(sessionId, state)
|
||||
},
|
||||
stateRequestId,
|
||||
)
|
||||
|
||||
await subscribeToPartialMessage(
|
||||
controller,
|
||||
EmptyRequest.create(),
|
||||
async (message) => {
|
||||
await this.handlePartialMessage(sessionId, message)
|
||||
},
|
||||
partialRequestId,
|
||||
)
|
||||
|
||||
return { stateRequestId, partialRequestId }
|
||||
}
|
||||
|
||||
private async handleStateUpdate(sessionId: string, state: State) {
|
||||
const session = this.sessions.get(sessionId)
|
||||
if (!session || !state.stateJson) {
|
||||
return
|
||||
}
|
||||
|
||||
let parsed: ExtensionState
|
||||
try {
|
||||
parsed = JSON.parse(state.stateJson) as ExtensionState
|
||||
} catch (error) {
|
||||
console.error("[cline-acp] Failed to parse state update:", error)
|
||||
return
|
||||
}
|
||||
|
||||
const modeId = resolveClineModeId(parsed.mode)
|
||||
if (modeId !== session.lastModeId) {
|
||||
session.lastModeId = modeId
|
||||
await this.client.sessionUpdate({
|
||||
sessionId,
|
||||
update: {
|
||||
sessionUpdate: "current_mode_update",
|
||||
currentModeId: modeId,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const messages = parsed.clineMessages ?? []
|
||||
if (messages.length <= session.lastMessageCount) {
|
||||
return
|
||||
}
|
||||
|
||||
const newMessages = messages.slice(session.lastMessageCount)
|
||||
session.lastMessageCount = messages.length
|
||||
|
||||
for (const message of newMessages) {
|
||||
if (shouldSkipStateMessage(message, session.conversionState)) {
|
||||
continue
|
||||
}
|
||||
await this.handleAskMessage(session, message)
|
||||
await this.sendNotifications(sessionId, buildNotificationsForMessage(message, sessionId, session.conversionState))
|
||||
}
|
||||
}
|
||||
|
||||
private async handlePartialMessage(sessionId: string, message: ProtoClineMessage) {
|
||||
const session = this.sessions.get(sessionId)
|
||||
if (!session) {
|
||||
return
|
||||
}
|
||||
const clineMessage = convertProtoToClineMessage(message)
|
||||
const notifications = buildNotificationsForPartialMessage(
|
||||
clineMessage,
|
||||
sessionId,
|
||||
session.conversionState,
|
||||
message.partial === false,
|
||||
)
|
||||
await this.sendNotifications(sessionId, notifications)
|
||||
}
|
||||
|
||||
private async handleAskMessage(session: ClineAcpSession, message: ClineMessage) {
|
||||
if (message.type !== "ask") {
|
||||
return
|
||||
}
|
||||
if (isPermissionAskType(message.ask)) {
|
||||
await this.handlePermissionRequest(session, message)
|
||||
return
|
||||
}
|
||||
session.awaitingUserInput = true
|
||||
session.pendingAsk = message
|
||||
}
|
||||
|
||||
private async handlePermissionRequest(session: ClineAcpSession, message: ClineMessage) {
|
||||
if (session.permissionRequests.has(message.ts)) {
|
||||
return
|
||||
}
|
||||
session.permissionRequests.add(message.ts)
|
||||
|
||||
const details =
|
||||
buildToolCallDetailsFromMessage(message, session.conversionState, {
|
||||
toolCallPrefix: "cline-permission",
|
||||
fallbackTitle: "Permission required",
|
||||
}) ??
|
||||
buildToolCallDetailsFromMessage(
|
||||
{ ...message, type: "say", say: "command", text: message.text },
|
||||
session.conversionState,
|
||||
{ toolCallPrefix: "cline-permission", fallbackTitle: "Permission required" },
|
||||
)
|
||||
|
||||
if (!details) {
|
||||
return
|
||||
}
|
||||
|
||||
let response: RequestPermissionResponse
|
||||
try {
|
||||
response = await this.client.requestPermission({
|
||||
sessionId: session.sessionId,
|
||||
toolCall: buildPermissionToolCall(details),
|
||||
options: PERMISSION_OPTIONS,
|
||||
})
|
||||
} catch (error) {
|
||||
console.error("[cline-acp] Permission request failed:", error)
|
||||
return
|
||||
}
|
||||
|
||||
if (response.outcome?.outcome === "cancelled" || session.cancelled) {
|
||||
session.cancelled = true
|
||||
await session.controller.cancelTask()
|
||||
return
|
||||
}
|
||||
|
||||
const approved =
|
||||
response.outcome?.outcome === "selected" &&
|
||||
(response.outcome.optionId === "allow" || response.outcome.optionId === "allow_always")
|
||||
|
||||
await session.controller.task?.handleWebviewAskResponse(approved ? "yesButtonClicked" : "noButtonClicked")
|
||||
}
|
||||
|
||||
private async waitForTurnCompletion(session: ClineAcpSession): Promise<PromptResponse["stopReason"]> {
|
||||
while (true) {
|
||||
if (session.cancelled) {
|
||||
return "cancelled"
|
||||
}
|
||||
|
||||
const task = session.controller.task
|
||||
if (!task) {
|
||||
return "end_turn"
|
||||
}
|
||||
|
||||
if (session.awaitingUserInput) {
|
||||
return "end_turn"
|
||||
}
|
||||
|
||||
if (!task.taskState.isStreaming && !task.taskState.isWaitingForFirstChunk) {
|
||||
return "end_turn"
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 100))
|
||||
}
|
||||
}
|
||||
|
||||
private async sendNotifications(sessionId: string, notifications: SessionNotification[]) {
|
||||
for (const notification of notifications) {
|
||||
try {
|
||||
await this.client.sessionUpdate(notification)
|
||||
} catch (error) {
|
||||
console.error(`[cline-acp] Failed to send session update for ${sessionId}:`, error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async closeSession(sessionId: string) {
|
||||
const session = this.sessions.get(sessionId)
|
||||
if (!session) {
|
||||
return
|
||||
}
|
||||
getRequestRegistry().cancelRequest(session.subscriptions.stateRequestId)
|
||||
getRequestRegistry().cancelRequest(session.subscriptions.partialRequestId)
|
||||
await session.controller.clearTask()
|
||||
this.sessions.delete(sessionId)
|
||||
}
|
||||
|
||||
private getSession(sessionId: string): ClineAcpSession {
|
||||
const session = this.sessions.get(sessionId)
|
||||
if (!session) {
|
||||
throw RequestError.invalidParams("Session not found")
|
||||
}
|
||||
return session
|
||||
}
|
||||
}
|
||||
|
||||
export function runAcp() {
|
||||
const input = nodeToWebWritable(process.stdout)
|
||||
const output = nodeToWebReadable(process.stdin)
|
||||
const stream = ndJsonStream(input, output)
|
||||
new AgentSideConnection((client) => new ClineAcpAgent(client), stream)
|
||||
}
|
||||
|
||||
function extractPromptContent(blocks: ContentBlock[]): { text: string; images: string[]; files: string[] } {
|
||||
const textParts: string[] = []
|
||||
const images: string[] = []
|
||||
const files: string[] = []
|
||||
const embeddedResources: string[] = []
|
||||
|
||||
for (const block of blocks ?? []) {
|
||||
switch (block.type) {
|
||||
case "text":
|
||||
textParts.push(block.text)
|
||||
break
|
||||
case "image":
|
||||
if (block.data && block.mimeType) {
|
||||
images.push(`data:${block.mimeType};base64,${block.data}`)
|
||||
}
|
||||
break
|
||||
case "resource":
|
||||
if ("text" in block.resource && block.resource.text) {
|
||||
embeddedResources.push(`<file_content path="${block.resource.uri}">\n${block.resource.text}\n</file_content>`)
|
||||
}
|
||||
break
|
||||
case "resource_link": {
|
||||
const filePath = resolveFilePath(block.uri)
|
||||
if (filePath) {
|
||||
files.push(filePath)
|
||||
} else {
|
||||
textParts.push(`Resource: ${block.uri}`)
|
||||
}
|
||||
break
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (embeddedResources.length > 0) {
|
||||
textParts.push(`Embedded resources:\n\n${embeddedResources.join("\n\n")}`)
|
||||
}
|
||||
|
||||
return {
|
||||
text: textParts.join("\n\n"),
|
||||
images,
|
||||
files,
|
||||
}
|
||||
}
|
||||
|
||||
function resolveFilePath(uri: string): string | undefined {
|
||||
try {
|
||||
const url = new URL(uri)
|
||||
if (url.protocol === "file:") {
|
||||
return fileURLToPath(url)
|
||||
}
|
||||
} catch (_error) {
|
||||
if (path.isAbsolute(uri)) {
|
||||
return uri
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user