Compare commits

..

1 Commits

Author SHA1 Message Date
Smit Barmase
b428f421d4 experiment with initial idea 2025-05-28 18:01:30 +05:30
594 changed files with 13596 additions and 39637 deletions

View File

@@ -1,8 +1,8 @@
name: Bug Report (AI) name: Bug Report (Agent Panel)
description: Zed Agent Panel Bugs description: Zed Agent Panel Bugs
type: "Bug" type: "Bug"
labels: ["ai"] labels: ["agent", "ai"]
title: "AI: <a short description of the AI Related bug>" title: "Agent Panel: <a short description of the Agent Panel bug>"
body: body:
- type: textarea - type: textarea
attributes: attributes:
@@ -14,19 +14,14 @@ body:
### Description ### Description
<!-- Describe with sufficient detail to reproduce from a clean Zed install. --> <!-- Describe with sufficient detail to reproduce from a clean Zed install. -->
<!-- Please include the LLM provider and model name you are using -->
Steps to trigger the problem: Steps to trigger the problem:
1. 1.
2. 2.
3. 3.
**Expected Behavior**: Actual Behavior:
**Actual Behavior**: Expected Behavior:
### Model Provider Details
- Provider: (Anthropic via ZedPro, Anthropic via API key, Copilot Chat, Mistral, OpenAI, etc)
- Model Name:
- Mode: (Agent Panel, Inline Assistant, Terminal Assistant or Text Threads)
- Other Details (MCPs, other settings, etc):
validations: validations:
required: true required: true

View File

@@ -0,0 +1,36 @@
name: Bug Report (Edit Predictions)
description: Zed Edit Predictions bugs
type: "Bug"
labels: ["ai", "inline completion", "zeta"]
title: "Edit Predictions: <a short description of the Edit Prediction bug>"
body:
- type: textarea
attributes:
label: Summary
description: Describe the bug with a one line summary, and provide detailed reproduction steps
value: |
<!-- Please insert a one line summary of the issue below -->
SUMMARY_SENTENCE_HERE
### Description
<!-- Describe with sufficient detail to reproduce from a clean Zed install. -->
<!-- Please include the LLM provider and model name you are using -->
Steps to trigger the problem:
1.
2.
3.
Actual Behavior:
Expected Behavior:
validations:
required: true
- type: textarea
id: environment
attributes:
label: Zed Version and System Specs
description: 'Open Zed, and in the command palette select "zed: copy system specs into clipboard"'
placeholder: |
Output of "zed: copy system specs into clipboard"
validations:
required: true

35
.github/ISSUE_TEMPLATE/03_bug_git.yml vendored Normal file
View File

@@ -0,0 +1,35 @@
name: Bug Report (Git)
description: Zed Git-Related Bugs
type: "Bug"
labels: ["git"]
title: "Git: <a short description of the Git bug>"
body:
- type: textarea
attributes:
label: Summary
description: Describe the bug with a one line summary, and provide detailed reproduction steps
value: |
<!-- Please insert a one line summary of the issue below -->
SUMMARY_SENTENCE_HERE
### Description
<!-- Describe with sufficient detail to reproduce from a clean Zed install. -->
Steps to trigger the problem:
1.
2.
3.
Actual Behavior:
Expected Behavior:
validations:
required: true
- type: textarea
id: environment
attributes:
label: Zed Version and System Specs
description: 'Open Zed, and in the command palette select "zed: copy system specs into clipboard"'
placeholder: |
Output of "zed: copy system specs into clipboard"
validations:
required: true

View File

@@ -19,8 +19,8 @@ body:
2. 2.
3. 3.
**Expected Behavior**: Actual Behavior:
**Actual Behavior**: Expected Behavior:
validations: validations:
required: true required: true

View File

@@ -18,16 +18,14 @@ body:
- Issues with insufficient detail may be summarily closed. - Issues with insufficient detail may be summarily closed.
--> -->
DESCRIPTION_HERE
Steps to reproduce: Steps to reproduce:
1. 1.
2. 2.
3. 3.
4. 4.
**Expected Behavior**: Expected Behavior:
**Actual Behavior**: Actual Behavior:
<!-- Before Submitting, did you: <!-- Before Submitting, did you:
1. Include settings.json, keymap.json, .editorconfig if relevant? 1. Include settings.json, keymap.json, .editorconfig if relevant?

View File

@@ -1,32 +0,0 @@
name: "Build docs"
description: "Build the docs"
runs:
using: "composite"
steps:
- name: Setup mdBook
uses: peaceiris/actions-mdbook@ee69d230fe19748b7abf22df32acaa93833fad08 # v2
with:
mdbook-version: "0.4.37"
- name: Cache dependencies
uses: swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2
with:
save-if: ${{ github.ref == 'refs/heads/main' }}
cache-provider: "buildjet"
- name: Install Linux dependencies
shell: bash -euxo pipefail {0}
run: ./script/linux
- name: Check for broken links
uses: lycheeverse/lychee-action@82202e5e9c2f4ef1a55a3d02563e1cb6041e5332 # v2.4.1
with:
args: --no-progress './docs/src/**/*'
fail: true
- name: Build book
shell: bash -euxo pipefail {0}
run: |
mkdir -p target/deploy
mdbook build ./docs --dest-dir=../target/deploy/docs/

View File

@@ -1,12 +1,6 @@
name: "Run tests" name: "Run tests"
description: "Runs the tests" description: "Runs the tests"
inputs:
use-xvfb:
description: "Whether to run tests with xvfb"
required: false
default: "false"
runs: runs:
using: "composite" using: "composite"
steps: steps:
@@ -26,9 +20,4 @@ runs:
- name: Run tests - name: Run tests
shell: bash -euxo pipefail {0} shell: bash -euxo pipefail {0}
run: | run: cargo nextest run --workspace --no-fail-fast
if [ "${{ inputs.use-xvfb }}" == "true" ]; then
xvfb-run --auto-servernum --server-args="-screen 0 1024x768x24 -nolisten tcp" cargo nextest run --workspace --no-fail-fast
else
cargo nextest run --workspace --no-fail-fast
fi

View File

@@ -73,7 +73,7 @@ jobs:
timeout-minutes: 60 timeout-minutes: 60
runs-on: runs-on:
- self-hosted - self-hosted
- macOS - test
steps: steps:
- name: Checkout repo - name: Checkout repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
@@ -183,9 +183,6 @@ jobs:
- name: Check for todo! and FIXME comments - name: Check for todo! and FIXME comments
run: script/check-todos run: script/check-todos
- name: Check modifier use in keymaps
run: script/check-keymaps
- name: Run style checks - name: Run style checks
uses: ./.github/actions/check_style uses: ./.github/actions/check_style
@@ -194,27 +191,6 @@ jobs:
with: with:
config: ./typos.toml config: ./typos.toml
check_docs:
timeout-minutes: 60
name: Check docs
needs: [job_spec]
if: github.repository_owner == 'zed-industries'
runs-on:
- buildjet-8vcpu-ubuntu-2204
steps:
- name: Checkout repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
clean: false
- name: Configure CI
run: |
mkdir -p ./../.cargo
cp ./.cargo/ci-config.toml ./../.cargo/config.toml
- name: Build docs
uses: ./.github/actions/build_docs
macos_tests: macos_tests:
timeout-minutes: 60 timeout-minutes: 60
name: (macOS) Run Clippy and tests name: (macOS) Run Clippy and tests
@@ -224,7 +200,7 @@ jobs:
needs.job_spec.outputs.run_tests == 'true' needs.job_spec.outputs.run_tests == 'true'
runs-on: runs-on:
- self-hosted - self-hosted
- macOS - test
steps: steps:
- name: Checkout repo - name: Checkout repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
@@ -319,8 +295,6 @@ jobs:
- name: Run tests - name: Run tests
uses: ./.github/actions/run_tests uses: ./.github/actions/run_tests
with:
use-xvfb: true
- name: Build other binaries and features - name: Build other binaries and features
run: | run: |
@@ -508,9 +482,7 @@ jobs:
- macos_tests - macos_tests
- windows_clippy - windows_clippy
- windows_tests - windows_tests
if: | if: always()
github.repository_owner == 'zed-industries' &&
always()
steps: steps:
- name: Check all tests passed - name: Check all tests passed
run: | run: |
@@ -741,66 +713,7 @@ jobs:
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
freebsd:
timeout-minutes: 60
runs-on: github-8vcpu-ubuntu-2404
if: |
startsWith(github.ref, 'refs/tags/v')
|| contains(github.event.pull_request.labels.*.name, 'run-bundling')
needs: [linux_tests]
name: Build Zed on FreeBSD
# env:
# MYTOKEN : ${{ secrets.MYTOKEN }}
# MYTOKEN2: "value2"
steps:
- uses: actions/checkout@v4
- name: Build FreeBSD remote-server
id: freebsd-build
uses: vmactions/freebsd-vm@c3ae29a132c8ef1924775414107a97cac042aad5 # v1.2.0
with:
# envs: "MYTOKEN MYTOKEN2"
usesh: true
release: 13.5
copyback: true
prepare: |
pkg install -y \
bash curl jq git \
rustup-init cmake-core llvm-devel-lite pkgconf protobuf # ibx11 alsa-lib rust-bindgen-cli
run: |
freebsd-version
sysctl hw.model
sysctl hw.ncpu
sysctl hw.physmem
sysctl hw.usermem
git config --global --add safe.directory /home/runner/work/zed/zed
rustup-init --profile minimal --default-toolchain none -y
. "$HOME/.cargo/env"
./script/bundle-freebsd
mkdir -p out/
mv "target/zed-remote-server-freebsd-x86_64.gz" out/
rm -rf target/
cargo clean
- name: Upload Artifact to Workflow - zed-remote-server (run-bundling)
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
if: contains(github.event.pull_request.labels.*.name, 'run-bundling')
with:
name: zed-remote-server-${{ github.event.pull_request.head.sha || github.sha }}-x86_64-unknown-freebsd.gz
path: out/zed-remote-server-freebsd-x86_64.gz
- name: Upload Artifacts to release
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # v1
if: ${{ !(contains(github.event.pull_request.labels.*.name, 'run-bundling')) }}
with:
draft: true
prerelease: ${{ env.RELEASE_CHANNEL == 'preview' }}
files: |
out/zed-remote-server-freebsd-x86_64.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
nix-build: nix-build:
name: Build with Nix
uses: ./.github/workflows/nix.yml uses: ./.github/workflows/nix.yml
if: github.repository_owner == 'zed-industries' && contains(github.event.pull_request.labels.*.name, 'run-nix') if: github.repository_owner == 'zed-industries' && contains(github.event.pull_request.labels.*.name, 'run-nix')
with: with:
@@ -813,12 +726,12 @@ jobs:
if: | if: |
startsWith(github.ref, 'refs/tags/v') startsWith(github.ref, 'refs/tags/v')
&& endsWith(github.ref, '-pre') && !endsWith(github.ref, '.0-pre') && endsWith(github.ref, '-pre') && !endsWith(github.ref, '.0-pre')
needs: [bundle-mac, bundle-linux-x86_x64, bundle-linux-aarch64, freebsd] needs: [bundle-mac, bundle-linux-x86_x64, bundle-linux-aarch64]
runs-on: runs-on:
- self-hosted - self-hosted
- bundle - bundle
steps: steps:
- name: gh release - name: gh release
run: gh release edit $GITHUB_REF_NAME --draft=false run: gh release edit $GITHUB_REF_NAME --draft=true
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -9,7 +9,7 @@ jobs:
deploy-docs: deploy-docs:
name: Deploy Docs name: Deploy Docs
if: github.repository_owner == 'zed-industries' if: github.repository_owner == 'zed-industries'
runs-on: buildjet-16vcpu-ubuntu-2204 runs-on: ubuntu-latest
steps: steps:
- name: Checkout repo - name: Checkout repo
@@ -17,11 +17,24 @@ jobs:
with: with:
clean: false clean: false
- name: Setup mdBook
uses: peaceiris/actions-mdbook@ee69d230fe19748b7abf22df32acaa93833fad08 # v2
with:
mdbook-version: "0.4.37"
- name: Set up default .cargo/config.toml - name: Set up default .cargo/config.toml
run: cp ./.cargo/collab-config.toml ./.cargo/config.toml run: cp ./.cargo/collab-config.toml ./.cargo/config.toml
- name: Build docs - name: Install system dependencies
uses: ./.github/actions/build_docs run: |
sudo apt-get update
sudo apt-get install libxkbcommon-dev libxkbcommon-x11-dev
- name: Build book
run: |
set -euo pipefail
mkdir -p target/deploy
mdbook build ./docs --dest-dir=../target/deploy/docs/
- name: Deploy Docs - name: Deploy Docs
uses: cloudflare/wrangler-action@da0e0dfe58b7a431659754fdf3f186c529afbe65 # v3 uses: cloudflare/wrangler-action@da0e0dfe58b7a431659754fdf3f186c529afbe65 # v3

View File

@@ -15,7 +15,7 @@ jobs:
if: github.repository_owner == 'zed-industries' if: github.repository_owner == 'zed-industries'
runs-on: runs-on:
- self-hosted - self-hosted
- macOS - test
steps: steps:
- name: Checkout repo - name: Checkout repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
@@ -33,7 +33,7 @@ jobs:
name: Run tests name: Run tests
runs-on: runs-on:
- self-hosted - self-hosted
- macOS - test
needs: style needs: style
steps: steps:
- name: Checkout repo - name: Checkout repo

View File

@@ -56,7 +56,6 @@ jobs:
name: zed name: zed
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}" authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
pushFilter: "${{ inputs.cachix-filter }}" pushFilter: "${{ inputs.cachix-filter }}"
cachixArgs: '-v'
- run: nix build .#${{ inputs.flake-output }} -L --accept-flake-config - run: nix build .#${{ inputs.flake-output }} -L --accept-flake-config

View File

@@ -20,7 +20,7 @@ jobs:
if: github.repository_owner == 'zed-industries' if: github.repository_owner == 'zed-industries'
runs-on: runs-on:
- self-hosted - self-hosted
- macOS - test
steps: steps:
- name: Checkout repo - name: Checkout repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
@@ -40,7 +40,7 @@ jobs:
if: github.repository_owner == 'zed-industries' if: github.repository_owner == 'zed-industries'
runs-on: runs-on:
- self-hosted - self-hosted
- macOS - test
needs: style needs: style
steps: steps:
- name: Checkout repo - name: Checkout repo
@@ -167,52 +167,7 @@ jobs:
- name: Upload Zed Nightly - name: Upload Zed Nightly
run: script/upload-nightly linux-targz run: script/upload-nightly linux-targz
freebsd:
timeout-minutes: 60
if: github.repository_owner == 'zed-industries'
runs-on: github-8vcpu-ubuntu-2404
needs: tests
env:
DIGITALOCEAN_SPACES_ACCESS_KEY: ${{ secrets.DIGITALOCEAN_SPACES_ACCESS_KEY }}
DIGITALOCEAN_SPACES_SECRET_KEY: ${{ secrets.DIGITALOCEAN_SPACES_SECRET_KEY }}
name: Build Zed on FreeBSD
# env:
# MYTOKEN : ${{ secrets.MYTOKEN }}
# MYTOKEN2: "value2"
steps:
- uses: actions/checkout@v4
- name: Build FreeBSD remote-server
id: freebsd-build
uses: vmactions/freebsd-vm@c3ae29a132c8ef1924775414107a97cac042aad5 # v1.2.0
with:
# envs: "MYTOKEN MYTOKEN2"
usesh: true
release: 13.5
copyback: true
prepare: |
pkg install -y \
bash curl jq git \
rustup-init cmake-core llvm-devel-lite pkgconf protobuf # ibx11 alsa-lib rust-bindgen-cli
run: |
freebsd-version
sysctl hw.model
sysctl hw.ncpu
sysctl hw.physmem
sysctl hw.usermem
git config --global --add safe.directory /home/runner/work/zed/zed
rustup-init --profile minimal --default-toolchain none -y
. "$HOME/.cargo/env"
./script/bundle-freebsd
mkdir -p out/
mv "target/zed-remote-server-freebsd-x86_64.gz" out/
rm -rf target/
cargo clean
- name: Upload Zed Nightly
run: script/upload-nightly freebsd
bundle-nix: bundle-nix:
name: Build and cache Nix package
needs: tests needs: tests
uses: ./.github/workflows/nix.yml uses: ./.github/workflows/nix.yml

View File

@@ -1,85 +0,0 @@
name: Run Unit Evals
on:
schedule:
# GitHub might drop jobs at busy times, so we choose a random time in the middle of the night.
- cron: "47 1 * * *"
workflow_dispatch:
concurrency:
# Allow only one workflow per any non-`main` branch.
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.ref_name == 'main' && github.sha || 'anysha' }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
RUST_BACKTRACE: 1
ZED_CLIENT_CHECKSUM_SEED: ${{ secrets.ZED_CLIENT_CHECKSUM_SEED }}
jobs:
unit_evals:
timeout-minutes: 60
name: Run unit evals
runs-on:
- buildjet-16vcpu-ubuntu-2204
steps:
- name: Add Rust to the PATH
run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH
- name: Checkout repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
clean: false
- name: Cache dependencies
uses: swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2
with:
save-if: ${{ github.ref == 'refs/heads/main' }}
cache-provider: "buildjet"
- name: Install Linux dependencies
run: ./script/linux
- name: Configure CI
run: |
mkdir -p ./../.cargo
cp ./.cargo/ci-config.toml ./../.cargo/config.toml
- name: Install Rust
shell: bash -euxo pipefail {0}
run: |
cargo install cargo-nextest --locked
- name: Install Node
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: "18"
- name: Limit target directory size
shell: bash -euxo pipefail {0}
run: script/clear-target-dir-if-larger-than 100
- name: Run unit evals
shell: bash -euxo pipefail {0}
run: cargo nextest run --workspace --no-fail-fast --features eval --no-capture -E 'test(::eval_)'
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
- name: Send failure message to Slack channel if needed
if: ${{ failure() }}
uses: slackapi/slack-github-action@b0fa283ad8fea605de13dc3f449259339835fc52
with:
method: chat.postMessage
token: ${{ secrets.SLACK_APP_ZED_UNIT_EVALS_BOT_TOKEN }}
payload: |
channel: C04UDRNNJFQ
text: "Unit Evals Failed: https://github.com/zed-industries/zed/actions/runs/${{ github.run_id }}"
# Even the Linux runner is not stateful, in theory there is no need to do this cleanup.
# But, to avoid potential issues in the future if we choose to use a stateful Linux runner and forget to add code
# to clean up the config file, Ive included the cleanup code here as a precaution.
# While its not strictly necessary at this moment, I believe its better to err on the side of caution.
- name: Clean CI config file
if: always()
run: rm -rf ./../.cargo

6
.rules
View File

@@ -5,12 +5,6 @@
* Prefer implementing functionality in existing files unless it is a new logical component. Avoid creating many small files. * Prefer implementing functionality in existing files unless it is a new logical component. Avoid creating many small files.
* Avoid using functions that panic like `unwrap()`, instead use mechanisms like `?` to propagate errors. * Avoid using functions that panic like `unwrap()`, instead use mechanisms like `?` to propagate errors.
* Be careful with operations like indexing which may panic if the indexes are out of bounds. * Be careful with operations like indexing which may panic if the indexes are out of bounds.
* Never silently discard errors with `let _ =` on fallible operations. Always handle errors appropriately:
- Propagate errors with `?` when the calling function should handle them
- Use `.log_err()` or similar when you need to ignore errors but want visibility
- Use explicit error handling with `match` or `if let Err(...)` when you need custom logic
- Example: avoid `let _ = client.request(...).await?;` - use `client.request(...).await?;` instead
* When implementing async operations that may fail, ensure errors propagate to the UI layer so users get meaningful feedback.
* Never create files with `mod.rs` paths - prefer `src/some_module.rs` instead of `src/some_module/mod.rs`. * Never create files with `mod.rs` paths - prefer `src/some_module.rs` instead of `src/some_module/mod.rs`.
# GPUI # GPUI

View File

@@ -2,11 +2,16 @@
{ {
"label": "Debug Zed (CodeLLDB)", "label": "Debug Zed (CodeLLDB)",
"adapter": "CodeLLDB", "adapter": "CodeLLDB",
"build": { "label": "Build Zed", "command": "cargo", "args": ["build"] } "program": "$ZED_WORKTREE_ROOT/target/debug/zed",
"request": "launch"
}, },
{ {
"label": "Debug Zed (GDB)", "label": "Debug Zed (GDB)",
"adapter": "GDB", "adapter": "GDB",
"build": { "label": "Build Zed", "command": "cargo", "args": ["build"] } "program": "$ZED_WORKTREE_ROOT/target/debug/zed",
"request": "launch",
"initialize_args": {
"stopAtBeginningOfMainSubprogram": true
}
} }
] ]

View File

@@ -47,7 +47,6 @@
"remove_trailing_whitespace_on_save": true, "remove_trailing_whitespace_on_save": true,
"ensure_final_newline_on_save": true, "ensure_final_newline_on_save": true,
"file_scan_exclusions": [ "file_scan_exclusions": [
"crates/assistant_tools/src/evals/fixtures",
"crates/eval/worktrees/", "crates/eval/worktrees/",
"crates/eval/repos/", "crates/eval/repos/",
"**/.git", "**/.git",

120
Cargo.lock generated
View File

@@ -59,7 +59,7 @@ dependencies = [
"assistant_slash_command", "assistant_slash_command",
"assistant_slash_commands", "assistant_slash_commands",
"assistant_tool", "assistant_tool",
"assistant_tools", "async-watch",
"audio", "audio",
"buffer_diff", "buffer_diff",
"chrono", "chrono",
@@ -99,7 +99,6 @@ dependencies = [
"paths", "paths",
"picker", "picker",
"postage", "postage",
"pretty_assertions",
"project", "project",
"prompt_store", "prompt_store",
"proto", "proto",
@@ -115,7 +114,6 @@ dependencies = [
"serde_json_lenient", "serde_json_lenient",
"settings", "settings",
"smol", "smol",
"sqlez",
"streaming_diff", "streaming_diff",
"telemetry", "telemetry",
"telemetry_events", "telemetry_events",
@@ -131,12 +129,10 @@ dependencies = [
"urlencoding", "urlencoding",
"util", "util",
"uuid", "uuid",
"watch",
"workspace", "workspace",
"workspace-hack", "workspace-hack",
"zed_actions", "zed_actions",
"zed_llm_client", "zed_llm_client",
"zstd",
] ]
[[package]] [[package]]
@@ -149,6 +145,7 @@ dependencies = [
"deepseek", "deepseek",
"fs", "fs",
"gpui", "gpui",
"indexmap",
"language_model", "language_model",
"lmstudio", "lmstudio",
"log", "log",
@@ -528,7 +525,6 @@ dependencies = [
"fuzzy", "fuzzy",
"gpui", "gpui",
"indexed_docs", "indexed_docs",
"indoc",
"language", "language",
"language_model", "language_model",
"languages", "languages",
@@ -563,7 +559,6 @@ dependencies = [
"workspace", "workspace",
"workspace-hack", "workspace-hack",
"zed_actions", "zed_actions",
"zed_llm_client",
] ]
[[package]] [[package]]
@@ -653,7 +648,6 @@ dependencies = [
"settings", "settings",
"text", "text",
"util", "util",
"watch",
"workspace", "workspace",
"workspace-hack", "workspace-hack",
"zlog", "zlog",
@@ -664,6 +658,7 @@ name = "assistant_tools"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"agent_settings", "agent_settings",
"aho-corasick",
"anyhow", "anyhow",
"assistant_tool", "assistant_tool",
"buffer_diff", "buffer_diff",
@@ -688,7 +683,6 @@ dependencies = [
"language_model", "language_model",
"language_models", "language_models",
"log", "log",
"lsp",
"markdown", "markdown",
"open", "open",
"paths", "paths",
@@ -705,7 +699,6 @@ dependencies = [
"serde_json", "serde_json",
"settings", "settings",
"smallvec", "smallvec",
"smol",
"streaming_diff", "streaming_diff",
"strsim", "strsim",
"task", "task",
@@ -717,7 +710,6 @@ dependencies = [
"ui", "ui",
"unindent", "unindent",
"util", "util",
"watch",
"web_search", "web_search",
"which 6.0.3", "which 6.0.3",
"workspace", "workspace",
@@ -1076,6 +1068,15 @@ dependencies = [
"tungstenite 0.26.2", "tungstenite 0.26.2",
] ]
[[package]]
name = "async-watch"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a078faf4e27c0c6cc0efb20e5da59dcccc04968ebf2801d8e0b2195124cdcdb2"
dependencies = [
"event-listener 2.5.3",
]
[[package]] [[package]]
name = "async_zip" name = "async_zip"
version = "0.0.17" version = "0.0.17"
@@ -2197,7 +2198,6 @@ dependencies = [
"editor", "editor",
"gpui", "gpui",
"itertools 0.14.0", "itertools 0.14.0",
"settings",
"theme", "theme",
"ui", "ui",
"workspace", "workspace",
@@ -2980,6 +2980,7 @@ dependencies = [
"anyhow", "anyhow",
"assistant_context_editor", "assistant_context_editor",
"assistant_slash_command", "assistant_slash_command",
"assistant_tool",
"async-stripe", "async-stripe",
"async-trait", "async-trait",
"async-tungstenite", "async-tungstenite",
@@ -3161,16 +3162,6 @@ dependencies = [
"memchr", "memchr",
] ]
[[package]]
name = "command-fds"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ec1052629a80c28594777d1252efc8a6b005d13f9edfd8c3fc0f44d5b32489a"
dependencies = [
"nix 0.30.1",
"thiserror 2.0.12",
]
[[package]] [[package]]
name = "command_palette" name = "command_palette"
version = "0.1.0" version = "0.1.0"
@@ -4063,7 +4054,6 @@ version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
"collections",
"dap", "dap",
"futures 0.3.31", "futures 0.3.31",
"gpui", "gpui",
@@ -4237,7 +4227,6 @@ dependencies = [
"futures 0.3.31", "futures 0.3.31",
"fuzzy", "fuzzy",
"gpui", "gpui",
"itertools 0.14.0",
"language", "language",
"log", "log",
"menu", "menu",
@@ -4547,8 +4536,6 @@ version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap", "clap",
"command_palette",
"gpui",
"mdbook", "mdbook",
"regex", "regex",
"serde", "serde",
@@ -4556,7 +4543,6 @@ dependencies = [
"settings", "settings",
"util", "util",
"workspace-hack", "workspace-hack",
"zed",
] ]
[[package]] [[package]]
@@ -4746,7 +4732,6 @@ dependencies = [
"tree-sitter-rust", "tree-sitter-rust",
"tree-sitter-typescript", "tree-sitter-typescript",
"ui", "ui",
"unicode-script",
"unicode-segmentation", "unicode-segmentation",
"unindent", "unindent",
"url", "url",
@@ -5017,6 +5002,7 @@ dependencies = [
"assistant_tool", "assistant_tool",
"assistant_tools", "assistant_tools",
"async-trait", "async-trait",
"async-watch",
"buffer_diff", "buffer_diff",
"chrono", "chrono",
"clap", "clap",
@@ -5058,9 +5044,7 @@ dependencies = [
"unindent", "unindent",
"util", "util",
"uuid", "uuid",
"watch",
"workspace-hack", "workspace-hack",
"zed_llm_client",
] ]
[[package]] [[package]]
@@ -6163,7 +6147,6 @@ dependencies = [
"workspace", "workspace",
"workspace-hack", "workspace-hack",
"zed_actions", "zed_actions",
"zed_llm_client",
"zlog", "zlog",
] ]
@@ -7081,7 +7064,6 @@ dependencies = [
"image", "image",
"inventory", "inventory",
"itertools 0.14.0", "itertools 0.14.0",
"libc",
"log", "log",
"lyon", "lyon",
"media", "media",
@@ -8743,6 +8725,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
"async-watch",
"clock", "clock",
"collections", "collections",
"ctor", "ctor",
@@ -8769,7 +8752,6 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"settings", "settings",
"shellexpand 2.1.2",
"smallvec", "smallvec",
"smol", "smol",
"streaming-iterator", "streaming-iterator",
@@ -8792,7 +8774,6 @@ dependencies = [
"unicase", "unicase",
"unindent", "unindent",
"util", "util",
"watch",
"workspace-hack", "workspace-hack",
"zlog", "zlog",
] ]
@@ -8872,7 +8853,6 @@ dependencies = [
"mistral", "mistral",
"ollama", "ollama",
"open_ai", "open_ai",
"open_router",
"partial-json-fixer", "partial-json-fixer",
"project", "project",
"proto", "proto",
@@ -8949,7 +8929,6 @@ dependencies = [
"async-compression", "async-compression",
"async-tar", "async-tar",
"async-trait", "async-trait",
"chrono",
"collections", "collections",
"dap", "dap",
"futures 0.3.31", "futures 0.3.31",
@@ -9003,7 +8982,6 @@ dependencies = [
"tree-sitter-yaml", "tree-sitter-yaml",
"unindent", "unindent",
"util", "util",
"which 6.0.3",
"workspace", "workspace",
"workspace-hack", "workspace-hack",
] ]
@@ -10142,18 +10120,6 @@ dependencies = [
"memoffset", "memoffset",
] ]
[[package]]
name = "nix"
version = "0.30.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6"
dependencies = [
"bitflags 2.9.0",
"cfg-if",
"cfg_aliases 0.2.1",
"libc",
]
[[package]] [[package]]
name = "node_runtime" name = "node_runtime"
version = "0.1.0" version = "0.1.0"
@@ -10163,6 +10129,7 @@ dependencies = [
"async-std", "async-std",
"async-tar", "async-tar",
"async-trait", "async-trait",
"async-watch",
"futures 0.3.31", "futures 0.3.31",
"http_client", "http_client",
"log", "log",
@@ -10172,7 +10139,6 @@ dependencies = [
"serde_json", "serde_json",
"smol", "smol",
"util", "util",
"watch",
"which 6.0.3", "which 6.0.3",
"workspace-hack", "workspace-hack",
] ]
@@ -10221,7 +10187,6 @@ dependencies = [
"util", "util",
"workspace", "workspace",
"workspace-hack", "workspace-hack",
"zed_actions",
] ]
[[package]] [[package]]
@@ -10730,19 +10695,6 @@ dependencies = [
"workspace-hack", "workspace-hack",
] ]
[[package]]
name = "open_router"
version = "0.1.0"
dependencies = [
"anyhow",
"futures 0.3.31",
"http_client",
"schemars",
"serde",
"serde_json",
"workspace-hack",
]
[[package]] [[package]]
name = "opener" name = "opener"
version = "0.7.2" version = "0.7.2"
@@ -13022,6 +12974,7 @@ dependencies = [
"askpass", "askpass",
"assistant_tool", "assistant_tool",
"assistant_tools", "assistant_tools",
"async-watch",
"backtrace", "backtrace",
"cargo_toml", "cargo_toml",
"chrono", "chrono",
@@ -13068,7 +13021,6 @@ dependencies = [
"toml 0.8.20", "toml 0.8.20",
"unindent", "unindent",
"util", "util",
"watch",
"worktree", "worktree",
"zlog", "zlog",
] ]
@@ -15629,7 +15581,6 @@ dependencies = [
"futures 0.3.31", "futures 0.3.31",
"gpui", "gpui",
"hex", "hex",
"log",
"parking_lot", "parking_lot",
"pretty_assertions", "pretty_assertions",
"proto", "proto",
@@ -15748,7 +15699,6 @@ dependencies = [
"task", "task",
"theme", "theme",
"thiserror 2.0.12", "thiserror 2.0.12",
"url",
"util", "util",
"windows 0.61.1", "windows 0.61.1",
"workspace-hack", "workspace-hack",
@@ -16530,9 +16480,9 @@ dependencies = [
[[package]] [[package]]
name = "tree-sitter" name = "tree-sitter"
version = "0.25.6" version = "0.25.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7cf18d43cbf0bfca51f657132cc616a5097edc4424d538bae6fa60142eaf9f0" checksum = "b9ac5ea5e7f2f1700842ec071401010b9c59bf735295f6e9fa079c3dc035b167"
dependencies = [ dependencies = [
"cc", "cc",
"regex", "regex",
@@ -16545,9 +16495,9 @@ dependencies = [
[[package]] [[package]]
name = "tree-sitter-bash" name = "tree-sitter-bash"
version = "0.25.0" version = "0.23.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "871b0606e667e98a1237ebdc1b0d7056e0aebfdc3141d12b399865d4cb6ed8a6" checksum = "329a4d48623ac337d42b1df84e81a1c9dbb2946907c102ca72db158c1964a52e"
dependencies = [ dependencies = [
"cc", "cc",
"tree-sitter-language", "tree-sitter-language",
@@ -16707,8 +16657,6 @@ dependencies = [
[[package]] [[package]]
name = "tree-sitter-python" name = "tree-sitter-python"
version = "0.23.6" version = "0.23.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d065aaa27f3aaceaf60c1f0e0ac09e1cb9eb8ed28e7bcdaa52129cffc7f4b04"
dependencies = [ dependencies = [
"cc", "cc",
"tree-sitter-language", "tree-sitter-language",
@@ -17145,14 +17093,12 @@ dependencies = [
"async-fs", "async-fs",
"async_zip", "async_zip",
"collections", "collections",
"command-fds",
"dirs 4.0.0", "dirs 4.0.0",
"dunce", "dunce",
"futures 0.3.31", "futures 0.3.31",
"futures-lite 1.13.0", "futures-lite 1.13.0",
"git2", "git2",
"globset", "globset",
"indoc",
"itertools 0.14.0", "itertools 0.14.0",
"libc", "libc",
"log", "log",
@@ -17167,6 +17113,8 @@ dependencies = [
"tempfile", "tempfile",
"tendril", "tendril",
"unicase", "unicase",
"unicode-script",
"unicode-segmentation",
"util_macros", "util_macros",
"walkdir", "walkdir",
"workspace-hack", "workspace-hack",
@@ -17931,19 +17879,6 @@ dependencies = [
"leb128", "leb128",
] ]
[[package]]
name = "watch"
version = "0.1.0"
dependencies = [
"ctor",
"futures 0.3.31",
"gpui",
"parking_lot",
"rand 0.8.5",
"workspace-hack",
"zlog",
]
[[package]] [[package]]
name = "wayland-backend" name = "wayland-backend"
version = "0.3.8" version = "0.3.8"
@@ -19743,7 +19678,7 @@ dependencies = [
[[package]] [[package]]
name = "zed" name = "zed"
version = "0.191.0" version = "0.189.0"
dependencies = [ dependencies = [
"activity_indicator", "activity_indicator",
"agent", "agent",
@@ -19755,6 +19690,7 @@ dependencies = [
"assistant_context_editor", "assistant_context_editor",
"assistant_tool", "assistant_tool",
"assistant_tools", "assistant_tools",
"async-watch",
"audio", "audio",
"auto_update", "auto_update",
"auto_update_ui", "auto_update_ui",
@@ -19861,6 +19797,7 @@ dependencies = [
"title_bar", "title_bar",
"toolchain_selector", "toolchain_selector",
"tree-sitter-md", "tree-sitter-md",
"tree-sitter-python",
"tree-sitter-rust", "tree-sitter-rust",
"ui", "ui",
"ui_input", "ui_input",
@@ -19871,7 +19808,6 @@ dependencies = [
"uuid", "uuid",
"vim", "vim",
"vim_mode_setting", "vim_mode_setting",
"watch",
"web_search", "web_search",
"web_search_providers", "web_search_providers",
"welcome", "welcome",
@@ -19939,9 +19875,9 @@ dependencies = [
[[package]] [[package]]
name = "zed_llm_client" name = "zed_llm_client"
version = "0.8.4" version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de7d9523255f4e00ee3d0918e5407bd252d798a4a8e71f6d37f23317a1588203" checksum = "22a8b9575b215536ed8ad254ba07171e4e13bd029eda3b54cca4b184d2768050"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"serde", "serde",

View File

@@ -100,7 +100,6 @@ members = [
"crates/notifications", "crates/notifications",
"crates/ollama", "crates/ollama",
"crates/open_ai", "crates/open_ai",
"crates/open_router",
"crates/outline", "crates/outline",
"crates/outline_panel", "crates/outline_panel",
"crates/panel", "crates/panel",
@@ -165,7 +164,6 @@ members = [
"crates/util_macros", "crates/util_macros",
"crates/vim", "crates/vim",
"crates/vim_mode_setting", "crates/vim_mode_setting",
"crates/watch",
"crates/web_search", "crates/web_search",
"crates/web_search_providers", "crates/web_search_providers",
"crates/welcome", "crates/welcome",
@@ -309,7 +307,6 @@ node_runtime = { path = "crates/node_runtime" }
notifications = { path = "crates/notifications" } notifications = { path = "crates/notifications" }
ollama = { path = "crates/ollama" } ollama = { path = "crates/ollama" }
open_ai = { path = "crates/open_ai" } open_ai = { path = "crates/open_ai" }
open_router = { path = "crates/open_router", features = ["schemars"] }
outline = { path = "crates/outline" } outline = { path = "crates/outline" }
outline_panel = { path = "crates/outline_panel" } outline_panel = { path = "crates/outline_panel" }
panel = { path = "crates/panel" } panel = { path = "crates/panel" }
@@ -374,7 +371,6 @@ util = { path = "crates/util" }
util_macros = { path = "crates/util_macros" } util_macros = { path = "crates/util_macros" }
vim = { path = "crates/vim" } vim = { path = "crates/vim" }
vim_mode_setting = { path = "crates/vim_mode_setting" } vim_mode_setting = { path = "crates/vim_mode_setting" }
watch = { path = "crates/watch" }
web_search = { path = "crates/web_search" } web_search = { path = "crates/web_search" }
web_search_providers = { path = "crates/web_search_providers" } web_search_providers = { path = "crates/web_search_providers" }
welcome = { path = "crates/welcome" } welcome = { path = "crates/welcome" }
@@ -405,6 +401,7 @@ async-recursion = "1.0.0"
async-tar = "0.5.0" async-tar = "0.5.0"
async-trait = "0.1" async-trait = "0.1"
async-tungstenite = "0.29.1" async-tungstenite = "0.29.1"
async-watch = "0.3.1"
async_zip = { version = "0.0.17", features = ["deflate", "deflate64"] } async_zip = { version = "0.0.17", features = ["deflate", "deflate64"] }
aws-config = { version = "1.6.1", features = ["behavior-version-latest"] } aws-config = { version = "1.6.1", features = ["behavior-version-latest"] }
aws-credential-types = { version = "1.2.2", features = [ aws-credential-types = { version = "1.2.2", features = [
@@ -575,8 +572,8 @@ tokio = { version = "1" }
tokio-tungstenite = { version = "0.26", features = ["__rustls-tls"] } tokio-tungstenite = { version = "0.26", features = ["__rustls-tls"] }
toml = "0.8" toml = "0.8"
tower-http = "0.4.4" tower-http = "0.4.4"
tree-sitter = { version = "0.25.6", features = ["wasm"] } tree-sitter = { version = "0.25.3", features = ["wasm"] }
tree-sitter-bash = "0.25.0" tree-sitter-bash = "0.23"
tree-sitter-c = "0.23" tree-sitter-c = "0.23"
tree-sitter-cpp = "0.23" tree-sitter-cpp = "0.23"
tree-sitter-css = "0.23" tree-sitter-css = "0.23"
@@ -592,7 +589,7 @@ tree-sitter-html = "0.23"
tree-sitter-jsdoc = "0.23" tree-sitter-jsdoc = "0.23"
tree-sitter-json = "0.24" tree-sitter-json = "0.24"
tree-sitter-md = { git = "https://github.com/tree-sitter-grammars/tree-sitter-markdown", rev = "9a23c1a96c0513d8fc6520972beedd419a973539" } tree-sitter-md = { git = "https://github.com/tree-sitter-grammars/tree-sitter-markdown", rev = "9a23c1a96c0513d8fc6520972beedd419a973539" }
tree-sitter-python = "0.23" tree-sitter-python = { path = "../repos/tree-sitter-python"}
tree-sitter-regex = "0.24" tree-sitter-regex = "0.24"
tree-sitter-ruby = "0.23" tree-sitter-ruby = "0.23"
tree-sitter-rust = "0.24" tree-sitter-rust = "0.24"
@@ -620,7 +617,7 @@ wasmtime = { version = "29", default-features = false, features = [
wasmtime-wasi = "29" wasmtime-wasi = "29"
which = "6.0.0" which = "6.0.0"
workspace-hack = "0.1.0" workspace-hack = "0.1.0"
zed_llm_client = "0.8.4" zed_llm_client = "0.8.3"
zstd = "0.11" zstd = "0.11"
[workspace.dependencies.async-stripe] [workspace.dependencies.async-stripe]

View File

@@ -1,8 +0,0 @@
<svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fill="currentColor" stroke="currentColor">
<g clip-path="url(#clip0_205_3)">
<path d="M0.094 7.78c0.469 0 2.281 -0.405 3.219 -0.936s0.938 -0.531 2.875 -1.906c2.453 -1.741 4.188 -1.158 7.031 -1.158" stroke-width="2.8125" />
<path d="m15.969 3.797 -4.805 2.774V1.023z" />
<path d="M0 7.781c0.469 0 2.281 0.405 3.219 0.936s0.938 0.531 2.875 1.906C8.547 12.364 10.281 11.781 13.125 11.781" stroke-width="2.8125" />
<path d="m15.875 11.764 -4.805 -2.774v5.548z" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 575 B

View File

@@ -1,4 +1,5 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M11 13H10.4C9.76346 13 9.15302 12.7893 8.70296 12.4142C8.25284 12.0391 8 11.5304 8 11V5C8 4.46957 8.25284 3.96086 8.70296 3.58579C9.15302 3.21071 9.76346 3 10.4 3H11" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> <path d="M17 20H16C14.9391 20 13.9217 19.6629 13.1716 19.0627C12.4214 18.4626 12 17.6487 12 16.8V7.2C12 6.35131 12.4214 5.53737 13.1716 4.93726C13.9217 4.33714 14.9391 4 16 4H17" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M5 13H5.6C6.23654 13 6.84698 12.7893 7.29704 12.4142C7.74716 12.0391 8 11.5304 8 11V5C8 4.46957 7.74716 3.96086 7.29704 3.58579C6.84698 3.21071 6.23654 3 5.6 3H5" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> <path d="M7 20H8C9.06087 20 10.0783 19.5786 10.8284 18.8284C11.5786 18.0783 12 17.0609 12 16V15" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M7 4H8C9.06087 4 10.0783 4.42143 10.8284 5.17157C11.5786 5.92172 12 6.93913 12 8V9" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 617 B

After

Width:  |  Height:  |  Size: 715 B

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-list-todo-icon lucide-list-todo"><rect x="3" y="5" width="6" height="6" rx="1"/><path d="m3 17 2 2 4-4"/><path d="M13 6h8"/><path d="M13 12h8"/><path d="M13 18h8"/></svg>

Before

Width:  |  Height:  |  Size: 373 B

View File

@@ -1,3 +0,0 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M4 3L13 8L4 13V3Z" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

Before

Width:  |  Height:  |  Size: 214 B

View File

@@ -1,8 +0,0 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M4 12C2.35977 11.85 1 10.575 1 9" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M1.00875 15.2C1.00875 13.625 0.683456 12.275 4.00001 12.2" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M7 9C7 10.575 5.62857 11.85 4 12" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M4 12.2C6.98117 12.2 7 13.625 7 15.2" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
<rect x="2.5" y="9" width="3" height="6" rx="1.5" fill="black"/>
<path d="M9 10L13 8L4 3V7.5" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

Before

Width:  |  Height:  |  Size: 813 B

View File

@@ -1,8 +1,3 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg width="17" height="17" viewBox="0 0 17 17" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2 5H4" stroke="black" stroke-width="1.5" stroke-linecap="round"/> <path fill-rule="evenodd" clip-rule="evenodd" d="M6.36667 3.79167C5.53364 3.79167 4.85833 4.46697 4.85833 5.3C4.85833 6.13303 5.53364 6.80833 6.36667 6.80833C7.1997 6.80833 7.875 6.13303 7.875 5.3C7.875 4.46697 7.1997 3.79167 6.36667 3.79167ZM2.1 5.925H3.67944C3.9626 7.14732 5.05824 8.05833 6.36667 8.05833C7.67509 8.05833 8.77073 7.14732 9.05389 5.925H14.9C15.2452 5.925 15.525 5.64518 15.525 5.3C15.525 4.95482 15.2452 4.675 14.9 4.675H9.05389C8.77073 3.45268 7.67509 2.54167 6.36667 2.54167C5.05824 2.54167 3.9626 3.45268 3.67944 4.675H2.1C1.75482 4.675 1.475 4.95482 1.475 5.3C1.475 5.64518 1.75482 5.925 2.1 5.925ZM13.3206 12.325C13.0374 13.5473 11.9418 14.4583 10.6333 14.4583C9.32491 14.4583 8.22927 13.5473 7.94611 12.325H2.1C1.75482 12.325 1.475 12.0452 1.475 11.7C1.475 11.3548 1.75482 11.075 2.1 11.075H7.94611C8.22927 9.85268 9.32491 8.94167 10.6333 8.94167C11.9418 8.94167 13.0374 9.85268 13.3206 11.075H14.9C15.2452 11.075 15.525 11.3548 15.525 11.7C15.525 12.0452 15.2452 12.325 14.9 12.325H13.3206ZM9.125 11.7C9.125 10.867 9.8003 10.1917 10.6333 10.1917C11.4664 10.1917 12.1417 10.867 12.1417 11.7C12.1417 12.533 11.4664 13.2083 10.6333 13.2083C9.8003 13.2083 9.125 12.533 9.125 11.7Z" fill="black"/>
<path d="M8 5L14 5" stroke="black" stroke-width="1.5" stroke-linecap="round"/>
<path d="M12 11L14 11" stroke="black" stroke-width="1.5" stroke-linecap="round"/>
<path d="M2 11H8" stroke="black" stroke-width="1.5" stroke-linecap="round"/>
<circle cx="6" cy="5" r="2" fill="black" fill-opacity="0.1" stroke="black" stroke-width="1.5" stroke-linecap="round"/>
<circle cx="10" cy="11" r="2" fill="black" fill-opacity="0.1" stroke="black" stroke-width="1.5" stroke-linecap="round"/>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 657 B

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@@ -1,3 +1 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M6.97942 1.25171L6.9585 1.30199L5.58662 4.60039C5.54342 4.70426 5.44573 4.77523 5.3336 4.78422L1.7727 5.0697L1.71841 5.07405L1.38687 5.10063L1.08608 5.12475C0.820085 5.14607 0.712228 5.47802 0.914889 5.65162L1.14406 5.84793L1.39666 6.06431L1.43802 6.09974L4.15105 8.42374C4.23648 8.49692 4.2738 8.61176 4.24769 8.72118L3.41882 12.196L3.40618 12.249L3.32901 12.5725L3.25899 12.866C3.19708 13.1256 3.47945 13.3308 3.70718 13.1917L3.9647 13.0344L4.24854 12.861L4.29502 12.8326L7.34365 10.9705C7.43965 10.9119 7.5604 10.9119 7.6564 10.9705L10.705 12.8326L10.7515 12.861L11.0354 13.0344L11.2929 13.1917C11.5206 13.3308 11.803 13.1256 11.7411 12.866L11.671 12.5725L11.5939 12.249L11.5812 12.196L10.7524 8.72118C10.7263 8.61176 10.7636 8.49692 10.849 8.42374L13.562 6.09974L13.6034 6.06431L13.856 5.84793L14.0852 5.65162C14.2878 5.47802 14.18 5.14607 13.914 5.12475L13.6132 5.10063L13.2816 5.07405L13.2274 5.0697L9.66645 4.78422C9.55432 4.77523 9.45663 4.70426 9.41343 4.60039L8.04155 1.30199L8.02064 1.25171L7.89291 0.944609L7.77702 0.665992C7.67454 0.419604 7.32551 0.419604 7.22303 0.665992L7.10715 0.944609L6.97942 1.25171ZM7.50003 2.60397L6.50994 4.98442C6.32273 5.43453 5.89944 5.74207 5.41351 5.78103L2.84361 5.98705L4.8016 7.66428C5.17183 7.98142 5.33351 8.47903 5.2204 8.95321L4.62221 11.461L6.8224 10.1171C7.23842 9.86302 7.76164 9.86302 8.17766 10.1171L10.3778 11.461L9.77965 8.95321C9.66654 8.47903 9.82822 7.98142 10.1984 7.66428L12.1564 5.98705L9.58654 5.78103C9.10061 5.74207 8.67732 5.43453 8.49011 4.98442L7.50003 2.60397Z" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd"></path></svg>
<path d="M7.68323 1.53C7.71245 1.47097 7.75758 1.42129 7.81353 1.38655C7.86949 1.35181 7.93404 1.3334 7.9999 1.3334C8.06576 1.3334 8.13031 1.35181 8.18626 1.38655C8.24222 1.42129 8.28735 1.47097 8.31656 1.53L9.85656 4.64933C9.95802 4.85465 10.1078 5.03227 10.293 5.16697C10.4782 5.30167 10.6933 5.38941 10.9199 5.42267L14.3639 5.92667C14.4292 5.93612 14.4905 5.96365 14.5409 6.00613C14.5913 6.04862 14.6289 6.10437 14.6492 6.16707C14.6696 6.22978 14.6721 6.29694 14.6563 6.36096C14.6405 6.42498 14.6071 6.4833 14.5599 6.52933L12.0692 8.95467C11.905 9.11473 11.7821 9.31232 11.7111 9.53042C11.6402 9.74852 11.6233 9.98059 11.6619 10.2067L12.2499 13.6333C12.2614 13.6986 12.2544 13.7657 12.2296 13.8271C12.2048 13.8885 12.1632 13.9417 12.1096 13.9807C12.056 14.0196 11.9926 14.0427 11.9265 14.0473C11.8604 14.0519 11.7944 14.0378 11.7359 14.0067L8.65723 12.388C8.45438 12.2815 8.22868 12.2258 7.99956 12.2258C7.77044 12.2258 7.54475 12.2815 7.3419 12.388L4.2639 14.0067C4.20545 14.0376 4.1395 14.0515 4.07353 14.0468C4.00757 14.0421 3.94424 14.019 3.89076 13.9801C3.83728 13.9413 3.79579 13.8881 3.771 13.8268C3.74622 13.7655 3.73914 13.6985 3.75056 13.6333L4.3379 10.2073C4.3767 9.98116 4.35989 9.74893 4.28892 9.5307C4.21796 9.31246 4.09497 9.11477 3.93056 8.95467L1.4399 6.53C1.39229 6.48402 1.35856 6.4256 1.34254 6.36138C1.32652 6.29717 1.32886 6.22975 1.34928 6.16679C1.36971 6.10384 1.40741 6.04789 1.45808 6.00532C1.50876 5.96275 1.57037 5.93527 1.6359 5.926L5.07923 5.42267C5.30607 5.38967 5.52149 5.30204 5.70695 5.16733C5.89242 5.03261 6.04237 4.85485 6.1439 4.64933L7.68323 1.53Z" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@@ -1,3 +1 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M7.22303 0.665992C7.32551 0.419604 7.67454 0.419604 7.77702 0.665992L9.41343 4.60039C9.45663 4.70426 9.55432 4.77523 9.66645 4.78422L13.914 5.12475C14.18 5.14607 14.2878 5.47802 14.0852 5.65162L10.849 8.42374C10.7636 8.49692 10.7263 8.61176 10.7524 8.72118L11.7411 12.866C11.803 13.1256 11.5206 13.3308 11.2929 13.1917L7.6564 10.9705C7.5604 10.9119 7.43965 10.9119 7.34365 10.9705L3.70718 13.1917C3.47945 13.3308 3.19708 13.1256 3.25899 12.866L4.24769 8.72118C4.2738 8.61176 4.23648 8.49692 4.15105 8.42374L0.914889 5.65162C0.712228 5.47802 0.820086 5.14607 1.08608 5.12475L5.3336 4.78422C5.44573 4.77523 5.54342 4.70426 5.58662 4.60039L7.22303 0.665992Z" fill="currentColor"></path></svg>
<path d="M7.68323 1.53C7.71245 1.47097 7.75758 1.42129 7.81353 1.38655C7.86949 1.35181 7.93404 1.3334 7.9999 1.3334C8.06576 1.3334 8.13031 1.35181 8.18626 1.38655C8.24222 1.42129 8.28735 1.47097 8.31656 1.53L9.85656 4.64933C9.95802 4.85465 10.1078 5.03227 10.293 5.16697C10.4782 5.30167 10.6933 5.38941 10.9199 5.42267L14.3639 5.92667C14.4292 5.93612 14.4905 5.96365 14.5409 6.00613C14.5913 6.04862 14.6289 6.10437 14.6492 6.16707C14.6696 6.22978 14.6721 6.29694 14.6563 6.36096C14.6405 6.42498 14.6071 6.4833 14.5599 6.52933L12.0692 8.95467C11.905 9.11473 11.7821 9.31232 11.7111 9.53042C11.6402 9.74852 11.6233 9.98059 11.6619 10.2067L12.2499 13.6333C12.2614 13.6986 12.2544 13.7657 12.2296 13.8271C12.2048 13.8885 12.1632 13.9417 12.1096 13.9807C12.056 14.0196 11.9926 14.0427 11.9265 14.0473C11.8604 14.0519 11.7944 14.0378 11.7359 14.0067L8.65723 12.388C8.45438 12.2815 8.22868 12.2258 7.99956 12.2258C7.77044 12.2258 7.54475 12.2815 7.3419 12.388L4.2639 14.0067C4.20545 14.0376 4.1395 14.0515 4.07353 14.0468C4.00757 14.0421 3.94424 14.019 3.89076 13.9801C3.83728 13.9413 3.79579 13.8881 3.771 13.8268C3.74622 13.7655 3.73914 13.6985 3.75056 13.6333L4.3379 10.2073C4.3767 9.98116 4.35989 9.74893 4.28892 9.5307C4.21796 9.31246 4.09497 9.11477 3.93056 8.95467L1.4399 6.53C1.39229 6.48402 1.35856 6.4256 1.34254 6.36138C1.32652 6.29717 1.32886 6.22975 1.34928 6.16679C1.36971 6.10384 1.40741 6.04789 1.45808 6.00532C1.50876 5.96275 1.57037 5.93527 1.6359 5.926L5.07923 5.42267C5.30607 5.38967 5.52149 5.30204 5.70695 5.16733C5.89242 5.03261 6.04237 4.85485 6.1439 4.64933L7.68323 1.53Z" fill="black" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 794 B

View File

@@ -1,5 +1,5 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M8 2L6.72534 5.87534C6.6601 6.07367 6.5492 6.25392 6.40155 6.40155C6.25392 6.5492 6.07367 6.6601 5.87534 6.72534L2 8L5.87534 9.27466C6.07367 9.3399 6.25392 9.4508 6.40155 9.59845C6.5492 9.74608 6.6601 9.92633 6.72534 10.1247L8 14L9.27466 10.1247C9.3399 9.92633 9.4508 9.74608 9.59845 9.59845C9.74608 9.4508 9.92633 9.3399 10.1247 9.27466L14 8L10.1247 6.72534C9.92633 6.6601 9.74608 6.5492 9.59845 6.40155C9.4508 6.25392 9.3399 6.07367 9.27466 5.87534L8 2Z" fill="black" fill-opacity="0.15" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> <path d="M7 1.75L5.88467 5.14092C5.82759 5.31446 5.73055 5.47218 5.60136 5.60136C5.47218 5.73055 5.31446 5.82759 5.14092 5.88467L1.75 7L5.14092 8.11533C5.31446 8.17241 5.47218 8.26945 5.60136 8.39864C5.73055 8.52782 5.82759 8.68554 5.88467 8.85908L7 12.25L8.11533 8.85908C8.17241 8.68554 8.26945 8.52782 8.39864 8.39864C8.52782 8.26945 8.68554 8.17241 8.85908 8.11533L12.25 7L8.85908 5.88467C8.68554 5.82759 8.52782 5.73055 8.39864 5.60136C8.26945 5.47218 8.17241 5.31446 8.11533 5.14092L7 1.75Z" fill="black" fill-opacity="0.15" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M3.33334 2V4.66666M2 3.33334H4.66666" stroke="black" stroke-opacity="0.75" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/> <path d="M2.91667 1.75V4.08333M1.75 2.91667H4.08333" stroke="black" stroke-opacity="0.75" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12.6665 11.3333V14M11.3333 12.6666H13.9999" stroke="black" stroke-opacity="0.75" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/> <path d="M11.0833 9.91667V12.25M9.91667 11.0833H12.25" stroke="black" stroke-opacity="0.75" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 998 B

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@@ -31,11 +31,13 @@
"ctrl-,": "zed::OpenSettings", "ctrl-,": "zed::OpenSettings",
"ctrl-q": "zed::Quit", "ctrl-q": "zed::Quit",
"f4": "debugger::Start", "f4": "debugger::Start",
"alt-f4": "debugger::RerunLastSession",
"f5": "debugger::Continue",
"shift-f5": "debugger::Stop", "shift-f5": "debugger::Stop",
"ctrl-shift-f5": "debugger::Restart", "ctrl-shift-f5": "debugger::Restart",
"f6": "debugger::Pause", "f6": "debugger::Pause",
"f7": "debugger::StepOver", "f7": "debugger::StepOver",
"ctrl-f11": "debugger::StepInto", "cmd-f11": "debugger::StepInto",
"shift-f11": "debugger::StepOut", "shift-f11": "debugger::StepOut",
"f11": "zed::ToggleFullScreen", "f11": "zed::ToggleFullScreen",
"ctrl-alt-z": "edit_prediction::RateCompletions", "ctrl-alt-z": "edit_prediction::RateCompletions",
@@ -59,6 +61,7 @@
"tab": "editor::Tab", "tab": "editor::Tab",
"shift-tab": "editor::Backtab", "shift-tab": "editor::Backtab",
"ctrl-k": "editor::CutToEndOfLine", "ctrl-k": "editor::CutToEndOfLine",
// "ctrl-t": "editor::Transpose",
"ctrl-k ctrl-q": "editor::Rewrap", "ctrl-k ctrl-q": "editor::Rewrap",
"ctrl-k q": "editor::Rewrap", "ctrl-k q": "editor::Rewrap",
"ctrl-backspace": "editor::DeleteToPreviousWordStart", "ctrl-backspace": "editor::DeleteToPreviousWordStart",
@@ -99,27 +102,34 @@
"shift-down": "editor::SelectDown", "shift-down": "editor::SelectDown",
"shift-left": "editor::SelectLeft", "shift-left": "editor::SelectLeft",
"shift-right": "editor::SelectRight", "shift-right": "editor::SelectRight",
"ctrl-shift-left": "editor::SelectToPreviousWordStart", "ctrl-shift-left": "editor::SelectToPreviousWordStart", // cursorWordLeftSelect
"ctrl-shift-right": "editor::SelectToNextWordEnd", "ctrl-shift-right": "editor::SelectToNextWordEnd", // cursorWordRightSelect
"ctrl-shift-home": "editor::SelectToBeginning", "ctrl-shift-home": "editor::SelectToBeginning",
"ctrl-shift-end": "editor::SelectToEnd", "ctrl-shift-end": "editor::SelectToEnd",
"ctrl-a": "editor::SelectAll", "ctrl-a": "editor::SelectAll",
"ctrl-l": "editor::SelectLine", "ctrl-l": "editor::SelectLine",
"ctrl-shift-i": "editor::Format", "ctrl-shift-i": "editor::Format",
"alt-shift-o": "editor::OrganizeImports", "alt-shift-o": "editor::OrganizeImports",
// "cmd-shift-left": ["editor::SelectToBeginningOfLine", {"stop_at_soft_wraps": true, "stop_at_indent": true }],
// "ctrl-shift-a": ["editor::SelectToBeginningOfLine", { "stop_at_soft_wraps": true, "stop_at_indent": true }],
"shift-home": ["editor::SelectToBeginningOfLine", { "stop_at_soft_wraps": true, "stop_at_indent": true }], "shift-home": ["editor::SelectToBeginningOfLine", { "stop_at_soft_wraps": true, "stop_at_indent": true }],
// "cmd-shift-right": ["editor::SelectToEndOfLine", { "stop_at_soft_wraps": true }],
// "ctrl-shift-e": ["editor::SelectToEndOfLine", { "stop_at_soft_wraps": true }],
"shift-end": ["editor::SelectToEndOfLine", { "stop_at_soft_wraps": true }], "shift-end": ["editor::SelectToEndOfLine", { "stop_at_soft_wraps": true }],
// "alt-v": ["editor::MovePageUp", { "center_cursor": true }],
"ctrl-alt-space": "editor::ShowCharacterPalette", "ctrl-alt-space": "editor::ShowCharacterPalette",
"ctrl-;": "editor::ToggleLineNumbers", "ctrl-;": "editor::ToggleLineNumbers",
"ctrl-'": "editor::ToggleSelectedDiffHunks", "ctrl-'": "editor::ToggleSelectedDiffHunks",
"ctrl-\"": "editor::ExpandAllDiffHunks", "ctrl-\"": "editor::ExpandAllDiffHunks",
"ctrl-i": "editor::ShowSignatureHelp", "ctrl-i": "editor::ShowSignatureHelp",
"alt-g b": "git::Blame", "alt-g b": "editor::ToggleGitBlame",
"menu": "editor::OpenContextMenu", "menu": "editor::OpenContextMenu",
"shift-f10": "editor::OpenContextMenu", "shift-f10": "editor::OpenContextMenu",
"ctrl-shift-e": "editor::ToggleEditPrediction", "ctrl-shift-e": "editor::ToggleEditPrediction",
"f9": "editor::ToggleBreakpoint", "f9": "editor::ToggleBreakpoint",
"shift-f9": "editor::EditLogBreakpoint" "shift-f9": "editor::EditLogBreakpoint",
"ctrl-shift-backspace": "editor::GoToPreviousChange",
"ctrl-shift-alt-backspace": "editor::GoToNextChange"
} }
}, },
{ {
@@ -134,11 +144,10 @@
"find": "buffer_search::Deploy", "find": "buffer_search::Deploy",
"ctrl-f": "buffer_search::Deploy", "ctrl-f": "buffer_search::Deploy",
"ctrl-h": "buffer_search::DeployReplace", "ctrl-h": "buffer_search::DeployReplace",
// "cmd-e": ["buffer_search::Deploy", { "focus": false }],
"ctrl->": "assistant::QuoteSelection", "ctrl->": "assistant::QuoteSelection",
"ctrl-<": "assistant::InsertIntoEditor", "ctrl-<": "assistant::InsertIntoEditor",
"ctrl-alt-e": "editor::SelectEnclosingSymbol", "ctrl-alt-e": "editor::SelectEnclosingSymbol",
"ctrl-shift-backspace": "editor::GoToPreviousChange",
"ctrl-shift-alt-backspace": "editor::GoToNextChange",
"alt-enter": "editor::OpenSelectionsInMultibuffer" "alt-enter": "editor::OpenSelectionsInMultibuffer"
} }
}, },
@@ -146,7 +155,8 @@
"context": "Editor && mode == full && edit_prediction", "context": "Editor && mode == full && edit_prediction",
"bindings": { "bindings": {
"alt-]": "editor::NextEditPrediction", "alt-]": "editor::NextEditPrediction",
"alt-[": "editor::PreviousEditPrediction" "alt-[": "editor::PreviousEditPrediction",
"alt-right": "editor::AcceptPartialEditPrediction"
} }
}, },
{ {
@@ -211,6 +221,7 @@
"ctrl-enter": "assistant::Assist", "ctrl-enter": "assistant::Assist",
"ctrl-s": "workspace::Save", "ctrl-s": "workspace::Save",
"save": "workspace::Save", "save": "workspace::Save",
"ctrl->": "assistant::QuoteSelection",
"ctrl-<": "assistant::InsertIntoEditor", "ctrl-<": "assistant::InsertIntoEditor",
"shift-enter": "assistant::Split", "shift-enter": "assistant::Split",
"ctrl-r": "assistant::CycleMessageRole", "ctrl-r": "assistant::CycleMessageRole",
@@ -233,15 +244,13 @@
"ctrl-i": "agent::ToggleProfileSelector", "ctrl-i": "agent::ToggleProfileSelector",
"ctrl-alt-/": "agent::ToggleModelSelector", "ctrl-alt-/": "agent::ToggleModelSelector",
"ctrl-shift-a": "agent::ToggleContextPicker", "ctrl-shift-a": "agent::ToggleContextPicker",
"ctrl-shift-j": "agent::ToggleNavigationMenu", "ctrl-shift-o": "agent::ToggleNavigationMenu",
"ctrl-shift-i": "agent::ToggleOptionsMenu", "ctrl-shift-i": "agent::ToggleOptionsMenu",
"shift-alt-escape": "agent::ExpandMessageEditor", "shift-alt-escape": "agent::ExpandMessageEditor",
"ctrl->": "assistant::QuoteSelection",
"ctrl-alt-e": "agent::RemoveAllContext", "ctrl-alt-e": "agent::RemoveAllContext",
"ctrl-shift-e": "project_panel::ToggleFocus", "ctrl-shift-e": "project_panel::ToggleFocus",
"ctrl-shift-enter": "agent::ContinueThread", "ctrl-shift-enter": "agent::ContinueThread",
"alt-enter": "agent::ContinueWithBurnMode", "alt-enter": "agent::ContinueWithBurnMode"
"ctrl-alt-b": "agent::ToggleBurnMode"
} }
}, },
{ {
@@ -260,8 +269,8 @@
{ {
"context": "AgentPanel && prompt_editor", "context": "AgentPanel && prompt_editor",
"bindings": { "bindings": {
"ctrl-n": "agent::NewTextThread", "cmd-n": "agent::NewTextThread",
"ctrl-alt-t": "agent::NewThread" "cmd-alt-t": "agent::NewThread"
} }
}, },
{ {
@@ -270,9 +279,7 @@
"enter": "agent::Chat", "enter": "agent::Chat",
"ctrl-enter": "agent::ChatWithFollow", "ctrl-enter": "agent::ChatWithFollow",
"ctrl-i": "agent::ToggleProfileSelector", "ctrl-i": "agent::ToggleProfileSelector",
"shift-ctrl-r": "agent::OpenAgentDiff", "shift-ctrl-r": "agent::OpenAgentDiff"
"ctrl-shift-y": "agent::KeepAll",
"ctrl-shift-n": "agent::RejectAll"
} }
}, },
{ {
@@ -504,14 +511,14 @@
{ {
"context": "Workspace", "context": "Workspace",
"bindings": { "bindings": {
"alt-open": ["projects::OpenRecent", { "create_new_window": false }],
// Change the default action on `menu::Confirm` by setting the parameter // Change the default action on `menu::Confirm` by setting the parameter
// "alt-ctrl-o": ["projects::OpenRecent", { "create_new_window": true }], // "alt-ctrl-o": ["projects::OpenRecent", { "create_new_window": true }],
"alt-ctrl-o": ["projects::OpenRecent", { "create_new_window": false }], "alt-open": "projects::OpenRecent",
"alt-shift-open": ["projects::OpenRemote", { "from_existing_connection": false, "create_new_window": false }], "alt-ctrl-o": "projects::OpenRecent",
"alt-shift-open": "projects::OpenRemote",
"alt-ctrl-shift-o": "projects::OpenRemote",
// Change to open path modal for existing remote connection by setting the parameter // Change to open path modal for existing remote connection by setting the parameter
// "alt-ctrl-shift-o": "["projects::OpenRemote", { "from_existing_connection": true }]", // "alt-ctrl-shift-o": "["projects::OpenRemote", { "from_existing_connection": true }]",
"alt-ctrl-shift-o": ["projects::OpenRemote", { "from_existing_connection": false, "create_new_window": false }],
"alt-ctrl-shift-b": "branches::OpenRecent", "alt-ctrl-shift-b": "branches::OpenRecent",
"alt-shift-enter": "toast::RunAction", "alt-shift-enter": "toast::RunAction",
"ctrl-~": "workspace::NewTerminal", "ctrl-~": "workspace::NewTerminal",
@@ -575,24 +582,11 @@
"ctrl-alt-r": "task::Rerun", "ctrl-alt-r": "task::Rerun",
"alt-t": "task::Rerun", "alt-t": "task::Rerun",
"alt-shift-t": "task::Spawn", "alt-shift-t": "task::Spawn",
"alt-shift-r": ["task::Spawn", { "reveal_target": "center" }], "alt-shift-r": ["task::Spawn", { "reveal_target": "center" }]
// also possible to spawn tasks by name: // also possible to spawn tasks by name:
// "foo-bar": ["task::Spawn", { "task_name": "MyTask", "reveal_target": "dock" }] // "foo-bar": ["task::Spawn", { "task_name": "MyTask", "reveal_target": "dock" }]
// or by tag: // or by tag:
// "foo-bar": ["task::Spawn", { "task_tag": "MyTag" }], // "foo-bar": ["task::Spawn", { "task_tag": "MyTag" }],
"f5": "debugger::RerunLastSession"
}
},
{
"context": "Workspace && debugger_running",
"bindings": {
"f5": "zed::NoAction"
}
},
{
"context": "Workspace && debugger_stopped",
"bindings": {
"f5": "debugger::Continue"
} }
}, },
{ {
@@ -654,16 +648,14 @@
"bindings": { "bindings": {
"alt-tab": "editor::AcceptEditPrediction", "alt-tab": "editor::AcceptEditPrediction",
"alt-l": "editor::AcceptEditPrediction", "alt-l": "editor::AcceptEditPrediction",
"tab": "editor::AcceptEditPrediction", "tab": "editor::AcceptEditPrediction"
"alt-right": "editor::AcceptPartialEditPrediction"
} }
}, },
{ {
"context": "Editor && edit_prediction_conflict", "context": "Editor && edit_prediction_conflict",
"bindings": { "bindings": {
"alt-tab": "editor::AcceptEditPrediction", "alt-tab": "editor::AcceptEditPrediction",
"alt-l": "editor::AcceptEditPrediction", "alt-l": "editor::AcceptEditPrediction"
"alt-right": "editor::AcceptPartialEditPrediction"
} }
}, },
{ {
@@ -880,8 +872,7 @@
"context": "DebugPanel", "context": "DebugPanel",
"bindings": { "bindings": {
"ctrl-t": "debugger::ToggleThreadPicker", "ctrl-t": "debugger::ToggleThreadPicker",
"ctrl-i": "debugger::ToggleSessionPicker", "ctrl-i": "debugger::ToggleSessionPicker"
"shift-alt-escape": "debugger::ToggleExpandItem"
} }
}, },
{ {
@@ -905,9 +896,7 @@
"context": "CollabPanel && not_editing", "context": "CollabPanel && not_editing",
"bindings": { "bindings": {
"ctrl-backspace": "collab_panel::Remove", "ctrl-backspace": "collab_panel::Remove",
"space": "menu::Confirm", "space": "menu::Confirm"
"ctrl-up": "collab_panel::MoveChannelUp",
"ctrl-down": "collab_panel::MoveChannelDown"
} }
}, },
{ {
@@ -938,13 +927,6 @@
"tab": "channel_modal::ToggleMode" "tab": "channel_modal::ToggleMode"
} }
}, },
{
"context": "FileFinder",
"bindings": {
"ctrl-shift-a": "file_finder::ToggleSplitMenu",
"ctrl-shift-i": "file_finder::ToggleFilterMenu"
}
},
{ {
"context": "FileFinder || (FileFinder > Picker > Editor) || (FileFinder > Picker > menu)", "context": "FileFinder || (FileFinder > Picker > Editor) || (FileFinder > Picker > menu)",
"bindings": { "bindings": {
@@ -1036,12 +1018,5 @@
"bindings": { "bindings": {
"enter": "menu::Confirm" "enter": "menu::Confirm"
} }
},
{
"context": "RunModal",
"bindings": {
"ctrl-tab": "pane::ActivateNextItem",
"ctrl-shift-tab": "pane::ActivatePreviousItem"
}
} }
] ]

View File

@@ -4,6 +4,8 @@
"use_key_equivalents": true, "use_key_equivalents": true,
"bindings": { "bindings": {
"f4": "debugger::Start", "f4": "debugger::Start",
"alt-f4": "debugger::RerunLastSession",
"f5": "debugger::Continue",
"shift-f5": "debugger::Stop", "shift-f5": "debugger::Stop",
"shift-cmd-f5": "debugger::Restart", "shift-cmd-f5": "debugger::Restart",
"f6": "debugger::Pause", "f6": "debugger::Pause",
@@ -138,7 +140,7 @@
"cmd-;": "editor::ToggleLineNumbers", "cmd-;": "editor::ToggleLineNumbers",
"cmd-'": "editor::ToggleSelectedDiffHunks", "cmd-'": "editor::ToggleSelectedDiffHunks",
"cmd-\"": "editor::ExpandAllDiffHunks", "cmd-\"": "editor::ExpandAllDiffHunks",
"cmd-alt-g b": "git::Blame", "cmd-alt-g b": "editor::ToggleGitBlame",
"cmd-i": "editor::ShowSignatureHelp", "cmd-i": "editor::ShowSignatureHelp",
"f9": "editor::ToggleBreakpoint", "f9": "editor::ToggleBreakpoint",
"shift-f9": "editor::EditLogBreakpoint", "shift-f9": "editor::EditLogBreakpoint",
@@ -181,7 +183,8 @@
"use_key_equivalents": true, "use_key_equivalents": true,
"bindings": { "bindings": {
"alt-tab": "editor::NextEditPrediction", "alt-tab": "editor::NextEditPrediction",
"alt-shift-tab": "editor::PreviousEditPrediction" "alt-shift-tab": "editor::PreviousEditPrediction",
"ctrl-cmd-right": "editor::AcceptPartialEditPrediction"
} }
}, },
{ {
@@ -252,6 +255,7 @@
"bindings": { "bindings": {
"cmd-enter": "assistant::Assist", "cmd-enter": "assistant::Assist",
"cmd-s": "workspace::Save", "cmd-s": "workspace::Save",
"cmd->": "assistant::QuoteSelection",
"cmd-<": "assistant::InsertIntoEditor", "cmd-<": "assistant::InsertIntoEditor",
"shift-enter": "assistant::Split", "shift-enter": "assistant::Split",
"ctrl-r": "assistant::CycleMessageRole", "ctrl-r": "assistant::CycleMessageRole",
@@ -275,15 +279,13 @@
"cmd-i": "agent::ToggleProfileSelector", "cmd-i": "agent::ToggleProfileSelector",
"cmd-alt-/": "agent::ToggleModelSelector", "cmd-alt-/": "agent::ToggleModelSelector",
"cmd-shift-a": "agent::ToggleContextPicker", "cmd-shift-a": "agent::ToggleContextPicker",
"cmd-shift-j": "agent::ToggleNavigationMenu", "cmd-shift-o": "agent::ToggleNavigationMenu",
"cmd-shift-i": "agent::ToggleOptionsMenu", "cmd-shift-i": "agent::ToggleOptionsMenu",
"shift-alt-escape": "agent::ExpandMessageEditor", "shift-alt-escape": "agent::ExpandMessageEditor",
"cmd->": "assistant::QuoteSelection",
"cmd-alt-e": "agent::RemoveAllContext", "cmd-alt-e": "agent::RemoveAllContext",
"cmd-shift-e": "project_panel::ToggleFocus", "cmd-shift-e": "project_panel::ToggleFocus",
"cmd-shift-enter": "agent::ContinueThread", "cmd-shift-enter": "agent::ContinueThread",
"alt-enter": "agent::ContinueWithBurnMode", "alt-enter": "agent::ContinueWithBurnMode"
"cmd-alt-b": "agent::ToggleBurnMode"
} }
}, },
{ {
@@ -314,9 +316,7 @@
"enter": "agent::Chat", "enter": "agent::Chat",
"cmd-enter": "agent::ChatWithFollow", "cmd-enter": "agent::ChatWithFollow",
"cmd-i": "agent::ToggleProfileSelector", "cmd-i": "agent::ToggleProfileSelector",
"shift-ctrl-r": "agent::OpenAgentDiff", "shift-ctrl-r": "agent::OpenAgentDiff"
"cmd-shift-y": "agent::KeepAll",
"cmd-shift-n": "agent::RejectAll"
} }
}, },
{ {
@@ -545,7 +545,9 @@
"cmd-\\": "pane::SplitRight", "cmd-\\": "pane::SplitRight",
"cmd-k v": "markdown::OpenPreviewToTheSide", "cmd-k v": "markdown::OpenPreviewToTheSide",
"cmd-shift-v": "markdown::OpenPreview", "cmd-shift-v": "markdown::OpenPreview",
"ctrl-cmd-c": "editor::DisplayCursorNames" "ctrl-cmd-c": "editor::DisplayCursorNames",
"cmd-shift-backspace": "editor::GoToPreviousChange",
"cmd-shift-alt-backspace": "editor::GoToNextChange"
} }
}, },
{ {
@@ -553,9 +555,7 @@
"use_key_equivalents": true, "use_key_equivalents": true,
"bindings": { "bindings": {
"cmd-shift-o": "outline::Toggle", "cmd-shift-o": "outline::Toggle",
"ctrl-g": "go_to_line::Toggle", "ctrl-g": "go_to_line::Toggle"
"cmd-shift-backspace": "editor::GoToPreviousChange",
"cmd-shift-alt-backspace": "editor::GoToNextChange"
} }
}, },
{ {
@@ -583,9 +583,9 @@
"bindings": { "bindings": {
// Change the default action on `menu::Confirm` by setting the parameter // Change the default action on `menu::Confirm` by setting the parameter
// "alt-cmd-o": ["projects::OpenRecent", {"create_new_window": true }], // "alt-cmd-o": ["projects::OpenRecent", {"create_new_window": true }],
"alt-cmd-o": ["projects::OpenRecent", { "create_new_window": false }], "alt-cmd-o": "projects::OpenRecent",
"ctrl-cmd-o": ["projects::OpenRemote", { "from_existing_connection": false, "create_new_window": false }], "ctrl-cmd-o": "projects::OpenRemote",
"ctrl-cmd-shift-o": ["projects::OpenRemote", { "from_existing_connection": true, "create_new_window": false }], "ctrl-cmd-shift-o": ["projects::OpenRemote", { "from_existing_connection": true }],
"alt-cmd-b": "branches::OpenRecent", "alt-cmd-b": "branches::OpenRecent",
"ctrl-~": "workspace::NewTerminal", "ctrl-~": "workspace::NewTerminal",
"cmd-s": "workspace::Save", "cmd-s": "workspace::Save",
@@ -634,8 +634,7 @@
"cmd-k shift-right": "workspace::SwapPaneRight", "cmd-k shift-right": "workspace::SwapPaneRight",
"cmd-k shift-up": "workspace::SwapPaneUp", "cmd-k shift-up": "workspace::SwapPaneUp",
"cmd-k shift-down": "workspace::SwapPaneDown", "cmd-k shift-down": "workspace::SwapPaneDown",
"cmd-shift-x": "zed::Extensions", "cmd-shift-x": "zed::Extensions"
"f5": "debugger::RerunLastSession"
} }
}, },
{ {
@@ -652,20 +651,6 @@
// "foo-bar": ["task::Spawn", { "task_tag": "MyTag" }], // "foo-bar": ["task::Spawn", { "task_tag": "MyTag" }],
} }
}, },
{
"context": "Workspace && debugger_running",
"use_key_equivalents": true,
"bindings": {
"f5": "zed::NoAction"
}
},
{
"context": "Workspace && debugger_stopped",
"use_key_equivalents": true,
"bindings": {
"f5": "debugger::Continue"
}
},
// Bindings from Sublime Text // Bindings from Sublime Text
{ {
"context": "Editor", "context": "Editor",
@@ -718,16 +703,14 @@
"context": "Editor && edit_prediction", "context": "Editor && edit_prediction",
"bindings": { "bindings": {
"alt-tab": "editor::AcceptEditPrediction", "alt-tab": "editor::AcceptEditPrediction",
"tab": "editor::AcceptEditPrediction", "tab": "editor::AcceptEditPrediction"
"ctrl-cmd-right": "editor::AcceptPartialEditPrediction"
} }
}, },
{ {
"context": "Editor && edit_prediction_conflict", "context": "Editor && edit_prediction_conflict",
"use_key_equivalents": true, "use_key_equivalents": true,
"bindings": { "bindings": {
"alt-tab": "editor::AcceptEditPrediction", "alt-tab": "editor::AcceptEditPrediction"
"ctrl-cmd-right": "editor::AcceptPartialEditPrediction"
} }
}, },
{ {
@@ -952,8 +935,7 @@
"context": "DebugPanel", "context": "DebugPanel",
"bindings": { "bindings": {
"cmd-t": "debugger::ToggleThreadPicker", "cmd-t": "debugger::ToggleThreadPicker",
"cmd-i": "debugger::ToggleSessionPicker", "cmd-i": "debugger::ToggleSessionPicker"
"shift-alt-escape": "debugger::ToggleExpandItem"
} }
}, },
{ {
@@ -968,9 +950,7 @@
"use_key_equivalents": true, "use_key_equivalents": true,
"bindings": { "bindings": {
"ctrl-backspace": "collab_panel::Remove", "ctrl-backspace": "collab_panel::Remove",
"space": "menu::Confirm", "space": "menu::Confirm"
"cmd-up": "collab_panel::MoveChannelUp",
"cmd-down": "collab_panel::MoveChannelDown"
} }
}, },
{ {
@@ -1006,14 +986,6 @@
"tab": "channel_modal::ToggleMode" "tab": "channel_modal::ToggleMode"
} }
}, },
{
"context": "FileFinder",
"use_key_equivalents": true,
"bindings": {
"cmd-shift-a": "file_finder::ToggleSplitMenu",
"cmd-shift-i": "file_finder::ToggleFilterMenu"
}
},
{ {
"context": "FileFinder || (FileFinder > Picker > Editor) || (FileFinder > Picker > menu)", "context": "FileFinder || (FileFinder > Picker > Editor) || (FileFinder > Picker > menu)",
"use_key_equivalents": true, "use_key_equivalents": true,
@@ -1136,13 +1108,5 @@
"bindings": { "bindings": {
"enter": "menu::Confirm" "enter": "menu::Confirm"
} }
},
{
"context": "RunModal",
"use_key_equivalents": true,
"bindings": {
"ctrl-tab": "pane::ActivateNextItem",
"ctrl-shift-tab": "pane::ActivatePreviousItem"
}
} }
] ]

View File

@@ -13,9 +13,9 @@
} }
}, },
{ {
"context": "Editor && vim_mode == insert && !menu", "context": "Editor",
"bindings": { "bindings": {
// "j k": "vim::SwitchToNormalMode" // "j k": ["workspace::SendKeystrokes", "escape"]
} }
} }
] ]

View File

@@ -1,85 +0,0 @@
[
// Cursor for MacOS. See: https://docs.cursor.com/kbd
{
"context": "Workspace",
"use_key_equivalents": true,
"bindings": {
"ctrl-i": "agent::ToggleFocus",
"ctrl-shift-i": "agent::ToggleFocus",
"ctrl-l": "agent::ToggleFocus",
"ctrl-shift-l": "agent::ToggleFocus",
"ctrl-alt-b": "agent::ToggleFocus",
"ctrl-shift-j": "agent::OpenConfiguration"
}
},
{
"context": "Editor && mode == full",
"use_key_equivalents": true,
"bindings": {
"ctrl-i": "agent::ToggleFocus",
"ctrl-shift-i": "agent::ToggleFocus",
"ctrl-shift-l": "assistant::QuoteSelection", // In cursor uses "Ask" mode
"ctrl-l": "assistant::QuoteSelection", // In cursor uses "Agent" mode
"ctrl-k": "assistant::InlineAssist",
"ctrl-shift-k": "assistant::InsertIntoEditor"
}
},
{
"context": "InlineAssistEditor",
"use_key_equivalents": true,
"bindings": {
"ctrl-shift-backspace": "editor::Cancel"
// "alt-enter": // Quick Question
// "ctrl-shift-enter": // Full File Context
// "ctrl-shift-k": // Toggle input focus (editor <> inline assist)
}
},
{
"context": "AgentPanel || ContextEditor || (MessageEditor > Editor)",
"use_key_equivalents": true,
"bindings": {
"ctrl-i": "workspace::ToggleRightDock",
"ctrl-shift-i": "workspace::ToggleRightDock",
"ctrl-l": "workspace::ToggleRightDock",
"ctrl-shift-l": "workspace::ToggleRightDock",
"ctrl-alt-b": "workspace::ToggleRightDock",
"ctrl-w": "workspace::ToggleRightDock", // technically should close chat
"ctrl-.": "agent::ToggleProfileSelector",
"ctrl-/": "agent::ToggleModelSelector",
"ctrl-shift-backspace": "editor::Cancel",
"ctrl-r": "agent::NewThread",
"ctrl-shift-v": "editor::Paste",
"ctrl-shift-k": "assistant::InsertIntoEditor"
// "escape": "agent::ToggleFocus"
///// Enable when Zed supports multiple thread tabs
// "ctrl-t": // new thread tab
// "ctrl-[": // next thread tab
// "ctrl-]": // next thread tab
///// Enable if Zed adds support for keyboard navigation of thread elements
// "tab": // cycle to next message
// "shift-tab": // cycle to previous message
}
},
{
"context": "Editor && editor_agent_diff",
"use_key_equivalents": true,
"bindings": {
"ctrl-enter": "agent::KeepAll",
"ctrl-backspace": "agent::RejectAll"
}
},
{
"context": "Editor && mode == full && edit_prediction",
"use_key_equivalents": true,
"bindings": {
"ctrl-right": "editor::AcceptPartialEditPrediction"
}
},
{
"context": "Terminal",
"use_key_equivalents": true,
"bindings": {
"ctrl-k": "assistant::InlineAssist"
}
}
]

View File

@@ -38,7 +38,7 @@
"ctrl-shift-d": "editor::DuplicateSelection", "ctrl-shift-d": "editor::DuplicateSelection",
"alt-f3": "editor::SelectAllMatches", // find_all_under "alt-f3": "editor::SelectAllMatches", // find_all_under
// "ctrl-f3": "", // find_under (cancels any selections) // "ctrl-f3": "", // find_under (cancels any selections)
// "ctrl-alt-shift-g": "" // find_under_prev (cancels any selections) // "cmd-alt-shift-g": "" // find_under_prev (cancels any selections)
"f9": "editor::SortLinesCaseSensitive", "f9": "editor::SortLinesCaseSensitive",
"ctrl-f9": "editor::SortLinesCaseInsensitive", "ctrl-f9": "editor::SortLinesCaseInsensitive",
"f12": "editor::GoToDefinition", "f12": "editor::GoToDefinition",
@@ -51,11 +51,7 @@
"ctrl-k ctrl-l": "editor::ConvertToLowerCase", "ctrl-k ctrl-l": "editor::ConvertToLowerCase",
"shift-alt-m": "markdown::OpenPreviewToTheSide", "shift-alt-m": "markdown::OpenPreviewToTheSide",
"ctrl-backspace": "editor::DeleteToPreviousWordStart", "ctrl-backspace": "editor::DeleteToPreviousWordStart",
"ctrl-delete": "editor::DeleteToNextWordEnd", "ctrl-delete": "editor::DeleteToNextWordEnd"
"alt-right": "editor::MoveToNextSubwordEnd",
"alt-left": "editor::MoveToPreviousSubwordStart",
"alt-shift-right": "editor::SelectToNextSubwordEnd",
"alt-shift-left": "editor::SelectToPreviousSubwordStart"
} }
}, },
{ {

View File

@@ -1,86 +0,0 @@
[
// Cursor for MacOS. See: https://docs.cursor.com/kbd
{
"context": "Workspace",
"use_key_equivalents": true,
"bindings": {
"cmd-i": "agent::ToggleFocus",
"cmd-shift-i": "agent::ToggleFocus",
"cmd-l": "agent::ToggleFocus",
"cmd-shift-l": "agent::ToggleFocus",
"cmd-alt-b": "agent::ToggleFocus",
"cmd-shift-j": "agent::OpenConfiguration"
}
},
{
"context": "Editor && mode == full",
"use_key_equivalents": true,
"bindings": {
"cmd-i": "agent::ToggleFocus",
"cmd-shift-i": "agent::ToggleFocus",
"cmd-shift-l": "assistant::QuoteSelection", // In cursor uses "Ask" mode
"cmd-l": "assistant::QuoteSelection", // In cursor uses "Agent" mode
"cmd-k": "assistant::InlineAssist",
"cmd-shift-k": "assistant::InsertIntoEditor"
}
},
{
"context": "InlineAssistEditor",
"use_key_equivalents": true,
"bindings": {
"cmd-shift-backspace": "editor::Cancel",
"cmd-enter": "menu::Confirm"
// "alt-enter": // Quick Question
// "cmd-shift-enter": // Full File Context
// "cmd-shift-k": // Toggle input focus (editor <> inline assist)
}
},
{
"context": "AgentPanel || ContextEditor || (MessageEditor > Editor)",
"use_key_equivalents": true,
"bindings": {
"cmd-i": "workspace::ToggleRightDock",
"cmd-shift-i": "workspace::ToggleRightDock",
"cmd-l": "workspace::ToggleRightDock",
"cmd-shift-l": "workspace::ToggleRightDock",
"cmd-alt-b": "workspace::ToggleRightDock",
"cmd-w": "workspace::ToggleRightDock", // technically should close chat
"cmd-.": "agent::ToggleProfileSelector",
"cmd-/": "agent::ToggleModelSelector",
"cmd-shift-backspace": "editor::Cancel",
"cmd-r": "agent::NewThread",
"cmd-shift-v": "editor::Paste",
"cmd-shift-k": "assistant::InsertIntoEditor"
// "escape": "agent::ToggleFocus"
///// Enable when Zed supports multiple thread tabs
// "cmd-t": // new thread tab
// "cmd-[": // next thread tab
// "cmd-]": // next thread tab
///// Enable if Zed adds support for keyboard navigation of thread elements
// "tab": // cycle to next message
// "shift-tab": // cycle to previous message
}
},
{
"context": "Editor && editor_agent_diff",
"use_key_equivalents": true,
"bindings": {
"cmd-enter": "agent::KeepAll",
"cmd-backspace": "agent::RejectAll"
}
},
{
"context": "Editor && mode == full && edit_prediction",
"use_key_equivalents": true,
"bindings": {
"cmd-right": "editor::AcceptPartialEditPrediction"
}
},
{
"context": "Terminal",
"use_key_equivalents": true,
"bindings": {
"cmd-k": "assistant::InlineAssist"
}
}
]

View File

@@ -53,11 +53,7 @@
"cmd-shift-j": "editor::JoinLines", "cmd-shift-j": "editor::JoinLines",
"shift-alt-m": "markdown::OpenPreviewToTheSide", "shift-alt-m": "markdown::OpenPreviewToTheSide",
"ctrl-backspace": "editor::DeleteToPreviousWordStart", "ctrl-backspace": "editor::DeleteToPreviousWordStart",
"ctrl-delete": "editor::DeleteToNextWordEnd", "ctrl-delete": "editor::DeleteToNextWordEnd"
"ctrl-right": "editor::MoveToNextSubwordEnd",
"ctrl-left": "editor::MoveToPreviousSubwordStart",
"ctrl-shift-right": "editor::SelectToNextSubwordEnd",
"ctrl-shift-left": "editor::SelectToPreviousSubwordStart"
} }
}, },
{ {

View File

@@ -198,8 +198,6 @@
"9": ["vim::Number", 9], "9": ["vim::Number", 9],
"ctrl-w d": "editor::GoToDefinitionSplit", "ctrl-w d": "editor::GoToDefinitionSplit",
"ctrl-w g d": "editor::GoToDefinitionSplit", "ctrl-w g d": "editor::GoToDefinitionSplit",
"ctrl-w ]": "editor::GoToDefinitionSplit",
"ctrl-w ctrl-]": "editor::GoToDefinitionSplit",
"ctrl-w shift-d": "editor::GoToTypeDefinitionSplit", "ctrl-w shift-d": "editor::GoToTypeDefinitionSplit",
"ctrl-w g shift-d": "editor::GoToTypeDefinitionSplit", "ctrl-w g shift-d": "editor::GoToTypeDefinitionSplit",
"ctrl-w space": "editor::OpenExcerptsSplit", "ctrl-w space": "editor::OpenExcerptsSplit",
@@ -711,7 +709,7 @@
} }
}, },
{ {
"context": "AgentPanel || GitPanel || ProjectPanel || CollabPanel || OutlinePanel || ChatPanel || VimControl || EmptyPane || SharedScreen || MarkdownPreview || KeyContextView || DebugPanel", "context": "GitPanel || ProjectPanel || CollabPanel || OutlinePanel || ChatPanel || VimControl || EmptyPane || SharedScreen || MarkdownPreview || KeyContextView || DebugPanel",
"bindings": { "bindings": {
// window related commands (ctrl-w X) // window related commands (ctrl-w X)
"ctrl-w": null, "ctrl-w": null,
@@ -840,19 +838,6 @@
"tab": "editor::AcceptEditPrediction" "tab": "editor::AcceptEditPrediction"
} }
}, },
{
"context": "MessageEditor > Editor && VimControl",
"bindings": {
"enter": "agent::Chat",
// TODO: Implement search
"/": null,
"?": null,
"#": null,
"*": null,
"n": null,
"shift-n": null
}
},
{ {
"context": "os != macos && Editor && edit_prediction_conflict", "context": "os != macos && Editor && edit_prediction_conflict",
"bindings": { "bindings": {

View File

@@ -17,13 +17,13 @@ You are a highly skilled software engineer with extensive knowledge in many prog
4. Use only the tools that are currently available. 4. Use only the tools that are currently available.
5. DO NOT use a tool that is not available just because it appears in the conversation. This means the user turned it off. 5. DO NOT use a tool that is not available just because it appears in the conversation. This means the user turned it off.
6. NEVER run commands that don't terminate on their own such as web servers (like `npm run start`, `npm run dev`, `python -m http.server`, etc) or file watchers. 6. NEVER run commands that don't terminate on their own such as web servers (like `npm run start`, `npm run dev`, `python -m http.server`, etc) or file watchers.
7. Avoid HTML entity escaping - use plain characters instead.
## Searching and Reading ## Searching and Reading
If you are unsure how to fulfill the user's request, gather more information with tool calls and/or clarifying questions. If you are unsure how to fulfill the user's request, gather more information with tool calls and/or clarifying questions.
{{! TODO: If there are files, we should mention it but otherwise omit that fact }} {{! TODO: If there are files, we should mention it but otherwise omit that fact }}
{{#if has_tools}}
If appropriate, use tool calls to explore the current project, which contains the following root directories: If appropriate, use tool calls to explore the current project, which contains the following root directories:
{{#each worktrees}} {{#each worktrees}}
@@ -38,6 +38,7 @@ If appropriate, use tool calls to explore the current project, which contains th
- As you learn about the structure of the project, use that information to scope `grep` searches to targeted subtrees of the project. - As you learn about the structure of the project, use that information to scope `grep` searches to targeted subtrees of the project.
- The user might specify a partial file path. If you don't know the full path, use `find_path` (not `grep`) before you read the file. - The user might specify a partial file path. If you don't know the full path, use `find_path` (not `grep`) before you read the file.
{{/if}} {{/if}}
{{/if}}
{{else}} {{else}}
You are being tasked with providing a response, but you have no ability to use tools or to read or write any aspect of the user's system (other than any context the user might have provided to you). You are being tasked with providing a response, but you have no ability to use tools or to read or write any aspect of the user's system (other than any context the user might have provided to you).

View File

@@ -73,6 +73,9 @@
"unnecessary_code_fade": 0.3, "unnecessary_code_fade": 0.3,
// Active pane styling settings. // Active pane styling settings.
"active_pane_modifiers": { "active_pane_modifiers": {
// The factor to grow the active pane by. Defaults to 1.0
// which gives the same size as all other panes.
"magnification": 1.0,
// Inset border size of the active pane, in pixels. // Inset border size of the active pane, in pixels.
"border_size": 0.0, "border_size": 0.0,
// Opacity of the inactive panes. 0 means transparent, 1 means opaque. // Opacity of the inactive panes. 0 means transparent, 1 means opaque.
@@ -101,12 +104,9 @@
// The second option is decimal. // The second option is decimal.
"unit": "binary" "unit": "binary"
}, },
// Determines the modifier to be used to add multiple cursors with the mouse. The open hover link mouse gestures will adapt such that it do not conflict with the multicursor modifier. // The key to use for adding multiple cursors
// // Currently "alt" or "cmd_or_ctrl" (also aliased as
// 1. Maps to `Alt` on Linux and Windows and to `Option` on MacOS: // "cmd" and "ctrl") are supported.
// "alt"
// 2. Maps `Control` on Linux and Windows and to `Command` on MacOS:
// "cmd_or_ctrl" (alias: "cmd", "ctrl")
"multi_cursor_modifier": "alt", "multi_cursor_modifier": "alt",
// Whether to enable vim modes and key bindings. // Whether to enable vim modes and key bindings.
"vim_mode": false, "vim_mode": false,
@@ -128,8 +128,6 @@
// //
// Default: true // Default: true
"restore_on_file_reopen": true, "restore_on_file_reopen": true,
// Whether to automatically close files that have been deleted on disk.
"close_on_file_delete": false,
// Size of the drop target in the editor. // Size of the drop target in the editor.
"drop_target_size": 0.2, "drop_target_size": 0.2,
// Whether the window should be closed when using 'close active item' on a window with no tabs. // Whether the window should be closed when using 'close active item' on a window with no tabs.
@@ -217,8 +215,6 @@
"show_signature_help_after_edits": false, "show_signature_help_after_edits": false,
// Whether to show code action button at start of buffer line. // Whether to show code action button at start of buffer line.
"inline_code_actions": true, "inline_code_actions": true,
// Whether to allow drag and drop text selection in buffer.
"drag_and_drop_selection": true,
// What to do when go to definition yields no results. // What to do when go to definition yields no results.
// //
// 1. Do nothing: `none` // 1. Do nothing: `none`
@@ -538,9 +534,6 @@
"function": false "function": false
} }
}, },
// Whether to resize all the panels in a dock when resizing the dock.
// Can be a combination of "left", "right" and "bottom".
"resize_all_panels_in_dock": ["left"],
"project_panel": { "project_panel": {
// Whether to show the project panel button in the status bar // Whether to show the project panel button in the status bar
"button": true, "button": true,
@@ -604,9 +597,7 @@
// 2. Never show indent guides: // 2. Never show indent guides:
// "never" // "never"
"show": "always" "show": "always"
}, }
// Whether to hide the root entry when only one folder is open in the window.
"hide_root": false
}, },
"outline_panel": { "outline_panel": {
// Whether to show the outline panel button in the status bar // Whether to show the outline panel button in the status bar
@@ -723,7 +714,7 @@
"version": "2", "version": "2",
// Whether the agent is enabled. // Whether the agent is enabled.
"enabled": true, "enabled": true,
/// What completion mode to start new threads in, if available. Can be 'normal' or 'burn'. /// What completion mode to start new threads in, if available. Can be 'normal' or 'max'.
"preferred_completion_mode": "normal", "preferred_completion_mode": "normal",
// Whether to show the agent panel button in the status bar. // Whether to show the agent panel button in the status bar.
"button": true, "button": true,
@@ -740,6 +731,13 @@
// The model to use. // The model to use.
"model": "claude-sonnet-4" "model": "claude-sonnet-4"
}, },
// The model to use when applying edits from the agent.
"editor_model": {
// The provider to use.
"provider": "zed.dev",
// The model to use.
"model": "claude-sonnet-4"
},
// Additional parameters for language model requests. When making a request to a model, parameters will be taken // Additional parameters for language model requests. When making a request to a model, parameters will be taken
// from the last entry in this list that matches the model's provider and name. In each entry, both provider // from the last entry in this list that matches the model's provider and name. In each entry, both provider
// and model are optional, so that you can specify parameters for either one. // and model are optional, so that you can specify parameters for either one.
@@ -778,6 +776,7 @@
"tools": { "tools": {
"copy_path": true, "copy_path": true,
"create_directory": true, "create_directory": true,
"create_file": true,
"delete_path": true, "delete_path": true,
"diagnostics": true, "diagnostics": true,
"edit_file": true, "edit_file": true,
@@ -1040,14 +1039,6 @@
"button": true, "button": true,
// Whether to show warnings or not by default. // Whether to show warnings or not by default.
"include_warnings": true, "include_warnings": true,
// Settings for using LSP pull diagnostics mechanism in Zed.
"lsp_pull_diagnostics": {
// Whether to pull for diagnostics or not.
"enabled": true,
// Minimum time to wait before pulling diagnostics from the language server(s).
// 0 turns the debounce off.
"debounce_ms": 50
},
// Settings for inline diagnostics // Settings for inline diagnostics
"inline": { "inline": {
// Whether to show diagnostics inline or not // Whether to show diagnostics inline or not
@@ -1323,17 +1314,7 @@
// Settings related to running tasks. // Settings related to running tasks.
"tasks": { "tasks": {
"variables": {}, "variables": {},
"enabled": true, "enabled": true
// Use LSP tasks over Zed language extension ones.
// If no LSP tasks are returned due to error/timeout or regular execution,
// Zed language extension tasks will be used instead.
//
// Other Zed tasks will still be shown:
// * Zed task from either of the task config file
// * Zed task from history (e.g. one-off task was spawned before)
//
// Default: true
"prefer_lsp": true
}, },
// An object whose keys are language names, and whose values // An object whose keys are language names, and whose values
// are arrays of filenames or extensions of files that should // are arrays of filenames or extensions of files that should
@@ -1472,8 +1453,8 @@
}, },
"Git Commit": { "Git Commit": {
"allow_rewrap": "anywhere", "allow_rewrap": "anywhere",
"soft_wrap": "editor_width", "preferred_line_length": 72,
"preferred_line_length": 72 "soft_wrap": "bounded"
}, },
"Go": { "Go": {
"code_actions_on_format": { "code_actions_on_format": {
@@ -1516,11 +1497,11 @@
} }
}, },
"LaTeX": { "LaTeX": {
"format_on_save": "on",
"formatter": "language_server", "formatter": "language_server",
"language_servers": ["texlab", "..."], "language_servers": ["texlab", "..."],
"prettier": { "prettier": {
"allowed": true, "allowed": false
"plugins": ["prettier-plugin-latex"]
} }
}, },
"Markdown": { "Markdown": {
@@ -1544,13 +1525,19 @@
"allow_rewrap": "anywhere" "allow_rewrap": "anywhere"
}, },
"Ruby": { "Ruby": {
"language_servers": ["solargraph", "!ruby-lsp", "!rubocop", "!sorbet", "!steep", "..."] "language_servers": ["solargraph", "!ruby-lsp", "!rubocop", "..."]
}, },
"SCSS": { "SCSS": {
"prettier": { "prettier": {
"allowed": true "allowed": true
} }
}, },
"SQL": {
"prettier": {
"allowed": true,
"plugins": ["prettier-plugin-sql"]
}
},
"Starlark": { "Starlark": {
"language_servers": ["starpls", "!buck2-lsp", "..."] "language_servers": ["starpls", "!buck2-lsp", "..."]
}, },
@@ -1615,9 +1602,6 @@
"version": "1", "version": "1",
"api_url": "https://api.openai.com/v1" "api_url": "https://api.openai.com/v1"
}, },
"open_router": {
"api_url": "https://openrouter.ai/api/v1"
},
"lmstudio": { "lmstudio": {
"api_url": "http://localhost:1234/api/v0" "api_url": "http://localhost:1234/api/v0"
}, },

View File

@@ -1,7 +1,3 @@
// Some example tasks for common languages.
//
// For more documentation on how to configure debug tasks,
// see: https://zed.dev/docs/debugger
[ [
{ {
"label": "Debug active PHP file", "label": "Debug active PHP file",

View File

@@ -1,5 +0,0 @@
// Project-local debug tasks
//
// For more documentation on how to configure debug tasks,
// see: https://zed.dev/docs/debugger
[]

View File

@@ -261,11 +261,6 @@
"font_style": null, "font_style": null,
"font_weight": null "font_weight": null
}, },
"namespace": {
"color": "#bfbdb6ff",
"font_style": null,
"font_weight": null
},
"number": { "number": {
"color": "#d2a6ffff", "color": "#d2a6ffff",
"font_style": null, "font_style": null,
@@ -321,16 +316,6 @@
"font_style": null, "font_style": null,
"font_weight": null "font_weight": null
}, },
"selector": {
"color": "#d2a6ffff",
"font_style": null,
"font_weight": null
},
"selector.pseudo": {
"color": "#5ac1feff",
"font_style": null,
"font_weight": null
},
"string": { "string": {
"color": "#a9d94bff", "color": "#a9d94bff",
"font_style": null, "font_style": null,
@@ -457,9 +442,9 @@
"terminal.foreground": "#5c6166ff", "terminal.foreground": "#5c6166ff",
"terminal.bright_foreground": "#5c6166ff", "terminal.bright_foreground": "#5c6166ff",
"terminal.dim_foreground": "#fcfcfcff", "terminal.dim_foreground": "#fcfcfcff",
"terminal.ansi.black": "#5c6166ff", "terminal.ansi.black": "#fcfcfcff",
"terminal.ansi.bright_black": "#3b9ee5ff", "terminal.ansi.bright_black": "#bcbec0ff",
"terminal.ansi.dim_black": "#9c9fa2ff", "terminal.ansi.dim_black": "#5c6166ff",
"terminal.ansi.red": "#ef7271ff", "terminal.ansi.red": "#ef7271ff",
"terminal.ansi.bright_red": "#febab6ff", "terminal.ansi.bright_red": "#febab6ff",
"terminal.ansi.dim_red": "#833538ff", "terminal.ansi.dim_red": "#833538ff",
@@ -478,9 +463,9 @@
"terminal.ansi.cyan": "#4dbf99ff", "terminal.ansi.cyan": "#4dbf99ff",
"terminal.ansi.bright_cyan": "#ace0cbff", "terminal.ansi.bright_cyan": "#ace0cbff",
"terminal.ansi.dim_cyan": "#2a5f4aff", "terminal.ansi.dim_cyan": "#2a5f4aff",
"terminal.ansi.white": "#fcfcfcff", "terminal.ansi.white": "#5c6166ff",
"terminal.ansi.bright_white": "#fcfcfcff", "terminal.ansi.bright_white": "#5c6166ff",
"terminal.ansi.dim_white": "#bcbec0ff", "terminal.ansi.dim_white": "#9c9fa2ff",
"link_text.hover": "#3b9ee5ff", "link_text.hover": "#3b9ee5ff",
"conflict": "#f1ad49ff", "conflict": "#f1ad49ff",
"conflict.background": "#ffeedaff", "conflict.background": "#ffeedaff",
@@ -647,11 +632,6 @@
"font_style": null, "font_style": null,
"font_weight": null "font_weight": null
}, },
"namespace": {
"color": "#5c6166ff",
"font_style": null,
"font_weight": null
},
"number": { "number": {
"color": "#a37accff", "color": "#a37accff",
"font_style": null, "font_style": null,
@@ -707,16 +687,6 @@
"font_style": null, "font_style": null,
"font_weight": null "font_weight": null
}, },
"selector": {
"color": "#a37accff",
"font_style": null,
"font_weight": null
},
"selector.pseudo": {
"color": "#3b9ee5ff",
"font_style": null,
"font_weight": null
},
"string": { "string": {
"color": "#86b300ff", "color": "#86b300ff",
"font_style": null, "font_style": null,
@@ -1033,11 +1003,6 @@
"font_style": null, "font_style": null,
"font_weight": null "font_weight": null
}, },
"namespace": {
"color": "#cccac2ff",
"font_style": null,
"font_weight": null
},
"number": { "number": {
"color": "#dfbfffff", "color": "#dfbfffff",
"font_style": null, "font_style": null,
@@ -1093,16 +1058,6 @@
"font_style": null, "font_style": null,
"font_weight": null "font_weight": null
}, },
"selector": {
"color": "#dfbfffff",
"font_style": null,
"font_weight": null
},
"selector.pseudo": {
"color": "#72cffeff",
"font_style": null,
"font_weight": null
},
"string": { "string": {
"color": "#d4fe7fff", "color": "#d4fe7fff",
"font_style": null, "font_style": null,

View File

@@ -270,11 +270,6 @@
"font_style": null, "font_style": null,
"font_weight": null "font_weight": null
}, },
"namespace": {
"color": "#83a598ff",
"font_style": null,
"font_weight": null
},
"number": { "number": {
"color": "#d3869bff", "color": "#d3869bff",
"font_style": null, "font_style": null,
@@ -330,16 +325,6 @@
"font_style": null, "font_style": null,
"font_weight": null "font_weight": null
}, },
"selector": {
"color": "#fabd2eff",
"font_style": null,
"font_weight": null
},
"selector.pseudo": {
"color": "#83a598ff",
"font_style": null,
"font_weight": null
},
"string": { "string": {
"color": "#b8bb25ff", "color": "#b8bb25ff",
"font_style": null, "font_style": null,
@@ -670,11 +655,6 @@
"font_style": null, "font_style": null,
"font_weight": null "font_weight": null
}, },
"namespace": {
"color": "#83a598ff",
"font_style": null,
"font_weight": null
},
"number": { "number": {
"color": "#d3869bff", "color": "#d3869bff",
"font_style": null, "font_style": null,
@@ -730,16 +710,6 @@
"font_style": null, "font_style": null,
"font_weight": null "font_weight": null
}, },
"selector": {
"color": "#fabd2eff",
"font_style": null,
"font_weight": null
},
"selector.pseudo": {
"color": "#83a598ff",
"font_style": null,
"font_weight": null
},
"string": { "string": {
"color": "#b8bb25ff", "color": "#b8bb25ff",
"font_style": null, "font_style": null,
@@ -1070,11 +1040,6 @@
"font_style": null, "font_style": null,
"font_weight": null "font_weight": null
}, },
"namespace": {
"color": "#83a598ff",
"font_style": null,
"font_weight": null
},
"number": { "number": {
"color": "#d3869bff", "color": "#d3869bff",
"font_style": null, "font_style": null,
@@ -1130,16 +1095,6 @@
"font_style": null, "font_style": null,
"font_weight": null "font_weight": null
}, },
"selector": {
"color": "#fabd2eff",
"font_style": null,
"font_weight": null
},
"selector.pseudo": {
"color": "#83a598ff",
"font_style": null,
"font_weight": null
},
"string": { "string": {
"color": "#b8bb25ff", "color": "#b8bb25ff",
"font_style": null, "font_style": null,
@@ -1272,9 +1227,9 @@
"terminal.foreground": "#282828ff", "terminal.foreground": "#282828ff",
"terminal.bright_foreground": "#282828ff", "terminal.bright_foreground": "#282828ff",
"terminal.dim_foreground": "#fbf1c7ff", "terminal.dim_foreground": "#fbf1c7ff",
"terminal.ansi.black": "#282828ff", "terminal.ansi.black": "#fbf1c7ff",
"terminal.ansi.bright_black": "#0b6678ff", "terminal.ansi.bright_black": "#b0a189ff",
"terminal.ansi.dim_black": "#5f5650ff", "terminal.ansi.dim_black": "#282828ff",
"terminal.ansi.red": "#9d0308ff", "terminal.ansi.red": "#9d0308ff",
"terminal.ansi.bright_red": "#db8b7aff", "terminal.ansi.bright_red": "#db8b7aff",
"terminal.ansi.dim_red": "#4e1207ff", "terminal.ansi.dim_red": "#4e1207ff",
@@ -1293,9 +1248,9 @@
"terminal.ansi.cyan": "#437b59ff", "terminal.ansi.cyan": "#437b59ff",
"terminal.ansi.bright_cyan": "#9fbca8ff", "terminal.ansi.bright_cyan": "#9fbca8ff",
"terminal.ansi.dim_cyan": "#253e2eff", "terminal.ansi.dim_cyan": "#253e2eff",
"terminal.ansi.white": "#fbf1c7ff", "terminal.ansi.white": "#282828ff",
"terminal.ansi.bright_white": "#fbf1c7ff", "terminal.ansi.bright_white": "#282828ff",
"terminal.ansi.dim_white": "#b0a189ff", "terminal.ansi.dim_white": "#73675eff",
"link_text.hover": "#0b6678ff", "link_text.hover": "#0b6678ff",
"version_control.added": "#797410ff", "version_control.added": "#797410ff",
"version_control.modified": "#b57615ff", "version_control.modified": "#b57615ff",
@@ -1470,11 +1425,6 @@
"font_style": null, "font_style": null,
"font_weight": null "font_weight": null
}, },
"namespace": {
"color": "#066578ff",
"font_style": null,
"font_weight": null
},
"number": { "number": {
"color": "#8f3e71ff", "color": "#8f3e71ff",
"font_style": null, "font_style": null,
@@ -1530,16 +1480,6 @@
"font_style": null, "font_style": null,
"font_weight": null "font_weight": null
}, },
"selector": {
"color": "#b57613ff",
"font_style": null,
"font_weight": null
},
"selector.pseudo": {
"color": "#0b6678ff",
"font_style": null,
"font_weight": null
},
"string": { "string": {
"color": "#79740eff", "color": "#79740eff",
"font_style": null, "font_style": null,
@@ -1672,9 +1612,9 @@
"terminal.foreground": "#282828ff", "terminal.foreground": "#282828ff",
"terminal.bright_foreground": "#282828ff", "terminal.bright_foreground": "#282828ff",
"terminal.dim_foreground": "#f9f5d7ff", "terminal.dim_foreground": "#f9f5d7ff",
"terminal.ansi.black": "#282828ff", "terminal.ansi.black": "#f9f5d7ff",
"terminal.ansi.bright_black": "#73675eff", "terminal.ansi.bright_black": "#b0a189ff",
"terminal.ansi.dim_black": "#f9f5d7ff", "terminal.ansi.dim_black": "#282828ff",
"terminal.ansi.red": "#9d0308ff", "terminal.ansi.red": "#9d0308ff",
"terminal.ansi.bright_red": "#db8b7aff", "terminal.ansi.bright_red": "#db8b7aff",
"terminal.ansi.dim_red": "#4e1207ff", "terminal.ansi.dim_red": "#4e1207ff",
@@ -1693,9 +1633,9 @@
"terminal.ansi.cyan": "#437b59ff", "terminal.ansi.cyan": "#437b59ff",
"terminal.ansi.bright_cyan": "#9fbca8ff", "terminal.ansi.bright_cyan": "#9fbca8ff",
"terminal.ansi.dim_cyan": "#253e2eff", "terminal.ansi.dim_cyan": "#253e2eff",
"terminal.ansi.white": "#f9f5d7ff", "terminal.ansi.white": "#282828ff",
"terminal.ansi.bright_white": "#f9f5d7ff", "terminal.ansi.bright_white": "#282828ff",
"terminal.ansi.dim_white": "#b0a189ff", "terminal.ansi.dim_white": "#73675eff",
"link_text.hover": "#0b6678ff", "link_text.hover": "#0b6678ff",
"version_control.added": "#797410ff", "version_control.added": "#797410ff",
"version_control.modified": "#b57615ff", "version_control.modified": "#b57615ff",
@@ -1870,11 +1810,6 @@
"font_style": null, "font_style": null,
"font_weight": null "font_weight": null
}, },
"namespace": {
"color": "#066578ff",
"font_style": null,
"font_weight": null
},
"number": { "number": {
"color": "#8f3e71ff", "color": "#8f3e71ff",
"font_style": null, "font_style": null,
@@ -1930,16 +1865,6 @@
"font_style": null, "font_style": null,
"font_weight": null "font_weight": null
}, },
"selector": {
"color": "#b57613ff",
"font_style": null,
"font_weight": null
},
"selector.pseudo": {
"color": "#0b6678ff",
"font_style": null,
"font_weight": null
},
"string": { "string": {
"color": "#79740eff", "color": "#79740eff",
"font_style": null, "font_style": null,
@@ -2072,9 +1997,9 @@
"terminal.foreground": "#282828ff", "terminal.foreground": "#282828ff",
"terminal.bright_foreground": "#282828ff", "terminal.bright_foreground": "#282828ff",
"terminal.dim_foreground": "#f2e5bcff", "terminal.dim_foreground": "#f2e5bcff",
"terminal.ansi.black": "#282828ff", "terminal.ansi.black": "#f2e5bcff",
"terminal.ansi.bright_black": "#73675eff", "terminal.ansi.bright_black": "#b0a189ff",
"terminal.ansi.dim_black": "#f2e5bcff", "terminal.ansi.dim_black": "#282828ff",
"terminal.ansi.red": "#9d0308ff", "terminal.ansi.red": "#9d0308ff",
"terminal.ansi.bright_red": "#db8b7aff", "terminal.ansi.bright_red": "#db8b7aff",
"terminal.ansi.dim_red": "#4e1207ff", "terminal.ansi.dim_red": "#4e1207ff",
@@ -2093,9 +2018,9 @@
"terminal.ansi.cyan": "#437b59ff", "terminal.ansi.cyan": "#437b59ff",
"terminal.ansi.bright_cyan": "#9fbca8ff", "terminal.ansi.bright_cyan": "#9fbca8ff",
"terminal.ansi.dim_cyan": "#253e2eff", "terminal.ansi.dim_cyan": "#253e2eff",
"terminal.ansi.white": "#f2e5bcff", "terminal.ansi.white": "#282828ff",
"terminal.ansi.bright_white": "#f2e5bcff", "terminal.ansi.bright_white": "#282828ff",
"terminal.ansi.dim_white": "#b0a189ff", "terminal.ansi.dim_white": "#73675eff",
"link_text.hover": "#0b6678ff", "link_text.hover": "#0b6678ff",
"version_control.added": "#797410ff", "version_control.added": "#797410ff",
"version_control.modified": "#b57615ff", "version_control.modified": "#b57615ff",
@@ -2270,11 +2195,6 @@
"font_style": null, "font_style": null,
"font_weight": null "font_weight": null
}, },
"namespace": {
"color": "#066578ff",
"font_style": null,
"font_weight": null
},
"number": { "number": {
"color": "#8f3e71ff", "color": "#8f3e71ff",
"font_style": null, "font_style": null,
@@ -2330,16 +2250,6 @@
"font_style": null, "font_style": null,
"font_weight": null "font_weight": null
}, },
"selector": {
"color": "#b57613ff",
"font_style": null,
"font_weight": null
},
"selector.pseudo": {
"color": "#0b6678ff",
"font_style": null,
"font_weight": null
},
"string": { "string": {
"color": "#79740eff", "color": "#79740eff",
"font_style": null, "font_style": null,

View File

@@ -99,8 +99,6 @@
"version_control.added": "#27a657ff", "version_control.added": "#27a657ff",
"version_control.modified": "#d3b020ff", "version_control.modified": "#d3b020ff",
"version_control.deleted": "#e06c76ff", "version_control.deleted": "#e06c76ff",
"version_control.conflict_marker.ours": "#a1c1811a",
"version_control.conflict_marker.theirs": "#74ade81a",
"conflict": "#dec184ff", "conflict": "#dec184ff",
"conflict.background": "#dec1841a", "conflict.background": "#dec1841a",
"conflict.border": "#5d4c2fff", "conflict.border": "#5d4c2fff",
@@ -266,11 +264,6 @@
"font_style": null, "font_style": null,
"font_weight": null "font_weight": null
}, },
"namespace": {
"color": "#dce0e5ff",
"font_style": null,
"font_weight": null
},
"number": { "number": {
"color": "#bf956aff", "color": "#bf956aff",
"font_style": null, "font_style": null,
@@ -326,16 +319,6 @@
"font_style": null, "font_style": null,
"font_weight": null "font_weight": null
}, },
"selector": {
"color": "#dfc184ff",
"font_style": null,
"font_weight": null
},
"selector.pseudo": {
"color": "#74ade8ff",
"font_style": null,
"font_weight": null
},
"string": { "string": {
"color": "#a1c181ff", "color": "#a1c181ff",
"font_style": null, "font_style": null,
@@ -467,9 +450,9 @@
"terminal.foreground": "#242529ff", "terminal.foreground": "#242529ff",
"terminal.bright_foreground": "#242529ff", "terminal.bright_foreground": "#242529ff",
"terminal.dim_foreground": "#fafafaff", "terminal.dim_foreground": "#fafafaff",
"terminal.ansi.black": "#242529ff", "terminal.ansi.black": "#fafafaff",
"terminal.ansi.bright_black": "#242529ff", "terminal.ansi.bright_black": "#aaaaaaff",
"terminal.ansi.dim_black": "#97979aff", "terminal.ansi.dim_black": "#242529ff",
"terminal.ansi.red": "#d36151ff", "terminal.ansi.red": "#d36151ff",
"terminal.ansi.bright_red": "#f0b0a4ff", "terminal.ansi.bright_red": "#f0b0a4ff",
"terminal.ansi.dim_red": "#6f312aff", "terminal.ansi.dim_red": "#6f312aff",
@@ -488,9 +471,9 @@
"terminal.ansi.cyan": "#3a82b7ff", "terminal.ansi.cyan": "#3a82b7ff",
"terminal.ansi.bright_cyan": "#a3bedaff", "terminal.ansi.bright_cyan": "#a3bedaff",
"terminal.ansi.dim_cyan": "#254058ff", "terminal.ansi.dim_cyan": "#254058ff",
"terminal.ansi.white": "#fafafaff", "terminal.ansi.white": "#242529ff",
"terminal.ansi.bright_white": "#fafafaff", "terminal.ansi.bright_white": "#242529ff",
"terminal.ansi.dim_white": "#aaaaaaff", "terminal.ansi.dim_white": "#97979aff",
"link_text.hover": "#5c78e2ff", "link_text.hover": "#5c78e2ff",
"version_control.added": "#27a657ff", "version_control.added": "#27a657ff",
"version_control.modified": "#d3b020ff", "version_control.modified": "#d3b020ff",
@@ -660,11 +643,6 @@
"font_style": null, "font_style": null,
"font_weight": null "font_weight": null
}, },
"namespace": {
"color": "#242529ff",
"font_style": null,
"font_weight": null
},
"number": { "number": {
"color": "#ad6e25ff", "color": "#ad6e25ff",
"font_style": null, "font_style": null,
@@ -720,16 +698,6 @@
"font_style": null, "font_style": null,
"font_weight": null "font_weight": null
}, },
"selector": {
"color": "#669f59ff",
"font_style": null,
"font_weight": null
},
"selector.pseudo": {
"color": "#5c78e2ff",
"font_style": null,
"font_weight": null
},
"string": { "string": {
"color": "#649f57ff", "color": "#649f57ff",
"font_style": null, "font_style": null,

View File

@@ -311,31 +311,6 @@ impl ActivityIndicator {
}); });
} }
if let Some(session) = self
.project
.read(cx)
.dap_store()
.read(cx)
.sessions()
.find(|s| !s.read(cx).is_started())
{
return Some(Content {
icon: Some(
Icon::new(IconName::ArrowCircle)
.size(IconSize::Small)
.with_animation(
"arrow-circle",
Animation::new(Duration::from_secs(2)).repeat(),
|icon, delta| icon.transform(Transformation::rotate(percentage(delta))),
)
.into_any_element(),
),
message: format!("Debug: {}", session.read(cx).adapter()),
tooltip_message: Some(session.read(cx).label().to_string()),
on_click: None,
});
}
let current_job = self let current_job = self
.project .project
.read(cx) .read(cx)
@@ -497,7 +472,7 @@ impl ActivityIndicator {
})), })),
tooltip_message: None, tooltip_message: None,
}), }),
AutoUpdateStatus::Downloading { version } => Some(Content { AutoUpdateStatus::Downloading => Some(Content {
icon: Some( icon: Some(
Icon::new(IconName::Download) Icon::new(IconName::Download)
.size(IconSize::Small) .size(IconSize::Small)
@@ -507,9 +482,9 @@ impl ActivityIndicator {
on_click: Some(Arc::new(|this, window, cx| { on_click: Some(Arc::new(|this, window, cx| {
this.dismiss_error_message(&DismissErrorMessage, window, cx) this.dismiss_error_message(&DismissErrorMessage, window, cx)
})), })),
tooltip_message: Some(Self::version_tooltip_message(&version)), tooltip_message: None,
}), }),
AutoUpdateStatus::Installing { version } => Some(Content { AutoUpdateStatus::Installing => Some(Content {
icon: Some( icon: Some(
Icon::new(IconName::Download) Icon::new(IconName::Download)
.size(IconSize::Small) .size(IconSize::Small)
@@ -519,7 +494,7 @@ impl ActivityIndicator {
on_click: Some(Arc::new(|this, window, cx| { on_click: Some(Arc::new(|this, window, cx| {
this.dismiss_error_message(&DismissErrorMessage, window, cx) this.dismiss_error_message(&DismissErrorMessage, window, cx)
})), })),
tooltip_message: Some(Self::version_tooltip_message(&version)), tooltip_message: None,
}), }),
AutoUpdateStatus::Updated { AutoUpdateStatus::Updated {
binary_path, binary_path,
@@ -533,7 +508,7 @@ impl ActivityIndicator {
}; };
move |_, _, cx| workspace::reload(&reload, cx) move |_, _, cx| workspace::reload(&reload, cx)
})), })),
tooltip_message: Some(Self::version_tooltip_message(&version)), tooltip_message: Some(Self::install_version_tooltip_message(&version)),
}), }),
AutoUpdateStatus::Errored => Some(Content { AutoUpdateStatus::Errored => Some(Content {
icon: Some( icon: Some(
@@ -573,8 +548,8 @@ impl ActivityIndicator {
None None
} }
fn version_tooltip_message(version: &VersionCheckType) -> String { fn install_version_tooltip_message(version: &VersionCheckType) -> String {
format!("Version: {}", { format!("Install version: {}", {
match version { match version {
auto_update::VersionCheckType::Sha(sha) => format!("{}", sha.short()), auto_update::VersionCheckType::Sha(sha) => format!("{}", sha.short()),
auto_update::VersionCheckType::Semantic(semantic_version) => { auto_update::VersionCheckType::Semantic(semantic_version) => {
@@ -724,17 +699,17 @@ mod tests {
use super::*; use super::*;
#[test] #[test]
fn test_version_tooltip_message() { fn test_install_version_tooltip_message() {
let message = ActivityIndicator::version_tooltip_message(&VersionCheckType::Semantic( let message = ActivityIndicator::install_version_tooltip_message(
SemanticVersion::new(1, 0, 0), &VersionCheckType::Semantic(SemanticVersion::new(1, 0, 0)),
)); );
assert_eq!(message, "Version: 1.0.0"); assert_eq!(message, "Install version: 1.0.0");
let message = ActivityIndicator::version_tooltip_message(&VersionCheckType::Sha( let message = ActivityIndicator::install_version_tooltip_message(&VersionCheckType::Sha(
AppCommitSha::new("14d9a4189f058d8736339b06ff2340101eaea5af".to_string()), AppCommitSha::new("14d9a4189f058d8736339b06ff2340101eaea5af".to_string()),
)); ));
assert_eq!(message, "Version: 14d9a41…"); assert_eq!(message, "Install version: 14d9a41…");
} }
} }

View File

@@ -25,6 +25,7 @@ assistant_context_editor.workspace = true
assistant_slash_command.workspace = true assistant_slash_command.workspace = true
assistant_slash_commands.workspace = true assistant_slash_commands.workspace = true
assistant_tool.workspace = true assistant_tool.workspace = true
async-watch.workspace = true
audio.workspace = true audio.workspace = true
buffer_diff.workspace = true buffer_diff.workspace = true
chrono.workspace = true chrono.workspace = true
@@ -45,7 +46,6 @@ git.workspace = true
gpui.workspace = true gpui.workspace = true
heed.workspace = true heed.workspace = true
html_to_markdown.workspace = true html_to_markdown.workspace = true
indoc.workspace = true
http_client.workspace = true http_client.workspace = true
indexed_docs.workspace = true indexed_docs.workspace = true
inventory.workspace = true inventory.workspace = true
@@ -78,7 +78,6 @@ serde_json.workspace = true
serde_json_lenient.workspace = true serde_json_lenient.workspace = true
settings.workspace = true settings.workspace = true
smol.workspace = true smol.workspace = true
sqlez.workspace = true
streaming_diff.workspace = true streaming_diff.workspace = true
telemetry.workspace = true telemetry.workspace = true
telemetry_events.workspace = true telemetry_events.workspace = true
@@ -94,21 +93,17 @@ ui_input.workspace = true
urlencoding.workspace = true urlencoding.workspace = true
util.workspace = true util.workspace = true
uuid.workspace = true uuid.workspace = true
watch.workspace = true
workspace-hack.workspace = true workspace-hack.workspace = true
workspace.workspace = true workspace.workspace = true
zed_actions.workspace = true zed_actions.workspace = true
zed_llm_client.workspace = true zed_llm_client.workspace = true
zstd.workspace = true
[dev-dependencies] [dev-dependencies]
assistant_tools.workspace = true
buffer_diff = { workspace = true, features = ["test-support"] } buffer_diff = { workspace = true, features = ["test-support"] }
editor = { workspace = true, features = ["test-support"] } editor = { workspace = true, features = ["test-support"] }
gpui = { workspace = true, "features" = ["test-support"] } gpui = { workspace = true, "features" = ["test-support"] }
indoc.workspace = true indoc.workspace = true
language = { workspace = true, "features" = ["test-support"] } language = { workspace = true, "features" = ["test-support"] }
language_model = { workspace = true, "features" = ["test-support"] } language_model = { workspace = true, "features" = ["test-support"] }
pretty_assertions.workspace = true
project = { workspace = true, features = ["test-support"] } project = { workspace = true, features = ["test-support"] }
rand.workspace = true rand.workspace = true

View File

@@ -1,8 +1,9 @@
use crate::AgentPanel;
use crate::context::{AgentContextHandle, RULES_ICON}; use crate::context::{AgentContextHandle, RULES_ICON};
use crate::context_picker::{ContextPicker, MentionLink}; use crate::context_picker::{ContextPicker, MentionLink};
use crate::context_store::ContextStore; use crate::context_store::ContextStore;
use crate::context_strip::{ContextStrip, ContextStripEvent, SuggestContextKind}; use crate::context_strip::{ContextStrip, ContextStripEvent, SuggestContextKind};
use crate::message_editor::{extract_message_creases, insert_message_creases}; use crate::message_editor::insert_message_creases;
use crate::thread::{ use crate::thread::{
LastRestoreCheckpoint, MessageCrease, MessageId, MessageSegment, Thread, ThreadError, LastRestoreCheckpoint, MessageCrease, MessageId, MessageSegment, Thread, ThreadError,
ThreadEvent, ThreadFeedback, ThreadSummary, ThreadEvent, ThreadFeedback, ThreadSummary,
@@ -12,7 +13,6 @@ use crate::tool_use::{PendingToolUseStatus, ToolUse};
use crate::ui::{ use crate::ui::{
AddedContext, AgentNotification, AgentNotificationEvent, AnimatedLabel, ContextPill, AddedContext, AgentNotification, AgentNotificationEvent, AnimatedLabel, ContextPill,
}; };
use crate::{AgentPanel, ModelUsageContext};
use agent_settings::{AgentSettings, NotifyWhenAgentWaiting}; use agent_settings::{AgentSettings, NotifyWhenAgentWaiting};
use anyhow::Context as _; use anyhow::Context as _;
use assistant_tool::ToolUseStatus; use assistant_tool::ToolUseStatus;
@@ -55,7 +55,6 @@ use util::ResultExt as _;
use util::markdown::MarkdownCodeBlock; use util::markdown::MarkdownCodeBlock;
use workspace::{CollaboratorId, Workspace}; use workspace::{CollaboratorId, Workspace};
use zed_actions::assistant::OpenRulesLibrary; use zed_actions::assistant::OpenRulesLibrary;
use zed_llm_client::CompletionIntent;
pub struct ActiveThread { pub struct ActiveThread {
context_store: Entity<ContextStore>, context_store: Entity<ContextStore>,
@@ -999,7 +998,7 @@ impl ActiveThread {
ThreadEvent::Stopped(reason) => match reason { ThreadEvent::Stopped(reason) => match reason {
Ok(StopReason::EndTurn | StopReason::MaxTokens) => { Ok(StopReason::EndTurn | StopReason::MaxTokens) => {
let used_tools = self.thread.read(cx).used_tools_since_last_user_message(); let used_tools = self.thread.read(cx).used_tools_since_last_user_message();
self.play_notification_sound(window, cx); self.play_notification_sound(cx);
self.show_notification( self.show_notification(
if used_tools { if used_tools {
"Finished running tools" "Finished running tools"
@@ -1014,18 +1013,9 @@ impl ActiveThread {
_ => {} _ => {}
}, },
ThreadEvent::ToolConfirmationNeeded => { ThreadEvent::ToolConfirmationNeeded => {
self.play_notification_sound(window, cx); self.play_notification_sound(cx);
self.show_notification("Waiting for tool confirmation", IconName::Info, window, cx); self.show_notification("Waiting for tool confirmation", IconName::Info, window, cx);
} }
ThreadEvent::ToolUseLimitReached => {
self.play_notification_sound(window, cx);
self.show_notification(
"Consecutive tool use limit reached.",
IconName::Warning,
window,
cx,
);
}
ThreadEvent::StreamedAssistantText(message_id, text) => { ThreadEvent::StreamedAssistantText(message_id, text) => {
if let Some(rendered_message) = self.rendered_messages_by_id.get_mut(&message_id) { if let Some(rendered_message) = self.rendered_messages_by_id.get_mut(&message_id) {
rendered_message.append_text(text, cx); rendered_message.append_text(text, cx);
@@ -1144,10 +1134,6 @@ impl ActiveThread {
cx, cx,
); );
} }
ThreadEvent::ProfileChanged => {
self.save_thread(cx);
cx.notify();
}
} }
} }
@@ -1164,9 +1150,9 @@ impl ActiveThread {
cx.notify(); cx.notify();
} }
fn play_notification_sound(&self, window: &Window, cx: &mut App) { fn play_notification_sound(&self, cx: &mut App) {
let settings = AgentSettings::get_global(cx); let settings = AgentSettings::get_global(cx);
if settings.play_sound_when_agent_done && !window.is_window_active() { if settings.play_sound_when_agent_done {
Audio::play_sound(Sound::AgentDone, cx); Audio::play_sound(Sound::AgentDone, cx);
} }
} }
@@ -1352,7 +1338,6 @@ impl ActiveThread {
Some(self.text_thread_store.downgrade()), Some(self.text_thread_store.downgrade()),
context_picker_menu_handle.clone(), context_picker_menu_handle.clone(),
SuggestContextKind::File, SuggestContextKind::File,
ModelUsageContext::Thread(self.thread.clone()),
window, window,
cx, cx,
) )
@@ -1451,7 +1436,6 @@ impl ActiveThread {
let request = language_model::LanguageModelRequest { let request = language_model::LanguageModelRequest {
thread_id: None, thread_id: None,
prompt_id: None, prompt_id: None,
intent: None,
mode: None, mode: None,
messages: vec![request_message], messages: vec![request_message],
tools: vec![], tools: vec![],
@@ -1522,25 +1506,36 @@ impl ActiveThread {
} }
fn paste(&mut self, _: &Paste, _window: &mut Window, cx: &mut Context<Self>) { fn paste(&mut self, _: &Paste, _window: &mut Window, cx: &mut Context<Self>) {
attach_pasted_images_as_context(&self.context_store, cx); let images = cx
.read_from_clipboard()
.map(|item| {
item.into_entries()
.filter_map(|entry| {
if let ClipboardEntry::Image(image) = entry {
Some(image)
} else {
None
}
})
.collect::<Vec<_>>()
})
.unwrap_or_default();
if images.is_empty() {
return;
}
cx.stop_propagation();
self.context_store.update(cx, |store, cx| {
for image in images {
store.add_image_instance(Arc::new(image), cx);
}
});
} }
fn cancel_editing_message( fn cancel_editing_message(&mut self, _: &menu::Cancel, _: &mut Window, cx: &mut Context<Self>) {
&mut self,
_: &menu::Cancel,
window: &mut Window,
cx: &mut Context<Self>,
) {
self.editing_message.take(); self.editing_message.take();
cx.notify(); cx.notify();
if let Some(workspace) = self.workspace.upgrade() {
workspace.update(cx, |workspace, cx| {
if let Some(panel) = workspace.panel::<AgentPanel>(cx) {
panel.focus_handle(cx).focus(window);
}
});
}
} }
fn confirm_editing_message( fn confirm_editing_message(
@@ -1567,8 +1562,6 @@ impl ActiveThread {
let edited_text = state.editor.read(cx).text(cx); let edited_text = state.editor.read(cx).text(cx);
let creases = state.editor.update(cx, extract_message_creases);
let new_context = self let new_context = self
.context_store .context_store
.read(cx) .read(cx)
@@ -1593,7 +1586,6 @@ impl ActiveThread {
message_id, message_id,
Role::User, Role::User,
vec![MessageSegment::Text(edited_text)], vec![MessageSegment::Text(edited_text)],
creases,
Some(context.loaded_context), Some(context.loaded_context),
checkpoint.ok(), checkpoint.ok(),
cx, cx,
@@ -1605,12 +1597,7 @@ impl ActiveThread {
this.thread.update(cx, |thread, cx| { this.thread.update(cx, |thread, cx| {
thread.advance_prompt_id(); thread.advance_prompt_id();
thread.send_to_model( thread.send_to_model(model.model, Some(window.window_handle()), cx);
model.model,
CompletionIntent::UserPrompt,
Some(window.window_handle()),
cx,
);
}); });
this._load_edited_message_context_task = None; this._load_edited_message_context_task = None;
cx.notify(); cx.notify();
@@ -1788,31 +1775,12 @@ impl ActiveThread {
fn render_message(&self, ix: usize, window: &mut Window, cx: &mut Context<Self>) -> AnyElement { fn render_message(&self, ix: usize, window: &mut Window, cx: &mut Context<Self>) -> AnyElement {
let message_id = self.messages[ix]; let message_id = self.messages[ix];
let workspace = self.workspace.clone(); let Some(message) = self.thread.read(cx).message(message_id) else {
let thread = self.thread.read(cx);
let is_first_message = ix == 0;
let is_last_message = ix == self.messages.len() - 1;
let Some(message) = thread.message(message_id) else {
return Empty.into_any(); return Empty.into_any();
}; };
let is_generating = thread.is_generating();
let is_generating_stale = thread.is_generation_stale().unwrap_or(false);
let loading_dots = (is_generating && is_last_message).then(|| {
h_flex()
.h_8()
.my_3()
.mx_5()
.when(is_generating_stale || message.is_hidden, |this| {
this.child(AnimatedLabel::new("").size(LabelSize::Small))
})
});
if message.is_hidden { if message.is_hidden {
return div().children(loading_dots).into_any(); return Empty.into_any();
} }
let message_creases = message.creases.clone(); let message_creases = message.creases.clone();
@@ -1821,16 +1789,26 @@ impl ActiveThread {
return Empty.into_any(); return Empty.into_any();
}; };
let workspace = self.workspace.clone();
let thread = self.thread.read(cx);
// Get all the data we need from thread before we start using it in closures // Get all the data we need from thread before we start using it in closures
let checkpoint = thread.checkpoint_for_message(message_id); let checkpoint = thread.checkpoint_for_message(message_id);
let configured_model = thread.configured_model().map(|m| m.model);
let added_context = thread let added_context = thread
.context_for_message(message_id) .context_for_message(message_id)
.map(|context| AddedContext::new_attached(context, configured_model.as_ref(), cx)) .map(|context| AddedContext::new_attached(context, cx))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let tool_uses = thread.tool_uses_for_message(message_id, cx); let tool_uses = thread.tool_uses_for_message(message_id, cx);
let has_tool_uses = !tool_uses.is_empty(); let has_tool_uses = !tool_uses.is_empty();
let is_generating = thread.is_generating();
let is_generating_stale = thread.is_generation_stale().unwrap_or(false);
let is_first_message = ix == 0;
let is_last_message = ix == self.messages.len() - 1;
let loading_dots = (is_generating_stale && is_last_message)
.then(|| AnimatedLabel::new("").size(LabelSize::Small));
let editing_message_state = self let editing_message_state = self
.editing_message .editing_message
@@ -1840,7 +1818,6 @@ impl ActiveThread {
let colors = cx.theme().colors(); let colors = cx.theme().colors();
let editor_bg_color = colors.editor_background; let editor_bg_color = colors.editor_background;
let panel_bg = colors.panel_background;
let open_as_markdown = IconButton::new(("open-as-markdown", ix), IconName::DocumentText) let open_as_markdown = IconButton::new(("open-as-markdown", ix), IconName::DocumentText)
.icon_size(IconSize::XSmall) .icon_size(IconSize::XSmall)
@@ -1861,6 +1838,7 @@ impl ActiveThread {
const RESPONSE_PADDING_X: Pixels = px(19.); const RESPONSE_PADDING_X: Pixels = px(19.);
let show_feedback = thread.is_turn_end(ix); let show_feedback = thread.is_turn_end(ix);
let feedback_container = h_flex() let feedback_container = h_flex()
.group("feedback_container") .group("feedback_container")
.mt_1() .mt_1()
@@ -2157,14 +2135,16 @@ impl ActiveThread {
message_id > *editing_message_id message_id > *editing_message_id
}); });
let panel_background = cx.theme().colors().panel_background;
let backdrop = div() let backdrop = div()
.id(("backdrop", ix)) .id("backdrop")
.size_full() .stop_mouse_events_except_scroll()
.absolute() .absolute()
.inset_0() .inset_0()
.bg(panel_bg) .size_full()
.bg(panel_background)
.opacity(0.8) .opacity(0.8)
.block_mouse_except_scroll()
.on_click(cx.listener(Self::handle_cancel_click)); .on_click(cx.listener(Self::handle_cancel_click));
v_flex() v_flex()
@@ -2246,7 +2226,17 @@ impl ActiveThread {
parent.child(self.render_rules_item(cx)) parent.child(self.render_rules_item(cx))
}) })
.child(styled_message) .child(styled_message)
.children(loading_dots) .when(is_generating && is_last_message, |this| {
this.child(
h_flex()
.h_8()
.mt_2()
.mb_4()
.ml_4()
.py_1p5()
.when_some(loading_dots, |this, loading_dots| this.child(loading_dots)),
)
})
.when(show_feedback, move |parent| { .when(show_feedback, move |parent| {
parent.child(feedback_items).when_some( parent.child(feedback_items).when_some(
self.open_feedback_editors.get(&message_id), self.open_feedback_editors.get(&message_id),
@@ -3631,38 +3621,6 @@ pub(crate) fn open_context(
} }
} }
pub(crate) fn attach_pasted_images_as_context(
context_store: &Entity<ContextStore>,
cx: &mut App,
) -> bool {
let images = cx
.read_from_clipboard()
.map(|item| {
item.into_entries()
.filter_map(|entry| {
if let ClipboardEntry::Image(image) = entry {
Some(image)
} else {
None
}
})
.collect::<Vec<_>>()
})
.unwrap_or_default();
if images.is_empty() {
return false;
}
cx.stop_propagation();
context_store.update(cx, |store, cx| {
for image in images {
store.add_image_instance(Arc::new(image), cx);
}
});
true
}
fn open_editor_at_position( fn open_editor_at_position(
project_path: project::ProjectPath, project_path: project::ProjectPath,
target_position: Point, target_position: Point,
@@ -3692,13 +3650,10 @@ fn open_editor_at_position(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use assistant_tool::{ToolRegistry, ToolWorkingSet}; use assistant_tool::{ToolRegistry, ToolWorkingSet};
use editor::{EditorSettings, display_map::CreaseMetadata}; use editor::EditorSettings;
use fs::FakeFs; use fs::FakeFs;
use gpui::{AppContext, TestAppContext, VisualTestContext}; use gpui::{AppContext, TestAppContext, VisualTestContext};
use language_model::{ use language_model::{LanguageModel, fake_provider::FakeLanguageModel};
ConfiguredModel, LanguageModel, LanguageModelRegistry,
fake_provider::{FakeLanguageModel, FakeLanguageModelProvider},
};
use project::Project; use project::Project;
use prompt_store::PromptBuilder; use prompt_store::PromptBuilder;
use serde_json::json; use serde_json::json;
@@ -3736,8 +3691,7 @@ mod tests {
// Stream response to user message // Stream response to user message
thread.update(cx, |thread, cx| { thread.update(cx, |thread, cx| {
let request = let request = thread.to_completion_request(model.clone(), cx);
thread.to_completion_request(model.clone(), CompletionIntent::UserPrompt, cx);
thread.stream_completion(request, model, cx.active_window(), cx) thread.stream_completion(request, model, cx.active_window(), cx)
}); });
// Follow the agent // Follow the agent
@@ -3759,87 +3713,6 @@ mod tests {
assert!(!cx.read(|cx| workspace.read(cx).is_being_followed(CollaboratorId::Agent))); assert!(!cx.read(|cx| workspace.read(cx).is_being_followed(CollaboratorId::Agent)));
} }
#[gpui::test]
async fn test_reinserting_creases_for_edited_message(cx: &mut TestAppContext) {
init_test_settings(cx);
let project = create_test_project(cx, json!({})).await;
let (cx, active_thread, _, thread, model) =
setup_test_environment(cx, project.clone()).await;
cx.update(|_, cx| {
LanguageModelRegistry::global(cx).update(cx, |registry, cx| {
registry.set_default_model(
Some(ConfiguredModel {
provider: Arc::new(FakeLanguageModelProvider),
model,
}),
cx,
);
});
});
let creases = vec![MessageCrease {
range: 14..22,
metadata: CreaseMetadata {
icon_path: "icon".into(),
label: "foo.txt".into(),
},
context: None,
}];
let message = thread.update(cx, |thread, cx| {
let message_id = thread.insert_user_message(
"Tell me about @foo.txt",
ContextLoadResult::default(),
None,
creases,
cx,
);
thread.message(message_id).cloned().unwrap()
});
active_thread.update_in(cx, |active_thread, window, cx| {
active_thread.start_editing_message(
message.id,
message.segments.as_slice(),
message.creases.as_slice(),
window,
cx,
);
let editor = active_thread
.editing_message
.as_ref()
.unwrap()
.1
.editor
.clone();
editor.update(cx, |editor, cx| editor.edit([(0..13, "modified")], cx));
active_thread.confirm_editing_message(&Default::default(), window, cx);
});
cx.run_until_parked();
let message = thread.update(cx, |thread, _| thread.message(message.id).cloned().unwrap());
active_thread.update_in(cx, |active_thread, window, cx| {
active_thread.start_editing_message(
message.id,
message.segments.as_slice(),
message.creases.as_slice(),
window,
cx,
);
let editor = active_thread
.editing_message
.as_ref()
.unwrap()
.1
.editor
.clone();
let text = editor.update(cx, |editor, cx| editor.text(cx));
assert_eq!(text, "modified @foo.txt");
});
}
fn init_test_settings(cx: &mut TestAppContext) { fn init_test_settings(cx: &mut TestAppContext) {
cx.update(|cx| { cx.update(|cx| {
let settings_store = SettingsStore::test(cx); let settings_store = SettingsStore::test(cx);

View File

@@ -3,7 +3,6 @@ mod agent_configuration;
mod agent_diff; mod agent_diff;
mod agent_model_selector; mod agent_model_selector;
mod agent_panel; mod agent_panel;
mod agent_profile;
mod buffer_codegen; mod buffer_codegen;
mod context; mod context;
mod context_picker; mod context_picker;
@@ -34,11 +33,9 @@ use assistant_slash_command::SlashCommandRegistry;
use client::Client; use client::Client;
use feature_flags::FeatureFlagAppExt as _; use feature_flags::FeatureFlagAppExt as _;
use fs::Fs; use fs::Fs;
use gpui::{App, Entity, actions, impl_actions}; use gpui::{App, actions, impl_actions};
use language::LanguageRegistry; use language::LanguageRegistry;
use language_model::{ use language_model::{LanguageModelId, LanguageModelProviderId, LanguageModelRegistry};
ConfiguredModel, LanguageModel, LanguageModelId, LanguageModelProviderId, LanguageModelRegistry,
};
use prompt_store::PromptBuilder; use prompt_store::PromptBuilder;
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::Deserialize; use serde::Deserialize;
@@ -92,7 +89,6 @@ actions!(
ResetTrialEndUpsell, ResetTrialEndUpsell,
ContinueThread, ContinueThread,
ContinueWithBurnMode, ContinueWithBurnMode,
ToggleBurnMode,
] ]
); );
@@ -118,28 +114,6 @@ impl ManageProfiles {
impl_actions!(agent, [NewThread, ManageProfiles]); impl_actions!(agent, [NewThread, ManageProfiles]);
#[derive(Clone)]
pub(crate) enum ModelUsageContext {
Thread(Entity<Thread>),
InlineAssistant,
}
impl ModelUsageContext {
pub fn configured_model(&self, cx: &App) -> Option<ConfiguredModel> {
match self {
Self::Thread(thread) => thread.read(cx).configured_model(),
Self::InlineAssistant => {
LanguageModelRegistry::read_global(cx).inline_assistant_model()
}
}
}
pub fn language_model(&self, cx: &App) -> Option<Arc<dyn LanguageModel>> {
self.configured_model(cx)
.map(|configured_model| configured_model.model)
}
}
/// Initializes the `agent` crate. /// Initializes the `agent` crate.
pub fn init( pub fn init(
fs: Arc<dyn Fs>, fs: Arc<dyn Fs>,

View File

@@ -12,7 +12,7 @@ use context_server::ContextServerId;
use fs::Fs; use fs::Fs;
use gpui::{ use gpui::{
Action, Animation, AnimationExt as _, AnyView, App, Entity, EventEmitter, FocusHandle, Action, Animation, AnimationExt as _, AnyView, App, Entity, EventEmitter, FocusHandle,
Focusable, ScrollHandle, Subscription, Transformation, percentage, Focusable, ScrollHandle, Subscription, pulsating_between,
}; };
use language_model::{LanguageModelProvider, LanguageModelProviderId, LanguageModelRegistry}; use language_model::{LanguageModelProvider, LanguageModelProviderId, LanguageModelRegistry};
use project::context_server_store::{ContextServerStatus, ContextServerStore}; use project::context_server_store::{ContextServerStatus, ContextServerStore};
@@ -475,6 +475,7 @@ impl AgentConfiguration {
.get(&context_server_id) .get(&context_server_id)
.copied() .copied()
.unwrap_or_default(); .unwrap_or_default();
let tools = tools_by_source let tools = tools_by_source
.get(&ToolSource::ContextServer { .get(&ToolSource::ContextServer {
id: context_server_id.0.clone().into(), id: context_server_id.0.clone().into(),
@@ -483,23 +484,25 @@ impl AgentConfiguration {
let tool_count = tools.len(); let tool_count = tools.len();
let border_color = cx.theme().colors().border.opacity(0.6); let border_color = cx.theme().colors().border.opacity(0.6);
let success_color = Color::Success.color(cx);
let (status_indicator, tooltip_text) = match server_status { let (status_indicator, tooltip_text) = match server_status {
ContextServerStatus::Starting => ( ContextServerStatus::Starting => (
Icon::new(IconName::LoadCircle) Indicator::dot()
.size(IconSize::XSmall) .color(Color::Success)
.color(Color::Accent)
.with_animation( .with_animation(
SharedString::from(format!("{}-starting", context_server_id.0.clone(),)), SharedString::from(format!("{}-starting", context_server_id.0.clone(),)),
Animation::new(Duration::from_secs(3)).repeat(), Animation::new(Duration::from_secs(2))
|icon, delta| icon.transform(Transformation::rotate(percentage(delta))), .repeat()
.with_easing(pulsating_between(0.4, 1.)),
move |this, delta| this.color(success_color.alpha(delta).into()),
) )
.into_any_element(), .into_any_element(),
"Server is starting.", "Server is starting.",
), ),
ContextServerStatus::Running => ( ContextServerStatus::Running => (
Indicator::dot().color(Color::Success).into_any_element(), Indicator::dot().color(Color::Success).into_any_element(),
"Server is active.", "Server is running.",
), ),
ContextServerStatus::Error(_) => ( ContextServerStatus::Error(_) => (
Indicator::dot().color(Color::Error).into_any_element(), Indicator::dot().color(Color::Error).into_any_element(),
@@ -523,11 +526,12 @@ impl AgentConfiguration {
.p_1() .p_1()
.justify_between() .justify_between()
.when( .when(
error.is_some() || are_tools_expanded && tool_count >= 1, error.is_some() || are_tools_expanded && tool_count > 1,
|element| element.border_b_1().border_color(border_color), |element| element.border_b_1().border_color(border_color),
) )
.child( .child(
h_flex() h_flex()
.gap_1p5()
.child( .child(
Disclosure::new( Disclosure::new(
"tool-list-disclosure", "tool-list-disclosure",
@@ -547,16 +551,12 @@ impl AgentConfiguration {
})), })),
) )
.child( .child(
h_flex() div()
.id(SharedString::from(format!("tooltip-{}", item_id))) .id(item_id.clone())
.h_full()
.w_3()
.mx_1()
.justify_center()
.tooltip(Tooltip::text(tooltip_text)) .tooltip(Tooltip::text(tooltip_text))
.child(status_indicator), .child(status_indicator),
) )
.child(Label::new(item_id).ml_0p5().mr_1p5()) .child(Label::new(context_server_id.0.clone()).ml_0p5())
.when(is_running, |this| { .when(is_running, |this| {
this.child( this.child(
Label::new(if tool_count == 1 { Label::new(if tool_count == 1 {
@@ -637,7 +637,7 @@ impl AgentConfiguration {
.hover(|style| style.bg(cx.theme().colors().element_hover)) .hover(|style| style.bg(cx.theme().colors().element_hover))
.rounded_sm() .rounded_sm()
.child( .child(
Label::new(tool.name()) Label::new(tool.ui_name())
.buffer_font(cx) .buffer_font(cx)
.size(LabelSize::Small), .size(LabelSize::Small),
) )

View File

@@ -2,21 +2,25 @@ mod profile_modal_header;
use std::sync::Arc; use std::sync::Arc;
use agent_settings::{AgentProfileId, AgentSettings, builtin_profiles}; use agent_settings::{AgentProfile, AgentProfileId, AgentSettings, builtin_profiles};
use assistant_tool::ToolWorkingSet; use assistant_tool::ToolWorkingSet;
use convert_case::{Case, Casing as _};
use editor::Editor; use editor::Editor;
use fs::Fs; use fs::Fs;
use gpui::{DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, Subscription, prelude::*}; use gpui::{
use settings::Settings as _; DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, Subscription, WeakEntity,
prelude::*,
};
use settings::{Settings as _, update_settings_file};
use ui::{ use ui::{
KeyBinding, ListItem, ListItemSpacing, ListSeparator, Navigable, NavigableEntry, prelude::*, KeyBinding, ListItem, ListItemSpacing, ListSeparator, Navigable, NavigableEntry, prelude::*,
}; };
use util::ResultExt as _;
use workspace::{ModalView, Workspace}; use workspace::{ModalView, Workspace};
use crate::agent_configuration::manage_profiles_modal::profile_modal_header::ProfileModalHeader; use crate::agent_configuration::manage_profiles_modal::profile_modal_header::ProfileModalHeader;
use crate::agent_configuration::tool_picker::{ToolPicker, ToolPickerDelegate}; use crate::agent_configuration::tool_picker::{ToolPicker, ToolPickerDelegate};
use crate::agent_profile::AgentProfile; use crate::{AgentPanel, ManageProfiles, ThreadStore};
use crate::{AgentPanel, ManageProfiles};
use super::tool_picker::ToolPickerMode; use super::tool_picker::ToolPickerMode;
@@ -99,6 +103,7 @@ pub struct NewProfileMode {
pub struct ManageProfilesModal { pub struct ManageProfilesModal {
fs: Arc<dyn Fs>, fs: Arc<dyn Fs>,
tools: Entity<ToolWorkingSet>, tools: Entity<ToolWorkingSet>,
thread_store: WeakEntity<ThreadStore>,
focus_handle: FocusHandle, focus_handle: FocusHandle,
mode: Mode, mode: Mode,
} }
@@ -114,8 +119,9 @@ impl ManageProfilesModal {
let fs = workspace.app_state().fs.clone(); let fs = workspace.app_state().fs.clone();
let thread_store = panel.read(cx).thread_store(); let thread_store = panel.read(cx).thread_store();
let tools = thread_store.read(cx).tools(); let tools = thread_store.read(cx).tools();
let thread_store = thread_store.downgrade();
workspace.toggle_modal(window, cx, |window, cx| { workspace.toggle_modal(window, cx, |window, cx| {
let mut this = Self::new(fs, tools, window, cx); let mut this = Self::new(fs, tools, thread_store, window, cx);
if let Some(profile_id) = action.customize_tools.clone() { if let Some(profile_id) = action.customize_tools.clone() {
this.configure_builtin_tools(profile_id, window, cx); this.configure_builtin_tools(profile_id, window, cx);
@@ -130,6 +136,7 @@ impl ManageProfilesModal {
pub fn new( pub fn new(
fs: Arc<dyn Fs>, fs: Arc<dyn Fs>,
tools: Entity<ToolWorkingSet>, tools: Entity<ToolWorkingSet>,
thread_store: WeakEntity<ThreadStore>,
window: &mut Window, window: &mut Window,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> Self { ) -> Self {
@@ -138,6 +145,7 @@ impl ManageProfilesModal {
Self { Self {
fs, fs,
tools, tools,
thread_store,
focus_handle, focus_handle,
mode: Mode::choose_profile(window, cx), mode: Mode::choose_profile(window, cx),
} }
@@ -198,6 +206,7 @@ impl ManageProfilesModal {
ToolPickerMode::McpTools, ToolPickerMode::McpTools,
self.fs.clone(), self.fs.clone(),
self.tools.clone(), self.tools.clone(),
self.thread_store.clone(),
profile_id.clone(), profile_id.clone(),
profile, profile,
cx, cx,
@@ -235,6 +244,7 @@ impl ManageProfilesModal {
ToolPickerMode::BuiltinTools, ToolPickerMode::BuiltinTools,
self.fs.clone(), self.fs.clone(),
self.tools.clone(), self.tools.clone(),
self.thread_store.clone(),
profile_id.clone(), profile_id.clone(),
profile, profile,
cx, cx,
@@ -260,10 +270,32 @@ impl ManageProfilesModal {
match &self.mode { match &self.mode {
Mode::ChooseProfile { .. } => {} Mode::ChooseProfile { .. } => {}
Mode::NewProfile(mode) => { Mode::NewProfile(mode) => {
let name = mode.name_editor.read(cx).text(cx); let settings = AgentSettings::get_global(cx);
let profile_id = let base_profile = mode
AgentProfile::create(name, mode.base_profile_id.clone(), self.fs.clone(), cx); .base_profile_id
.as_ref()
.and_then(|profile_id| settings.profiles.get(profile_id).cloned());
let name = mode.name_editor.read(cx).text(cx);
let profile_id = AgentProfileId(name.to_case(Case::Kebab).into());
let profile = AgentProfile {
name: name.into(),
tools: base_profile
.as_ref()
.map(|profile| profile.tools.clone())
.unwrap_or_default(),
enable_all_context_servers: base_profile
.as_ref()
.map(|profile| profile.enable_all_context_servers)
.unwrap_or_default(),
context_servers: base_profile
.map(|profile| profile.context_servers)
.unwrap_or_default(),
};
self.create_profile(profile_id.clone(), profile, cx);
self.view_profile(profile_id, window, cx); self.view_profile(profile_id, window, cx);
} }
Mode::ViewProfile(_) => {} Mode::ViewProfile(_) => {}
@@ -293,6 +325,19 @@ impl ManageProfilesModal {
} }
} }
} }
fn create_profile(
&self,
profile_id: AgentProfileId,
profile: AgentProfile,
cx: &mut Context<Self>,
) {
update_settings_file::<AgentSettings>(self.fs.clone(), cx, {
move |settings, _cx| {
settings.create_profile(profile_id, profile).log_err();
}
});
}
} }
impl ModalView for ManageProfilesModal {} impl ModalView for ManageProfilesModal {}
@@ -475,13 +520,14 @@ impl ManageProfilesModal {
) -> impl IntoElement { ) -> impl IntoElement {
let settings = AgentSettings::get_global(cx); let settings = AgentSettings::get_global(cx);
let profile_id = &settings.default_profile;
let profile_name = settings let profile_name = settings
.profiles .profiles
.get(&mode.profile_id) .get(&mode.profile_id)
.map(|profile| profile.name.clone()) .map(|profile| profile.name.clone())
.unwrap_or_else(|| "Unknown".into()); .unwrap_or_else(|| "Unknown".into());
let icon = match mode.profile_id.as_str() { let icon = match profile_id.as_str() {
"write" => IconName::Pencil, "write" => IconName::Pencil,
"ask" => IconName::MessageBubbles, "ask" => IconName::MessageBubbles,
_ => IconName::UserRoundPen, _ => IconName::UserRoundPen,

View File

@@ -1,17 +1,19 @@
use std::{collections::BTreeMap, sync::Arc}; use std::{collections::BTreeMap, sync::Arc};
use agent_settings::{ use agent_settings::{
AgentProfileContent, AgentProfileId, AgentProfileSettings, AgentSettings, AgentSettingsContent, AgentProfile, AgentProfileContent, AgentProfileId, AgentSettings, AgentSettingsContent,
ContextServerPresetContent, ContextServerPresetContent,
}; };
use assistant_tool::{ToolSource, ToolWorkingSet}; use assistant_tool::{ToolSource, ToolWorkingSet};
use fs::Fs; use fs::Fs;
use gpui::{App, Context, DismissEvent, Entity, EventEmitter, Focusable, Task, WeakEntity, Window}; use gpui::{App, Context, DismissEvent, Entity, EventEmitter, Focusable, Task, WeakEntity, Window};
use picker::{Picker, PickerDelegate}; use picker::{Picker, PickerDelegate};
use settings::update_settings_file; use settings::{Settings as _, update_settings_file};
use ui::{ListItem, ListItemSpacing, prelude::*}; use ui::{ListItem, ListItemSpacing, prelude::*};
use util::ResultExt as _; use util::ResultExt as _;
use crate::ThreadStore;
pub struct ToolPicker { pub struct ToolPicker {
picker: Entity<Picker<ToolPickerDelegate>>, picker: Entity<Picker<ToolPickerDelegate>>,
} }
@@ -69,10 +71,11 @@ pub enum PickerItem {
pub struct ToolPickerDelegate { pub struct ToolPickerDelegate {
tool_picker: WeakEntity<ToolPicker>, tool_picker: WeakEntity<ToolPicker>,
thread_store: WeakEntity<ThreadStore>,
fs: Arc<dyn Fs>, fs: Arc<dyn Fs>,
items: Arc<Vec<PickerItem>>, items: Arc<Vec<PickerItem>>,
profile_id: AgentProfileId, profile_id: AgentProfileId,
profile_settings: AgentProfileSettings, profile: AgentProfile,
filtered_items: Vec<PickerItem>, filtered_items: Vec<PickerItem>,
selected_index: usize, selected_index: usize,
mode: ToolPickerMode, mode: ToolPickerMode,
@@ -83,18 +86,20 @@ impl ToolPickerDelegate {
mode: ToolPickerMode, mode: ToolPickerMode,
fs: Arc<dyn Fs>, fs: Arc<dyn Fs>,
tool_set: Entity<ToolWorkingSet>, tool_set: Entity<ToolWorkingSet>,
thread_store: WeakEntity<ThreadStore>,
profile_id: AgentProfileId, profile_id: AgentProfileId,
profile_settings: AgentProfileSettings, profile: AgentProfile,
cx: &mut Context<ToolPicker>, cx: &mut Context<ToolPicker>,
) -> Self { ) -> Self {
let items = Arc::new(Self::resolve_items(mode, &tool_set, cx)); let items = Arc::new(Self::resolve_items(mode, &tool_set, cx));
Self { Self {
tool_picker: cx.entity().downgrade(), tool_picker: cx.entity().downgrade(),
thread_store,
fs, fs,
items, items,
profile_id, profile_id,
profile_settings, profile,
filtered_items: Vec::new(), filtered_items: Vec::new(),
selected_index: 0, selected_index: 0,
mode, mode,
@@ -112,7 +117,7 @@ impl ToolPickerDelegate {
ToolSource::Native => { ToolSource::Native => {
if mode == ToolPickerMode::BuiltinTools { if mode == ToolPickerMode::BuiltinTools {
items.extend(tools.into_iter().map(|tool| PickerItem::Tool { items.extend(tools.into_iter().map(|tool| PickerItem::Tool {
name: tool.name().into(), name: tool.ui_name().into(),
server_id: None, server_id: None,
})); }));
} }
@@ -124,7 +129,7 @@ impl ToolPickerDelegate {
server_id: server_id.clone(), server_id: server_id.clone(),
}); });
items.extend(tools.into_iter().map(|tool| PickerItem::Tool { items.extend(tools.into_iter().map(|tool| PickerItem::Tool {
name: tool.name().into(), name: tool.ui_name().into(),
server_id: Some(server_id.clone()), server_id: Some(server_id.clone()),
})); }));
} }
@@ -244,31 +249,28 @@ impl PickerDelegate for ToolPickerDelegate {
}; };
let is_currently_enabled = if let Some(server_id) = server_id.clone() { let is_currently_enabled = if let Some(server_id) = server_id.clone() {
let preset = self let preset = self.profile.context_servers.entry(server_id).or_default();
.profile_settings
.context_servers
.entry(server_id)
.or_default();
let is_enabled = *preset.tools.entry(tool_name.clone()).or_default(); let is_enabled = *preset.tools.entry(tool_name.clone()).or_default();
*preset.tools.entry(tool_name.clone()).or_default() = !is_enabled; *preset.tools.entry(tool_name.clone()).or_default() = !is_enabled;
is_enabled is_enabled
} else { } else {
let is_enabled = *self let is_enabled = *self.profile.tools.entry(tool_name.clone()).or_default();
.profile_settings *self.profile.tools.entry(tool_name.clone()).or_default() = !is_enabled;
.tools
.entry(tool_name.clone())
.or_default();
*self
.profile_settings
.tools
.entry(tool_name.clone())
.or_default() = !is_enabled;
is_enabled is_enabled
}; };
let active_profile_id = &AgentSettings::get_global(cx).default_profile;
if active_profile_id == &self.profile_id {
self.thread_store
.update(cx, |this, cx| {
this.load_profile(self.profile.clone(), cx);
})
.log_err();
}
update_settings_file::<AgentSettings>(self.fs.clone(), cx, { update_settings_file::<AgentSettings>(self.fs.clone(), cx, {
let profile_id = self.profile_id.clone(); let profile_id = self.profile_id.clone();
let default_profile = self.profile_settings.clone(); let default_profile = self.profile.clone();
let server_id = server_id.clone(); let server_id = server_id.clone();
let tool_name = tool_name.clone(); let tool_name = tool_name.clone();
move |settings: &mut AgentSettingsContent, _cx| { move |settings: &mut AgentSettingsContent, _cx| {
@@ -346,18 +348,14 @@ impl PickerDelegate for ToolPickerDelegate {
), ),
PickerItem::Tool { name, server_id } => { PickerItem::Tool { name, server_id } => {
let is_enabled = if let Some(server_id) = server_id { let is_enabled = if let Some(server_id) = server_id {
self.profile_settings self.profile
.context_servers .context_servers
.get(server_id.as_ref()) .get(server_id.as_ref())
.and_then(|preset| preset.tools.get(name)) .and_then(|preset| preset.tools.get(name))
.copied() .copied()
.unwrap_or(self.profile_settings.enable_all_context_servers) .unwrap_or(self.profile.enable_all_context_servers)
} else { } else {
self.profile_settings self.profile.tools.get(name).copied().unwrap_or(false)
.tools
.get(name)
.copied()
.unwrap_or(false)
}; };
Some( Some(

View File

@@ -699,7 +699,7 @@ fn render_diff_hunk_controls(
.rounded_b_md() .rounded_b_md()
.bg(cx.theme().colors().editor_background) .bg(cx.theme().colors().editor_background)
.gap_1() .gap_1()
.block_mouse_except_scroll() .stop_mouse_events_except_scroll()
.shadow_md() .shadow_md()
.children(vec![ .children(vec![
Button::new(("reject", row as u64), "Reject") Button::new(("reject", row as u64), "Reject")
@@ -1086,7 +1086,7 @@ impl Render for AgentDiffToolbar {
.child(vertical_divider()) .child(vertical_divider())
.when_some(editor.read(cx).workspace(), |this, _workspace| { .when_some(editor.read(cx).workspace(), |this, _workspace| {
this.child( this.child(
IconButton::new("review", IconName::ListTodo) IconButton::new("review", IconName::ListCollapse)
.icon_size(IconSize::Small) .icon_size(IconSize::Small)
.tooltip(Tooltip::for_action_title_in( .tooltip(Tooltip::for_action_title_in(
"Review All Files", "Review All Files",
@@ -1116,13 +1116,8 @@ impl Render for AgentDiffToolbar {
return Empty.into_any(); return Empty.into_any();
}; };
let has_pending_edit_tool_use = agent_diff let is_generating = agent_diff.read(cx).thread.read(cx).is_generating();
.read(cx) if is_generating {
.thread
.read(cx)
.has_pending_edit_tool_uses();
if has_pending_edit_tool_use {
return div().px_2().child(spinner_icon).into_any(); return div().px_2().child(spinner_icon).into_any();
} }
@@ -1377,9 +1372,7 @@ impl AgentDiff {
| ThreadEvent::ToolFinished { .. } | ThreadEvent::ToolFinished { .. }
| ThreadEvent::CheckpointChanged | ThreadEvent::CheckpointChanged
| ThreadEvent::ToolConfirmationNeeded | ThreadEvent::ToolConfirmationNeeded
| ThreadEvent::ToolUseLimitReached | ThreadEvent::CancelEditing => {}
| ThreadEvent::CancelEditing
| ThreadEvent::ProfileChanged => {}
} }
} }
@@ -1471,10 +1464,7 @@ impl AgentDiff {
if !AgentSettings::get_global(cx).single_file_review { if !AgentSettings::get_global(cx).single_file_review {
for (editor, _) in self.reviewing_editors.drain() { for (editor, _) in self.reviewing_editors.drain() {
editor editor
.update(cx, |editor, cx| { .update(cx, |editor, cx| editor.end_temporary_diff_override(cx))
editor.end_temporary_diff_override(cx);
editor.unregister_addon::<EditorAgentDiffAddon>();
})
.ok(); .ok();
} }
return; return;
@@ -1513,7 +1503,7 @@ impl AgentDiff {
multibuffer.add_diff(diff_handle.clone(), cx); multibuffer.add_diff(diff_handle.clone(), cx);
}); });
let new_state = if thread.read(cx).has_pending_edit_tool_uses() { let new_state = if thread.read(cx).is_generating() {
EditorState::Generating EditorState::Generating
} else { } else {
EditorState::Reviewing EditorState::Reviewing
@@ -1570,10 +1560,7 @@ impl AgentDiff {
if in_workspace { if in_workspace {
editor editor
.update(cx, |editor, cx| { .update(cx, |editor, cx| editor.end_temporary_diff_override(cx))
editor.end_temporary_diff_override(cx);
editor.unregister_addon::<EditorAgentDiffAddon>();
})
.ok(); .ok();
self.reviewing_editors.remove(&editor); self.reviewing_editors.remove(&editor);
} }

View File

@@ -1,17 +1,22 @@
use agent_settings::AgentSettings; use agent_settings::AgentSettings;
use fs::Fs; use fs::Fs;
use gpui::{Entity, FocusHandle, SharedString}; use gpui::{Entity, FocusHandle, SharedString};
use picker::popover_menu::PickerPopoverMenu;
use crate::ModelUsageContext; use crate::Thread;
use assistant_context_editor::language_model_selector::{ use assistant_context_editor::language_model_selector::{
LanguageModelSelector, ToggleModelSelector, language_model_selector, LanguageModelSelector, LanguageModelSelectorPopoverMenu, ToggleModelSelector,
}; };
use language_model::{ConfiguredModel, LanguageModelRegistry}; use language_model::{ConfiguredModel, LanguageModelRegistry};
use settings::update_settings_file; use settings::update_settings_file;
use std::sync::Arc; use std::sync::Arc;
use ui::{PopoverMenuHandle, Tooltip, prelude::*}; use ui::{PopoverMenuHandle, Tooltip, prelude::*};
#[derive(Clone)]
pub enum ModelType {
Default(Entity<Thread>),
InlineAssistant,
}
pub struct AgentModelSelector { pub struct AgentModelSelector {
selector: Entity<LanguageModelSelector>, selector: Entity<LanguageModelSelector>,
menu_handle: PopoverMenuHandle<LanguageModelSelector>, menu_handle: PopoverMenuHandle<LanguageModelSelector>,
@@ -23,23 +28,28 @@ impl AgentModelSelector {
fs: Arc<dyn Fs>, fs: Arc<dyn Fs>,
menu_handle: PopoverMenuHandle<LanguageModelSelector>, menu_handle: PopoverMenuHandle<LanguageModelSelector>,
focus_handle: FocusHandle, focus_handle: FocusHandle,
model_usage_context: ModelUsageContext, model_type: ModelType,
window: &mut Window, window: &mut Window,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> Self { ) -> Self {
Self { Self {
selector: cx.new(move |cx| { selector: cx.new(move |cx| {
let fs = fs.clone(); let fs = fs.clone();
language_model_selector( LanguageModelSelector::new(
{ {
let model_context = model_usage_context.clone(); let model_type = model_type.clone();
move |cx| model_context.configured_model(cx) move |cx| match &model_type {
ModelType::Default(thread) => thread.read(cx).configured_model(),
ModelType::InlineAssistant => {
LanguageModelRegistry::read_global(cx).inline_assistant_model()
}
}
}, },
move |model, cx| { move |model, cx| {
let provider = model.provider_id().0.to_string(); let provider = model.provider_id().0.to_string();
let model_id = model.id().0.to_string(); let model_id = model.id().0.to_string();
match &model_usage_context { match &model_type {
ModelUsageContext::Thread(thread) => { ModelType::Default(thread) => {
thread.update(cx, |thread, cx| { thread.update(cx, |thread, cx| {
let registry = LanguageModelRegistry::read_global(cx); let registry = LanguageModelRegistry::read_global(cx);
if let Some(provider) = registry.provider(&model.provider_id()) if let Some(provider) = registry.provider(&model.provider_id())
@@ -61,7 +71,7 @@ impl AgentModelSelector {
}, },
); );
} }
ModelUsageContext::InlineAssistant => { ModelType::InlineAssistant => {
update_settings_file::<AgentSettings>( update_settings_file::<AgentSettings>(
fs.clone(), fs.clone(),
cx, cx,
@@ -90,14 +100,15 @@ impl AgentModelSelector {
} }
impl Render for AgentModelSelector { impl Render for AgentModelSelector {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let focus_handle = self.focus_handle.clone(); let focus_handle = self.focus_handle.clone();
let model = self.selector.read(cx).delegate.active_model(cx); let model = self.selector.read(cx).active_model(cx);
let model_name = model let model_name = model
.map(|model| model.model.name().0) .map(|model| model.model.name().0)
.unwrap_or_else(|| SharedString::from("No model selected")); .unwrap_or_else(|| SharedString::from("No model selected"));
PickerPopoverMenu::new(
LanguageModelSelectorPopoverMenu::new(
self.selector.clone(), self.selector.clone(),
Button::new("active-model", model_name) Button::new("active-model", model_name)
.label_size(LabelSize::Small) .label_size(LabelSize::Small)
@@ -116,9 +127,7 @@ impl Render for AgentModelSelector {
) )
}, },
gpui::Corner::BottomRight, gpui::Corner::BottomRight,
cx,
) )
.with_handle(self.menu_handle.clone()) .with_handle(self.menu_handle.clone())
.render(window, cx)
} }
} }

View File

@@ -52,12 +52,12 @@ use workspace::{
use zed_actions::agent::{OpenConfiguration, OpenOnboardingModal, ResetOnboarding}; use zed_actions::agent::{OpenConfiguration, OpenOnboardingModal, ResetOnboarding};
use zed_actions::assistant::{OpenRulesLibrary, ToggleFocus}; use zed_actions::assistant::{OpenRulesLibrary, ToggleFocus};
use zed_actions::{DecreaseBufferFontSize, IncreaseBufferFontSize, ResetBufferFontSize}; use zed_actions::{DecreaseBufferFontSize, IncreaseBufferFontSize, ResetBufferFontSize};
use zed_llm_client::{CompletionIntent, UsageLimit}; use zed_llm_client::UsageLimit;
use crate::active_thread::{self, ActiveThread, ActiveThreadEvent}; use crate::active_thread::{self, ActiveThread, ActiveThreadEvent};
use crate::agent_configuration::{AgentConfiguration, AssistantConfigurationEvent}; use crate::agent_configuration::{AgentConfiguration, AssistantConfigurationEvent};
use crate::agent_diff::AgentDiff; use crate::agent_diff::AgentDiff;
use crate::history_store::{HistoryEntryId, HistoryStore}; use crate::history_store::{HistoryStore, RecentEntry};
use crate::message_editor::{MessageEditor, MessageEditorEvent}; use crate::message_editor::{MessageEditor, MessageEditorEvent};
use crate::thread::{Thread, ThreadError, ThreadId, ThreadSummary, TokenUsageRatio}; use crate::thread::{Thread, ThreadError, ThreadId, ThreadSummary, TokenUsageRatio};
use crate::thread_history::{HistoryEntryElement, ThreadHistory}; use crate::thread_history::{HistoryEntryElement, ThreadHistory};
@@ -67,8 +67,8 @@ use crate::{
AddContextServer, AgentDiffPane, ContextStore, ContinueThread, ContinueWithBurnMode, AddContextServer, AgentDiffPane, ContextStore, ContinueThread, ContinueWithBurnMode,
DeleteRecentlyOpenThread, ExpandMessageEditor, Follow, InlineAssistant, NewTextThread, DeleteRecentlyOpenThread, ExpandMessageEditor, Follow, InlineAssistant, NewTextThread,
NewThread, OpenActiveThreadAsMarkdown, OpenAgentDiff, OpenHistory, ResetTrialEndUpsell, NewThread, OpenActiveThreadAsMarkdown, OpenAgentDiff, OpenHistory, ResetTrialEndUpsell,
ResetTrialUpsell, TextThreadStore, ThreadEvent, ToggleBurnMode, ToggleContextPicker, ResetTrialUpsell, TextThreadStore, ThreadEvent, ToggleContextPicker, ToggleNavigationMenu,
ToggleNavigationMenu, ToggleOptionsMenu, ToggleOptionsMenu,
}; };
const AGENT_PANEL_KEY: &str = "agent_panel"; const AGENT_PANEL_KEY: &str = "agent_panel";
@@ -174,7 +174,7 @@ enum ActiveView {
thread: WeakEntity<Thread>, thread: WeakEntity<Thread>,
_subscriptions: Vec<gpui::Subscription>, _subscriptions: Vec<gpui::Subscription>,
}, },
TextThread { PromptEditor {
context_editor: Entity<ContextEditor>, context_editor: Entity<ContextEditor>,
title_editor: Entity<Editor>, title_editor: Entity<Editor>,
buffer_search_bar: Entity<BufferSearchBar>, buffer_search_bar: Entity<BufferSearchBar>,
@@ -194,7 +194,7 @@ impl ActiveView {
pub fn which_font_size_used(&self) -> WhichFontSize { pub fn which_font_size_used(&self) -> WhichFontSize {
match self { match self {
ActiveView::Thread { .. } | ActiveView::History => WhichFontSize::AgentFont, ActiveView::Thread { .. } | ActiveView::History => WhichFontSize::AgentFont,
ActiveView::TextThread { .. } => WhichFontSize::BufferFont, ActiveView::PromptEditor { .. } => WhichFontSize::BufferFont,
ActiveView::Configuration => WhichFontSize::None, ActiveView::Configuration => WhichFontSize::None,
} }
} }
@@ -257,7 +257,6 @@ impl ActiveView {
pub fn prompt_editor( pub fn prompt_editor(
context_editor: Entity<ContextEditor>, context_editor: Entity<ContextEditor>,
history_store: Entity<HistoryStore>,
language_registry: Arc<LanguageRegistry>, language_registry: Arc<LanguageRegistry>,
window: &mut Window, window: &mut Window,
cx: &mut App, cx: &mut App,
@@ -323,19 +322,6 @@ impl ActiveView {
editor.set_text(summary, window, cx); editor.set_text(summary, window, cx);
}) })
} }
ContextEvent::PathChanged { old_path, new_path } => {
history_store.update(cx, |history_store, cx| {
if let Some(old_path) = old_path {
history_store
.replace_recently_opened_text_thread(old_path, new_path, cx);
} else {
history_store.push_recently_opened_entry(
HistoryEntryId::Context(new_path.clone()),
cx,
);
}
});
}
_ => {} _ => {}
} }
}), }),
@@ -347,7 +333,7 @@ impl ActiveView {
buffer_search_bar.set_active_pane_item(Some(&context_editor), window, cx) buffer_search_bar.set_active_pane_item(Some(&context_editor), window, cx)
}); });
Self::TextThread { Self::PromptEditor {
context_editor, context_editor,
title_editor: editor, title_editor: editor,
buffer_search_bar, buffer_search_bar,
@@ -530,7 +516,8 @@ impl AgentPanel {
HistoryStore::new( HistoryStore::new(
thread_store.clone(), thread_store.clone(),
context_store.clone(), context_store.clone(),
[HistoryEntryId::Thread(thread_id)], [RecentEntry::Thread(thread_id, thread.clone())],
window,
cx, cx,
) )
}); });
@@ -557,13 +544,7 @@ impl AgentPanel {
editor.insert_default_prompt(window, cx); editor.insert_default_prompt(window, cx);
editor editor
}); });
ActiveView::prompt_editor( ActiveView::prompt_editor(context_editor, language_registry.clone(), window, cx)
context_editor,
history_store.clone(),
language_registry.clone(),
window,
cx,
)
} }
}; };
@@ -600,9 +581,86 @@ impl AgentPanel {
let panel = weak_panel.clone(); let panel = weak_panel.clone();
let assistant_navigation_menu = let assistant_navigation_menu =
ContextMenu::build_persistent(window, cx, move |mut menu, _window, cx| { ContextMenu::build_persistent(window, cx, move |mut menu, _window, cx| {
if let Some(panel) = panel.upgrade() { let recently_opened = panel
menu = Self::populate_recently_opened_menu_section(menu, panel, cx); .update(cx, |this, cx| {
this.history_store.update(cx, |history_store, cx| {
history_store.recently_opened_entries(cx)
})
})
.unwrap_or_default();
if !recently_opened.is_empty() {
menu = menu.header("Recently Opened");
for entry in recently_opened.iter() {
if let RecentEntry::Context(context) = entry {
if context.read(cx).path().is_none() {
log::error!(
"bug: text thread in recent history list was never saved"
);
continue;
}
}
let summary = entry.summary(cx);
menu = menu.entry_with_end_slot_on_hover(
summary,
None,
{
let panel = panel.clone();
let entry = entry.clone();
move |window, cx| {
panel
.update(cx, {
let entry = entry.clone();
move |this, cx| match entry {
RecentEntry::Thread(_, thread) => {
this.open_thread(thread, window, cx)
}
RecentEntry::Context(context) => {
let Some(path) = context.read(cx).path()
else {
return;
};
this.open_saved_prompt_editor(
path.clone(),
window,
cx,
)
.detach_and_log_err(cx)
}
}
})
.ok();
}
},
IconName::Close,
"Close Entry".into(),
{
let panel = panel.clone();
let entry = entry.clone();
move |_window, cx| {
panel
.update(cx, |this, cx| {
this.history_store.update(
cx,
|history_store, cx| {
history_store.remove_recently_opened_entry(
&entry, cx,
);
},
);
})
.ok();
}
},
);
}
menu = menu.separator();
} }
menu.action("View All", Box::new(OpenHistory)) menu.action("View All", Box::new(OpenHistory))
.end_slot_action(DeleteRecentlyOpenThread.boxed_clone()) .end_slot_action(DeleteRecentlyOpenThread.boxed_clone())
.fixed_width(px(320.).into()) .fixed_width(px(320.).into())
@@ -840,7 +898,6 @@ impl AgentPanel {
self.set_active_view( self.set_active_view(
ActiveView::prompt_editor( ActiveView::prompt_editor(
context_editor.clone(), context_editor.clone(),
self.history_store.clone(),
self.language_registry.clone(), self.language_registry.clone(),
window, window,
cx, cx,
@@ -927,13 +984,7 @@ impl AgentPanel {
) )
}); });
self.set_active_view( self.set_active_view(
ActiveView::prompt_editor( ActiveView::prompt_editor(editor.clone(), self.language_registry.clone(), window, cx),
editor.clone(),
self.history_store.clone(),
self.language_registry.clone(),
window,
cx,
),
window, window,
cx, cx,
); );
@@ -1033,23 +1084,9 @@ impl AgentPanel {
pub fn go_back(&mut self, _: &workspace::GoBack, window: &mut Window, cx: &mut Context<Self>) { pub fn go_back(&mut self, _: &workspace::GoBack, window: &mut Window, cx: &mut Context<Self>) {
match self.active_view { match self.active_view {
ActiveView::Configuration | ActiveView::History => { ActiveView::Configuration | ActiveView::History => {
if let Some(previous_view) = self.previous_view.take() { self.active_view =
self.active_view = previous_view; ActiveView::thread(self.thread.read(cx).thread().clone(), window, cx);
self.message_editor.focus_handle(cx).focus(window);
match &self.active_view {
ActiveView::Thread { .. } => {
self.message_editor.focus_handle(cx).focus(window);
}
ActiveView::TextThread { context_editor, .. } => {
context_editor.focus_handle(cx).focus(window);
}
_ => {}
}
} else {
self.active_view =
ActiveView::thread(self.thread.read(cx).thread().clone(), window, cx);
self.message_editor.focus_handle(cx).focus(window);
}
cx.notify(); cx.notify();
} }
_ => {} _ => {}
@@ -1259,12 +1296,7 @@ impl AgentPanel {
active_thread.thread().update(cx, |thread, cx| { active_thread.thread().update(cx, |thread, cx| {
thread.insert_invisible_continue_message(cx); thread.insert_invisible_continue_message(cx);
thread.advance_prompt_id(); thread.advance_prompt_id();
thread.send_to_model( thread.send_to_model(model, Some(window.window_handle()), cx);
model,
CompletionIntent::UserPrompt,
Some(window.window_handle()),
cx,
);
}); });
}); });
} else { } else {
@@ -1272,27 +1304,9 @@ impl AgentPanel {
} }
} }
fn toggle_burn_mode(
&mut self,
_: &ToggleBurnMode,
_window: &mut Window,
cx: &mut Context<Self>,
) {
self.thread.update(cx, |active_thread, cx| {
active_thread.thread().update(cx, |thread, _cx| {
let current_mode = thread.completion_mode();
thread.set_completion_mode(match current_mode {
CompletionMode::Burn => CompletionMode::Normal,
CompletionMode::Normal => CompletionMode::Burn,
});
});
});
}
pub(crate) fn active_context_editor(&self) -> Option<Entity<ContextEditor>> { pub(crate) fn active_context_editor(&self) -> Option<Entity<ContextEditor>> {
match &self.active_view { match &self.active_view {
ActiveView::TextThread { context_editor, .. } => Some(context_editor.clone()), ActiveView::PromptEditor { context_editor, .. } => Some(context_editor.clone()),
_ => None, _ => None,
} }
} }
@@ -1315,12 +1329,6 @@ impl AgentPanel {
let current_is_history = matches!(self.active_view, ActiveView::History); let current_is_history = matches!(self.active_view, ActiveView::History);
let new_is_history = matches!(new_view, ActiveView::History); let new_is_history = matches!(new_view, ActiveView::History);
let current_is_config = matches!(self.active_view, ActiveView::Configuration);
let new_is_config = matches!(new_view, ActiveView::Configuration);
let current_is_special = current_is_history || current_is_config;
let new_is_special = new_is_history || new_is_config;
match &self.active_view { match &self.active_view {
ActiveView::Thread { thread, .. } => { ActiveView::Thread { thread, .. } => {
if let Some(thread) = thread.upgrade() { if let Some(thread) = thread.upgrade() {
@@ -1332,6 +1340,16 @@ impl AgentPanel {
} }
} }
} }
ActiveView::PromptEditor { context_editor, .. } => {
let context = context_editor.read(cx).context();
// When switching away from an unsaved text thread, delete its entry.
if context.read(cx).path().is_none() {
let context = context.clone();
self.history_store.update(cx, |store, cx| {
store.remove_recently_opened_entry(&RecentEntry::Context(context), cx);
});
}
}
_ => {} _ => {}
} }
@@ -1339,25 +1357,24 @@ impl AgentPanel {
ActiveView::Thread { thread, .. } => self.history_store.update(cx, |store, cx| { ActiveView::Thread { thread, .. } => self.history_store.update(cx, |store, cx| {
if let Some(thread) = thread.upgrade() { if let Some(thread) = thread.upgrade() {
let id = thread.read(cx).id().clone(); let id = thread.read(cx).id().clone();
store.push_recently_opened_entry(HistoryEntryId::Thread(id), cx); store.push_recently_opened_entry(RecentEntry::Thread(id, thread), cx);
} }
}), }),
ActiveView::TextThread { context_editor, .. } => { ActiveView::PromptEditor { context_editor, .. } => {
self.history_store.update(cx, |store, cx| { self.history_store.update(cx, |store, cx| {
if let Some(path) = context_editor.read(cx).context().read(cx).path() { let context = context_editor.read(cx).context().clone();
store.push_recently_opened_entry(HistoryEntryId::Context(path.clone()), cx) store.push_recently_opened_entry(RecentEntry::Context(context), cx)
}
}) })
} }
_ => {} _ => {}
} }
if current_is_special && !new_is_special { if current_is_history && !new_is_history {
self.active_view = new_view; self.active_view = new_view;
} else if !current_is_special && new_is_special { } else if !current_is_history && new_is_history {
self.previous_view = Some(std::mem::replace(&mut self.active_view, new_view)); self.previous_view = Some(std::mem::replace(&mut self.active_view, new_view));
} else { } else {
if !new_is_special { if !new_is_history {
self.previous_view = None; self.previous_view = None;
} }
self.active_view = new_view; self.active_view = new_view;
@@ -1365,70 +1382,6 @@ impl AgentPanel {
self.focus_handle(cx).focus(window); self.focus_handle(cx).focus(window);
} }
fn populate_recently_opened_menu_section(
mut menu: ContextMenu,
panel: Entity<Self>,
cx: &mut Context<ContextMenu>,
) -> ContextMenu {
let entries = panel
.read(cx)
.history_store
.read(cx)
.recently_opened_entries(cx);
if entries.is_empty() {
return menu;
}
menu = menu.header("Recently Opened");
for entry in entries {
let title = entry.title().clone();
let id = entry.id();
menu = menu.entry_with_end_slot_on_hover(
title,
None,
{
let panel = panel.downgrade();
let id = id.clone();
move |window, cx| {
let id = id.clone();
panel
.update(cx, move |this, cx| match id {
HistoryEntryId::Thread(id) => this
.open_thread_by_id(&id, window, cx)
.detach_and_log_err(cx),
HistoryEntryId::Context(path) => this
.open_saved_prompt_editor(path.clone(), window, cx)
.detach_and_log_err(cx),
})
.ok();
}
},
IconName::Close,
"Close Entry".into(),
{
let panel = panel.downgrade();
let id = id.clone();
move |_window, cx| {
panel
.update(cx, |this, cx| {
this.history_store.update(cx, |history_store, cx| {
history_store.remove_recently_opened_entry(&id, cx);
});
})
.ok();
}
},
);
}
menu = menu.separator();
menu
}
} }
impl Focusable for AgentPanel { impl Focusable for AgentPanel {
@@ -1436,7 +1389,7 @@ impl Focusable for AgentPanel {
match &self.active_view { match &self.active_view {
ActiveView::Thread { .. } => self.message_editor.focus_handle(cx), ActiveView::Thread { .. } => self.message_editor.focus_handle(cx),
ActiveView::History => self.history.focus_handle(cx), ActiveView::History => self.history.focus_handle(cx),
ActiveView::TextThread { context_editor, .. } => context_editor.focus_handle(cx), ActiveView::PromptEditor { context_editor, .. } => context_editor.focus_handle(cx),
ActiveView::Configuration => { ActiveView::Configuration => {
if let Some(configuration) = self.configuration.as_ref() { if let Some(configuration) = self.configuration.as_ref() {
configuration.focus_handle(cx) configuration.focus_handle(cx)
@@ -1588,7 +1541,7 @@ impl AgentPanel {
.into_any_element(), .into_any_element(),
} }
} }
ActiveView::TextThread { ActiveView::PromptEditor {
title_editor, title_editor,
context_editor, context_editor,
.. ..
@@ -1680,7 +1633,7 @@ impl AgentPanel {
let show_token_count = match &self.active_view { let show_token_count = match &self.active_view {
ActiveView::Thread { .. } => !is_empty || !editor_empty, ActiveView::Thread { .. } => !is_empty || !editor_empty,
ActiveView::TextThread { .. } => true, ActiveView::PromptEditor { .. } => true,
_ => false, _ => false,
}; };
@@ -1996,7 +1949,7 @@ impl AgentPanel {
Some(token_count) Some(token_count)
} }
ActiveView::TextThread { context_editor, .. } => { ActiveView::PromptEditor { context_editor, .. } => {
let element = render_remaining_tokens(context_editor, cx)?; let element = render_remaining_tokens(context_editor, cx)?;
Some(element.into_any_element()) Some(element.into_any_element())
@@ -2710,7 +2663,7 @@ impl AgentPanel {
.on_click(cx.listener(|this, _, window, cx| { .on_click(cx.listener(|this, _, window, cx| {
this.thread.update(cx, |active_thread, cx| { this.thread.update(cx, |active_thread, cx| {
active_thread.thread().update(cx, |thread, _cx| { active_thread.thread().update(cx, |thread, _cx| {
thread.set_completion_mode(CompletionMode::Burn); thread.set_completion_mode(CompletionMode::Max);
}); });
}); });
this.continue_conversation(window, cx); this.continue_conversation(window, cx);
@@ -2914,7 +2867,7 @@ impl AgentPanel {
) -> Div { ) -> Div {
let mut registrar = buffer_search::DivRegistrar::new( let mut registrar = buffer_search::DivRegistrar::new(
|this, _, _cx| match &this.active_view { |this, _, _cx| match &this.active_view {
ActiveView::TextThread { ActiveView::PromptEditor {
buffer_search_bar, .. buffer_search_bar, ..
} => Some(buffer_search_bar.clone()), } => Some(buffer_search_bar.clone()),
_ => None, _ => None,
@@ -3032,7 +2985,7 @@ impl AgentPanel {
.detach(); .detach();
}); });
} }
ActiveView::TextThread { context_editor, .. } => { ActiveView::PromptEditor { context_editor, .. } => {
context_editor.update(cx, |context_editor, cx| { context_editor.update(cx, |context_editor, cx| {
ContextEditor::insert_dragged_files( ContextEditor::insert_dragged_files(
context_editor, context_editor,
@@ -3059,7 +3012,7 @@ impl AgentPanel {
fn key_context(&self) -> KeyContext { fn key_context(&self) -> KeyContext {
let mut key_context = KeyContext::new_with_defaults(); let mut key_context = KeyContext::new_with_defaults();
key_context.add("AgentPanel"); key_context.add("AgentPanel");
if matches!(self.active_view, ActiveView::TextThread { .. }) { if matches!(self.active_view, ActiveView::PromptEditor { .. }) {
key_context.add("prompt_editor"); key_context.add("prompt_editor");
} }
key_context key_context
@@ -3107,12 +3060,11 @@ impl Render for AgentPanel {
.on_action(cx.listener(|this, _: &ContinueWithBurnMode, window, cx| { .on_action(cx.listener(|this, _: &ContinueWithBurnMode, window, cx| {
this.thread.update(cx, |active_thread, cx| { this.thread.update(cx, |active_thread, cx| {
active_thread.thread().update(cx, |thread, _cx| { active_thread.thread().update(cx, |thread, _cx| {
thread.set_completion_mode(CompletionMode::Burn); thread.set_completion_mode(CompletionMode::Max);
}); });
}); });
this.continue_conversation(window, cx); this.continue_conversation(window, cx);
})) }))
.on_action(cx.listener(Self::toggle_burn_mode))
.child(self.render_toolbar(window, cx)) .child(self.render_toolbar(window, cx))
.children(self.render_upsell(window, cx)) .children(self.render_upsell(window, cx))
.children(self.render_trial_end_upsell(window, cx)) .children(self.render_trial_end_upsell(window, cx))
@@ -3125,7 +3077,7 @@ impl Render for AgentPanel {
.children(self.render_last_error(cx)) .children(self.render_last_error(cx))
.child(self.render_drag_target(cx)), .child(self.render_drag_target(cx)),
ActiveView::History => parent.child(self.history.clone()), ActiveView::History => parent.child(self.history.clone()),
ActiveView::TextThread { ActiveView::PromptEditor {
context_editor, context_editor,
buffer_search_bar, buffer_search_bar,
.. ..

View File

@@ -1,334 +0,0 @@
use std::sync::Arc;
use agent_settings::{AgentProfileId, AgentProfileSettings, AgentSettings};
use assistant_tool::{Tool, ToolSource, ToolWorkingSet};
use collections::IndexMap;
use convert_case::{Case, Casing};
use fs::Fs;
use gpui::{App, Entity};
use settings::{Settings, update_settings_file};
use ui::SharedString;
use util::ResultExt;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct AgentProfile {
id: AgentProfileId,
tool_set: Entity<ToolWorkingSet>,
}
pub type AvailableProfiles = IndexMap<AgentProfileId, SharedString>;
impl AgentProfile {
pub fn new(id: AgentProfileId, tool_set: Entity<ToolWorkingSet>) -> Self {
Self { id, tool_set }
}
/// Saves a new profile to the settings.
pub fn create(
name: String,
base_profile_id: Option<AgentProfileId>,
fs: Arc<dyn Fs>,
cx: &App,
) -> AgentProfileId {
let id = AgentProfileId(name.to_case(Case::Kebab).into());
let base_profile =
base_profile_id.and_then(|id| AgentSettings::get_global(cx).profiles.get(&id).cloned());
let profile_settings = AgentProfileSettings {
name: name.into(),
tools: base_profile
.as_ref()
.map(|profile| profile.tools.clone())
.unwrap_or_default(),
enable_all_context_servers: base_profile
.as_ref()
.map(|profile| profile.enable_all_context_servers)
.unwrap_or_default(),
context_servers: base_profile
.map(|profile| profile.context_servers)
.unwrap_or_default(),
};
update_settings_file::<AgentSettings>(fs, cx, {
let id = id.clone();
move |settings, _cx| {
settings.create_profile(id, profile_settings).log_err();
}
});
id
}
/// Returns a map of AgentProfileIds to their names
pub fn available_profiles(cx: &App) -> AvailableProfiles {
let mut profiles = AvailableProfiles::default();
for (id, profile) in AgentSettings::get_global(cx).profiles.iter() {
profiles.insert(id.clone(), profile.name.clone());
}
profiles
}
pub fn id(&self) -> &AgentProfileId {
&self.id
}
pub fn enabled_tools(&self, cx: &App) -> Vec<Arc<dyn Tool>> {
let Some(settings) = AgentSettings::get_global(cx).profiles.get(&self.id) else {
return Vec::new();
};
self.tool_set
.read(cx)
.tools(cx)
.into_iter()
.filter(|tool| Self::is_enabled(settings, tool.source(), tool.name()))
.collect()
}
fn is_enabled(settings: &AgentProfileSettings, source: ToolSource, name: String) -> bool {
match source {
ToolSource::Native => *settings.tools.get(name.as_str()).unwrap_or(&false),
ToolSource::ContextServer { id } => {
if settings.enable_all_context_servers {
return true;
}
let Some(preset) = settings.context_servers.get(id.as_ref()) else {
return false;
};
*preset.tools.get(name.as_str()).unwrap_or(&false)
}
}
}
}
#[cfg(test)]
mod tests {
use agent_settings::ContextServerPreset;
use assistant_tool::ToolRegistry;
use collections::IndexMap;
use gpui::{AppContext, TestAppContext};
use http_client::FakeHttpClient;
use project::Project;
use settings::{Settings, SettingsStore};
use ui::SharedString;
use super::*;
#[gpui::test]
async fn test_enabled_built_in_tools_for_profile(cx: &mut TestAppContext) {
init_test_settings(cx);
let id = AgentProfileId::default();
let profile_settings = cx.read(|cx| {
AgentSettings::get_global(cx)
.profiles
.get(&id)
.unwrap()
.clone()
});
let tool_set = default_tool_set(cx);
let profile = AgentProfile::new(id.clone(), tool_set);
let mut enabled_tools = cx
.read(|cx| profile.enabled_tools(cx))
.into_iter()
.map(|tool| tool.name())
.collect::<Vec<_>>();
enabled_tools.sort();
let mut expected_tools = profile_settings
.tools
.into_iter()
.filter_map(|(tool, enabled)| enabled.then_some(tool.to_string()))
// Provider dependent
.filter(|tool| tool != "web_search")
.collect::<Vec<_>>();
// Plus all registered MCP tools
expected_tools.extend(["enabled_mcp_tool".into(), "disabled_mcp_tool".into()]);
expected_tools.sort();
assert_eq!(enabled_tools, expected_tools);
}
#[gpui::test]
async fn test_custom_mcp_settings(cx: &mut TestAppContext) {
init_test_settings(cx);
let id = AgentProfileId("custom_mcp".into());
let profile_settings = cx.read(|cx| {
AgentSettings::get_global(cx)
.profiles
.get(&id)
.unwrap()
.clone()
});
let tool_set = default_tool_set(cx);
let profile = AgentProfile::new(id.clone(), tool_set);
let mut enabled_tools = cx
.read(|cx| profile.enabled_tools(cx))
.into_iter()
.map(|tool| tool.name())
.collect::<Vec<_>>();
enabled_tools.sort();
let mut expected_tools = profile_settings.context_servers["mcp"]
.tools
.iter()
.filter_map(|(key, enabled)| enabled.then(|| key.to_string()))
.collect::<Vec<_>>();
expected_tools.sort();
assert_eq!(enabled_tools, expected_tools);
}
#[gpui::test]
async fn test_only_built_in(cx: &mut TestAppContext) {
init_test_settings(cx);
let id = AgentProfileId("write_minus_mcp".into());
let profile_settings = cx.read(|cx| {
AgentSettings::get_global(cx)
.profiles
.get(&id)
.unwrap()
.clone()
});
let tool_set = default_tool_set(cx);
let profile = AgentProfile::new(id.clone(), tool_set);
let mut enabled_tools = cx
.read(|cx| profile.enabled_tools(cx))
.into_iter()
.map(|tool| tool.name())
.collect::<Vec<_>>();
enabled_tools.sort();
let mut expected_tools = profile_settings
.tools
.into_iter()
.filter_map(|(tool, enabled)| enabled.then_some(tool.to_string()))
// Provider dependent
.filter(|tool| tool != "web_search")
.collect::<Vec<_>>();
expected_tools.sort();
assert_eq!(enabled_tools, expected_tools);
}
fn init_test_settings(cx: &mut TestAppContext) {
cx.update(|cx| {
let settings_store = SettingsStore::test(cx);
cx.set_global(settings_store);
Project::init_settings(cx);
AgentSettings::register(cx);
language_model::init_settings(cx);
ToolRegistry::default_global(cx);
assistant_tools::init(FakeHttpClient::with_404_response(), cx);
});
cx.update(|cx| {
let mut agent_settings = AgentSettings::get_global(cx).clone();
agent_settings.profiles.insert(
AgentProfileId("write_minus_mcp".into()),
AgentProfileSettings {
name: "write_minus_mcp".into(),
enable_all_context_servers: false,
..agent_settings.profiles[&AgentProfileId::default()].clone()
},
);
agent_settings.profiles.insert(
AgentProfileId("custom_mcp".into()),
AgentProfileSettings {
name: "mcp".into(),
tools: IndexMap::default(),
enable_all_context_servers: false,
context_servers: IndexMap::from_iter([("mcp".into(), context_server_preset())]),
},
);
AgentSettings::override_global(agent_settings, cx);
})
}
fn context_server_preset() -> ContextServerPreset {
ContextServerPreset {
tools: IndexMap::from_iter([
("enabled_mcp_tool".into(), true),
("disabled_mcp_tool".into(), false),
]),
}
}
fn default_tool_set(cx: &mut TestAppContext) -> Entity<ToolWorkingSet> {
cx.new(|_| {
let mut tool_set = ToolWorkingSet::default();
tool_set.insert(Arc::new(FakeTool::new("enabled_mcp_tool", "mcp")));
tool_set.insert(Arc::new(FakeTool::new("disabled_mcp_tool", "mcp")));
tool_set
})
}
struct FakeTool {
name: String,
source: SharedString,
}
impl FakeTool {
fn new(name: impl Into<String>, source: impl Into<SharedString>) -> Self {
Self {
name: name.into(),
source: source.into(),
}
}
}
impl Tool for FakeTool {
fn name(&self) -> String {
self.name.clone()
}
fn source(&self) -> ToolSource {
ToolSource::ContextServer {
id: self.source.clone(),
}
}
fn description(&self) -> String {
unimplemented!()
}
fn icon(&self) -> ui::IconName {
unimplemented!()
}
fn needs_confirmation(&self, _input: &serde_json::Value, _cx: &App) -> bool {
unimplemented!()
}
fn ui_text(&self, _input: &serde_json::Value) -> String {
unimplemented!()
}
fn run(
self: Arc<Self>,
_input: serde_json::Value,
_request: Arc<language_model::LanguageModelRequest>,
_project: Entity<Project>,
_action_log: Entity<assistant_tool::ActionLog>,
_model: Arc<dyn language_model::LanguageModel>,
_window: Option<gpui::AnyWindowHandle>,
_cx: &mut App,
) -> assistant_tool::ToolResult {
unimplemented!()
}
fn may_perform_edits(&self) -> bool {
unimplemented!()
}
}
}

View File

@@ -34,7 +34,6 @@ use std::{
}; };
use streaming_diff::{CharOperation, LineDiff, LineOperation, StreamingDiff}; use streaming_diff::{CharOperation, LineDiff, LineOperation, StreamingDiff};
use telemetry_events::{AssistantEventData, AssistantKind, AssistantPhase}; use telemetry_events::{AssistantEventData, AssistantKind, AssistantPhase};
use zed_llm_client::CompletionIntent;
pub struct BufferCodegen { pub struct BufferCodegen {
alternatives: Vec<Entity<CodegenAlternative>>, alternatives: Vec<Entity<CodegenAlternative>>,
@@ -386,10 +385,8 @@ impl CodegenAlternative {
async { Ok(LanguageModelTextStream::default()) }.boxed_local() async { Ok(LanguageModelTextStream::default()) }.boxed_local()
} else { } else {
let request = self.build_request(&model, user_prompt, cx)?; let request = self.build_request(&model, user_prompt, cx)?;
cx.spawn(async move |_, cx| { cx.spawn(async move |_, cx| model.stream_completion_text(request.await, &cx).await)
Ok(model.stream_completion_text(request.await, &cx).await?) .boxed_local()
})
.boxed_local()
}; };
self.handle_stream(telemetry_id, provider_id.to_string(), api_key, stream, cx); self.handle_stream(telemetry_id, provider_id.to_string(), api_key, stream, cx);
Ok(()) Ok(())
@@ -467,7 +464,6 @@ impl CodegenAlternative {
LanguageModelRequest { LanguageModelRequest {
thread_id: None, thread_id: None,
prompt_id: None, prompt_id: None,
intent: Some(CompletionIntent::InlineAssist),
mode: None, mode: None,
tools: Vec::new(), tools: Vec::new(),
tool_choice: None, tool_choice: None,

View File

@@ -734,7 +734,6 @@ impl Display for RulesContext {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ImageContext { pub struct ImageContext {
pub project_path: Option<ProjectPath>, pub project_path: Option<ProjectPath>,
pub full_path: Option<Arc<Path>>,
pub original_image: Arc<gpui::Image>, pub original_image: Arc<gpui::Image>,
// TODO: handle this elsewhere and remove `ignore-interior-mutability` opt-out in clippy.toml // TODO: handle this elsewhere and remove `ignore-interior-mutability` opt-out in clippy.toml
// needed due to a false positive of `clippy::mutable_key_type`. // needed due to a false positive of `clippy::mutable_key_type`.
@@ -745,7 +744,6 @@ pub struct ImageContext {
pub enum ImageStatus { pub enum ImageStatus {
Loading, Loading,
Error, Error,
Warning,
Ready, Ready,
} }
@@ -762,17 +760,11 @@ impl ImageContext {
self.image_task.clone().now_or_never().flatten() self.image_task.clone().now_or_never().flatten()
} }
pub fn status(&self, model: Option<&Arc<dyn language_model::LanguageModel>>) -> ImageStatus { pub fn status(&self) -> ImageStatus {
match self.image_task.clone().now_or_never() { match self.image_task.clone().now_or_never() {
None => ImageStatus::Loading, None => ImageStatus::Loading,
Some(None) => ImageStatus::Error, Some(None) => ImageStatus::Error,
Some(Some(_)) => { Some(Some(_)) => ImageStatus::Ready,
if model.is_some_and(|model| !model.supports_images()) {
ImageStatus::Warning
} else {
ImageStatus::Ready
}
}
} }
} }

View File

@@ -1,5 +1,7 @@
use std::cell::RefCell;
use std::ops::Range; use std::ops::Range;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::sync::Arc; use std::sync::Arc;
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
@@ -12,7 +14,7 @@ use http_client::HttpClientWithUrl;
use itertools::Itertools; use itertools::Itertools;
use language::{Buffer, CodeLabel, HighlightId}; use language::{Buffer, CodeLabel, HighlightId};
use lsp::CompletionContext; use lsp::CompletionContext;
use project::{Completion, CompletionIntent, CompletionResponse, ProjectPath, Symbol, WorktreeId}; use project::{Completion, CompletionIntent, ProjectPath, Symbol, WorktreeId};
use prompt_store::PromptStore; use prompt_store::PromptStore;
use rope::Point; use rope::Point;
use text::{Anchor, OffsetRangeExt, ToPoint}; use text::{Anchor, OffsetRangeExt, ToPoint};
@@ -744,7 +746,7 @@ impl CompletionProvider for ContextPickerCompletionProvider {
_trigger: CompletionContext, _trigger: CompletionContext,
_window: &mut Window, _window: &mut Window,
cx: &mut Context<Editor>, cx: &mut Context<Editor>,
) -> Task<Result<Vec<CompletionResponse>>> { ) -> Task<Result<Option<Vec<Completion>>>> {
let state = buffer.update(cx, |buffer, _cx| { let state = buffer.update(cx, |buffer, _cx| {
let position = buffer_position.to_point(buffer); let position = buffer_position.to_point(buffer);
let line_start = Point::new(position.row, 0); let line_start = Point::new(position.row, 0);
@@ -754,18 +756,18 @@ impl CompletionProvider for ContextPickerCompletionProvider {
MentionCompletion::try_parse(line, offset_to_line) MentionCompletion::try_parse(line, offset_to_line)
}); });
let Some(state) = state else { let Some(state) = state else {
return Task::ready(Ok(Vec::new())); return Task::ready(Ok(None));
}; };
let Some((workspace, context_store)) = let Some((workspace, context_store)) =
self.workspace.upgrade().zip(self.context_store.upgrade()) self.workspace.upgrade().zip(self.context_store.upgrade())
else { else {
return Task::ready(Ok(Vec::new())); return Task::ready(Ok(None));
}; };
let snapshot = buffer.read(cx).snapshot(); let snapshot = buffer.read(cx).snapshot();
let source_range = snapshot.anchor_before(state.source_range.start) let source_range = snapshot.anchor_before(state.source_range.start)
..snapshot.anchor_after(state.source_range.end); ..snapshot.anchor_before(state.source_range.end);
let thread_store = self.thread_store.clone(); let thread_store = self.thread_store.clone();
let text_thread_store = self.text_thread_store.clone(); let text_thread_store = self.text_thread_store.clone();
@@ -813,10 +815,10 @@ impl CompletionProvider for ContextPickerCompletionProvider {
cx.spawn(async move |_, cx| { cx.spawn(async move |_, cx| {
let matches = search_task.await; let matches = search_task.await;
let Some(editor) = editor.upgrade() else { let Some(editor) = editor.upgrade() else {
return Ok(Vec::new()); return Ok(None);
}; };
let completions = cx.update(|cx| { Ok(Some(cx.update(|cx| {
matches matches
.into_iter() .into_iter()
.filter_map(|mat| match mat { .filter_map(|mat| match mat {
@@ -899,24 +901,26 @@ impl CompletionProvider for ContextPickerCompletionProvider {
), ),
}) })
.collect() .collect()
})?; })?))
Ok(vec![CompletionResponse {
completions,
// Since this does its own filtering (see `filter_completions()` returns false),
// there is no benefit to computing whether this set of completions is incomplete.
is_incomplete: true,
}])
}) })
} }
fn resolve_completions(
&self,
_buffer: Entity<Buffer>,
_completion_indices: Vec<usize>,
_completions: Rc<RefCell<Box<[Completion]>>>,
_cx: &mut Context<Editor>,
) -> Task<Result<bool>> {
Task::ready(Ok(true))
}
fn is_completion_trigger( fn is_completion_trigger(
&self, &self,
buffer: &Entity<language::Buffer>, buffer: &Entity<language::Buffer>,
position: language::Anchor, position: language::Anchor,
_text: &str, _: &str,
_trigger_in_words: bool, _: bool,
_menu_is_open: bool,
cx: &mut Context<Editor>, cx: &mut Context<Editor>,
) -> bool { ) -> bool {
let buffer = buffer.read(cx); let buffer = buffer.read(cx);
@@ -1065,7 +1069,7 @@ mod tests {
use project::{Project, ProjectPath}; use project::{Project, ProjectPath};
use serde_json::json; use serde_json::json;
use settings::SettingsStore; use settings::SettingsStore;
use std::{ops::Deref, rc::Rc}; use std::ops::Deref;
use util::{path, separator}; use util::{path, separator};
use workspace::{AppState, Item}; use workspace::{AppState, Item};

View File

@@ -282,18 +282,15 @@ pub fn unordered_thread_entries(
text_thread_store: Entity<TextThreadStore>, text_thread_store: Entity<TextThreadStore>,
cx: &App, cx: &App,
) -> impl Iterator<Item = (DateTime<Utc>, ThreadContextEntry)> { ) -> impl Iterator<Item = (DateTime<Utc>, ThreadContextEntry)> {
let threads = thread_store let threads = thread_store.read(cx).unordered_threads().map(|thread| {
.read(cx) (
.reverse_chronological_threads() thread.updated_at,
.map(|thread| { ThreadContextEntry::Thread {
( id: thread.id.clone(),
thread.updated_at, title: thread.summary.clone(),
ThreadContextEntry::Thread { },
id: thread.id.clone(), )
title: thread.summary.clone(), });
},
)
});
let text_threads = text_thread_store let text_threads = text_thread_store
.read(cx) .read(cx)
@@ -303,7 +300,7 @@ pub fn unordered_thread_entries(
context.mtime.to_utc(), context.mtime.to_utc(),
ThreadContextEntry::Context { ThreadContextEntry::Context {
path: context.path.clone(), path: context.path.clone(),
title: context.title.clone(), title: context.title.clone().into(),
}, },
) )
}); });

View File

@@ -30,6 +30,10 @@ impl ContextServerTool {
impl Tool for ContextServerTool { impl Tool for ContextServerTool {
fn name(&self) -> String { fn name(&self) -> String {
format!("{}-{}", self.server_id, self.tool.name)
}
fn ui_name(&self) -> String {
self.tool.name.clone() self.tool.name.clone()
} }
@@ -51,10 +55,6 @@ impl Tool for ContextServerTool {
true true
} }
fn may_perform_edits(&self) -> bool {
true
}
fn input_schema(&self, format: LanguageModelToolSchemaFormat) -> Result<serde_json::Value> { fn input_schema(&self, format: LanguageModelToolSchemaFormat) -> Result<serde_json::Value> {
let mut schema = self.tool.input_schema.clone(); let mut schema = self.tool.input_schema.clone();
assistant_tool::adapt_schema_to_format(&mut schema, format)?; assistant_tool::adapt_schema_to_format(&mut schema, format)?;
@@ -104,15 +104,7 @@ impl Tool for ContextServerTool {
tool_name, tool_name,
arguments arguments
); );
let response = protocol let response = protocol.run_tool(tool_name, arguments).await?;
.request::<context_server::types::requests::CallTool>(
context_server::types::CallToolParams {
name: tool_name,
arguments,
meta: None,
},
)
.await?;
let mut result = String::new(); let mut result = String::new();
for content in response.content { for content in response.content {
@@ -123,9 +115,6 @@ impl Tool for ContextServerTool {
types::ToolResponseContent::Image { .. } => { types::ToolResponseContent::Image { .. } => {
log::warn!("Ignoring image content from tool response"); log::warn!("Ignoring image content from tool response");
} }
types::ToolResponseContent::Audio { .. } => {
log::warn!("Ignoring audio content from tool response");
}
types::ToolResponseContent::Resource { .. } => { types::ToolResponseContent::Resource { .. } => {
log::warn!("Ignoring resource content from tool response"); log::warn!("Ignoring resource content from tool response");
} }

View File

@@ -7,7 +7,7 @@ use assistant_context_editor::AssistantContext;
use collections::{HashSet, IndexSet}; use collections::{HashSet, IndexSet};
use futures::{self, FutureExt}; use futures::{self, FutureExt};
use gpui::{App, Context, Entity, EventEmitter, Image, SharedString, Task, WeakEntity}; use gpui::{App, Context, Entity, EventEmitter, Image, SharedString, Task, WeakEntity};
use language::{Buffer, File as _}; use language::Buffer;
use language_model::LanguageModelImage; use language_model::LanguageModelImage;
use project::image_store::is_image_file; use project::image_store::is_image_file;
use project::{Project, ProjectItem, ProjectPath, Symbol}; use project::{Project, ProjectItem, ProjectPath, Symbol};
@@ -304,13 +304,11 @@ impl ContextStore {
project.open_image(project_path.clone(), cx) project.open_image(project_path.clone(), cx)
})?; })?;
let image_item = open_image_task.await?; let image_item = open_image_task.await?;
let image = image_item.read_with(cx, |image_item, _| image_item.image.clone())?;
this.update(cx, |this, cx| { this.update(cx, |this, cx| {
let item = image_item.read(cx);
this.insert_image( this.insert_image(
Some(item.project_path(cx)), Some(image_item.read(cx).project_path(cx)),
Some(item.file.full_path(cx).into()), image,
item.image.clone(),
remove_if_exists, remove_if_exists,
cx, cx,
) )
@@ -319,13 +317,12 @@ impl ContextStore {
} }
pub fn add_image_instance(&mut self, image: Arc<Image>, cx: &mut Context<ContextStore>) { pub fn add_image_instance(&mut self, image: Arc<Image>, cx: &mut Context<ContextStore>) {
self.insert_image(None, None, image, false, cx); self.insert_image(None, image, false, cx);
} }
fn insert_image( fn insert_image(
&mut self, &mut self,
project_path: Option<ProjectPath>, project_path: Option<ProjectPath>,
full_path: Option<Arc<Path>>,
image: Arc<Image>, image: Arc<Image>,
remove_if_exists: bool, remove_if_exists: bool,
cx: &mut Context<ContextStore>, cx: &mut Context<ContextStore>,
@@ -333,7 +330,6 @@ impl ContextStore {
let image_task = LanguageModelImage::from_image(image.clone(), cx).shared(); let image_task = LanguageModelImage::from_image(image.clone(), cx).shared();
let context = AgentContextHandle::Image(ImageContext { let context = AgentContextHandle::Image(ImageContext {
project_path, project_path,
full_path,
original_image: image, original_image: image,
image_task, image_task,
context_id: self.next_context_id.post_inc(), context_id: self.next_context_id.post_inc(),

View File

@@ -23,7 +23,7 @@ use crate::thread_store::{TextThreadStore, ThreadStore};
use crate::ui::{AddedContext, ContextPill}; use crate::ui::{AddedContext, ContextPill};
use crate::{ use crate::{
AcceptSuggestedContext, AgentPanel, FocusDown, FocusLeft, FocusRight, FocusUp, AcceptSuggestedContext, AgentPanel, FocusDown, FocusLeft, FocusRight, FocusUp,
ModelUsageContext, RemoveAllContext, RemoveFocusedContext, ToggleContextPicker, RemoveAllContext, RemoveFocusedContext, ToggleContextPicker,
}; };
pub struct ContextStrip { pub struct ContextStrip {
@@ -37,7 +37,6 @@ pub struct ContextStrip {
_subscriptions: Vec<Subscription>, _subscriptions: Vec<Subscription>,
focused_index: Option<usize>, focused_index: Option<usize>,
children_bounds: Option<Vec<Bounds<Pixels>>>, children_bounds: Option<Vec<Bounds<Pixels>>>,
model_usage_context: ModelUsageContext,
} }
impl ContextStrip { impl ContextStrip {
@@ -48,7 +47,6 @@ impl ContextStrip {
text_thread_store: Option<WeakEntity<TextThreadStore>>, text_thread_store: Option<WeakEntity<TextThreadStore>>,
context_picker_menu_handle: PopoverMenuHandle<ContextPicker>, context_picker_menu_handle: PopoverMenuHandle<ContextPicker>,
suggest_context_kind: SuggestContextKind, suggest_context_kind: SuggestContextKind,
model_usage_context: ModelUsageContext,
window: &mut Window, window: &mut Window,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> Self { ) -> Self {
@@ -83,7 +81,6 @@ impl ContextStrip {
_subscriptions: subscriptions, _subscriptions: subscriptions,
focused_index: None, focused_index: None,
children_bounds: None, children_bounds: None,
model_usage_context,
} }
} }
@@ -101,20 +98,11 @@ impl ContextStrip {
.as_ref() .as_ref()
.and_then(|thread_store| thread_store.upgrade()) .and_then(|thread_store| thread_store.upgrade())
.and_then(|thread_store| thread_store.read(cx).prompt_store().as_ref()); .and_then(|thread_store| thread_store.read(cx).prompt_store().as_ref());
let current_model = self.model_usage_context.language_model(cx);
self.context_store self.context_store
.read(cx) .read(cx)
.context() .context()
.flat_map(|context| { .flat_map(|context| {
AddedContext::new_pending( AddedContext::new_pending(context.clone(), prompt_store, project, cx)
context.clone(),
prompt_store,
project,
current_model.as_ref(),
cx,
)
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()
} else { } else {

View File

@@ -1,17 +1,18 @@
use std::{collections::VecDeque, path::Path, sync::Arc}; use std::{collections::VecDeque, path::Path, sync::Arc};
use anyhow::{Context as _, Result}; use anyhow::Context as _;
use assistant_context_editor::SavedContextMetadata; use assistant_context_editor::{AssistantContext, SavedContextMetadata};
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use gpui::{AsyncApp, Entity, SharedString, Task, prelude::*}; use futures::future::{TryFutureExt as _, join_all};
use itertools::Itertools; use gpui::{Entity, Task, prelude::*};
use paths::contexts_dir;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use smol::future::FutureExt;
use std::time::Duration; use std::time::Duration;
use ui::App; use ui::{App, SharedString, Window};
use util::ResultExt as _; use util::ResultExt as _;
use crate::{ use crate::{
Thread,
thread::ThreadId, thread::ThreadId,
thread_store::{SerializedThreadMetadata, ThreadStore}, thread_store::{SerializedThreadMetadata, ThreadStore},
}; };
@@ -40,34 +41,52 @@ impl HistoryEntry {
HistoryEntry::Context(context) => HistoryEntryId::Context(context.path.clone()), HistoryEntry::Context(context) => HistoryEntryId::Context(context.path.clone()),
} }
} }
pub fn title(&self) -> &SharedString {
match self {
HistoryEntry::Thread(thread) => &thread.summary,
HistoryEntry::Context(context) => &context.title,
}
}
} }
/// Generic identifier for a history entry. /// Generic identifier for a history entry.
#[derive(Clone, PartialEq, Eq, Debug)] #[derive(Clone, PartialEq, Eq)]
pub enum HistoryEntryId { pub enum HistoryEntryId {
Thread(ThreadId), Thread(ThreadId),
Context(Arc<Path>), Context(Arc<Path>),
} }
#[derive(Clone, Debug)]
pub(crate) enum RecentEntry {
Thread(ThreadId, Entity<Thread>),
Context(Entity<AssistantContext>),
}
impl PartialEq for RecentEntry {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Thread(l0, _), Self::Thread(r0, _)) => l0 == r0,
(Self::Context(l0), Self::Context(r0)) => l0 == r0,
_ => false,
}
}
}
impl Eq for RecentEntry {}
impl RecentEntry {
pub(crate) fn summary(&self, cx: &App) -> SharedString {
match self {
RecentEntry::Thread(_, thread) => thread.read(cx).summary().or_default(),
RecentEntry::Context(context) => context.read(cx).summary().or_default(),
}
}
}
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
enum SerializedRecentOpen { enum SerializedRecentEntry {
Thread(String), Thread(String),
ContextName(String),
/// Old format which stores the full path
Context(String), Context(String),
} }
pub struct HistoryStore { pub struct HistoryStore {
thread_store: Entity<ThreadStore>, thread_store: Entity<ThreadStore>,
context_store: Entity<assistant_context_editor::ContextStore>, context_store: Entity<assistant_context_editor::ContextStore>,
recently_opened_entries: VecDeque<HistoryEntryId>, recently_opened_entries: VecDeque<RecentEntry>,
_subscriptions: Vec<gpui::Subscription>, _subscriptions: Vec<gpui::Subscription>,
_save_recently_opened_entries_task: Task<()>, _save_recently_opened_entries_task: Task<()>,
} }
@@ -76,7 +95,8 @@ impl HistoryStore {
pub fn new( pub fn new(
thread_store: Entity<ThreadStore>, thread_store: Entity<ThreadStore>,
context_store: Entity<assistant_context_editor::ContextStore>, context_store: Entity<assistant_context_editor::ContextStore>,
initial_recent_entries: impl IntoIterator<Item = HistoryEntryId>, initial_recent_entries: impl IntoIterator<Item = RecentEntry>,
window: &mut Window,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> Self { ) -> Self {
let subscriptions = vec![ let subscriptions = vec![
@@ -84,20 +104,68 @@ impl HistoryStore {
cx.observe(&context_store, |_, _, cx| cx.notify()), cx.observe(&context_store, |_, _, cx| cx.notify()),
]; ];
cx.spawn(async move |this, cx| { window
let entries = Self::load_recently_opened_entries(cx).await.log_err()?; .spawn(cx, {
this.update(cx, |this, _| { let thread_store = thread_store.downgrade();
this.recently_opened_entries let context_store = context_store.downgrade();
.extend( let this = cx.weak_entity();
entries.into_iter().take( async move |cx| {
MAX_RECENTLY_OPENED_ENTRIES let path = paths::data_dir().join(NAVIGATION_HISTORY_PATH);
.saturating_sub(this.recently_opened_entries.len()), let contents = cx
), .background_spawn(async move { std::fs::read_to_string(path) })
); .await
.ok()?;
let entries = serde_json::from_str::<Vec<SerializedRecentEntry>>(&contents)
.context("deserializing persisted agent panel navigation history")
.log_err()?
.into_iter()
.take(MAX_RECENTLY_OPENED_ENTRIES)
.map(|serialized| match serialized {
SerializedRecentEntry::Thread(id) => thread_store
.update_in(cx, |thread_store, window, cx| {
let thread_id = ThreadId::from(id.as_str());
thread_store
.open_thread(&thread_id, window, cx)
.map_ok(|thread| RecentEntry::Thread(thread_id, thread))
.boxed()
})
.unwrap_or_else(|_| {
async {
anyhow::bail!("no thread store");
}
.boxed()
}),
SerializedRecentEntry::Context(id) => context_store
.update(cx, |context_store, cx| {
context_store
.open_local_context(Path::new(&id).into(), cx)
.map_ok(RecentEntry::Context)
.boxed()
})
.unwrap_or_else(|_| {
async {
anyhow::bail!("no context store");
}
.boxed()
}),
});
let entries = join_all(entries)
.await
.into_iter()
.filter_map(|result| result.log_err())
.collect::<VecDeque<_>>();
this.update(cx, |this, _| {
this.recently_opened_entries.extend(entries);
this.recently_opened_entries
.truncate(MAX_RECENTLY_OPENED_ENTRIES);
})
.ok();
Some(())
}
}) })
.ok() .detach();
})
.detach();
Self { Self {
thread_store, thread_store,
@@ -116,20 +184,19 @@ impl HistoryStore {
return history_entries; return history_entries;
} }
history_entries.extend( for thread in self
self.thread_store .thread_store
.read(cx) .update(cx, |this, _cx| this.reverse_chronological_threads())
.reverse_chronological_threads() {
.cloned() history_entries.push(HistoryEntry::Thread(thread));
.map(HistoryEntry::Thread), }
);
history_entries.extend( for context in self
self.context_store .context_store
.read(cx) .update(cx, |this, _cx| this.reverse_chronological_contexts())
.unordered_contexts() {
.cloned() history_entries.push(HistoryEntry::Context(context));
.map(HistoryEntry::Context), }
);
history_entries.sort_unstable_by_key(|entry| std::cmp::Reverse(entry.updated_at())); history_entries.sort_unstable_by_key(|entry| std::cmp::Reverse(entry.updated_at()));
history_entries history_entries
@@ -139,62 +206,15 @@ impl HistoryStore {
self.entries(cx).into_iter().take(limit).collect() self.entries(cx).into_iter().take(limit).collect()
} }
pub fn recently_opened_entries(&self, cx: &App) -> Vec<HistoryEntry> {
#[cfg(debug_assertions)]
if std::env::var("ZED_SIMULATE_NO_THREAD_HISTORY").is_ok() {
return Vec::new();
}
let thread_entries = self
.thread_store
.read(cx)
.reverse_chronological_threads()
.flat_map(|thread| {
self.recently_opened_entries
.iter()
.enumerate()
.flat_map(|(index, entry)| match entry {
HistoryEntryId::Thread(id) if &thread.id == id => {
Some((index, HistoryEntry::Thread(thread.clone())))
}
_ => None,
})
});
let context_entries =
self.context_store
.read(cx)
.unordered_contexts()
.flat_map(|context| {
self.recently_opened_entries
.iter()
.enumerate()
.flat_map(|(index, entry)| match entry {
HistoryEntryId::Context(path) if &context.path == path => {
Some((index, HistoryEntry::Context(context.clone())))
}
_ => None,
})
});
thread_entries
.chain(context_entries)
// optimization to halt iteration early
.take(self.recently_opened_entries.len())
.sorted_unstable_by_key(|(index, _)| *index)
.map(|(_, entry)| entry)
.collect()
}
fn save_recently_opened_entries(&mut self, cx: &mut Context<Self>) { fn save_recently_opened_entries(&mut self, cx: &mut Context<Self>) {
let serialized_entries = self let serialized_entries = self
.recently_opened_entries .recently_opened_entries
.iter() .iter()
.filter_map(|entry| match entry { .filter_map(|entry| match entry {
HistoryEntryId::Context(path) => path.file_name().map(|file| { RecentEntry::Context(context) => Some(SerializedRecentEntry::Context(
SerializedRecentOpen::ContextName(file.to_string_lossy().to_string()) context.read(cx).path()?.to_str()?.to_owned(),
}), )),
HistoryEntryId::Thread(id) => Some(SerializedRecentOpen::Thread(id.to_string())), RecentEntry::Thread(id, _) => Some(SerializedRecentEntry::Thread(id.to_string())),
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
@@ -213,33 +233,7 @@ impl HistoryStore {
}); });
} }
fn load_recently_opened_entries(cx: &AsyncApp) -> Task<Result<Vec<HistoryEntryId>>> { pub fn push_recently_opened_entry(&mut self, entry: RecentEntry, cx: &mut Context<Self>) {
cx.background_spawn(async move {
let path = paths::data_dir().join(NAVIGATION_HISTORY_PATH);
let contents = smol::fs::read_to_string(path).await?;
let entries = serde_json::from_str::<Vec<SerializedRecentOpen>>(&contents)
.context("deserializing persisted agent panel navigation history")?
.into_iter()
.take(MAX_RECENTLY_OPENED_ENTRIES)
.flat_map(|entry| match entry {
SerializedRecentOpen::Thread(id) => {
Some(HistoryEntryId::Thread(id.as_str().into()))
}
SerializedRecentOpen::ContextName(file_name) => Some(HistoryEntryId::Context(
contexts_dir().join(file_name).into(),
)),
SerializedRecentOpen::Context(path) => {
Path::new(&path).file_name().map(|file_name| {
HistoryEntryId::Context(contexts_dir().join(file_name).into())
})
}
})
.collect::<Vec<_>>();
Ok(entries)
})
}
pub fn push_recently_opened_entry(&mut self, entry: HistoryEntryId, cx: &mut Context<Self>) {
self.recently_opened_entries self.recently_opened_entries
.retain(|old_entry| old_entry != &entry); .retain(|old_entry| old_entry != &entry);
self.recently_opened_entries.push_front(entry); self.recently_opened_entries.push_front(entry);
@@ -250,33 +244,24 @@ impl HistoryStore {
pub fn remove_recently_opened_thread(&mut self, id: ThreadId, cx: &mut Context<Self>) { pub fn remove_recently_opened_thread(&mut self, id: ThreadId, cx: &mut Context<Self>) {
self.recently_opened_entries.retain(|entry| match entry { self.recently_opened_entries.retain(|entry| match entry {
HistoryEntryId::Thread(thread_id) if thread_id == &id => false, RecentEntry::Thread(thread_id, _) if thread_id == &id => false,
_ => true, _ => true,
}); });
self.save_recently_opened_entries(cx); self.save_recently_opened_entries(cx);
} }
pub fn replace_recently_opened_text_thread( pub fn remove_recently_opened_entry(&mut self, entry: &RecentEntry, cx: &mut Context<Self>) {
&mut self,
old_path: &Path,
new_path: &Arc<Path>,
cx: &mut Context<Self>,
) {
for entry in &mut self.recently_opened_entries {
match entry {
HistoryEntryId::Context(path) if path.as_ref() == old_path => {
*entry = HistoryEntryId::Context(new_path.clone());
break;
}
_ => {}
}
}
self.save_recently_opened_entries(cx);
}
pub fn remove_recently_opened_entry(&mut self, entry: &HistoryEntryId, cx: &mut Context<Self>) {
self.recently_opened_entries self.recently_opened_entries
.retain(|old_entry| old_entry != entry); .retain(|old_entry| old_entry != entry);
self.save_recently_opened_entries(cx); self.save_recently_opened_entries(cx);
} }
pub fn recently_opened_entries(&self, _cx: &mut Context<Self>) -> VecDeque<RecentEntry> {
#[cfg(debug_assertions)]
if std::env::var("ZED_SIMULATE_NO_THREAD_HISTORY").is_ok() {
return VecDeque::new();
}
self.recently_opened_entries.clone()
}
} }

View File

@@ -1011,7 +1011,7 @@ impl InlineAssistant {
self.update_editor_highlights(&editor, cx); self.update_editor_highlights(&editor, cx);
} }
} else { } else {
entry.get_mut().highlight_updates.send(()).ok(); entry.get().highlight_updates.send(()).ok();
} }
} }
@@ -1331,7 +1331,7 @@ impl InlineAssistant {
editor.clear_gutter_highlights::<GutterPendingRange>(cx); editor.clear_gutter_highlights::<GutterPendingRange>(cx);
} else { } else {
editor.highlight_gutter::<GutterPendingRange>( editor.highlight_gutter::<GutterPendingRange>(
gutter_pending_ranges, &gutter_pending_ranges,
|cx| cx.theme().status().info_background, |cx| cx.theme().status().info_background,
cx, cx,
) )
@@ -1342,7 +1342,7 @@ impl InlineAssistant {
editor.clear_gutter_highlights::<GutterTransformedRange>(cx); editor.clear_gutter_highlights::<GutterTransformedRange>(cx);
} else { } else {
editor.highlight_gutter::<GutterTransformedRange>( editor.highlight_gutter::<GutterTransformedRange>(
gutter_transformed_ranges, &gutter_transformed_ranges,
|cx| cx.theme().status().info, |cx| cx.theme().status().info,
cx, cx,
) )
@@ -1445,7 +1445,7 @@ impl InlineAssistant {
style: BlockStyle::Flex, style: BlockStyle::Flex,
render: Arc::new(move |cx| { render: Arc::new(move |cx| {
div() div()
.block_mouse_except_scroll() .block_mouse_down()
.bg(cx.theme().status().deleted_background) .bg(cx.theme().status().deleted_background)
.size_full() .size_full()
.h(height as f32 * cx.window.line_height()) .h(height as f32 * cx.window.line_height())
@@ -1519,7 +1519,7 @@ impl InlineAssistant {
struct EditorInlineAssists { struct EditorInlineAssists {
assist_ids: Vec<InlineAssistId>, assist_ids: Vec<InlineAssistId>,
scroll_lock: Option<InlineAssistScrollLock>, scroll_lock: Option<InlineAssistScrollLock>,
highlight_updates: watch::Sender<()>, highlight_updates: async_watch::Sender<()>,
_update_highlights: Task<Result<()>>, _update_highlights: Task<Result<()>>,
_subscriptions: Vec<gpui::Subscription>, _subscriptions: Vec<gpui::Subscription>,
} }
@@ -1531,7 +1531,7 @@ struct InlineAssistScrollLock {
impl EditorInlineAssists { impl EditorInlineAssists {
fn new(editor: &Entity<Editor>, window: &mut Window, cx: &mut App) -> Self { fn new(editor: &Entity<Editor>, window: &mut Window, cx: &mut App) -> Self {
let (highlight_updates_tx, mut highlight_updates_rx) = watch::channel(()); let (highlight_updates_tx, mut highlight_updates_rx) = async_watch::channel(());
Self { Self {
assist_ids: Vec::new(), assist_ids: Vec::new(),
scroll_lock: None, scroll_lock: None,
@@ -1689,7 +1689,7 @@ impl InlineAssist {
if let Some(editor) = editor.upgrade() { if let Some(editor) = editor.upgrade() {
InlineAssistant::update_global(cx, |this, cx| { InlineAssistant::update_global(cx, |this, cx| {
if let Some(editor_assists) = if let Some(editor_assists) =
this.assists_by_editor.get_mut(&editor.downgrade()) this.assists_by_editor.get(&editor.downgrade())
{ {
editor_assists.highlight_updates.send(()).ok(); editor_assists.highlight_updates.send(()).ok();
} }

View File

@@ -1,4 +1,4 @@
use crate::agent_model_selector::AgentModelSelector; use crate::agent_model_selector::{AgentModelSelector, ModelType};
use crate::buffer_codegen::BufferCodegen; use crate::buffer_codegen::BufferCodegen;
use crate::context::ContextCreasesAddon; use crate::context::ContextCreasesAddon;
use crate::context_picker::{ContextPicker, ContextPickerCompletionProvider}; use crate::context_picker::{ContextPicker, ContextPickerCompletionProvider};
@@ -7,13 +7,12 @@ use crate::context_strip::{ContextStrip, ContextStripEvent, SuggestContextKind};
use crate::message_editor::{extract_message_creases, insert_message_creases}; use crate::message_editor::{extract_message_creases, insert_message_creases};
use crate::terminal_codegen::TerminalCodegen; use crate::terminal_codegen::TerminalCodegen;
use crate::thread_store::{TextThreadStore, ThreadStore}; use crate::thread_store::{TextThreadStore, ThreadStore};
use crate::{CycleNextInlineAssist, CyclePreviousInlineAssist, ModelUsageContext}; use crate::{CycleNextInlineAssist, CyclePreviousInlineAssist};
use crate::{RemoveAllContext, ToggleContextPicker}; use crate::{RemoveAllContext, ToggleContextPicker};
use assistant_context_editor::language_model_selector::ToggleModelSelector; use assistant_context_editor::language_model_selector::ToggleModelSelector;
use client::ErrorExt; use client::ErrorExt;
use collections::VecDeque; use collections::VecDeque;
use db::kvp::Dismissable; use db::kvp::Dismissable;
use editor::actions::Paste;
use editor::display_map::EditorMargins; use editor::display_map::EditorMargins;
use editor::{ use editor::{
ContextMenuOptions, Editor, EditorElement, EditorEvent, EditorMode, EditorStyle, MultiBuffer, ContextMenuOptions, Editor, EditorElement, EditorEvent, EditorMode, EditorStyle, MultiBuffer,
@@ -100,9 +99,8 @@ impl<T: 'static> Render for PromptEditor<T> {
v_flex() v_flex()
.key_context("PromptEditor") .key_context("PromptEditor")
.capture_action(cx.listener(Self::paste))
.bg(cx.theme().colors().editor_background) .bg(cx.theme().colors().editor_background)
.block_mouse_except_scroll() .block_mouse_down()
.gap_0p5() .gap_0p5()
.border_y_1() .border_y_1()
.border_color(cx.theme().status().info_border) .border_color(cx.theme().status().info_border)
@@ -305,10 +303,6 @@ impl<T: 'static> PromptEditor<T> {
self.editor.read(cx).text(cx) self.editor.read(cx).text(cx)
} }
fn paste(&mut self, _: &Paste, _window: &mut Window, cx: &mut Context<Self>) {
crate::active_thread::attach_pasted_images_as_context(&self.context_store, cx);
}
fn toggle_rate_limit_notice( fn toggle_rate_limit_notice(
&mut self, &mut self,
_: &ClickEvent, _: &ClickEvent,
@@ -918,7 +912,6 @@ impl PromptEditor<BufferCodegen> {
text_thread_store.clone(), text_thread_store.clone(),
context_picker_menu_handle.clone(), context_picker_menu_handle.clone(),
SuggestContextKind::Thread, SuggestContextKind::Thread,
ModelUsageContext::InlineAssistant,
window, window,
cx, cx,
) )
@@ -937,7 +930,7 @@ impl PromptEditor<BufferCodegen> {
fs, fs,
model_selector_menu_handle, model_selector_menu_handle,
prompt_editor.focus_handle(cx), prompt_editor.focus_handle(cx),
ModelUsageContext::InlineAssistant, ModelType::InlineAssistant,
window, window,
cx, cx,
) )
@@ -1090,7 +1083,6 @@ impl PromptEditor<TerminalCodegen> {
text_thread_store.clone(), text_thread_store.clone(),
context_picker_menu_handle.clone(), context_picker_menu_handle.clone(),
SuggestContextKind::Thread, SuggestContextKind::Thread,
ModelUsageContext::InlineAssistant,
window, window,
cx, cx,
) )
@@ -1109,7 +1101,7 @@ impl PromptEditor<TerminalCodegen> {
fs, fs,
model_selector_menu_handle.clone(), model_selector_menu_handle.clone(),
prompt_editor.focus_handle(cx), prompt_editor.focus_handle(cx),
ModelUsageContext::InlineAssistant, ModelType::InlineAssistant,
window, window,
cx, cx,
) )

View File

@@ -2,11 +2,11 @@ use std::collections::BTreeMap;
use std::rc::Rc; use std::rc::Rc;
use std::sync::Arc; use std::sync::Arc;
use crate::agent_model_selector::AgentModelSelector; use crate::agent_model_selector::{AgentModelSelector, ModelType};
use crate::context::{AgentContextKey, ContextCreasesAddon, ContextLoadResult, load_context}; use crate::context::{AgentContextKey, ContextCreasesAddon, ContextLoadResult, load_context};
use crate::tool_compatibility::{IncompatibleToolsState, IncompatibleToolsTooltip}; use crate::tool_compatibility::{IncompatibleToolsState, IncompatibleToolsTooltip};
use crate::ui::{ use crate::ui::{
MaxModeTooltip, AnimatedLabel, MaxModeTooltip,
preview::{AgentPreview, UsageCallout}, preview::{AgentPreview, UsageCallout},
}; };
use agent_settings::{AgentSettings, CompletionMode}; use agent_settings::{AgentSettings, CompletionMode};
@@ -24,10 +24,10 @@ use fs::Fs;
use futures::future::Shared; use futures::future::Shared;
use futures::{FutureExt as _, future}; use futures::{FutureExt as _, future};
use gpui::{ use gpui::{
Animation, AnimationExt, App, Entity, EventEmitter, Focusable, Subscription, Task, TextStyle, Animation, AnimationExt, App, ClipboardEntry, Entity, EventEmitter, Focusable, Subscription,
WeakEntity, linear_color_stop, linear_gradient, point, pulsating_between, Task, TextStyle, WeakEntity, linear_color_stop, linear_gradient, point, pulsating_between,
}; };
use language::{Buffer, Language, Point}; use language::{Buffer, Language};
use language_model::{ use language_model::{
ConfiguredModel, LanguageModelRequestMessage, MessageContent, RequestUsage, ConfiguredModel, LanguageModelRequestMessage, MessageContent, RequestUsage,
ZED_CLOUD_PROVIDER_ID, ZED_CLOUD_PROVIDER_ID,
@@ -42,7 +42,6 @@ use theme::ThemeSettings;
use ui::{Disclosure, KeyBinding, PopoverMenuHandle, Tooltip, prelude::*}; use ui::{Disclosure, KeyBinding, PopoverMenuHandle, Tooltip, prelude::*};
use util::{ResultExt as _, maybe}; use util::{ResultExt as _, maybe};
use workspace::{CollaboratorId, Workspace}; use workspace::{CollaboratorId, Workspace};
use zed_llm_client::CompletionIntent;
use crate::context_picker::{ContextPicker, ContextPickerCompletionProvider, crease_for_mention}; use crate::context_picker::{ContextPicker, ContextPickerCompletionProvider, crease_for_mention};
use crate::context_store::ContextStore; use crate::context_store::ContextStore;
@@ -51,9 +50,9 @@ use crate::profile_selector::ProfileSelector;
use crate::thread::{MessageCrease, Thread, TokenUsageRatio}; use crate::thread::{MessageCrease, Thread, TokenUsageRatio};
use crate::thread_store::{TextThreadStore, ThreadStore}; use crate::thread_store::{TextThreadStore, ThreadStore};
use crate::{ use crate::{
ActiveThread, AgentDiffPane, Chat, ChatWithFollow, ExpandMessageEditor, Follow, KeepAll, ActiveThread, AgentDiffPane, Chat, ChatWithFollow, ExpandMessageEditor, Follow, NewThread,
ModelUsageContext, NewThread, OpenAgentDiff, RejectAll, RemoveAllContext, ToggleBurnMode, OpenAgentDiff, RemoveAllContext, ToggleContextPicker, ToggleProfileSelector,
ToggleContextPicker, ToggleProfileSelector, register_agent_preview, register_agent_preview,
}; };
#[derive(RegisterComponent)] #[derive(RegisterComponent)]
@@ -112,7 +111,6 @@ pub(crate) fn create_editor(
editor.set_placeholder_text("Message the agent @ to include context", cx); editor.set_placeholder_text("Message the agent @ to include context", cx);
editor.set_show_indent_guides(false, cx); editor.set_show_indent_guides(false, cx);
editor.set_soft_wrap(); editor.set_soft_wrap();
editor.set_use_modal_editing(true);
editor.set_context_menu_options(ContextMenuOptions { editor.set_context_menu_options(ContextMenuOptions {
min_entries_visible: 12, min_entries_visible: 12,
max_entries_visible: 12, max_entries_visible: 12,
@@ -169,13 +167,13 @@ impl MessageEditor {
Some(text_thread_store.clone()), Some(text_thread_store.clone()),
context_picker_menu_handle.clone(), context_picker_menu_handle.clone(),
SuggestContextKind::File, SuggestContextKind::File,
ModelUsageContext::Thread(thread.clone()),
window, window,
cx, cx,
) )
}); });
let incompatible_tools = cx.new(|cx| IncompatibleToolsState::new(thread.clone(), cx)); let incompatible_tools =
cx.new(|cx| IncompatibleToolsState::new(thread.read(cx).tools().clone(), cx));
let subscriptions = vec![ let subscriptions = vec![
cx.subscribe_in(&context_strip, window, Self::handle_context_strip_event), cx.subscribe_in(&context_strip, window, Self::handle_context_strip_event),
@@ -197,14 +195,21 @@ impl MessageEditor {
fs.clone(), fs.clone(),
model_selector_menu_handle, model_selector_menu_handle,
editor.focus_handle(cx), editor.focus_handle(cx),
ModelUsageContext::Thread(thread.clone()), ModelType::Default(thread.clone()),
window, window,
cx, cx,
) )
}); });
let profile_selector = let profile_selector = cx.new(|cx| {
cx.new(|cx| ProfileSelector::new(fs, thread.clone(), editor.focus_handle(cx), cx)); ProfileSelector::new(
fs,
thread.clone(),
thread_store,
editor.focus_handle(cx),
cx,
)
});
Self { Self {
editor: editor.clone(), editor: editor.clone(),
@@ -370,12 +375,7 @@ impl MessageEditor {
thread thread
.update(cx, |thread, cx| { .update(cx, |thread, cx| {
thread.advance_prompt_id(); thread.advance_prompt_id();
thread.send_to_model( thread.send_to_model(model, Some(window_handle), cx);
model,
CompletionIntent::UserPrompt,
Some(window_handle),
cx,
);
}) })
.log_err(); .log_err();
}) })
@@ -424,24 +424,39 @@ impl MessageEditor {
} }
fn paste(&mut self, _: &Paste, _: &mut Window, cx: &mut Context<Self>) { fn paste(&mut self, _: &Paste, _: &mut Window, cx: &mut Context<Self>) {
crate::active_thread::attach_pasted_images_as_context(&self.context_store, cx); let images = cx
.read_from_clipboard()
.map(|item| {
item.into_entries()
.filter_map(|entry| {
if let ClipboardEntry::Image(image) = entry {
Some(image)
} else {
None
}
})
.collect::<Vec<_>>()
})
.unwrap_or_default();
if images.is_empty() {
return;
}
cx.stop_propagation();
self.context_store.update(cx, |store, cx| {
for image in images {
store.add_image_instance(Arc::new(image), cx);
}
});
} }
fn handle_review_click(&mut self, window: &mut Window, cx: &mut Context<Self>) { fn handle_review_click(&mut self, window: &mut Window, cx: &mut Context<Self>) {
if self.thread.read(cx).has_pending_edit_tool_uses() {
return;
}
self.edits_expanded = true; self.edits_expanded = true;
AgentDiffPane::deploy(self.thread.clone(), self.workspace.clone(), window, cx).log_err(); AgentDiffPane::deploy(self.thread.clone(), self.workspace.clone(), window, cx).log_err();
cx.notify(); cx.notify();
} }
fn handle_edit_bar_expand(&mut self, cx: &mut Context<Self>) {
self.edits_expanded = !self.edits_expanded;
cx.notify();
}
fn handle_file_click( fn handle_file_click(
&self, &self,
buffer: Entity<Buffer>, buffer: Entity<Buffer>,
@@ -456,56 +471,6 @@ impl MessageEditor {
} }
} }
pub fn toggle_burn_mode(
&mut self,
_: &ToggleBurnMode,
_window: &mut Window,
cx: &mut Context<Self>,
) {
self.thread.update(cx, |thread, _cx| {
let active_completion_mode = thread.completion_mode();
thread.set_completion_mode(match active_completion_mode {
CompletionMode::Burn => CompletionMode::Normal,
CompletionMode::Normal => CompletionMode::Burn,
});
});
}
fn handle_accept_all(&mut self, _window: &mut Window, cx: &mut Context<Self>) {
if self.thread.read(cx).has_pending_edit_tool_uses() {
return;
}
self.thread.update(cx, |thread, cx| {
thread.keep_all_edits(cx);
});
cx.notify();
}
fn handle_reject_all(&mut self, _window: &mut Window, cx: &mut Context<Self>) {
if self.thread.read(cx).has_pending_edit_tool_uses() {
return;
}
// Since there's no reject_all_edits method in the thread API,
// we need to iterate through all buffers and reject their edits
let action_log = self.thread.read(cx).action_log().clone();
let changed_buffers = action_log.read(cx).changed_buffers(cx);
for (buffer, _) in changed_buffers {
self.thread.update(cx, |thread, cx| {
let buffer_snapshot = buffer.read(cx);
let start = buffer_snapshot.anchor_before(Point::new(0, 0));
let end = buffer_snapshot.anchor_after(buffer_snapshot.max_point());
thread
.reject_edits_in_ranges(buffer, vec![start..end], cx)
.detach();
});
}
cx.notify();
}
fn render_max_mode_toggle(&self, cx: &mut Context<Self>) -> Option<AnyElement> { fn render_max_mode_toggle(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
let thread = self.thread.read(cx); let thread = self.thread.read(cx);
let model = thread.configured_model(); let model = thread.configured_model();
@@ -514,8 +479,8 @@ impl MessageEditor {
} }
let active_completion_mode = thread.completion_mode(); let active_completion_mode = thread.completion_mode();
let burn_mode_enabled = active_completion_mode == CompletionMode::Burn; let max_mode_enabled = active_completion_mode == CompletionMode::Max;
let icon = if burn_mode_enabled { let icon = if max_mode_enabled {
IconName::ZedBurnModeOn IconName::ZedBurnModeOn
} else { } else {
IconName::ZedBurnMode IconName::ZedBurnMode
@@ -525,13 +490,18 @@ impl MessageEditor {
IconButton::new("burn-mode", icon) IconButton::new("burn-mode", icon)
.icon_size(IconSize::Small) .icon_size(IconSize::Small)
.icon_color(Color::Muted) .icon_color(Color::Muted)
.toggle_state(burn_mode_enabled) .toggle_state(max_mode_enabled)
.selected_icon_color(Color::Error) .selected_icon_color(Color::Error)
.on_click(cx.listener(|this, _event, window, cx| { .on_click(cx.listener(move |this, _event, _window, cx| {
this.toggle_burn_mode(&ToggleBurnMode, window, cx); this.thread.update(cx, |thread, _cx| {
thread.set_completion_mode(match active_completion_mode {
CompletionMode::Max => CompletionMode::Normal,
CompletionMode::Normal => CompletionMode::Max,
});
});
})) }))
.tooltip(move |_window, cx| { .tooltip(move |_window, cx| {
cx.new(|_| MaxModeTooltip::new().selected(burn_mode_enabled)) cx.new(|_| MaxModeTooltip::new().selected(max_mode_enabled))
.into() .into()
}) })
.into_any_element(), .into_any_element(),
@@ -626,13 +596,6 @@ impl MessageEditor {
.on_action(cx.listener(Self::remove_all_context)) .on_action(cx.listener(Self::remove_all_context))
.on_action(cx.listener(Self::move_up)) .on_action(cx.listener(Self::move_up))
.on_action(cx.listener(Self::expand_message_editor)) .on_action(cx.listener(Self::expand_message_editor))
.on_action(cx.listener(Self::toggle_burn_mode))
.on_action(
cx.listener(|this, _: &KeepAll, window, cx| this.handle_accept_all(window, cx)),
)
.on_action(
cx.listener(|this, _: &RejectAll, window, cx| this.handle_reject_all(window, cx)),
)
.capture_action(cx.listener(Self::paste)) .capture_action(cx.listener(Self::paste))
.gap_2() .gap_2()
.p_2() .p_2()
@@ -888,10 +851,7 @@ impl MessageEditor {
let bg_edit_files_disclosure = editor_bg_color.blend(active_color.opacity(0.3)); let bg_edit_files_disclosure = editor_bg_color.blend(active_color.opacity(0.3));
let is_edit_changes_expanded = self.edits_expanded; let is_edit_changes_expanded = self.edits_expanded;
let thread = self.thread.read(cx); let is_generating = self.thread.read(cx).is_generating();
let pending_edits = thread.has_pending_edit_tool_uses();
const EDIT_NOT_READY_TOOLTIP_LABEL: &str = "Wait until file edits are complete.";
v_flex() v_flex()
.mt_1() .mt_1()
@@ -909,28 +869,31 @@ impl MessageEditor {
}]) }])
.child( .child(
h_flex() h_flex()
.p_1() .id("edits-container")
.cursor_pointer()
.p_1p5()
.justify_between() .justify_between()
.when(is_edit_changes_expanded, |this| { .when(is_edit_changes_expanded, |this| {
this.border_b_1().border_color(border_color) this.border_b_1().border_color(border_color)
}) })
.on_click(
cx.listener(|this, _, window, cx| this.handle_review_click(window, cx)),
)
.child( .child(
h_flex() h_flex()
.id("edits-container")
.cursor_pointer()
.w_full()
.gap_1() .gap_1()
.child( .child(
Disclosure::new("edits-disclosure", is_edit_changes_expanded) Disclosure::new("edits-disclosure", is_edit_changes_expanded)
.on_click(cx.listener(|this, _, _, cx| { .on_click(cx.listener(|this, _ev, _window, cx| {
this.handle_edit_bar_expand(cx) this.edits_expanded = !this.edits_expanded;
cx.notify();
})), })),
) )
.map(|this| { .map(|this| {
if pending_edits { if is_generating {
this.child( this.child(
Label::new(format!( AnimatedLabel::new(format!(
"Editing {} {}", "Editing {} {}",
changed_buffers.len(), changed_buffers.len(),
if changed_buffers.len() == 1 { if changed_buffers.len() == 1 {
"file" "file"
@@ -938,15 +901,7 @@ impl MessageEditor {
"files" "files"
} }
)) ))
.color(Color::Muted) .size(LabelSize::Small),
.size(LabelSize::Small)
.with_animation(
"edit-label",
Animation::new(Duration::from_secs(2))
.repeat()
.with_easing(pulsating_between(0.3, 0.7)),
|label, delta| label.alpha(delta),
),
) )
} else { } else {
this.child( this.child(
@@ -971,74 +926,23 @@ impl MessageEditor {
.color(Color::Muted), .color(Color::Muted),
) )
} }
}) }),
.on_click(
cx.listener(|this, _, _, cx| this.handle_edit_bar_expand(cx)),
),
) )
.child( .child(
h_flex() Button::new("review", "Review Changes")
.gap_1() .label_size(LabelSize::Small)
.child( .key_binding(
IconButton::new("review-changes", IconName::ListTodo) KeyBinding::for_action_in(
.icon_size(IconSize::Small) &OpenAgentDiff,
.tooltip({ &focus_handle,
let focus_handle = focus_handle.clone(); window,
move |window, cx| { cx,
Tooltip::for_action_in( )
"Review Changes", .map(|kb| kb.size(rems_from_px(12.))),
&OpenAgentDiff,
&focus_handle,
window,
cx,
)
}
})
.on_click(cx.listener(|this, _, window, cx| {
this.handle_review_click(window, cx)
})),
) )
.child(ui::Divider::vertical().color(ui::DividerColor::Border)) .on_click(cx.listener(|this, _, window, cx| {
.child( this.handle_review_click(window, cx)
Button::new("reject-all-changes", "Reject All") })),
.label_size(LabelSize::Small)
.disabled(pending_edits)
.when(pending_edits, |this| {
this.tooltip(Tooltip::text(EDIT_NOT_READY_TOOLTIP_LABEL))
})
.key_binding(
KeyBinding::for_action_in(
&RejectAll,
&focus_handle.clone(),
window,
cx,
)
.map(|kb| kb.size(rems_from_px(10.))),
)
.on_click(cx.listener(|this, _, window, cx| {
this.handle_reject_all(window, cx)
})),
)
.child(
Button::new("accept-all-changes", "Accept All")
.label_size(LabelSize::Small)
.disabled(pending_edits)
.when(pending_edits, |this| {
this.tooltip(Tooltip::text(EDIT_NOT_READY_TOOLTIP_LABEL))
})
.key_binding(
KeyBinding::for_action_in(
&KeepAll,
&focus_handle,
window,
cx,
)
.map(|kb| kb.size(rems_from_px(10.))),
)
.on_click(cx.listener(|this, _, window, cx| {
this.handle_accept_all(window, cx)
})),
),
), ),
) )
.when(is_edit_changes_expanded, |parent| { .when(is_edit_changes_expanded, |parent| {
@@ -1364,7 +1268,6 @@ impl MessageEditor {
let request = language_model::LanguageModelRequest { let request = language_model::LanguageModelRequest {
thread_id: None, thread_id: None,
prompt_id: None, prompt_id: None,
intent: None,
mode: None, mode: None,
messages: vec![request_message], messages: vec![request_message],
tools: vec![], tools: vec![],

View File

@@ -1,24 +1,26 @@
use std::sync::Arc; use std::sync::Arc;
use agent_settings::{AgentDockPosition, AgentProfileId, AgentSettings, builtin_profiles}; use agent_settings::{
AgentDockPosition, AgentProfile, AgentProfileId, AgentSettings, GroupedAgentProfiles,
builtin_profiles,
};
use fs::Fs; use fs::Fs;
use gpui::{Action, Empty, Entity, FocusHandle, Subscription, prelude::*}; use gpui::{Action, Empty, Entity, FocusHandle, Subscription, WeakEntity, prelude::*};
use language_model::LanguageModelRegistry; use language_model::LanguageModelRegistry;
use settings::{Settings as _, SettingsStore, update_settings_file}; use settings::{Settings as _, SettingsStore, update_settings_file};
use ui::{ use ui::{
ContextMenu, ContextMenuEntry, DocumentationSide, PopoverMenu, PopoverMenuHandle, Tooltip, ContextMenu, ContextMenuEntry, DocumentationSide, PopoverMenu, PopoverMenuHandle, Tooltip,
prelude::*, prelude::*,
}; };
use util::ResultExt as _;
use crate::{ use crate::{ManageProfiles, Thread, ThreadStore, ToggleProfileSelector};
ManageProfiles, Thread, ToggleProfileSelector,
agent_profile::{AgentProfile, AvailableProfiles},
};
pub struct ProfileSelector { pub struct ProfileSelector {
profiles: AvailableProfiles, profiles: GroupedAgentProfiles,
fs: Arc<dyn Fs>, fs: Arc<dyn Fs>,
thread: Entity<Thread>, thread: Entity<Thread>,
thread_store: WeakEntity<ThreadStore>,
menu_handle: PopoverMenuHandle<ContextMenu>, menu_handle: PopoverMenuHandle<ContextMenu>,
focus_handle: FocusHandle, focus_handle: FocusHandle,
_subscriptions: Vec<Subscription>, _subscriptions: Vec<Subscription>,
@@ -28,6 +30,7 @@ impl ProfileSelector {
pub fn new( pub fn new(
fs: Arc<dyn Fs>, fs: Arc<dyn Fs>,
thread: Entity<Thread>, thread: Entity<Thread>,
thread_store: WeakEntity<ThreadStore>,
focus_handle: FocusHandle, focus_handle: FocusHandle,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> Self { ) -> Self {
@@ -36,9 +39,10 @@ impl ProfileSelector {
}); });
Self { Self {
profiles: AgentProfile::available_profiles(cx), profiles: GroupedAgentProfiles::from_settings(AgentSettings::get_global(cx)),
fs, fs,
thread, thread,
thread_store,
menu_handle: PopoverMenuHandle::default(), menu_handle: PopoverMenuHandle::default(),
focus_handle, focus_handle,
_subscriptions: vec![settings_subscription], _subscriptions: vec![settings_subscription],
@@ -50,7 +54,7 @@ impl ProfileSelector {
} }
fn refresh_profiles(&mut self, cx: &mut Context<Self>) { fn refresh_profiles(&mut self, cx: &mut Context<Self>) {
self.profiles = AgentProfile::available_profiles(cx); self.profiles = GroupedAgentProfiles::from_settings(AgentSettings::get_global(cx));
} }
fn build_context_menu( fn build_context_menu(
@@ -60,30 +64,21 @@ impl ProfileSelector {
) -> Entity<ContextMenu> { ) -> Entity<ContextMenu> {
ContextMenu::build(window, cx, |mut menu, _window, cx| { ContextMenu::build(window, cx, |mut menu, _window, cx| {
let settings = AgentSettings::get_global(cx); let settings = AgentSettings::get_global(cx);
for (profile_id, profile) in self.profiles.builtin.iter() {
let mut found_non_builtin = false;
for (profile_id, profile_name) in self.profiles.iter() {
if !builtin_profiles::is_builtin(profile_id) {
found_non_builtin = true;
continue;
}
menu = menu.item(self.menu_entry_for_profile( menu = menu.item(self.menu_entry_for_profile(
profile_id.clone(), profile_id.clone(),
profile_name, profile,
settings, settings,
cx, cx,
)); ));
} }
if found_non_builtin { if !self.profiles.custom.is_empty() {
menu = menu.separator().header("Custom Profiles"); menu = menu.separator().header("Custom Profiles");
for (profile_id, profile_name) in self.profiles.iter() { for (profile_id, profile) in self.profiles.custom.iter() {
if builtin_profiles::is_builtin(profile_id) {
continue;
}
menu = menu.item(self.menu_entry_for_profile( menu = menu.item(self.menu_entry_for_profile(
profile_id.clone(), profile_id.clone(),
profile_name, profile,
settings, settings,
cx, cx,
)); ));
@@ -104,20 +99,19 @@ impl ProfileSelector {
fn menu_entry_for_profile( fn menu_entry_for_profile(
&self, &self,
profile_id: AgentProfileId, profile_id: AgentProfileId,
profile_name: &SharedString, profile: &AgentProfile,
settings: &AgentSettings, settings: &AgentSettings,
cx: &App, _cx: &App,
) -> ContextMenuEntry { ) -> ContextMenuEntry {
let documentation = match profile_name.to_lowercase().as_str() { let documentation = match profile.name.to_lowercase().as_str() {
builtin_profiles::WRITE => Some("Get help to write anything."), builtin_profiles::WRITE => Some("Get help to write anything."),
builtin_profiles::ASK => Some("Chat about your codebase."), builtin_profiles::ASK => Some("Chat about your codebase."),
builtin_profiles::MINIMAL => Some("Chat about anything with no tools."), builtin_profiles::MINIMAL => Some("Chat about anything with no tools."),
_ => None, _ => None,
}; };
let thread_profile_id = self.thread.read(cx).profile().id();
let entry = ContextMenuEntry::new(profile_name.clone()) let entry = ContextMenuEntry::new(profile.name.clone())
.toggleable(IconPosition::End, &profile_id == thread_profile_id); .toggleable(IconPosition::End, profile_id == settings.default_profile);
let entry = if let Some(doc_text) = documentation { let entry = if let Some(doc_text) = documentation {
entry.documentation_aside(documentation_side(settings.dock), move |_| { entry.documentation_aside(documentation_side(settings.dock), move |_| {
@@ -129,7 +123,7 @@ impl ProfileSelector {
entry.handler({ entry.handler({
let fs = self.fs.clone(); let fs = self.fs.clone();
let thread = self.thread.clone(); let thread_store = self.thread_store.clone();
let profile_id = profile_id.clone(); let profile_id = profile_id.clone();
move |_window, cx| { move |_window, cx| {
update_settings_file::<AgentSettings>(fs.clone(), cx, { update_settings_file::<AgentSettings>(fs.clone(), cx, {
@@ -139,9 +133,11 @@ impl ProfileSelector {
} }
}); });
thread.update(cx, |this, cx| { thread_store
this.set_profile(profile_id.clone(), cx); .update(cx, |this, cx| {
}); this.load_profile_by_id(profile_id.clone(), cx);
})
.log_err();
} }
}) })
} }
@@ -150,7 +146,7 @@ impl ProfileSelector {
impl Render for ProfileSelector { impl Render for ProfileSelector {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let settings = AgentSettings::get_global(cx); let settings = AgentSettings::get_global(cx);
let profile_id = self.thread.read(cx).profile().id(); let profile_id = &settings.default_profile;
let profile = settings.profiles.get(profile_id); let profile = settings.profiles.get(profile_id);
let selected_profile = profile let selected_profile = profile

View File

@@ -1 +0,0 @@
These files changed since last read:

View File

@@ -1,6 +0,0 @@
Generate a detailed summary of this conversation. Include:
1. A brief overview of what was discussed
2. Key facts or information discovered
3. Outcomes or conclusions reached
4. Any action items or next steps if any
Format it in Markdown with headings and bullet points.

View File

@@ -1,4 +0,0 @@
Generate a concise 3-7 word title for this conversation, omitting punctuation.
Go straight to the title, without any preamble and prefix like `Here's a concise suggestion:...` or `Title:`.
If the conversation is about a specific subject, include it in the title.
Be descriptive. DO NOT speak in the first person.

View File

@@ -179,17 +179,18 @@ impl TerminalTransaction {
// Ensure that the assistant cannot accidentally execute commands that are streamed into the terminal // Ensure that the assistant cannot accidentally execute commands that are streamed into the terminal
let input = Self::sanitize_input(hunk); let input = Self::sanitize_input(hunk);
self.terminal self.terminal
.update(cx, |terminal, _| terminal.input(input.into_bytes())); .update(cx, |terminal, _| terminal.input(input));
} }
pub fn undo(&self, cx: &mut App) { pub fn undo(&self, cx: &mut App) {
self.terminal self.terminal
.update(cx, |terminal, _| terminal.input(CLEAR_INPUT.as_bytes())); .update(cx, |terminal, _| terminal.input(CLEAR_INPUT.to_string()));
} }
pub fn complete(&self, cx: &mut App) { pub fn complete(&self, cx: &mut App) {
self.terminal self.terminal.update(cx, |terminal, _| {
.update(cx, |terminal, _| terminal.input(CARRIAGE_RETURN.as_bytes())); terminal.input(CARRIAGE_RETURN.to_string())
});
} }
fn sanitize_input(mut input: String) -> String { fn sanitize_input(mut input: String) -> String {

View File

@@ -25,7 +25,6 @@ use terminal_view::TerminalView;
use ui::prelude::*; use ui::prelude::*;
use util::ResultExt; use util::ResultExt;
use workspace::{Toast, Workspace, notifications::NotificationId}; use workspace::{Toast, Workspace, notifications::NotificationId};
use zed_llm_client::CompletionIntent;
pub fn init( pub fn init(
fs: Arc<dyn Fs>, fs: Arc<dyn Fs>,
@@ -106,7 +105,7 @@ impl TerminalInlineAssistant {
}); });
let prompt_editor_render = prompt_editor.clone(); let prompt_editor_render = prompt_editor.clone();
let block = terminal_view::BlockProperties { let block = terminal_view::BlockProperties {
height: 4, height: 2,
render: Box::new(move |_| prompt_editor_render.clone().into_any_element()), render: Box::new(move |_| prompt_editor_render.clone().into_any_element()),
}; };
terminal_view.update(cx, |terminal_view, cx| { terminal_view.update(cx, |terminal_view, cx| {
@@ -202,7 +201,7 @@ impl TerminalInlineAssistant {
.update(cx, |terminal, cx| { .update(cx, |terminal, cx| {
terminal terminal
.terminal() .terminal()
.update(cx, |terminal, _| terminal.input(CLEAR_INPUT.as_bytes())); .update(cx, |terminal, _| terminal.input(CLEAR_INPUT.to_string()));
}) })
.log_err(); .log_err();
@@ -292,7 +291,6 @@ impl TerminalInlineAssistant {
thread_id: None, thread_id: None,
prompt_id: None, prompt_id: None,
mode: None, mode: None,
intent: Some(CompletionIntent::TerminalInlineAssist),
messages: vec![request_message], messages: vec![request_message],
tools: Vec::new(), tools: Vec::new(),
tool_choice: None, tool_choice: None,

View File

@@ -4,7 +4,7 @@ use std::ops::Range;
use std::sync::Arc; use std::sync::Arc;
use std::time::Instant; use std::time::Instant;
use agent_settings::{AgentProfileId, AgentSettings, CompletionMode}; use agent_settings::{AgentSettings, CompletionMode};
use anyhow::{Result, anyhow}; use anyhow::{Result, anyhow};
use assistant_tool::{ActionLog, AnyToolCard, Tool, ToolWorkingSet}; use assistant_tool::{ActionLog, AnyToolCard, Tool, ToolWorkingSet};
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
@@ -24,7 +24,7 @@ use language_model::{
LanguageModelRequestMessage, LanguageModelRequestTool, LanguageModelToolResult, LanguageModelRequestMessage, LanguageModelRequestTool, LanguageModelToolResult,
LanguageModelToolResultContent, LanguageModelToolUseId, MessageContent, LanguageModelToolResultContent, LanguageModelToolUseId, MessageContent,
ModelRequestLimitReachedError, PaymentRequiredError, RequestUsage, Role, SelectedModel, ModelRequestLimitReachedError, PaymentRequiredError, RequestUsage, Role, SelectedModel,
StopReason, TokenUsage, StopReason, TokenUsage, WrappedTextContent,
}; };
use postage::stream::Stream as _; use postage::stream::Stream as _;
use project::Project; use project::Project;
@@ -38,10 +38,9 @@ use thiserror::Error;
use ui::Window; use ui::Window;
use util::{ResultExt as _, post_inc}; use util::{ResultExt as _, post_inc};
use uuid::Uuid; use uuid::Uuid;
use zed_llm_client::{CompletionIntent, CompletionRequestStatus}; use zed_llm_client::CompletionRequestStatus;
use crate::ThreadStore; use crate::ThreadStore;
use crate::agent_profile::AgentProfile;
use crate::context::{AgentContext, AgentContextHandle, ContextLoadResult, LoadedContext}; use crate::context::{AgentContext, AgentContextHandle, ContextLoadResult, LoadedContext};
use crate::thread_store::{ use crate::thread_store::{
SerializedCrease, SerializedLanguageModel, SerializedMessage, SerializedMessageSegment, SerializedCrease, SerializedLanguageModel, SerializedMessage, SerializedMessageSegment,
@@ -195,20 +194,20 @@ impl MessageSegment {
} }
} }
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProjectSnapshot { pub struct ProjectSnapshot {
pub worktree_snapshots: Vec<WorktreeSnapshot>, pub worktree_snapshots: Vec<WorktreeSnapshot>,
pub unsaved_buffer_paths: Vec<String>, pub unsaved_buffer_paths: Vec<String>,
pub timestamp: DateTime<Utc>, pub timestamp: DateTime<Utc>,
} }
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WorktreeSnapshot { pub struct WorktreeSnapshot {
pub worktree_path: String, pub worktree_path: String,
pub git_state: Option<GitState>, pub git_state: Option<GitState>,
} }
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GitState { pub struct GitState {
pub remote_url: Option<String>, pub remote_url: Option<String>,
pub head_sha: Option<String>, pub head_sha: Option<String>,
@@ -247,7 +246,7 @@ impl LastRestoreCheckpoint {
} }
} }
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)] #[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub enum DetailedSummaryState { pub enum DetailedSummaryState {
#[default] #[default]
NotGenerated, NotGenerated,
@@ -361,7 +360,6 @@ pub struct Thread {
>, >,
remaining_turns: u32, remaining_turns: u32,
configured_model: Option<ConfiguredModel>, configured_model: Option<ConfiguredModel>,
profile: AgentProfile,
} }
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
@@ -391,7 +389,7 @@ impl ThreadSummary {
} }
} }
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExceededWindowError { pub struct ExceededWindowError {
/// Model used when last message exceeded context window /// Model used when last message exceeded context window
model_id: LanguageModelId, model_id: LanguageModelId,
@@ -409,7 +407,6 @@ impl Thread {
) -> Self { ) -> Self {
let (detailed_summary_tx, detailed_summary_rx) = postage::watch::channel(); let (detailed_summary_tx, detailed_summary_rx) = postage::watch::channel();
let configured_model = LanguageModelRegistry::read_global(cx).default_model(); let configured_model = LanguageModelRegistry::read_global(cx).default_model();
let profile_id = AgentSettings::get_global(cx).default_profile.clone();
Self { Self {
id: ThreadId::new(), id: ThreadId::new(),
@@ -452,7 +449,6 @@ impl Thread {
request_callback: None, request_callback: None,
remaining_turns: u32::MAX, remaining_turns: u32::MAX,
configured_model, configured_model,
profile: AgentProfile::new(profile_id, tools),
} }
} }
@@ -499,9 +495,6 @@ impl Thread {
let completion_mode = serialized let completion_mode = serialized
.completion_mode .completion_mode
.unwrap_or_else(|| AgentSettings::get_global(cx).preferred_completion_mode); .unwrap_or_else(|| AgentSettings::get_global(cx).preferred_completion_mode);
let profile_id = serialized
.profile
.unwrap_or_else(|| AgentSettings::get_global(cx).default_profile.clone());
Self { Self {
id, id,
@@ -561,7 +554,7 @@ impl Thread {
pending_checkpoint: None, pending_checkpoint: None,
project: project.clone(), project: project.clone(),
prompt_builder, prompt_builder,
tools: tools.clone(), tools,
tool_use, tool_use,
action_log: cx.new(|_| ActionLog::new(project)), action_log: cx.new(|_| ActionLog::new(project)),
initial_project_snapshot: Task::ready(serialized.initial_project_snapshot).shared(), initial_project_snapshot: Task::ready(serialized.initial_project_snapshot).shared(),
@@ -577,7 +570,6 @@ impl Thread {
request_callback: None, request_callback: None,
remaining_turns: u32::MAX, remaining_turns: u32::MAX,
configured_model, configured_model,
profile: AgentProfile::new(profile_id, tools),
} }
} }
@@ -593,17 +585,6 @@ impl Thread {
&self.id &self.id
} }
pub fn profile(&self) -> &AgentProfile {
&self.profile
}
pub fn set_profile(&mut self, id: AgentProfileId, cx: &mut Context<Self>) {
if &id != self.profile.id() {
self.profile = AgentProfile::new(id, self.tools.clone());
cx.emit(ThreadEvent::ProfileChanged);
}
}
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
self.messages.is_empty() self.messages.is_empty()
} }
@@ -890,16 +871,7 @@ impl Thread {
self.tool_use self.tool_use
.pending_tool_uses() .pending_tool_uses()
.iter() .iter()
.all(|pending_tool_use| pending_tool_use.status.is_error()) .all(|tool_use| tool_use.status.is_error())
}
/// Returns whether any pending tool uses may perform edits
pub fn has_pending_edit_tool_uses(&self) -> bool {
self.tool_use
.pending_tool_uses()
.iter()
.filter(|pending_tool_use| !pending_tool_use.status.is_error())
.any(|pending_tool_use| pending_tool_use.may_perform_edits)
} }
pub fn tool_uses_for_message(&self, id: MessageId, cx: &App) -> Vec<ToolUse> { pub fn tool_uses_for_message(&self, id: MessageId, cx: &App) -> Vec<ToolUse> {
@@ -919,7 +891,10 @@ impl Thread {
pub fn output_for_tool(&self, id: &LanguageModelToolUseId) -> Option<&Arc<str>> { pub fn output_for_tool(&self, id: &LanguageModelToolUseId) -> Option<&Arc<str>> {
match &self.tool_use.tool_result(id)?.content { match &self.tool_use.tool_result(id)?.content {
LanguageModelToolResultContent::Text(text) => Some(text), LanguageModelToolResultContent::Text(text)
| LanguageModelToolResultContent::WrappedText(WrappedTextContent { text, .. }) => {
Some(text)
}
LanguageModelToolResultContent::Image(_) => { LanguageModelToolResultContent::Image(_) => {
// TODO: We should display image // TODO: We should display image
None None
@@ -938,7 +913,8 @@ impl Thread {
model: Arc<dyn LanguageModel>, model: Arc<dyn LanguageModel>,
) -> Vec<LanguageModelRequestTool> { ) -> Vec<LanguageModelRequestTool> {
if model.supports_tools() { if model.supports_tools() {
self.profile self.tools()
.read(cx)
.enabled_tools(cx) .enabled_tools(cx)
.into_iter() .into_iter()
.filter_map(|tool| { .filter_map(|tool| {
@@ -1050,7 +1026,6 @@ impl Thread {
id: MessageId, id: MessageId,
new_role: Role, new_role: Role,
new_segments: Vec<MessageSegment>, new_segments: Vec<MessageSegment>,
creases: Vec<MessageCrease>,
loaded_context: Option<LoadedContext>, loaded_context: Option<LoadedContext>,
checkpoint: Option<GitStoreCheckpoint>, checkpoint: Option<GitStoreCheckpoint>,
cx: &mut Context<Self>, cx: &mut Context<Self>,
@@ -1060,7 +1035,6 @@ impl Thread {
}; };
message.role = new_role; message.role = new_role;
message.segments = new_segments; message.segments = new_segments;
message.creases = creases;
if let Some(context) = loaded_context { if let Some(context) = loaded_context {
message.loaded_context = context; message.loaded_context = context;
} }
@@ -1198,7 +1172,6 @@ impl Thread {
}), }),
completion_mode: Some(this.completion_mode), completion_mode: Some(this.completion_mode),
tool_use_limit_reached: this.tool_use_limit_reached, tool_use_limit_reached: this.tool_use_limit_reached,
profile: Some(this.profile.id().clone()),
}) })
}) })
} }
@@ -1214,7 +1187,6 @@ impl Thread {
pub fn send_to_model( pub fn send_to_model(
&mut self, &mut self,
model: Arc<dyn LanguageModel>, model: Arc<dyn LanguageModel>,
intent: CompletionIntent,
window: Option<AnyWindowHandle>, window: Option<AnyWindowHandle>,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) { ) {
@@ -1224,7 +1196,7 @@ impl Thread {
self.remaining_turns -= 1; self.remaining_turns -= 1;
let request = self.to_completion_request(model.clone(), intent, cx); let request = self.to_completion_request(model.clone(), cx);
self.stream_completion(request, model, window, cx); self.stream_completion(request, model, window, cx);
} }
@@ -1244,13 +1216,11 @@ impl Thread {
pub fn to_completion_request( pub fn to_completion_request(
&self, &self,
model: Arc<dyn LanguageModel>, model: Arc<dyn LanguageModel>,
intent: CompletionIntent,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> LanguageModelRequest { ) -> LanguageModelRequest {
let mut request = LanguageModelRequest { let mut request = LanguageModelRequest {
thread_id: Some(self.id.to_string()), thread_id: Some(self.id.to_string()),
prompt_id: Some(self.last_prompt_id.to_string()), prompt_id: Some(self.last_prompt_id.to_string()),
intent: Some(intent),
mode: None, mode: None,
messages: vec![], messages: vec![],
tools: Vec::new(), tools: Vec::new(),
@@ -1404,14 +1374,12 @@ impl Thread {
fn to_summarize_request( fn to_summarize_request(
&self, &self,
model: &Arc<dyn LanguageModel>, model: &Arc<dyn LanguageModel>,
intent: CompletionIntent,
added_user_message: String, added_user_message: String,
cx: &App, cx: &App,
) -> LanguageModelRequest { ) -> LanguageModelRequest {
let mut request = LanguageModelRequest { let mut request = LanguageModelRequest {
thread_id: None, thread_id: None,
prompt_id: None, prompt_id: None,
intent: Some(intent),
mode: None, mode: None,
messages: vec![], messages: vec![],
tools: Vec::new(), tools: Vec::new(),
@@ -1458,7 +1426,7 @@ impl Thread {
messages: &mut Vec<LanguageModelRequestMessage>, messages: &mut Vec<LanguageModelRequestMessage>,
cx: &App, cx: &App,
) { ) {
const STALE_FILES_HEADER: &str = include_str!("./prompts/stale_files_prompt_header.txt"); const STALE_FILES_HEADER: &str = "These files changed since last read:";
let mut stale_message = String::new(); let mut stale_message = String::new();
@@ -1470,7 +1438,7 @@ impl Thread {
}; };
if stale_message.is_empty() { if stale_message.is_empty() {
write!(&mut stale_message, "{}\n", STALE_FILES_HEADER.trim()).ok(); write!(&mut stale_message, "{}\n", STALE_FILES_HEADER).ok();
} }
writeln!(&mut stale_message, "- {}", file.path().display()).ok(); writeln!(&mut stale_message, "- {}", file.path().display()).ok();
@@ -1563,9 +1531,6 @@ impl Thread {
Err(LanguageModelCompletionError::Other(error)) => { Err(LanguageModelCompletionError::Other(error)) => {
return Err(error); return Err(error);
} }
Err(err @ LanguageModelCompletionError::RateLimit(..)) => {
return Err(err.into());
}
}; };
match event { match event {
@@ -1706,7 +1671,6 @@ impl Thread {
} }
CompletionRequestStatus::ToolUseLimitReached => { CompletionRequestStatus::ToolUseLimitReached => {
thread.tool_use_limit_reached = true; thread.tool_use_limit_reached = true;
cx.emit(ThreadEvent::ToolUseLimitReached);
} }
} }
} }
@@ -1888,14 +1852,12 @@ impl Thread {
return; return;
} }
let added_user_message = include_str!("./prompts/summarize_thread_prompt.txt"); let added_user_message = "Generate a concise 3-7 word title for this conversation, omitting punctuation. \
Go straight to the title, without any preamble and prefix like `Here's a concise suggestion:...` or `Title:`. \
If the conversation is about a specific subject, include it in the title. \
Be descriptive. DO NOT speak in the first person.";
let request = self.to_summarize_request( let request = self.to_summarize_request(&model.model, added_user_message.into(), cx);
&model.model,
CompletionIntent::ThreadSummarization,
added_user_message.into(),
cx,
);
self.summary = ThreadSummary::Generating; self.summary = ThreadSummary::Generating;
@@ -1989,14 +1951,14 @@ impl Thread {
return; return;
} }
let added_user_message = include_str!("./prompts/summarize_thread_detailed_prompt.txt"); let added_user_message = "Generate a detailed summary of this conversation. Include:\n\
1. A brief overview of what was discussed\n\
2. Key facts or information discovered\n\
3. Outcomes or conclusions reached\n\
4. Any action items or next steps if any\n\
Format it in Markdown with headings and bullet points.";
let request = self.to_summarize_request( let request = self.to_summarize_request(&model, added_user_message.into(), cx);
&model,
CompletionIntent::ThreadContextSummarization,
added_user_message.into(),
cx,
);
*self.detailed_summary_tx.borrow_mut() = DetailedSummaryState::Generating { *self.detailed_summary_tx.borrow_mut() = DetailedSummaryState::Generating {
message_id: last_message_id, message_id: last_message_id,
@@ -2088,8 +2050,7 @@ impl Thread {
model: Arc<dyn LanguageModel>, model: Arc<dyn LanguageModel>,
) -> Vec<PendingToolUse> { ) -> Vec<PendingToolUse> {
self.auto_capture_telemetry(cx); self.auto_capture_telemetry(cx);
let request = let request = Arc::new(self.to_completion_request(model.clone(), cx));
Arc::new(self.to_completion_request(model.clone(), CompletionIntent::ToolResults, cx));
let pending_tool_uses = self let pending_tool_uses = self
.tool_use .tool_use
.pending_tool_uses() .pending_tool_uses()
@@ -2143,7 +2104,7 @@ impl Thread {
window: Option<AnyWindowHandle>, window: Option<AnyWindowHandle>,
cx: &mut Context<Thread>, cx: &mut Context<Thread>,
) { ) {
let available_tools = self.profile.enabled_tools(cx); let available_tools = self.tools.read(cx).enabled_tools(cx);
let tool_list = available_tools let tool_list = available_tools
.iter() .iter()
@@ -2235,15 +2196,19 @@ impl Thread {
) -> Task<()> { ) -> Task<()> {
let tool_name: Arc<str> = tool.name().into(); let tool_name: Arc<str> = tool.name().into();
let tool_result = tool.run( let tool_result = if self.tools.read(cx).is_disabled(&tool.source(), &tool_name) {
input, Task::ready(Err(anyhow!("tool is disabled: {tool_name}"))).into()
request, } else {
self.project.clone(), tool.run(
self.action_log.clone(), input,
model, request,
window, self.project.clone(),
cx, self.action_log.clone(),
); model,
window,
cx,
)
};
// Store the card separately if it exists // Store the card separately if it exists
if let Some(card) = tool_result.card.clone() { if let Some(card) = tool_result.card.clone() {
@@ -2281,7 +2246,7 @@ impl Thread {
if self.all_tools_finished() { if self.all_tools_finished() {
if let Some(ConfiguredModel { model, .. }) = self.configured_model.as_ref() { if let Some(ConfiguredModel { model, .. }) = self.configured_model.as_ref() {
if !canceled { if !canceled {
self.send_to_model(model.clone(), CompletionIntent::ToolResults, window, cx); self.send_to_model(model.clone(), window, cx);
} }
self.auto_capture_telemetry(cx); self.auto_capture_telemetry(cx);
} }
@@ -2362,7 +2327,8 @@ impl Thread {
let client = self.project.read(cx).client(); let client = self.project.read(cx).client();
let enabled_tool_names: Vec<String> = self let enabled_tool_names: Vec<String> = self
.profile .tools()
.read(cx)
.enabled_tools(cx) .enabled_tools(cx)
.iter() .iter()
.map(|tool| tool.name()) .map(|tool| tool.name())
@@ -2627,7 +2593,11 @@ impl Thread {
writeln!(markdown, "**\n")?; writeln!(markdown, "**\n")?;
match &tool_result.content { match &tool_result.content {
LanguageModelToolResultContent::Text(text) => { LanguageModelToolResultContent::Text(text)
| LanguageModelToolResultContent::WrappedText(WrappedTextContent {
text,
..
}) => {
writeln!(markdown, "{text}")?; writeln!(markdown, "{text}")?;
} }
LanguageModelToolResultContent::Image(image) => { LanguageModelToolResultContent::Image(image) => {
@@ -2872,10 +2842,8 @@ pub enum ThreadEvent {
}, },
CheckpointChanged, CheckpointChanged,
ToolConfirmationNeeded, ToolConfirmationNeeded,
ToolUseLimitReached,
CancelEditing, CancelEditing,
CompletionCanceled, CompletionCanceled,
ProfileChanged,
} }
impl EventEmitter<ThreadEvent> for Thread {} impl EventEmitter<ThreadEvent> for Thread {}
@@ -2890,7 +2858,7 @@ struct PendingCompletion {
mod tests { mod tests {
use super::*; use super::*;
use crate::{ThreadStore, context::load_context, context_store::ContextStore, thread_store}; use crate::{ThreadStore, context::load_context, context_store::ContextStore, thread_store};
use agent_settings::{AgentProfileId, AgentSettings, LanguageModelParameters}; use agent_settings::{AgentSettings, LanguageModelParameters};
use assistant_tool::ToolRegistry; use assistant_tool::ToolRegistry;
use editor::EditorSettings; use editor::EditorSettings;
use gpui::TestAppContext; use gpui::TestAppContext;
@@ -2973,7 +2941,7 @@ fn main() {{
// Check message in request // Check message in request
let request = thread.update(cx, |thread, cx| { let request = thread.update(cx, |thread, cx| {
thread.to_completion_request(model.clone(), CompletionIntent::UserPrompt, cx) thread.to_completion_request(model.clone(), cx)
}); });
assert_eq!(request.messages.len(), 2); assert_eq!(request.messages.len(), 2);
@@ -3068,7 +3036,7 @@ fn main() {{
// Check entire request to make sure all contexts are properly included // Check entire request to make sure all contexts are properly included
let request = thread.update(cx, |thread, cx| { let request = thread.update(cx, |thread, cx| {
thread.to_completion_request(model.clone(), CompletionIntent::UserPrompt, cx) thread.to_completion_request(model.clone(), cx)
}); });
// The request should contain all 3 messages // The request should contain all 3 messages
@@ -3175,7 +3143,7 @@ fn main() {{
// Check message in request // Check message in request
let request = thread.update(cx, |thread, cx| { let request = thread.update(cx, |thread, cx| {
thread.to_completion_request(model.clone(), CompletionIntent::UserPrompt, cx) thread.to_completion_request(model.clone(), cx)
}); });
assert_eq!(request.messages.len(), 2); assert_eq!(request.messages.len(), 2);
@@ -3201,7 +3169,7 @@ fn main() {{
// Check that both messages appear in the request // Check that both messages appear in the request
let request = thread.update(cx, |thread, cx| { let request = thread.update(cx, |thread, cx| {
thread.to_completion_request(model.clone(), CompletionIntent::UserPrompt, cx) thread.to_completion_request(model.clone(), cx)
}); });
assert_eq!(request.messages.len(), 3); assert_eq!(request.messages.len(), 3);
@@ -3246,7 +3214,7 @@ fn main() {{
// Create a request and check that it doesn't have a stale buffer warning yet // Create a request and check that it doesn't have a stale buffer warning yet
let initial_request = thread.update(cx, |thread, cx| { let initial_request = thread.update(cx, |thread, cx| {
thread.to_completion_request(model.clone(), CompletionIntent::UserPrompt, cx) thread.to_completion_request(model.clone(), cx)
}); });
// Make sure we don't have a stale file warning yet // Make sure we don't have a stale file warning yet
@@ -3282,7 +3250,7 @@ fn main() {{
// Create a new request and check for the stale buffer warning // Create a new request and check for the stale buffer warning
let new_request = thread.update(cx, |thread, cx| { let new_request = thread.update(cx, |thread, cx| {
thread.to_completion_request(model.clone(), CompletionIntent::UserPrompt, cx) thread.to_completion_request(model.clone(), cx)
}); });
// We should have a stale file warning as the last message // We should have a stale file warning as the last message
@@ -3303,71 +3271,6 @@ fn main() {{
); );
} }
#[gpui::test]
async fn test_storing_profile_setting_per_thread(cx: &mut TestAppContext) {
init_test_settings(cx);
let project = create_test_project(
cx,
json!({"code.rs": "fn main() {\n println!(\"Hello, world!\");\n}"}),
)
.await;
let (_workspace, thread_store, thread, _context_store, _model) =
setup_test_environment(cx, project.clone()).await;
// Check that we are starting with the default profile
let profile = cx.read(|cx| thread.read(cx).profile.clone());
let tool_set = cx.read(|cx| thread_store.read(cx).tools());
assert_eq!(
profile,
AgentProfile::new(AgentProfileId::default(), tool_set)
);
}
#[gpui::test]
async fn test_serializing_thread_profile(cx: &mut TestAppContext) {
init_test_settings(cx);
let project = create_test_project(
cx,
json!({"code.rs": "fn main() {\n println!(\"Hello, world!\");\n}"}),
)
.await;
let (_workspace, thread_store, thread, _context_store, _model) =
setup_test_environment(cx, project.clone()).await;
// Profile gets serialized with default values
let serialized = thread
.update(cx, |thread, cx| thread.serialize(cx))
.await
.unwrap();
assert_eq!(serialized.profile, Some(AgentProfileId::default()));
let deserialized = cx.update(|cx| {
thread.update(cx, |thread, cx| {
Thread::deserialize(
thread.id.clone(),
serialized,
thread.project.clone(),
thread.tools.clone(),
thread.prompt_builder.clone(),
thread.project_context.clone(),
None,
cx,
)
})
});
let tool_set = cx.read(|cx| thread_store.read(cx).tools());
assert_eq!(
deserialized.profile,
AgentProfile::new(AgentProfileId::default(), tool_set)
);
}
#[gpui::test] #[gpui::test]
async fn test_temperature_setting(cx: &mut TestAppContext) { async fn test_temperature_setting(cx: &mut TestAppContext) {
init_test_settings(cx); init_test_settings(cx);
@@ -3397,7 +3300,7 @@ fn main() {{
}); });
let request = thread.update(cx, |thread, cx| { let request = thread.update(cx, |thread, cx| {
thread.to_completion_request(model.clone(), CompletionIntent::UserPrompt, cx) thread.to_completion_request(model.clone(), cx)
}); });
assert_eq!(request.temperature, Some(0.66)); assert_eq!(request.temperature, Some(0.66));
@@ -3417,7 +3320,7 @@ fn main() {{
}); });
let request = thread.update(cx, |thread, cx| { let request = thread.update(cx, |thread, cx| {
thread.to_completion_request(model.clone(), CompletionIntent::UserPrompt, cx) thread.to_completion_request(model.clone(), cx)
}); });
assert_eq!(request.temperature, Some(0.66)); assert_eq!(request.temperature, Some(0.66));
@@ -3437,7 +3340,7 @@ fn main() {{
}); });
let request = thread.update(cx, |thread, cx| { let request = thread.update(cx, |thread, cx| {
thread.to_completion_request(model.clone(), CompletionIntent::UserPrompt, cx) thread.to_completion_request(model.clone(), cx)
}); });
assert_eq!(request.temperature, Some(0.66)); assert_eq!(request.temperature, Some(0.66));
@@ -3457,7 +3360,7 @@ fn main() {{
}); });
let request = thread.update(cx, |thread, cx| { let request = thread.update(cx, |thread, cx| {
thread.to_completion_request(model.clone(), CompletionIntent::UserPrompt, cx) thread.to_completion_request(model.clone(), cx)
}); });
assert_eq!(request.temperature, None); assert_eq!(request.temperature, None);
} }
@@ -3489,12 +3392,7 @@ fn main() {{
// Send a message // Send a message
thread.update(cx, |thread, cx| { thread.update(cx, |thread, cx| {
thread.insert_user_message("Hi!", ContextLoadResult::default(), None, vec![], cx); thread.insert_user_message("Hi!", ContextLoadResult::default(), None, vec![], cx);
thread.send_to_model( thread.send_to_model(model.clone(), None, cx);
model.clone(),
CompletionIntent::ThreadSummarization,
None,
cx,
);
}); });
let fake_model = model.as_fake(); let fake_model = model.as_fake();
@@ -3516,8 +3414,8 @@ fn main() {{
}); });
cx.run_until_parked(); cx.run_until_parked();
fake_model.stream_last_completion_response("Brief"); fake_model.stream_last_completion_response("Brief".into());
fake_model.stream_last_completion_response(" Introduction"); fake_model.stream_last_completion_response(" Introduction".into());
fake_model.end_last_completion_stream(); fake_model.end_last_completion_stream();
cx.run_until_parked(); cx.run_until_parked();
@@ -3589,7 +3487,7 @@ fn main() {{
vec![], vec![],
cx, cx,
); );
thread.send_to_model(model.clone(), CompletionIntent::UserPrompt, None, cx); thread.send_to_model(model.clone(), None, cx);
}); });
let fake_model = model.as_fake(); let fake_model = model.as_fake();
@@ -3610,7 +3508,7 @@ fn main() {{
}); });
cx.run_until_parked(); cx.run_until_parked();
fake_model.stream_last_completion_response("A successful summary"); fake_model.stream_last_completion_response("A successful summary".into());
fake_model.end_last_completion_stream(); fake_model.end_last_completion_stream();
cx.run_until_parked(); cx.run_until_parked();
@@ -3627,12 +3525,7 @@ fn main() {{
) { ) {
thread.update(cx, |thread, cx| { thread.update(cx, |thread, cx| {
thread.insert_user_message("Hi!", ContextLoadResult::default(), None, vec![], cx); thread.insert_user_message("Hi!", ContextLoadResult::default(), None, vec![], cx);
thread.send_to_model( thread.send_to_model(model.clone(), None, cx);
model.clone(),
CompletionIntent::ThreadSummarization,
None,
cx,
);
}); });
let fake_model = model.as_fake(); let fake_model = model.as_fake();
@@ -3657,7 +3550,7 @@ fn main() {{
fn simulate_successful_response(fake_model: &FakeLanguageModel, cx: &mut TestAppContext) { fn simulate_successful_response(fake_model: &FakeLanguageModel, cx: &mut TestAppContext) {
cx.run_until_parked(); cx.run_until_parked();
fake_model.stream_last_completion_response("Assistant response"); fake_model.stream_last_completion_response("Assistant response".into());
fake_model.end_last_completion_stream(); fake_model.end_last_completion_stream();
cx.run_until_parked(); cx.run_until_parked();
} }

View File

@@ -671,7 +671,7 @@ impl RenderOnce for HistoryEntryElement {
), ),
HistoryEntry::Context(context) => ( HistoryEntry::Context(context) => (
context.path.to_string_lossy().to_string(), context.path.to_string_lossy().to_string(),
context.title.clone(), context.title.clone().into(),
context.mtime.timestamp(), context.mtime.timestamp(),
), ),
}; };

View File

@@ -1,11 +1,12 @@
use std::borrow::Cow;
use std::cell::{Ref, RefCell}; use std::cell::{Ref, RefCell};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::rc::Rc; use std::rc::Rc;
use std::sync::{Arc, Mutex}; use std::sync::Arc;
use agent_settings::{AgentProfileId, CompletionMode}; use agent_settings::{AgentProfile, AgentProfileId, AgentSettings, CompletionMode};
use anyhow::{Context as _, Result, anyhow}; use anyhow::{Context as _, Result, anyhow};
use assistant_tool::{ToolId, ToolWorkingSet}; use assistant_tool::{ToolId, ToolSource, ToolWorkingSet};
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use collections::HashMap; use collections::HashMap;
use context_server::ContextServerId; use context_server::ContextServerId;
@@ -16,7 +17,8 @@ use gpui::{
App, BackgroundExecutor, Context, Entity, EventEmitter, Global, ReadGlobal, SharedString, App, BackgroundExecutor, Context, Entity, EventEmitter, Global, ReadGlobal, SharedString,
Subscription, Task, prelude::*, Subscription, Task, prelude::*,
}; };
use heed::Database;
use heed::types::SerdeBincode;
use language_model::{LanguageModelToolResultContent, LanguageModelToolUseId, Role, TokenUsage}; use language_model::{LanguageModelToolResultContent, LanguageModelToolUseId, Role, TokenUsage};
use project::context_server_store::{ContextServerStatus, ContextServerStore}; use project::context_server_store::{ContextServerStatus, ContextServerStore};
use project::{Project, ProjectItem, ProjectPath, Worktree}; use project::{Project, ProjectItem, ProjectPath, Worktree};
@@ -25,6 +27,7 @@ use prompt_store::{
UserRulesContext, WorktreeContext, UserRulesContext, WorktreeContext,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use settings::{Settings as _, SettingsStore};
use ui::Window; use ui::Window;
use util::ResultExt as _; use util::ResultExt as _;
@@ -32,52 +35,14 @@ use crate::context_server_tool::ContextServerTool;
use crate::thread::{ use crate::thread::{
DetailedSummaryState, ExceededWindowError, MessageId, ProjectSnapshot, Thread, ThreadId, DetailedSummaryState, ExceededWindowError, MessageId, ProjectSnapshot, Thread, ThreadId,
}; };
use indoc::indoc;
use sqlez::{
bindable::{Bind, Column},
connection::Connection,
statement::Statement,
};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] const RULES_FILE_NAMES: [&'static str; 6] = [
pub enum DataType {
#[serde(rename = "json")]
Json,
#[serde(rename = "zstd")]
Zstd,
}
impl Bind for DataType {
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
let value = match self {
DataType::Json => "json",
DataType::Zstd => "zstd",
};
value.bind(statement, start_index)
}
}
impl Column for DataType {
fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)> {
let (value, next_index) = String::column(statement, start_index)?;
let data_type = match value.as_str() {
"json" => DataType::Json,
"zstd" => DataType::Zstd,
_ => anyhow::bail!("Unknown data type: {}", value),
};
Ok((data_type, next_index))
}
}
const RULES_FILE_NAMES: [&'static str; 8] = [
".rules", ".rules",
".cursorrules", ".cursorrules",
".windsurfrules", ".windsurfrules",
".clinerules", ".clinerules",
".github/copilot-instructions.md", ".github/copilot-instructions.md",
"CLAUDE.md", "CLAUDE.md",
"AGENT.md",
"AGENTS.md",
]; ];
pub fn init(cx: &mut App) { pub fn init(cx: &mut App) {
@@ -89,7 +54,7 @@ pub fn init(cx: &mut App) {
pub struct SharedProjectContext(Rc<RefCell<Option<ProjectContext>>>); pub struct SharedProjectContext(Rc<RefCell<Option<ProjectContext>>>);
impl SharedProjectContext { impl SharedProjectContext {
pub fn borrow(&self) -> Ref<'_, Option<ProjectContext>> { pub fn borrow(&self) -> Ref<Option<ProjectContext>> {
self.0.borrow() self.0.borrow()
} }
} }
@@ -146,7 +111,12 @@ impl ThreadStore {
prompt_store: Option<Entity<PromptStore>>, prompt_store: Option<Entity<PromptStore>>,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> (Self, oneshot::Receiver<()>) { ) -> (Self, oneshot::Receiver<()>) {
let mut subscriptions = vec![cx.subscribe(&project, Self::handle_project_event)]; let mut subscriptions = vec![
cx.observe_global::<SettingsStore>(move |this: &mut Self, cx| {
this.load_default_profile(cx);
}),
cx.subscribe(&project, Self::handle_project_event),
];
if let Some(prompt_store) = prompt_store.as_ref() { if let Some(prompt_store) = prompt_store.as_ref() {
subscriptions.push(cx.subscribe( subscriptions.push(cx.subscribe(
@@ -194,6 +164,7 @@ impl ThreadStore {
_reload_system_prompt_task: reload_system_prompt_task, _reload_system_prompt_task: reload_system_prompt_task,
_subscriptions: subscriptions, _subscriptions: subscriptions,
}; };
this.load_default_profile(cx);
this.register_context_server_handlers(cx); this.register_context_server_handlers(cx);
this.reload(cx).detach_and_log_err(cx); this.reload(cx).detach_and_log_err(cx);
(this, ready_rx) (this, ready_rx)
@@ -393,11 +364,16 @@ impl ThreadStore {
self.threads.len() self.threads.len()
} }
pub fn reverse_chronological_threads(&self) -> impl Iterator<Item = &SerializedThreadMetadata> { pub fn unordered_threads(&self) -> impl Iterator<Item = &SerializedThreadMetadata> {
// ordering is from "ORDER BY" in `list_threads`
self.threads.iter() self.threads.iter()
} }
pub fn reverse_chronological_threads(&self) -> Vec<SerializedThreadMetadata> {
let mut threads = self.threads.iter().cloned().collect::<Vec<_>>();
threads.sort_unstable_by_key(|thread| std::cmp::Reverse(thread.updated_at));
threads
}
pub fn create_thread(&mut self, cx: &mut Context<Self>) -> Entity<Thread> { pub fn create_thread(&mut self, cx: &mut Context<Self>) -> Entity<Thread> {
cx.new(|cx| { cx.new(|cx| {
Thread::new( Thread::new(
@@ -508,17 +484,94 @@ impl ThreadStore {
}) })
} }
fn register_context_server_handlers(&self, cx: &mut Context<Self>) { fn load_default_profile(&self, cx: &mut Context<Self>) {
let context_server_store = self.project.read(cx).context_server_store(); let assistant_settings = AgentSettings::get_global(cx);
cx.subscribe(&context_server_store, Self::handle_context_server_event)
.detach();
// Check for any servers that were already running before the handler was registered self.load_profile_by_id(assistant_settings.default_profile.clone(), cx);
for server in context_server_store.read(cx).running_servers() { }
self.load_context_server_tools(server.id(), context_server_store.clone(), cx);
pub fn load_profile_by_id(&self, profile_id: AgentProfileId, cx: &mut Context<Self>) {
let assistant_settings = AgentSettings::get_global(cx);
if let Some(profile) = assistant_settings.profiles.get(&profile_id) {
self.load_profile(profile.clone(), cx);
} }
} }
pub fn load_profile(&self, profile: AgentProfile, cx: &mut Context<Self>) {
self.tools.update(cx, |tools, cx| {
tools.disable_all_tools(cx);
tools.enable(
ToolSource::Native,
&profile
.tools
.into_iter()
.filter_map(|(tool, enabled)| enabled.then(|| tool))
.collect::<Vec<_>>(),
cx,
);
});
if profile.enable_all_context_servers {
for context_server_id in self
.project
.read(cx)
.context_server_store()
.read(cx)
.all_server_ids()
{
self.tools.update(cx, |tools, cx| {
tools.enable_source(
ToolSource::ContextServer {
id: context_server_id.0.into(),
},
cx,
);
});
}
// Enable all the tools from all context servers, but disable the ones that are explicitly disabled
for (context_server_id, preset) in profile.context_servers {
self.tools.update(cx, |tools, cx| {
tools.disable(
ToolSource::ContextServer {
id: context_server_id.into(),
},
&preset
.tools
.into_iter()
.filter_map(|(tool, enabled)| (!enabled).then(|| tool))
.collect::<Vec<_>>(),
cx,
)
})
}
} else {
for (context_server_id, preset) in profile.context_servers {
self.tools.update(cx, |tools, cx| {
tools.enable(
ToolSource::ContextServer {
id: context_server_id.into(),
},
&preset
.tools
.into_iter()
.filter_map(|(tool, enabled)| enabled.then(|| tool))
.collect::<Vec<_>>(),
cx,
)
})
}
}
}
fn register_context_server_handlers(&self, cx: &mut Context<Self>) {
cx.subscribe(
&self.project.read(cx).context_server_store(),
Self::handle_context_server_event,
)
.detach();
}
fn handle_context_server_event( fn handle_context_server_event(
&mut self, &mut self,
context_server_store: Entity<ContextServerStore>, context_server_store: Entity<ContextServerStore>,
@@ -529,71 +582,71 @@ impl ThreadStore {
match event { match event {
project::context_server_store::Event::ServerStatusChanged { server_id, status } => { project::context_server_store::Event::ServerStatusChanged { server_id, status } => {
match status { match status {
ContextServerStatus::Starting => {}
ContextServerStatus::Running => { ContextServerStatus::Running => {
self.load_context_server_tools(server_id.clone(), context_server_store, cx); if let Some(server) =
context_server_store.read(cx).get_running_server(server_id)
{
let context_server_manager = context_server_store.clone();
cx.spawn({
let server = server.clone();
let server_id = server_id.clone();
async move |this, cx| {
let Some(protocol) = server.client() else {
return;
};
if protocol.capable(context_server::protocol::ServerCapability::Tools) {
if let Some(tools) = protocol.list_tools().await.log_err() {
let tool_ids = tool_working_set
.update(cx, |tool_working_set, _| {
tools
.tools
.into_iter()
.map(|tool| {
log::info!(
"registering context server tool: {:?}",
tool.name
);
tool_working_set.insert(Arc::new(
ContextServerTool::new(
context_server_manager.clone(),
server.id(),
tool,
),
))
})
.collect::<Vec<_>>()
})
.log_err();
if let Some(tool_ids) = tool_ids {
this.update(cx, |this, cx| {
this.context_server_tool_ids
.insert(server_id, tool_ids);
this.load_default_profile(cx);
})
.log_err();
}
}
}
}
})
.detach();
}
} }
ContextServerStatus::Stopped | ContextServerStatus::Error(_) => { ContextServerStatus::Stopped | ContextServerStatus::Error(_) => {
if let Some(tool_ids) = self.context_server_tool_ids.remove(server_id) { if let Some(tool_ids) = self.context_server_tool_ids.remove(server_id) {
tool_working_set.update(cx, |tool_working_set, _| { tool_working_set.update(cx, |tool_working_set, _| {
tool_working_set.remove(&tool_ids); tool_working_set.remove(&tool_ids);
}); });
self.load_default_profile(cx);
} }
} }
_ => {}
} }
} }
} }
} }
fn load_context_server_tools(
&self,
server_id: ContextServerId,
context_server_store: Entity<ContextServerStore>,
cx: &mut Context<Self>,
) {
let Some(server) = context_server_store.read(cx).get_running_server(&server_id) else {
return;
};
let tool_working_set = self.tools.clone();
cx.spawn(async move |this, cx| {
let Some(protocol) = server.client() else {
return;
};
if protocol.capable(context_server::protocol::ServerCapability::Tools) {
if let Some(response) = protocol
.request::<context_server::types::requests::ListTools>(())
.await
.log_err()
{
let tool_ids = tool_working_set
.update(cx, |tool_working_set, _| {
response
.tools
.into_iter()
.map(|tool| {
log::info!("registering context server tool: {:?}", tool.name);
tool_working_set.insert(Arc::new(ContextServerTool::new(
context_server_store.clone(),
server.id(),
tool,
)))
})
.collect::<Vec<_>>()
})
.log_err();
if let Some(tool_ids) = tool_ids {
this.update(cx, |this, _| {
this.context_server_tool_ids.insert(server_id, tool_ids);
})
.log_err();
}
}
}
})
.detach();
}
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
@@ -603,7 +656,7 @@ pub struct SerializedThreadMetadata {
pub updated_at: DateTime<Utc>, pub updated_at: DateTime<Utc>,
} }
#[derive(Serialize, Deserialize, Debug, PartialEq)] #[derive(Serialize, Deserialize, Debug)]
pub struct SerializedThread { pub struct SerializedThread {
pub version: String, pub version: String,
pub summary: SharedString, pub summary: SharedString,
@@ -625,11 +678,9 @@ pub struct SerializedThread {
pub completion_mode: Option<CompletionMode>, pub completion_mode: Option<CompletionMode>,
#[serde(default)] #[serde(default)]
pub tool_use_limit_reached: bool, pub tool_use_limit_reached: bool,
#[serde(default)]
pub profile: Option<AgentProfileId>,
} }
#[derive(Serialize, Deserialize, Debug, PartialEq)] #[derive(Serialize, Deserialize, Debug)]
pub struct SerializedLanguageModel { pub struct SerializedLanguageModel {
pub provider: String, pub provider: String,
pub model: String, pub model: String,
@@ -690,15 +741,11 @@ impl SerializedThreadV0_1_0 {
messages.push(message); messages.push(message);
} }
SerializedThread { SerializedThread { messages, ..self.0 }
messages,
version: SerializedThread::VERSION.to_string(),
..self.0
}
} }
} }
#[derive(Debug, Serialize, Deserialize, PartialEq)] #[derive(Debug, Serialize, Deserialize)]
pub struct SerializedMessage { pub struct SerializedMessage {
pub id: MessageId, pub id: MessageId,
pub role: Role, pub role: Role,
@@ -716,7 +763,7 @@ pub struct SerializedMessage {
pub is_hidden: bool, pub is_hidden: bool,
} }
#[derive(Debug, Serialize, Deserialize, PartialEq)] #[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "type")] #[serde(tag = "type")]
pub enum SerializedMessageSegment { pub enum SerializedMessageSegment {
#[serde(rename = "text")] #[serde(rename = "text")]
@@ -734,14 +781,14 @@ pub enum SerializedMessageSegment {
}, },
} }
#[derive(Debug, Serialize, Deserialize, PartialEq)] #[derive(Debug, Serialize, Deserialize)]
pub struct SerializedToolUse { pub struct SerializedToolUse {
pub id: LanguageModelToolUseId, pub id: LanguageModelToolUseId,
pub name: SharedString, pub name: SharedString,
pub input: serde_json::Value, pub input: serde_json::Value,
} }
#[derive(Debug, Serialize, Deserialize, PartialEq)] #[derive(Debug, Serialize, Deserialize)]
pub struct SerializedToolResult { pub struct SerializedToolResult {
pub tool_use_id: LanguageModelToolUseId, pub tool_use_id: LanguageModelToolUseId,
pub is_error: bool, pub is_error: bool,
@@ -773,7 +820,6 @@ impl LegacySerializedThread {
model: None, model: None,
completion_mode: None, completion_mode: None,
tool_use_limit_reached: false, tool_use_limit_reached: false,
profile: None,
} }
} }
} }
@@ -804,7 +850,7 @@ impl LegacySerializedMessage {
} }
} }
#[derive(Debug, Serialize, Deserialize, PartialEq)] #[derive(Debug, Serialize, Deserialize)]
pub struct SerializedCrease { pub struct SerializedCrease {
pub start: usize, pub start: usize,
pub end: usize, pub end: usize,
@@ -820,27 +866,25 @@ impl Global for GlobalThreadsDatabase {}
pub(crate) struct ThreadsDatabase { pub(crate) struct ThreadsDatabase {
executor: BackgroundExecutor, executor: BackgroundExecutor,
connection: Arc<Mutex<Connection>>, env: heed::Env,
threads: Database<SerdeBincode<ThreadId>, SerializedThread>,
} }
impl ThreadsDatabase { impl heed::BytesEncode<'_> for SerializedThread {
fn connection(&self) -> Arc<Mutex<Connection>> { type EItem = SerializedThread;
self.connection.clone()
}
const COMPRESSION_LEVEL: i32 = 3; fn bytes_encode(item: &Self::EItem) -> Result<Cow<[u8]>, heed::BoxedError> {
} serde_json::to_vec(item).map(Cow::Owned).map_err(Into::into)
impl Bind for ThreadId {
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
self.to_string().bind(statement, start_index)
} }
} }
impl Column for ThreadId { impl<'a> heed::BytesDecode<'a> for SerializedThread {
fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)> { type DItem = SerializedThread;
let (id_str, next_index) = String::column(statement, start_index)?;
Ok((ThreadId::from(id_str.as_str()), next_index)) fn bytes_decode(bytes: &'a [u8]) -> Result<Self::DItem, heed::BoxedError> {
// We implement this type manually because we want to call `SerializedThread::from_json`,
// instead of the Deserialize trait implementation for `SerializedThread`.
SerializedThread::from_json(bytes).map_err(Into::into)
} }
} }
@@ -856,8 +900,8 @@ impl ThreadsDatabase {
let database_future = executor let database_future = executor
.spawn({ .spawn({
let executor = executor.clone(); let executor = executor.clone();
let threads_dir = paths::data_dir().join("threads"); let database_path = paths::data_dir().join("threads/threads-db.1.mdb");
async move { ThreadsDatabase::new(threads_dir, executor) } async move { ThreadsDatabase::new(database_path, executor) }
}) })
.then(|result| future::ready(result.map(Arc::new).map_err(Arc::new))) .then(|result| future::ready(result.map(Arc::new).map_err(Arc::new)))
.boxed() .boxed()
@@ -866,144 +910,41 @@ impl ThreadsDatabase {
cx.set_global(GlobalThreadsDatabase(database_future)); cx.set_global(GlobalThreadsDatabase(database_future));
} }
pub fn new(threads_dir: PathBuf, executor: BackgroundExecutor) -> Result<Self> { pub fn new(path: PathBuf, executor: BackgroundExecutor) -> Result<Self> {
std::fs::create_dir_all(&threads_dir)?; std::fs::create_dir_all(&path)?;
let sqlite_path = threads_dir.join("threads.db");
let mdb_path = threads_dir.join("threads-db.1.mdb");
let needs_migration_from_heed = mdb_path.exists();
let connection = Connection::open_file(&sqlite_path.to_string_lossy());
connection.exec(indoc! {"
CREATE TABLE IF NOT EXISTS threads (
id TEXT PRIMARY KEY,
summary TEXT NOT NULL,
updated_at TEXT NOT NULL,
data_type TEXT NOT NULL,
data BLOB NOT NULL
)
"})?()
.map_err(|e| anyhow!("Failed to create threads table: {}", e))?;
let db = Self {
executor: executor.clone(),
connection: Arc::new(Mutex::new(connection)),
};
if needs_migration_from_heed {
let db_connection = db.connection();
let executor_clone = executor.clone();
executor
.spawn(async move {
log::info!("Starting threads.db migration");
Self::migrate_from_heed(&mdb_path, db_connection, executor_clone)?;
std::fs::remove_dir_all(mdb_path)?;
log::info!("threads.db migrated to sqlite");
Ok::<(), anyhow::Error>(())
})
.detach();
}
Ok(db)
}
// Remove this migration after 2025-09-01
fn migrate_from_heed(
mdb_path: &Path,
connection: Arc<Mutex<Connection>>,
_executor: BackgroundExecutor,
) -> Result<()> {
use heed::types::SerdeBincode;
struct SerializedThreadHeed(SerializedThread);
impl heed::BytesEncode<'_> for SerializedThreadHeed {
type EItem = SerializedThreadHeed;
fn bytes_encode(
item: &Self::EItem,
) -> Result<std::borrow::Cow<'_, [u8]>, heed::BoxedError> {
serde_json::to_vec(&item.0)
.map(std::borrow::Cow::Owned)
.map_err(Into::into)
}
}
impl<'a> heed::BytesDecode<'a> for SerializedThreadHeed {
type DItem = SerializedThreadHeed;
fn bytes_decode(bytes: &'a [u8]) -> Result<Self::DItem, heed::BoxedError> {
SerializedThread::from_json(bytes)
.map(SerializedThreadHeed)
.map_err(Into::into)
}
}
const ONE_GB_IN_BYTES: usize = 1024 * 1024 * 1024; const ONE_GB_IN_BYTES: usize = 1024 * 1024 * 1024;
let env = unsafe { let env = unsafe {
heed::EnvOpenOptions::new() heed::EnvOpenOptions::new()
.map_size(ONE_GB_IN_BYTES) .map_size(ONE_GB_IN_BYTES)
.max_dbs(1) .max_dbs(1)
.open(mdb_path)? .open(path)?
}; };
let txn = env.write_txn()?; let mut txn = env.write_txn()?;
let threads: heed::Database<SerdeBincode<ThreadId>, SerializedThreadHeed> = env let threads = env.create_database(&mut txn, Some("threads"))?;
.open_database(&txn, Some("threads"))? txn.commit()?;
.ok_or_else(|| anyhow!("threads database not found"))?;
for result in threads.iter(&txn)? { Ok(Self {
let (thread_id, thread_heed) = result?; executor,
Self::save_thread_sync(&connection, thread_id, thread_heed.0)?; env,
} threads,
})
Ok(())
}
fn save_thread_sync(
connection: &Arc<Mutex<Connection>>,
id: ThreadId,
thread: SerializedThread,
) -> Result<()> {
let json_data = serde_json::to_string(&thread)?;
let summary = thread.summary.to_string();
let updated_at = thread.updated_at.to_rfc3339();
let connection = connection.lock().unwrap();
let compressed = zstd::encode_all(json_data.as_bytes(), Self::COMPRESSION_LEVEL)?;
let data_type = DataType::Zstd;
let data = compressed;
let mut insert = connection.exec_bound::<(ThreadId, String, String, DataType, Vec<u8>)>(indoc! {"
INSERT OR REPLACE INTO threads (id, summary, updated_at, data_type, data) VALUES (?, ?, ?, ?, ?)
"})?;
insert((id, summary, updated_at, data_type, data))?;
Ok(())
} }
pub fn list_threads(&self) -> Task<Result<Vec<SerializedThreadMetadata>>> { pub fn list_threads(&self) -> Task<Result<Vec<SerializedThreadMetadata>>> {
let connection = self.connection.clone(); let env = self.env.clone();
let threads = self.threads;
self.executor.spawn(async move { self.executor.spawn(async move {
let connection = connection.lock().unwrap(); let txn = env.read_txn()?;
let mut select = let mut iter = threads.iter(&txn)?;
connection.select_bound::<(), (ThreadId, String, String)>(indoc! {"
SELECT id, summary, updated_at FROM threads ORDER BY updated_at DESC
"})?;
let rows = select(())?;
let mut threads = Vec::new(); let mut threads = Vec::new();
while let Some((key, value)) = iter.next().transpose()? {
for (id, summary, updated_at) in rows {
threads.push(SerializedThreadMetadata { threads.push(SerializedThreadMetadata {
id, id: key,
summary: summary.into(), summary: value.summary,
updated_at: DateTime::parse_from_rfc3339(&updated_at)?.with_timezone(&Utc), updated_at: value.updated_at,
}); });
} }
@@ -1012,230 +953,37 @@ impl ThreadsDatabase {
} }
pub fn try_find_thread(&self, id: ThreadId) -> Task<Result<Option<SerializedThread>>> { pub fn try_find_thread(&self, id: ThreadId) -> Task<Result<Option<SerializedThread>>> {
let connection = self.connection.clone(); let env = self.env.clone();
let threads = self.threads;
self.executor.spawn(async move { self.executor.spawn(async move {
let connection = connection.lock().unwrap(); let txn = env.read_txn()?;
let mut select = connection.select_bound::<ThreadId, (DataType, Vec<u8>)>(indoc! {" let thread = threads.get(&txn, &id)?;
SELECT data_type, data FROM threads WHERE id = ? LIMIT 1 Ok(thread)
"})?;
let rows = select(id)?;
if let Some((data_type, data)) = rows.into_iter().next() {
let json_data = match data_type {
DataType::Zstd => {
let decompressed = zstd::decode_all(&data[..])?;
String::from_utf8(decompressed)?
}
DataType::Json => String::from_utf8(data)?,
};
let thread = SerializedThread::from_json(json_data.as_bytes())?;
Ok(Some(thread))
} else {
Ok(None)
}
}) })
} }
pub fn save_thread(&self, id: ThreadId, thread: SerializedThread) -> Task<Result<()>> { pub fn save_thread(&self, id: ThreadId, thread: SerializedThread) -> Task<Result<()>> {
let connection = self.connection.clone(); let env = self.env.clone();
let threads = self.threads;
self.executor self.executor.spawn(async move {
.spawn(async move { Self::save_thread_sync(&connection, id, thread) }) let mut txn = env.write_txn()?;
threads.put(&mut txn, &id, &thread)?;
txn.commit()?;
Ok(())
})
} }
pub fn delete_thread(&self, id: ThreadId) -> Task<Result<()>> { pub fn delete_thread(&self, id: ThreadId) -> Task<Result<()>> {
let connection = self.connection.clone(); let env = self.env.clone();
let threads = self.threads;
self.executor.spawn(async move { self.executor.spawn(async move {
let connection = connection.lock().unwrap(); let mut txn = env.write_txn()?;
threads.delete(&mut txn, &id)?;
let mut delete = connection.exec_bound::<ThreadId>(indoc! {" txn.commit()?;
DELETE FROM threads WHERE id = ?
"})?;
delete(id)?;
Ok(()) Ok(())
}) })
} }
} }
#[cfg(test)]
mod tests {
use super::*;
use crate::thread::{DetailedSummaryState, MessageId};
use chrono::Utc;
use language_model::{Role, TokenUsage};
use pretty_assertions::assert_eq;
#[test]
fn test_legacy_serialized_thread_upgrade() {
let updated_at = Utc::now();
let legacy_thread = LegacySerializedThread {
summary: "Test conversation".into(),
updated_at,
messages: vec![LegacySerializedMessage {
id: MessageId(1),
role: Role::User,
text: "Hello, world!".to_string(),
tool_uses: vec![],
tool_results: vec![],
}],
initial_project_snapshot: None,
};
let upgraded = legacy_thread.upgrade();
assert_eq!(
upgraded,
SerializedThread {
summary: "Test conversation".into(),
updated_at,
messages: vec![SerializedMessage {
id: MessageId(1),
role: Role::User,
segments: vec![SerializedMessageSegment::Text {
text: "Hello, world!".to_string()
}],
tool_uses: vec![],
tool_results: vec![],
context: "".to_string(),
creases: vec![],
is_hidden: false
}],
version: SerializedThread::VERSION.to_string(),
initial_project_snapshot: None,
cumulative_token_usage: TokenUsage::default(),
request_token_usage: vec![],
detailed_summary_state: DetailedSummaryState::default(),
exceeded_window_error: None,
model: None,
completion_mode: None,
tool_use_limit_reached: false,
profile: None
}
)
}
#[test]
fn test_serialized_threadv0_1_0_upgrade() {
let updated_at = Utc::now();
let thread_v0_1_0 = SerializedThreadV0_1_0(SerializedThread {
summary: "Test conversation".into(),
updated_at,
messages: vec![
SerializedMessage {
id: MessageId(1),
role: Role::User,
segments: vec![SerializedMessageSegment::Text {
text: "Use tool_1".to_string(),
}],
tool_uses: vec![],
tool_results: vec![],
context: "".to_string(),
creases: vec![],
is_hidden: false,
},
SerializedMessage {
id: MessageId(2),
role: Role::Assistant,
segments: vec![SerializedMessageSegment::Text {
text: "I want to use a tool".to_string(),
}],
tool_uses: vec![SerializedToolUse {
id: "abc".into(),
name: "tool_1".into(),
input: serde_json::Value::Null,
}],
tool_results: vec![],
context: "".to_string(),
creases: vec![],
is_hidden: false,
},
SerializedMessage {
id: MessageId(1),
role: Role::User,
segments: vec![SerializedMessageSegment::Text {
text: "Here is the tool result".to_string(),
}],
tool_uses: vec![],
tool_results: vec![SerializedToolResult {
tool_use_id: "abc".into(),
is_error: false,
content: LanguageModelToolResultContent::Text("abcdef".into()),
output: Some(serde_json::Value::Null),
}],
context: "".to_string(),
creases: vec![],
is_hidden: false,
},
],
version: SerializedThreadV0_1_0::VERSION.to_string(),
initial_project_snapshot: None,
cumulative_token_usage: TokenUsage::default(),
request_token_usage: vec![],
detailed_summary_state: DetailedSummaryState::default(),
exceeded_window_error: None,
model: None,
completion_mode: None,
tool_use_limit_reached: false,
profile: None,
});
let upgraded = thread_v0_1_0.upgrade();
assert_eq!(
upgraded,
SerializedThread {
summary: "Test conversation".into(),
updated_at,
messages: vec![
SerializedMessage {
id: MessageId(1),
role: Role::User,
segments: vec![SerializedMessageSegment::Text {
text: "Use tool_1".to_string()
}],
tool_uses: vec![],
tool_results: vec![],
context: "".to_string(),
creases: vec![],
is_hidden: false
},
SerializedMessage {
id: MessageId(2),
role: Role::Assistant,
segments: vec![SerializedMessageSegment::Text {
text: "I want to use a tool".to_string(),
}],
tool_uses: vec![SerializedToolUse {
id: "abc".into(),
name: "tool_1".into(),
input: serde_json::Value::Null,
}],
tool_results: vec![SerializedToolResult {
tool_use_id: "abc".into(),
is_error: false,
content: LanguageModelToolResultContent::Text("abcdef".into()),
output: Some(serde_json::Value::Null),
}],
context: "".to_string(),
creases: vec![],
is_hidden: false,
},
],
version: SerializedThread::VERSION.to_string(),
initial_project_snapshot: None,
cumulative_token_usage: TokenUsage::default(),
request_token_usage: vec![],
detailed_summary_state: DetailedSummaryState::default(),
exceeded_window_error: None,
model: None,
completion_mode: None,
tool_use_limit_reached: false,
profile: None
}
)
}
}

View File

@@ -1,33 +1,30 @@
use std::sync::Arc; use std::sync::Arc;
use assistant_tool::{Tool, ToolSource}; use assistant_tool::{Tool, ToolSource, ToolWorkingSet, ToolWorkingSetEvent};
use collections::HashMap; use collections::HashMap;
use gpui::{App, Context, Entity, IntoElement, Render, Subscription, Window}; use gpui::{App, Context, Entity, IntoElement, Render, Subscription, Window};
use language_model::{LanguageModel, LanguageModelToolSchemaFormat}; use language_model::{LanguageModel, LanguageModelToolSchemaFormat};
use ui::prelude::*; use ui::prelude::*;
use crate::{Thread, ThreadEvent};
pub struct IncompatibleToolsState { pub struct IncompatibleToolsState {
cache: HashMap<LanguageModelToolSchemaFormat, Vec<Arc<dyn Tool>>>, cache: HashMap<LanguageModelToolSchemaFormat, Vec<Arc<dyn Tool>>>,
thread: Entity<Thread>, tool_working_set: Entity<ToolWorkingSet>,
_thread_subscription: Subscription, _tool_working_set_subscription: Subscription,
} }
impl IncompatibleToolsState { impl IncompatibleToolsState {
pub fn new(thread: Entity<Thread>, cx: &mut Context<Self>) -> Self { pub fn new(tool_working_set: Entity<ToolWorkingSet>, cx: &mut Context<Self>) -> Self {
let _tool_working_set_subscription = let _tool_working_set_subscription =
cx.subscribe(&thread, |this, _, event, _| match event { cx.subscribe(&tool_working_set, |this, _, event, _| match event {
ThreadEvent::ProfileChanged => { ToolWorkingSetEvent::EnabledToolsChanged => {
this.cache.clear(); this.cache.clear();
} }
_ => {}
}); });
Self { Self {
cache: HashMap::default(), cache: HashMap::default(),
thread, tool_working_set,
_thread_subscription: _tool_working_set_subscription, _tool_working_set_subscription,
} }
} }
@@ -39,9 +36,8 @@ impl IncompatibleToolsState {
self.cache self.cache
.entry(model.tool_input_format()) .entry(model.tool_input_format())
.or_insert_with(|| { .or_insert_with(|| {
self.thread self.tool_working_set
.read(cx) .read(cx)
.profile()
.enabled_tools(cx) .enabled_tools(cx)
.iter() .iter()
.filter(|tool| tool.input_schema(model.tool_input_format()).is_err()) .filter(|tool| tool.input_schema(model.tool_input_format()).is_err())

View File

@@ -337,12 +337,6 @@ impl ToolUseState {
) )
.into(); .into();
let may_perform_edits = self
.tools
.read(cx)
.tool(&tool_use.name, cx)
.is_some_and(|tool| tool.may_perform_edits());
self.pending_tool_uses_by_id.insert( self.pending_tool_uses_by_id.insert(
tool_use.id.clone(), tool_use.id.clone(),
PendingToolUse { PendingToolUse {
@@ -351,7 +345,6 @@ impl ToolUseState {
name: tool_use.name.clone(), name: tool_use.name.clone(),
ui_text: ui_text.clone(), ui_text: ui_text.clone(),
input: tool_use.input, input: tool_use.input,
may_perform_edits,
status, status,
}, },
); );
@@ -525,7 +518,6 @@ pub struct PendingToolUse {
pub ui_text: Arc<str>, pub ui_text: Arc<str>,
pub input: serde_json::Value, pub input: serde_json::Value,
pub status: PendingToolUseStatus, pub status: PendingToolUseStatus,
pub may_perform_edits: bool,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

View File

@@ -93,9 +93,20 @@ impl ContextPill {
Self::Suggested { Self::Suggested {
icon_path: Some(icon_path), icon_path: Some(icon_path),
.. ..
}
| Self::Added {
context:
AddedContext {
icon_path: Some(icon_path),
..
},
..
} => Icon::from_path(icon_path), } => Icon::from_path(icon_path),
Self::Suggested { kind, .. } => Icon::new(kind.icon()), Self::Suggested { kind, .. }
Self::Added { context, .. } => context.icon(), | Self::Added {
context: AddedContext { kind, .. },
..
} => Icon::new(kind.icon()),
} }
} }
} }
@@ -122,7 +133,6 @@ impl RenderOnce for ContextPill {
on_click, on_click,
} => { } => {
let status_is_error = matches!(context.status, ContextStatus::Error { .. }); let status_is_error = matches!(context.status, ContextStatus::Error { .. });
let status_is_warning = matches!(context.status, ContextStatus::Warning { .. });
base_pill base_pill
.pr(if on_remove.is_some() { px(2.) } else { px(4.) }) .pr(if on_remove.is_some() { px(2.) } else { px(4.) })
@@ -130,9 +140,6 @@ impl RenderOnce for ContextPill {
if status_is_error { if status_is_error {
pill.bg(cx.theme().status().error_background) pill.bg(cx.theme().status().error_background)
.border_color(cx.theme().status().error_border) .border_color(cx.theme().status().error_border)
} else if status_is_warning {
pill.bg(cx.theme().status().warning_background)
.border_color(cx.theme().status().warning_border)
} else if *focused { } else if *focused {
pill.bg(color.element_background) pill.bg(color.element_background)
.border_color(color.border_focused) .border_color(color.border_focused)
@@ -188,8 +195,7 @@ impl RenderOnce for ContextPill {
|label, delta| label.opacity(delta), |label, delta| label.opacity(delta),
) )
.into_any_element(), .into_any_element(),
ContextStatus::Warning { message } ContextStatus::Error { message } => element
| ContextStatus::Error { message } => element
.tooltip(ui::Tooltip::text(message.clone())) .tooltip(ui::Tooltip::text(message.clone()))
.into_any_element(), .into_any_element(),
}), }),
@@ -264,7 +270,6 @@ pub enum ContextStatus {
Ready, Ready,
Loading { message: SharedString }, Loading { message: SharedString },
Error { message: SharedString }, Error { message: SharedString },
Warning { message: SharedString },
} }
#[derive(RegisterComponent)] #[derive(RegisterComponent)]
@@ -280,19 +285,6 @@ pub struct AddedContext {
} }
impl AddedContext { impl AddedContext {
pub fn icon(&self) -> Icon {
match &self.status {
ContextStatus::Warning { .. } => Icon::new(IconName::Warning).color(Color::Warning),
ContextStatus::Error { .. } => Icon::new(IconName::XCircle).color(Color::Error),
_ => {
if let Some(icon_path) = &self.icon_path {
Icon::from_path(icon_path)
} else {
Icon::new(self.kind.icon())
}
}
}
}
/// Creates an `AddedContext` by retrieving relevant details of `AgentContext`. This returns a /// Creates an `AddedContext` by retrieving relevant details of `AgentContext`. This returns a
/// `None` if `DirectoryContext` or `RulesContext` no longer exist. /// `None` if `DirectoryContext` or `RulesContext` no longer exist.
/// ///
@@ -301,7 +293,6 @@ impl AddedContext {
handle: AgentContextHandle, handle: AgentContextHandle,
prompt_store: Option<&Entity<PromptStore>>, prompt_store: Option<&Entity<PromptStore>>,
project: &Project, project: &Project,
model: Option<&Arc<dyn language_model::LanguageModel>>,
cx: &App, cx: &App,
) -> Option<AddedContext> { ) -> Option<AddedContext> {
match handle { match handle {
@@ -313,15 +304,11 @@ impl AddedContext {
AgentContextHandle::Thread(handle) => Some(Self::pending_thread(handle, cx)), AgentContextHandle::Thread(handle) => Some(Self::pending_thread(handle, cx)),
AgentContextHandle::TextThread(handle) => Some(Self::pending_text_thread(handle, cx)), AgentContextHandle::TextThread(handle) => Some(Self::pending_text_thread(handle, cx)),
AgentContextHandle::Rules(handle) => Self::pending_rules(handle, prompt_store, cx), AgentContextHandle::Rules(handle) => Self::pending_rules(handle, prompt_store, cx),
AgentContextHandle::Image(handle) => Some(Self::image(handle, model, cx)), AgentContextHandle::Image(handle) => Some(Self::image(handle)),
} }
} }
pub fn new_attached( pub fn new_attached(context: &AgentContext, cx: &App) -> AddedContext {
context: &AgentContext,
model: Option<&Arc<dyn language_model::LanguageModel>>,
cx: &App,
) -> AddedContext {
match context { match context {
AgentContext::File(context) => Self::attached_file(context, cx), AgentContext::File(context) => Self::attached_file(context, cx),
AgentContext::Directory(context) => Self::attached_directory(context), AgentContext::Directory(context) => Self::attached_directory(context),
@@ -331,7 +318,7 @@ impl AddedContext {
AgentContext::Thread(context) => Self::attached_thread(context), AgentContext::Thread(context) => Self::attached_thread(context),
AgentContext::TextThread(context) => Self::attached_text_thread(context), AgentContext::TextThread(context) => Self::attached_text_thread(context),
AgentContext::Rules(context) => Self::attached_rules(context), AgentContext::Rules(context) => Self::attached_rules(context),
AgentContext::Image(context) => Self::image(context.clone(), model, cx), AgentContext::Image(context) => Self::image(context.clone()),
} }
} }
@@ -346,8 +333,14 @@ impl AddedContext {
fn file(handle: FileContextHandle, full_path: &Path, cx: &App) -> AddedContext { fn file(handle: FileContextHandle, full_path: &Path, cx: &App) -> AddedContext {
let full_path_string: SharedString = full_path.to_string_lossy().into_owned().into(); let full_path_string: SharedString = full_path.to_string_lossy().into_owned().into();
let (name, parent) = let name = full_path
extract_file_name_and_directory_from_full_path(full_path, &full_path_string); .file_name()
.map(|n| n.to_string_lossy().into_owned().into())
.unwrap_or_else(|| full_path_string.clone());
let parent = full_path
.parent()
.and_then(|p| p.file_name())
.map(|n| n.to_string_lossy().into_owned().into());
AddedContext { AddedContext {
kind: ContextKind::File, kind: ContextKind::File,
name, name,
@@ -377,8 +370,14 @@ impl AddedContext {
fn directory(handle: DirectoryContextHandle, full_path: &Path) -> AddedContext { fn directory(handle: DirectoryContextHandle, full_path: &Path) -> AddedContext {
let full_path_string: SharedString = full_path.to_string_lossy().into_owned().into(); let full_path_string: SharedString = full_path.to_string_lossy().into_owned().into();
let (name, parent) = let name = full_path
extract_file_name_and_directory_from_full_path(full_path, &full_path_string); .file_name()
.map(|n| n.to_string_lossy().into_owned().into())
.unwrap_or_else(|| full_path_string.clone());
let parent = full_path
.parent()
.and_then(|p| p.file_name())
.map(|n| n.to_string_lossy().into_owned().into());
AddedContext { AddedContext {
kind: ContextKind::Directory, kind: ContextKind::Directory,
name, name,
@@ -606,45 +605,22 @@ impl AddedContext {
} }
} }
fn image( fn image(context: ImageContext) -> AddedContext {
context: ImageContext,
model: Option<&Arc<dyn language_model::LanguageModel>>,
cx: &App,
) -> AddedContext {
let (name, parent, icon_path) = if let Some(full_path) = context.full_path.as_ref() {
let full_path_string: SharedString = full_path.to_string_lossy().into_owned().into();
let (name, parent) =
extract_file_name_and_directory_from_full_path(full_path, &full_path_string);
let icon_path = FileIcons::get_icon(&full_path, cx);
(name, parent, icon_path)
} else {
("Image".into(), None, None)
};
let status = match context.status(model) {
ImageStatus::Loading => ContextStatus::Loading {
message: "Loading…".into(),
},
ImageStatus::Error => ContextStatus::Error {
message: "Failed to load Image".into(),
},
ImageStatus::Warning => ContextStatus::Warning {
message: format!(
"{} doesn't support attaching Images as Context",
model.map(|m| m.name().0).unwrap_or_else(|| "Model".into())
)
.into(),
},
ImageStatus::Ready => ContextStatus::Ready,
};
AddedContext { AddedContext {
kind: ContextKind::Image, kind: ContextKind::Image,
name, name: "Image".into(),
parent, parent: None,
tooltip: None, tooltip: None,
icon_path, icon_path: None,
status, status: match context.status() {
ImageStatus::Loading => ContextStatus::Loading {
message: "Loading…".into(),
},
ImageStatus::Error => ContextStatus::Error {
message: "Failed to load image".into(),
},
ImageStatus::Ready => ContextStatus::Ready,
},
render_hover: Some(Rc::new({ render_hover: Some(Rc::new({
let image = context.original_image.clone(); let image = context.original_image.clone();
move |_, cx| { move |_, cx| {
@@ -663,22 +639,6 @@ impl AddedContext {
} }
} }
fn extract_file_name_and_directory_from_full_path(
path: &Path,
name_fallback: &SharedString,
) -> (SharedString, Option<SharedString>) {
let name = path
.file_name()
.map(|n| n.to_string_lossy().into_owned().into())
.unwrap_or_else(|| name_fallback.clone());
let parent = path
.parent()
.and_then(|p| p.file_name())
.map(|n| n.to_string_lossy().into_owned().into());
(name, parent)
}
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
struct ContextFileExcerpt { struct ContextFileExcerpt {
pub file_name_and_range: SharedString, pub file_name_and_range: SharedString,
@@ -805,52 +765,37 @@ impl Component for AddedContext {
let mut next_context_id = ContextId::zero(); let mut next_context_id = ContextId::zero();
let image_ready = ( let image_ready = (
"Ready", "Ready",
AddedContext::image( AddedContext::image(ImageContext {
ImageContext { context_id: next_context_id.post_inc(),
context_id: next_context_id.post_inc(), project_path: None,
project_path: None, original_image: Arc::new(Image::empty()),
full_path: None, image_task: Task::ready(Some(LanguageModelImage::empty())).shared(),
original_image: Arc::new(Image::empty()), }),
image_task: Task::ready(Some(LanguageModelImage::empty())).shared(),
},
None,
cx,
),
); );
let image_loading = ( let image_loading = (
"Loading", "Loading",
AddedContext::image( AddedContext::image(ImageContext {
ImageContext { context_id: next_context_id.post_inc(),
context_id: next_context_id.post_inc(), project_path: None,
project_path: None, original_image: Arc::new(Image::empty()),
full_path: None, image_task: cx
original_image: Arc::new(Image::empty()), .background_spawn(async move {
image_task: cx smol::Timer::after(Duration::from_secs(60 * 5)).await;
.background_spawn(async move { Some(LanguageModelImage::empty())
smol::Timer::after(Duration::from_secs(60 * 5)).await; })
Some(LanguageModelImage::empty()) .shared(),
}) }),
.shared(),
},
None,
cx,
),
); );
let image_error = ( let image_error = (
"Error", "Error",
AddedContext::image( AddedContext::image(ImageContext {
ImageContext { context_id: next_context_id.post_inc(),
context_id: next_context_id.post_inc(), project_path: None,
project_path: None, original_image: Arc::new(Image::empty()),
full_path: None, image_task: Task::ready(None).shared(),
original_image: Arc::new(Image::empty()), }),
image_task: Task::ready(None).shared(),
},
None,
cx,
),
); );
Some( Some(
@@ -870,60 +815,3 @@ impl Component for AddedContext {
) )
} }
} }
#[cfg(test)]
mod tests {
use super::*;
use gpui::App;
use language_model::{LanguageModel, fake_provider::FakeLanguageModel};
use std::sync::Arc;
#[gpui::test]
fn test_image_context_warning_for_unsupported_model(cx: &mut App) {
let model: Arc<dyn LanguageModel> = Arc::new(FakeLanguageModel::default());
assert!(!model.supports_images());
let image_context = ImageContext {
context_id: ContextId::zero(),
project_path: None,
original_image: Arc::new(Image::empty()),
image_task: Task::ready(Some(LanguageModelImage::empty())).shared(),
full_path: None,
};
let added_context = AddedContext::image(image_context, Some(&model), cx);
assert!(matches!(
added_context.status,
ContextStatus::Warning { .. }
));
assert!(matches!(added_context.kind, ContextKind::Image));
assert_eq!(added_context.name.as_ref(), "Image");
assert!(added_context.parent.is_none());
assert!(added_context.icon_path.is_none());
}
#[gpui::test]
fn test_image_context_ready_for_no_model(cx: &mut App) {
let image_context = ImageContext {
context_id: ContextId::zero(),
project_path: None,
original_image: Arc::new(Image::empty()),
image_task: Task::ready(Some(LanguageModelImage::empty())).shared(),
full_path: None,
};
let added_context = AddedContext::image(image_context, None, cx);
assert!(
matches!(added_context.status, ContextStatus::Ready),
"Expected ready status when no model provided"
);
assert!(matches!(added_context.kind, ContextKind::Image));
assert_eq!(added_context.name.as_ref(), "Image");
assert!(added_context.parent.is_none());
assert!(added_context.icon_path.is_none());
}
}

View File

@@ -1,6 +1,5 @@
use crate::ToggleBurnMode; use gpui::{Context, IntoElement, Render, Window};
use gpui::{Context, FontWeight, IntoElement, Render, Window}; use ui::{prelude::*, tooltip_container};
use ui::{KeyBinding, prelude::*, tooltip_container};
pub struct MaxModeTooltip { pub struct MaxModeTooltip {
selected: bool, selected: bool,
@@ -19,48 +18,39 @@ impl MaxModeTooltip {
impl Render for MaxModeTooltip { impl Render for MaxModeTooltip {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let (icon, color) = if self.selected { let icon = if self.selected {
(IconName::ZedBurnModeOn, Color::Error) IconName::ZedBurnModeOn
} else { } else {
(IconName::ZedBurnMode, Color::Default) IconName::ZedBurnMode
}; };
let turned_on = h_flex()
.h_4()
.px_1()
.border_1()
.border_color(cx.theme().colors().border)
.bg(cx.theme().colors().text_accent.opacity(0.1))
.rounded_sm()
.child(
Label::new("ON")
.size(LabelSize::XSmall)
.weight(FontWeight::SEMIBOLD)
.color(Color::Accent),
);
let title = h_flex() let title = h_flex()
.gap_1p5() .gap_1()
.child(Icon::new(icon).size(IconSize::Small).color(color)) .child(Icon::new(icon).size(IconSize::Small))
.child(Label::new("Burn Mode")) .child(Label::new("Burn Mode"));
.when(self.selected, |title| title.child(turned_on));
let keybinding = KeyBinding::for_action(&ToggleBurnMode, window, cx)
.map(|kb| kb.size(rems_from_px(12.)));
tooltip_container(window, cx, |this, _, _| { tooltip_container(window, cx, |this, _, _| {
this this.gap_0p5()
.child( .map(|header| if self.selected {
h_flex() header.child(
.justify_between() h_flex()
.child(title) .justify_between()
.children(keybinding) .child(title)
) .child(
h_flex()
.gap_0p5()
.child(Icon::new(IconName::Check).size(IconSize::XSmall).color(Color::Accent))
.child(Label::new("Turned On").size(LabelSize::XSmall).color(Color::Accent))
)
)
} else {
header.child(title)
})
.child( .child(
div() div()
.max_w_64() .max_w_72()
.child( .child(
Label::new("Enables models to use large context windows, unlimited tool calls, and other capabilities for expanded reasoning.") Label::new("Enables models to use large context windows, unlimited tool calls, and other capabilities for expanded reasoning, offering an unfettered agentic experience.")
.size(LabelSize::Small) .size(LabelSize::Small)
.color(Color::Muted) .color(Color::Muted)
) )

View File

@@ -16,6 +16,7 @@ anthropic = { workspace = true, features = ["schemars"] }
anyhow.workspace = true anyhow.workspace = true
collections.workspace = true collections.workspace = true
gpui.workspace = true gpui.workspace = true
indexmap.workspace = true
language_model.workspace = true language_model.workspace = true
lmstudio = { workspace = true, features = ["schemars"] } lmstudio = { workspace = true, features = ["schemars"] }
log.workspace = true log.workspace = true

View File

@@ -17,6 +17,29 @@ pub mod builtin_profiles {
} }
} }
#[derive(Default)]
pub struct GroupedAgentProfiles {
pub builtin: IndexMap<AgentProfileId, AgentProfile>,
pub custom: IndexMap<AgentProfileId, AgentProfile>,
}
impl GroupedAgentProfiles {
pub fn from_settings(settings: &crate::AgentSettings) -> Self {
let mut builtin = IndexMap::default();
let mut custom = IndexMap::default();
for (profile_id, profile) in settings.profiles.clone() {
if builtin_profiles::is_builtin(&profile_id) {
builtin.insert(profile_id, profile);
} else {
custom.insert(profile_id, profile);
}
}
Self { builtin, custom }
}
}
#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize, JsonSchema)] #[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize, JsonSchema)]
pub struct AgentProfileId(pub Arc<str>); pub struct AgentProfileId(pub Arc<str>);
@@ -40,7 +63,7 @@ impl Default for AgentProfileId {
/// A profile for the Zed Agent that controls its behavior. /// A profile for the Zed Agent that controls its behavior.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct AgentProfileSettings { pub struct AgentProfile {
/// The name of the profile. /// The name of the profile.
pub name: SharedString, pub name: SharedString,
pub tools: IndexMap<Arc<str>, bool>, pub tools: IndexMap<Arc<str>, bool>,

View File

@@ -102,7 +102,7 @@ pub struct AgentSettings {
pub using_outdated_settings_version: bool, pub using_outdated_settings_version: bool,
pub default_profile: AgentProfileId, pub default_profile: AgentProfileId,
pub default_view: DefaultView, pub default_view: DefaultView,
pub profiles: IndexMap<AgentProfileId, AgentProfileSettings>, pub profiles: IndexMap<AgentProfileId, AgentProfile>,
pub always_allow_tool_actions: bool, pub always_allow_tool_actions: bool,
pub notify_when_agent_waiting: NotifyWhenAgentWaiting, pub notify_when_agent_waiting: NotifyWhenAgentWaiting,
pub play_sound_when_agent_done: bool, pub play_sound_when_agent_done: bool,
@@ -372,8 +372,6 @@ impl AgentSettingsContent {
None, None,
None, None,
Some(language_model.supports_tools()), Some(language_model.supports_tools()),
Some(language_model.supports_images()),
None,
)), )),
api_url, api_url,
}); });
@@ -531,7 +529,7 @@ impl AgentSettingsContent {
pub fn create_profile( pub fn create_profile(
&mut self, &mut self,
profile_id: AgentProfileId, profile_id: AgentProfileId,
profile_settings: AgentProfileSettings, profile: AgentProfile,
) -> Result<()> { ) -> Result<()> {
self.v2_setting(|settings| { self.v2_setting(|settings| {
let profiles = settings.profiles.get_or_insert_default(); let profiles = settings.profiles.get_or_insert_default();
@@ -542,10 +540,10 @@ impl AgentSettingsContent {
profiles.insert( profiles.insert(
profile_id, profile_id,
AgentProfileContent { AgentProfileContent {
name: profile_settings.name.into(), name: profile.name.into(),
tools: profile_settings.tools, tools: profile.tools,
enable_all_context_servers: Some(profile_settings.enable_all_context_servers), enable_all_context_servers: Some(profile.enable_all_context_servers),
context_servers: profile_settings context_servers: profile
.context_servers .context_servers
.into_iter() .into_iter()
.map(|(server_id, preset)| { .map(|(server_id, preset)| {
@@ -691,15 +689,14 @@ pub struct AgentSettingsContentV2 {
pub enum CompletionMode { pub enum CompletionMode {
#[default] #[default]
Normal, Normal,
#[serde(alias = "max")] Max,
Burn,
} }
impl From<CompletionMode> for zed_llm_client::CompletionMode { impl From<CompletionMode> for zed_llm_client::CompletionMode {
fn from(value: CompletionMode) -> Self { fn from(value: CompletionMode) -> Self {
match value { match value {
CompletionMode::Normal => zed_llm_client::CompletionMode::Normal, CompletionMode::Normal => zed_llm_client::CompletionMode::Normal,
CompletionMode::Burn => zed_llm_client::CompletionMode::Max, CompletionMode::Max => zed_llm_client::CompletionMode::Max,
} }
} }
} }
@@ -730,7 +727,6 @@ impl JsonSchema for LanguageModelProviderSetting {
"zed.dev".into(), "zed.dev".into(),
"copilot_chat".into(), "copilot_chat".into(),
"deepseek".into(), "deepseek".into(),
"openrouter".into(),
"mistral".into(), "mistral".into(),
]), ]),
..Default::default() ..Default::default()
@@ -910,7 +906,7 @@ impl Settings for AgentSettings {
.extend(profiles.into_iter().map(|(id, profile)| { .extend(profiles.into_iter().map(|(id, profile)| {
( (
id, id,
AgentProfileSettings { AgentProfile {
name: profile.name.into(), name: profile.name.into(),
tools: profile.tools, tools: profile.tools,
enable_all_context_servers: profile enable_all_context_servers: profile

View File

@@ -1,5 +1,4 @@
use std::str::FromStr; use std::str::FromStr;
use std::time::Duration;
use anyhow::{Context as _, Result, anyhow}; use anyhow::{Context as _, Result, anyhow};
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
@@ -407,7 +406,6 @@ impl RateLimit {
/// <https://docs.anthropic.com/en/api/rate-limits#response-headers> /// <https://docs.anthropic.com/en/api/rate-limits#response-headers>
#[derive(Debug)] #[derive(Debug)]
pub struct RateLimitInfo { pub struct RateLimitInfo {
pub retry_after: Option<Duration>,
pub requests: Option<RateLimit>, pub requests: Option<RateLimit>,
pub tokens: Option<RateLimit>, pub tokens: Option<RateLimit>,
pub input_tokens: Option<RateLimit>, pub input_tokens: Option<RateLimit>,
@@ -419,11 +417,10 @@ impl RateLimitInfo {
// Check if any rate limit headers exist // Check if any rate limit headers exist
let has_rate_limit_headers = headers let has_rate_limit_headers = headers
.keys() .keys()
.any(|k| k == "retry-after" || k.as_str().starts_with("anthropic-ratelimit-")); .any(|k| k.as_str().starts_with("anthropic-ratelimit-"));
if !has_rate_limit_headers { if !has_rate_limit_headers {
return Self { return Self {
retry_after: None,
requests: None, requests: None,
tokens: None, tokens: None,
input_tokens: None, input_tokens: None,
@@ -432,11 +429,6 @@ impl RateLimitInfo {
} }
Self { Self {
retry_after: headers
.get("retry-after")
.and_then(|v| v.to_str().ok())
.and_then(|v| v.parse::<u64>().ok())
.map(Duration::from_secs),
requests: RateLimit::from_headers("requests", headers).ok(), requests: RateLimit::from_headers("requests", headers).ok(),
tokens: RateLimit::from_headers("tokens", headers).ok(), tokens: RateLimit::from_headers("tokens", headers).ok(),
input_tokens: RateLimit::from_headers("input-tokens", headers).ok(), input_tokens: RateLimit::from_headers("input-tokens", headers).ok(),
@@ -489,8 +481,8 @@ pub async fn stream_completion_with_rate_limit_info(
.send(request) .send(request)
.await .await
.context("failed to send request to Anthropic")?; .context("failed to send request to Anthropic")?;
let rate_limits = RateLimitInfo::from_headers(response.headers());
if response.status().is_success() { if response.status().is_success() {
let rate_limits = RateLimitInfo::from_headers(response.headers());
let reader = BufReader::new(response.into_body()); let reader = BufReader::new(response.into_body());
let stream = reader let stream = reader
.lines() .lines()
@@ -508,8 +500,6 @@ pub async fn stream_completion_with_rate_limit_info(
}) })
.boxed(); .boxed();
Ok((stream, Some(rate_limits))) Ok((stream, Some(rate_limits)))
} else if let Some(retry_after) = rate_limits.retry_after {
Err(AnthropicError::RateLimit(retry_after))
} else { } else {
let mut body = Vec::new(); let mut body = Vec::new();
response response
@@ -779,8 +769,6 @@ pub struct MessageDelta {
#[derive(Error, Debug)] #[derive(Error, Debug)]
pub enum AnthropicError { pub enum AnthropicError {
#[error("rate limit exceeded, retry after {0:?}")]
RateLimit(Duration),
#[error("an error occurred while interacting with the Anthropic API: {error_type}: {message}", error_type = .0.error_type, message = .0.message)] #[error("an error occurred while interacting with the Anthropic API: {error_type}: {message}", error_type = .0.error_type, message = .0.message)]
ApiError(ApiError), ApiError(ApiError),
#[error("{0}")] #[error("{0}")]

View File

@@ -57,10 +57,8 @@ uuid.workspace = true
workspace-hack.workspace = true workspace-hack.workspace = true
workspace.workspace = true workspace.workspace = true
zed_actions.workspace = true zed_actions.workspace = true
zed_llm_client.workspace = true
[dev-dependencies] [dev-dependencies]
indoc.workspace = true
language_model = { workspace = true, features = ["test-support"] } language_model = { workspace = true, features = ["test-support"] }
languages = { workspace = true, features = ["test-support"] } languages = { workspace = true, features = ["test-support"] }
pretty_assertions.workspace = true pretty_assertions.workspace = true

View File

@@ -3,7 +3,6 @@ mod context_editor;
mod context_history; mod context_history;
mod context_store; mod context_store;
pub mod language_model_selector; pub mod language_model_selector;
mod max_mode_tooltip;
mod slash_command; mod slash_command;
mod slash_command_picker; mod slash_command_picker;

View File

@@ -11,7 +11,7 @@ use assistant_slash_commands::FileCommandMetadata;
use client::{self, proto, telemetry::Telemetry}; use client::{self, proto, telemetry::Telemetry};
use clock::ReplicaId; use clock::ReplicaId;
use collections::{HashMap, HashSet}; use collections::{HashMap, HashSet};
use fs::{Fs, RenameOptions}; use fs::{Fs, RemoveOptions};
use futures::{FutureExt, StreamExt, future::Shared}; use futures::{FutureExt, StreamExt, future::Shared};
use gpui::{ use gpui::{
App, AppContext as _, Context, Entity, EventEmitter, RenderImage, SharedString, Subscription, App, AppContext as _, Context, Entity, EventEmitter, RenderImage, SharedString, Subscription,
@@ -29,7 +29,6 @@ use paths::contexts_dir;
use project::Project; use project::Project;
use prompt_store::PromptBuilder; use prompt_store::PromptBuilder;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use settings::Settings;
use smallvec::SmallVec; use smallvec::SmallVec;
use std::{ use std::{
cmp::{Ordering, max}, cmp::{Ordering, max},
@@ -45,7 +44,6 @@ use text::{BufferSnapshot, ToPoint};
use ui::IconName; use ui::IconName;
use util::{ResultExt, TryFutureExt, post_inc}; use util::{ResultExt, TryFutureExt, post_inc};
use uuid::Uuid; use uuid::Uuid;
use zed_llm_client::CompletionIntent;
#[derive(Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord, Serialize, Deserialize)] #[derive(Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
pub struct ContextId(String); pub struct ContextId(String);
@@ -452,10 +450,6 @@ pub enum ContextEvent {
MessagesEdited, MessagesEdited,
SummaryChanged, SummaryChanged,
SummaryGenerated, SummaryGenerated,
PathChanged {
old_path: Option<Arc<Path>>,
new_path: Arc<Path>,
},
StreamedCompletion, StreamedCompletion,
StartedThoughtProcess(Range<language::Anchor>), StartedThoughtProcess(Range<language::Anchor>),
EndedThoughtProcess(language::Anchor), EndedThoughtProcess(language::Anchor),
@@ -688,7 +682,6 @@ pub struct AssistantContext {
language_registry: Arc<LanguageRegistry>, language_registry: Arc<LanguageRegistry>,
project: Option<Entity<Project>>, project: Option<Entity<Project>>,
prompt_builder: Arc<PromptBuilder>, prompt_builder: Arc<PromptBuilder>,
completion_mode: agent_settings::CompletionMode,
} }
trait ContextAnnotation { trait ContextAnnotation {
@@ -725,14 +718,6 @@ impl AssistantContext {
) )
} }
pub fn completion_mode(&self) -> agent_settings::CompletionMode {
self.completion_mode
}
pub fn set_completion_mode(&mut self, completion_mode: agent_settings::CompletionMode) {
self.completion_mode = completion_mode;
}
pub fn new( pub fn new(
id: ContextId, id: ContextId,
replica_id: ReplicaId, replica_id: ReplicaId,
@@ -779,7 +764,6 @@ impl AssistantContext {
pending_cache_warming_task: Task::ready(None), pending_cache_warming_task: Task::ready(None),
_subscriptions: vec![cx.subscribe(&buffer, Self::handle_buffer_event)], _subscriptions: vec![cx.subscribe(&buffer, Self::handle_buffer_event)],
pending_save: Task::ready(Ok(())), pending_save: Task::ready(Ok(())),
completion_mode: AgentSettings::get_global(cx).preferred_completion_mode,
path: None, path: None,
buffer, buffer,
telemetry, telemetry,
@@ -2277,7 +2261,6 @@ impl AssistantContext {
let mut completion_request = LanguageModelRequest { let mut completion_request = LanguageModelRequest {
thread_id: None, thread_id: None,
prompt_id: None, prompt_id: None,
intent: Some(CompletionIntent::UserPrompt),
mode: None, mode: None,
messages: Vec::new(), messages: Vec::new(),
tools: Vec::new(), tools: Vec::new(),
@@ -2338,15 +2321,7 @@ impl AssistantContext {
completion_request.messages.push(request_message); completion_request.messages.push(request_message);
} }
} }
let supports_max_mode = if let Some(model) = model {
model.supports_max_mode()
} else {
false
};
if supports_max_mode {
completion_request.mode = Some(self.completion_mode.into());
}
completion_request completion_request
} }
@@ -2898,34 +2873,22 @@ impl AssistantContext {
} }
fs.create_dir(contexts_dir().as_ref()).await?; fs.create_dir(contexts_dir().as_ref()).await?;
fs.atomic_write(new_path.clone(), serde_json::to_string(&context).unwrap())
// rename before write ensures that only one file exists .await?;
if let Some(old_path) = old_path.as_ref() { if let Some(old_path) = old_path {
if new_path.as_path() != old_path.as_ref() { if new_path.as_path() != old_path.as_ref() {
fs.rename( fs.remove_file(
&old_path, &old_path,
&new_path, RemoveOptions {
RenameOptions { recursive: false,
overwrite: true, ignore_if_not_exists: true,
ignore_if_exists: true,
}, },
) )
.await?; .await?;
} }
} }
// update path before write in case it fails this.update(cx, |this, _| this.path = Some(new_path.into()))?;
this.update(cx, {
let new_path: Arc<Path> = new_path.clone().into();
move |this, cx| {
this.path = Some(new_path.clone());
cx.emit(ContextEvent::PathChanged { old_path, new_path });
}
})
.ok();
fs.atomic_write(new_path, serde_json::to_string(&context).unwrap())
.await?;
} }
Ok(()) Ok(())
@@ -3293,7 +3256,7 @@ impl SavedContextV0_1_0 {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct SavedContextMetadata { pub struct SavedContextMetadata {
pub title: SharedString, pub title: String,
pub path: Arc<Path>, pub path: Arc<Path>,
pub mtime: chrono::DateTime<chrono::Local>, pub mtime: chrono::DateTime<chrono::Local>,
} }

View File

@@ -1210,8 +1210,8 @@ async fn test_summarization(cx: &mut TestAppContext) {
}); });
cx.run_until_parked(); cx.run_until_parked();
fake_model.stream_last_completion_response("Brief"); fake_model.stream_last_completion_response("Brief".into());
fake_model.stream_last_completion_response(" Introduction"); fake_model.stream_last_completion_response(" Introduction".into());
fake_model.end_last_completion_stream(); fake_model.end_last_completion_stream();
cx.run_until_parked(); cx.run_until_parked();
@@ -1274,7 +1274,7 @@ async fn test_thread_summary_error_retry(cx: &mut TestAppContext) {
}); });
cx.run_until_parked(); cx.run_until_parked();
fake_model.stream_last_completion_response("A successful summary"); fake_model.stream_last_completion_response("A successful summary".into());
fake_model.end_last_completion_stream(); fake_model.end_last_completion_stream();
cx.run_until_parked(); cx.run_until_parked();
@@ -1356,7 +1356,7 @@ fn setup_context_editor_with_fake_model(
fn simulate_successful_response(fake_model: &FakeLanguageModel, cx: &mut TestAppContext) { fn simulate_successful_response(fake_model: &FakeLanguageModel, cx: &mut TestAppContext) {
cx.run_until_parked(); cx.run_until_parked();
fake_model.stream_last_completion_response("Assistant response"); fake_model.stream_last_completion_response("Assistant response".into());
fake_model.end_last_completion_stream(); fake_model.end_last_completion_stream();
cx.run_until_parked(); cx.run_until_parked();
} }

View File

@@ -1,10 +1,7 @@
use crate::{ use crate::language_model_selector::{
language_model_selector::{ LanguageModelSelector, LanguageModelSelectorPopoverMenu, ToggleModelSelector,
LanguageModelSelector, ToggleModelSelector, language_model_selector,
},
max_mode_tooltip::MaxModeTooltip,
}; };
use agent_settings::{AgentSettings, CompletionMode}; use agent_settings::AgentSettings;
use anyhow::Result; use anyhow::Result;
use assistant_slash_command::{SlashCommand, SlashCommandOutputSection, SlashCommandWorkingSet}; use assistant_slash_command::{SlashCommand, SlashCommandOutputSection, SlashCommandWorkingSet};
use assistant_slash_commands::{ use assistant_slash_commands::{
@@ -43,7 +40,7 @@ use language_model::{
Role, Role,
}; };
use multi_buffer::MultiBufferRow; use multi_buffer::MultiBufferRow;
use picker::{Picker, popover_menu::PickerPopoverMenu}; use picker::Picker;
use project::{Project, Worktree}; use project::{Project, Worktree};
use project::{ProjectPath, lsp_store::LocalLspAdapterDelegate}; use project::{ProjectPath, lsp_store::LocalLspAdapterDelegate};
use rope::Point; use rope::Point;
@@ -283,7 +280,7 @@ impl ContextEditor {
slash_menu_handle: Default::default(), slash_menu_handle: Default::default(),
dragged_file_worktrees: Vec::new(), dragged_file_worktrees: Vec::new(),
language_model_selector: cx.new(|cx| { language_model_selector: cx.new(|cx| {
language_model_selector( LanguageModelSelector::new(
|cx| LanguageModelRegistry::read_global(cx).default_model(), |cx| LanguageModelRegistry::read_global(cx).default_model(),
move |model, cx| { move |model, cx| {
update_settings_file::<AgentSettings>( update_settings_file::<AgentSettings>(
@@ -580,7 +577,6 @@ impl ContextEditor {
}); });
} }
ContextEvent::SummaryGenerated => {} ContextEvent::SummaryGenerated => {}
ContextEvent::PathChanged { .. } => {}
ContextEvent::StartedThoughtProcess(range) => { ContextEvent::StartedThoughtProcess(range) => {
let creases = self.insert_thought_process_output_sections( let creases = self.insert_thought_process_output_sections(
[( [(
@@ -1647,35 +1643,34 @@ impl ContextEditor {
let context = self.context.read(cx); let context = self.context.read(cx);
let mut text = String::new(); let mut text = String::new();
for message in context.messages(cx) {
// If selection is empty, we want to copy the entire line if message.offset_range.start >= selection.range().end {
if selection.range().is_empty() { break;
let snapshot = context.buffer().read(cx).snapshot(); } else if message.offset_range.end >= selection.range().start {
let point = snapshot.offset_to_point(selection.range().start); let range = cmp::max(message.offset_range.start, selection.range().start)
selection.start = snapshot.point_to_offset(Point::new(point.row, 0)); ..cmp::min(message.offset_range.end, selection.range().end);
selection.end = snapshot if range.is_empty() {
.point_to_offset(cmp::min(Point::new(point.row + 1, 0), snapshot.max_point())); let snapshot = context.buffer().read(cx).snapshot();
for chunk in context.buffer().read(cx).text_for_range(selection.range()) { let point = snapshot.offset_to_point(range.start);
text.push_str(chunk); selection.start = snapshot.point_to_offset(Point::new(point.row, 0));
} selection.end = snapshot.point_to_offset(cmp::min(
} else { Point::new(point.row + 1, 0),
for message in context.messages(cx) { snapshot.max_point(),
if message.offset_range.start >= selection.range().end { ));
break; for chunk in context.buffer().read(cx).text_for_range(selection.range()) {
} else if message.offset_range.end >= selection.range().start { text.push_str(chunk);
let range = cmp::max(message.offset_range.start, selection.range().start) }
..cmp::min(message.offset_range.end, selection.range().end); } else {
if !range.is_empty() { for chunk in context.buffer().read(cx).text_for_range(range) {
for chunk in context.buffer().read(cx).text_for_range(range) { text.push_str(chunk);
text.push_str(chunk); }
} if message.offset_range.end < selection.range().end {
if message.offset_range.end < selection.range().end { text.push('\n');
text.push('\n');
}
} }
} }
} }
} }
(text, CopyMetadata { creases }, vec![selection]) (text, CopyMetadata { creases }, vec![selection])
} }
@@ -2013,17 +2008,17 @@ impl ContextEditor {
None => (ButtonStyle::Filled, None), None => (ButtonStyle::Filled, None),
}; };
Button::new("send_button", "Send") ButtonLike::new("send_button")
.label_size(LabelSize::Small)
.disabled(self.sending_disabled(cx)) .disabled(self.sending_disabled(cx))
.style(style) .style(style)
.when_some(tooltip, |button, tooltip| { .when_some(tooltip, |button, tooltip| {
button.tooltip(move |_, _| tooltip.clone()) button.tooltip(move |_, _| tooltip.clone())
}) })
.layer(ElevationIndex::ModalSurface) .layer(ElevationIndex::ModalSurface)
.key_binding( .child(Label::new("Send"))
.children(
KeyBinding::for_action_in(&Assist, &focus_handle, window, cx) KeyBinding::for_action_in(&Assist, &focus_handle, window, cx)
.map(|kb| kb.size(rems_from_px(12.))), .map(|binding| binding.into_any_element()),
) )
.on_click(move |_event, window, cx| { .on_click(move |_event, window, cx| {
focus_handle.dispatch_action(&Assist, window, cx); focus_handle.dispatch_action(&Assist, window, cx);
@@ -2063,50 +2058,7 @@ impl ContextEditor {
) )
} }
fn render_max_mode_toggle(&self, cx: &mut Context<Self>) -> Option<AnyElement> { fn render_language_model_selector(&self, cx: &mut Context<Self>) -> impl IntoElement {
let context = self.context().read(cx);
let active_model = LanguageModelRegistry::read_global(cx)
.default_model()
.map(|default| default.model)?;
if !active_model.supports_max_mode() {
return None;
}
let active_completion_mode = context.completion_mode();
let burn_mode_enabled = active_completion_mode == CompletionMode::Burn;
let icon = if burn_mode_enabled {
IconName::ZedBurnModeOn
} else {
IconName::ZedBurnMode
};
Some(
IconButton::new("burn-mode", icon)
.icon_size(IconSize::Small)
.icon_color(Color::Muted)
.toggle_state(burn_mode_enabled)
.selected_icon_color(Color::Error)
.on_click(cx.listener(move |this, _event, _window, cx| {
this.context().update(cx, |context, _cx| {
context.set_completion_mode(match active_completion_mode {
CompletionMode::Burn => CompletionMode::Normal,
CompletionMode::Normal => CompletionMode::Burn,
});
});
}))
.tooltip(move |_window, cx| {
cx.new(|_| MaxModeTooltip::new().selected(burn_mode_enabled))
.into()
})
.into_any_element(),
)
}
fn render_language_model_selector(
&self,
window: &mut Window,
cx: &mut Context<Self>,
) -> impl IntoElement {
let active_model = LanguageModelRegistry::read_global(cx) let active_model = LanguageModelRegistry::read_global(cx)
.default_model() .default_model()
.map(|default| default.model); .map(|default| default.model);
@@ -2116,7 +2068,7 @@ impl ContextEditor {
None => SharedString::from("No model selected"), None => SharedString::from("No model selected"),
}; };
PickerPopoverMenu::new( LanguageModelSelectorPopoverMenu::new(
self.language_model_selector.clone(), self.language_model_selector.clone(),
ButtonLike::new("active-model") ButtonLike::new("active-model")
.style(ButtonStyle::Subtle) .style(ButtonStyle::Subtle)
@@ -2144,10 +2096,8 @@ impl ContextEditor {
) )
}, },
gpui::Corner::BottomLeft, gpui::Corner::BottomLeft,
cx,
) )
.with_handle(self.language_model_selector_menu_handle.clone()) .with_handle(self.language_model_selector_menu_handle.clone())
.render(window, cx)
} }
fn render_last_error(&self, cx: &mut Context<Self>) -> Option<AnyElement> { fn render_last_error(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
@@ -2553,7 +2503,6 @@ impl Render for ContextEditor {
let provider = LanguageModelRegistry::read_global(cx) let provider = LanguageModelRegistry::read_global(cx)
.default_model() .default_model()
.map(|default| default.provider); .map(|default| default.provider);
let accept_terms = if self.show_accept_terms { let accept_terms = if self.show_accept_terms {
provider.as_ref().and_then(|provider| { provider.as_ref().and_then(|provider| {
provider.render_accept_terms(LanguageModelProviderTosView::PromptEditorPopup, cx) provider.render_accept_terms(LanguageModelProviderTosView::PromptEditorPopup, cx)
@@ -2563,8 +2512,6 @@ impl Render for ContextEditor {
}; };
let language_model_selector = self.language_model_selector_menu_handle.clone(); let language_model_selector = self.language_model_selector_menu_handle.clone();
let max_mode_toggle = self.render_max_mode_toggle(cx);
v_flex() v_flex()
.key_context("ContextEditor") .key_context("ContextEditor")
.capture_action(cx.listener(ContextEditor::cancel)) .capture_action(cx.listener(ContextEditor::cancel))
@@ -2604,28 +2551,31 @@ impl Render for ContextEditor {
}) })
.children(self.render_last_error(cx)) .children(self.render_last_error(cx))
.child( .child(
h_flex() h_flex().w_full().relative().child(
.relative() h_flex()
.py_2() .p_2()
.pl_1p5() .w_full()
.pr_2() .border_t_1()
.w_full() .border_color(cx.theme().colors().border_variant)
.justify_between() .bg(cx.theme().colors().editor_background)
.border_t_1() .child(
.border_color(cx.theme().colors().border_variant) h_flex()
.bg(cx.theme().colors().editor_background) .gap_1()
.child( .child(self.render_inject_context_menu(cx))
h_flex() .child(ui::Divider::vertical())
.gap_0p5() .child(
.child(self.render_inject_context_menu(cx)) div()
.when_some(max_mode_toggle, |this, element| this.child(element)), .pl_0p5()
) .child(self.render_language_model_selector(cx)),
.child( ),
h_flex() )
.gap_1() .child(
.child(self.render_language_model_selector(window, cx)) h_flex()
.child(self.render_send_button(window, cx)), .w_full()
), .justify_end()
.child(self.render_send_button(window, cx)),
),
),
) )
} }
} }
@@ -3266,92 +3216,74 @@ mod tests {
use super::*; use super::*;
use fs::FakeFs; use fs::FakeFs;
use gpui::{App, TestAppContext, VisualTestContext}; use gpui::{App, TestAppContext, VisualTestContext};
use indoc::indoc;
use language::{Buffer, LanguageRegistry}; use language::{Buffer, LanguageRegistry};
use pretty_assertions::assert_eq;
use prompt_store::PromptBuilder; use prompt_store::PromptBuilder;
use text::OffsetRangeExt;
use unindent::Unindent; use unindent::Unindent;
use util::path; use util::path;
#[gpui::test]
async fn test_copy_paste_whole_message(cx: &mut TestAppContext) {
let (context, context_editor, mut cx) = setup_context_editor_text(vec![
(Role::User, "What is the Zed editor?"),
(
Role::Assistant,
"Zed is a modern, high-performance code editor designed from the ground up for speed and collaboration.",
),
(Role::User, ""),
],cx).await;
// Select & Copy whole user message
assert_copy_paste_context_editor(
&context_editor,
message_range(&context, 0, &mut cx),
indoc! {"
What is the Zed editor?
Zed is a modern, high-performance code editor designed from the ground up for speed and collaboration.
What is the Zed editor?
"},
&mut cx,
);
// Select & Copy whole assistant message
assert_copy_paste_context_editor(
&context_editor,
message_range(&context, 1, &mut cx),
indoc! {"
What is the Zed editor?
Zed is a modern, high-performance code editor designed from the ground up for speed and collaboration.
What is the Zed editor?
Zed is a modern, high-performance code editor designed from the ground up for speed and collaboration.
"},
&mut cx,
);
}
#[gpui::test] #[gpui::test]
async fn test_copy_paste_no_selection(cx: &mut TestAppContext) { async fn test_copy_paste_no_selection(cx: &mut TestAppContext) {
let (context, context_editor, mut cx) = setup_context_editor_text( cx.update(init_test);
vec![
(Role::User, "user1"),
(Role::Assistant, "assistant1"),
(Role::Assistant, "assistant2"),
(Role::User, ""),
],
cx,
)
.await;
// Copy and paste first assistant message let fs = FakeFs::new(cx.executor());
let message_2_range = message_range(&context, 1, &mut cx); let registry = Arc::new(LanguageRegistry::test(cx.executor()));
assert_copy_paste_context_editor( let prompt_builder = Arc::new(PromptBuilder::new(None).unwrap());
&context_editor, let context = cx.new(|cx| {
message_2_range.start..message_2_range.start, AssistantContext::local(
indoc! {" registry,
user1 None,
assistant1 None,
assistant2 prompt_builder.clone(),
assistant1 Arc::new(SlashCommandWorkingSet::default()),
"}, cx,
&mut cx, )
); });
let project = Project::test(fs.clone(), [path!("/test").as_ref()], cx).await;
let window = cx.add_window(|window, cx| Workspace::test_new(project.clone(), window, cx));
let workspace = window.root(cx).unwrap();
let cx = &mut VisualTestContext::from_window(*window, cx);
// Copy and cut second assistant message let context_editor = window
let message_3_range = message_range(&context, 2, &mut cx); .update(cx, |_, window, cx| {
assert_copy_paste_context_editor( cx.new(|cx| {
&context_editor, ContextEditor::for_context(
message_3_range.start..message_3_range.start, context,
indoc! {" fs,
user1 workspace.downgrade(),
assistant1 project,
assistant2 None,
assistant1 window,
assistant2 cx,
"}, )
&mut cx, })
); })
.unwrap();
context_editor.update_in(cx, |context_editor, window, cx| {
context_editor.editor.update(cx, |editor, cx| {
editor.set_text("abc\ndef\nghi", window, cx);
editor.move_to_beginning(&Default::default(), window, cx);
})
});
context_editor.update_in(cx, |context_editor, window, cx| {
context_editor.editor.update(cx, |editor, cx| {
editor.copy(&Default::default(), window, cx);
editor.paste(&Default::default(), window, cx);
assert_eq!(editor.text(cx), "abc\nabc\ndef\nghi");
})
});
context_editor.update_in(cx, |context_editor, window, cx| {
context_editor.editor.update(cx, |editor, cx| {
editor.cut(&Default::default(), window, cx);
assert_eq!(editor.text(cx), "abc\ndef\nghi");
editor.paste(&Default::default(), window, cx);
assert_eq!(editor.text(cx), "abc\nabc\ndef\nghi");
})
});
} }
#[gpui::test] #[gpui::test]
@@ -3428,129 +3360,6 @@ mod tests {
} }
} }
async fn setup_context_editor_text(
messages: Vec<(Role, &str)>,
cx: &mut TestAppContext,
) -> (
Entity<AssistantContext>,
Entity<ContextEditor>,
VisualTestContext,
) {
cx.update(init_test);
let fs = FakeFs::new(cx.executor());
let context = create_context_with_messages(messages, cx);
let project = Project::test(fs.clone(), [path!("/test").as_ref()], cx).await;
let window = cx.add_window(|window, cx| Workspace::test_new(project.clone(), window, cx));
let workspace = window.root(cx).unwrap();
let mut cx = VisualTestContext::from_window(*window, cx);
let context_editor = window
.update(&mut cx, |_, window, cx| {
cx.new(|cx| {
let editor = ContextEditor::for_context(
context.clone(),
fs,
workspace.downgrade(),
project,
None,
window,
cx,
);
editor
})
})
.unwrap();
(context, context_editor, cx)
}
fn message_range(
context: &Entity<AssistantContext>,
message_ix: usize,
cx: &mut TestAppContext,
) -> Range<usize> {
context.update(cx, |context, cx| {
context
.messages(cx)
.nth(message_ix)
.unwrap()
.anchor_range
.to_offset(&context.buffer().read(cx).snapshot())
})
}
fn assert_copy_paste_context_editor<T: editor::ToOffset>(
context_editor: &Entity<ContextEditor>,
range: Range<T>,
expected_text: &str,
cx: &mut VisualTestContext,
) {
context_editor.update_in(cx, |context_editor, window, cx| {
context_editor.editor.update(cx, |editor, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([range]));
});
context_editor.copy(&Default::default(), window, cx);
context_editor.editor.update(cx, |editor, cx| {
editor.move_to_end(&Default::default(), window, cx);
});
context_editor.paste(&Default::default(), window, cx);
context_editor.editor.update(cx, |editor, cx| {
assert_eq!(editor.text(cx), expected_text);
});
});
}
fn create_context_with_messages(
mut messages: Vec<(Role, &str)>,
cx: &mut TestAppContext,
) -> Entity<AssistantContext> {
let registry = Arc::new(LanguageRegistry::test(cx.executor()));
let prompt_builder = Arc::new(PromptBuilder::new(None).unwrap());
cx.new(|cx| {
let mut context = AssistantContext::local(
registry,
None,
None,
prompt_builder.clone(),
Arc::new(SlashCommandWorkingSet::default()),
cx,
);
let mut message_1 = context.messages(cx).next().unwrap();
let (role, text) = messages.remove(0);
loop {
if role == message_1.role {
context.buffer().update(cx, |buffer, cx| {
buffer.edit([(message_1.offset_range, text)], None, cx);
});
break;
}
let mut ids = HashSet::default();
ids.insert(message_1.id);
context.cycle_message_roles(ids, cx);
message_1 = context.messages(cx).next().unwrap();
}
let mut last_message_id = message_1.id;
for (role, text) in messages {
context.insert_message_after(last_message_id, role, MessageStatus::Done, cx);
let message = context.messages(cx).last().unwrap();
last_message_id = message.id;
context.buffer().update(cx, |buffer, cx| {
buffer.edit([(message.offset_range, text)], None, cx);
})
}
context
})
}
fn init_test(cx: &mut App) { fn init_test(cx: &mut App) {
let settings_store = SettingsStore::test(cx); let settings_store = SettingsStore::test(cx);
prompt_store::init(cx); prompt_store::init(cx);

View File

@@ -347,6 +347,12 @@ impl ContextStore {
self.contexts_metadata.iter() self.contexts_metadata.iter()
} }
pub fn reverse_chronological_contexts(&self) -> Vec<SavedContextMetadata> {
let mut contexts = self.contexts_metadata.iter().cloned().collect::<Vec<_>>();
contexts.sort_unstable_by_key(|thread| std::cmp::Reverse(thread.mtime));
contexts
}
pub fn create(&mut self, cx: &mut Context<Self>) -> Entity<AssistantContext> { pub fn create(&mut self, cx: &mut Context<Self>) -> Entity<AssistantContext> {
let context = cx.new(|cx| { let context = cx.new(|cx| {
AssistantContext::local( AssistantContext::local(
@@ -612,16 +618,6 @@ impl ContextStore {
ContextEvent::SummaryChanged => { ContextEvent::SummaryChanged => {
self.advertise_contexts(cx); self.advertise_contexts(cx);
} }
ContextEvent::PathChanged { old_path, new_path } => {
if let Some(old_path) = old_path.as_ref() {
for metadata in &mut self.contexts_metadata {
if &metadata.path == old_path {
metadata.path = new_path.clone();
break;
}
}
}
}
ContextEvent::Operation(operation) => { ContextEvent::Operation(operation) => {
let context_id = context.read(cx).id().to_proto(); let context_id = context.read(cx).id().to_proto();
let operation = operation.to_proto(); let operation = operation.to_proto();
@@ -796,7 +792,7 @@ impl ContextStore {
.next() .next()
{ {
contexts.push(SavedContextMetadata { contexts.push(SavedContextMetadata {
title: title.to_string().into(), title: title.to_string(),
path: path.into(), path: path.into(),
mtime: metadata.mtime.timestamp_for_user().into(), mtime: metadata.mtime.timestamp_for_user().into(),
}); });
@@ -813,37 +809,74 @@ impl ContextStore {
} }
fn register_context_server_handlers(&self, cx: &mut Context<Self>) { fn register_context_server_handlers(&self, cx: &mut Context<Self>) {
let context_server_store = self.project.read(cx).context_server_store(); cx.subscribe(
cx.subscribe(&context_server_store, Self::handle_context_server_event) &self.project.read(cx).context_server_store(),
.detach(); Self::handle_context_server_event,
)
// Check for any servers that were already running before the handler was registered .detach();
for server in context_server_store.read(cx).running_servers() {
self.load_context_server_slash_commands(server.id(), context_server_store.clone(), cx);
}
} }
fn handle_context_server_event( fn handle_context_server_event(
&mut self, &mut self,
context_server_store: Entity<ContextServerStore>, context_server_manager: Entity<ContextServerStore>,
event: &project::context_server_store::Event, event: &project::context_server_store::Event,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) { ) {
let slash_command_working_set = self.slash_commands.clone();
match event { match event {
project::context_server_store::Event::ServerStatusChanged { server_id, status } => { project::context_server_store::Event::ServerStatusChanged { server_id, status } => {
match status { match status {
ContextServerStatus::Running => { ContextServerStatus::Running => {
self.load_context_server_slash_commands( if let Some(server) = context_server_manager
server_id.clone(), .read(cx)
context_server_store.clone(), .get_running_server(server_id)
cx, {
); let context_server_manager = context_server_manager.clone();
cx.spawn({
let server = server.clone();
let server_id = server_id.clone();
async move |this, cx| {
let Some(protocol) = server.client() else {
return;
};
if protocol.capable(context_server::protocol::ServerCapability::Prompts) {
if let Some(prompts) = protocol.list_prompts().await.log_err() {
let slash_command_ids = prompts
.into_iter()
.filter(assistant_slash_commands::acceptable_prompt)
.map(|prompt| {
log::info!(
"registering context server command: {:?}",
prompt.name
);
slash_command_working_set.insert(Arc::new(
assistant_slash_commands::ContextServerSlashCommand::new(
context_server_manager.clone(),
server.id(),
prompt,
),
))
})
.collect::<Vec<_>>();
this.update( cx, |this, _cx| {
this.context_server_slash_command_ids
.insert(server_id.clone(), slash_command_ids);
})
.log_err();
}
}
}
})
.detach();
}
} }
ContextServerStatus::Stopped | ContextServerStatus::Error(_) => { ContextServerStatus::Stopped | ContextServerStatus::Error(_) => {
if let Some(slash_command_ids) = if let Some(slash_command_ids) =
self.context_server_slash_command_ids.remove(server_id) self.context_server_slash_command_ids.remove(server_id)
{ {
self.slash_commands.remove(&slash_command_ids); slash_command_working_set.remove(&slash_command_ids);
} }
} }
_ => {} _ => {}
@@ -851,52 +884,4 @@ impl ContextStore {
} }
} }
} }
fn load_context_server_slash_commands(
&self,
server_id: ContextServerId,
context_server_store: Entity<ContextServerStore>,
cx: &mut Context<Self>,
) {
let Some(server) = context_server_store.read(cx).get_running_server(&server_id) else {
return;
};
let slash_command_working_set = self.slash_commands.clone();
cx.spawn(async move |this, cx| {
let Some(protocol) = server.client() else {
return;
};
if protocol.capable(context_server::protocol::ServerCapability::Prompts) {
if let Some(response) = protocol
.request::<context_server::types::requests::PromptsList>(())
.await
.log_err()
{
let slash_command_ids = response
.prompts
.into_iter()
.filter(assistant_slash_commands::acceptable_prompt)
.map(|prompt| {
log::info!("registering context server command: {:?}", prompt.name);
slash_command_working_set.insert(Arc::new(
assistant_slash_commands::ContextServerSlashCommand::new(
context_server_store.clone(),
server.id(),
prompt,
),
))
})
.collect::<Vec<_>>();
this.update(cx, |this, _cx| {
this.context_server_slash_command_ids
.insert(server_id.clone(), slash_command_ids);
})
.log_err();
}
}
})
.detach();
}
} }

View File

@@ -4,7 +4,8 @@ use collections::{HashSet, IndexMap};
use feature_flags::ZedProFeatureFlag; use feature_flags::ZedProFeatureFlag;
use fuzzy::{StringMatch, StringMatchCandidate, match_strings}; use fuzzy::{StringMatch, StringMatchCandidate, match_strings};
use gpui::{ use gpui::{
Action, AnyElement, App, BackgroundExecutor, DismissEvent, Subscription, Task, Action, AnyElement, AnyView, App, BackgroundExecutor, Corner, DismissEvent, Entity,
EventEmitter, FocusHandle, Focusable, Subscription, Task, WeakEntity,
action_with_deprecated_aliases, action_with_deprecated_aliases,
}; };
use language_model::{ use language_model::{
@@ -14,7 +15,7 @@ use language_model::{
use ordered_float::OrderedFloat; use ordered_float::OrderedFloat;
use picker::{Picker, PickerDelegate}; use picker::{Picker, PickerDelegate};
use proto::Plan; use proto::Plan;
use ui::{ListItem, ListItemSpacing, prelude::*}; use ui::{ListItem, ListItemSpacing, PopoverMenu, PopoverMenuHandle, PopoverTrigger, prelude::*};
action_with_deprecated_aliases!( action_with_deprecated_aliases!(
agent, agent,
@@ -30,128 +31,77 @@ const TRY_ZED_PRO_URL: &str = "https://zed.dev/pro";
type OnModelChanged = Arc<dyn Fn(Arc<dyn LanguageModel>, &mut App) + 'static>; type OnModelChanged = Arc<dyn Fn(Arc<dyn LanguageModel>, &mut App) + 'static>;
type GetActiveModel = Arc<dyn Fn(&App) -> Option<ConfiguredModel> + 'static>; type GetActiveModel = Arc<dyn Fn(&App) -> Option<ConfiguredModel> + 'static>;
pub type LanguageModelSelector = Picker<LanguageModelPickerDelegate>; pub struct LanguageModelSelector {
picker: Entity<Picker<LanguageModelPickerDelegate>>,
pub fn language_model_selector(
get_active_model: impl Fn(&App) -> Option<ConfiguredModel> + 'static,
on_model_changed: impl Fn(Arc<dyn LanguageModel>, &mut App) + 'static,
window: &mut Window,
cx: &mut Context<LanguageModelSelector>,
) -> LanguageModelSelector {
let delegate = LanguageModelPickerDelegate::new(get_active_model, on_model_changed, window, cx);
Picker::list(delegate, window, cx)
.show_scrollbar(true)
.width(rems(20.))
.max_height(Some(rems(20.).into()))
}
fn all_models(cx: &App) -> GroupedModels {
let providers = LanguageModelRegistry::global(cx).read(cx).providers();
let recommended = providers
.iter()
.flat_map(|provider| {
provider
.recommended_models(cx)
.into_iter()
.map(|model| ModelInfo {
model,
icon: provider.icon(),
})
})
.collect();
let other = providers
.iter()
.flat_map(|provider| {
provider
.provided_models(cx)
.into_iter()
.map(|model| ModelInfo {
model,
icon: provider.icon(),
})
})
.collect();
GroupedModels::new(other, recommended)
}
#[derive(Clone)]
struct ModelInfo {
model: Arc<dyn LanguageModel>,
icon: IconName,
}
pub struct LanguageModelPickerDelegate {
on_model_changed: OnModelChanged,
get_active_model: GetActiveModel,
all_models: Arc<GroupedModels>,
filtered_entries: Vec<LanguageModelPickerEntry>,
selected_index: usize,
_authenticate_all_providers_task: Task<()>, _authenticate_all_providers_task: Task<()>,
_subscriptions: Vec<Subscription>, _subscriptions: Vec<Subscription>,
} }
impl LanguageModelPickerDelegate { impl LanguageModelSelector {
fn new( pub fn new(
get_active_model: impl Fn(&App) -> Option<ConfiguredModel> + 'static, get_active_model: impl Fn(&App) -> Option<ConfiguredModel> + 'static,
on_model_changed: impl Fn(Arc<dyn LanguageModel>, &mut App) + 'static, on_model_changed: impl Fn(Arc<dyn LanguageModel>, &mut App) + 'static,
window: &mut Window, window: &mut Window,
cx: &mut Context<Picker<Self>>, cx: &mut Context<Self>,
) -> Self { ) -> Self {
let on_model_changed = Arc::new(on_model_changed); let on_model_changed = Arc::new(on_model_changed);
let models = all_models(cx);
let entries = models.entries();
Self { let all_models = Self::all_models(cx);
let entries = all_models.entries();
let delegate = LanguageModelPickerDelegate {
language_model_selector: cx.entity().downgrade(),
on_model_changed: on_model_changed.clone(), on_model_changed: on_model_changed.clone(),
all_models: Arc::new(models), all_models: Arc::new(all_models),
selected_index: Self::get_active_model_index(&entries, get_active_model(cx)), selected_index: Self::get_active_model_index(&entries, get_active_model(cx)),
filtered_entries: entries, filtered_entries: entries,
get_active_model: Arc::new(get_active_model), get_active_model: Arc::new(get_active_model),
};
let picker = cx.new(|cx| {
Picker::list(delegate, window, cx)
.show_scrollbar(true)
.width(rems(20.))
.max_height(Some(rems(20.).into()))
});
let subscription = cx.subscribe(&picker, |_, _, _, cx| cx.emit(DismissEvent));
LanguageModelSelector {
picker,
_authenticate_all_providers_task: Self::authenticate_all_providers(cx), _authenticate_all_providers_task: Self::authenticate_all_providers(cx),
_subscriptions: vec![cx.subscribe_in( _subscriptions: vec![
&LanguageModelRegistry::global(cx), cx.subscribe_in(
window, &LanguageModelRegistry::global(cx),
|picker, _, event, window, cx| { window,
match event { Self::handle_language_model_registry_event,
language_model::Event::ProviderStateChanged ),
| language_model::Event::AddedProvider(_) subscription,
| language_model::Event::RemovedProvider(_) => { ],
let query = picker.query(cx);
picker.delegate.all_models = Arc::new(all_models(cx));
// Update matches will automatically drop the previous task
// if we get a provider event again
picker.update_matches(query, window, cx)
}
_ => {}
}
},
)],
} }
} }
fn get_active_model_index( fn handle_language_model_registry_event(
entries: &[LanguageModelPickerEntry], &mut self,
active_model: Option<ConfiguredModel>, _registry: &Entity<LanguageModelRegistry>,
) -> usize { event: &language_model::Event,
entries window: &mut Window,
.iter() cx: &mut Context<Self>,
.position(|entry| { ) {
if let LanguageModelPickerEntry::Model(model) = entry { match event {
active_model language_model::Event::ProviderStateChanged
.as_ref() | language_model::Event::AddedProvider(_)
.map(|active_model| { | language_model::Event::RemovedProvider(_) => {
active_model.model.id() == model.model.id() self.picker.update(cx, |this, cx| {
&& active_model.provider.id() == model.model.provider_id() let query = this.query(cx);
}) this.delegate.all_models = Arc::new(Self::all_models(cx));
.unwrap_or_default() // Update matches will automatically drop the previous task
} else { // if we get a provider event again
false this.update_matches(query, window, cx)
} });
}) }
.unwrap_or(0) _ => {}
}
} }
/// Authenticates all providers in the [`LanguageModelRegistry`]. /// Authenticates all providers in the [`LanguageModelRegistry`].
@@ -204,9 +154,169 @@ impl LanguageModelPickerDelegate {
}) })
} }
pub fn active_model(&self, cx: &App) -> Option<ConfiguredModel> { fn all_models(cx: &App) -> GroupedModels {
(self.get_active_model)(cx) let mut recommended = Vec::new();
let mut recommended_set = HashSet::default();
for provider in LanguageModelRegistry::global(cx)
.read(cx)
.providers()
.iter()
{
let models = provider.recommended_models(cx);
recommended_set.extend(models.iter().map(|model| (model.provider_id(), model.id())));
recommended.extend(
provider
.recommended_models(cx)
.into_iter()
.map(move |model| ModelInfo {
model: model.clone(),
icon: provider.icon(),
}),
);
}
let other_models = LanguageModelRegistry::global(cx)
.read(cx)
.providers()
.iter()
.map(|provider| {
(
provider.id(),
provider
.provided_models(cx)
.into_iter()
.filter_map(|model| {
let not_included =
!recommended_set.contains(&(model.provider_id(), model.id()));
not_included.then(|| ModelInfo {
model: model.clone(),
icon: provider.icon(),
})
})
.collect::<Vec<_>>(),
)
})
.collect::<IndexMap<_, _>>();
GroupedModels {
recommended,
other: other_models,
}
} }
pub fn active_model(&self, cx: &App) -> Option<ConfiguredModel> {
(self.picker.read(cx).delegate.get_active_model)(cx)
}
fn get_active_model_index(
entries: &[LanguageModelPickerEntry],
active_model: Option<ConfiguredModel>,
) -> usize {
entries
.iter()
.position(|entry| {
if let LanguageModelPickerEntry::Model(model) = entry {
active_model
.as_ref()
.map(|active_model| {
active_model.model.id() == model.model.id()
&& active_model.provider.id() == model.model.provider_id()
})
.unwrap_or_default()
} else {
false
}
})
.unwrap_or(0)
}
}
impl EventEmitter<DismissEvent> for LanguageModelSelector {}
impl Focusable for LanguageModelSelector {
fn focus_handle(&self, cx: &App) -> FocusHandle {
self.picker.focus_handle(cx)
}
}
impl Render for LanguageModelSelector {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
self.picker.clone()
}
}
#[derive(IntoElement)]
pub struct LanguageModelSelectorPopoverMenu<T, TT>
where
T: PopoverTrigger + ButtonCommon,
TT: Fn(&mut Window, &mut App) -> AnyView + 'static,
{
language_model_selector: Entity<LanguageModelSelector>,
trigger: T,
tooltip: TT,
handle: Option<PopoverMenuHandle<LanguageModelSelector>>,
anchor: Corner,
}
impl<T, TT> LanguageModelSelectorPopoverMenu<T, TT>
where
T: PopoverTrigger + ButtonCommon,
TT: Fn(&mut Window, &mut App) -> AnyView + 'static,
{
pub fn new(
language_model_selector: Entity<LanguageModelSelector>,
trigger: T,
tooltip: TT,
anchor: Corner,
) -> Self {
Self {
language_model_selector,
trigger,
tooltip,
handle: None,
anchor,
}
}
pub fn with_handle(mut self, handle: PopoverMenuHandle<LanguageModelSelector>) -> Self {
self.handle = Some(handle);
self
}
}
impl<T, TT> RenderOnce for LanguageModelSelectorPopoverMenu<T, TT>
where
T: PopoverTrigger + ButtonCommon,
TT: Fn(&mut Window, &mut App) -> AnyView + 'static,
{
fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
let language_model_selector = self.language_model_selector.clone();
PopoverMenu::new("model-switcher")
.menu(move |_window, _cx| Some(language_model_selector.clone()))
.trigger_with_tooltip(self.trigger, self.tooltip)
.anchor(self.anchor)
.when_some(self.handle.clone(), |menu, handle| menu.with_handle(handle))
.offset(gpui::Point {
x: px(0.0),
y: px(-2.0),
})
}
}
#[derive(Clone)]
struct ModelInfo {
model: Arc<dyn LanguageModel>,
icon: IconName,
}
pub struct LanguageModelPickerDelegate {
language_model_selector: WeakEntity<LanguageModelSelector>,
on_model_changed: OnModelChanged,
get_active_model: GetActiveModel,
all_models: Arc<GroupedModels>,
filtered_entries: Vec<LanguageModelPickerEntry>,
selected_index: usize,
} }
struct GroupedModels { struct GroupedModels {
@@ -216,14 +326,11 @@ struct GroupedModels {
impl GroupedModels { impl GroupedModels {
pub fn new(other: Vec<ModelInfo>, recommended: Vec<ModelInfo>) -> Self { pub fn new(other: Vec<ModelInfo>, recommended: Vec<ModelInfo>) -> Self {
let recommended_ids = recommended let recommended_ids: HashSet<_> = recommended.iter().map(|info| info.model.id()).collect();
.iter()
.map(|info| (info.model.provider_id(), info.model.id()))
.collect::<HashSet<_>>();
let mut other_by_provider: IndexMap<_, Vec<ModelInfo>> = IndexMap::default(); let mut other_by_provider: IndexMap<_, Vec<ModelInfo>> = IndexMap::default();
for model in other { for model in other {
if recommended_ids.contains(&(model.model.provider_id(), model.model.id())) { if recommended_ids.contains(&model.model.id()) {
continue; continue;
} }
@@ -470,7 +577,9 @@ impl PickerDelegate for LanguageModelPickerDelegate {
} }
fn dismissed(&mut self, _: &mut Window, cx: &mut Context<Picker<Self>>) { fn dismissed(&mut self, _: &mut Window, cx: &mut Context<Picker<Self>>) {
cx.emit(DismissEvent); self.language_model_selector
.update(cx, |_this, cx| cx.emit(DismissEvent))
.ok();
} }
fn render_match( fn render_match(
@@ -682,12 +791,11 @@ mod tests {
_: &AsyncApp, _: &AsyncApp,
) -> BoxFuture< ) -> BoxFuture<
'static, 'static,
Result< http_client::Result<
BoxStream< BoxStream<
'static, 'static,
Result<LanguageModelCompletionEvent, LanguageModelCompletionError>, http_client::Result<LanguageModelCompletionEvent, LanguageModelCompletionError>,
>, >,
LanguageModelCompletionError,
>, >,
> { > {
unimplemented!() unimplemented!()
@@ -809,26 +917,4 @@ mod tests {
// Recommended models should not appear in "other" // Recommended models should not appear in "other"
assert_models_eq(actual_other_models, vec!["zed/gemini", "copilot/o3"]); assert_models_eq(actual_other_models, vec!["zed/gemini", "copilot/o3"]);
} }
#[gpui::test]
fn test_dont_exclude_models_from_other_providers(_cx: &mut TestAppContext) {
let recommended_models = create_models(vec![("zed", "claude")]);
let all_models = create_models(vec![
("zed", "claude"), // Should be filtered out from "other"
("zed", "gemini"),
("copilot", "claude"), // Should not be filtered out from "other"
]);
let grouped_models = GroupedModels::new(all_models, recommended_models);
let actual_other_models = grouped_models
.other
.values()
.flatten()
.cloned()
.collect::<Vec<_>>();
// Recommended models should not appear in "other"
assert_models_eq(actual_other_models, vec!["zed/gemini", "copilot/claude"]);
}
} }

View File

@@ -1,61 +0,0 @@
use gpui::{Context, FontWeight, IntoElement, Render, Window};
use ui::{prelude::*, tooltip_container};
pub struct MaxModeTooltip {
selected: bool,
}
impl MaxModeTooltip {
pub fn new() -> Self {
Self { selected: false }
}
pub fn selected(mut self, selected: bool) -> Self {
self.selected = selected;
self
}
}
impl Render for MaxModeTooltip {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let (icon, color) = if self.selected {
(IconName::ZedBurnModeOn, Color::Error)
} else {
(IconName::ZedBurnMode, Color::Default)
};
let turned_on = h_flex()
.h_4()
.px_1()
.border_1()
.border_color(cx.theme().colors().border)
.bg(cx.theme().colors().text_accent.opacity(0.1))
.rounded_sm()
.child(
Label::new("ON")
.size(LabelSize::XSmall)
.weight(FontWeight::SEMIBOLD)
.color(Color::Accent),
);
let title = h_flex()
.gap_1p5()
.child(Icon::new(icon).size(IconSize::Small).color(color))
.child(Label::new("Burn Mode"))
.when(self.selected, |title| title.child(turned_on));
tooltip_container(window, cx, |this, _, _| {
this
.child(title)
.child(
div()
.max_w_64()
.child(
Label::new("Enables models to use large context windows, unlimited tool calls, and other capabilities for expanded reasoning.")
.size(LabelSize::Small)
.color(Color::Muted)
)
)
})
}
}

View File

@@ -10,7 +10,9 @@ use parking_lot::Mutex;
use project::{CompletionIntent, CompletionSource, lsp_store::CompletionDocumentation}; use project::{CompletionIntent, CompletionSource, lsp_store::CompletionDocumentation};
use rope::Point; use rope::Point;
use std::{ use std::{
cell::RefCell,
ops::Range, ops::Range,
rc::Rc,
sync::{ sync::{
Arc, Arc,
atomic::{AtomicBool, Ordering::SeqCst}, atomic::{AtomicBool, Ordering::SeqCst},
@@ -46,7 +48,7 @@ impl SlashCommandCompletionProvider {
name_range: Range<Anchor>, name_range: Range<Anchor>,
window: &mut Window, window: &mut Window,
cx: &mut App, cx: &mut App,
) -> Task<Result<Vec<project::CompletionResponse>>> { ) -> Task<Result<Option<Vec<project::Completion>>>> {
let slash_commands = self.slash_commands.clone(); let slash_commands = self.slash_commands.clone();
let candidates = slash_commands let candidates = slash_commands
.command_names(cx) .command_names(cx)
@@ -69,27 +71,28 @@ impl SlashCommandCompletionProvider {
.await; .await;
cx.update(|_, cx| { cx.update(|_, cx| {
let completions = matches Some(
.into_iter() matches
.filter_map(|mat| { .into_iter()
let command = slash_commands.command(&mat.string, cx)?; .filter_map(|mat| {
let mut new_text = mat.string.clone(); let command = slash_commands.command(&mat.string, cx)?;
let requires_argument = command.requires_argument(); let mut new_text = mat.string.clone();
let accepts_arguments = command.accepts_arguments(); let requires_argument = command.requires_argument();
if requires_argument || accepts_arguments { let accepts_arguments = command.accepts_arguments();
new_text.push(' '); if requires_argument || accepts_arguments {
} new_text.push(' ');
}
let confirm = let confirm =
editor editor
.clone() .clone()
.zip(workspace.clone()) .zip(workspace.clone())
.map(|(editor, workspace)| { .map(|(editor, workspace)| {
let command_name = mat.string.clone(); let command_name = mat.string.clone();
let command_range = command_range.clone(); let command_range = command_range.clone();
let editor = editor.clone(); let editor = editor.clone();
let workspace = workspace.clone(); let workspace = workspace.clone();
Arc::new( Arc::new(
move |intent: CompletionIntent, move |intent: CompletionIntent,
window: &mut Window, window: &mut Window,
cx: &mut App| { cx: &mut App| {
@@ -115,27 +118,22 @@ impl SlashCommandCompletionProvider {
} }
}, },
) as Arc<_> ) as Arc<_>
}); });
Some(project::Completion {
Some(project::Completion { replace_range: name_range.clone(),
replace_range: name_range.clone(), documentation: Some(CompletionDocumentation::SingleLine(
documentation: Some(CompletionDocumentation::SingleLine( command.description().into(),
command.description().into(), )),
)), new_text,
new_text, label: command.label(cx),
label: command.label(cx), icon_path: None,
icon_path: None, insert_text_mode: None,
insert_text_mode: None, confirm,
confirm, source: CompletionSource::Custom,
source: CompletionSource::Custom, })
}) })
}) .collect(),
.collect(); )
vec![project::CompletionResponse {
completions,
is_incomplete: false,
}]
}) })
}) })
} }
@@ -149,7 +147,7 @@ impl SlashCommandCompletionProvider {
last_argument_range: Range<Anchor>, last_argument_range: Range<Anchor>,
window: &mut Window, window: &mut Window,
cx: &mut App, cx: &mut App,
) -> Task<Result<Vec<project::CompletionResponse>>> { ) -> Task<Result<Option<Vec<project::Completion>>>> {
let new_cancel_flag = Arc::new(AtomicBool::new(false)); let new_cancel_flag = Arc::new(AtomicBool::new(false));
let mut flag = self.cancel_flag.lock(); let mut flag = self.cancel_flag.lock();
flag.store(true, SeqCst); flag.store(true, SeqCst);
@@ -167,27 +165,28 @@ impl SlashCommandCompletionProvider {
let workspace = self.workspace.clone(); let workspace = self.workspace.clone();
let arguments = arguments.to_vec(); let arguments = arguments.to_vec();
cx.background_spawn(async move { cx.background_spawn(async move {
let completions = completions Ok(Some(
.await? completions
.into_iter() .await?
.map(|new_argument| { .into_iter()
let confirm = .map(|new_argument| {
editor let confirm =
.clone() editor
.zip(workspace.clone()) .clone()
.map(|(editor, workspace)| { .zip(workspace.clone())
Arc::new({ .map(|(editor, workspace)| {
let mut completed_arguments = arguments.clone(); Arc::new({
if new_argument.replace_previous_arguments { let mut completed_arguments = arguments.clone();
completed_arguments.clear(); if new_argument.replace_previous_arguments {
} else { completed_arguments.clear();
completed_arguments.pop(); } else {
} completed_arguments.pop();
completed_arguments.push(new_argument.new_text.clone()); }
completed_arguments.push(new_argument.new_text.clone());
let command_range = command_range.clone(); let command_range = command_range.clone();
let command_name = command_name.clone(); let command_name = command_name.clone();
move |intent: CompletionIntent, move |intent: CompletionIntent,
window: &mut Window, window: &mut Window,
cx: &mut App| { cx: &mut App| {
if new_argument.after_completion.run() if new_argument.after_completion.run()
@@ -211,42 +210,34 @@ impl SlashCommandCompletionProvider {
!new_argument.after_completion.run() !new_argument.after_completion.run()
} }
} }
}) as Arc<_> }) as Arc<_>
}); });
let mut new_text = new_argument.new_text.clone(); let mut new_text = new_argument.new_text.clone();
if new_argument.after_completion == AfterCompletion::Continue { if new_argument.after_completion == AfterCompletion::Continue {
new_text.push(' '); new_text.push(' ');
} }
project::Completion { project::Completion {
replace_range: if new_argument.replace_previous_arguments { replace_range: if new_argument.replace_previous_arguments {
argument_range.clone() argument_range.clone()
} else { } else {
last_argument_range.clone() last_argument_range.clone()
}, },
label: new_argument.label, label: new_argument.label,
icon_path: None, icon_path: None,
new_text, new_text,
documentation: None, documentation: None,
confirm, confirm,
insert_text_mode: None, insert_text_mode: None,
source: CompletionSource::Custom, source: CompletionSource::Custom,
} }
}) })
.collect(); .collect(),
))
Ok(vec![project::CompletionResponse {
completions,
// TODO: Could have slash commands indicate whether their completions are incomplete.
is_incomplete: true,
}])
}) })
} else { } else {
Task::ready(Ok(vec![project::CompletionResponse { Task::ready(Ok(Some(Vec::new())))
completions: Vec::new(),
is_incomplete: true,
}]))
} }
} }
} }
@@ -260,7 +251,7 @@ impl CompletionProvider for SlashCommandCompletionProvider {
_: editor::CompletionContext, _: editor::CompletionContext,
window: &mut Window, window: &mut Window,
cx: &mut Context<Editor>, cx: &mut Context<Editor>,
) -> Task<Result<Vec<project::CompletionResponse>>> { ) -> Task<Result<Option<Vec<project::Completion>>>> {
let Some((name, arguments, command_range, last_argument_range)) = let Some((name, arguments, command_range, last_argument_range)) =
buffer.update(cx, |buffer, _cx| { buffer.update(cx, |buffer, _cx| {
let position = buffer_position.to_point(buffer); let position = buffer_position.to_point(buffer);
@@ -274,17 +265,17 @@ impl CompletionProvider for SlashCommandCompletionProvider {
position.row, position.row,
call.arguments.last().map_or(call.name.end, |arg| arg.end) as u32, call.arguments.last().map_or(call.name.end, |arg| arg.end) as u32,
); );
let command_range = buffer.anchor_before(command_range_start) let command_range = buffer.anchor_after(command_range_start)
..buffer.anchor_after(command_range_end); ..buffer.anchor_after(command_range_end);
let name = line[call.name.clone()].to_string(); let name = line[call.name.clone()].to_string();
let (arguments, last_argument_range) = if let Some(argument) = call.arguments.last() let (arguments, last_argument_range) = if let Some(argument) = call.arguments.last()
{ {
let last_arg_start = let last_arg_start =
buffer.anchor_before(Point::new(position.row, argument.start as u32)); buffer.anchor_after(Point::new(position.row, argument.start as u32));
let first_arg_start = call.arguments.first().expect("we have the last element"); let first_arg_start = call.arguments.first().expect("we have the last element");
let first_arg_start = buffer let first_arg_start =
.anchor_before(Point::new(position.row, first_arg_start.start as u32)); buffer.anchor_after(Point::new(position.row, first_arg_start.start as u32));
let arguments = call let arguments = call
.arguments .arguments
.into_iter() .into_iter()
@@ -297,17 +288,14 @@ impl CompletionProvider for SlashCommandCompletionProvider {
) )
} else { } else {
let start = let start =
buffer.anchor_before(Point::new(position.row, call.name.start as u32)); buffer.anchor_after(Point::new(position.row, call.name.start as u32));
(None, start..buffer_position) (None, start..buffer_position)
}; };
Some((name, arguments, command_range, last_argument_range)) Some((name, arguments, command_range, last_argument_range))
}) })
else { else {
return Task::ready(Ok(vec![project::CompletionResponse { return Task::ready(Ok(Some(Vec::new())));
completions: Vec::new(),
is_incomplete: false,
}]));
}; };
if let Some((arguments, argument_range)) = arguments { if let Some((arguments, argument_range)) = arguments {
@@ -325,13 +313,22 @@ impl CompletionProvider for SlashCommandCompletionProvider {
} }
} }
fn resolve_completions(
&self,
_: Entity<Buffer>,
_: Vec<usize>,
_: Rc<RefCell<Box<[project::Completion]>>>,
_: &mut Context<Editor>,
) -> Task<Result<bool>> {
Task::ready(Ok(true))
}
fn is_completion_trigger( fn is_completion_trigger(
&self, &self,
buffer: &Entity<Buffer>, buffer: &Entity<Buffer>,
position: language::Anchor, position: language::Anchor,
_text: &str, _text: &str,
_trigger_in_words: bool, _trigger_in_words: bool,
_menu_is_open: bool,
cx: &mut Context<Editor>, cx: &mut Context<Editor>,
) -> bool { ) -> bool {
let buffer = buffer.read(cx); let buffer = buffer.read(cx);

View File

@@ -86,26 +86,20 @@ impl SlashCommand for ContextServerSlashCommand {
cx.foreground_executor().spawn(async move { cx.foreground_executor().spawn(async move {
let protocol = server.client().context("Context server not initialized")?; let protocol = server.client().context("Context server not initialized")?;
let response = protocol let completion_result = protocol
.request::<context_server::types::requests::CompletionComplete>( .completion(
context_server::types::CompletionCompleteParams { context_server::types::CompletionReference::Prompt(
reference: context_server::types::CompletionReference::Prompt( context_server::types::PromptReference {
context_server::types::PromptReference { r#type: context_server::types::PromptReferenceType::Prompt,
ty: context_server::types::PromptReferenceType::Prompt, name: prompt_name,
name: prompt_name,
},
),
argument: context_server::types::CompletionArgument {
name: arg_name,
value: arg_value,
}, },
meta: None, ),
}, arg_name,
arg_value,
) )
.await?; .await?;
let completions = response let completions = completion_result
.completion
.values .values
.into_iter() .into_iter()
.map(|value| ArgumentCompletion { .map(|value| ArgumentCompletion {
@@ -144,18 +138,10 @@ impl SlashCommand for ContextServerSlashCommand {
if let Some(server) = store.get_running_server(&server_id) { if let Some(server) = store.get_running_server(&server_id) {
cx.foreground_executor().spawn(async move { cx.foreground_executor().spawn(async move {
let protocol = server.client().context("Context server not initialized")?; let protocol = server.client().context("Context server not initialized")?;
let response = protocol let result = protocol.run_prompt(&prompt_name, prompt_args).await?;
.request::<context_server::types::requests::PromptsGet>(
context_server::types::PromptsGetParams {
name: prompt_name.clone(),
arguments: Some(prompt_args),
meta: None,
},
)
.await?;
anyhow::ensure!( anyhow::ensure!(
response result
.messages .messages
.iter() .iter()
.all(|msg| matches!(msg.role, context_server::types::Role::User)), .all(|msg| matches!(msg.role, context_server::types::Role::User)),
@@ -163,7 +149,7 @@ impl SlashCommand for ContextServerSlashCommand {
); );
// Extract text from user messages into a single prompt string // Extract text from user messages into a single prompt string
let mut prompt = response let mut prompt = result
.messages .messages
.into_iter() .into_iter()
.filter_map(|msg| match msg.content { .filter_map(|msg| match msg.content {
@@ -181,7 +167,7 @@ impl SlashCommand for ContextServerSlashCommand {
range: 0..(prompt.len()), range: 0..(prompt.len()),
icon: IconName::ZedAssistant, icon: IconName::ZedAssistant,
label: SharedString::from( label: SharedString::from(
response result
.description .description
.unwrap_or(format!("Result from {}", prompt_name)), .unwrap_or(format!("Result from {}", prompt_name)),
), ),

View File

@@ -29,7 +29,6 @@ serde.workspace = true
serde_json.workspace = true serde_json.workspace = true
text.workspace = true text.workspace = true
util.workspace = true util.workspace = true
watch.workspace = true
workspace.workspace = true workspace.workspace = true
workspace-hack.workspace = true workspace-hack.workspace = true

View File

@@ -1,7 +1,7 @@
use anyhow::{Context as _, Result}; use anyhow::{Context as _, Result};
use buffer_diff::BufferDiff; use buffer_diff::BufferDiff;
use collections::BTreeMap; use collections::BTreeMap;
use futures::{FutureExt, StreamExt, channel::mpsc}; use futures::{StreamExt, channel::mpsc};
use gpui::{App, AppContext, AsyncApp, Context, Entity, Subscription, Task, WeakEntity}; use gpui::{App, AppContext, AsyncApp, Context, Entity, Subscription, Task, WeakEntity};
use language::{Anchor, Buffer, BufferEvent, DiskState, Point, ToPoint}; use language::{Anchor, Buffer, BufferEvent, DiskState, Point, ToPoint};
use project::{Project, ProjectItem, lsp_store::OpenLspBufferHandle}; use project::{Project, ProjectItem, lsp_store::OpenLspBufferHandle};
@@ -92,21 +92,21 @@ impl ActionLog {
let diff = cx.new(|cx| BufferDiff::new(&text_snapshot, cx)); let diff = cx.new(|cx| BufferDiff::new(&text_snapshot, cx));
let (diff_update_tx, diff_update_rx) = mpsc::unbounded(); let (diff_update_tx, diff_update_rx) = mpsc::unbounded();
let diff_base; let diff_base;
let unreviewed_edits; let unreviewed_changes;
if is_created { if is_created {
diff_base = Rope::default(); diff_base = Rope::default();
unreviewed_edits = Patch::new(vec![Edit { unreviewed_changes = Patch::new(vec![Edit {
old: 0..1, old: 0..1,
new: 0..text_snapshot.max_point().row + 1, new: 0..text_snapshot.max_point().row + 1,
}]) }])
} else { } else {
diff_base = buffer.read(cx).as_rope().clone(); diff_base = buffer.read(cx).as_rope().clone();
unreviewed_edits = Patch::default(); unreviewed_changes = Patch::default();
} }
TrackedBuffer { TrackedBuffer {
buffer: buffer.clone(), buffer: buffer.clone(),
diff_base, diff_base,
unreviewed_edits: unreviewed_edits, unreviewed_changes,
snapshot: text_snapshot.clone(), snapshot: text_snapshot.clone(),
status, status,
version: buffer.read(cx).version(), version: buffer.read(cx).version(),
@@ -175,7 +175,7 @@ impl ActionLog {
.map_or(false, |file| file.disk_state() != DiskState::Deleted) .map_or(false, |file| file.disk_state() != DiskState::Deleted)
{ {
// If the buffer had been deleted by a tool, but it got // If the buffer had been deleted by a tool, but it got
// resurrected externally, we want to clear the edits we // resurrected externally, we want to clear the changes we
// were tracking and reset the buffer's state. // were tracking and reset the buffer's state.
self.tracked_buffers.remove(&buffer); self.tracked_buffers.remove(&buffer);
self.track_buffer_internal(buffer, false, cx); self.track_buffer_internal(buffer, false, cx);
@@ -188,274 +188,108 @@ impl ActionLog {
async fn maintain_diff( async fn maintain_diff(
this: WeakEntity<Self>, this: WeakEntity<Self>,
buffer: Entity<Buffer>, buffer: Entity<Buffer>,
mut buffer_updates: mpsc::UnboundedReceiver<(ChangeAuthor, text::BufferSnapshot)>, mut diff_update: mpsc::UnboundedReceiver<(ChangeAuthor, text::BufferSnapshot)>,
cx: &mut AsyncApp, cx: &mut AsyncApp,
) -> Result<()> { ) -> Result<()> {
let git_store = this.read_with(cx, |this, cx| this.project.read(cx).git_store().clone())?; while let Some((author, buffer_snapshot)) = diff_update.next().await {
let git_diff = this let (rebase, diff, language, language_registry) =
.update(cx, |this, cx| { this.read_with(cx, |this, cx| {
this.project.update(cx, |project, cx| { let tracked_buffer = this
project.open_uncommitted_diff(buffer.clone(), cx) .tracked_buffers
}) .get(&buffer)
})? .context("buffer not tracked")?;
.await
.ok();
let buffer_repo = git_store.read_with(cx, |git_store, cx| {
git_store.repository_and_path_for_buffer_id(buffer.read(cx).remote_id(), cx)
})?;
let (mut git_diff_updates_tx, mut git_diff_updates_rx) = watch::channel(()); let rebase = cx.background_spawn({
let _repo_subscription = let mut base_text = tracked_buffer.diff_base.clone();
if let Some((git_diff, (buffer_repo, _))) = git_diff.as_ref().zip(buffer_repo) { let old_snapshot = tracked_buffer.snapshot.clone();
cx.update(|cx| { let new_snapshot = buffer_snapshot.clone();
let mut old_head = buffer_repo.read(cx).head_commit.clone(); let unreviewed_changes = tracked_buffer.unreviewed_changes.clone();
Some(cx.subscribe(git_diff, move |_, event, cx| match event { async move {
buffer_diff::BufferDiffEvent::DiffChanged { .. } => { let edits = diff_snapshots(&old_snapshot, &new_snapshot);
let new_head = buffer_repo.read(cx).head_commit.clone(); if let ChangeAuthor::User = author {
if new_head != old_head { apply_non_conflicting_edits(
old_head = new_head; &unreviewed_changes,
git_diff_updates_tx.send(()).ok(); edits,
&mut base_text,
new_snapshot.as_rope(),
);
} }
(Arc::new(base_text.to_string()), base_text)
} }
_ => {} });
}))
})?
} else {
None
};
loop { anyhow::Ok((
futures::select_biased! { rebase,
buffer_update = buffer_updates.next() => { tracked_buffer.diff.clone(),
if let Some((author, buffer_snapshot)) = buffer_update { tracked_buffer.buffer.read(cx).language().cloned(),
Self::track_edits(&this, &buffer, author, buffer_snapshot, cx).await?; tracked_buffer.buffer.read(cx).language_registry(),
} else { ))
break; })??;
}
} let (new_base_text, new_diff_base) = rebase.await;
_ = git_diff_updates_rx.changed().fuse() => { let diff_snapshot = BufferDiff::update_diff(
if let Some(git_diff) = git_diff.as_ref() { diff.clone(),
Self::keep_committed_edits(&this, &buffer, &git_diff, cx).await?; buffer_snapshot.clone(),
} Some(new_base_text),
} true,
false,
language,
language_registry,
cx,
)
.await;
let mut unreviewed_changes = Patch::default();
if let Ok(diff_snapshot) = diff_snapshot {
unreviewed_changes = cx
.background_spawn({
let diff_snapshot = diff_snapshot.clone();
let buffer_snapshot = buffer_snapshot.clone();
let new_diff_base = new_diff_base.clone();
async move {
let mut unreviewed_changes = Patch::default();
for hunk in diff_snapshot.hunks_intersecting_range(
Anchor::MIN..Anchor::MAX,
&buffer_snapshot,
) {
let old_range = new_diff_base
.offset_to_point(hunk.diff_base_byte_range.start)
..new_diff_base.offset_to_point(hunk.diff_base_byte_range.end);
let new_range = hunk.range.start..hunk.range.end;
unreviewed_changes.push(point_to_row_edit(
Edit {
old: old_range,
new: new_range,
},
&new_diff_base,
&buffer_snapshot.as_rope(),
));
}
unreviewed_changes
}
})
.await;
diff.update(cx, |diff, cx| {
diff.set_snapshot(diff_snapshot, &buffer_snapshot, cx)
})?;
} }
this.update(cx, |this, cx| {
let tracked_buffer = this
.tracked_buffers
.get_mut(&buffer)
.context("buffer not tracked")?;
tracked_buffer.diff_base = new_diff_base;
tracked_buffer.snapshot = buffer_snapshot;
tracked_buffer.unreviewed_changes = unreviewed_changes;
cx.notify();
anyhow::Ok(())
})??;
} }
Ok(()) Ok(())
} }
async fn track_edits(
this: &WeakEntity<ActionLog>,
buffer: &Entity<Buffer>,
author: ChangeAuthor,
buffer_snapshot: text::BufferSnapshot,
cx: &mut AsyncApp,
) -> Result<()> {
let rebase = this.read_with(cx, |this, cx| {
let tracked_buffer = this
.tracked_buffers
.get(buffer)
.context("buffer not tracked")?;
let rebase = cx.background_spawn({
let mut base_text = tracked_buffer.diff_base.clone();
let old_snapshot = tracked_buffer.snapshot.clone();
let new_snapshot = buffer_snapshot.clone();
let unreviewed_edits = tracked_buffer.unreviewed_edits.clone();
async move {
let edits = diff_snapshots(&old_snapshot, &new_snapshot);
if let ChangeAuthor::User = author {
apply_non_conflicting_edits(
&unreviewed_edits,
edits,
&mut base_text,
new_snapshot.as_rope(),
);
}
(Arc::new(base_text.to_string()), base_text)
}
});
anyhow::Ok(rebase)
})??;
let (new_base_text, new_diff_base) = rebase.await;
Self::update_diff(
this,
buffer,
buffer_snapshot,
new_base_text,
new_diff_base,
cx,
)
.await
}
async fn keep_committed_edits(
this: &WeakEntity<ActionLog>,
buffer: &Entity<Buffer>,
git_diff: &Entity<BufferDiff>,
cx: &mut AsyncApp,
) -> Result<()> {
let buffer_snapshot = this.read_with(cx, |this, _cx| {
let tracked_buffer = this
.tracked_buffers
.get(buffer)
.context("buffer not tracked")?;
anyhow::Ok(tracked_buffer.snapshot.clone())
})??;
let (new_base_text, new_diff_base) = this
.read_with(cx, |this, cx| {
let tracked_buffer = this
.tracked_buffers
.get(buffer)
.context("buffer not tracked")?;
let old_unreviewed_edits = tracked_buffer.unreviewed_edits.clone();
let agent_diff_base = tracked_buffer.diff_base.clone();
let git_diff_base = git_diff.read(cx).base_text().as_rope().clone();
let buffer_text = tracked_buffer.snapshot.as_rope().clone();
anyhow::Ok(cx.background_spawn(async move {
let mut old_unreviewed_edits = old_unreviewed_edits.into_iter().peekable();
let committed_edits = language::line_diff(
&agent_diff_base.to_string(),
&git_diff_base.to_string(),
)
.into_iter()
.map(|(old, new)| Edit { old, new });
let mut new_agent_diff_base = agent_diff_base.clone();
let mut row_delta = 0i32;
for committed in committed_edits {
while let Some(unreviewed) = old_unreviewed_edits.peek() {
// If the committed edit matches the unreviewed
// edit, assume the user wants to keep it.
if committed.old == unreviewed.old {
let unreviewed_new =
buffer_text.slice_rows(unreviewed.new.clone()).to_string();
let committed_new =
git_diff_base.slice_rows(committed.new.clone()).to_string();
if unreviewed_new == committed_new {
let old_byte_start =
new_agent_diff_base.point_to_offset(Point::new(
(unreviewed.old.start as i32 + row_delta) as u32,
0,
));
let old_byte_end =
new_agent_diff_base.point_to_offset(cmp::min(
Point::new(
(unreviewed.old.end as i32 + row_delta) as u32,
0,
),
new_agent_diff_base.max_point(),
));
new_agent_diff_base
.replace(old_byte_start..old_byte_end, &unreviewed_new);
row_delta +=
unreviewed.new_len() as i32 - unreviewed.old_len() as i32;
}
} else if unreviewed.old.start >= committed.old.end {
break;
}
old_unreviewed_edits.next().unwrap();
}
}
(
Arc::new(new_agent_diff_base.to_string()),
new_agent_diff_base,
)
}))
})??
.await;
Self::update_diff(
this,
buffer,
buffer_snapshot,
new_base_text,
new_diff_base,
cx,
)
.await
}
async fn update_diff(
this: &WeakEntity<ActionLog>,
buffer: &Entity<Buffer>,
buffer_snapshot: text::BufferSnapshot,
new_base_text: Arc<String>,
new_diff_base: Rope,
cx: &mut AsyncApp,
) -> Result<()> {
let (diff, language, language_registry) = this.read_with(cx, |this, cx| {
let tracked_buffer = this
.tracked_buffers
.get(buffer)
.context("buffer not tracked")?;
anyhow::Ok((
tracked_buffer.diff.clone(),
buffer.read(cx).language().cloned(),
buffer.read(cx).language_registry().clone(),
))
})??;
let diff_snapshot = BufferDiff::update_diff(
diff.clone(),
buffer_snapshot.clone(),
Some(new_base_text),
true,
false,
language,
language_registry,
cx,
)
.await;
let mut unreviewed_edits = Patch::default();
if let Ok(diff_snapshot) = diff_snapshot {
unreviewed_edits = cx
.background_spawn({
let diff_snapshot = diff_snapshot.clone();
let buffer_snapshot = buffer_snapshot.clone();
let new_diff_base = new_diff_base.clone();
async move {
let mut unreviewed_edits = Patch::default();
for hunk in diff_snapshot
.hunks_intersecting_range(Anchor::MIN..Anchor::MAX, &buffer_snapshot)
{
let old_range = new_diff_base
.offset_to_point(hunk.diff_base_byte_range.start)
..new_diff_base.offset_to_point(hunk.diff_base_byte_range.end);
let new_range = hunk.range.start..hunk.range.end;
unreviewed_edits.push(point_to_row_edit(
Edit {
old: old_range,
new: new_range,
},
&new_diff_base,
&buffer_snapshot.as_rope(),
));
}
unreviewed_edits
}
})
.await;
diff.update(cx, |diff, cx| {
diff.set_snapshot(diff_snapshot, &buffer_snapshot, cx);
})?;
}
this.update(cx, |this, cx| {
let tracked_buffer = this
.tracked_buffers
.get_mut(buffer)
.context("buffer not tracked")?;
tracked_buffer.diff_base = new_diff_base;
tracked_buffer.snapshot = buffer_snapshot;
tracked_buffer.unreviewed_edits = unreviewed_edits;
cx.notify();
anyhow::Ok(())
})?
}
/// Track a buffer as read, so we can notify the model about user edits. /// Track a buffer as read, so we can notify the model about user edits.
pub fn buffer_read(&mut self, buffer: Entity<Buffer>, cx: &mut Context<Self>) { pub fn buffer_read(&mut self, buffer: Entity<Buffer>, cx: &mut Context<Self>) {
self.track_buffer_internal(buffer, false, cx); self.track_buffer_internal(buffer, false, cx);
@@ -516,7 +350,7 @@ impl ActionLog {
buffer_range.start.to_point(buffer)..buffer_range.end.to_point(buffer); buffer_range.start.to_point(buffer)..buffer_range.end.to_point(buffer);
let mut delta = 0i32; let mut delta = 0i32;
tracked_buffer.unreviewed_edits.retain_mut(|edit| { tracked_buffer.unreviewed_changes.retain_mut(|edit| {
edit.old.start = (edit.old.start as i32 + delta) as u32; edit.old.start = (edit.old.start as i32 + delta) as u32;
edit.old.end = (edit.old.end as i32 + delta) as u32; edit.old.end = (edit.old.end as i32 + delta) as u32;
@@ -581,38 +415,14 @@ impl ActionLog {
self.project self.project
.update(cx, |project, cx| project.save_buffer(buffer.clone(), cx)) .update(cx, |project, cx| project.save_buffer(buffer.clone(), cx))
} else { } else {
// For a file created by AI with no pre-existing content, buffer
// only delete the file if we're certain it contains only AI content .read(cx)
// with no edits from the user. .entry_id(cx)
.and_then(|entry_id| {
let initial_version = tracked_buffer.version.clone(); self.project
let current_version = buffer.read(cx).version(); .update(cx, |project, cx| project.delete_entry(entry_id, false, cx))
})
let current_content = buffer.read(cx).text(); .unwrap_or(Task::ready(Ok(())))
let tracked_content = tracked_buffer.snapshot.text();
let is_ai_only_content =
initial_version == current_version && current_content == tracked_content;
if is_ai_only_content {
buffer
.read(cx)
.entry_id(cx)
.and_then(|entry_id| {
self.project.update(cx, |project, cx| {
project.delete_entry(entry_id, false, cx)
})
})
.unwrap_or(Task::ready(Ok(())))
} else {
// Not sure how to disentangle edits made by the user
// from edits made by the AI at this point.
// For now, preserve both to avoid data loss.
//
// TODO: Better solution (disable "Reject" after user makes some
// edit or find a way to differentiate between AI and user edits)
Task::ready(Ok(()))
}
}; };
self.tracked_buffers.remove(&buffer); self.tracked_buffers.remove(&buffer);
@@ -627,7 +437,7 @@ impl ActionLog {
.project .project
.update(cx, |project, cx| project.save_buffer(buffer.clone(), cx)); .update(cx, |project, cx| project.save_buffer(buffer.clone(), cx));
// Clear all tracked edits for this buffer and start over as if we just read it. // Clear all tracked changes for this buffer and start over as if we just read it.
self.tracked_buffers.remove(&buffer); self.tracked_buffers.remove(&buffer);
self.buffer_read(buffer.clone(), cx); self.buffer_read(buffer.clone(), cx);
cx.notify(); cx.notify();
@@ -643,7 +453,7 @@ impl ActionLog {
.peekable(); .peekable();
let mut edits_to_revert = Vec::new(); let mut edits_to_revert = Vec::new();
for edit in tracked_buffer.unreviewed_edits.edits() { for edit in tracked_buffer.unreviewed_changes.edits() {
let new_range = tracked_buffer let new_range = tracked_buffer
.snapshot .snapshot
.anchor_before(Point::new(edit.new.start, 0)) .anchor_before(Point::new(edit.new.start, 0))
@@ -695,7 +505,7 @@ impl ActionLog {
.retain(|_buffer, tracked_buffer| match tracked_buffer.status { .retain(|_buffer, tracked_buffer| match tracked_buffer.status {
TrackedBufferStatus::Deleted => false, TrackedBufferStatus::Deleted => false,
_ => { _ => {
tracked_buffer.unreviewed_edits.clear(); tracked_buffer.unreviewed_changes.clear();
tracked_buffer.diff_base = tracked_buffer.snapshot.as_rope().clone(); tracked_buffer.diff_base = tracked_buffer.snapshot.as_rope().clone();
tracked_buffer.schedule_diff_update(ChangeAuthor::User, cx); tracked_buffer.schedule_diff_update(ChangeAuthor::User, cx);
true true
@@ -704,11 +514,11 @@ impl ActionLog {
cx.notify(); cx.notify();
} }
/// Returns the set of buffers that contain edits that haven't been reviewed by the user. /// Returns the set of buffers that contain changes that haven't been reviewed by the user.
pub fn changed_buffers(&self, cx: &App) -> BTreeMap<Entity<Buffer>, Entity<BufferDiff>> { pub fn changed_buffers(&self, cx: &App) -> BTreeMap<Entity<Buffer>, Entity<BufferDiff>> {
self.tracked_buffers self.tracked_buffers
.iter() .iter()
.filter(|(_, tracked)| tracked.has_edits(cx)) .filter(|(_, tracked)| tracked.has_changes(cx))
.map(|(buffer, tracked)| (buffer.clone(), tracked.diff.clone())) .map(|(buffer, tracked)| (buffer.clone(), tracked.diff.clone()))
.collect() .collect()
} }
@@ -828,7 +638,11 @@ fn point_to_row_edit(edit: Edit<Point>, old_text: &Rope, new_text: &Rope) -> Edi
old: edit.old.start.row + 1..edit.old.end.row + 1, old: edit.old.start.row + 1..edit.old.end.row + 1,
new: edit.new.start.row + 1..edit.new.end.row + 1, new: edit.new.start.row + 1..edit.new.end.row + 1,
} }
} else if edit.old.start.column == 0 && edit.old.end.column == 0 && edit.new.end.column == 0 { } else if edit.old.start.column == 0
&& edit.old.end.column == 0
&& edit.new.end.column == 0
&& edit.old.end != old_text.max_point()
{
Edit { Edit {
old: edit.old.start.row..edit.old.end.row, old: edit.old.start.row..edit.old.end.row,
new: edit.new.start.row..edit.new.end.row, new: edit.new.start.row..edit.new.end.row,
@@ -856,7 +670,7 @@ enum TrackedBufferStatus {
struct TrackedBuffer { struct TrackedBuffer {
buffer: Entity<Buffer>, buffer: Entity<Buffer>,
diff_base: Rope, diff_base: Rope,
unreviewed_edits: Patch<u32>, unreviewed_changes: Patch<u32>,
status: TrackedBufferStatus, status: TrackedBufferStatus,
version: clock::Global, version: clock::Global,
diff: Entity<BufferDiff>, diff: Entity<BufferDiff>,
@@ -868,7 +682,7 @@ struct TrackedBuffer {
} }
impl TrackedBuffer { impl TrackedBuffer {
fn has_edits(&self, cx: &App) -> bool { fn has_changes(&self, cx: &App) -> bool {
self.diff self.diff
.read(cx) .read(cx)
.hunks(&self.buffer.read(cx), cx) .hunks(&self.buffer.read(cx), cx)
@@ -889,6 +703,8 @@ pub struct ChangedBuffer {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::env;
use super::*; use super::*;
use buffer_diff::DiffHunkStatusKind; use buffer_diff::DiffHunkStatusKind;
use gpui::TestAppContext; use gpui::TestAppContext;
@@ -897,7 +713,6 @@ mod tests {
use rand::prelude::*; use rand::prelude::*;
use serde_json::json; use serde_json::json;
use settings::SettingsStore; use settings::SettingsStore;
use std::env;
use util::{RandomCharIter, path}; use util::{RandomCharIter, path};
#[ctor::ctor] #[ctor::ctor]
@@ -1761,6 +1576,7 @@ mod tests {
project.find_project_path("dir/new_file", cx) project.find_project_path("dir/new_file", cx)
}) })
.unwrap(); .unwrap();
let buffer = project let buffer = project
.update(cx, |project, cx| project.open_buffer(file_path, cx)) .update(cx, |project, cx| project.open_buffer(file_path, cx))
.await .await
@@ -1803,72 +1619,6 @@ mod tests {
assert_eq!(unreviewed_hunks(&action_log, cx), vec![]); assert_eq!(unreviewed_hunks(&action_log, cx), vec![]);
} }
#[gpui::test]
async fn test_reject_created_file_with_user_edits(cx: &mut TestAppContext) {
init_test(cx);
let fs = FakeFs::new(cx.executor());
let project = Project::test(fs.clone(), [path!("/dir").as_ref()], cx).await;
let action_log = cx.new(|_| ActionLog::new(project.clone()));
let file_path = project
.read_with(cx, |project, cx| {
project.find_project_path("dir/new_file", cx)
})
.unwrap();
let buffer = project
.update(cx, |project, cx| project.open_buffer(file_path, cx))
.await
.unwrap();
// AI creates file with initial content
cx.update(|cx| {
action_log.update(cx, |log, cx| log.buffer_created(buffer.clone(), cx));
buffer.update(cx, |buffer, cx| buffer.set_text("ai content", cx));
action_log.update(cx, |log, cx| log.buffer_edited(buffer.clone(), cx));
});
project
.update(cx, |project, cx| project.save_buffer(buffer.clone(), cx))
.await
.unwrap();
cx.run_until_parked();
// User makes additional edits
cx.update(|cx| {
buffer.update(cx, |buffer, cx| {
buffer.edit([(10..10, "\nuser added this line")], None, cx);
});
});
project
.update(cx, |project, cx| project.save_buffer(buffer.clone(), cx))
.await
.unwrap();
assert!(fs.is_file(path!("/dir/new_file").as_ref()).await);
// Reject all
action_log
.update(cx, |log, cx| {
log.reject_edits_in_ranges(
buffer.clone(),
vec![Point::new(0, 0)..Point::new(100, 0)],
cx,
)
})
.await
.unwrap();
cx.run_until_parked();
// File should still contain all the content
assert!(fs.is_file(path!("/dir/new_file").as_ref()).await);
let content = buffer.read_with(cx, |buffer, _| buffer.text());
assert_eq!(content, "ai content\nuser added this line");
}
#[gpui::test(iterations = 100)] #[gpui::test(iterations = 100)]
async fn test_random_diffs(mut rng: StdRng, cx: &mut TestAppContext) { async fn test_random_diffs(mut rng: StdRng, cx: &mut TestAppContext) {
init_test(cx); init_test(cx);
@@ -1912,15 +1662,15 @@ mod tests {
.unwrap(); .unwrap();
} }
_ => { _ => {
let is_agent_edit = rng.gen_bool(0.5); let is_agent_change = rng.gen_bool(0.5);
if is_agent_edit { if is_agent_change {
log::info!("agent edit"); log::info!("agent edit");
} else { } else {
log::info!("user edit"); log::info!("user edit");
} }
cx.update(|cx| { cx.update(|cx| {
buffer.update(cx, |buffer, cx| buffer.randomly_edit(&mut rng, 1, cx)); buffer.update(cx, |buffer, cx| buffer.randomly_edit(&mut rng, 1, cx));
if is_agent_edit { if is_agent_change {
action_log.update(cx, |log, cx| log.buffer_edited(buffer.clone(), cx)); action_log.update(cx, |log, cx| log.buffer_edited(buffer.clone(), cx));
} }
}); });
@@ -1945,7 +1695,7 @@ mod tests {
let tracked_buffer = log.tracked_buffers.get(&buffer).unwrap(); let tracked_buffer = log.tracked_buffers.get(&buffer).unwrap();
let mut old_text = tracked_buffer.diff_base.clone(); let mut old_text = tracked_buffer.diff_base.clone();
let new_text = buffer.read(cx).as_rope(); let new_text = buffer.read(cx).as_rope();
for edit in tracked_buffer.unreviewed_edits.edits() { for edit in tracked_buffer.unreviewed_changes.edits() {
let old_start = old_text.point_to_offset(Point::new(edit.new.start, 0)); let old_start = old_text.point_to_offset(Point::new(edit.new.start, 0));
let old_end = old_text.point_to_offset(cmp::min( let old_end = old_text.point_to_offset(cmp::min(
Point::new(edit.new.start + edit.old_len(), 0), Point::new(edit.new.start + edit.old_len(), 0),
@@ -1961,171 +1711,6 @@ mod tests {
} }
} }
#[gpui::test]
async fn test_keep_edits_on_commit(cx: &mut gpui::TestAppContext) {
init_test(cx);
let fs = FakeFs::new(cx.background_executor.clone());
fs.insert_tree(
path!("/project"),
json!({
".git": {},
"file.txt": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj",
}),
)
.await;
fs.set_head_for_repo(
path!("/project/.git").as_ref(),
&[("file.txt".into(), "a\nb\nc\nd\ne\nf\ng\nh\ni\nj".into())],
"0000000",
);
cx.run_until_parked();
let project = Project::test(fs.clone(), [path!("/project").as_ref()], cx).await;
let action_log = cx.new(|_| ActionLog::new(project.clone()));
let file_path = project
.read_with(cx, |project, cx| {
project.find_project_path(path!("/project/file.txt"), cx)
})
.unwrap();
let buffer = project
.update(cx, |project, cx| project.open_buffer(file_path, cx))
.await
.unwrap();
cx.update(|cx| {
action_log.update(cx, |log, cx| log.buffer_read(buffer.clone(), cx));
buffer.update(cx, |buffer, cx| {
buffer.edit(
[
// Edit at the very start: a -> A
(Point::new(0, 0)..Point::new(0, 1), "A"),
// Deletion in the middle: remove lines d and e
(Point::new(3, 0)..Point::new(5, 0), ""),
// Modification: g -> GGG
(Point::new(6, 0)..Point::new(6, 1), "GGG"),
// Addition: insert new line after h
(Point::new(7, 1)..Point::new(7, 1), "\nNEW"),
// Edit the very last character: j -> J
(Point::new(9, 0)..Point::new(9, 1), "J"),
],
None,
cx,
);
});
action_log.update(cx, |log, cx| log.buffer_edited(buffer.clone(), cx));
});
cx.run_until_parked();
assert_eq!(
unreviewed_hunks(&action_log, cx),
vec![(
buffer.clone(),
vec![
HunkStatus {
range: Point::new(0, 0)..Point::new(1, 0),
diff_status: DiffHunkStatusKind::Modified,
old_text: "a\n".into()
},
HunkStatus {
range: Point::new(3, 0)..Point::new(3, 0),
diff_status: DiffHunkStatusKind::Deleted,
old_text: "d\ne\n".into()
},
HunkStatus {
range: Point::new(4, 0)..Point::new(5, 0),
diff_status: DiffHunkStatusKind::Modified,
old_text: "g\n".into()
},
HunkStatus {
range: Point::new(6, 0)..Point::new(7, 0),
diff_status: DiffHunkStatusKind::Added,
old_text: "".into()
},
HunkStatus {
range: Point::new(8, 0)..Point::new(8, 1),
diff_status: DiffHunkStatusKind::Modified,
old_text: "j".into()
}
]
)]
);
// Simulate a git commit that matches some edits but not others:
// - Accepts the first edit (a -> A)
// - Accepts the deletion (remove d and e)
// - Makes a different change to g (g -> G instead of GGG)
// - Ignores the NEW line addition
// - Ignores the last line edit (j stays as j)
fs.set_head_for_repo(
path!("/project/.git").as_ref(),
&[("file.txt".into(), "A\nb\nc\nf\nG\nh\ni\nj".into())],
"0000001",
);
cx.run_until_parked();
assert_eq!(
unreviewed_hunks(&action_log, cx),
vec![(
buffer.clone(),
vec![
HunkStatus {
range: Point::new(4, 0)..Point::new(5, 0),
diff_status: DiffHunkStatusKind::Modified,
old_text: "g\n".into()
},
HunkStatus {
range: Point::new(6, 0)..Point::new(7, 0),
diff_status: DiffHunkStatusKind::Added,
old_text: "".into()
},
HunkStatus {
range: Point::new(8, 0)..Point::new(8, 1),
diff_status: DiffHunkStatusKind::Modified,
old_text: "j".into()
}
]
)]
);
// Make another commit that accepts the NEW line but with different content
fs.set_head_for_repo(
path!("/project/.git").as_ref(),
&[(
"file.txt".into(),
"A\nb\nc\nf\nGGG\nh\nDIFFERENT\ni\nj".into(),
)],
"0000002",
);
cx.run_until_parked();
assert_eq!(
unreviewed_hunks(&action_log, cx),
vec![(
buffer.clone(),
vec![
HunkStatus {
range: Point::new(6, 0)..Point::new(7, 0),
diff_status: DiffHunkStatusKind::Added,
old_text: "".into()
},
HunkStatus {
range: Point::new(8, 0)..Point::new(8, 1),
diff_status: DiffHunkStatusKind::Modified,
old_text: "j".into()
}
]
)]
);
// Final commit that accepts all remaining edits
fs.set_head_for_repo(
path!("/project/.git").as_ref(),
&[("file.txt".into(), "A\nb\nc\nf\nGGG\nh\nNEW\ni\nJ".into())],
"0000003",
);
cx.run_until_parked();
assert_eq!(unreviewed_hunks(&action_log, cx), vec![]);
}
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
struct HunkStatus { struct HunkStatus {
range: Range<Point>, range: Range<Point>,

View File

@@ -203,6 +203,11 @@ pub trait Tool: 'static + Send + Sync {
/// Returns the name of the tool. /// Returns the name of the tool.
fn name(&self) -> String; fn name(&self) -> String;
/// Returns the name to be displayed in the UI for this tool.
fn ui_name(&self) -> String {
self.name()
}
/// Returns the description of the tool. /// Returns the description of the tool.
fn description(&self) -> String; fn description(&self) -> String;
@@ -214,13 +219,10 @@ pub trait Tool: 'static + Send + Sync {
ToolSource::Native ToolSource::Native
} }
/// Returns true if the tool needs the users's confirmation /// Returns true iff the tool needs the users's confirmation
/// before having permission to run. /// before having permission to run.
fn needs_confirmation(&self, input: &serde_json::Value, cx: &App) -> bool; fn needs_confirmation(&self, input: &serde_json::Value, cx: &App) -> bool;
/// Returns true if the tool may perform edits.
fn may_perform_edits(&self) -> bool;
/// Returns the JSON schema that describes the tool's input. /// Returns the JSON schema that describes the tool's input.
fn input_schema(&self, _: LanguageModelToolSchemaFormat) -> Result<serde_json::Value> { fn input_schema(&self, _: LanguageModelToolSchemaFormat) -> Result<serde_json::Value> {
Ok(serde_json::Value::Object(serde_json::Map::default())) Ok(serde_json::Value::Object(serde_json::Map::default()))

View File

@@ -16,24 +16,11 @@ pub fn adapt_schema_to_format(
} }
match format { match format {
LanguageModelToolSchemaFormat::JsonSchema => preprocess_json_schema(json), LanguageModelToolSchemaFormat::JsonSchema => Ok(()),
LanguageModelToolSchemaFormat::JsonSchemaSubset => adapt_to_json_schema_subset(json), LanguageModelToolSchemaFormat::JsonSchemaSubset => adapt_to_json_schema_subset(json),
} }
} }
fn preprocess_json_schema(json: &mut Value) -> Result<()> {
// `additionalProperties` defaults to `false` unless explicitly specified.
// This prevents models from hallucinating tool parameters.
if let Value::Object(obj) = json {
if let Some(Value::String(type_str)) = obj.get("type") {
if type_str == "object" && !obj.contains_key("additionalProperties") {
obj.insert("additionalProperties".to_string(), Value::Bool(false));
}
}
}
Ok(())
}
/// Tries to adapt the json schema so that it is compatible with https://ai.google.dev/api/caching#Schema /// Tries to adapt the json schema so that it is compatible with https://ai.google.dev/api/caching#Schema
fn adapt_to_json_schema_subset(json: &mut Value) -> Result<()> { fn adapt_to_json_schema_subset(json: &mut Value) -> Result<()> {
if let Value::Object(obj) = json { if let Value::Object(obj) = json {
@@ -46,19 +33,15 @@ fn adapt_to_json_schema_subset(json: &mut Value) -> Result<()> {
); );
} }
const KEYS_TO_REMOVE: [(&str, fn(&Value) -> bool); 5] = [ const KEYS_TO_REMOVE: [&str; 5] = [
("format", |value| value.is_string()), "format",
("additionalProperties", |value| value.is_boolean()), "additionalProperties",
("exclusiveMinimum", |value| value.is_number()), "exclusiveMinimum",
("exclusiveMaximum", |value| value.is_number()), "exclusiveMaximum",
("optional", |value| value.is_boolean()), "optional",
]; ];
for (key, predicate) in KEYS_TO_REMOVE { for key in KEYS_TO_REMOVE {
if let Some(value) = obj.get(key) { obj.remove(key);
if predicate(value) {
obj.remove(key);
}
}
} }
// If a type is not specified for an input parameter, add a default type // If a type is not specified for an input parameter, add a default type
@@ -157,24 +140,6 @@ mod tests {
"type": "integer" "type": "integer"
}) })
); );
// Ensure that we do not remove keys that are actually supported (e.g. "format" can just be used as another property)
let mut json = json!({
"description": "A test field",
"type": "integer",
"format": {},
});
adapt_to_json_schema_subset(&mut json).unwrap();
assert_eq!(
json,
json!({
"description": "A test field",
"type": "integer",
"format": {},
})
);
} }
#[test] #[test]
@@ -272,59 +237,4 @@ mod tests {
assert!(adapt_to_json_schema_subset(&mut json).is_err()); assert!(adapt_to_json_schema_subset(&mut json).is_err());
} }
#[test]
fn test_preprocess_json_schema_adds_additional_properties() {
let mut json = json!({
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
});
preprocess_json_schema(&mut json).unwrap();
assert_eq!(
json,
json!({
"type": "object",
"properties": {
"name": {
"type": "string"
}
},
"additionalProperties": false
})
);
}
#[test]
fn test_preprocess_json_schema_preserves_additional_properties() {
let mut json = json!({
"type": "object",
"properties": {
"name": {
"type": "string"
}
},
"additionalProperties": true
});
preprocess_json_schema(&mut json).unwrap();
assert_eq!(
json,
json!({
"type": "object",
"properties": {
"name": {
"type": "string"
}
},
"additionalProperties": true
})
);
}
} }

View File

@@ -1,7 +1,7 @@
use std::sync::Arc; use std::sync::Arc;
use collections::{HashMap, IndexMap}; use collections::{HashMap, HashSet, IndexMap};
use gpui::App; use gpui::{App, Context, EventEmitter};
use crate::{Tool, ToolRegistry, ToolSource}; use crate::{Tool, ToolRegistry, ToolSource};
@@ -13,9 +13,17 @@ pub struct ToolId(usize);
pub struct ToolWorkingSet { pub struct ToolWorkingSet {
context_server_tools_by_id: HashMap<ToolId, Arc<dyn Tool>>, context_server_tools_by_id: HashMap<ToolId, Arc<dyn Tool>>,
context_server_tools_by_name: HashMap<String, Arc<dyn Tool>>, context_server_tools_by_name: HashMap<String, Arc<dyn Tool>>,
enabled_sources: HashSet<ToolSource>,
enabled_tools_by_source: HashMap<ToolSource, HashSet<Arc<str>>>,
next_tool_id: ToolId, next_tool_id: ToolId,
} }
pub enum ToolWorkingSetEvent {
EnabledToolsChanged,
}
impl EventEmitter<ToolWorkingSetEvent> for ToolWorkingSet {}
impl ToolWorkingSet { impl ToolWorkingSet {
pub fn tool(&self, name: &str, cx: &App) -> Option<Arc<dyn Tool>> { pub fn tool(&self, name: &str, cx: &App) -> Option<Arc<dyn Tool>> {
self.context_server_tools_by_name self.context_server_tools_by_name
@@ -49,6 +57,42 @@ impl ToolWorkingSet {
tools_by_source tools_by_source
} }
pub fn enabled_tools(&self, cx: &App) -> Vec<Arc<dyn Tool>> {
let all_tools = self.tools(cx);
all_tools
.into_iter()
.filter(|tool| self.is_enabled(&tool.source(), &tool.name().into()))
.collect()
}
pub fn disable_all_tools(&mut self, cx: &mut Context<Self>) {
self.enabled_tools_by_source.clear();
cx.emit(ToolWorkingSetEvent::EnabledToolsChanged);
}
pub fn enable_source(&mut self, source: ToolSource, cx: &mut Context<Self>) {
self.enabled_sources.insert(source.clone());
let tools_by_source = self.tools_by_source(cx);
if let Some(tools) = tools_by_source.get(&source) {
self.enabled_tools_by_source.insert(
source,
tools
.into_iter()
.map(|tool| tool.name().into())
.collect::<HashSet<_>>(),
);
}
cx.emit(ToolWorkingSetEvent::EnabledToolsChanged);
}
pub fn disable_source(&mut self, source: &ToolSource, cx: &mut Context<Self>) {
self.enabled_sources.remove(source);
self.enabled_tools_by_source.remove(source);
cx.emit(ToolWorkingSetEvent::EnabledToolsChanged);
}
pub fn insert(&mut self, tool: Arc<dyn Tool>) -> ToolId { pub fn insert(&mut self, tool: Arc<dyn Tool>) -> ToolId {
let tool_id = self.next_tool_id; let tool_id = self.next_tool_id;
self.next_tool_id.0 += 1; self.next_tool_id.0 += 1;
@@ -58,6 +102,42 @@ impl ToolWorkingSet {
tool_id tool_id
} }
pub fn is_enabled(&self, source: &ToolSource, name: &Arc<str>) -> bool {
self.enabled_tools_by_source
.get(source)
.map_or(false, |enabled_tools| enabled_tools.contains(name))
}
pub fn is_disabled(&self, source: &ToolSource, name: &Arc<str>) -> bool {
!self.is_enabled(source, name)
}
pub fn enable(
&mut self,
source: ToolSource,
tools_to_enable: &[Arc<str>],
cx: &mut Context<Self>,
) {
self.enabled_tools_by_source
.entry(source)
.or_default()
.extend(tools_to_enable.into_iter().cloned());
cx.emit(ToolWorkingSetEvent::EnabledToolsChanged);
}
pub fn disable(
&mut self,
source: ToolSource,
tools_to_disable: &[Arc<str>],
cx: &mut Context<Self>,
) {
self.enabled_tools_by_source
.entry(source)
.or_default()
.retain(|name| !tools_to_disable.contains(name));
cx.emit(ToolWorkingSetEvent::EnabledToolsChanged);
}
pub fn remove(&mut self, tool_ids_to_remove: &[ToolId]) { pub fn remove(&mut self, tool_ids_to_remove: &[ToolId]) {
self.context_server_tools_by_id self.context_server_tools_by_id
.retain(|id, _| !tool_ids_to_remove.contains(id)); .retain(|id, _| !tool_ids_to_remove.contains(id));

View File

@@ -16,6 +16,7 @@ eval = []
[dependencies] [dependencies]
agent_settings.workspace = true agent_settings.workspace = true
aho-corasick.workspace = true
anyhow.workspace = true anyhow.workspace = true
assistant_tool.workspace = true assistant_tool.workspace = true
buffer_diff.workspace = true buffer_diff.workspace = true
@@ -35,7 +36,6 @@ itertools.workspace = true
language.workspace = true language.workspace = true
language_model.workspace = true language_model.workspace = true
log.workspace = true log.workspace = true
lsp.workspace = true
markdown.workspace = true markdown.workspace = true
open.workspace = true open.workspace = true
paths.workspace = true paths.workspace = true
@@ -57,7 +57,6 @@ terminal_view.workspace = true
theme.workspace = true theme.workspace = true
ui.workspace = true ui.workspace = true
util.workspace = true util.workspace = true
watch.workspace = true
web_search.workspace = true web_search.workspace = true
which.workspace = true which.workspace = true
workspace-hack.workspace = true workspace-hack.workspace = true
@@ -65,7 +64,6 @@ workspace.workspace = true
zed_llm_client.workspace = true zed_llm_client.workspace = true
[dev-dependencies] [dev-dependencies]
lsp = { workspace = true, features = ["test-support"] }
client = { workspace = true, features = ["test-support"] } client = { workspace = true, features = ["test-support"] }
clock = { workspace = true, features = ["test-support"] } clock = { workspace = true, features = ["test-support"] }
collections = { workspace = true, features = ["test-support"] } collections = { workspace = true, features = ["test-support"] }
@@ -80,7 +78,6 @@ rand.workspace = true
pretty_assertions.workspace = true pretty_assertions.workspace = true
reqwest_client.workspace = true reqwest_client.workspace = true
settings = { workspace = true, features = ["test-support"] } settings = { workspace = true, features = ["test-support"] }
smol.workspace = true
task = { workspace = true, features = ["test-support"]} task = { workspace = true, features = ["test-support"]}
tempfile.workspace = true tempfile.workspace = true
theme.workspace = true theme.workspace = true

View File

@@ -37,13 +37,13 @@ use crate::diagnostics_tool::DiagnosticsTool;
use crate::edit_file_tool::EditFileTool; use crate::edit_file_tool::EditFileTool;
use crate::fetch_tool::FetchTool; use crate::fetch_tool::FetchTool;
use crate::find_path_tool::FindPathTool; use crate::find_path_tool::FindPathTool;
use crate::grep_tool::GrepTool;
use crate::list_directory_tool::ListDirectoryTool; use crate::list_directory_tool::ListDirectoryTool;
use crate::now_tool::NowTool; use crate::now_tool::NowTool;
use crate::thinking_tool::ThinkingTool; use crate::thinking_tool::ThinkingTool;
pub use edit_file_tool::{EditFileMode, EditFileToolInput}; pub use edit_file_tool::{EditFileMode, EditFileToolInput};
pub use find_path_tool::FindPathToolInput; pub use find_path_tool::FindPathToolInput;
pub use grep_tool::{GrepTool, GrepToolInput};
pub use open_tool::OpenTool; pub use open_tool::OpenTool;
pub use read_file_tool::{ReadFileTool, ReadFileToolInput}; pub use read_file_tool::{ReadFileTool, ReadFileToolInput};
pub use terminal_tool::TerminalTool; pub use terminal_tool::TerminalTool;
@@ -126,7 +126,6 @@ mod tests {
} }
}, },
"required": ["location"], "required": ["location"],
"additionalProperties": false
}) })
); );
} }

View File

@@ -0,0 +1,9 @@
Invoke multiple other tool calls either sequentially or concurrently.
This tool is useful when you need to perform several operations at once, improving efficiency by reducing the number of back-and-forth interactions needed to complete complex tasks.
If the tool calls are set to be run sequentially, then each tool call within the batch is executed in the order provided. If it's set to run concurrently, then they may run in a different order. Regardless, all tool calls will have the same permissions and context as if they were called individually.
This tool should never be used to run a total of one tool. Instead, just run that one tool directly. You can run batches within batches if desired, which is a way you can mix concurrent and sequential tool call execution.
When it's possible to run tools in a batch, you should run as many as possible in the batch, up to a maximum of 32. For example, don't run multiple consecutive batches of 10 when you could instead run one batch of 30.

View File

@@ -0,0 +1,19 @@
A tool for applying code actions to specific sections of your code. It uses language servers to provide refactoring capabilities similar to what you'd find in an IDE.
This tool can:
- List all available code actions for a selected text range
- Execute a specific code action on that range
- Rename symbols across your codebase. This tool is the preferred way to rename things, and you should always prefer to rename code symbols using this tool rather than using textual find/replace when both are available.
Use this tool when you want to:
- Discover what code actions are available for a piece of code
- Apply automatic fixes and code transformations
- Rename variables, functions, or other symbols consistently throughout your project
- Clean up imports, implement interfaces, or perform other language-specific operations
- If unsure what actions are available, call the tool without specifying an action to get a list
- For common operations, you can directly specify actions like "quickfix.all" or "source.organizeImports"
- For renaming, use the special "textDocument/rename" action and provide the new name in the arguments field
- Be specific with your text range and context to ensure the tool identifies the correct code location
The tool will automatically save any changes it makes to your files.

Some files were not shown because too many files have changed in this diff Show More