Compare commits
108
Commits
v0.7.2
...
44783c5573
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
44783c5573
|
||
|
|
8629c1ca15
|
||
|
|
078e6e3744
|
||
|
|
b908fc20ba
|
||
|
|
058810137c
|
||
|
|
c979041161
|
||
|
|
a606ea552d
|
||
|
|
39a654a79e
|
||
|
|
17d1decce6
|
||
|
|
a45e66c634
|
||
|
|
8c885d9a77
|
||
|
|
6dd1e59815
|
||
|
|
f5085a773a
|
||
|
|
09afdeaf7c
|
||
|
|
0216d84eee
|
||
|
|
320dbf2479
|
||
|
|
6958e9cba8
|
||
|
|
825f9f6bf5
|
||
|
|
863740f916
|
||
|
|
304088bf5c
|
||
|
|
b7599b8acf
|
||
|
|
9b3ae761f3
|
||
|
|
0f7877aafc
|
||
|
|
5843a9ac15
|
||
|
|
4bfaabcb99
|
||
|
|
f16f858074
|
||
|
|
e9a8c01dc4
|
||
|
|
5bbf1b2d71 | ||
|
|
e9c52566b8
|
||
|
|
4c7de650c0
|
||
|
|
6127d964ee
|
||
|
|
8bbbd71fec
|
||
|
|
7f89a80f7e
|
||
|
|
19cca06db6
|
||
|
|
e8df9f119c
|
||
|
|
8abe297bfe
|
||
|
|
4ec6daff30
|
||
|
|
9c1067e544
|
||
|
|
2fe6704fbc | ||
|
|
dd40892ad5 | ||
|
|
ed86b7bfc3 | ||
|
|
f32d72a3f2 | ||
|
|
7b00638476 | ||
|
|
6733b3600f
|
||
|
|
de6010d525
|
||
|
|
9b0e26bade
|
||
|
|
ac40043c00
|
||
|
|
d8eec1d427
|
||
|
|
382916c3ee
|
||
|
|
bc3cc10a7b
|
||
|
|
b91f738209
|
||
|
|
4f0dae9b49
|
||
|
|
deb673ebc9
|
||
|
|
7fc06ad9bc
|
||
|
|
e814b9f62d
|
||
|
|
209fbc9e41
|
||
|
|
5eb1daf18d
|
||
|
|
b8990fdfc2
|
||
|
|
7673799d83
|
||
|
|
ce212fe660
|
||
|
|
f855a45493
|
||
|
|
5be4f45671
|
||
|
|
84ce094677
|
||
|
|
fa7eadd08a
|
||
|
|
af91b89cff
|
||
|
|
d4a6a2fb34
|
||
|
|
8f667886c8
|
||
|
|
898bac3c69
|
||
|
|
fc0b2ada7e
|
||
|
|
09cdb40420
|
||
|
|
9d2e936e7f
|
||
|
|
159afbbc06
|
||
|
|
428d544277
|
||
|
|
531bdfab7f
|
||
|
|
08f6ea5e6c
|
||
|
|
ede0f75a89
|
||
|
|
2ec2aec4c0
|
||
|
|
c2cb4ac433
|
||
|
|
605a9170b0
|
||
|
|
385bd3eda2
|
||
|
|
6c3d96ac83
|
||
|
|
aa1fe7f7aa
|
||
|
|
5e50828108
|
||
|
|
693e2d9672
|
||
|
|
16f324cefc
|
||
|
|
cc50d39ab4
|
||
|
|
fc23b532d9
|
||
|
|
c2d4240138
|
||
|
|
cd1b043b1e
|
||
|
|
81b4f6a76e
|
||
|
|
d48b11dcfa | ||
|
|
86dd922d2c | ||
|
|
9ec20d74a4
|
||
|
|
c78cdef5ae
|
||
|
|
3df590f276
|
||
|
|
91300c16fe
|
||
|
|
52356ead6c
|
||
|
|
ad9fc524d4
|
||
|
|
af50909a89
|
||
|
|
318d9ba1cd
|
||
|
|
45d709f28e
|
||
|
|
9cd074cb9b
|
||
|
|
93eec45473
|
||
|
|
e585e0b049
|
||
|
|
13bfaf9aca
|
||
|
|
040dad05d2 | ||
|
|
1ba38860f2 | ||
|
|
84ec5fe7b8
|
@@ -8,9 +8,9 @@ on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
bump_type:
|
||||
description: "Specify the type of version bump"
|
||||
description: 'Specify the type of version bump'
|
||||
required: true
|
||||
default: "patch"
|
||||
default: 'patch'
|
||||
type: choice
|
||||
options:
|
||||
- patch
|
||||
@@ -46,7 +46,7 @@ jobs:
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: "3.10"
|
||||
python-version: '3.10'
|
||||
|
||||
- name: Install Commitizen
|
||||
run: |
|
||||
@@ -108,17 +108,19 @@ jobs:
|
||||
|
||||
cargo update || true
|
||||
|
||||
sed -i "s|image: 'darkalex17/coyote:v[^']*'|image: 'darkalex17/coyote:v${VERSION}'|" assets/sbx-kit/spec.yaml
|
||||
|
||||
# Git config that helps in Act
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
||||
|
||||
git status --porcelain
|
||||
git diff --name-only -- Cargo.toml Cargo.lock || true
|
||||
git diff --name-only -- Cargo.toml Cargo.lock assets/sbx-kit/spec.yaml || true
|
||||
|
||||
if ! git diff --quiet -- Cargo.toml Cargo.lock; then
|
||||
git add -u -- Cargo.toml Cargo.lock
|
||||
git commit -m "chore: bump Cargo.toml to $VERSION"
|
||||
if ! git diff --quiet -- Cargo.toml Cargo.lock assets/sbx-kit/spec.yaml; then
|
||||
git add -u -- Cargo.toml Cargo.lock assets/sbx-kit/spec.yaml
|
||||
git commit -m "chore: bump Cargo.toml and sandbox image to $VERSION"
|
||||
else
|
||||
echo "No changes to commit (already at $VERSION)"
|
||||
fi
|
||||
@@ -163,28 +165,28 @@ jobs:
|
||||
- target: aarch64-unknown-linux-musl
|
||||
os: ubuntu-latest
|
||||
use-cross: true
|
||||
cargo-flags: ""
|
||||
cargo-flags: ''
|
||||
- target: aarch64-apple-darwin
|
||||
os: macos-latest
|
||||
use-cross: true
|
||||
cargo-flags: ""
|
||||
cargo-flags: ''
|
||||
- target: aarch64-pc-windows-msvc
|
||||
os: windows-latest
|
||||
use-cross: true
|
||||
cargo-flags: ""
|
||||
cargo-flags: ''
|
||||
- target: x86_64-apple-darwin
|
||||
os: macos-latest
|
||||
cargo-flags: ""
|
||||
cargo-flags: ''
|
||||
- target: x86_64-pc-windows-msvc
|
||||
os: windows-latest
|
||||
cargo-flags: ""
|
||||
cargo-flags: ''
|
||||
- target: x86_64-unknown-linux-musl
|
||||
os: ubuntu-latest
|
||||
use-cross: true
|
||||
cargo-flags: ""
|
||||
cargo-flags: ''
|
||||
- target: x86_64-unknown-linux-gnu
|
||||
os: ubuntu-latest
|
||||
cargo-flags: ""
|
||||
cargo-flags: ''
|
||||
|
||||
steps:
|
||||
- name: Check if actor is repository owner
|
||||
@@ -338,7 +340,7 @@ jobs:
|
||||
${{ steps.package.outputs.archive }}
|
||||
${{ steps.package.outputs.sha }}
|
||||
tag_name: v${{ env.RELEASE_VERSION }}
|
||||
name: "v${{ env.RELEASE_VERSION }}"
|
||||
name: 'v${{ env.RELEASE_VERSION }}'
|
||||
body_path: artifacts/changelog.md
|
||||
prerelease: false
|
||||
|
||||
@@ -456,3 +458,63 @@ jobs:
|
||||
if: env.ACT != 'true'
|
||||
with:
|
||||
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
||||
|
||||
publish-sandbox-image:
|
||||
needs: [publish-github-release]
|
||||
name: Publish Sandbox Docker Image
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check if actor is repository owner
|
||||
if: ${{ github.actor != github.repository_owner && env.ACT != 'true' }}
|
||||
run: |
|
||||
echo "You are not authorized to run this workflow."
|
||||
exit 1
|
||||
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
- name: Ensure repository is up-to-date
|
||||
if: env.ACT != 'true'
|
||||
run: |
|
||||
git fetch --all
|
||||
git pull
|
||||
|
||||
- name: Get release artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
merge-multiple: true
|
||||
|
||||
- name: Set version variable
|
||||
run: |
|
||||
version="$(cat artifacts/release-version)"
|
||||
echo "version=$version" >> $GITHUB_ENV
|
||||
|
||||
- name: Validate release environment variables
|
||||
run: |
|
||||
echo "Release version: ${{ env.version }}"
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to Docker Hub
|
||||
if: env.ACT != 'true'
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Push to Docker Hub
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: ${{ env.ACT != 'true' }}
|
||||
tags: darkalex17/coyote:latest, darkalex17/coyote:${{ env.version }}
|
||||
build-args: COYOTE_VERSION=${{ env.version }}
|
||||
|
||||
@@ -1,3 +1,26 @@
|
||||
## v0.7.4 (2026-07-02)
|
||||
|
||||
### Feat
|
||||
|
||||
- Pin specific usql version to sbx kit
|
||||
- recursively take ownership over the copied in coyote config for the sbx
|
||||
- explicitly specify the COYOTE_CONFIG_DIR in the sbx kit
|
||||
- --tail-logs can track log rollovers and incoporates a sleep timer to minimize idle CPU cycles
|
||||
- Added support for log rolling so log files don't just blow up over time
|
||||
|
||||
### Fix
|
||||
|
||||
- Added back in --kit specification for the running of the sbx
|
||||
- sbx isn't copying base files in their respective directories
|
||||
- Update deprecated sbx kit config
|
||||
- Properly chown the coyote config recursively and password file in the sbx
|
||||
|
||||
## v0.7.3 (2026-06-24)
|
||||
|
||||
### Fix
|
||||
|
||||
- apply bootstrapping of functions at startup to fix edge case
|
||||
|
||||
## v0.7.2 (2026-06-19)
|
||||
|
||||
### Fix
|
||||
|
||||
Generated
+161
-115
@@ -141,9 +141,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.102"
|
||||
version = "1.0.103"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"
|
||||
checksum = "2a4385e2e34eb35d6b3efe798b9eb88096925d87726c0798709bf56d9ed84af3"
|
||||
|
||||
[[package]]
|
||||
name = "arbitrary"
|
||||
@@ -174,9 +174,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "arc-swap"
|
||||
version = "1.9.1"
|
||||
version = "1.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a3a1fd6f75306b68087b831f025c712524bcb19aad54e557b1129cfa0a2b207"
|
||||
checksum = "c049c0be4daef0b145cb3555416b3b8ef5b7888a38aea1a3a155801fe7b0810b"
|
||||
dependencies = [
|
||||
"rustversion",
|
||||
]
|
||||
@@ -321,11 +321,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "aws-lc-rs"
|
||||
version = "1.17.0"
|
||||
version = "1.17.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5ec2f1fc3ec205783a5da9a7e6c1509cc69dedf09a1949e412c1e18469326d00"
|
||||
checksum = "4342d8937fc7e5dd9b1c60292261c0670c882a2cd1719cfc11b1af41731e32ad"
|
||||
dependencies = [
|
||||
"aws-lc-sys 0.41.0",
|
||||
"aws-lc-sys 0.42.0",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
@@ -344,14 +344,15 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "aws-lc-sys"
|
||||
version = "0.41.0"
|
||||
version = "0.42.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a2f9779ce85b93ab6170dd940ad0169b5766ff848247aff13bb788b832fe3f4"
|
||||
checksum = "6d9ceb1da931507a12f4fccea479dccd00da1943e1b4ae72d8e502d707361444"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"cmake",
|
||||
"dunce",
|
||||
"fs_extra",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -566,7 +567,7 @@ dependencies = [
|
||||
"hyper-util",
|
||||
"pin-project-lite",
|
||||
"rustls 0.21.12",
|
||||
"rustls 0.23.40",
|
||||
"rustls 0.23.41",
|
||||
"rustls-native-certs",
|
||||
"rustls-pki-types",
|
||||
"tokio",
|
||||
@@ -893,7 +894,7 @@ version = "0.72.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"cexpr",
|
||||
"clang-sys",
|
||||
"itertools 0.13.0",
|
||||
@@ -922,6 +923,12 @@ version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.13.0"
|
||||
@@ -1104,9 +1111,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "chacha20"
|
||||
version = "0.10.0"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6f8d983286843e49675a4b7a2d174efe136dc93a18d69130dd18198a6c167601"
|
||||
checksum = "d524456ba66e72eb8b115ff89e01e497f8e6d11d78b70b1aa13c0fbd97540a81"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures 0.3.0",
|
||||
@@ -1187,14 +1194,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_complete"
|
||||
version = "4.6.5"
|
||||
version = "4.6.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e0a7a9bfdb35811f9e59832f0f05975114d2251b415fb534108e6f34060fd772"
|
||||
checksum = "db8b397918185f0161ff3d6fcaa9e4bfc09b8367caf6e1d4a2848e5477ed027b"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"clap_lex",
|
||||
"is_executable",
|
||||
"shlex 1.3.0",
|
||||
"shlex 2.0.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1315,9 +1322,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "console"
|
||||
version = "0.16.3"
|
||||
version = "0.16.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d64e8af5551369d19cf50138de61f1c42074ab970f74e99be916646777f8fc87"
|
||||
checksum = "4fe5f465a4f6fee88fad41b85d990f84c835335e85b5d9e6e63e0d06d28cba7c"
|
||||
dependencies = [
|
||||
"encode_unicode",
|
||||
"libc",
|
||||
@@ -1402,7 +1409,7 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
||||
|
||||
[[package]]
|
||||
name = "coyote-ai"
|
||||
version = "0.7.2"
|
||||
version = "0.7.4"
|
||||
dependencies = [
|
||||
"ansi_colours",
|
||||
"anyhow",
|
||||
@@ -1414,7 +1421,7 @@ dependencies = [
|
||||
"aws-smithy-types",
|
||||
"base64",
|
||||
"bincode 2.0.1",
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"bm25",
|
||||
"bytes",
|
||||
"chrono",
|
||||
@@ -1448,6 +1455,7 @@ dependencies = [
|
||||
"os_info",
|
||||
"parking_lot",
|
||||
"path-absolutize",
|
||||
"petgraph 0.7.1",
|
||||
"pretty_assertions",
|
||||
"rand 0.10.1",
|
||||
"reedline",
|
||||
@@ -1556,7 +1564,7 @@ version = "0.29.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8b9f2e4c67f833b660cdb0a3523065869fb35570177239812ed4c905aeff87b"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"crossterm_winapi",
|
||||
"derive_more 2.1.1",
|
||||
"document-features",
|
||||
@@ -1727,6 +1735,38 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "defmt"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a6e524506490a1953d237cb87b1cfc1e46f88c18f10a22dfe0f507dc6bfc7f7f"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"defmt-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "defmt-macros"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0a27770e9c8f719a79d8b638281f4d828f77d8fd61e0bd94451b9b85e576a0b"
|
||||
dependencies = [
|
||||
"defmt-parser",
|
||||
"proc-macro-error2",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "defmt-parser"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "10d60334b3b2e7c9d91ef8150abfb6fa4c1c39ebbcf4a81c2e346aad939fee3e"
|
||||
dependencies = [
|
||||
"thiserror 2.0.18",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "der"
|
||||
version = "0.7.10"
|
||||
@@ -1872,7 +1912,7 @@ version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e0e367e4e7da84520dedcac1901e4da967309406d1e51017ae1abfb97adbd38"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"objc2",
|
||||
]
|
||||
|
||||
@@ -2007,9 +2047,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "env_filter"
|
||||
version = "1.0.1"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32e90c2accc4b07a8456ea0debdc2e7587bdd890680d71173a15d4ae604f6eef"
|
||||
checksum = "900d271a03799a1ee8d1ca9b19893b48ca674a9284fefcfb85f05e74ed314217"
|
||||
dependencies = [
|
||||
"log",
|
||||
"regex",
|
||||
@@ -2017,9 +2057,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.11.10"
|
||||
version = "0.11.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0621c04f2196ac3f488dd583365b9c09be011a4ab8b9f37248ffcc8f6198b56a"
|
||||
checksum = "de671bd27a75a797dc9ae289ba1e77276e75e2026408aab65185384e2d5cd3f6"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
@@ -2737,9 +2777,9 @@ checksum = "135b12329e5e3ce057a9f972339ea52bc954fe1e9358ef27f95e89716fbc5424"
|
||||
|
||||
[[package]]
|
||||
name = "hybrid-array"
|
||||
version = "0.4.12"
|
||||
version = "0.4.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9155a582abd142abc056962c29e3ce5ff2ad5469f4246b537ed42c5deba857da"
|
||||
checksum = "818356c5132c1fede50f837ca96afbe78ff42413047f4abb886217845e1b6c8c"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
]
|
||||
@@ -2814,7 +2854,7 @@ dependencies = [
|
||||
"http 1.4.2",
|
||||
"hyper 1.10.1",
|
||||
"hyper-util",
|
||||
"rustls 0.23.40",
|
||||
"rustls 0.23.41",
|
||||
"rustls-native-certs",
|
||||
"tokio",
|
||||
"tokio-rustls 0.26.4",
|
||||
@@ -3031,9 +3071,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "indicatif"
|
||||
version = "0.18.4"
|
||||
version = "0.18.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "25470f23803092da7d239834776d653104d551bc4d7eacaf31e6837854b8e9eb"
|
||||
checksum = "9433806cd6b4ec1aba79c021c7e4c58fb4c3b9977c085062e611ac929998fb0c"
|
||||
dependencies = [
|
||||
"console",
|
||||
"portable-atomic",
|
||||
@@ -3066,7 +3106,7 @@ version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6654738b8024300cf062d04a1c13c10c8e2cea598ec1c47dc9b6641159429756"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"crossterm",
|
||||
"dyn-clone",
|
||||
"fuzzy-matcher",
|
||||
@@ -3151,10 +3191,11 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
||||
|
||||
[[package]]
|
||||
name = "jiff"
|
||||
version = "0.2.28"
|
||||
version = "0.2.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4603d3033e49e2b0e31229fcab20a5d40089c607d975cd9c80551dc69eed9102"
|
||||
checksum = "ccfe6121cbe750cf81efa362d85c0bde7ea298ec43092d3a193baca59cdbd634"
|
||||
dependencies = [
|
||||
"defmt",
|
||||
"jiff-static",
|
||||
"log",
|
||||
"portable-atomic",
|
||||
@@ -3164,9 +3205,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "jiff-static"
|
||||
version = "0.2.28"
|
||||
version = "0.2.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "782d32378dddf207193ac91cefb848ad41abb58195c95168e1291227a0832b47"
|
||||
checksum = "e165e897f662d428f3cd3828a919dbe067c2d42bb1031eede74ef9d27ecdedd2"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -3234,9 +3275,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.102"
|
||||
version = "0.3.103"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "03d04c30968dffe80775bd4d7fb676131cd04a1fb46d2686dbffbaec2d9dfd31"
|
||||
checksum = "53b44bfcdb3f8d5837a46dae1ca9660a837176eee74a28b229bc626816589102"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"futures-util",
|
||||
@@ -3306,9 +3347,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libredox"
|
||||
version = "0.1.17"
|
||||
version = "0.1.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f02ab6bace2054fb888a3c16f990117b579d14a3088e472d63c6011fa185c9d3"
|
||||
checksum = "c943259e342f1e06ff2da7a83eabdfe7f92ce10262688dbf1895ff0b3e6e4652"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
@@ -3342,9 +3383,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.32"
|
||||
version = "0.4.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "953f07c43838f8e6f9758cab68bf5bed85465e7587ebe0b823f1bcd81978ad3a"
|
||||
checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
@@ -3518,7 +3559,7 @@ version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ecce9d566cb9234ae3db9e249c8b55665feaaf32b0859ff1e27e310d2beb3d8"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"combine",
|
||||
"libc",
|
||||
"mach2",
|
||||
@@ -3570,7 +3611,7 @@ version = "0.30.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"cfg-if",
|
||||
"cfg_aliases",
|
||||
"libc",
|
||||
@@ -3582,7 +3623,7 @@ version = "0.31.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf20d2fde8ff38632c426f1165ed7436270b44f199fc55284c38276f9db47c3d"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"cfg-if",
|
||||
"cfg_aliases",
|
||||
"libc",
|
||||
@@ -3684,7 +3725,7 @@ version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d49e936b501e5c5bf01fda3a9452ff86dc3ea98ad5f283e1455153142d97518c"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"objc2",
|
||||
"objc2-core-graphics",
|
||||
"objc2-foundation",
|
||||
@@ -3696,7 +3737,7 @@ version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73ad74d880bb43877038da939b7427bba67e9dd42004a18b809ba7d87cee241c"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"objc2",
|
||||
"objc2-foundation",
|
||||
]
|
||||
@@ -3717,7 +3758,7 @@ version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2a180dd8642fa45cdb7dd721cd4c11b1cadd4929ce112ebd8b9f5803cc79d536"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"dispatch2",
|
||||
"objc2",
|
||||
]
|
||||
@@ -3728,7 +3769,7 @@ version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e022c9d066895efa1345f8e33e584b9f958da2fd4cd116792e15e07e4720a807"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"dispatch2",
|
||||
"objc2",
|
||||
"objc2-core-foundation",
|
||||
@@ -3761,7 +3802,7 @@ version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0cde0dfb48d25d2b4862161a4d5fcc0e3c24367869ad306b0c9ec0073bfed92d"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"objc2",
|
||||
"objc2-core-foundation",
|
||||
"objc2-core-graphics",
|
||||
@@ -3779,7 +3820,7 @@ version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3e0adef53c21f888deb4fa59fc59f7eb17404926ee8a6f59f5df0fd7f9f3272"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"block2",
|
||||
"libc",
|
||||
"objc2",
|
||||
@@ -3802,7 +3843,7 @@ version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "180788110936d59bab6bd83b6060ffdfffb3b922ba1396b312ae795e1de9d81d"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"objc2",
|
||||
"objc2-core-foundation",
|
||||
]
|
||||
@@ -3813,7 +3854,7 @@ version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96c1358452b371bf9f104e21ec536d37a650eb10f7ee379fff67d2e08d537f1f"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"objc2",
|
||||
"objc2-core-foundation",
|
||||
"objc2-foundation",
|
||||
@@ -3825,7 +3866,7 @@ version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d87d638e33c06f577498cbcc50491496a3ed4246998a7fbba7ccb98b1e7eab22"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"block2",
|
||||
"objc2",
|
||||
"objc2-cloud-kit",
|
||||
@@ -3877,7 +3918,7 @@ version = "6.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0cc3cbf698f9438986c11a880c90a6d04b9de27575afd28bbf45b154b6c709e2"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"libc",
|
||||
"once_cell",
|
||||
"onig_sys",
|
||||
@@ -3901,13 +3942,12 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
|
||||
|
||||
[[package]]
|
||||
name = "open"
|
||||
version = "5.3.5"
|
||||
version = "5.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2fbaa89d2ddc8473c78a3adf69eea8cffa28c483b8e02a971ef31527cd0fc92c"
|
||||
checksum = "cd8d3b65c44123a56e0133d2cd06ce4361bd3ca99d41198b2f25e3c3db9b8b4a"
|
||||
dependencies = [
|
||||
"is-wsl",
|
||||
"libc",
|
||||
"pathdiff",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3916,7 +3956,7 @@ version = "0.10.81"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77823a27f0babb03091cb9ed9ef80af3b39dbc82f97e8fa530374b7dafd87a45"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"cfg-if",
|
||||
"foreign-types",
|
||||
"libc",
|
||||
@@ -4073,12 +4113,6 @@ dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pathdiff"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3"
|
||||
|
||||
[[package]]
|
||||
name = "pem"
|
||||
version = "3.0.6"
|
||||
@@ -4095,6 +4129,18 @@ version = "2.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
|
||||
|
||||
[[package]]
|
||||
name = "petgraph"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3672b37090dbd86368a4145bc067582552b29c27377cad4e0a306c97f9bd7772"
|
||||
dependencies = [
|
||||
"fixedbitset",
|
||||
"indexmap 2.14.0",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "petgraph"
|
||||
version = "0.8.3"
|
||||
@@ -4392,9 +4438,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "quinn"
|
||||
version = "0.11.9"
|
||||
version = "0.11.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9e20a958963c291dc322d98411f541009df2ced7b5a4f2bd52337638cfccf20"
|
||||
checksum = "0c1a41e437b6bbd489372cd4971de128e85c855f56c57f283d20ff016cf7c0a8"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"cfg_aliases",
|
||||
@@ -4402,7 +4448,7 @@ dependencies = [
|
||||
"quinn-proto",
|
||||
"quinn-udp",
|
||||
"rustc-hash",
|
||||
"rustls 0.23.40",
|
||||
"rustls 0.23.41",
|
||||
"socket2 0.6.4",
|
||||
"thiserror 2.0.18",
|
||||
"tokio",
|
||||
@@ -4412,9 +4458,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "quinn-proto"
|
||||
version = "0.11.14"
|
||||
version = "0.11.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "434b42fec591c96ef50e21e886936e66d3cc3f737104fdb9b737c40ffb94c098"
|
||||
checksum = "4fcb935c5bec503c2f0e306bdd3e58bb9029dcb14fa8d9ac76e3a5256ac0763e"
|
||||
dependencies = [
|
||||
"aws-lc-rs",
|
||||
"bytes",
|
||||
@@ -4423,7 +4469,7 @@ dependencies = [
|
||||
"rand 0.9.4",
|
||||
"ring",
|
||||
"rustc-hash",
|
||||
"rustls 0.23.40",
|
||||
"rustls 0.23.41",
|
||||
"rustls-pki-types",
|
||||
"slab",
|
||||
"thiserror 2.0.18",
|
||||
@@ -4448,9 +4494,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.45"
|
||||
version = "1.0.46"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
|
||||
checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
@@ -4492,7 +4538,7 @@ version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2e8e8bcc7961af1fdac401278c6a831614941f6164ee3bf4ce61b7edb162207"
|
||||
dependencies = [
|
||||
"chacha20 0.10.0",
|
||||
"chacha20 0.10.1",
|
||||
"getrandom 0.4.3",
|
||||
"rand_core 0.10.1",
|
||||
]
|
||||
@@ -4557,7 +4603,7 @@ version = "0.5.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4669,7 +4715,7 @@ dependencies = [
|
||||
"native-tls",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"rustls 0.23.40",
|
||||
"rustls 0.23.41",
|
||||
"rustls-native-certs",
|
||||
"rustls-pki-types",
|
||||
"serde",
|
||||
@@ -4716,7 +4762,7 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"quinn",
|
||||
"rustls 0.23.40",
|
||||
"rustls 0.23.41",
|
||||
"rustls-pki-types",
|
||||
"rustls-platform-verifier",
|
||||
"serde",
|
||||
@@ -4762,9 +4808,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rmcp"
|
||||
version = "1.7.0"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0810a9f717d9828f475fe1f629f4c305c8464b7f496c3a854b58d29e65f4058e"
|
||||
checksum = "1d1f571c72940a19d9532fe52dbea8bc9912bf1d766c2970bb824056b86f3f59"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"base64",
|
||||
@@ -4789,9 +4835,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rmcp-macros"
|
||||
version = "1.7.0"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6aefac48c364756e97f04c0401ba3231e8607882c7c1d92da0437dc16307904d"
|
||||
checksum = "1aad0035b69380782d78ea95b508327e6deaa2235909053e596eea8f27b5e1d5"
|
||||
dependencies = [
|
||||
"darling 0.23.0",
|
||||
"proc-macro2",
|
||||
@@ -4898,7 +4944,7 @@ version = "1.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
@@ -4919,9 +4965,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustls"
|
||||
version = "0.23.40"
|
||||
version = "0.23.41"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ef86cd5876211988985292b91c96a8f2d298df24e75989a43a3c73f2d4d8168b"
|
||||
checksum = "6b92b125634d9b795e7beca796cc790df15a7fb38323bf3196fda83292d06b1f"
|
||||
dependencies = [
|
||||
"aws-lc-rs",
|
||||
"log",
|
||||
@@ -4947,9 +4993,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustls-pki-types"
|
||||
version = "1.14.1"
|
||||
version = "1.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "30a7197ae7eb376e574fe940d068c30fe0462554a3ddbe4eca7838e049c937a9"
|
||||
checksum = "764899a24af3980067ee14bc143654f297b22eaebfe3c7b6b211920a5a59b046"
|
||||
dependencies = [
|
||||
"web-time",
|
||||
"zeroize",
|
||||
@@ -4966,7 +5012,7 @@ dependencies = [
|
||||
"jni",
|
||||
"log",
|
||||
"once_cell",
|
||||
"rustls 0.23.40",
|
||||
"rustls 0.23.41",
|
||||
"rustls-native-certs",
|
||||
"rustls-platform-verifier-android",
|
||||
"rustls-webpki 0.103.13",
|
||||
@@ -5129,7 +5175,7 @@ version = "3.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"core-foundation",
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
@@ -5152,7 +5198,7 @@ version = "0.26.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd568a4c9bb598e291a08244a5c1f5a8a6650bee243b5b0f8dbb3d9cc1d87fe8"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"cssparser",
|
||||
"derive_more 0.99.20",
|
||||
"fxhash",
|
||||
@@ -5759,7 +5805,7 @@ version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "01198a2debb237c62b6826ec7081082d951f46dbb64b0e8c7649a452230d1dfc"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"byteorder",
|
||||
"enum-as-inner",
|
||||
"libc",
|
||||
@@ -6042,7 +6088,7 @@ version = "0.26.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61"
|
||||
dependencies = [
|
||||
"rustls 0.23.40",
|
||||
"rustls 0.23.41",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
@@ -6165,7 +6211,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840"
|
||||
dependencies = [
|
||||
"async-compression",
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"bytes",
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
@@ -6226,9 +6272,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tree-sitter"
|
||||
version = "0.26.9"
|
||||
version = "0.26.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4dab76d0b724ba557954125188cf0633a1ca43199ced82d95c7b9c32cc3de1f3"
|
||||
checksum = "3c343ed63e3f5c64d1acdecb5d2c13d4e169cb5fde0052106ebaa6c6f27f9e55"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"regex",
|
||||
@@ -6272,7 +6318,7 @@ checksum = "b8765b90061cba6c22b5831f675da109ae5561588290f9fa2317adab2714d5a6"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"nom 8.0.0",
|
||||
"petgraph",
|
||||
"petgraph 0.8.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6438,7 +6484,7 @@ dependencies = [
|
||||
"flate2",
|
||||
"log",
|
||||
"percent-encoding",
|
||||
"rustls 0.23.40",
|
||||
"rustls 0.23.41",
|
||||
"rustls-pki-types",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -6504,9 +6550,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "1.23.3"
|
||||
version = "1.23.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "144d6b123cef80b301b8f72a9e2ca4370ddec21950d0a103dd22c437006d2db7"
|
||||
checksum = "bf80a72845275afea99e7f2b434723d3bc7e38470fcd1c7ed39a599c73319a53"
|
||||
dependencies = [
|
||||
"getrandom 0.4.3",
|
||||
"js-sys",
|
||||
@@ -6606,9 +6652,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.125"
|
||||
version = "0.2.126"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ddb3f79143bced6de84270411622a2699cee572fc0875aeaf1e7867cf9fca1a"
|
||||
checksum = "4b067c0c11094aef6b7a801c1e34a26affafdf3d051dba08456b868789aaf9a4"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
@@ -6619,9 +6665,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-futures"
|
||||
version = "0.4.75"
|
||||
version = "0.4.76"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "503b14d284f2c8dac03b819967e155ea753f573586193b2b2c95990cb5d69280"
|
||||
checksum = "c62df1340f32221cb9c54d6a27b030e3dba64361d4a95bed55f9aacb44da291d"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
@@ -6629,9 +6675,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.125"
|
||||
version = "0.2.126"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e21a184b13fb19e157296e2c46056aec9092264fab83e4ba59e68c61b323c3d"
|
||||
checksum = "167ce5e579f6bcf889c4f7175a8a5a585de84e8ff93976ce393efa5f2837aab1"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
@@ -6639,9 +6685,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.125"
|
||||
version = "0.2.126"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fecefd9c35bd935a20fc3fc344b5f29138961e4f47fb03297d88f2587afb5ebd"
|
||||
checksum = "f3997c7839262f4ef12cf90b818d6340c18e80f263f1a94bf157d0ec4420380e"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
@@ -6652,9 +6698,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.125"
|
||||
version = "0.2.126"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23939e44bb9a5d7576fa2b563dc2e136628f1224e88a8deed09e04858b77871f"
|
||||
checksum = "dc1b4cb0cc549fcf58d7dfc081778139b3d283a081644e833e84682ad71cea24"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
@@ -6704,7 +6750,7 @@ version = "0.31.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "645c7c96bb74690c3189b5c9cb4ca1627062bb23693a4fad9d8c3de958260144"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"rustix",
|
||||
"wayland-backend",
|
||||
"wayland-scanner",
|
||||
@@ -6716,7 +6762,7 @@ version = "0.32.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23d0c813de3daa2ed6520af85a3bd49b0e722a3078506899aa9686fea58dc4b6"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-scanner",
|
||||
@@ -6728,7 +6774,7 @@ version = "0.3.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eb04e52f7836d7c7976c78ca0250d61e33873c34156a2a1fc9474828ec268234"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 2.13.0",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
@@ -6757,9 +6803,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "web-sys"
|
||||
version = "0.3.102"
|
||||
version = "0.3.103"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a6430a72df5eb332242960fe84b3002a241163998241eb596d4f739b9757061d"
|
||||
checksum = "8622dcb61c0bcc9fffa6938bed81210af2da9a7e4a1a834b2e37a59b6dfb6141"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
@@ -7411,9 +7457,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zlib-rs"
|
||||
version = "0.6.3"
|
||||
version = "0.6.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3be3d40e40a133f9c916ee3f9f4fa2d9d63435b5fbe1bfc6d9dae0aa0ada1513"
|
||||
checksum = "5431d5661c32445236631278f27946e444ddafe4684cac70b185272d4f9c52d5"
|
||||
|
||||
[[package]]
|
||||
name = "zmij"
|
||||
|
||||
+3
-2
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "coyote-ai"
|
||||
version = "0.7.2"
|
||||
version = "0.7.4"
|
||||
edition = "2024"
|
||||
authors = ["Alex Clarke <alex.j.tusa@gmail.com>"]
|
||||
description = "An all-in-one, batteries included LLM CLI Tool"
|
||||
@@ -49,7 +49,7 @@ textwrap = "0.16.0"
|
||||
ansi_colours = "1.2.2"
|
||||
eventsource-stream = "0.2.3"
|
||||
log = "0.4.28"
|
||||
log4rs = { version = "1.4.0", features = ["file_appender"] }
|
||||
log4rs = { version = "1.4.0", features = ["file_appender", "rolling_file_appender", "compound_policy", "fixed_window_roller", "size_trigger"] }
|
||||
shell-words = "1.1.0"
|
||||
sha2 = "0.10.8"
|
||||
unicode-width = "0.2.0"
|
||||
@@ -74,6 +74,7 @@ html_to_markdown = "0.1.0"
|
||||
rust-embed = "8.5.0"
|
||||
os_info = { version = "3.8.2", default-features = false }
|
||||
bm25 = { version = "2.0.1", features = ["parallelism"] }
|
||||
petgraph = { version = "0.7", features = ["serde-1"] }
|
||||
which = "8.0.0"
|
||||
fuzzy-matcher = "0.3.7"
|
||||
terminal-colorsaurus = "0.4.8"
|
||||
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
ARG COYOTE_VERSION
|
||||
FROM docker/sandbox-templates:shell-docker
|
||||
|
||||
ARG COYOTE_VERSION
|
||||
ARG TARGETARCH
|
||||
|
||||
ENV PATH="/home/agent/.cargo/bin:/home/agent/.local/bin:${PATH}"
|
||||
|
||||
USER root
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends \
|
||||
jq curl git \
|
||||
build-essential pkg-config \
|
||||
cmake \
|
||||
clang libclang-dev \
|
||||
musl-tools \
|
||||
libssl-dev \
|
||||
pandoc \
|
||||
bzip2 \
|
||||
nano && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN set -euo pipefail; \
|
||||
USQL_VERSION=0.21.4; \
|
||||
case "${TARGETARCH}" in \
|
||||
amd64) USQL_ARCH=amd64 ;; \
|
||||
arm64) USQL_ARCH=arm64 ;; \
|
||||
*) echo "Unsupported TARGETARCH: ${TARGETARCH}" >&2; exit 1 ;; \
|
||||
esac; \
|
||||
TMPDIR=$(mktemp -d); \
|
||||
curl -fsSL --retry 3 \
|
||||
"https://github.com/xo/usql/releases/download/v${USQL_VERSION}/usql_static-${USQL_VERSION}-linux-${USQL_ARCH}.tar.bz2" \
|
||||
-o "$TMPDIR/usql.tar.bz2"; \
|
||||
tar -xjf "$TMPDIR/usql.tar.bz2" -C "$TMPDIR"; \
|
||||
install -m 0755 "$TMPDIR/usql_static" /usr/local/bin/usql; \
|
||||
rm -rf "$TMPDIR"
|
||||
|
||||
USER 1000
|
||||
|
||||
RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \
|
||||
printf '#!/bin/sh\nexec uv tool run "$@"\n' > "$HOME/.local/bin/uvx" && \
|
||||
chmod +x "$HOME/.local/bin/uvx"
|
||||
|
||||
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \
|
||||
sh -s -- -y --default-toolchain stable --profile minimal && \
|
||||
. "$HOME/.cargo/env" && \
|
||||
cargo install --locked iwec && \
|
||||
cargo install --locked ast-grep
|
||||
|
||||
USER root
|
||||
|
||||
RUN set -euo pipefail; \
|
||||
case "${TARGETARCH}" in \
|
||||
amd64) MUSL_TARGET=x86_64-unknown-linux-musl ;; \
|
||||
arm64) MUSL_TARGET=aarch64-unknown-linux-musl ;; \
|
||||
*) echo "Unsupported TARGETARCH: ${TARGETARCH}" >&2; exit 1 ;; \
|
||||
esac; \
|
||||
TMPDIR=$(mktemp -d); \
|
||||
curl -fsSL --retry 3 \
|
||||
"https://github.com/Dark-Alex-17/coyote/releases/download/v${COYOTE_VERSION}/coyote-${MUSL_TARGET}.tar.gz" \
|
||||
-o "$TMPDIR/coyote.tar.gz"; \
|
||||
tar -xzf "$TMPDIR/coyote.tar.gz" -C "$TMPDIR"; \
|
||||
install -m 0755 "$TMPDIR/coyote" /home/agent/.cargo/bin/coyote; \
|
||||
chown 1000:1000 /home/agent/.cargo/bin/coyote; \
|
||||
rm -rf "$TMPDIR"
|
||||
|
||||
USER 1000
|
||||
|
||||
ENTRYPOINT ["coyote"]
|
||||
@@ -5,6 +5,7 @@
|
||||

|
||||

|
||||
[](https://github.com/Dark-Alex-17/coyote/releases)
|
||||

|
||||
|
||||
Coyote is an all-in-one, batteries-included, LLM CLI tool featuring Shell Assistant, CLI & REPL Mode, RAG, AI Tools &
|
||||
Agents, and More.
|
||||
@@ -38,6 +39,7 @@ Coming from [AIChat](https://github.com/sigoden/aichat)? Follow the [migration g
|
||||
* [RAG](https://github.com/Dark-Alex-17/coyote/wiki/RAG): Retrieval-Augmented Generation for enhanced information retrieval and generation.
|
||||
* [Sessions](https://github.com/Dark-Alex-17/coyote/wiki/Sessions): Manage and persist conversational contexts and settings across multiple interactions.
|
||||
* [Memory](https://github.com/Dark-Alex-17/coyote/wiki/Memory): Persistent file-based memory that survives across sessions. Bootstrap with `coyote --init-memory [global|workspace]`.
|
||||
* [Workspace Instructions](https://github.com/Dark-Alex-17/coyote/wiki/Workspace-Instructions): Human-curated project instructions (`COYOTE.md`) injected into every prompt, with `AGENTS.md`/`CLAUDE.md`/`GEMINI.md` fallbacks for cross-tool compatibility. Scaffold with `coyote --init-instructions`.
|
||||
* [Roles](https://github.com/Dark-Alex-17/coyote/wiki/Roles): Customize model behavior for specific tasks or domains.
|
||||
* [Skills](https://github.com/Dark-Alex-17/coyote/wiki/Skills): Modular knowledge or capability packs the LLM can load and unload mid-conversation. Multiple skills compose; instructions stack, tools and MCPs union.
|
||||
* [Agents](https://github.com/Dark-Alex-17/coyote/wiki/Agents): Leverage AI agents to perform complex tasks and workflows, including sub-agent spawning, teammate messaging, and user interaction tools.
|
||||
@@ -59,6 +61,14 @@ Coyote requires the following tools to be installed on your system:
|
||||
* [docker](https://docs.docker.com/engine/install/)
|
||||
* [uv](https://docs.astral.sh/uv/getting-started/installation/)
|
||||
* `curl -LsSf https://astral.sh/uv/install.sh | sh`
|
||||
* [iwe](https://github.com/iwe-org/iwe) (`iwec`, for the built-in `iwe` MCP server that navigates large markdown knowledgebases)
|
||||
* **Homebrew:** `brew tap iwe-org/iwe && brew install iwe`
|
||||
* **Cargo:** `cargo install iwec`
|
||||
* [ast-grep](https://ast-grep.github.io/) (for the built-in `ast_grep` structural code search tool, used by the `explore` agent)
|
||||
* **Homebrew:** `brew install ast-grep`
|
||||
* **Cargo:** `cargo install ast-grep --locked`
|
||||
* **npm:** `npm i -g @ast-grep/cli`
|
||||
* Optional: if `ast-grep` is not installed, the `ast_grep` tool reports it and agents fall back to `fs_grep`
|
||||
|
||||
These tools are used to provide various functionalities within Coyote, such as document processing, JSON manipulation,
|
||||
etc., and they are used within agents and tools.
|
||||
@@ -92,13 +102,39 @@ To upgrade `coyote` using Homebrew:
|
||||
brew upgrade coyote
|
||||
```
|
||||
|
||||
### Docker
|
||||
Coyote is available as a Docker image on Docker Hub (`darkalex17/coyote`) for Linux amd64 and arm64.
|
||||
Useful for CI, ephemeral environments, or anywhere you prefer not to install it natively.
|
||||
|
||||
```bash
|
||||
docker pull darkalex17/coyote
|
||||
docker run --rm -it darkalex17/coyote
|
||||
```
|
||||
|
||||
To persist your configuration across container runs, mount your existing config directory:
|
||||
|
||||
```bash
|
||||
docker run --rm -it \
|
||||
-v ~/.config/coyote:/home/agent/.config/coyote \
|
||||
darkalex17/coyote
|
||||
```
|
||||
|
||||
If you use the local vault provider and want your vault credentials available in the container, also mount the password file:
|
||||
|
||||
```bash
|
||||
docker run --rm -it \
|
||||
-v ~/.config/coyote:/home/agent/.config/coyote \
|
||||
-v ~/.coyote_password:/home/agent/.coyote_password:ro \
|
||||
darkalex17/coyote
|
||||
```
|
||||
|
||||
### Scripts
|
||||
#### Linux/MacOS (`bash`)
|
||||
You can use the following command to run a bash script that downloads and installs the latest version of `coyote` for your
|
||||
OS (Linux/MacOS) and architecture (x86_64/arm64):
|
||||
|
||||
```shell
|
||||
curl -fsSL https://raw.githubusercontent.com/Dark-Alex-17/coyote/main/install_coyote.sh | bash
|
||||
curl -fsSL https://raw.githubusercontent.com/Dark-Alex-17/coyote/refs/heads/main/scripts/install_coyote.sh | bash
|
||||
```
|
||||
|
||||
#### Windows/Linux/MacOS (`PowerShell`)
|
||||
@@ -106,7 +142,7 @@ You can use the following command to run a PowerShell script that downloads and
|
||||
for your OS (Windows/Linux/MacOS) and architecture (x86_64/arm64):
|
||||
|
||||
```powershell
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -Command "iwr -useb https://raw.githubusercontent.com/Dark-Alex-17/coyote/main/scripts/install_coyote.ps1 | iex"
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -Command "iwr -useb https://raw.githubusercontent.com/Dark-Alex-17/coyote/refs/heads/main/scripts/install_coyote.ps1 | iex"
|
||||
```
|
||||
|
||||
### Manual
|
||||
|
||||
@@ -16,7 +16,7 @@ agents while handling coordination and final reporting.
|
||||
## Pro-Tip: Use an IDE MCP Server for Improved Performance
|
||||
Many modern IDEs now include MCP servers that let LLMs perform operations within the IDE itself and use IDE tools. Using
|
||||
an IDE's MCP server dramatically improves the performance of coding agents. So if you have an IDE, try adding that MCP
|
||||
server to your config (see the [MCP Server docs](../../../docs/function-calling/MCP-SERVERS.md) to see how to configure
|
||||
server to your config (see the [MCP Server docs](https://github.com/Dark-Alex-17/coyote/wiki/MCP-Servers) to see how to configure
|
||||
them), and modify the agent definition to look like this:
|
||||
|
||||
```yaml
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
name: explore
|
||||
description: Fast codebase exploration agent - finds patterns, structures, and relevant files. Designed to be fanned out 2-5 in parallel by orchestrators.
|
||||
version: 3.0.0
|
||||
version: 3.1.0
|
||||
|
||||
skills_enabled: true
|
||||
enabled_skills:
|
||||
@@ -19,6 +19,7 @@ global_tools:
|
||||
- fs_grep.sh
|
||||
- fs_glob.sh
|
||||
- fs_ls.sh
|
||||
- ast_grep.sh
|
||||
|
||||
instructions: |
|
||||
You are a codebase explorer. Your job: Search, find, report. Nothing else.
|
||||
@@ -49,6 +50,8 @@ instructions: |
|
||||
|
||||
4. **Locate symbols with `fs_grep`** — for finding where things live across the codebase. `fs_grep --pattern "fn handle_request" --include "*.rs"` is faster than reading files.
|
||||
|
||||
4b. **Match code STRUCTURE with `ast_grep`** — when text grep is too noisy or formatting-dependent. It matches syntax trees: `ast_grep --pattern '$X.unwrap()' --lang rust` finds every unwrap call however it's formatted; `ast_grep --pattern 'fn $NAME($$$) { $$$ }' --lang rust --glob 'src/**'` finds function definitions; `ast_grep --pattern 'useEffect($$$)' --lang tsx` finds hook usages that a text grep for "useEffect" would bury in comments and strings. Meta-variables: `$NAME` = one AST node, `$$$` = zero or more. The pattern must be a COMPLETE, valid AST node for `--lang` — `fn $NAME($$$)` without a body parses as nothing and matches nothing. Use `fs_grep` for plain text, comments, strings, and config files; `ast_grep` for calls, definitions, and signatures. If ast-grep isn't installed the tool says so — fall back to fs_grep.
|
||||
|
||||
5. **Read targeted sections with `fs_read --offset/--limit`** — `fs_read --path "src/main.rs" --offset 50 --limit 30` reads lines 50-79 only. `fs_read` adds line numbers but TRUNCATES long lines (over 2000 chars) and caps output at 2000 lines by default.
|
||||
|
||||
6. **Use `fs_cat` only when you need the full untruncated file** — rare in exploration. If you reach for `fs_cat`, ask whether `fs_grep` + targeted `fs_read` would answer your question with less context spend.
|
||||
@@ -59,6 +62,7 @@ instructions: |
|
||||
|
||||
- `fs_grep --pattern "struct User" --include "*.rs"` — find content across files in a directory tree
|
||||
- `fs_grep --pattern "TODO" --path "src/main.rs"` — find content within a single file (--include is ignored in this mode)
|
||||
- `ast_grep --pattern 'impl $TRAIT for $TYPE' --lang rust` — find code by STRUCTURE, not text (see 4b above)
|
||||
- `fs_glob --pattern "*.rs" --path src/` — find files by name pattern
|
||||
- `fs_read --path "src/main.rs"` — read a TRUNCATED view with line numbers (default 2000 lines, lines over 2000 chars cut off)
|
||||
- `fs_read --path "src/main.rs" --offset 100 --limit 50` — read lines 100-149 only (line numbers; truncation rules still apply)
|
||||
|
||||
@@ -16,7 +16,7 @@ one file while communicating with sibling agents to catch issues that span multi
|
||||
## Pro-Tip: Use an IDE MCP Server for Improved Performance
|
||||
Many modern IDEs now include MCP servers that let LLMs perform operations within the IDE itself and use IDE tools. Using
|
||||
an IDE's MCP server dramatically improves the performance of coding agents. So if you have an IDE, try adding that MCP
|
||||
server to your config (see the [MCP Server docs](../../../docs/function-calling/MCP-SERVERS.md) to see how to configure
|
||||
server to your config (see the [MCP Server docs](https://github.com/Dark-Alex-17/coyote/wiki/MCP-Servers) to see how to configure
|
||||
them), and modify the agent definition to look like this:
|
||||
|
||||
```yaml
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
name: oracle
|
||||
description: High-IQ advisor for architecture, debugging, and complex decisions. Blocking by design - the orchestrator is waiting on you.
|
||||
version: 2.0.0
|
||||
version: 2.1.0
|
||||
|
||||
skills_enabled: true
|
||||
enabled_skills:
|
||||
- code-review
|
||||
- ai-slop-remover
|
||||
- plan-review
|
||||
- plan-authoring
|
||||
- iwe-knowledge-base
|
||||
|
||||
variables:
|
||||
- name: project_dir
|
||||
@@ -46,13 +49,16 @@ instructions: |
|
||||
3. **Code review** — evaluating proposed designs or implementations.
|
||||
4. **Risk assessment** — security, performance, reliability concerns.
|
||||
5. **Multi-component questions** — anything spanning 3+ files or modules.
|
||||
6. **Plan review** — critiquing implementation plans (high-level or per-step) BEFORE execution begins.
|
||||
|
||||
## Skills available
|
||||
|
||||
Two skills are available to you. Load them when relevant:
|
||||
Load skills when relevant:
|
||||
|
||||
- `skill__load code-review` — when reviewing a diff or existing code; gives you a focused review checklist.
|
||||
- `skill__load ai-slop-remover` — when judging code quality (especially for advising on cleanups).
|
||||
- `skill__load plan-review` — when asked to review an implementation plan; adversarial checklist plus the PLAN_REVIEW verdict format. Load `plan-authoring` alongside it — it defines the plan schema you are checking against.
|
||||
- `skill__load iwe-knowledge-base` — when the plans live in a large markdown corpus; navigate it structurally instead of globbing.
|
||||
|
||||
Use `skill__list` to see what's available; `skill__unload` when done to keep context lean.
|
||||
|
||||
@@ -91,6 +97,8 @@ instructions: |
|
||||
ORACLE_COMPLETE
|
||||
```
|
||||
|
||||
Exception: for plan reviews, use the `PLAN_REVIEW: OKAY` / `PLAN_REVIEW: REJECT` verdict format from the `plan-review` skill as the body, then end with `ORACLE_COMPLETE` on the final line as usual.
|
||||
|
||||
## Rules
|
||||
|
||||
1. **Never modify files** — you advise, others implement.
|
||||
|
||||
@@ -16,6 +16,21 @@ Sisyphus acts as the primary entry point, capable of handling complex tasks by c
|
||||
- 💻 **CLI Coding**: Provides a natural language interface for writing and editing code.
|
||||
- 🔄 **Task Management**: Tracks progress and context across complex operations.
|
||||
- 🛠️ **Tool Integration**: Seamlessly uses system tools for building, testing, and file manipulation.
|
||||
- 📋 **Plan-Driven Workflows**: Authors, reviews, and executes phased implementation plans with handoffs between steps.
|
||||
|
||||
## Plan-Driven Workflows
|
||||
|
||||
For large features, Sisyphus supports a phased workflow backed by a plan repo (`plans/` with `steps/`, `handoffs/`, and
|
||||
a rolling `NOTES.md`):
|
||||
|
||||
1. **Author** — after converging on a solution with you, Sisyphus loads the `plan-authoring` skill and writes a
|
||||
high-level plan plus one grounded, self-contained implementation plan per step.
|
||||
2. **Review** — [Oracle](../oracle/README.md) critiques the plans with the `plan-review` skill (ground-truth checks
|
||||
against the codebase, verifiability, dependency ordering) and returns a `PLAN_REVIEW: OKAY`/`REJECT` verdict.
|
||||
Rejected plans are fixed before any code is written.
|
||||
3. **Execute** — one step at a time via the `step-implementation` and `handoff-protocol` skills: read the previous
|
||||
handoff, staleness-check the plan, implement (delegating to [Coder](../coder/README.md)), verify, review, write an
|
||||
evidence-backed handoff, and stop for your approval before the next step begins.
|
||||
|
||||
## Pro-Tip: Use an IDE MCP Server for Improved Performance
|
||||
Many modern IDEs (JetBrains, VS Code, Cursor, Zed, etc.) expose MCP servers that let LLMs use IDE tools directly. Using
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
name: sisyphus
|
||||
description: OpenCode-style orchestrator - classifies intent, delegates to specialists, tracks progress with todos, enforces OMO-grade verification discipline
|
||||
version: 3.0.0
|
||||
version: 3.2.0
|
||||
|
||||
agent_session: temp
|
||||
auto_continue: true
|
||||
@@ -23,6 +23,10 @@ enabled_skills:
|
||||
- parallel-research
|
||||
- verification-gates
|
||||
- oracle-protocol
|
||||
- plan-authoring
|
||||
- step-implementation
|
||||
- handoff-protocol
|
||||
- iwe-knowledge-base
|
||||
|
||||
variables:
|
||||
- name: project_dir
|
||||
@@ -101,6 +105,9 @@ instructions: |
|
||||
| About to touch git history | `git-master` |
|
||||
| About to touch UI/components | `frontend-ui-ux` (also nudge delegates to load it) |
|
||||
| About to write any code | `ai-slop-remover` |
|
||||
| About to author a high-level plan or step plans | `plan-authoring` |
|
||||
| About to execute a step of a phased plan | `step-implementation` + `handoff-protocol` |
|
||||
| Navigating a plan repo or markdown knowledge base | `iwe-knowledge-base` |
|
||||
|
||||
Load skills BEFORE the phase, not after. Unload when the phase ends if context is getting heavy. `skill__unload` keeps the context lean.
|
||||
|
||||
@@ -124,7 +131,8 @@ instructions: |
|
||||
| `explore` | Find patterns in THIS codebase, understand local code | Read-only, returns findings, fan out 2-5 in parallel |
|
||||
| `librarian` | Find official docs, OSS examples, web best practices for EXTERNAL libraries | Read-only, returns citation-backed findings, fan out 1-3 in parallel |
|
||||
| `coder` | Write/edit files, implement features | Graph agent: plan → approval → implement → verify build+tests → self_review → bounded fix-loop |
|
||||
| `oracle` | Architecture, complex debugging, review | Advisory, blocking — never answer the user before collecting Oracle results |
|
||||
| `oracle` | Architecture, complex debugging, review, plan review | Advisory, blocking — never answer the user before collecting Oracle results |
|
||||
| `step-runner` | Execute ONE step of a phased plan repo (Phase 8) | Graph agent: orient → staleness check → coder → verify → handoff → user approval gate |
|
||||
|
||||
### When to fire `librarian` (external grep) vs `explore` (internal grep)
|
||||
|
||||
@@ -312,6 +320,47 @@ instructions: |
|
||||
|
||||
Never: leave code in broken state, continue hoping it'll work, delete failing tests to "pass," suppress errors to silence them.
|
||||
|
||||
## Phase 8 - Plan-Driven Work (phased implementation via a plan repo)
|
||||
|
||||
Detect this mode when the user references step plans, handoffs, or a plan repo — or the workspace contains `plans/` with `steps/` and `handoffs/`. Plan-driven work has two lifecycles. Never mix them in one turn.
|
||||
|
||||
### Authoring lifecycle (no code changes)
|
||||
|
||||
1. Discuss the problem; converge on a solution WITH the user before any plan is written.
|
||||
2. Load `plan-authoring`. Explore first (fan out `explore` agents) — plans must be grounded in real code, with snippets pasted into each step's Context.
|
||||
3. Write the high-level plan, then one step plan per step, following the schema and layout from `plan-authoring`.
|
||||
4. **Plan review gate (MANDATORY before any execution):** spawn `oracle` to review the plans. Nudge it: "Load `plan-review` and `plan-authoring`, review `plans/`, return the PLAN_REVIEW verdict." REJECT → fix the complaints, re-submit. Do not start execution on an unreviewed or rejected plan.
|
||||
5. Present the reviewed plan to the user for approval.
|
||||
|
||||
### Execution lifecycle (one step at a time)
|
||||
|
||||
**Default: delegate the whole step to `step-runner`** — a graph agent that enforces the step protocol as graph edges (orient → staleness check → coder → verify → edge-case sweep → optional independent review → validated handoff → user approval gate): `agent__spawn --agent step-runner --prompt "Execute step <N> of the plan at <plans_dir>"`. It returns `STEP_COMPLETE` / `STEP_BLOCKED` / `STEP_REJECTED` / `STEP_FAILED`. Relay its escalations (deviation gate, approval gate) promptly. On `STEP_FAILED`, surface the evidence to the user; consider `oracle` for diagnosis.
|
||||
|
||||
Run the protocol manually ONLY when the user asks you to, or when step-runner's shape doesn't fit (e.g. a docs-only step with nothing to build). Then:
|
||||
|
||||
1. Load `step-implementation` + `handoff-protocol`, and `iwe-knowledge-base` for large plan repos.
|
||||
2. Follow the step protocol phase by phase: orient (previous handoff + `NOTES.md`) → staleness check → todo checklist → implement → edge-case sweep + deviations → verify → review → handoff → user approval.
|
||||
3. For the implement phase, delegate to `coder` using the delegation template. Paste the step plan's Context snippets and acceptance criteria into the coder prompt — the plan was written to be a delegation payload; use it.
|
||||
4. Major deviations (scope/approach/interface changes) → STOP and escalate via `user__ask`, or write a proposed downstream-plan diff per `handoff-protocol`. Never silently absorb them.
|
||||
5. **HARD STOP at the approval gate.** Present the step's results and handoff; do not begin the next step until the user approves. Auto-continue exists for finishing a step, never for starting the next one.
|
||||
|
||||
## Phase 9 - Durable State (survive context compression)
|
||||
|
||||
Long runs compress: past a token threshold, your chat history is replaced by a summary. Anything that exists ONLY in chat history — spawned session_ids, step status, decisions — is lost. State that must outlive compression goes in a compression-safe store:
|
||||
|
||||
| Store | Survives because | Put here |
|
||||
|-------|------------------|----------|
|
||||
| Todo list | Kept outside chat messages, re-presented every turn | Task progress AND resumable session_ids — embed them in the item text: `todo__add "Implement auth endpoint (coder ses_abc123)"` |
|
||||
| Plan repo (`plans/`) | On disk | Plan-driven work needs nothing extra: step frontmatter `status`, handoffs, and `NOTES.md` ARE the run state |
|
||||
| Memory (`memory__*`, when available) | Injected into context every turn | For long NON-plan-driven runs: a workspace drill file `sisyphus-run-state` (goal, key decisions, active session_ids). Set `expires` to tomorrow; delete it when the run completes |
|
||||
|
||||
Rules:
|
||||
|
||||
1. **Session_ids you may need to resume are never chat-only.** Record them in the todo item for that work the moment the spawn returns. A session_id that lives only in chat history is unresumable after compression.
|
||||
2. **Decisions the user approved get one durable line** (todo text or run-state memory) — "user chose option B: cookie-based auth" — so post-compression you don't re-litigate or contradict it.
|
||||
3. **Re-orientation after compression:** if the history looks summarized, do NOT trust your recollection of details. Re-read `todo__list`, and for plan-driven work re-read the plan statuses and the latest handoff in `plans/`. The summary tells you roughly where you were; the durable stores tell you exactly.
|
||||
4. Do not hoard: run state is not knowledge. Never bloat `MEMORY.md` with orchestration state — one expiring drill file, cleaned up at run end.
|
||||
|
||||
## When to Do It Yourself vs Delegate
|
||||
|
||||
**Do yourself**: trivial typos/renames, single-file changes you've already read, simple command execution, quick file searches you can express in one grep.
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
schemaVersion: '1'
|
||||
kind: mixin
|
||||
name: sisyphus-ddg
|
||||
description: >
|
||||
Allows Sisyphus to hit all domains since it utilizes the DuckDuckGo
|
||||
MCP server. This allows the MCP server to actually perform web searches
|
||||
on arbitrary domains and retrieve info for the agent.
|
||||
|
||||
network:
|
||||
allowedDomains:
|
||||
- '*'
|
||||
@@ -0,0 +1,93 @@
|
||||
# Step-Runner
|
||||
|
||||
A graph-based agent that executes **one step** of a phased implementation
|
||||
plan, with the step protocol from the `step-implementation` skill enforced
|
||||
as graph edges rather than prose. Designed to be delegated to by
|
||||
**[Sisyphus](../sisyphus/README.md)**; delegates implementation to
|
||||
**[Coder](../coder/README.md)** and independent review to
|
||||
**[code-reviewer](../code-reviewer/README.md)**.
|
||||
|
||||
It expects a plan repo authored per the `plan-authoring` skill:
|
||||
|
||||
```
|
||||
plans/
|
||||
steps/NN-<slug>.md # step plans with frontmatter (step/title/depends_on/status)
|
||||
handoffs/NN-<slug>.md # written by this agent, validated by a deterministic gate
|
||||
NOTES.md # rolling durable facts
|
||||
```
|
||||
|
||||
## Workflow
|
||||
|
||||
```
|
||||
resolve_step (script) locate plan + previous handoff, check depends_on,
|
||||
↓ mark plan in-progress [→ gate_blocked if deps unsatisfied]
|
||||
orient (llm, read-only) merge handoff directives + staleness-check the plan
|
||||
↓
|
||||
route_staleness (script) major deviation → gate_deviation (approval)
|
||||
↓
|
||||
implement (agent → coder) coder runs its own build/test/self-review fix-loop
|
||||
↓
|
||||
route_coder_result (script) COMPLETE → verify | REJECTED / FAILED → end
|
||||
↓
|
||||
verify_format_lint (script) format BEFORE evidence, then lint
|
||||
verify_build (script) step-level build/typecheck
|
||||
verify_tests (script) FULL test suite
|
||||
↓ [failures → fix_loop_gate, back-edge to implement]
|
||||
edge_case_sweep (llm) missed edge cases; annotate downstream plans
|
||||
↓ (Edge cases sections ONLY - scope changes become proposals)
|
||||
route_sweep (script) 5+ files or architectural boundary → independent_review
|
||||
independent_review (agent) code-reviewer; 🔴 findings loop back to implement (bounded)
|
||||
↓
|
||||
write_handoff (llm) evidence-backed handoff per handoff-protocol + NOTES.md
|
||||
check_handoff (script) deterministic schema gate; marks plan status complete
|
||||
↓
|
||||
gate_user_review (approval) HARD STOP - approve, or send revision comments
|
||||
↓ (revisions loop through implement → verify → handoff again)
|
||||
end_success / end_blocked / end_rejected / end_failure
|
||||
```
|
||||
|
||||
End nodes emit sentinel outcomes for the caller:
|
||||
|
||||
- `STEP_COMPLETE` — step implemented, verified, handoff written, user approved.
|
||||
- `STEP_BLOCKED` — `depends_on` unsatisfied and the user declined to proceed.
|
||||
- `STEP_REJECTED` — user aborted at the deviation gate, or the coder's plan
|
||||
was rejected at its approval gate.
|
||||
- `STEP_FAILED` — coder failed, the step-level fix budget was exhausted, or
|
||||
the handoff failed validation twice.
|
||||
|
||||
## Usage
|
||||
|
||||
```sh
|
||||
# From the project root: run the next in-progress/pending step
|
||||
coyote -a step-runner "Execute the next step"
|
||||
|
||||
# A specific step (also parsed from the prompt: "execute step 3")
|
||||
coyote -a step-runner --agent-variable step 3 "Execute step 3"
|
||||
|
||||
# Plan repo somewhere else
|
||||
coyote -a step-runner --agent-variable plans_dir docs/plans "Execute the next step"
|
||||
```
|
||||
|
||||
**Invoke from the project root.** The coder sub-agent resolves its own
|
||||
`project_dir` from the invocation directory; overriding `project_dir` here
|
||||
does not propagate to the spawned coder.
|
||||
|
||||
## Tuning
|
||||
|
||||
`graph.yaml` `initial_state` exposes:
|
||||
|
||||
- `max_fix_attempts` (default `2`) — step-level fix budget (the coder has
|
||||
its own internal budget of 3).
|
||||
- `max_review_attempts` (default `1`) — bounded 🔴-finding fix loops after
|
||||
independent review.
|
||||
|
||||
Environment overrides honored by the script nodes:
|
||||
|
||||
- `FORMAT_CMD` / `LINT_CMD` — formatting and linting (otherwise a per-type
|
||||
heuristic formats, and linting defers to the build/check command).
|
||||
- `BUILD_CMD` / `TEST_CMD` — skip project-type detection (same as coder).
|
||||
- `STEP_AUTOAPPROVE=1` — bypass the deviation gate (non-interactive runs).
|
||||
- `STEP_SKIP_REVIEW=1` — never spawn the independent reviewer.
|
||||
|
||||
The final user approval gate is never bypassed by an environment variable -
|
||||
it is the point of the workflow.
|
||||
@@ -0,0 +1,599 @@
|
||||
name: step-runner
|
||||
description: |
|
||||
Executes ONE step of a phased implementation plan (plans/ repo) with the
|
||||
step protocol enforced as graph edges: orient -> staleness check ->
|
||||
implement (coder) -> verify -> edge-case sweep -> optional independent
|
||||
review -> evidence-backed handoff -> user approval gate. Designed to be
|
||||
delegated to by sisyphus.
|
||||
version: "1.0"
|
||||
|
||||
global_tools:
|
||||
- fs_cat.sh
|
||||
- fs_ls.sh
|
||||
- fs_write.sh
|
||||
- fs_patch.sh
|
||||
- execute_command.sh
|
||||
|
||||
skills_enabled: true
|
||||
enabled_skills:
|
||||
- step-implementation
|
||||
- handoff-protocol
|
||||
- code-review
|
||||
- ai-slop-remover
|
||||
|
||||
variables:
|
||||
- name: project_dir
|
||||
description: |
|
||||
Absolute path to the project directory. Defaults to "." (the directory
|
||||
coyote was invoked from). The coder sub-agent resolves its own
|
||||
project_dir the same way, so invoke step-runner FROM the project root
|
||||
unless you override this for both.
|
||||
default: "."
|
||||
- name: plans_dir
|
||||
description: |
|
||||
Path to the plan repo. Relative paths resolve against project_dir.
|
||||
Expected layout: <plans_dir>/steps/NN-<slug>.md,
|
||||
<plans_dir>/handoffs/, <plans_dir>/NOTES.md.
|
||||
default: "plans"
|
||||
- name: step
|
||||
description: |
|
||||
Which step to execute: a step number, or "next" to pick the first
|
||||
in-progress (resume) or pending step plan.
|
||||
default: "next"
|
||||
|
||||
settings:
|
||||
max_loop_iterations: 20
|
||||
log_state_snapshots: true
|
||||
validate_before_run: true
|
||||
timeout: 7200
|
||||
|
||||
initial_state:
|
||||
project_dir: ""
|
||||
plans_dir: ""
|
||||
step_number: 0
|
||||
step_slug: ""
|
||||
step_title: ""
|
||||
step_plan_path: ""
|
||||
step_plan: ""
|
||||
prev_handoff_path: "(none)"
|
||||
prev_handoff: "(none - this is the first step)"
|
||||
notes_path: ""
|
||||
notes: "(none)"
|
||||
handoff_path: ""
|
||||
blocking_reason: ""
|
||||
plan_summary: ""
|
||||
implementation_brief: ""
|
||||
staleness_report: ""
|
||||
has_major_deviation: false
|
||||
deviation_summary: ""
|
||||
user_feedback: ""
|
||||
fix_instructions: ""
|
||||
fix_attempts: 0
|
||||
max_fix_attempts: 2
|
||||
coder_result: ""
|
||||
format_output: ""
|
||||
lint_ok: true
|
||||
lint_output: ""
|
||||
build_ok: true
|
||||
build_output: ""
|
||||
tests_ok: true
|
||||
tests_output: ""
|
||||
edge_case_report: ""
|
||||
downstream_updates: ""
|
||||
needs_independent_review: false
|
||||
review_report: ""
|
||||
review_attempts: 0
|
||||
max_review_attempts: 1
|
||||
handoff_attempts: 0
|
||||
handoff_fix: ""
|
||||
step_summary: ""
|
||||
|
||||
start: resolve_step
|
||||
|
||||
nodes:
|
||||
resolve_step:
|
||||
id: resolve_step
|
||||
type: script
|
||||
description: |
|
||||
Locate the step plan, previous handoff, and NOTES.md; parse frontmatter;
|
||||
check depends_on satisfaction against existing handoffs; mark the plan
|
||||
in-progress. Routes to gate_blocked when dependencies are unsatisfied.
|
||||
script: scripts/resolve_step.sh
|
||||
timeout: 30
|
||||
fallback: end_failure
|
||||
next: orient
|
||||
|
||||
gate_blocked:
|
||||
id: gate_blocked
|
||||
type: approval
|
||||
description: Escalate unsatisfied dependencies instead of building on missing ground.
|
||||
question: |
|
||||
Step {{step_number}} ({{step_title}}) is BLOCKED:
|
||||
|
||||
{{blocking_reason}}
|
||||
|
||||
Proceed anyway?
|
||||
options:
|
||||
- "yes"
|
||||
- "no"
|
||||
routes:
|
||||
"yes": orient
|
||||
"no": end_blocked
|
||||
on_other: end_blocked
|
||||
|
||||
orient:
|
||||
id: orient
|
||||
type: llm
|
||||
description: |
|
||||
Read-only orientation and staleness check: merge the previous handoff's
|
||||
directives with the step plan, then verify the plan's assumptions
|
||||
against the CURRENT codebase before any edit.
|
||||
skills_enabled: true
|
||||
enabled_skills:
|
||||
- step-implementation
|
||||
instructions: |
|
||||
You are orienting for one step of a phased implementation plan. Load
|
||||
`step-implementation` and apply its Orient and Staleness-check phases.
|
||||
You are READ-ONLY in this node: no edits, no fixes.
|
||||
|
||||
1. Read the previous handoff (below). Note directives aimed at this
|
||||
step, deviations that changed the codebase, and bare assertions
|
||||
that need re-verification.
|
||||
2. Staleness-check the step plan against the code at {{project_dir}}:
|
||||
grep the symbols it references (via execute_command), read its
|
||||
Context snippets at their claimed locations with fs_cat, confirm
|
||||
its Test commands exist.
|
||||
3. Classify discrepancies per the skill's deviation table: minor
|
||||
(mechanics differ; correct silently in the brief) vs major (scope,
|
||||
approach, interfaces, or a later step's assumptions affected).
|
||||
|
||||
Produce `implementation_brief`: the corrected, self-contained marching
|
||||
orders for the implementer - plan tasks in order, handoff directives
|
||||
applied, minor staleness corrections folded in, acceptance criteria
|
||||
restated. The implementer sees ONLY the step plan plus your brief.
|
||||
prompt: |
|
||||
## Step plan ({{step_plan_path}})
|
||||
{{step_plan}}
|
||||
|
||||
## Previous handoff ({{prev_handoff_path}})
|
||||
{{prev_handoff}}
|
||||
|
||||
## Rolling project notes
|
||||
{{notes}}
|
||||
tools:
|
||||
- fs_cat
|
||||
- fs_ls
|
||||
- execute_command
|
||||
max_iterations: 20
|
||||
output_schema:
|
||||
type: object
|
||||
properties:
|
||||
plan_summary:
|
||||
type: string
|
||||
description: 1-3 sentences summarizing what this step delivers
|
||||
implementation_brief:
|
||||
type: string
|
||||
description: Corrected, self-contained instructions for the implementer
|
||||
staleness_report:
|
||||
type: string
|
||||
description: Findings from checking plan assumptions against current code; "clean" if none
|
||||
has_major_deviation:
|
||||
type: boolean
|
||||
description: True when a discrepancy changes scope, approach, or interfaces
|
||||
deviation_summary:
|
||||
type: string
|
||||
description: Major deviations only, with the plan claim vs current reality. Empty when none
|
||||
required: [plan_summary, implementation_brief, staleness_report, has_major_deviation, deviation_summary]
|
||||
fallback: end_failure
|
||||
next: route_staleness
|
||||
|
||||
route_staleness:
|
||||
id: route_staleness
|
||||
type: script
|
||||
description: Major deviation -> user gate; otherwise straight to implement.
|
||||
script: scripts/route_staleness.sh
|
||||
timeout: 5
|
||||
fallback: implement
|
||||
|
||||
gate_deviation:
|
||||
id: gate_deviation
|
||||
type: approval
|
||||
description: Major deviations are never silently absorbed - the user decides.
|
||||
question: |
|
||||
Step {{step_number}} ({{step_title}}): the plan no longer matches the
|
||||
codebase in a way that changes scope or approach.
|
||||
|
||||
{{deviation_summary}}
|
||||
|
||||
Staleness report:
|
||||
{{staleness_report}}
|
||||
|
||||
Proceed with the corrected brief? (Answer with anything else to give
|
||||
your own guidance to the implementer.)
|
||||
options:
|
||||
- "proceed"
|
||||
- "abort"
|
||||
routes:
|
||||
"proceed": implement
|
||||
"abort": end_rejected
|
||||
on_other: implement
|
||||
state_updates:
|
||||
user_feedback: "{{choice}}"
|
||||
|
||||
implement:
|
||||
id: implement
|
||||
type: agent
|
||||
description: |
|
||||
Delegate implementation to the coder graph agent, which runs its own
|
||||
plan -> implement -> build -> tests -> self-review fix-loop internally.
|
||||
agent: coder
|
||||
prompt: |
|
||||
## TASK
|
||||
Execute step {{step_number}} ({{step_title}}) of a phased implementation
|
||||
plan for the project at {{project_dir}}.
|
||||
|
||||
## EXPECTED OUTCOME
|
||||
Every task in the step plan below is implemented and its acceptance
|
||||
criteria are met. Tests are derived from the Acceptance criteria
|
||||
section (not from the implementation). Build and full test suite pass.
|
||||
|
||||
## MUST DO
|
||||
- Follow the Orientation brief below - it supersedes the raw plan where
|
||||
they disagree (it folds in corrections from the staleness check).
|
||||
- Match the patterns pasted in the step plan's Context section.
|
||||
- Derive tests from the plan's Acceptance criteria.
|
||||
|
||||
## MUST NOT DO
|
||||
- Do not touch anything listed in the plan's Out of scope section.
|
||||
- Do not modify files under {{plans_dir}}.
|
||||
- Do not implement work belonging to other steps.
|
||||
|
||||
## CONTEXT
|
||||
### Step plan
|
||||
{{step_plan}}
|
||||
|
||||
### Orientation brief (handoff directives + staleness corrections applied)
|
||||
{{implementation_brief}}
|
||||
|
||||
### User guidance (if any)
|
||||
{{user_feedback}}
|
||||
|
||||
### Fix loop status (empty on first attempt)
|
||||
{{fix_instructions}}
|
||||
timeout: 3600
|
||||
state_updates:
|
||||
coder_result: "{{output}}"
|
||||
next: route_coder_result
|
||||
|
||||
route_coder_result:
|
||||
id: route_coder_result
|
||||
type: script
|
||||
description: Route on the coder sentinel - COMPLETE verifies, REJECTED/FAILED terminate.
|
||||
script: scripts/route_coder_result.sh
|
||||
timeout: 5
|
||||
fallback: end_failure
|
||||
|
||||
verify_format_lint:
|
||||
id: verify_format_lint
|
||||
type: script
|
||||
description: |
|
||||
Format BEFORE evidence collection (FORMAT_CMD override or per-type
|
||||
heuristic), then lint (LINT_CMD, when configured). Lint failure routes
|
||||
to the fix loop.
|
||||
script: scripts/verify_format_lint.sh
|
||||
timeout: 300
|
||||
fallback: fix_loop_gate
|
||||
|
||||
verify_build:
|
||||
id: verify_build
|
||||
type: script
|
||||
description: Step-level build/typecheck evidence, collected AFTER formatting.
|
||||
script: scripts/verify_build.sh
|
||||
timeout: 600
|
||||
fallback: fix_loop_gate
|
||||
|
||||
verify_tests:
|
||||
id: verify_tests
|
||||
type: script
|
||||
description: FULL test suite - regressions in untouched code fail the step too.
|
||||
script: scripts/verify_tests.sh
|
||||
timeout: 1200
|
||||
fallback: fix_loop_gate
|
||||
|
||||
fix_loop_gate:
|
||||
id: fix_loop_gate
|
||||
type: script
|
||||
description: |
|
||||
Step-level fix budget (the coder already ran its own internal fix
|
||||
loop). Loops to implement with fix_instructions, or ends as failure.
|
||||
script: scripts/fix_loop_gate.sh
|
||||
timeout: 5
|
||||
fallback: end_failure
|
||||
|
||||
edge_case_sweep:
|
||||
id: edge_case_sweep
|
||||
type: llm
|
||||
description: |
|
||||
Post-implementation sweep: missed spots, edge cases, downstream plan
|
||||
implications. May annotate downstream plans' Edge cases sections
|
||||
(annotate vs propose per handoff-protocol). Also judges whether the
|
||||
change warrants an independent review pass.
|
||||
skills_enabled: true
|
||||
enabled_skills:
|
||||
- step-implementation
|
||||
- handoff-protocol
|
||||
instructions: |
|
||||
The implementation for this step just passed build and tests. Load
|
||||
`step-implementation` (edge-case sweep phase) and `handoff-protocol`
|
||||
(annotate-vs-propose rules), then:
|
||||
|
||||
1. Read the changed code (the coder result below names the files).
|
||||
Look for edge cases the plan missed: empty inputs, error paths,
|
||||
concurrency, partial failure, compat.
|
||||
2. For each edge case belonging to a LATER step: check that step's
|
||||
plan under {{plans_dir}}/steps/. If its Edge cases section already
|
||||
covers it, done. If not, append an entry to that section via
|
||||
fs_patch - touch NOTHING else in the file.
|
||||
3. NEVER edit a later plan's Objective, Tasks, Acceptance criteria,
|
||||
or Out of scope. Scope-affecting changes become proposed diffs in
|
||||
`downstream_updates` instead.
|
||||
4. Set needs_independent_review=true when the change touched 5+ files
|
||||
or crosses architectural boundaries (auth, public APIs, schema,
|
||||
security-sensitive paths).
|
||||
|
||||
Be terse. Findings, not prose.
|
||||
prompt: |
|
||||
## Coder result
|
||||
{{coder_result}}
|
||||
|
||||
## Step plan
|
||||
{{step_plan}}
|
||||
|
||||
## Staleness report from orientation
|
||||
{{staleness_report}}
|
||||
tools:
|
||||
- fs_cat
|
||||
- fs_ls
|
||||
- fs_patch
|
||||
- execute_command
|
||||
max_iterations: 20
|
||||
output_schema:
|
||||
type: object
|
||||
properties:
|
||||
edge_case_report:
|
||||
type: string
|
||||
description: Edge cases discovered - both handled and punted, one per line. "none" if empty
|
||||
downstream_updates:
|
||||
type: string
|
||||
description: Annotations made (plan file + section) and proposed diffs for scope-affecting changes. "none" if empty
|
||||
needs_independent_review:
|
||||
type: boolean
|
||||
required: [edge_case_report, downstream_updates, needs_independent_review]
|
||||
fallback: write_handoff
|
||||
next: route_sweep
|
||||
|
||||
route_sweep:
|
||||
id: route_sweep
|
||||
type: script
|
||||
description: Broad or boundary-crossing changes get an independent reviewer.
|
||||
script: scripts/route_sweep.sh
|
||||
timeout: 5
|
||||
fallback: write_handoff
|
||||
|
||||
independent_review:
|
||||
id: independent_review
|
||||
type: agent
|
||||
description: Independent review pass - the author's self-review cannot catch its own rationalizations.
|
||||
agent: code-reviewer
|
||||
prompt: |
|
||||
Review the changes produced for step {{step_number}} ({{step_title}})
|
||||
of a phased implementation plan in {{project_dir}}.
|
||||
|
||||
What the step was supposed to do:
|
||||
{{plan_summary}}
|
||||
|
||||
Coder summary (names the modified/created files):
|
||||
{{coder_result}}
|
||||
|
||||
Review the changed files against the step plan's acceptance criteria.
|
||||
Preserve severity tags in your findings.
|
||||
timeout: 1200
|
||||
state_updates:
|
||||
review_report: "{{output}}"
|
||||
next: route_review
|
||||
|
||||
route_review:
|
||||
id: route_review
|
||||
type: script
|
||||
description: Critical findings loop back to implement (bounded); otherwise proceed to handoff.
|
||||
script: scripts/route_review.sh
|
||||
timeout: 5
|
||||
fallback: write_handoff
|
||||
|
||||
write_handoff:
|
||||
id: write_handoff
|
||||
type: llm
|
||||
description: |
|
||||
Write the evidence-backed handoff per handoff-protocol and append
|
||||
durable facts to NOTES.md. The completion gate (check_handoff)
|
||||
verifies the document afterward.
|
||||
skills_enabled: true
|
||||
enabled_skills:
|
||||
- handoff-protocol
|
||||
- ai-slop-remover
|
||||
instructions: |
|
||||
Load `handoff-protocol` and follow its writer schema EXACTLY: the
|
||||
frontmatter (step, title, result) and all eight sections, writing
|
||||
"None" rather than omitting a section.
|
||||
|
||||
Write the handoff to {{handoff_path}} with fs_write. Paste the
|
||||
verification evidence below verbatim into the Evidence section -
|
||||
commands, exit codes, decisive output lines. Deviations come from the
|
||||
staleness report, gate decisions, and fix loop history. Downstream
|
||||
plan updates come from the sweep results.
|
||||
|
||||
Then append durable, step-independent facts (if any) to {{notes_path}}
|
||||
- create the file if missing, never rewrite existing entries.
|
||||
|
||||
If "Gate feedback" below is non-empty, a previous handoff attempt
|
||||
failed validation - fix exactly what it lists.
|
||||
prompt: |
|
||||
## Step
|
||||
{{step_number}} ({{step_title}}) - plan at {{step_plan_path}}
|
||||
|
||||
## Plan summary
|
||||
{{plan_summary}}
|
||||
|
||||
## Coder result
|
||||
{{coder_result}}
|
||||
|
||||
## Staleness report / deviations
|
||||
{{staleness_report}}
|
||||
|
||||
Major deviation summary (if any): {{deviation_summary}}
|
||||
User guidance given (if any): {{user_feedback}}
|
||||
Fix loop attempts used: {{fix_attempts}} of {{max_fix_attempts}}
|
||||
|
||||
## Edge cases discovered
|
||||
{{edge_case_report}}
|
||||
|
||||
## Downstream plan updates
|
||||
{{downstream_updates}}
|
||||
|
||||
## Independent review report (if any)
|
||||
{{review_report}}
|
||||
|
||||
## Verification evidence (paste verbatim)
|
||||
### Format
|
||||
{{format_output}}
|
||||
### Lint
|
||||
{{lint_output}}
|
||||
### Build
|
||||
{{build_output}}
|
||||
### Tests
|
||||
{{tests_output}}
|
||||
|
||||
## Gate feedback
|
||||
{{handoff_fix}}
|
||||
tools:
|
||||
- fs_cat
|
||||
- fs_ls
|
||||
- fs_write
|
||||
- fs_patch
|
||||
max_iterations: 15
|
||||
output_schema:
|
||||
type: object
|
||||
properties:
|
||||
step_summary:
|
||||
type: string
|
||||
description: 3-6 sentence summary of the step for the user's approval decision - what was done, deviations, anything needing their attention
|
||||
required: [step_summary]
|
||||
fallback: end_failure
|
||||
next: check_handoff
|
||||
|
||||
check_handoff:
|
||||
id: check_handoff
|
||||
type: script
|
||||
description: |
|
||||
Deterministic completion gate - handoff exists with frontmatter and all
|
||||
required sections. On success, marks the step plan status complete.
|
||||
One retry back to write_handoff, then failure.
|
||||
script: scripts/check_handoff.sh
|
||||
timeout: 10
|
||||
fallback: end_failure
|
||||
|
||||
gate_user_review:
|
||||
id: gate_user_review
|
||||
type: approval
|
||||
description: The hard stop - the next step never starts without explicit approval.
|
||||
question: |
|
||||
## Step {{step_number}} ({{step_title}}) - ready for review
|
||||
|
||||
{{step_summary}}
|
||||
|
||||
Handoff: {{handoff_path}}
|
||||
Build: {{build_ok}} | Tests: {{tests_ok}} | Fix attempts: {{fix_attempts}}/{{max_fix_attempts}}
|
||||
|
||||
Approve this step? (Answer with anything else to send revision
|
||||
instructions straight to the implementer.)
|
||||
options:
|
||||
- "approve"
|
||||
- "revise"
|
||||
routes:
|
||||
"approve": end_success
|
||||
"revise": get_revision
|
||||
on_other: revise_from_choice
|
||||
state_updates:
|
||||
user_feedback: "{{choice}}"
|
||||
|
||||
get_revision:
|
||||
id: get_revision
|
||||
type: input
|
||||
description: Collect revision instructions, then loop back through implement -> verify -> handoff.
|
||||
question: "What should change? Your comments go to the implementer verbatim."
|
||||
validation: "len(input) > 0"
|
||||
state_updates:
|
||||
fix_instructions: "{{input}}"
|
||||
next: implement
|
||||
|
||||
revise_from_choice:
|
||||
id: revise_from_choice
|
||||
type: script
|
||||
description: Free-form approval answers are treated as revision instructions.
|
||||
script: scripts/revise_from_choice.sh
|
||||
timeout: 5
|
||||
fallback: get_revision
|
||||
|
||||
end_success:
|
||||
id: end_success
|
||||
type: end
|
||||
output: |
|
||||
STEP_COMPLETE
|
||||
Step: {{step_number}} ({{step_title}})
|
||||
Plan: {{step_plan_path}}
|
||||
Handoff: {{handoff_path}}
|
||||
Build: passed | Tests: passed | Fix attempts: {{fix_attempts}}/{{max_fix_attempts}}
|
||||
|
||||
{{step_summary}}
|
||||
|
||||
Downstream plan updates:
|
||||
{{downstream_updates}}
|
||||
|
||||
end_blocked:
|
||||
id: end_blocked
|
||||
type: end
|
||||
output: |
|
||||
STEP_BLOCKED
|
||||
Step: {{step_number}} ({{step_title}})
|
||||
Reason:
|
||||
{{blocking_reason}}
|
||||
|
||||
end_rejected:
|
||||
id: end_rejected
|
||||
type: end
|
||||
output: |
|
||||
STEP_REJECTED
|
||||
Step: {{step_number}} ({{step_title}})
|
||||
Rejected at: deviation gate or coder approval gate.
|
||||
Deviation summary:
|
||||
{{deviation_summary}}
|
||||
Coder result (if it ran):
|
||||
{{coder_result}}
|
||||
|
||||
end_failure:
|
||||
id: end_failure
|
||||
type: end
|
||||
output: |
|
||||
STEP_FAILED
|
||||
Step: {{step_number}} ({{step_title}})
|
||||
Fix attempts: {{fix_attempts}}/{{max_fix_attempts}}
|
||||
Blocking reason (if resolution failed): {{blocking_reason}}
|
||||
|
||||
Coder result:
|
||||
{{coder_result}}
|
||||
|
||||
Last build output:
|
||||
{{build_output}}
|
||||
|
||||
Last tests output:
|
||||
{{tests_output}}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env bash
|
||||
set -uo pipefail
|
||||
|
||||
if [[ -n "${GRAPH_STATE_FILE:-}" ]]; then
|
||||
state=$(cat "$GRAPH_STATE_FILE")
|
||||
elif [[ -n "${GRAPH_STATE:-}" ]]; then
|
||||
state="$GRAPH_STATE"
|
||||
else
|
||||
state='{}'
|
||||
fi
|
||||
|
||||
handoff_path=$(echo "$state" | jq -r '.handoff_path // ""')
|
||||
step_plan_path=$(echo "$state" | jq -r '.step_plan_path // ""')
|
||||
handoff_attempts=$(echo "$state" | jq -r '.handoff_attempts // 0')
|
||||
|
||||
problems=""
|
||||
|
||||
if [[ ! -f "$handoff_path" ]]; then
|
||||
problems="- handoff file does not exist at $handoff_path"$'\n'
|
||||
else
|
||||
content=$(cat "$handoff_path")
|
||||
grep -qE '^result:[[:space:]]*(complete|partial|blocked)' <<< "$content" \
|
||||
|| problems+="- frontmatter is missing 'result: complete|partial|blocked'"$'\n'
|
||||
for section in "Summary" "Completed" "Not completed" "Deviations" "Downstream plan updates" "Edge cases discovered" "Evidence" "Notes for next step"; do
|
||||
grep -qE "^##[[:space:]]+${section}" <<< "$content" \
|
||||
|| problems+="- missing required section: ## ${section}"$'\n'
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ -z "$problems" ]]; then
|
||||
if [[ -f "$step_plan_path" ]]; then
|
||||
tmp=$(mktemp)
|
||||
awk 'BEGIN{n=0} /^---[[:space:]]*$/{n++; print; next} n==1 && /^status:/{print "status: complete"; next} {print}' "$step_plan_path" > "$tmp" && mv "$tmp" "$step_plan_path"
|
||||
fi
|
||||
jq -nc '{"handoff_fix": "", "_next": "gate_user_review"}'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if (( handoff_attempts >= 1 )); then
|
||||
jq -nc \
|
||||
--arg br "Handoff failed validation twice. Problems:
|
||||
$problems" \
|
||||
'{"blocking_reason": $br, "_next": "end_failure"}'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
jq -nc \
|
||||
--arg hf "The previous handoff attempt failed validation. Fix exactly these problems:
|
||||
$problems" \
|
||||
'{
|
||||
"handoff_attempts": 1,
|
||||
"handoff_fix": $hf,
|
||||
"_next": "write_handoff"
|
||||
}'
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if [[ -n "${GRAPH_STATE_FILE:-}" ]]; then
|
||||
state=$(cat "$GRAPH_STATE_FILE")
|
||||
elif [[ -n "${GRAPH_STATE:-}" ]]; then
|
||||
state="$GRAPH_STATE"
|
||||
else
|
||||
state='{}'
|
||||
fi
|
||||
|
||||
fix_attempts=$(echo "$state" | jq -r '.fix_attempts // 0')
|
||||
max_fix_attempts=$(echo "$state" | jq -r '.max_fix_attempts // 2')
|
||||
lint_ok=$(echo "$state" | jq -r '.lint_ok | if . == null then "true" else (. | tostring) end')
|
||||
build_ok=$(echo "$state" | jq -r '.build_ok | if . == null then "true" else (. | tostring) end')
|
||||
tests_ok=$(echo "$state" | jq -r '.tests_ok | if . == null then "true" else (. | tostring) end')
|
||||
lint_output=$(echo "$state" | jq -r '.lint_output // ""')
|
||||
build_output=$(echo "$state" | jq -r '.build_output // ""')
|
||||
tests_output=$(echo "$state" | jq -r '.tests_output // ""')
|
||||
|
||||
if (( fix_attempts >= max_fix_attempts )); then
|
||||
jq -nc \
|
||||
--argjson n "$fix_attempts" \
|
||||
'{
|
||||
"fix_attempts": $n,
|
||||
"_next": "end_failure"
|
||||
}'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
next_attempts=$((fix_attempts + 1))
|
||||
|
||||
if [[ "$lint_ok" != "true" ]]; then
|
||||
stage="lint"
|
||||
output="$lint_output"
|
||||
elif [[ "$build_ok" != "true" ]]; then
|
||||
stage="build"
|
||||
output="$build_output"
|
||||
elif [[ "$tests_ok" != "true" ]]; then
|
||||
stage="full test suite"
|
||||
output="$tests_output"
|
||||
else
|
||||
stage="verification"
|
||||
output="fix_loop_gate was reached but no failing stage was recorded. Re-run verification."
|
||||
fi
|
||||
|
||||
fix_instructions=$(printf '## Fix loop status (step-level attempt %d of %d)\n\nThe implementation passed the coder'"'"'s internal checks but failed step-level verification at the %s stage.\n\nOutput:\n```\n%s\n```\n\nIdentify the minimal fix and apply it. Do not refactor. Regressions in untouched code caused by this change are in scope.' \
|
||||
"$next_attempts" "$max_fix_attempts" "$stage" "$output")
|
||||
|
||||
jq -nc \
|
||||
--argjson n "$next_attempts" \
|
||||
--arg 'fi' "$fix_instructions" \
|
||||
'{
|
||||
"fix_attempts": $n,
|
||||
"fix_instructions": $fi,
|
||||
"lint_ok": true,
|
||||
"build_ok": true,
|
||||
"tests_ok": true,
|
||||
"_next": "implement"
|
||||
}'
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
#!/usr/bin/env bash
|
||||
set -uo pipefail
|
||||
|
||||
if [[ -n "${GRAPH_STATE_FILE:-}" ]]; then
|
||||
state=$(cat "$GRAPH_STATE_FILE")
|
||||
elif [[ -n "${GRAPH_STATE:-}" ]]; then
|
||||
state="$GRAPH_STATE"
|
||||
else
|
||||
state='{}'
|
||||
fi
|
||||
|
||||
fail() {
|
||||
jq -nc --arg r "$1" '{"blocking_reason": $r, "_next": "end_failure"}'
|
||||
exit 0
|
||||
}
|
||||
|
||||
project_dir="${LLM_AGENT_VAR_PROJECT_DIR:-.}"
|
||||
project_dir=$(cd "$project_dir" 2>/dev/null && pwd) || fail "project_dir does not exist: $project_dir"
|
||||
|
||||
plans_dir="${LLM_AGENT_VAR_PLANS_DIR:-plans}"
|
||||
[[ "$plans_dir" != /* ]] && plans_dir="$project_dir/$plans_dir"
|
||||
steps_dir="$plans_dir/steps"
|
||||
handoffs_dir="$plans_dir/handoffs"
|
||||
notes_path="$plans_dir/NOTES.md"
|
||||
|
||||
[[ -d "$steps_dir" ]] || fail "No step plans directory at $steps_dir (expected <plans_dir>/steps/NN-<slug>.md)"
|
||||
|
||||
frontmatter() {
|
||||
awk '/^---[[:space:]]*$/{n++; next} n==1{print} n>=2{exit}' "$1"
|
||||
}
|
||||
|
||||
fm_value() {
|
||||
echo "$1" | grep -E "^$2:" | head -1 | sed -E "s/^$2:[[:space:]]*//" | sed -E 's/^["'"'"']|["'"'"']$//g'
|
||||
}
|
||||
|
||||
step="${LLM_AGENT_VAR_STEP:-next}"
|
||||
if [[ "$step" == "next" ]]; then
|
||||
prompt_step=$(echo "$state" | jq -r '.initial_prompt // ""' | grep -oiE 'step[[:space:]#:]*[0-9]+' | head -1 | grep -oE '[0-9]+' || true)
|
||||
[[ -n "$prompt_step" ]] && step="$prompt_step"
|
||||
fi
|
||||
|
||||
plan_file=""
|
||||
if [[ "$step" == "next" ]]; then
|
||||
first_pending=""
|
||||
while IFS= read -r f; do
|
||||
st=$(fm_value "$(frontmatter "$f")" "status")
|
||||
if [[ "$st" == "in-progress" ]]; then
|
||||
plan_file="$f"
|
||||
break
|
||||
fi
|
||||
[[ -z "$first_pending" && ( "$st" == "pending" || -z "$st" ) ]] && first_pending="$f"
|
||||
done < <(find "$steps_dir" -maxdepth 1 -name '*.md' | sort)
|
||||
[[ -z "$plan_file" ]] && plan_file="$first_pending"
|
||||
[[ -z "$plan_file" ]] && fail "No in-progress or pending step plans in $steps_dir"
|
||||
else
|
||||
[[ "$step" =~ ^[0-9]+$ ]] || fail "step must be a number or 'next'; got: $step"
|
||||
padded=$(printf '%02d' "$((10#$step))")
|
||||
plan_file=$(find "$steps_dir" -maxdepth 1 \( -name "${padded}-*.md" -o -name "${step}-*.md" \) | sort | head -1)
|
||||
[[ -n "$plan_file" ]] || fail "No step plan matching step $step in $steps_dir"
|
||||
fi
|
||||
|
||||
bn=$(basename "$plan_file" .md)
|
||||
num_part="${bn%%-*}"
|
||||
[[ "$num_part" =~ ^[0-9]+$ ]] || fail "Step plan filename must start with a number: $bn"
|
||||
step_number=$((10#$num_part))
|
||||
step_slug="${bn#*-}"
|
||||
|
||||
fm=$(frontmatter "$plan_file")
|
||||
step_title=$(fm_value "$fm" "title")
|
||||
[[ -z "$step_title" ]] && step_title="$step_slug"
|
||||
|
||||
deps=$(echo "$fm" | awk '/^depends_on:/{f=1; print; next} f && /^[[:space:]]*-/{print; next} f{exit}' | grep -oE '[0-9]+' || true)
|
||||
unsatisfied=""
|
||||
for dep in $deps; do
|
||||
dep_padded=$(printf '%02d' "$((10#$dep))")
|
||||
dep_handoff=$(find "$handoffs_dir" -maxdepth 1 \( -name "${dep_padded}-*.md" -o -name "${dep}-*.md" \) 2>/dev/null | sort | head -1)
|
||||
if [[ -z "$dep_handoff" ]]; then
|
||||
unsatisfied+="- step $dep: no handoff found (step not executed?)"$'\n'
|
||||
continue
|
||||
fi
|
||||
dep_result=$(fm_value "$(frontmatter "$dep_handoff")" "result")
|
||||
if [[ "$dep_result" != "complete" ]]; then
|
||||
unsatisfied+="- step $dep: handoff result is '$dep_result' (not complete): $dep_handoff"$'\n'
|
||||
fi
|
||||
done
|
||||
|
||||
prev_handoff_path="(none)"
|
||||
prev_handoff="(none - this is the first step)"
|
||||
prev_file=""
|
||||
prev_num=0
|
||||
while IFS= read -r h; do
|
||||
hn="${h##*/}"
|
||||
hn="${hn%%-*}"
|
||||
[[ "$hn" =~ ^[0-9]+$ ]] || continue
|
||||
n=$((10#$hn))
|
||||
if (( n < step_number && n >= prev_num )); then
|
||||
prev_num=$n
|
||||
prev_file="$h"
|
||||
fi
|
||||
done < <(find "$handoffs_dir" -maxdepth 1 -name '*.md' 2>/dev/null | sort)
|
||||
if [[ -n "$prev_file" ]]; then
|
||||
prev_handoff_path="$prev_file"
|
||||
prev_handoff=$(head -c 16000 "$prev_file")
|
||||
fi
|
||||
|
||||
notes="(none)"
|
||||
[[ -f "$notes_path" ]] && notes=$(head -c 8000 "$notes_path")
|
||||
|
||||
step_plan=$(head -c 24000 "$plan_file")
|
||||
handoff_path="$handoffs_dir/$(basename "$plan_file")"
|
||||
|
||||
tmp=$(mktemp)
|
||||
awk 'BEGIN{n=0} /^---[[:space:]]*$/{n++; print; next} n==1 && /^status:/{print "status: in-progress"; next} {print}' "$plan_file" > "$tmp" && mv "$tmp" "$plan_file"
|
||||
|
||||
next_node="orient"
|
||||
blocking_reason=""
|
||||
if [[ -n "$unsatisfied" ]]; then
|
||||
next_node="gate_blocked"
|
||||
blocking_reason="Unsatisfied dependencies:"$'\n'"$unsatisfied"
|
||||
fi
|
||||
|
||||
jq -nc \
|
||||
--arg pd "$project_dir" \
|
||||
--arg pl "$plans_dir" \
|
||||
--argjson sn "$step_number" \
|
||||
--arg ss "$step_slug" \
|
||||
--arg st "$step_title" \
|
||||
--arg spp "$plan_file" \
|
||||
--arg sp "$step_plan" \
|
||||
--arg php "$prev_handoff_path" \
|
||||
--arg ph "$prev_handoff" \
|
||||
--arg np "$notes_path" \
|
||||
--arg no "$notes" \
|
||||
--arg hp "$handoff_path" \
|
||||
--arg br "$blocking_reason" \
|
||||
--arg nx "$next_node" \
|
||||
'{
|
||||
"project_dir": $pd,
|
||||
"plans_dir": $pl,
|
||||
"step_number": $sn,
|
||||
"step_slug": $ss,
|
||||
"step_title": $st,
|
||||
"step_plan_path": $spp,
|
||||
"step_plan": $sp,
|
||||
"prev_handoff_path": $php,
|
||||
"prev_handoff": $ph,
|
||||
"notes_path": $np,
|
||||
"notes": $no,
|
||||
"handoff_path": $hp,
|
||||
"blocking_reason": $br,
|
||||
"_next": $nx
|
||||
}'
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if [[ -n "${GRAPH_STATE_FILE:-}" ]]; then
|
||||
state=$(cat "$GRAPH_STATE_FILE")
|
||||
elif [[ -n "${GRAPH_STATE:-}" ]]; then
|
||||
state="$GRAPH_STATE"
|
||||
else
|
||||
state='{}'
|
||||
fi
|
||||
|
||||
feedback=$(echo "$state" | jq -r '.user_feedback // ""')
|
||||
|
||||
if [[ -z "$feedback" ]]; then
|
||||
jq -nc '{"_next": "get_revision"}'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
fix_instructions=$(printf '## Revision requested by the user at the step approval gate\n\nAddress these comments with minimal edits, then the step re-verifies and the handoff is rewritten:\n\n%s' \
|
||||
"$feedback")
|
||||
|
||||
jq -nc \
|
||||
--arg 'fi' "$fix_instructions" \
|
||||
'{
|
||||
"fix_instructions": $fi,
|
||||
"_next": "implement"
|
||||
}'
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if [[ -n "${GRAPH_STATE_FILE:-}" ]]; then
|
||||
state=$(cat "$GRAPH_STATE_FILE")
|
||||
elif [[ -n "${GRAPH_STATE:-}" ]]; then
|
||||
state="$GRAPH_STATE"
|
||||
else
|
||||
state='{}'
|
||||
fi
|
||||
|
||||
coder_result=$(echo "$state" | jq -r '.coder_result // ""')
|
||||
|
||||
case "$coder_result" in
|
||||
*CODER_COMPLETE*)
|
||||
jq -nc '{"_next": "verify_format_lint"}'
|
||||
;;
|
||||
*CODER_REJECTED*)
|
||||
jq -nc '{"_next": "end_rejected"}'
|
||||
;;
|
||||
*CODER_FAILED*)
|
||||
jq -nc '{"blocking_reason": "coder fix-loop exhausted; see coder result", "_next": "end_failure"}'
|
||||
;;
|
||||
*)
|
||||
jq -nc '{"blocking_reason": "coder returned no recognizable sentinel (expected CODER_COMPLETE / CODER_REJECTED / CODER_FAILED)", "_next": "end_failure"}'
|
||||
;;
|
||||
esac
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if [[ -n "${GRAPH_STATE_FILE:-}" ]]; then
|
||||
state=$(cat "$GRAPH_STATE_FILE")
|
||||
elif [[ -n "${GRAPH_STATE:-}" ]]; then
|
||||
state="$GRAPH_STATE"
|
||||
else
|
||||
state='{}'
|
||||
fi
|
||||
|
||||
review_report=$(echo "$state" | jq -r '.review_report // ""')
|
||||
review_attempts=$(echo "$state" | jq -r '.review_attempts // 0')
|
||||
max_review_attempts=$(echo "$state" | jq -r '.max_review_attempts // 1')
|
||||
|
||||
if ! grep -qF "🔴" <<< "$review_report"; then
|
||||
jq -nc '{"_next": "write_handoff"}'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if (( review_attempts >= max_review_attempts )); then
|
||||
jq -nc '{"_next": "write_handoff"}'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
next_review=$((review_attempts + 1))
|
||||
fix_instructions=$(printf '## Independent review findings (attempt %d of %d)\n\nAn independent reviewer flagged CRITICAL (🔴) findings. Address ONLY the 🔴 findings with minimal edits. Do not refactor unrelated code.\n\n%s' \
|
||||
"$next_review" "$max_review_attempts" "$review_report")
|
||||
|
||||
jq -nc \
|
||||
--argjson n "$next_review" \
|
||||
--arg 'fi' "$fix_instructions" \
|
||||
'{
|
||||
"review_attempts": $n,
|
||||
"fix_instructions": $fi,
|
||||
"needs_independent_review": false,
|
||||
"_next": "implement"
|
||||
}'
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if [[ -n "${GRAPH_STATE_FILE:-}" ]]; then
|
||||
state=$(cat "$GRAPH_STATE_FILE")
|
||||
elif [[ -n "${GRAPH_STATE:-}" ]]; then
|
||||
state="$GRAPH_STATE"
|
||||
else
|
||||
state='{}'
|
||||
fi
|
||||
|
||||
has_major=$(echo "$state" | jq -r '.has_major_deviation // false')
|
||||
|
||||
if [[ "${STEP_AUTOAPPROVE:-0}" == "1" ]]; then
|
||||
jq -nc '{"_next": "implement"}'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "$has_major" == "true" ]]; then
|
||||
jq -nc '{"_next": "gate_deviation"}'
|
||||
else
|
||||
jq -nc '{"_next": "implement"}'
|
||||
fi
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if [[ -n "${GRAPH_STATE_FILE:-}" ]]; then
|
||||
state=$(cat "$GRAPH_STATE_FILE")
|
||||
elif [[ -n "${GRAPH_STATE:-}" ]]; then
|
||||
state="$GRAPH_STATE"
|
||||
else
|
||||
state='{}'
|
||||
fi
|
||||
|
||||
needs_review=$(echo "$state" | jq -r '.needs_independent_review // false')
|
||||
|
||||
if [[ "${STEP_SKIP_REVIEW:-0}" == "1" ]]; then
|
||||
jq -nc '{"_next": "write_handoff"}'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "$needs_review" == "true" ]]; then
|
||||
jq -nc '{"_next": "independent_review"}'
|
||||
else
|
||||
jq -nc '{"_next": "write_handoff"}'
|
||||
fi
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env bash
|
||||
set -uo pipefail
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
source "$(dirname "$0")/../../.shared/utils.sh"
|
||||
|
||||
if [[ -n "${GRAPH_STATE_FILE:-}" ]]; then
|
||||
state=$(cat "$GRAPH_STATE_FILE")
|
||||
elif [[ -n "${GRAPH_STATE:-}" ]]; then
|
||||
state="$GRAPH_STATE"
|
||||
else
|
||||
state='{}'
|
||||
fi
|
||||
|
||||
project_dir=$(echo "$state" | jq -r '.project_dir // "."')
|
||||
|
||||
if [[ -n "${BUILD_CMD:-}" ]]; then
|
||||
cmd="$BUILD_CMD"
|
||||
else
|
||||
project_info=$(detect_project "$project_dir")
|
||||
cmd=$(echo "$project_info" | jq -r '.check // .build // ""')
|
||||
fi
|
||||
|
||||
if [[ -z "$cmd" || "$cmd" == "null" ]]; then
|
||||
jq -nc '{
|
||||
"build_ok": true,
|
||||
"build_output": "(no build/check command available for this project type)",
|
||||
"_next": "verify_tests"
|
||||
}'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
exit_code=0
|
||||
output=$(cd "$project_dir" && eval "$cmd" 2>&1) || exit_code=$?
|
||||
|
||||
if (( exit_code == 0 )); then
|
||||
jq -nc \
|
||||
--arg out "Ran: $cmd
|
||||
|
||||
$output" \
|
||||
'{
|
||||
"build_ok": true,
|
||||
"build_output": $out,
|
||||
"_next": "verify_tests"
|
||||
}'
|
||||
else
|
||||
jq -nc \
|
||||
--arg out "Ran: $cmd
|
||||
Exit code: $exit_code
|
||||
|
||||
$output" \
|
||||
'{
|
||||
"build_ok": false,
|
||||
"build_output": $out,
|
||||
"_next": "fix_loop_gate"
|
||||
}'
|
||||
fi
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env bash
|
||||
set -uo pipefail
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
source "$(dirname "$0")/../../.shared/utils.sh"
|
||||
|
||||
if [[ -n "${GRAPH_STATE_FILE:-}" ]]; then
|
||||
state=$(cat "$GRAPH_STATE_FILE")
|
||||
elif [[ -n "${GRAPH_STATE:-}" ]]; then
|
||||
state="$GRAPH_STATE"
|
||||
else
|
||||
state='{}'
|
||||
fi
|
||||
|
||||
project_dir=$(echo "$state" | jq -r '.project_dir // "."')
|
||||
project_type=$(detect_project "$project_dir" | jq -r '.type // "unknown"')
|
||||
|
||||
format_cmd="${FORMAT_CMD:-}"
|
||||
if [[ -z "$format_cmd" ]]; then
|
||||
case "$project_type" in
|
||||
rust) format_cmd="cargo fmt" ;;
|
||||
go) format_cmd="gofmt -w ." ;;
|
||||
python) command -v ruff &>/dev/null && format_cmd="ruff format ." ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [[ -z "$format_cmd" ]]; then
|
||||
format_output="(no format command configured for project type '$project_type'; skipped. Set FORMAT_CMD to enable.)"
|
||||
else
|
||||
fmt_rc=0
|
||||
fmt_out=$(cd "$project_dir" && eval "$format_cmd" 2>&1) || fmt_rc=$?
|
||||
format_output="Ran: $format_cmd
|
||||
Exit code: $fmt_rc
|
||||
|
||||
$fmt_out"
|
||||
fi
|
||||
|
||||
lint_cmd="${LINT_CMD:-}"
|
||||
if [[ -z "$lint_cmd" ]]; then
|
||||
jq -nc \
|
||||
--arg fo "$format_output" \
|
||||
'{
|
||||
"format_output": $fo,
|
||||
"lint_ok": true,
|
||||
"lint_output": "(no LINT_CMD configured; linting is covered by the build/check command)",
|
||||
"_next": "verify_build"
|
||||
}'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
lint_rc=0
|
||||
lint_out=$(cd "$project_dir" && eval "$lint_cmd" 2>&1) || lint_rc=$?
|
||||
|
||||
if (( lint_rc == 0 )); then
|
||||
jq -nc \
|
||||
--arg fo "$format_output" \
|
||||
--arg lo "Ran: $lint_cmd
|
||||
|
||||
$lint_out" \
|
||||
'{
|
||||
"format_output": $fo,
|
||||
"lint_ok": true,
|
||||
"lint_output": $lo,
|
||||
"_next": "verify_build"
|
||||
}'
|
||||
else
|
||||
jq -nc \
|
||||
--arg fo "$format_output" \
|
||||
--arg lo "Ran: $lint_cmd
|
||||
Exit code: $lint_rc
|
||||
|
||||
$lint_out" \
|
||||
'{
|
||||
"format_output": $fo,
|
||||
"lint_ok": false,
|
||||
"lint_output": $lo,
|
||||
"_next": "fix_loop_gate"
|
||||
}'
|
||||
fi
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env bash
|
||||
set -uo pipefail
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
source "$(dirname "$0")/../../.shared/utils.sh"
|
||||
|
||||
if [[ -n "${GRAPH_STATE_FILE:-}" ]]; then
|
||||
state=$(cat "$GRAPH_STATE_FILE")
|
||||
elif [[ -n "${GRAPH_STATE:-}" ]]; then
|
||||
state="$GRAPH_STATE"
|
||||
else
|
||||
state='{}'
|
||||
fi
|
||||
|
||||
project_dir=$(echo "$state" | jq -r '.project_dir // "."')
|
||||
|
||||
if [[ -n "${TEST_CMD:-}" ]]; then
|
||||
cmd="$TEST_CMD"
|
||||
else
|
||||
project_info=$(detect_project "$project_dir")
|
||||
cmd=$(echo "$project_info" | jq -r '.test // ""')
|
||||
fi
|
||||
|
||||
if [[ -z "$cmd" || "$cmd" == "null" ]]; then
|
||||
jq -nc '{
|
||||
"tests_ok": true,
|
||||
"tests_output": "(no test command available for this project type)",
|
||||
"_next": "edge_case_sweep"
|
||||
}'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
exit_code=0
|
||||
output=$(cd "$project_dir" && eval "$cmd" 2>&1) || exit_code=$?
|
||||
|
||||
if (( exit_code == 0 )); then
|
||||
jq -nc \
|
||||
--arg out "Ran: $cmd
|
||||
|
||||
$output" \
|
||||
'{
|
||||
"tests_ok": true,
|
||||
"tests_output": $out,
|
||||
"_next": "edge_case_sweep"
|
||||
}'
|
||||
else
|
||||
jq -nc \
|
||||
--arg out "Ran: $cmd
|
||||
Exit code: $exit_code
|
||||
|
||||
$output" \
|
||||
'{
|
||||
"tests_ok": false,
|
||||
"tests_output": $out,
|
||||
"_next": "fix_loop_gate"
|
||||
}'
|
||||
fi
|
||||
@@ -18,6 +18,11 @@
|
||||
"type": "stdio",
|
||||
"command": "uvx",
|
||||
"args": ["duckduckgo-mcp-server"]
|
||||
},
|
||||
"iwe": {
|
||||
"type": "stdio",
|
||||
"command": "iwec",
|
||||
"args": ["--project", "."]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+81
@@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Structural code search using AST patterns (ast-grep). Matches syntax trees, not text,
|
||||
# so it finds code regardless of formatting: function calls with any arguments, definitions, etc.
|
||||
# Use meta-variables in patterns: $NAME matches one AST node, $$$ matches zero or more nodes.
|
||||
# Patterns must be COMPLETE, valid AST nodes in the target language: 'fn $NAME($$$) { $$$ }'
|
||||
# matches Rust fn definitions (with body - 'fn $NAME($$$)' alone parses as nothing and matches
|
||||
# nothing), 'foo($$$)' matches all calls to foo, '$X.unwrap()' matches all unwrap calls.
|
||||
# Prefer this over fs_grep when searching for code STRUCTURE (calls, definitions, signatures);
|
||||
# use fs_grep for plain text, comments, or strings.
|
||||
|
||||
# @option --pattern! The AST pattern to search for (must parse as valid code in the target language)
|
||||
# @option --lang The target language (e.g. rust, typescript, tsx, javascript, python, go, java, c, cpp, kotlin, swift, ruby, php, css, html, yaml, json). Strongly recommended; without it files of every supported language are scanned
|
||||
# @option --path The directory OR file to search in (defaults to current working directory)
|
||||
# @option --glob File glob to narrow the search (e.g. "src/**/*.rs", "!**/tests/**")
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
MAX_RESULTS=100
|
||||
MAX_OUTPUT_BYTES=32768
|
||||
|
||||
resolve_binary() {
|
||||
if command -v ast-grep &>/dev/null; then
|
||||
echo "ast-grep"
|
||||
return 0
|
||||
fi
|
||||
if command -v sg &>/dev/null && sg --version 2>/dev/null | grep -qi 'ast-grep'; then
|
||||
echo "sg"
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
main() {
|
||||
# shellcheck disable=SC2154
|
||||
local pattern="$argc_pattern"
|
||||
local lang="${argc_lang:-}"
|
||||
local search_path="${argc_path:-.}"
|
||||
local glob="${argc_glob:-}"
|
||||
|
||||
local bin
|
||||
if ! bin=$(resolve_binary); then
|
||||
printf 'ast-grep is not installed. Fall back to fs_grep for this search.\nTo enable structural search, install ast-grep:\n cargo install ast-grep --locked\n brew install ast-grep\n npm i -g @ast-grep/cli\n' >> "$LLM_OUTPUT"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ ! -e "$search_path" ]]; then
|
||||
echo "Error: path not found: $search_path" >> "$LLM_OUTPUT"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local args=(run --pattern "$pattern" --color never --heading never)
|
||||
[[ -n "$lang" ]] && args+=(--lang "$lang")
|
||||
[[ -n "$glob" ]] && args+=(--globs "$glob")
|
||||
args+=("$search_path")
|
||||
|
||||
local output exit_code=0
|
||||
output=$("$bin" "${args[@]}" 2>&1) || exit_code=$?
|
||||
|
||||
if [[ -z "$output" ]]; then
|
||||
echo "No structural matches found for: $pattern" >> "$LLM_OUTPUT"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if (( exit_code > 1 )); then
|
||||
printf 'ast-grep failed (exit %s):\n%s\n\nHint: the pattern must be valid %s syntax. Meta-variables: $NAME (one node), $$$ (zero or more).\n' \
|
||||
"$exit_code" "$output" "${lang:-source}" >> "$LLM_OUTPUT"
|
||||
return 0
|
||||
fi
|
||||
|
||||
local total
|
||||
total=$(wc -l <<< "$output")
|
||||
output=$(head -n "$MAX_RESULTS" <<< "$output" | head -c "$MAX_OUTPUT_BYTES")
|
||||
|
||||
echo "$output" >> "$LLM_OUTPUT"
|
||||
if (( total > MAX_RESULTS )); then
|
||||
printf '\n(Showing %s of %s matching lines. Narrow with --glob, --lang, or a more specific pattern.)\n' \
|
||||
"$MAX_RESULTS" "$total" >> "$LLM_OUTPUT"
|
||||
fi
|
||||
}
|
||||
@@ -10,5 +10,13 @@ set -e
|
||||
|
||||
main() {
|
||||
# shellcheck disable=SC2154
|
||||
cat "$argc_path" >> "$LLM_OUTPUT" 2>&1 || echo "No such file or path: $argc_path" >> "$LLM_OUTPUT"
|
||||
local path="$argc_path"
|
||||
|
||||
# An empty result is shown to the model as the opaque literal "DONE"; emit a note instead.
|
||||
if [[ -f "$path" && ! -s "$path" ]]; then
|
||||
echo "(empty file: $path)" >> "$LLM_OUTPUT"
|
||||
return 0
|
||||
fi
|
||||
|
||||
cat "$path" >> "$LLM_OUTPUT" 2>&1 || echo "No such file or path: $path" >> "$LLM_OUTPUT"
|
||||
}
|
||||
@@ -17,8 +17,8 @@ main() {
|
||||
local search_path="${argc_path:-.}"
|
||||
|
||||
if [[ ! -d "$search_path" ]]; then
|
||||
echo "Error: directory not found: $search_path" >> "$LLM_OUTPUT"
|
||||
return 1
|
||||
echo "Error: directory not found: $search_path" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local results
|
||||
|
||||
@@ -21,8 +21,8 @@ main() {
|
||||
local include_filter="${argc_include:-}"
|
||||
|
||||
if [[ ! -e "$search_path" ]]; then
|
||||
echo "Error: path not found: $search_path" >> "$LLM_OUTPUT"
|
||||
return 1
|
||||
echo "Error: path not found: $search_path" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local grep_args=(-nH --color=never)
|
||||
|
||||
@@ -9,5 +9,18 @@ set -e
|
||||
|
||||
main() {
|
||||
# shellcheck disable=SC2154
|
||||
ls -1 "$argc_path" >> "$LLM_OUTPUT" 2>&1 || echo "No such path: $argc_path" >> "$LLM_OUTPUT"
|
||||
local path="$argc_path"
|
||||
local output
|
||||
|
||||
if ! output=$(ls -1 "$path" 2>&1); then
|
||||
echo "$output" >> "$LLM_OUTPUT"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# An empty result is shown to the model as the opaque literal "DONE"; emit a note instead.
|
||||
if [[ -z "$output" ]]; then
|
||||
echo "(empty directory: $path)" >> "$LLM_OUTPUT"
|
||||
else
|
||||
echo "$output" >> "$LLM_OUTPUT"
|
||||
fi
|
||||
}
|
||||
@@ -8,8 +8,8 @@ set -e
|
||||
# Use the grep tool to find specific content before reading, then read with offset to target the relevant section.
|
||||
|
||||
# @option --path! The absolute path to the file or directory to read
|
||||
# @option --offset The line number to start reading from (1-indexed, default: 1)
|
||||
# @option --limit The maximum number of lines to read (default: 2000)
|
||||
# @option --offset <INT> The line number to start reading from (1-indexed, default: 1)
|
||||
# @option --limit <INT> The maximum number of lines to read (default: 2000)
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
@@ -23,8 +23,8 @@ main() {
|
||||
local limit="${argc_limit:-2000}"
|
||||
|
||||
if [[ ! -e "$target" ]]; then
|
||||
echo "Error: path not found: $target" >> "$LLM_OUTPUT"
|
||||
return 1
|
||||
echo "Error: path not found: $target" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -d "$target" ]]; then
|
||||
@@ -33,9 +33,20 @@ main() {
|
||||
fi
|
||||
|
||||
local total_lines file_bytes
|
||||
total_lines=$(wc -l < "$target" 2>/dev/null || echo 0)
|
||||
# awk counts a final line that lacks a trailing newline; wc -l would undercount it by one.
|
||||
total_lines=$(awk 'END { print NR }' "$target" 2>/dev/null || echo 0)
|
||||
file_bytes=$(wc -c < "$target" 2>/dev/null || echo 0)
|
||||
|
||||
if [[ "$total_lines" -eq 0 ]]; then
|
||||
echo "(file is empty: $target)" >> "$LLM_OUTPUT"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ "$offset" -gt "$total_lines" ]]; then
|
||||
echo "(offset $offset is past the end of the file, which has $total_lines lines)" >> "$LLM_OUTPUT"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ "$file_bytes" -gt "$MAX_BYTES" ]] && [[ "$offset" -eq 1 ]] && [[ "$limit" -ge 2000 ]]; then
|
||||
{
|
||||
echo "Warning: Large file (${file_bytes} bytes, ${total_lines} lines). Showing first ${limit} lines."
|
||||
@@ -48,7 +59,8 @@ main() {
|
||||
|
||||
sed -n "${offset},${end_line}p" "$target" 2>/dev/null | {
|
||||
local line_num=$offset
|
||||
while IFS= read -r line; do
|
||||
# `|| [[ -n "$line" ]]` keeps the final line when the file has no trailing newline.
|
||||
while IFS= read -r line || [[ -n "$line" ]]; do
|
||||
if [[ ${#line} -gt $MAX_LINE_LENGTH ]]; then
|
||||
line="${line:0:$MAX_LINE_LENGTH}... (truncated)"
|
||||
fi
|
||||
|
||||
@@ -552,7 +552,7 @@ patch_file() {
|
||||
continue
|
||||
}
|
||||
|
||||
if (line ~ /^@@ /) {
|
||||
if (line ~ /^@@/) {
|
||||
mode = "hunk"
|
||||
hunkIndex++
|
||||
patchLineIndex++
|
||||
@@ -585,6 +585,10 @@ patch_file() {
|
||||
|
||||
if (hunkIndex == 0) {
|
||||
print "error: no patch" > "/dev/stderr"
|
||||
print "" > "/dev/stderr"
|
||||
print "No hunk header was found. Each hunk must start with a line beginning \"@@\"" > "/dev/stderr"
|
||||
print "(for example \"@@ ... @@\" or \"@@ -1,4 +1,4 @@\"). Inside a hunk, context lines" > "/dev/stderr"
|
||||
print "start with a single space, removed lines with \"-\", and added lines with \"+\"." > "/dev/stderr"
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
---
|
||||
name: diagnose
|
||||
enabled_tools:
|
||||
- execute_command
|
||||
- fs_cat
|
||||
- fs_ls
|
||||
- web_search_coyote
|
||||
skills_enabled: false
|
||||
auto_continue: true
|
||||
max_auto_continues: 10
|
||||
---
|
||||
You are an expert systems troubleshooter: equal parts SRE, sysadmin, network engineer, and homelab tinkerer. Your job
|
||||
is to diagnose and fix technical problems of any kind: services that won't start, networking failures, container
|
||||
issues, driver problems, permission errors, misbehaving hardware, broken configs, or anything else. You are not limited
|
||||
to code.
|
||||
|
||||
<system>
|
||||
os: {{__os__}}
|
||||
distro: {{__os_distro__}}
|
||||
arch: {{__arch__}}
|
||||
shell: {{__shell__}}
|
||||
cwd: {{__cwd__}}
|
||||
now: {{__now__}}
|
||||
</system>
|
||||
|
||||
## Prime Directive
|
||||
|
||||
**You run the diagnostics yourself.** Never tell the user to run a command and paste the output back. Use the
|
||||
`execute_command` tool to gather evidence directly, then interpret the results for them. The user should watch you
|
||||
work, not act as your terminal.
|
||||
|
||||
## Diagnostic Loop
|
||||
|
||||
Work the loop until the problem is solved or genuinely blocked:
|
||||
|
||||
1. **Reproduce & observe.** Run the failing thing (or inspect its state) to see the actual error with your own eyes.
|
||||
Never diagnose from the user's paraphrase alone.
|
||||
2. **Establish what changed.** Most breakage follows a change: updates, config edits, reboots, new hardware, expired
|
||||
certs/leases. Check timestamps, package logs, and recent history early.
|
||||
3. **Check the dumb stuff first.** Is the service running? Is it enabled? Is the interface up? Is the disk full? Is
|
||||
DNS resolving? Is the clock right? Cheap checks before deep theories.
|
||||
4. **Isolate by layer.** Split the problem space in half with each test:
|
||||
- Networking: bottom-up — link → IP/DHCP → routing → DNS → transport → application.
|
||||
- Software: process alive? → logs → config → dependencies/permissions → environment → binary itself.
|
||||
- Containers: daemon → image → container state → logs → mounts/networks → host resources.
|
||||
5. **Hypothesize, then test.** State your current best hypothesis in one line before each test, and change ONE
|
||||
variable at a time. If a test disproves the hypothesis, say so and pivot; don't quietly move on.
|
||||
6. **Fix the root cause, not the symptom.** A restart that "fixes" it without explanation is a data point, not a fix.
|
||||
7. **Verify.** After any fix, re-run the original failing operation and confirm it now works. No verification, no
|
||||
victory declaration.
|
||||
|
||||
## Evidence Gathering
|
||||
|
||||
- Primary sources, in rough order of value: exit codes and stderr, service/app logs (`journalctl`, `docker logs`,
|
||||
files under `/var/log`), kernel messages (`dmesg`), state inspection (`systemctl status`, `ip`, `ss`, `df`, `free`,
|
||||
`lsblk`, `nmcli`, `docker ps/inspect`), then config files.
|
||||
- Make every command non-interactive and bounded: `--no-pager` for `journalctl`/`systemctl`, `-n`/`--since` to limit
|
||||
log output, `timeout 10 ...` for anything that might hang, `-c` counts for `ping`. Never launch interactive TUIs
|
||||
(top, htop, lazydocker itself) — use their batch/one-shot modes or underlying CLIs instead.
|
||||
- Prefer unprivileged commands. When root is genuinely required, say why and use `sudo` (the user may get a password
|
||||
prompt in their terminal — that's expected).
|
||||
- Search the web for exact error strings (quoted, with software name and version) when an error is unfamiliar or
|
||||
smells like a known bug or recent regression. Distro wikis, GitHub issues, and bug trackers beat guessing.
|
||||
|
||||
## Safety Rules
|
||||
|
||||
Commands fall into three tiers:
|
||||
|
||||
1. **Read-only / inspection** (status, logs, listing, ping, dig, cat): run freely, no permission needed.
|
||||
2. **Reversible state changes** (restart a service, bounce an interface, recreate a container, edit a config after
|
||||
backing it up): announce what you're about to do and why in one sentence, then do it. Back up any file before
|
||||
modifying it (`cp file file.bak.$(date +%s)`).
|
||||
3. **Destructive or hard-to-reverse actions** (deleting data or volumes, formatting, `dd`, partitioning, package
|
||||
removal, firewall flushes, forced resets): STOP and ask for explicit confirmation first, including the exact
|
||||
command and a rollback plan. Never run these on your own judgment.
|
||||
|
||||
Additional hard rules:
|
||||
|
||||
- Never print or transmit secrets. If command output contains tokens, keys, or passwords, redact them in your response.
|
||||
- Never disable security controls (firewalls, SELinux/AppArmor, certificate validation) as a "fix" — at most as a
|
||||
temporary, clearly-labeled isolation test, restored immediately after.
|
||||
- If the evidence points to failing hardware or risk of data loss, stop, say so plainly, and present options before
|
||||
touching anything else.
|
||||
|
||||
## When to Stop Gathering Evidence
|
||||
|
||||
Once you have two or more independent pieces of evidence pointing to the same root cause, **stop gathering and deliver your diagnosis**. Do not add more verification steps to verify your verification. If you notice yourself thinking "let me just confirm one more thing" after you have already reached a conclusion, that is the signal to stop and explain the diagnosis instead. More data is not always better — a timely diagnosis with strong evidence beats an exhaustive audit.
|
||||
|
||||
## Communication
|
||||
|
||||
- Lead with what you found, not what you did. Then show the key evidence: the command and the relevant lines of its
|
||||
output (trimmed — never dump walls of text).
|
||||
- When the problem is multi-step, keep a running todo list so the user can follow the investigation.
|
||||
- On resolution, close with a short summary: **root cause → fix applied → how it was verified → how to prevent it**.
|
||||
- If you're blocked (needs physical access, a password you don't have, a reboot decision), say exactly what you need
|
||||
and what you'll do once you have it.
|
||||
@@ -9,8 +9,8 @@ security/configuration settings. The analysis aims to ensure a thorough understa
|
||||
structured and operates, enabling the creation of new files, maintaining consistency with existing practices, and the
|
||||
potential implementation of best practices.
|
||||
|
||||
Should the root directory contain a `COYOTE.md` file, this was generated by Coyote and should be used as a reference
|
||||
point for all analysis, style questions, etc.
|
||||
Should the root directory contain a `COYOTE.md` (or `AGENTS.md`/`CLAUDE.md`) file, this contains human-curated project
|
||||
instructions and should be used as a reference point for all analysis, style questions, etc.
|
||||
|
||||
**Objective:** Enable the AI to thoroughly analyze a software repository, providing detailed insights and guidelines on
|
||||
all relevant aspects for understanding and potentially contributing to the project.
|
||||
|
||||
+56
-94
@@ -5,20 +5,19 @@
|
||||
# sbx cp $HOME/.config/coyote/ testing:/home/agent/.config/
|
||||
# sbx cp $HOME/.coyote_password testing:/home/agent/
|
||||
# sbx run testing --kit ./sbx-kit/
|
||||
schemaVersion: "1"
|
||||
kind: agent
|
||||
schemaVersion: '1'
|
||||
kind: sandbox
|
||||
name: coyote
|
||||
displayName: Coyote
|
||||
description: >
|
||||
An all-in-one, batteries-included LLM CLI tool featuring Shell Assistant,
|
||||
CLI & REPL mode, RAG, AI tools & agents, MCP servers, skills, and macros.
|
||||
|
||||
agent:
|
||||
image: "docker/sandbox-templates:shell-docker"
|
||||
sandbox:
|
||||
image: 'darkalex17/coyote:v0.7.4'
|
||||
aiFilename: COYOTE.md
|
||||
# persistence: persistent
|
||||
entrypoint:
|
||||
run: ["bash", "-lc", "exec /home/agent/.cargo/bin/coyote"]
|
||||
run: ['bash', '-lc', 'exec /home/agent/.cargo/bin/coyote']
|
||||
|
||||
network:
|
||||
# Proxy-managed LLM providers: the proxy substitutes `proxy-managed` for
|
||||
@@ -51,96 +50,96 @@ network:
|
||||
serviceAuth:
|
||||
openai:
|
||||
headerName: Authorization
|
||||
valueFormat: "Bearer %s"
|
||||
valueFormat: 'Bearer %s'
|
||||
anthropic:
|
||||
headerName: x-api-key
|
||||
valueFormat: "%s"
|
||||
valueFormat: '%s'
|
||||
gemini:
|
||||
headerName: x-goog-api-key
|
||||
valueFormat: "%s"
|
||||
valueFormat: '%s'
|
||||
cohere:
|
||||
headerName: Authorization
|
||||
valueFormat: "Bearer %s"
|
||||
valueFormat: 'Bearer %s'
|
||||
groq:
|
||||
headerName: Authorization
|
||||
valueFormat: "Bearer %s"
|
||||
valueFormat: 'Bearer %s'
|
||||
openrouter:
|
||||
headerName: Authorization
|
||||
valueFormat: "Bearer %s"
|
||||
valueFormat: 'Bearer %s'
|
||||
ai21:
|
||||
headerName: Authorization
|
||||
valueFormat: "Bearer %s"
|
||||
valueFormat: 'Bearer %s'
|
||||
cloudflare:
|
||||
headerName: Authorization
|
||||
valueFormat: "Bearer %s"
|
||||
valueFormat: 'Bearer %s'
|
||||
deepinfra:
|
||||
headerName: Authorization
|
||||
valueFormat: "Bearer %s"
|
||||
valueFormat: 'Bearer %s'
|
||||
deepseek:
|
||||
headerName: Authorization
|
||||
valueFormat: "Bearer %s"
|
||||
valueFormat: 'Bearer %s'
|
||||
mistral:
|
||||
headerName: Authorization
|
||||
valueFormat: "Bearer %s"
|
||||
valueFormat: 'Bearer %s'
|
||||
perplexity:
|
||||
headerName: Authorization
|
||||
valueFormat: "Bearer %s"
|
||||
valueFormat: 'Bearer %s'
|
||||
voyageai:
|
||||
headerName: Authorization
|
||||
valueFormat: "Bearer %s"
|
||||
valueFormat: 'Bearer %s'
|
||||
xai:
|
||||
headerName: Authorization
|
||||
valueFormat: "Bearer %s"
|
||||
valueFormat: 'Bearer %s'
|
||||
jina:
|
||||
headerName: Authorization
|
||||
valueFormat: "Bearer %s"
|
||||
valueFormat: 'Bearer %s'
|
||||
ernie:
|
||||
headerName: Authorization
|
||||
valueFormat: "Bearer %s"
|
||||
valueFormat: 'Bearer %s'
|
||||
hunyuan:
|
||||
headerName: Authorization
|
||||
valueFormat: "Bearer %s"
|
||||
valueFormat: 'Bearer %s'
|
||||
minimax:
|
||||
headerName: Authorization
|
||||
valueFormat: "Bearer %s"
|
||||
valueFormat: 'Bearer %s'
|
||||
moonshot:
|
||||
headerName: Authorization
|
||||
valueFormat: "Bearer %s"
|
||||
valueFormat: 'Bearer %s'
|
||||
qianwen:
|
||||
headerName: Authorization
|
||||
valueFormat: "Bearer %s"
|
||||
valueFormat: 'Bearer %s'
|
||||
zhipuai:
|
||||
headerName: Authorization
|
||||
valueFormat: "Bearer %s"
|
||||
valueFormat: 'Bearer %s'
|
||||
allowedDomains:
|
||||
# Coyote release + self-update + model-registry sync
|
||||
- "github.com:443"
|
||||
- "api.github.com:443"
|
||||
- "raw.githubusercontent.com:443"
|
||||
- "objects.githubusercontent.com:443"
|
||||
- "*.githubusercontent.com:443"
|
||||
# Coyote install paths (cargo install + uv + rustup + Python tool deps at runtime)
|
||||
- "crates.io:443"
|
||||
- "static.crates.io:443"
|
||||
- "pypi.org:443"
|
||||
- "files.pythonhosted.org:443"
|
||||
- "astral.sh:443"
|
||||
- "sh.rustup.rs:443"
|
||||
- "static.rust-lang.org:443"
|
||||
- 'github.com:443'
|
||||
- 'api.github.com:443'
|
||||
- 'raw.githubusercontent.com:443'
|
||||
- 'objects.githubusercontent.com:443'
|
||||
- '*.githubusercontent.com:443'
|
||||
# Package managers and developer tools (cargo, uv, pip — useful at runtime for user installs)
|
||||
- 'crates.io:443'
|
||||
- 'static.crates.io:443'
|
||||
- 'pypi.org:443'
|
||||
- 'files.pythonhosted.org:443'
|
||||
- 'astral.sh:443'
|
||||
- 'sh.rustup.rs:443'
|
||||
- 'static.rust-lang.org:443'
|
||||
|
||||
# LLM model OAuth + API endpoints
|
||||
- "claude.ai:443"
|
||||
- "console.anthropic.com:443"
|
||||
- "accounts.google.com:443"
|
||||
- 'claude.ai:443'
|
||||
- 'console.anthropic.com:443'
|
||||
- 'accounts.google.com:443'
|
||||
# *.googleapis.com covers oauth2 + userinfo + VertexAI regional endpoints
|
||||
# (*-aiplatform.googleapis.com). Do not narrow without re-checking VertexAI.
|
||||
- "*.googleapis.com:443"
|
||||
- '*.googleapis.com:443'
|
||||
|
||||
# Bedrock and GitHub Models use signed / GitHub-PAT auth that the proxy
|
||||
# cannot rewrite. Domains are allow-listed; credentials must be injected
|
||||
# separately (see README "Extending").
|
||||
- "*.amazonaws.com:443"
|
||||
- "models.inference.ai.azure.com:443"
|
||||
- '*.amazonaws.com:443'
|
||||
- 'models.inference.ai.azure.com:443'
|
||||
|
||||
credentials:
|
||||
sources:
|
||||
@@ -211,8 +210,10 @@ credentials:
|
||||
|
||||
environment:
|
||||
variables:
|
||||
IS_SANDBOX: "1"
|
||||
IS_SANDBOX: '1'
|
||||
COYOTE_LOG_LEVEL: INFO
|
||||
COYOTE_CONFIG_DIR: /home/agent/.config/coyote
|
||||
EDITOR: nano
|
||||
proxyManaged:
|
||||
- OPENAI_API_KEY
|
||||
- ANTHROPIC_API_KEY
|
||||
@@ -238,57 +239,18 @@ environment:
|
||||
- ZHIPUAI_API_KEY
|
||||
|
||||
commands:
|
||||
install:
|
||||
- command: |
|
||||
sudo apt-get update &&
|
||||
sudo apt-get install -y \
|
||||
jq curl git \
|
||||
build-essential pkg-config \
|
||||
cmake \
|
||||
clang libclang-dev \
|
||||
musl-tools \
|
||||
libssl-dev \
|
||||
pandoc \
|
||||
bzip2
|
||||
user: "1000"
|
||||
description: Install system prerequisites (including pandoc for fetch_url_via_curl)
|
||||
- command: "curl -LsSf https://astral.sh/uv/install.sh | sh"
|
||||
user: "1000"
|
||||
description: Install uv (required for Python-based custom tools)
|
||||
- command: |
|
||||
set -euo pipefail
|
||||
USQL_VERSION=$(curl -sSL https://api.github.com/repos/xo/usql/releases/latest | jq -r .tag_name | sed 's/^v//')
|
||||
ARCH=$(uname -m)
|
||||
case "$ARCH" in
|
||||
x86_64) USQL_ARCH=amd64 ;;
|
||||
aarch64) USQL_ARCH=arm64 ;;
|
||||
*) echo "Unsupported arch for usql install: $ARCH" >&2; exit 1 ;;
|
||||
esac
|
||||
TMPDIR=$(mktemp -d)
|
||||
trap 'rm -rf "$TMPDIR"' EXIT
|
||||
curl -sSL "https://github.com/xo/usql/releases/download/v${USQL_VERSION}/usql_static-${USQL_VERSION}-linux-${USQL_ARCH}.tar.bz2" -o "$TMPDIR/usql.tar.bz2"
|
||||
tar -xjf "$TMPDIR/usql.tar.bz2" -C "$TMPDIR"
|
||||
sudo install -m 0755 "$TMPDIR/usql_static" /usr/local/bin/usql
|
||||
user: "1000"
|
||||
description: Install the usql universal SQL CLI (used by the built-in sql agent and execute_sql_code tool)
|
||||
- command: |
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \
|
||||
sh -s -- -y \
|
||||
--default-toolchain stable \
|
||||
--profile minimal \
|
||||
--target x86_64-unknown-linux-musl
|
||||
. "$HOME/.cargo/env"
|
||||
cargo install --locked coyote-ai
|
||||
user: "1000"
|
||||
description: Install Coyote AI CLI via Rust's Cargo
|
||||
|
||||
startup:
|
||||
- command: ["sh", "-c", "test -f \"$HOME/.config/coyote/config.yaml\" || coyote --info >/dev/null 2>&1 || true"]
|
||||
user: "1000"
|
||||
- command:
|
||||
[
|
||||
'sh',
|
||||
'-c',
|
||||
'test -f "$HOME/.config/coyote/config.yaml" || coyote --info >/dev/null 2>&1 || true',
|
||||
]
|
||||
user: '1000'
|
||||
background: false
|
||||
description: Bootstrap Coyote config directory on first sandbox start
|
||||
|
||||
memory: |
|
||||
agentContext: |
|
||||
## Sandbox environment
|
||||
|
||||
You are running inside a Docker sandbox launched via `sbx run coyote`. The
|
||||
|
||||
@@ -37,7 +37,7 @@ Every `agent__spawn` result includes a session_id. **Use it.**
|
||||
|
||||
Starting a fresh agent for a follow-up forces it to re-read every file it already read. That's 70%+ wasted tokens, plus the agent loses the reasoning it built up.
|
||||
|
||||
After every delegation, **store the session_id** for potential continuation.
|
||||
After every delegation, **store the session_id compression-safe** for potential continuation. Long sessions compress: chat history gets replaced by a summary, and a session_id that exists only in chat history is unresumable afterward. Embed it in the todo item for that work — `todo__add "Implement auth endpoint (coder ses_abc123)"` — or in your run-state memory file. The todo list and memory survive compression; the conversation does not.
|
||||
|
||||
## Skill nudges to delegates
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
---
|
||||
description: Systematic troubleshooting of technical issues (services, networking, containers, OS) by running diagnostic commands directly instead of asking the user to.
|
||||
enabled_tools: execute_command
|
||||
---
|
||||
A technical problem needs diagnosing. Apply this methodology strictly. Use the `execute_command` tool to gather
|
||||
evidence yourself — never ask the user to run commands and paste output back.
|
||||
|
||||
## Loop
|
||||
|
||||
1. **Reproduce first.** Run the failing thing and read the actual error before theorizing.
|
||||
2. **Ask "what changed?"** Updates, config edits, reboots, expirations. Check recent history early.
|
||||
3. **Cheap checks first.** Service running/enabled? Interface up? Disk full? DNS resolving? Clock right?
|
||||
4. **Isolate by layer, one variable at a time.** Network: link → IP → routing → DNS → transport → app.
|
||||
Software: process → logs → config → deps/permissions → environment. Containers: daemon → image → container →
|
||||
logs → mounts/networks → host.
|
||||
5. **State each hypothesis in one line before testing it.** Pivot openly when disproved.
|
||||
6. **Fix root cause, then verify** by re-running the original failing operation. No verification, no fix.
|
||||
|
||||
## When to Stop Gathering Evidence
|
||||
|
||||
Once you have two or more independent pieces of evidence pointing to the same root cause, **stop gathering and deliver your diagnosis**. Do not add more verification steps to verify your verification. If you notice yourself thinking "let me just confirm one more thing" after you have already reached a conclusion, that is the signal to stop and explain the diagnosis instead. More data is not always better — a timely diagnosis with strong evidence beats an exhaustive audit.
|
||||
|
||||
## Command Discipline
|
||||
|
||||
- Non-interactive and bounded, always: `--no-pager`, `-n`/`--since` on logs, `timeout 10` on anything that might
|
||||
hang, `-c` on ping. No TUIs — use batch modes.
|
||||
- Unprivileged first; `sudo` only when required, stating why.
|
||||
- Web-search exact quoted error strings (with software name + version) for unfamiliar errors.
|
||||
|
||||
## Safety Tiers
|
||||
|
||||
1. **Read-only** (status, logs, ls, cat, ping, dig): run freely.
|
||||
2. **Reversible changes** (service restart, interface bounce, config edit): announce in one sentence, back up files
|
||||
first (`cp file file.bak.$(date +%s)`), then do it.
|
||||
3. **Destructive** (data/volume deletion, formatting, `dd`, package removal, firewall flush): require explicit user
|
||||
confirmation with the exact command and a rollback plan. Never on your own judgment.
|
||||
|
||||
Redact any secrets appearing in command output. Never disable security controls as a "fix". Stop and present options
|
||||
if evidence suggests failing hardware or data-loss risk.
|
||||
|
||||
## Reporting
|
||||
|
||||
Lead with findings, show trimmed key evidence, and close resolved issues with: root cause → fix → verification →
|
||||
prevention.
|
||||
@@ -0,0 +1,78 @@
|
||||
---
|
||||
description: Schema and discipline for writing and reading step handoff documents - the only channel between implementation steps. Evidence must be pasted, downstream plan changes proposed not imposed. Grants filesystem access for reading and writing handoffs.
|
||||
enabled_tools: fs_read, fs_cat, fs_ls, fs_write
|
||||
---
|
||||
A handoff is the ONLY channel between step N and step N+1. The next executor runs in a fresh session: it sees the plan repo, the code, and this document — nothing else. Whatever you learned that isn't in the handoff (or in `plans/NOTES.md`) is lost. Write accordingly.
|
||||
|
||||
Handoffs live in `plans/handoffs/`, named to match their step plan: `plans/handoffs/03-<slug>.md` for `plans/steps/03-<slug>.md`.
|
||||
|
||||
## Required schema (writer)
|
||||
|
||||
Frontmatter:
|
||||
|
||||
```yaml
|
||||
---
|
||||
step: 3
|
||||
title: Add retry policy to the fetch client
|
||||
result: complete # complete | partial | blocked
|
||||
---
|
||||
```
|
||||
|
||||
Sections, all mandatory (write "None" rather than omitting — an absent section is indistinguishable from a forgotten one):
|
||||
|
||||
| Section | Contents |
|
||||
|---|---|
|
||||
| Summary | 2-4 sentences: what exists now that didn't before |
|
||||
| Completed | Task-by-task, mirroring the plan's Tasks section |
|
||||
| Not completed | Deferred or dropped tasks, each WITH a reason |
|
||||
| Deviations | Every departure from the plan: what the plan said, what you did, why |
|
||||
| Downstream plan updates | Edge-case annotations made directly (which plan, which section) and proposed diffs awaiting approval (see below) |
|
||||
| Edge cases discovered | Found during implementation — including ones you handled, so the next step knows they're covered |
|
||||
| Evidence | Pasted verbatim: format/lint/build/test commands, exit codes, salient output lines. Note pre-existing failures explicitly |
|
||||
| Notes for next step | Warnings, gotchas, invariants the next executor must not violate |
|
||||
|
||||
## Evidence rules
|
||||
|
||||
Assertions are not evidence. "Tests pass" is a claim; this is evidence:
|
||||
|
||||
```
|
||||
$ cargo test
|
||||
...
|
||||
test result: ok. 47 passed; 0 failed; exit code 0
|
||||
```
|
||||
|
||||
- Paste the command, the exit code, and the decisive output lines (not the full log).
|
||||
- Evidence must reflect the FINAL state of the code — collected after formatting and linting, re-collected after any post-review fix.
|
||||
- If a check was skipped (no formatter configured, etc.), say so explicitly.
|
||||
|
||||
## Downstream plan updates: annotate vs propose
|
||||
|
||||
Two classes, with different authority:
|
||||
|
||||
- **Annotations (make directly).** Adding an entry to a later plan's Edge cases section. Additive, non-scope-changing. Record each in Downstream plan updates.
|
||||
- **Proposals (never apply directly).** Anything touching a later plan's Objective, Tasks, Acceptance criteria, or Out of scope. Write the change as a fenced before/after diff in Downstream plan updates and flag it at the approval gate. The user applies or rejects it.
|
||||
|
||||
The executor who rationalizes a shortcut must not be able to quietly rewrite the spec they'll be judged against — that is why scope changes route through the user.
|
||||
|
||||
## Rolling notes vs handoff
|
||||
|
||||
- **Handoff**: step-scoped. What happened in THIS step.
|
||||
- **`plans/NOTES.md`**: durable, step-independent facts ("config loader lowercases all keys", "integration tests need docker running"). Append; never rewrite others' entries. Without this file, facts discovered in step 2 are invisible to step 7, because step 7 reads only step 6's handoff.
|
||||
|
||||
## Reading a handoff (start of a step)
|
||||
|
||||
1. Check `result`. `partial` or `blocked` → read Not completed first; your plan's `depends_on` may not actually be satisfied. Escalate rather than build on missing ground.
|
||||
2. Trust what has pasted evidence. Re-verify bare assertions before depending on them.
|
||||
3. Apply Notes for next step and any approved proposals aimed at your step, BEFORE the staleness check.
|
||||
4. Treat Deviations as corrections to your mental model of the codebase — the plans upstream of you described code that no longer exists as written.
|
||||
5. Read `plans/NOTES.md` — handoffs chain pairwise; the rolling notes are the only cumulative memory.
|
||||
|
||||
## Anti-patterns
|
||||
|
||||
- "All tests pass" with nothing pasted — a claim, not a handoff
|
||||
- Omitting a section instead of writing "None" — forgotten or empty, the reader can't tell
|
||||
- Editing a later plan's Tasks or scope directly instead of proposing a diff
|
||||
- Burying a major deviation in prose instead of the Deviations section
|
||||
- Durable facts in the handoff only — lost after one more step
|
||||
- Evidence collected before the formatter ran — the pasted output describes bytes that no longer exist
|
||||
- Writing the handoff before the completion gate (todos done or deferred-with-reason) is satisfied
|
||||
@@ -0,0 +1,66 @@
|
||||
---
|
||||
description: Navigate and curate markdown knowledge bases (plan repos, spec repos, companion docs) with IWE graph tools. Load when the workspace is or contains a markdown knowledge base and the task involves finding, reading, or reorganizing plans, specs, designs, or notes. Activates the iwe MCP server rooted at the current directory.
|
||||
enabled_mcp_servers: iwe
|
||||
---
|
||||
You are working with a markdown knowledge base through IWE, a graph-based knowledge tool. The `iwe` MCP server is rooted at the current working directory (`--project .`), so the knowledge base is the directory Coyote was launched in. IWE derives structure from links: a link on its own line is an *inclusion link* (parent-child hierarchy); a link inside text is an *inline reference* (cross-reference, produces backlinks). The server watches the filesystem, so external edits are picked up automatically — never ask for a restart.
|
||||
|
||||
## When to use this (and when not)
|
||||
|
||||
Use IWE tools when the task involves a corpus of markdown documents: plan repositories, spec/design collections, companion docs repos, meeting notes, PKM vaults.
|
||||
|
||||
Do NOT use IWE tools for:
|
||||
|
||||
- **Agent memory** (`.coyote/memory/`) — use the `memory__*` tools; they own the index conventions there.
|
||||
- **Workspace instructions** (`COYOTE.md`, `AGENTS.md`, `CLAUDE.md`, `GEMINI.md`) — human-curated and read-only; never edit them with IWE write tools.
|
||||
- **Semantic/similarity search over documents** — that is RAG's job. IWE search is fuzzy title/key matching plus structural traversal, not embeddings.
|
||||
- **Source code** — IWE only understands markdown.
|
||||
|
||||
If unsure whether the current directory is actually a knowledge base, probe with `iwe_stats` first. Few or zero documents means this skill does not apply; unload it rather than forcing the tools.
|
||||
|
||||
## Orientation protocol (always start here)
|
||||
|
||||
Never guess document keys. Orient first:
|
||||
|
||||
1. `iwe_stats` — corpus size and shape. Cheap sanity check.
|
||||
2. `iwe_find(query="<topic>")` — fuzzy search for entry points. Use `roots` behavior via structural selectors when you want top-level topics only.
|
||||
3. `iwe_tree(key="<entry>", max_depth=2)` — see the hierarchy before reading bodies.
|
||||
4. `iwe_retrieve(key="<entry>", depth=1, context=1)` — read with structure.
|
||||
|
||||
## Reading efficiently
|
||||
|
||||
`iwe_retrieve` is the workhorse. Control cost explicitly:
|
||||
|
||||
- `depth` — how many levels of included children to expand. Start at 1-2; increase only if needed.
|
||||
- `context` — parent levels to include, so you know where a document sits. `context=1` is usually enough.
|
||||
- `max_tokens` — ALWAYS set a budget (e.g. 2000-4000) on large corpora; results report truncation so you can drill further deliberately.
|
||||
- `exclude` — pass keys you have already read to avoid re-retrieving known content.
|
||||
- `links` / `backlinks` — include outbound/inbound references when tracing how a topic connects.
|
||||
|
||||
Scope searches structurally with selectors on `iwe_find`/`iwe_retrieve`/`iwe_tree`:
|
||||
|
||||
- `in` — only sub-documents of EVERY listed key (AND)
|
||||
- `in_any` — sub-documents of at least one key (OR)
|
||||
- `not_in` — exclude subtrees (e.g. archives)
|
||||
|
||||
Filter by frontmatter with the YAML query language: `status: draft`, `created: {$gte: "2026-01-01"}`, `tags: {$in: [urgent]}`, `reviewed: {$exists: true}`.
|
||||
|
||||
Use `iwe_squash(key=...)` to flatten a subtree into one linear document — good for producing a full plan readout or summary input.
|
||||
|
||||
## Writing and refactoring
|
||||
|
||||
Write tools: `iwe_create` (new doc from title + content), `iwe_update` (replace a doc's content), `iwe_delete` (remove + clean up references). Refactor tools: `iwe_rename` (key rename with automatic link updates everywhere), `iwe_extract` (split a section into its own doc, leaving an inclusion link), `iwe_inline` (merge a referenced doc back into its parent), `iwe_normalize` (reformat all docs consistently).
|
||||
|
||||
Rules:
|
||||
|
||||
- **Preview destructive operations**: `iwe_rename`, `iwe_delete`, `iwe_extract`, `iwe_inline`, and `iwe_normalize` support `dry_run` — use it first, show the user what will change, then apply.
|
||||
- Never rename or delete by editing files directly; the refactor tools update every referencing document, manual edits break links.
|
||||
- When adding a document, link it from an existing parent (inclusion link on its own line) so it joins the hierarchy instead of becoming an orphan.
|
||||
- Match the corpus conventions: check an existing document's frontmatter fields before inventing your own schema.
|
||||
- Do not run `iwe_normalize` across someone's knowledge base unprompted — it rewrites every file's formatting.
|
||||
|
||||
## Anti-patterns
|
||||
|
||||
- Retrieving with `depth=5` and no `max_tokens` "to get everything" — you will flood the context. Iterate: shallow first, drill selectively.
|
||||
- Calling `iwe_find` repeatedly with rephrased queries when structural navigation (`iwe_tree`, selectors) would locate the document deterministically.
|
||||
- Using IWE write tools on `.coyote/memory/` files — wrong tier; that corrupts the memory index.
|
||||
- Creating documents without linking them into the hierarchy — orphans are invisible to depth-based retrieval.
|
||||
@@ -0,0 +1,82 @@
|
||||
---
|
||||
description: Author executable high-level plans and per-step implementation plans for phased work. Defines the plan repo layout and step-plan schema. Grants filesystem access for grounding plans in real code.
|
||||
enabled_tools: fs_read, fs_grep, fs_glob, fs_ls, fs_cat, fs_write
|
||||
---
|
||||
You are writing implementation plans that a DIFFERENT agent will execute later, in a fresh session, with zero access to this conversation. The plan IS the executor's entire context. A plan that needs the conversation to make sense is a broken plan.
|
||||
|
||||
## Plan repo layout
|
||||
|
||||
Default layout (match the existing layout instead if the repo already has one):
|
||||
|
||||
```
|
||||
plans/
|
||||
plan.md # high-level plan; links each step plan
|
||||
steps/01-<slug>.md # one file per step, numbered in execution order
|
||||
handoffs/ # written by executors; see `handoff-protocol`
|
||||
NOTES.md # rolling durable facts discovered during execution
|
||||
```
|
||||
|
||||
In `plan.md`, link each step plan with an inclusion link (the link alone on its own line). This makes the plan repo an IWE hierarchy — agents navigating a large plan corpus can load `iwe-knowledge-base` and traverse it structurally instead of globbing.
|
||||
|
||||
## High-level plan requirements
|
||||
|
||||
- Ordered list of steps. Each step is independently implementable and independently verifiable — it compiles and its tests pass WITHOUT any later step existing.
|
||||
- The dependency graph is explicit and acyclic. If step 4 needs step 2's API, step 4's plan says so.
|
||||
- Steps are sized for one focused session: roughly 1-5 files of meaningful change. A step that needs "and then also..." is two steps.
|
||||
- State what the plan does NOT cover. Scope creep starts where scope boundaries are implicit.
|
||||
|
||||
## Step plan schema
|
||||
|
||||
Every step plan starts with frontmatter:
|
||||
|
||||
```yaml
|
||||
---
|
||||
step: 3
|
||||
title: Add retry policy to the fetch client
|
||||
depends_on: [1, 2]
|
||||
status: pending # pending | in-progress | complete
|
||||
---
|
||||
```
|
||||
|
||||
And contains these sections, all mandatory:
|
||||
|
||||
| Section | Contents |
|
||||
|---|---|
|
||||
| Objective | 1-3 sentences: what exists after this step that didn't before |
|
||||
| Context | File paths AND pasted code snippets (5-20 lines) showing the patterns to follow. Not just paths — actual code |
|
||||
| Tasks | Ordered, atomic tasks. Each maps to one todo item for the executor |
|
||||
| Acceptance criteria | Measurable behaviors. These become the tests |
|
||||
| Test commands | Exact commands to run, from the repo root |
|
||||
| Edge cases | Known edge cases this step must handle or explicitly punt on |
|
||||
| Out of scope | What the executor must NOT touch, even if tempting |
|
||||
|
||||
## Writing for a context-free executor
|
||||
|
||||
- Paste code snippets from your exploration into Context. "Follow the pattern in foo.rs" forces the executor to re-do exploration you already did.
|
||||
- Use repo-relative paths from the project root. Never "the file we discussed."
|
||||
- Name symbols exactly: `RetryPolicy::backoff`, not "the backoff logic."
|
||||
- If a decision was made in discussion (X over Y), record the decision AND the one-line reason. The executor will face the same fork and must not re-litigate it.
|
||||
- Write acceptance criteria as observable behavior ("returns 429 after 3 failed attempts"), not implementation ("uses a for loop"). Criteria that describe implementation produce tautological tests.
|
||||
|
||||
## Grounding (before the plan is done)
|
||||
|
||||
Plans rot when written from memory. Before finalizing each step plan:
|
||||
|
||||
1. `fs_grep` every symbol the plan references — confirm it exists and is spelled right.
|
||||
2. `fs_read` the files listed in Context — confirm the pasted snippets are current.
|
||||
3. Confirm the test commands actually exist (check `justfile`, `Makefile`, `package.json` scripts, CI config).
|
||||
|
||||
A plan referencing a function that doesn't exist fails the executor at the worst possible time: mid-implementation.
|
||||
|
||||
## Edge cases are a first-class section
|
||||
|
||||
For every step, enumerate the edge cases you can foresee: empty inputs, concurrent access, error paths, partial failures, migration/compat concerns. If an edge case belongs to a LATER step, write it in that step's plan now — not in a comment, not in your head. Executors are instructed to propagate newly discovered edge cases downstream; make their diff small by having the section exist.
|
||||
|
||||
## Anti-patterns
|
||||
|
||||
- "As discussed above" / "per our conversation" — the executor has no conversation
|
||||
- File paths without pasted snippets in Context — forces re-exploration
|
||||
- Acceptance criteria like "works correctly" — unmeasurable, untestable
|
||||
- A step that depends on a later step — cycle; re-order or merge
|
||||
- Omitting Out of scope — the executor will helpfully refactor things you didn't ask for
|
||||
- Frontmatter without `depends_on` or `status` — breaks status queries and dependency checks
|
||||
@@ -0,0 +1,83 @@
|
||||
---
|
||||
description: Adversarial review of implementation plans against executability, verifiability, and completeness standards. Verdict is OKAY or REJECT with line-referenced complaints. Grants read-only filesystem access for ground-truth checks.
|
||||
enabled_tools: fs_read, fs_grep, fs_glob, fs_ls, fs_cat
|
||||
---
|
||||
You are reviewing an implementation plan BEFORE any code is written. You are the critic, not a co-author: your job is to find the ways this plan fails an executor who has zero conversation context, not to redesign the approach. A flaw caught here costs one plan edit; the same flaw caught mid-implementation costs a deviation, a handoff note, and possibly rework across steps.
|
||||
|
||||
The plan schema you are checking against is defined in the `plan-authoring` skill — load it alongside this one if it is not already loaded.
|
||||
|
||||
## Review checklist (in order)
|
||||
|
||||
### 1. Executability without context
|
||||
|
||||
Read the plan as if you know nothing but what is on the page.
|
||||
|
||||
- Does every referenced decision carry its rationale, or does it assume a conversation you can't see?
|
||||
- Does Context contain pasted code snippets, or only file paths (which force re-exploration)?
|
||||
- Are symbols named exactly? "The validation logic" is not a name.
|
||||
|
||||
### 2. Ground truth (verify, don't trust)
|
||||
|
||||
Plans are written from exploration that may be stale or wrong. Spot-check claims against the actual codebase:
|
||||
|
||||
- `fs_grep` for every function, type, and file the plan references. Flag anything that doesn't exist or is spelled differently.
|
||||
- `fs_read` 1-2 of the pasted Context snippets at their claimed locations. Flag drift.
|
||||
- Check that the Test commands exist (`justfile`, `Makefile`, `package.json`, CI config).
|
||||
|
||||
A plan that references phantom code is an automatic REJECT.
|
||||
|
||||
### 3. Verifiability
|
||||
|
||||
- Is every acceptance criterion a measurable, observable behavior? "Works correctly" and "is robust" are unmeasurable — flag them.
|
||||
- Do the criteria describe behavior rather than implementation? Implementation-shaped criteria produce tautological tests.
|
||||
- Can each criterion be checked by the listed Test commands, or is there a criterion with no way to verify it?
|
||||
|
||||
### 4. Dependencies and ordering
|
||||
|
||||
- Is `depends_on` present, acyclic, and complete? If the step uses an API introduced in step N, is N listed?
|
||||
- Does anything in this step silently assume a LATER step's output? That's a cycle the frontmatter hides.
|
||||
- Is the step independently verifiable — will it build and pass tests without later steps existing?
|
||||
|
||||
### 5. Scope and sizing
|
||||
|
||||
- Is Out of scope present and specific? Absent scope boundaries invite helpful refactoring.
|
||||
- Is the step sized for one focused session (~1-5 files of meaningful change)? Flag steps hiding an "and then also".
|
||||
- Do two steps touch the same code region without an ordering constraint between them?
|
||||
|
||||
### 6. Edge cases
|
||||
|
||||
- Is the Edge cases section present and non-empty (or explicitly "none foreseen — <reason>")?
|
||||
- Think adversarially for 60 seconds: empty inputs, concurrency, error paths, partial failure, compat. Anything obvious the plan misses?
|
||||
- If this step creates a new surface (API, config, schema), do DOWNSTREAM step plans account for it where they must?
|
||||
|
||||
## Verdict format
|
||||
|
||||
End with exactly one of:
|
||||
|
||||
```
|
||||
PLAN_REVIEW: OKAY
|
||||
<optional: 1-3 non-blocking observations>
|
||||
```
|
||||
|
||||
```
|
||||
PLAN_REVIEW: REJECT
|
||||
Complaints:
|
||||
1. <file>:<line or section> — <what is wrong> — <what would fix it>
|
||||
2. ...
|
||||
```
|
||||
|
||||
Every complaint must be actionable and point at a specific location. "The plan could be clearer" is noise; "steps/03-retry.md, Acceptance criteria #2 — 'handles errors gracefully' is unmeasurable — specify the expected behavior per error class" is signal.
|
||||
|
||||
## Scope discipline
|
||||
|
||||
- Review THE PLAN, not the design. If the approach is defensible, do not relitigate it because you'd have chosen differently. Flag design only when it is factually broken (races, missing dependency, contradicts the codebase).
|
||||
- Do not rewrite the plan yourself. Complaints, not patches — the author owns the fix.
|
||||
- Three strong complaints beat fifteen weak ones. If you have fifteen, the plan needs a rewrite, not a list: say so.
|
||||
|
||||
## Anti-patterns
|
||||
|
||||
- Approving without running a single ground-truth check — a syntax review, not a plan review
|
||||
- REJECT for style or phrasing while missing a phantom-symbol reference
|
||||
- Redesigning the author's approach in your complaints
|
||||
- Vague complaints with no location and no fix direction
|
||||
- Rubber-stamping a step with no acceptance criteria because "the tasks look reasonable"
|
||||
@@ -0,0 +1,85 @@
|
||||
---
|
||||
description: End-to-end protocol for executing one step of a phased implementation plan - orient, staleness check, checklist, implement, edge-case sweep, verify, review, handoff, approval. Grants shell access for build/test commands.
|
||||
enabled_tools: execute_command
|
||||
---
|
||||
You are executing ONE step of a phased implementation plan. Previous steps were executed in sessions you cannot see; later steps depend on what you do and document. The protocol below is ordered — do not skip phases, do not reorder them.
|
||||
|
||||
Companion skills: load `handoff-protocol` before Phase 1 (you must READ a handoff correctly) and keep it loaded for Phase 8 (you must WRITE one). Load `verification-gates` for Phase 6. The plan schema is defined in `plan-authoring`.
|
||||
|
||||
## Phase 1 - Orient
|
||||
|
||||
1. Read the previous step's handoff (`plans/handoffs/`, highest step number below yours). If none exists, you are step 1.
|
||||
2. Read the current step plan (`plans/steps/`). Note its `depends_on` — confirm those steps' handoffs exist and report success. If a dependency failed or is missing, STOP and escalate via `user__ask`.
|
||||
3. Read `plans/NOTES.md` for durable facts discovered by earlier steps.
|
||||
4. Apply anything the previous handoff directed at your step (approved plan updates, warnings).
|
||||
5. Set the plan's frontmatter `status: in-progress`.
|
||||
|
||||
## Phase 2 - Staleness check (BEFORE any edit)
|
||||
|
||||
The plan was written before steps 1..N-1 changed the codebase. Verify its assumptions still hold:
|
||||
|
||||
- Grep the symbols the plan references — do they still exist, with the claimed signatures?
|
||||
- Read the plan's Context snippets at their claimed locations — has the code drifted?
|
||||
- Confirm the Test commands still work.
|
||||
|
||||
Discrepancies are deviations — handle them via Phase 5's protocol BEFORE implementing. Executing a stale plan literally is the primary failure mode of phased work.
|
||||
|
||||
## Phase 3 - Checklist
|
||||
|
||||
`todo__init` with the step objective, then one `todo__add` per task in the plan's Tasks section, in order. Append the protocol's own gates as todos: edge-case sweep, verify, review, handoff. Mark items done with `todo__done` as you go — never batch. The checklist is what survives context compression; keep it truthful.
|
||||
|
||||
When you spawn an agent whose session you may need to resume, embed its session_id in the corresponding todo item text (`"Implement task 3 (coder ses_abc123)"`). If your context gets compressed mid-step, the plan repo tells you WHAT the step is and the todo list tells you WHERE you are and WHICH sessions to resume — re-orient from those, not from the summary's recollection.
|
||||
|
||||
## Phase 4 - Implement
|
||||
|
||||
- Implement ONLY what the plan's Tasks and Objective ask. Out of scope means out of scope.
|
||||
- Follow the patterns pasted in the plan's Context. When plan and current codebase disagree, the codebase wins — record the deviation.
|
||||
- Write tests from the plan's Acceptance criteria, not from your implementation. Criteria-first tests catch what tautological tests cannot.
|
||||
- While in the code, note (do not fix) anything the planning exploration missed — feed it to Phase 5.
|
||||
|
||||
## Phase 5 - Edge-case sweep and deviations
|
||||
|
||||
**Edge cases.** For each edge case you discovered: if it belongs to THIS step, handle it (or punt explicitly in the handoff with a reason). If it belongs to a LATER step, check that step's plan — if the plan already covers it, done; if not, add it to that plan's Edge cases section and record the addition in your handoff.
|
||||
|
||||
**Deviations.** Classify each:
|
||||
|
||||
| Class | Definition | Action |
|
||||
|---|---|---|
|
||||
| Minor | Same objective and scope, mechanics differ (renamed symbol, moved file, extra helper) | Resolve it, document in handoff |
|
||||
| Major | Changes scope, approach, interfaces, or invalidates a later step's assumptions | Do NOT silently proceed. Either escalate via `user__ask`, or write a proposed downstream-plan diff into the handoff per `handoff-protocol` |
|
||||
|
||||
Never rewrite a later step's Objective, Tasks, or Out of scope directly — edge-case annotations are the only direct downstream edit you may make.
|
||||
|
||||
## Phase 6 - Verify (order matters)
|
||||
|
||||
1. Formatter (if configured) — format BEFORE collecting evidence, so evidence reflects final code.
|
||||
2. Linter (if configured) — fix findings your change introduced.
|
||||
3. Build/typecheck — exit code 0.
|
||||
4. FULL test suite — not just your new tests; regressions in untouched code are your problem if your change caused them.
|
||||
|
||||
Capture commands and exit codes verbatim — they go in the handoff as evidence. Pre-existing failures: note explicitly, don't fix, don't hide. Apply the 3-strike rule: after 3 failed fix attempts, stop, revert to working state, escalate.
|
||||
|
||||
## Phase 7 - Review
|
||||
|
||||
Self-review the diff with `code-review` + `ai-slop-remover` loaded. For broad steps (5+ files or crossing architectural boundaries), request an independent pass (`code-reviewer` agent) instead. Fix blockers; re-run Phase 6 after any fix.
|
||||
|
||||
## Phase 8 - Handoff
|
||||
|
||||
Gate: every todo is either done or explicitly deferred with a reason. No silent drops.
|
||||
|
||||
Write the handoff per `handoff-protocol` — schema, pasted evidence, deviations, downstream updates, notes for the next step. Append durable, step-independent facts to `plans/NOTES.md`. Set the plan's frontmatter `status: complete`.
|
||||
|
||||
## Phase 9 - User approval
|
||||
|
||||
Present: what was done, deviations, downstream plan changes (made or proposed), evidence summary, handoff location. Then STOP — do not begin the next step. If the user requests changes, address them, re-run Phase 6, update the handoff, and present again.
|
||||
|
||||
## Anti-patterns
|
||||
|
||||
- Editing code before the staleness check — the primary source of mid-step surprises
|
||||
- Implementing "while I'm here" improvements outside the plan's scope
|
||||
- Tests derived from the implementation instead of the acceptance criteria
|
||||
- Collecting build/test evidence BEFORE formatting/linting, then shipping different bytes
|
||||
- Running only your new tests and claiming "tests pass"
|
||||
- Silently absorbing a major deviation instead of escalating or proposing a plan diff
|
||||
- Rewriting downstream plan scope directly instead of proposing per `handoff-protocol`
|
||||
- Starting the next step without user approval
|
||||
@@ -13,6 +13,8 @@
|
||||
model: openai:gpt-4o # Specify the LLM to use
|
||||
temperature: null # Set default temperature parameter, range (0, 1)
|
||||
top_p: null # Set default top-p parameter, with a range of (0, 1) or (0, 2) depending on the model
|
||||
reasoning_effort: null # Reasoning effort level for models that support it (e.g. low, medium, high).
|
||||
# Only valid when the agent's model declares reasoning_levels.
|
||||
agent_session: null # Set a session to use when starting the agent. (e.g. temp, default); defaults to globally set agent_session
|
||||
name: <agent-name> # Name of the agent, used in the UI and logs
|
||||
description: <description> # Description of the agent, used in the UI
|
||||
@@ -92,6 +94,9 @@ conversation_starters: # Optional conversation starters for the agent
|
||||
- What is the best way to exercise?
|
||||
- How do I manage my time effectively?
|
||||
documents: # Optional documents to load for the agent
|
||||
# To enable graph-based RAG (entity/relationship extraction + knowledge graph retrieval),
|
||||
# set `rag_extractor_model` in your global config.yaml.
|
||||
# See https://github.com/Dark-Alex-17/coyote/wiki/RAG#graph-based-rag
|
||||
- git:/some/repo # Explicitly tell Coyote to use the 'git' document loader using an absolute path
|
||||
- pdf:some-pdf-file.pdf # Explicitly tell Coyote to use the 'pdf' document loader using a relative path
|
||||
- https://some-website.com/some-page
|
||||
|
||||
+29
-3
@@ -2,6 +2,8 @@
|
||||
model: openai:gpt-4o # Specify the LLM to use
|
||||
temperature: null # Set default temperature parameter (0, 1)
|
||||
top_p: null # Set default top-p parameter, with a range of (0, 1) or (0, 2) depending on the model
|
||||
reasoning_effort: null # Reasoning effort level for models that support it (e.g. low, medium, high).
|
||||
# Only valid when the active model declares reasoning_levels. See the Clients docs.
|
||||
|
||||
# ---- Behavior ----
|
||||
stream: true # Controls whether to use the stream-style APIs when querying for completions from LLM clients.
|
||||
@@ -31,7 +33,7 @@ sync_models_url: > # URL to sync model changes from
|
||||
left_prompt:
|
||||
'{color.red}{model}){color.green}{?session {?agent {agent}>}{session}{?role /}}{!session {?agent {agent}>}}{role}{?rag @{rag}}{color.cyan}{?session )}{!session >}{color.reset} '
|
||||
right_prompt:
|
||||
'{color.purple}{?session {?consume_tokens {consume_tokens}({consume_percent}%)}{!consume_tokens {consume_tokens}}}{color.reset}'
|
||||
'{color.cyan}{?reasoning_effort [{reasoning_effort}] }{color.purple}{?session {?consume_tokens {consume_tokens}({consume_percent}%)}{!consume_tokens {consume_tokens}}}{color.reset}'
|
||||
|
||||
# ---- Vault ----
|
||||
# See the [Vault documentation](https://github.com/Dark-Alex-17/coyote/wiki/Vault) for more information on the Coyote vault.
|
||||
@@ -91,6 +93,7 @@ enabled_tools: null # Which tools to enable by default.
|
||||
# Example (comma-separated form):
|
||||
# enabled_tools: fs,web_search_coyote
|
||||
visible_tools: # Which tools are visible to be compiled (and are thus able to be defined in 'enabled_tools')
|
||||
# - ast_grep.sh
|
||||
# - demo_py.py
|
||||
# - demo_sh.sh
|
||||
# - demo_ts.ts
|
||||
@@ -133,6 +136,14 @@ enabled_mcp_servers: null # Which MCP servers to enable by default.
|
||||
# - slack
|
||||
# Example (comma-separated form):
|
||||
# enabled_mcp_servers: github,slack,ddg-search
|
||||
no_workspace_mcp: false # Disable loading workspace-local MCP servers (default: false).
|
||||
# When false (the default), Coyote merges the first workspace MCP config it finds
|
||||
# into the global MCP registry at startup, checking in order:
|
||||
# 1. .coyote/mcp.json
|
||||
# 2. .coyote/.mcp.json (Claude-style file name)
|
||||
# 3. .mcp.json (project root; Claude Code convention)
|
||||
# Workspace entries shadow global ones on name collision.
|
||||
# Set to true (or pass --no-workspace-mcp) to skip this entirely.
|
||||
|
||||
# ---- Skills ----
|
||||
# Skills are modular knowledge or capability packs the LLM can load and unload mid-conversation.
|
||||
@@ -178,8 +189,8 @@ summary_context_prompt: > # The text prompt used for including the summar
|
||||
|
||||
# ---- Memory ----
|
||||
# See the [Memory documentation](https://github.com/Dark-Alex-17/coyote/wiki/Memory) for more information.
|
||||
# Memory is opt-in by workspace presence (a `COYOTE.md` or `.coyote/memory/MEMORY.md`)
|
||||
# and global presence (`<config_dir>/memory/MEMORY.md`). Set `memory: false` to disable
|
||||
# Memory is opt-in by workspace presence (`.coyote/memory/MEMORY.md`) and global
|
||||
# presence (`<config_dir>/memory/MEMORY.md`). Set `memory: false` to disable
|
||||
# even when memory files exist. The cascade is: agent > session > role > app.
|
||||
# Bootstrap with `coyote --init-memory [global|workspace]` to create the marker file
|
||||
# the LLM needs before it will write any memory.
|
||||
@@ -189,6 +200,18 @@ memory_cap_with_tools: null # Char cap for injected memory when function ca
|
||||
memory_cap_without_tools: null # Char cap when function calling is unavailable (default: 12000).
|
||||
# Indexes plus drill file bodies are injected up to this cap.
|
||||
|
||||
# ---- Workspace Instructions ----
|
||||
# Human-curated project instructions injected read-only into the system prompt, in full.
|
||||
# Coyote walks up from the current directory and injects the first match from the file
|
||||
# chain below (per directory, in order). Scaffold with `coyote --init-instructions`.
|
||||
# Disable per-invocation with --no-workspace-instructions, or override the chain with
|
||||
# repeatable --workspace-instructions-file flags.
|
||||
workspace_instructions: null # null/true = inject when an instructions file exists; false = never inject
|
||||
workspace_instructions_files: null # File name chain to search, in priority order.
|
||||
# Default: [COYOTE.md, AGENTS.md, CLAUDE.md, GEMINI.md]
|
||||
# Set to a custom list to reorder or drop fallbacks, e.g.:
|
||||
# workspace_instructions_files: [COYOTE.md]
|
||||
|
||||
# ---- RAG ----
|
||||
# See the [RAG Docs](https://github.com/Dark-Alex-17/coyote/wiki/RAG) for more details.
|
||||
rag_embedding_model: null # Specifies the embedding model used for context retrieval
|
||||
@@ -196,6 +219,9 @@ rag_reranker_model: null # Specifies the reranker model used for sorting
|
||||
rag_top_k: 5 # Specifies the number of documents to retrieve for answering queries
|
||||
rag_chunk_size: null # Defines the size of chunks for document processing in characters
|
||||
rag_chunk_overlap: null # Defines the overlap between chunks
|
||||
rag_extractor_model: null # LLM model for graph-based entity/relationship extraction; when set, enables a graph RAG signal alongside vector and BM25
|
||||
rag_extractor_prompt: null # Custom extraction prompt template; must contain __CHUNK__ placeholder; defaults to built-in prompt when null
|
||||
rag_graph_hops: 1 # Number of hops to expand from matched entities at query time (0 = seed nodes only; 1 = direct neighbors; increase for denser graphs)
|
||||
# Defines the query structure using variables like __CONTEXT__, __SOURCES__, and __INPUT__ to tailor searches to specific needs
|
||||
rag_template: |
|
||||
Answer the query based on the context while respecting the rules. (user query, some textual context and rules, all inside xml tags)
|
||||
|
||||
@@ -8,6 +8,8 @@ name: <role-name> # The name of the role
|
||||
model: openai:gpt-4o # The model to use for this role
|
||||
temperature: 0.2 # The temperature to use for this role when querying the model
|
||||
top_p: 0 # The top_p to use for this role when querying the model
|
||||
reasoning_effort: null # Reasoning effort level for models that support it (e.g. low, medium, high).
|
||||
# Only valid when the role's model declares reasoning_levels.
|
||||
enabled_tools: # Tools to enable for this role. Accepts a YAML list (preferred)
|
||||
- fs_ls # or a comma-separated string (e.g. `enabled_tools: fs_ls,fs_cat`).
|
||||
- fs_cat # Use `all` to enable every visible tool.
|
||||
|
||||
@@ -33,6 +33,8 @@ version: "1.0" # Graph schema version. Only "1.0" is accepte
|
||||
model: claude:claude-sonnet-4-6 # Default model for `llm` nodes that don't override it
|
||||
temperature: 0.0 # Default sampling temperature for `llm` nodes
|
||||
top_p: null # Default sampling top-p for `llm` nodes
|
||||
reasoning_effort: null # Default reasoning effort for `llm` nodes that don't override it.
|
||||
# Only valid when the model declares reasoning_levels.
|
||||
|
||||
global_tools: # Tool universe an `llm` node's `tools:` whitelist draws from
|
||||
- web_search_coyote.sh
|
||||
@@ -225,6 +227,9 @@ nodes:
|
||||
chunk_size: 1000
|
||||
chunk_overlap: 100
|
||||
reranker_model: null # Optional reranker for hybrid-search results
|
||||
extractor_model: null # Optional chat model for graph-based entity/relationship extraction; enables graph RAG signal when set
|
||||
extractor_prompt: null # Optional custom extraction prompt; must contain __CHUNK__ placeholder; uses built-in prompt when null
|
||||
graph_hops: 1 # Graph expansion depth at query time (0 = seed nodes only; 1 = direct neighbors; increase for denser knowledge graphs)
|
||||
batch_size: 100 # Optional embedding-request batch size
|
||||
state_updates: # {{output}} = { context: <str>, sources: [<path>, ...] }
|
||||
context: "{{output.context}}" # writes `context` -> `reducers.context = concat`
|
||||
@@ -391,6 +396,7 @@ nodes:
|
||||
- mcp:ddg-search # `mcp:<server>` includes that server's functions
|
||||
model: claude:claude-haiku-4-5 # Optional per-node model override
|
||||
temperature: 0.3 # Optional per-node sampling override
|
||||
reasoning_effort: null # Optional per-node reasoning effort override (e.g. low, medium, high)
|
||||
max_attempts: 2 # Retry count on transient errors only. Default 1.
|
||||
max_iterations: 10 # Tool-call-loop turn cap. Default 10.
|
||||
fallback: review # Route here if all attempts fail
|
||||
|
||||
@@ -23,3 +23,16 @@ fmt:
|
||||
[arg('build_type', pattern="debug|release")]
|
||||
build build_type='debug':
|
||||
@cargo build {{ if build_type == "release" { "--release" } else { "" } }}
|
||||
|
||||
# Build a multi-platform Docker image (linux/amd64 + linux/arm64).
|
||||
# Requires an active buildx builder with multi-platform support and a registry login.
|
||||
# version: must match an existing GitHub release tag (e.g. 0.7.4)
|
||||
# image: registry/image name to push to (default: darkalex17/coyote)
|
||||
[group: 'build']
|
||||
docker-build version image='darkalex17/coyote':
|
||||
docker buildx build \
|
||||
--platform linux/amd64,linux/arm64 \
|
||||
--build-arg COYOTE_VERSION={{ version }} \
|
||||
--tag {{ image }}:{{ version }} \
|
||||
--tag {{ image }}:latest \
|
||||
.
|
||||
|
||||
+275
@@ -3,6 +3,33 @@
|
||||
# - https://platform.openai.com/docs/api-reference/chat
|
||||
- provider: openai
|
||||
models:
|
||||
- name: gpt-5.6-sol
|
||||
max_input_tokens: 1050000
|
||||
max_output_tokens: 128000
|
||||
input_price: 5
|
||||
output_price: 30
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [none, low, medium, high, xhigh, max]
|
||||
default_reasoning_effort: medium
|
||||
- name: gpt-5.6-terra
|
||||
max_input_tokens: 1050000
|
||||
max_output_tokens: 128000
|
||||
input_price: 5
|
||||
output_price: 30
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [none, low, medium, high, xhigh, max]
|
||||
default_reasoning_effort: medium
|
||||
- name: gpt-5.6-luna
|
||||
max_input_tokens: 1050000
|
||||
max_output_tokens: 128000
|
||||
input_price: 5
|
||||
output_price: 30
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [none, low, medium, high, xhigh, max]
|
||||
default_reasoning_effort: medium
|
||||
- name: gpt-5.5
|
||||
max_input_tokens: 1050000
|
||||
max_output_tokens: 128000
|
||||
@@ -10,6 +37,8 @@
|
||||
output_price: 30
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [none, low, medium, high, xhigh]
|
||||
default_reasoning_effort: medium
|
||||
- name: gpt-5.5-pro
|
||||
max_input_tokens: 1050000
|
||||
max_output_tokens: 128000
|
||||
@@ -17,6 +46,8 @@
|
||||
output_price: 180
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [medium, high, xhigh]
|
||||
default_reasoning_effort: high
|
||||
- name: gpt-5.4
|
||||
max_input_tokens: 1050000
|
||||
max_output_tokens: 128000
|
||||
@@ -24,6 +55,8 @@
|
||||
output_price: 15
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [none, low, medium, high, xhigh]
|
||||
default_reasoning_effort: none
|
||||
- name: gpt-5.4-pro
|
||||
max_input_tokens: 1050000
|
||||
max_output_tokens: 128000
|
||||
@@ -31,6 +64,8 @@
|
||||
output_price: 180
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [medium, high, xhigh]
|
||||
default_reasoning_effort: medium
|
||||
- name: gpt-5.4-mini
|
||||
max_input_tokens: 400000
|
||||
max_output_tokens: 128000
|
||||
@@ -38,6 +73,8 @@
|
||||
output_price: 4.5
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [none, low, medium, high, xhigh]
|
||||
default_reasoning_effort: none
|
||||
- name: gpt-5.4-nano
|
||||
max_input_tokens: 400000
|
||||
max_output_tokens: 128000
|
||||
@@ -45,6 +82,8 @@
|
||||
output_price: 1.25
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [none, low, medium, high, xhigh]
|
||||
default_reasoning_effort: none
|
||||
- name: gpt-5.3-codex
|
||||
max_input_tokens: 400000
|
||||
max_output_tokens: 128000
|
||||
@@ -52,6 +91,8 @@
|
||||
output_price: 14
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high, xhigh]
|
||||
default_reasoning_effort: medium
|
||||
- name: chat-latest
|
||||
max_input_tokens: 400000
|
||||
max_output_tokens: 128000
|
||||
@@ -66,6 +107,17 @@
|
||||
output_price: 14
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [none, low, medium, high, xhigh]
|
||||
default_reasoning_effort: none
|
||||
- name: gpt-5.2-pro
|
||||
max_input_tokens: 400000
|
||||
max_output_tokens: 128000
|
||||
input_price: 21
|
||||
output_price: 168
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [medium, high, xhigh]
|
||||
default_reasoning_effort: medium
|
||||
- name: gpt-5.1
|
||||
max_input_tokens: 400000
|
||||
max_output_tokens: 128000
|
||||
@@ -73,6 +125,8 @@
|
||||
output_price: 10
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [none, low, medium, high]
|
||||
default_reasoning_effort: none
|
||||
- name: gpt-5.1-chat-latest
|
||||
max_input_tokens: 400000
|
||||
max_output_tokens: 128000
|
||||
@@ -80,6 +134,8 @@
|
||||
output_price: 10
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [none, low, medium, high]
|
||||
default_reasoning_effort: none
|
||||
- name: gpt-5
|
||||
max_input_tokens: 400000
|
||||
max_output_tokens: 128000
|
||||
@@ -87,6 +143,8 @@
|
||||
output_price: 10
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [minimal, low, medium, high]
|
||||
default_reasoning_effort: medium
|
||||
- name: gpt-5-chat-latest
|
||||
max_input_tokens: 400000
|
||||
max_output_tokens: 128000
|
||||
@@ -94,6 +152,8 @@
|
||||
output_price: 10
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [minimal, low, medium, high]
|
||||
default_reasoning_effort: medium
|
||||
- name: gpt-5-mini
|
||||
max_input_tokens: 400000
|
||||
max_output_tokens: 128000
|
||||
@@ -151,6 +211,8 @@
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
system_prompt_prefix: Formatting re-enabled
|
||||
reasoning_levels: [low, medium, high]
|
||||
default_reasoning_effort: medium
|
||||
patch:
|
||||
body:
|
||||
max_tokens: null
|
||||
@@ -264,18 +326,24 @@
|
||||
input_price: 0.2
|
||||
output_price: 1.5
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [minimal, low, medium, high]
|
||||
default_reasoning_effort: medium
|
||||
- name: gemini-3-flash-preview
|
||||
max_input_tokens: 1048576
|
||||
max_output_tokens: 65536
|
||||
input_price: 0.2
|
||||
output_price: 1.5
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [minimal, low, medium, high]
|
||||
default_reasoning_effort: high
|
||||
- name: gemini-3.1-flash-lite
|
||||
max_input_tokens: 1048576
|
||||
max_output_tokens: 65536
|
||||
input_price: 0.2
|
||||
output_price: 1.5
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [minimal, low, medium, high]
|
||||
default_reasoning_effort: minimal
|
||||
- name: gemini-3.1-pro-preview
|
||||
max_input_tokens: 1048576
|
||||
max_output_tokens: 65535
|
||||
@@ -283,6 +351,8 @@
|
||||
output_price: 2.5
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high]
|
||||
default_reasoning_effort: high
|
||||
- name: gemini-2.5-flash
|
||||
max_input_tokens: 1048576
|
||||
max_output_tokens: 65536
|
||||
@@ -290,6 +360,8 @@
|
||||
output_price: 0
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high]
|
||||
default_reasoning_effort: low
|
||||
- name: gemini-2.5-pro
|
||||
max_input_tokens: 1048576
|
||||
max_output_tokens: 65536
|
||||
@@ -297,6 +369,8 @@
|
||||
output_price: 0
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high]
|
||||
default_reasoning_effort: high
|
||||
- name: gemini-2.5-flash-lite
|
||||
max_input_tokens: 1000000
|
||||
max_output_tokens: 64000
|
||||
@@ -308,10 +382,14 @@
|
||||
max_input_tokens: 1048576
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, high]
|
||||
default_reasoning_level: high
|
||||
- name: gemini-3-flash-preview
|
||||
max_input_tokens: 1048576
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [minimal, low, medium, high]
|
||||
default_reasoning_level: high
|
||||
- name: gemma-3-27b-it
|
||||
max_input_tokens: 131072
|
||||
max_output_tokens: 8192
|
||||
@@ -337,6 +415,8 @@
|
||||
output_price: 50
|
||||
supports_function_calling: true
|
||||
supports_vision: true
|
||||
reasoning_levels: [low, medium, high, xhigh, max]
|
||||
default_reasoning_effort: high
|
||||
- name: claude-opus-4-8
|
||||
max_input_tokens: 1000000
|
||||
max_output_tokens: 128000
|
||||
@@ -345,6 +425,8 @@
|
||||
output_price: 25
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high, xhigh, max]
|
||||
default_reasoning_effort: high
|
||||
- name: claude-opus-4-7
|
||||
max_input_tokens: 1000000
|
||||
max_output_tokens: 128000
|
||||
@@ -353,6 +435,8 @@
|
||||
output_price: 25
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high, xhigh, max]
|
||||
default_reasoning_effort: high
|
||||
- name: claude-opus-4-6
|
||||
max_input_tokens: 200000
|
||||
max_output_tokens: 8192
|
||||
@@ -361,6 +445,8 @@
|
||||
output_price: 25
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high, max]
|
||||
default_reasoning_effort: high
|
||||
- name: claude-opus-4-6:thinking
|
||||
real_name: claude-opus-4-6
|
||||
max_input_tokens: 200000
|
||||
@@ -377,6 +463,16 @@
|
||||
thinking:
|
||||
type: enabled
|
||||
budget_tokens: 16000
|
||||
- name: claude-sonnet-5
|
||||
max_input_tokens: 1000000
|
||||
max_output_tokens: 128000
|
||||
require_max_tokens: true
|
||||
input_price: 3
|
||||
output_price: 15
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high, xhigh, max]
|
||||
default_reasoning_effort: high
|
||||
- name: claude-sonnet-4-6
|
||||
max_input_tokens: 200000
|
||||
max_output_tokens: 8192
|
||||
@@ -385,6 +481,8 @@
|
||||
output_price: 15
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high, max]
|
||||
default_reasoning_effort: high
|
||||
- name: claude-sonnet-4-6:thinking
|
||||
real_name: claude-sonnet-4-6
|
||||
max_input_tokens: 200000
|
||||
@@ -827,18 +925,24 @@
|
||||
input_price: 0.2
|
||||
output_price: 1.5
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [minimal, low, medium, high]
|
||||
default_reasoning_effort: medium
|
||||
- name: gemini-3-flash-preview
|
||||
max_input_tokens: 1048576
|
||||
max_output_tokens: 65536
|
||||
input_price: 0.2
|
||||
output_price: 1.5
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [minimal, low, medium, high]
|
||||
default_reasoning_effort: high
|
||||
- name: gemini-3.1-flash-lite
|
||||
max_input_tokens: 1048576
|
||||
max_output_tokens: 65536
|
||||
input_price: 0.2
|
||||
output_price: 1.5
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [minimal, high]
|
||||
default_reasoning_effort: minimal
|
||||
- name: gemini-3.1-pro-preview
|
||||
max_input_tokens: 1048576
|
||||
max_output_tokens: 65536
|
||||
@@ -846,6 +950,8 @@
|
||||
output_price: 12
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high]
|
||||
default_reasoning_effort: high
|
||||
- name: gemini-2.5-flash
|
||||
max_input_tokens: 1048576
|
||||
max_output_tokens: 65535
|
||||
@@ -853,6 +959,8 @@
|
||||
output_price: 2.5
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high]
|
||||
default_reasoning_effort: medium
|
||||
- name: gemini-2.5-pro
|
||||
max_input_tokens: 1048576
|
||||
max_output_tokens: 65536
|
||||
@@ -860,6 +968,8 @@
|
||||
output_price: 10
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high]
|
||||
default_reasoning_effort: high
|
||||
- name: gemini-2.5-flash-lite
|
||||
max_input_tokens: 1048576
|
||||
max_output_tokens: 65536
|
||||
@@ -871,10 +981,14 @@
|
||||
max_input_tokens: 1048576
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, high]
|
||||
default_reasoning_effort: high
|
||||
- name: gemini-3-flash-preview
|
||||
max_input_tokens: 1048576
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [minimal, low, medium, high]
|
||||
default_reasoning_effort: high
|
||||
- name: claude-fable-5
|
||||
max_input_tokens: 1000000
|
||||
max_output_tokens: 128000
|
||||
@@ -883,6 +997,8 @@
|
||||
output_price: 50
|
||||
supports_function_calling: true
|
||||
supports_vision: true
|
||||
reasoning_levels: [low, medium, high, xhigh, max]
|
||||
default_reasoning_effort: high
|
||||
- name: claude-opus-4-8
|
||||
max_input_tokens: 1000000
|
||||
max_output_tokens: 128000
|
||||
@@ -891,6 +1007,8 @@
|
||||
output_price: 25
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high, xhigh, max]
|
||||
default_reasoning_effort: high
|
||||
- name: claude-opus-4-7
|
||||
max_input_tokens: 1000000
|
||||
max_output_tokens: 128000
|
||||
@@ -899,6 +1017,8 @@
|
||||
output_price: 25
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high, xhigh, max]
|
||||
default_reasoning_effort: high
|
||||
- name: claude-opus-4-6
|
||||
max_input_tokens: 200000
|
||||
max_output_tokens: 8192
|
||||
@@ -922,6 +1042,16 @@
|
||||
thinking:
|
||||
type: enabled
|
||||
budget_tokens: 16000
|
||||
- name: claude-sonnet-5
|
||||
max_input_tokens: 1000000
|
||||
max_output_tokens: 128000
|
||||
require_max_tokens: true
|
||||
input_price: 3
|
||||
output_price: 15
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high, xhigh, max]
|
||||
default_reasoning_effort: high
|
||||
- name: claude-sonnet-4-6
|
||||
max_input_tokens: 200000
|
||||
max_output_tokens: 8192
|
||||
@@ -930,6 +1060,8 @@
|
||||
output_price: 15
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high, max]
|
||||
default_reasoning_effort: high
|
||||
- name: claude-sonnet-4-6:thinking
|
||||
real_name: claude-sonnet-4-6
|
||||
max_input_tokens: 200000
|
||||
@@ -1062,6 +1194,8 @@
|
||||
output_price: 50
|
||||
supports_function_calling: true
|
||||
supports_vision: true
|
||||
reasoning_levels: [low, medium, high, xhigh, max]
|
||||
default_reasoning_effort: high
|
||||
- name: us.anthropic.claude-opus-4-8
|
||||
max_input_tokens: 1000000
|
||||
max_output_tokens: 128000
|
||||
@@ -1070,6 +1204,8 @@
|
||||
output_price: 25
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high, xhigh, max]
|
||||
default_reasoning_effort: high
|
||||
- name: us.anthropic.claude-opus-4-7
|
||||
max_input_tokens: 1000000
|
||||
max_output_tokens: 128000
|
||||
@@ -1078,6 +1214,8 @@
|
||||
output_price: 25
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high, xhigh, max]
|
||||
default_reasoning_effort: high
|
||||
- name: us.anthropic.claude-opus-4-6-v1
|
||||
max_input_tokens: 200000
|
||||
max_output_tokens: 8192
|
||||
@@ -1086,6 +1224,8 @@
|
||||
output_price: 25
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high, max]
|
||||
default_reasoning_effort: high
|
||||
- name: us.anthropic.claude-opus-4-6-v1:thinking
|
||||
real_name: us.anthropic.claude-opus-4-6-v1
|
||||
max_input_tokens: 200000
|
||||
@@ -1103,6 +1243,16 @@
|
||||
thinking:
|
||||
type: enabled
|
||||
budget_tokens: 16000
|
||||
- name: us.anthropic.claude-sonnet-5
|
||||
max_input_tokens: 1000000
|
||||
max_output_tokens: 128000
|
||||
require_max_tokens: true
|
||||
input_price: 3
|
||||
output_price: 15
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high, xhigh, max]
|
||||
default_reasoning_effort: high
|
||||
- name: us.anthropic.claude-sonnet-4-6
|
||||
max_input_tokens: 200000
|
||||
max_output_tokens: 8192
|
||||
@@ -1111,6 +1261,8 @@
|
||||
output_price: 15
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high, max]
|
||||
default_reasoning_effort: high
|
||||
- name: us.anthropic.claude-sonnet-4-6:thinking
|
||||
real_name: us.anthropic.claude-sonnet-4-6
|
||||
max_input_tokens: 200000
|
||||
@@ -1620,6 +1772,33 @@
|
||||
# - https://openrouter.ai/docs/api-reference/chat-completion
|
||||
- provider: openrouter
|
||||
models:
|
||||
- name: openai/gpt-5.6-sol
|
||||
max_input_tokens: 1050000
|
||||
max_output_tokens: 128000
|
||||
input_price: 5
|
||||
output_price: 30
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [none, low, medium, high, xhigh, max]
|
||||
default_reasoning_effort: medium
|
||||
- name: openai/gpt-5.6-terra
|
||||
max_input_tokens: 1050000
|
||||
max_output_tokens: 128000
|
||||
input_price: 5
|
||||
output_price: 30
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [none, low, medium, high, xhigh, max]
|
||||
default_reasoning_effort: medium
|
||||
- name: openai/gpt-5.6-luna
|
||||
max_input_tokens: 1050000
|
||||
max_output_tokens: 128000
|
||||
input_price: 5
|
||||
output_price: 30
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [none, low, medium, high, xhigh, max]
|
||||
default_reasoning_effort: medium
|
||||
- name: openai/gpt-5.5
|
||||
max_input_tokens: 1050000
|
||||
max_output_tokens: 128000
|
||||
@@ -1627,6 +1806,8 @@
|
||||
output_price: 30
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [none, low, medium, high, xhigh]
|
||||
default_reasoning_effort: medium
|
||||
- name: openai/gpt-5.5-pro
|
||||
max_input_tokens: 1050000
|
||||
max_output_tokens: 128000
|
||||
@@ -1634,6 +1815,8 @@
|
||||
output_price: 180
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [medium, high, xhigh]
|
||||
default_reasoning_effort: high
|
||||
- name: openai/gpt-5.4
|
||||
max_input_tokens: 1050000
|
||||
max_output_tokens: 128000
|
||||
@@ -1641,6 +1824,8 @@
|
||||
output_price: 15
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [none, low, medium, high, xhigh]
|
||||
default_reasoning_effort: none
|
||||
- name: openai/gpt-5.4-pro
|
||||
max_input_tokens: 1050000
|
||||
max_output_tokens: 128000
|
||||
@@ -1648,6 +1833,8 @@
|
||||
output_price: 180
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [medium, high, xhigh]
|
||||
default_reasoning_effort: medium
|
||||
- name: openai/gpt-5.4-mini
|
||||
max_input_tokens: 400000
|
||||
max_output_tokens: 128000
|
||||
@@ -1655,6 +1842,8 @@
|
||||
output_price: 4.5
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [none, low, medium, high, xhigh]
|
||||
default_reasoning_effort: none
|
||||
- name: openai/gpt-5.4-nano
|
||||
max_input_tokens: 400000
|
||||
max_output_tokens: 128000
|
||||
@@ -1662,6 +1851,8 @@
|
||||
output_price: 1.25
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [none, low, medium, high, xhigh]
|
||||
default_reasoning_effort: none
|
||||
- name: openai/gpt-5.3-codex
|
||||
max_input_tokens: 400000
|
||||
max_output_tokens: 128000
|
||||
@@ -1669,6 +1860,8 @@
|
||||
output_price: 14
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high, xhigh]
|
||||
default_reasoning_effort: medium
|
||||
- name: openai/gpt-5.2
|
||||
max_input_tokens: 400000
|
||||
max_output_tokens: 128000
|
||||
@@ -1676,6 +1869,17 @@
|
||||
output_price: 14
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [none, low, medium, high, xhigh]
|
||||
default_reasoning_effort: none
|
||||
- name: openai/gpt-5.2-pro
|
||||
max_input_tokens: 400000
|
||||
max_output_tokens: 128000
|
||||
input_price: 21
|
||||
output_price: 168
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [medium, high, xhigh]
|
||||
default_reasoning_effort: medium
|
||||
- name: openai/gpt-5
|
||||
max_input_tokens: 400000
|
||||
max_output_tokens: 128000
|
||||
@@ -1683,6 +1887,8 @@
|
||||
output_price: 10
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [minimal, low, medium, high]
|
||||
default_reasoning_effort: medium
|
||||
- name: openai/gpt-5-mini
|
||||
max_input_tokens: 400000
|
||||
max_output_tokens: 128000
|
||||
@@ -1720,18 +1926,67 @@
|
||||
input_price: 0.04
|
||||
output_price: 0.16
|
||||
supports_function_calling: true
|
||||
- name: google/gemini-3.5-flash
|
||||
max_input_tokens: 1048576
|
||||
max_output_tokens: 65536
|
||||
input_price: 0.2
|
||||
output_price: 1.5
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [minimal, low, medium, high]
|
||||
default_reasoning_effort: medium
|
||||
- name: google/gemini-3-flash-preview
|
||||
max_input_tokens: 1048576
|
||||
max_output_tokens: 65536
|
||||
input_price: 0.2
|
||||
output_price: 1.5
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [minimal, low, medium, high]
|
||||
default_reasoning_effort: high
|
||||
- name: google/gemini-3.1-flash-lite
|
||||
max_input_tokens: 1048576
|
||||
max_output_tokens: 65536
|
||||
input_price: 0.2
|
||||
output_price: 1.5
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [minimal, low, medium, high]
|
||||
default_reasoning_effort: minimal
|
||||
- name: google/gemini-3.1-pro-preview
|
||||
max_input_tokens: 1048576
|
||||
max_output_tokens: 65535
|
||||
input_price: 0.3
|
||||
output_price: 2.5
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high]
|
||||
default_reasoning_effort: high
|
||||
- name: google/gemini-3-pro-preview
|
||||
max_input_tokens: 1048576
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, high]
|
||||
default_reasoning_level: high
|
||||
- name: google/gemini-3-flash-preview
|
||||
max_input_tokens: 1048576
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [minimal, low, medium, high]
|
||||
default_reasoning_level: high
|
||||
- name: google/gemini-2.5-flash
|
||||
max_input_tokens: 1048576
|
||||
input_price: 0.3
|
||||
output_price: 2.5
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high]
|
||||
default_reasoning_effort: low
|
||||
- name: google/gemini-2.5-pro
|
||||
max_input_tokens: 1048576
|
||||
input_price: 1.25
|
||||
output_price: 10
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high]
|
||||
default_reasoning_effort: high
|
||||
- name: google/gemini-2.5-flash-lite
|
||||
max_input_tokens: 1048576
|
||||
input_price: 0.3
|
||||
@@ -1761,6 +2016,8 @@
|
||||
output_price: 50
|
||||
supports_function_calling: true
|
||||
supports_vision: true
|
||||
reasoning_levels: [low, medium, high, xhigh, max]
|
||||
default_reasoning_effort: high
|
||||
- name: anthropic/claude-opus-4-8
|
||||
max_input_tokens: 1000000
|
||||
max_output_tokens: 128000
|
||||
@@ -1769,6 +2026,8 @@
|
||||
output_price: 25
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high, xhigh, max]
|
||||
default_reasoning_effort: high
|
||||
- name: anthropic/claude-opus-4-7
|
||||
max_input_tokens: 1000000
|
||||
max_output_tokens: 128000
|
||||
@@ -1777,6 +2036,8 @@
|
||||
output_price: 25
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high, xhigh, max]
|
||||
default_reasoning_effort: high
|
||||
- name: anthropic/claude-opus-4.6
|
||||
max_input_tokens: 200000
|
||||
max_output_tokens: 8192
|
||||
@@ -1785,6 +2046,18 @@
|
||||
output_price: 25
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high, max]
|
||||
default_reasoning_effort: high
|
||||
- name: anthropic/claude-sonnet-5
|
||||
max_input_tokens: 1000000
|
||||
max_output_tokens: 128000
|
||||
require_max_tokens: true
|
||||
input_price: 3
|
||||
output_price: 15
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high, xhigh, max]
|
||||
default_reasoning_effort: high
|
||||
- name: anthropic/claude-sonnet-4.6
|
||||
max_input_tokens: 200000
|
||||
max_output_tokens: 8192
|
||||
@@ -1793,6 +2066,8 @@
|
||||
output_price: 15
|
||||
supports_vision: true
|
||||
supports_function_calling: true
|
||||
reasoning_levels: [low, medium, high, max]
|
||||
default_reasoning_effort: high
|
||||
- name: anthropic/claude-opus-4.5
|
||||
max_input_tokens: 200000
|
||||
max_output_tokens: 8192
|
||||
|
||||
@@ -39,7 +39,7 @@ switch ([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) {
|
||||
|
||||
if (-not $BinDir) {
|
||||
if ($isWin) { $BinDir = Join-Path $env:LOCALAPPDATA 'coyote\bin' }
|
||||
else { $home = $env:HOME; if (-not $home) { $home = (Get-Item -Path ~).FullName }; $BinDir = Join-Path $home '.local/bin' }
|
||||
else { $userHome = $env:HOME; if (-not $userHome) { $userHome = (Get-Item -Path ~).FullName }; $BinDir = Join-Path $userHome '.local/bin' }
|
||||
}
|
||||
New-Item -ItemType Directory -Force -Path $BinDir | Out-Null
|
||||
|
||||
@@ -95,13 +95,13 @@ if ($asset.name -match '\.zip$') {
|
||||
[System.IO.Compression.ZipFile]::ExtractToDirectory($archive, $extractDir)
|
||||
} elseif ($asset.name -match '\.tar\.gz$' -or $asset.name -match '\.tgz$') {
|
||||
$tar = Get-Command tar -ErrorAction SilentlyContinue
|
||||
if ($tar) { & $tar.FullName -xzf $archive -C $extractDir }
|
||||
if ($tar) { & $tar.Source -xzf $archive -C $extractDir }
|
||||
else { Fail "Asset is tar archive but 'tar' is not available." }
|
||||
} else {
|
||||
try { Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory($archive, $extractDir) }
|
||||
catch {
|
||||
$tar = Get-Command tar -ErrorAction SilentlyContinue
|
||||
if ($tar) { & $tar.FullName -xf $archive -C $extractDir } else { Fail "Unknown archive format; neither zip nor tar workable." }
|
||||
if ($tar) { & $tar.Source -xf $archive -C $extractDir } else { Fail "Unknown archive format; neither zip nor tar workable." }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Regular → Executable
+13
-22
@@ -133,30 +133,21 @@ else
|
||||
echo "Error: unsupported OS for this installer: $OS" >&2; exit 1
|
||||
fi
|
||||
|
||||
DL_URLS=$(grep -oE '"browser_download_url":[[:space:]]*"[^"]+"' "$JSON" \
|
||||
| sed -E 's/.*"browser_download_url":[[:space:]]*"//; s/"$//' \
|
||||
|| true)
|
||||
|
||||
ASSET_NAME=""; ASSET_URL=""
|
||||
for candidate in "${ASSET_CANDIDATES[@]}"; do
|
||||
NAME=$(grep -oE '"name":\s*"[^"]+"' "$JSON" | sed 's/"name":\s*"//; s/"$//' | grep -Fx "$candidate" || true)
|
||||
if [[ -n "$NAME" ]]; then
|
||||
ASSET_NAME="$NAME"
|
||||
ASSET_URL=$(awk -v pat="$NAME" '
|
||||
BEGIN{ FS=":"; want=0 }
|
||||
/"name"/ {
|
||||
line=$0;
|
||||
gsub(/^\s+|\s+$/,"",line);
|
||||
gsub(/"name"\s*:\s*"|"/ ,"", line);
|
||||
want = (line==pat) ? 1 : 0;
|
||||
next
|
||||
}
|
||||
want==1 && /"browser_download_url"/ {
|
||||
u=$0;
|
||||
gsub(/^\s+|\s+$/,"",u);
|
||||
gsub(/.*"browser_download_url"\s*:\s*"|".*/ ,"", u);
|
||||
print u;
|
||||
exit
|
||||
}
|
||||
' "$JSON")
|
||||
if [[ -n "$ASSET_URL" ]]; then break; fi
|
||||
fi
|
||||
while IFS= read -r url; do
|
||||
[[ -z "$url" ]] && continue
|
||||
if [[ "$url" == */"$candidate" ]]; then
|
||||
ASSET_NAME="$candidate"
|
||||
ASSET_URL="$url"
|
||||
break
|
||||
fi
|
||||
done <<< "$DL_URLS"
|
||||
[[ -n "$ASSET_URL" ]] && break
|
||||
done
|
||||
|
||||
if [[ -z "$ASSET_URL" ]]; then
|
||||
|
||||
+29
-1
@@ -5,9 +5,9 @@ use crate::utils::list_file_names;
|
||||
use crate::vault::Vault;
|
||||
use clap_complete::{CompletionCandidate, Shell, generate};
|
||||
use clap_complete_nushell::Nushell;
|
||||
use std::env;
|
||||
use std::ffi::OsStr;
|
||||
use std::io;
|
||||
use std::{env, fs};
|
||||
|
||||
const COYOTE_CLI_NAME: &str = "coyote";
|
||||
|
||||
@@ -134,6 +134,34 @@ pub(super) fn session_completer(current: &OsStr) -> Vec<CompletionCandidate> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub(super) fn mcp_server_completer(current: &OsStr) -> Vec<CompletionCandidate> {
|
||||
let cur = current.to_string_lossy();
|
||||
let content = match fs::read_to_string(paths::mcp_config_file()) {
|
||||
Ok(c) => c,
|
||||
Err(_) => return vec![],
|
||||
};
|
||||
let json: serde_json::Value = match serde_json::from_str(&content) {
|
||||
Ok(v) => v,
|
||||
Err(_) => return vec![],
|
||||
};
|
||||
let servers = match json.get("mcpServers").and_then(|v| v.as_object()) {
|
||||
Some(s) => s,
|
||||
None => return vec![],
|
||||
};
|
||||
|
||||
servers
|
||||
.iter()
|
||||
.filter(|(_, v)| {
|
||||
v.get("type")
|
||||
.and_then(|t| t.as_str())
|
||||
.map(|t| t == "http" || t == "sse")
|
||||
.unwrap_or(false)
|
||||
})
|
||||
.filter(|(k, _)| k.starts_with(&*cur))
|
||||
.map(|(k, _)| CompletionCandidate::new(k))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub(super) fn secrets_completer(current: &OsStr) -> Vec<CompletionCandidate> {
|
||||
let cur = current.to_string_lossy();
|
||||
match load_app_config_for_completion() {
|
||||
|
||||
+176
-106
@@ -1,8 +1,8 @@
|
||||
mod completer;
|
||||
|
||||
use crate::cli::completer::{
|
||||
ShellCompletion, agent_completer, macro_completer, model_completer, rag_completer,
|
||||
role_completer, secrets_completer, session_completer,
|
||||
ShellCompletion, agent_completer, macro_completer, mcp_server_completer, model_completer,
|
||||
rag_completer, role_completer, secrets_completer, session_completer,
|
||||
};
|
||||
use crate::config::{AssetCategory, InstallFilter, MemoryScope};
|
||||
use anyhow::{Context, Result};
|
||||
@@ -43,6 +43,10 @@ use std::io::{Read, stdin};
|
||||
),
|
||||
)]
|
||||
pub struct Cli {
|
||||
/// Input text
|
||||
#[arg(trailing_var_arg = true)]
|
||||
text: Vec<String>,
|
||||
|
||||
/// Select a LLM model
|
||||
#[arg(short, long, add = ArgValueCompleter::new(model_completer))]
|
||||
pub model: Option<String>,
|
||||
@@ -52,30 +56,6 @@ pub struct Cli {
|
||||
/// Select a role
|
||||
#[arg(short, long, add = ArgValueCompleter::new(role_completer))]
|
||||
pub role: Option<String>,
|
||||
/// Start or join a session
|
||||
#[arg(short = 's', long, add = ArgValueCompleter::new(session_completer))]
|
||||
pub session: Option<Option<String>>,
|
||||
/// Ensure the session is empty
|
||||
#[arg(long)]
|
||||
pub empty_session: bool,
|
||||
/// Ensure the new conversation is saved to the session
|
||||
#[arg(long)]
|
||||
pub save_session: bool,
|
||||
/// Start an agent
|
||||
#[arg(short = 'a', long, add = ArgValueCompleter::new(agent_completer))]
|
||||
pub agent: Option<String>,
|
||||
/// Set agent variables
|
||||
#[arg(long, value_names = ["NAME", "VALUE"], num_args = 2)]
|
||||
pub agent_variable: Vec<String>,
|
||||
/// Start a RAG
|
||||
#[arg(long, add = ArgValueCompleter::new(rag_completer))]
|
||||
pub rag: Option<String>,
|
||||
/// Rebuild the RAG to sync document changes
|
||||
#[arg(long)]
|
||||
pub rebuild_rag: bool,
|
||||
/// Execute a macro
|
||||
#[arg(long = "macro", value_name = "MACRO", add = ArgValueCompleter::new(macro_completer))]
|
||||
pub macro_name: Option<String>,
|
||||
/// Execute commands in natural language
|
||||
#[arg(short = 'e', long)]
|
||||
pub execute: bool,
|
||||
@@ -88,107 +68,185 @@ pub struct Cli {
|
||||
/// Turn off stream mode
|
||||
#[arg(short = 'S', long)]
|
||||
pub no_stream: bool,
|
||||
/// Disable memory for this invocation
|
||||
#[arg(long)]
|
||||
pub no_memory: bool,
|
||||
/// Bootstrap a memory marker so coyote begins loading memory next run
|
||||
#[arg(long, value_name = "SCOPE", value_enum)]
|
||||
pub init_memory: Option<MemoryScope>,
|
||||
/// Display the message without sending it
|
||||
#[arg(long)]
|
||||
pub dry_run: bool,
|
||||
/// Display information
|
||||
/// Disable loading workspace MCP servers from .coyote/mcp.json, .coyote/.mcp.json, or .mcp.json
|
||||
#[arg(long)]
|
||||
pub info: bool,
|
||||
/// Build all configured Bash tool scripts
|
||||
pub no_workspace_mcp: bool,
|
||||
/// Disable memory for this invocation
|
||||
#[arg(long)]
|
||||
pub build_tools: bool,
|
||||
/// Reinstall bundled assets, overwriting any local changes
|
||||
#[arg(long, value_name = "CATEGORY", value_enum)]
|
||||
pub install: Option<AssetCategory>,
|
||||
/// Install assets from a remote git repository (URL may be suffixed with #<ref>)
|
||||
#[arg(long, value_name = "GIT_URL")]
|
||||
pub install_from: Option<String>,
|
||||
/// Restrict --install-from to a single asset category
|
||||
#[arg(long, value_name = "CATEGORY", value_enum, requires = "install_from")]
|
||||
pub filter: Option<InstallFilter>,
|
||||
/// Overwrite all conflicts without prompting (used with --install-from)
|
||||
#[arg(long, requires = "install_from")]
|
||||
pub install_force: bool,
|
||||
/// Sync models updates
|
||||
pub no_memory: bool,
|
||||
/// Disable loading workspace instructions (COYOTE.md/AGENTS.md/CLAUDE.md/etc.) for this invocation
|
||||
#[arg(long)]
|
||||
pub sync_models: bool,
|
||||
/// List all available chat models
|
||||
pub no_workspace_instructions: bool,
|
||||
/// Override the workspace instructions file chain for this invocation (repeatable, priority order)
|
||||
#[arg(long, value_name = "NAME")]
|
||||
pub workspace_instructions_file: Vec<String>,
|
||||
/// Skip permission prompts by setting AUTO_CONFIRM for all tools (dangerous!)
|
||||
#[arg(long)]
|
||||
pub list_models: bool,
|
||||
/// List all roles
|
||||
#[arg(long)]
|
||||
pub list_roles: bool,
|
||||
/// List all sessions
|
||||
#[arg(long)]
|
||||
pub list_sessions: bool,
|
||||
/// List all agents
|
||||
#[arg(long)]
|
||||
pub list_agents: bool,
|
||||
/// List all RAGs
|
||||
#[arg(long)]
|
||||
pub list_rags: bool,
|
||||
/// List all macros
|
||||
#[arg(long)]
|
||||
pub list_macros: bool,
|
||||
/// List all installed skills
|
||||
#[arg(long)]
|
||||
pub list_skills: bool,
|
||||
pub dangerously_skip_permissions: bool,
|
||||
|
||||
/// Start or join a session
|
||||
#[arg(short = 's', long, help_heading = "Session & Memory", add = ArgValueCompleter::new(session_completer))]
|
||||
pub session: Option<Option<String>>,
|
||||
/// Ensure the session is empty
|
||||
#[arg(long, help_heading = "Session & Memory")]
|
||||
pub empty_session: bool,
|
||||
/// Ensure the new conversation is saved to the session
|
||||
#[arg(long, help_heading = "Session & Memory")]
|
||||
pub save_session: bool,
|
||||
/// Bootstrap a memory marker so coyote begins loading memory next run
|
||||
#[arg(
|
||||
long,
|
||||
value_name = "SCOPE",
|
||||
value_enum,
|
||||
help_heading = "Session & Memory"
|
||||
)]
|
||||
pub init_memory: Option<MemoryScope>,
|
||||
/// Scaffold a COYOTE.md workspace instructions file in the current directory
|
||||
#[arg(long, help_heading = "Session & Memory")]
|
||||
pub init_instructions: bool,
|
||||
/// Pre-load an existing skill into the session (repeatable). If a single
|
||||
/// `--skill <NAME>` is given and the skill doesn't exist, opens $EDITOR
|
||||
/// with a scaffold to create it.
|
||||
#[arg(long, value_name = "NAME")]
|
||||
#[arg(long, value_name = "NAME", help_heading = "Session & Memory")]
|
||||
pub skill: Vec<String>,
|
||||
/// Input text
|
||||
#[arg(trailing_var_arg = true)]
|
||||
text: Vec<String>,
|
||||
/// Tail logs
|
||||
#[arg(long)]
|
||||
pub tail_logs: bool,
|
||||
/// Disable colored log output
|
||||
#[arg(long, requires = "tail_logs")]
|
||||
pub disable_log_colors: bool,
|
||||
/// Add a secret to the Coyote vault
|
||||
#[arg(long, value_name = "SECRET_NAME", exclusive = true)]
|
||||
pub add_secret: Option<String>,
|
||||
/// Decrypt a secret from the Coyote vault and print the plaintext
|
||||
#[arg(long, value_name = "SECRET_NAME", exclusive = true, add = ArgValueCompleter::new(secrets_completer))]
|
||||
pub get_secret: Option<String>,
|
||||
/// Update an existing secret in the Coyote vault
|
||||
#[arg(long, value_name = "SECRET_NAME", exclusive = true, add = ArgValueCompleter::new(secrets_completer))]
|
||||
pub update_secret: Option<String>,
|
||||
/// Delete a secret from the Coyote vault
|
||||
#[arg(long, value_name = "SECRET_NAME", exclusive = true, add = ArgValueCompleter::new(secrets_completer))]
|
||||
pub delete_secret: Option<String>,
|
||||
/// List all secrets stored in the Coyote vault
|
||||
#[arg(long, exclusive = true)]
|
||||
pub list_secrets: bool,
|
||||
/// Authenticate with an LLM provider using OAuth (e.g., --authenticate client_name)
|
||||
#[arg(long, exclusive = true, value_name = "CLIENT_NAME")]
|
||||
pub authenticate: Option<Option<String>>,
|
||||
/// Generate static shell completion scripts
|
||||
#[arg(long, value_name = "SHELL", value_enum)]
|
||||
pub completions: Option<ShellCompletion>,
|
||||
|
||||
/// Start an agent
|
||||
#[arg(short = 'a', long, help_heading = "Agents, RAG & Macros", add = ArgValueCompleter::new(agent_completer))]
|
||||
pub agent: Option<String>,
|
||||
/// Set agent variables
|
||||
#[arg(long, value_names = ["NAME", "VALUE"], num_args = 2, help_heading = "Agents, RAG & Macros")]
|
||||
pub agent_variable: Vec<String>,
|
||||
/// Start a RAG
|
||||
#[arg(long, help_heading = "Agents, RAG & Macros", add = ArgValueCompleter::new(rag_completer))]
|
||||
pub rag: Option<String>,
|
||||
/// Rebuild the RAG to sync document changes
|
||||
#[arg(long, help_heading = "Agents, RAG & Macros")]
|
||||
pub rebuild_rag: bool,
|
||||
/// Execute a macro
|
||||
#[arg(long = "macro", value_name = "MACRO", help_heading = "Agents, RAG & Macros", add = ArgValueCompleter::new(macro_completer))]
|
||||
pub macro_name: Option<String>,
|
||||
|
||||
/// List all available chat models
|
||||
#[arg(long, help_heading = "List & Discovery")]
|
||||
pub list_models: bool,
|
||||
/// List all roles
|
||||
#[arg(long, help_heading = "List & Discovery")]
|
||||
pub list_roles: bool,
|
||||
/// List all sessions
|
||||
#[arg(long, help_heading = "List & Discovery")]
|
||||
pub list_sessions: bool,
|
||||
/// List all agents
|
||||
#[arg(long, help_heading = "List & Discovery")]
|
||||
pub list_agents: bool,
|
||||
/// List all RAGs
|
||||
#[arg(long, help_heading = "List & Discovery")]
|
||||
pub list_rags: bool,
|
||||
/// List all macros
|
||||
#[arg(long, help_heading = "List & Discovery")]
|
||||
pub list_macros: bool,
|
||||
/// List all installed skills
|
||||
#[arg(long, help_heading = "List & Discovery")]
|
||||
pub list_skills: bool,
|
||||
|
||||
/// Reinstall bundled assets, overwriting any local changes
|
||||
#[arg(
|
||||
long,
|
||||
value_name = "CATEGORY",
|
||||
value_enum,
|
||||
help_heading = "Installation & Updates"
|
||||
)]
|
||||
pub install: Option<AssetCategory>,
|
||||
/// Install assets from a remote git repository (URL may be suffixed with #<ref>)
|
||||
#[arg(long, value_name = "GIT_URL", help_heading = "Installation & Updates")]
|
||||
pub install_from: Option<String>,
|
||||
/// Restrict --install-from to a single asset category
|
||||
#[arg(
|
||||
long,
|
||||
value_name = "CATEGORY",
|
||||
value_enum,
|
||||
requires = "install_from",
|
||||
help_heading = "Installation & Updates"
|
||||
)]
|
||||
pub filter: Option<InstallFilter>,
|
||||
/// Overwrite all conflicts without prompting (used with --install-from)
|
||||
#[arg(
|
||||
long,
|
||||
requires = "install_from",
|
||||
help_heading = "Installation & Updates"
|
||||
)]
|
||||
pub install_force: bool,
|
||||
/// Sync models updates
|
||||
#[arg(long, help_heading = "Installation & Updates")]
|
||||
pub sync_models: bool,
|
||||
/// Update Coyote to the latest release, or to a specific version
|
||||
#[arg(long, value_name = "VERSION")]
|
||||
#[arg(long, value_name = "VERSION", help_heading = "Installation & Updates")]
|
||||
pub update: Option<Option<String>>,
|
||||
/// With --update, update even if Coyote was installed via a package manager
|
||||
#[arg(long, requires = "update")]
|
||||
#[arg(long, requires = "update", help_heading = "Installation & Updates")]
|
||||
pub force: bool,
|
||||
|
||||
/// Add a secret to the Coyote vault
|
||||
#[arg(
|
||||
long,
|
||||
value_name = "SECRET_NAME",
|
||||
exclusive = true,
|
||||
help_heading = "Vault & Secrets"
|
||||
)]
|
||||
pub add_secret: Option<String>,
|
||||
/// Decrypt a secret from the Coyote vault and print the plaintext
|
||||
#[arg(long, value_name = "SECRET_NAME", exclusive = true, help_heading = "Vault & Secrets", add = ArgValueCompleter::new(secrets_completer))]
|
||||
pub get_secret: Option<String>,
|
||||
/// Update an existing secret in the Coyote vault
|
||||
#[arg(long, value_name = "SECRET_NAME", exclusive = true, help_heading = "Vault & Secrets", add = ArgValueCompleter::new(secrets_completer))]
|
||||
pub update_secret: Option<String>,
|
||||
/// Delete a secret from the Coyote vault
|
||||
#[arg(long, value_name = "SECRET_NAME", exclusive = true, help_heading = "Vault & Secrets", add = ArgValueCompleter::new(secrets_completer))]
|
||||
pub delete_secret: Option<String>,
|
||||
/// List all secrets stored in the Coyote vault
|
||||
#[arg(long, exclusive = true, help_heading = "Vault & Secrets")]
|
||||
pub list_secrets: bool,
|
||||
|
||||
/// Authenticate with an LLM provider using OAuth (e.g., --authenticate client_name)
|
||||
#[arg(
|
||||
long,
|
||||
exclusive = true,
|
||||
value_name = "CLIENT_NAME",
|
||||
help_heading = "Authentication"
|
||||
)]
|
||||
pub authenticate: Option<Option<String>>,
|
||||
/// Authenticate with an OAuth-protected remote MCP server (e.g., --auth-mcp server_name)
|
||||
#[arg(long, exclusive = true, value_name = "SERVER_NAME", help_heading = "Authentication", add = ArgValueCompleter::new(mcp_server_completer))]
|
||||
pub auth_mcp: Option<String>,
|
||||
|
||||
/// Launch Coyote inside a Docker sandbox (via `sbx`); name defaults to current directory basename
|
||||
#[arg(long, value_name = "NAME")]
|
||||
#[arg(long, value_name = "NAME", help_heading = "Sandbox")]
|
||||
pub sandbox: Option<Option<String>>,
|
||||
/// Create the sandbox without bootstrapping the host config or vault password file
|
||||
#[arg(long, requires = "sandbox")]
|
||||
#[arg(long, requires = "sandbox", help_heading = "Sandbox")]
|
||||
pub fresh: bool,
|
||||
/// Skip discovery and application of all sbx mixins (user and built-in)
|
||||
#[arg(long, requires = "sandbox")]
|
||||
#[arg(long, requires = "sandbox", help_heading = "Sandbox")]
|
||||
pub no_mixins: bool,
|
||||
|
||||
/// Display information
|
||||
#[arg(long, help_heading = "Diagnostics & Tools")]
|
||||
pub info: bool,
|
||||
/// Build all configured Bash tool scripts
|
||||
#[arg(long, help_heading = "Diagnostics & Tools")]
|
||||
pub build_tools: bool,
|
||||
/// Tail logs
|
||||
#[arg(long, help_heading = "Diagnostics & Tools")]
|
||||
pub tail_logs: bool,
|
||||
/// Disable colored log output
|
||||
#[arg(long, requires = "tail_logs", help_heading = "Diagnostics & Tools")]
|
||||
pub disable_log_colors: bool,
|
||||
|
||||
/// Generate static shell completion scripts
|
||||
#[arg(long, value_name = "SHELL", value_enum, help_heading = "Shell")]
|
||||
pub completions: Option<ShellCompletion>,
|
||||
}
|
||||
|
||||
impl Cli {
|
||||
@@ -421,6 +479,18 @@ mod tests {
|
||||
assert!(cli.build_tools);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_dangerously_skip_permissions_flag() {
|
||||
let cli = parse(&["--dangerously-skip-permissions"]);
|
||||
assert!(cli.dangerously_skip_permissions);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_dangerously_skip_permissions_default_off() {
|
||||
let cli = parse(&[]);
|
||||
assert!(!cli.dangerously_skip_permissions);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_sync_models_flag() {
|
||||
let cli = parse(&["--sync-models"]);
|
||||
|
||||
@@ -4,29 +4,44 @@ use indexmap::IndexMap;
|
||||
use parking_lot::RwLock;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
static ACCESS_TOKENS: LazyLock<RwLock<IndexMap<String, (String, i64)>>> =
|
||||
type AccessTokenEntry = (String, i64, Option<String>);
|
||||
|
||||
static ACCESS_TOKENS: LazyLock<RwLock<IndexMap<String, AccessTokenEntry>>> =
|
||||
LazyLock::new(|| RwLock::new(IndexMap::new()));
|
||||
|
||||
pub fn get_access_token(client_name: &str) -> Result<String> {
|
||||
ACCESS_TOKENS
|
||||
.read()
|
||||
.get(client_name)
|
||||
.map(|(token, _)| token.clone())
|
||||
.map(|(token, _, _)| token.clone())
|
||||
.ok_or_else(|| anyhow!("Invalid access token"))
|
||||
}
|
||||
|
||||
pub fn get_access_token_account_id(client_name: &str) -> Option<String> {
|
||||
ACCESS_TOKENS
|
||||
.read()
|
||||
.get(client_name)
|
||||
.and_then(|(_, _, account_id)| account_id.clone())
|
||||
}
|
||||
|
||||
pub fn is_valid_access_token(client_name: &str) -> bool {
|
||||
let access_tokens = ACCESS_TOKENS.read();
|
||||
let (token, expires_at) = match access_tokens.get(client_name) {
|
||||
let (token, expires_at, _) = match access_tokens.get(client_name) {
|
||||
Some(v) => v,
|
||||
None => return false,
|
||||
};
|
||||
!token.is_empty() && Utc::now().timestamp() < *expires_at
|
||||
}
|
||||
|
||||
pub fn set_access_token(client_name: &str, token: String, expires_at: i64) {
|
||||
pub fn set_access_token(
|
||||
client_name: &str,
|
||||
token: String,
|
||||
expires_at: i64,
|
||||
account_id: Option<String>,
|
||||
) {
|
||||
let mut access_tokens = ACCESS_TOKENS.write();
|
||||
let entry = access_tokens.entry(client_name.to_string()).or_default();
|
||||
entry.0 = token;
|
||||
entry.1 = expires_at;
|
||||
entry.2 = account_id;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ fn prepare_chat_completions(
|
||||
|
||||
let url = format!(
|
||||
"{}/openai/deployments/{}/chat/completions?api-version=2024-12-01-preview",
|
||||
&api_base,
|
||||
api_base,
|
||||
self_.model.real_name()
|
||||
);
|
||||
|
||||
@@ -69,7 +69,7 @@ fn prepare_embeddings(self_: &AzureOpenAIClient, data: &EmbeddingsData) -> Resul
|
||||
|
||||
let url = format!(
|
||||
"{}/openai/deployments/{}/embeddings?api-version=2024-10-21",
|
||||
&api_base,
|
||||
api_base,
|
||||
self_.model.real_name()
|
||||
);
|
||||
|
||||
|
||||
+10
-1
@@ -325,6 +325,7 @@ fn build_chat_completions_body(data: ChatCompletionsData, model: &Model) -> Resu
|
||||
mut messages,
|
||||
temperature,
|
||||
top_p,
|
||||
reasoning_effort,
|
||||
functions,
|
||||
stream: _,
|
||||
} = data;
|
||||
@@ -396,6 +397,11 @@ fn build_chat_completions_body(data: ChatCompletionsData, model: &Model) -> Resu
|
||||
}))
|
||||
}
|
||||
for tool_result in tool_results {
|
||||
if let Some(round_text) = &tool_result.text {
|
||||
assistant_parts.push(json!({
|
||||
"text": round_text,
|
||||
}))
|
||||
}
|
||||
assistant_parts.push(json!({
|
||||
"toolUse": {
|
||||
"toolUseId": tool_result.call.id,
|
||||
@@ -457,6 +463,9 @@ fn build_chat_completions_body(data: ChatCompletionsData, model: &Model) -> Resu
|
||||
if let Some(v) = top_p {
|
||||
body["inferenceConfig"]["topP"] = v.into();
|
||||
}
|
||||
if let Some(v) = reasoning_effort {
|
||||
body["additionalModelRequestFields"] = json!({ "output_config": { "effort": v } });
|
||||
}
|
||||
if let Some(functions) = functions {
|
||||
let tools: Vec<_> = functions
|
||||
.iter()
|
||||
@@ -520,7 +529,7 @@ fn extract_chat_completions(data: &Value) -> Result<ChatCompletionsOutput> {
|
||||
bail!("Invalid response data: {data}");
|
||||
}
|
||||
|
||||
let output = ChatCompletionsOutput { text, tool_calls };
|
||||
let output = ChatCompletionsOutput { text, tool_calls, ..Default::default() };
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
|
||||
+53
-7
@@ -168,12 +168,22 @@ pub async fn claude_chat_completions_streaming(
|
||||
let mut function_arguments = String::new();
|
||||
let mut function_id = String::new();
|
||||
let mut reasoning_state = 0;
|
||||
let mut thinking_text = String::new();
|
||||
let mut thinking_signature = String::new();
|
||||
let handle = |message: SseMessage| -> Result<bool> {
|
||||
let data: Value = serde_json::from_str(&message.data)?;
|
||||
debug!("stream-data: {data}");
|
||||
if let Some(typ) = data["type"].as_str() {
|
||||
match typ {
|
||||
"content_block_start" => {
|
||||
if let (Some("redacted_thinking"), Some(redacted_data)) = (
|
||||
data["content_block"]["type"].as_str(),
|
||||
data["content_block"]["data"].as_str(),
|
||||
) {
|
||||
handler.thinking_block(ThinkingBlock::RedactedThinking {
|
||||
data: redacted_data.to_string(),
|
||||
});
|
||||
}
|
||||
if let (Some("tool_use"), Some(name), Some(id)) = (
|
||||
data["content_block"]["type"].as_str(),
|
||||
data["content_block"]["name"].as_str(),
|
||||
@@ -206,7 +216,10 @@ pub async fn claude_chat_completions_streaming(
|
||||
handler.text("<think>\n")?;
|
||||
reasoning_state = 1;
|
||||
}
|
||||
thinking_text.push_str(text);
|
||||
handler.text(text)?;
|
||||
} else if let Some(signature) = data["delta"]["signature"].as_str() {
|
||||
thinking_signature.push_str(signature);
|
||||
} else if let (true, Some(partial_json)) = (
|
||||
!function_name.is_empty(),
|
||||
data["delta"]["partial_json"].as_str(),
|
||||
@@ -218,6 +231,10 @@ pub async fn claude_chat_completions_streaming(
|
||||
if reasoning_state == 1 {
|
||||
handler.text("\n</think>\n\n")?;
|
||||
reasoning_state = 0;
|
||||
handler.thinking_block(ThinkingBlock::Thinking {
|
||||
thinking: std::mem::take(&mut thinking_text),
|
||||
signature: std::mem::take(&mut thinking_signature),
|
||||
});
|
||||
}
|
||||
if !function_name.is_empty() {
|
||||
let arguments: Value = if function_arguments.is_empty() {
|
||||
@@ -251,6 +268,7 @@ pub fn claude_build_chat_completions_body(
|
||||
mut messages,
|
||||
temperature,
|
||||
top_p,
|
||||
reasoning_effort,
|
||||
functions,
|
||||
stream,
|
||||
} = data;
|
||||
@@ -312,13 +330,25 @@ pub fn claude_build_chat_completions_body(
|
||||
}) => {
|
||||
let mut assistant_parts = vec![];
|
||||
let mut user_parts = vec![];
|
||||
if !text.is_empty() {
|
||||
assistant_parts.push(json!({
|
||||
"type": "text",
|
||||
"text": text,
|
||||
}))
|
||||
}
|
||||
for tool_result in tool_results {
|
||||
for (index, tool_result) in tool_results.iter().enumerate() {
|
||||
for block in &tool_result.thinking {
|
||||
assistant_parts.push(json!(block));
|
||||
}
|
||||
let round_text = if index == 0 && !text.is_empty() {
|
||||
Some(text.as_str())
|
||||
} else {
|
||||
tool_result.text.as_deref()
|
||||
};
|
||||
if let Some(round_text) = round_text {
|
||||
let round_text = strip_think_tag(round_text);
|
||||
let round_text = round_text.trim();
|
||||
if !round_text.is_empty() {
|
||||
assistant_parts.push(json!({
|
||||
"type": "text",
|
||||
"text": round_text,
|
||||
}))
|
||||
}
|
||||
}
|
||||
assistant_parts.push(json!({
|
||||
"type": "tool_use",
|
||||
"id": tool_result.call.id,
|
||||
@@ -369,6 +399,9 @@ pub fn claude_build_chat_completions_body(
|
||||
if let Some(v) = top_p {
|
||||
body["top_p"] = v.into();
|
||||
}
|
||||
if let Some(v) = reasoning_effort {
|
||||
body["output_config"] = json!({ "effort": v });
|
||||
}
|
||||
if stream {
|
||||
body["stream"] = true.into();
|
||||
}
|
||||
@@ -399,12 +432,24 @@ pub fn claude_extract_chat_completions(data: &Value) -> Result<ChatCompletionsOu
|
||||
let mut text = String::new();
|
||||
let mut reasoning = None;
|
||||
let mut tool_calls = vec![];
|
||||
let mut thinking = vec![];
|
||||
if let Some(list) = data["content"].as_array() {
|
||||
for item in list {
|
||||
match item["type"].as_str() {
|
||||
Some("thinking") => {
|
||||
if let Some(v) = item["thinking"].as_str() {
|
||||
reasoning = Some(v.to_string());
|
||||
thinking.push(ThinkingBlock::Thinking {
|
||||
thinking: v.to_string(),
|
||||
signature: item["signature"].as_str().unwrap_or_default().to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
Some("redacted_thinking") => {
|
||||
if let Some(v) = item["data"].as_str() {
|
||||
thinking.push(ThinkingBlock::RedactedThinking {
|
||||
data: v.to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
Some("text") => {
|
||||
@@ -443,6 +488,7 @@ pub fn claude_extract_chat_completions(data: &Value) -> Result<ChatCompletionsOu
|
||||
let output = ChatCompletionsOutput {
|
||||
text: text.to_string(),
|
||||
tool_calls,
|
||||
thinking,
|
||||
};
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
@@ -244,6 +244,6 @@ fn extract_chat_completions(data: &Value) -> Result<ChatCompletionsOutput> {
|
||||
if text.is_empty() && tool_calls.is_empty() {
|
||||
bail!("Invalid response data: {data}");
|
||||
}
|
||||
let output = ChatCompletionsOutput { text, tool_calls };
|
||||
let output = ChatCompletionsOutput { text, tool_calls, ..Default::default() };
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
+12
-3
@@ -286,6 +286,7 @@ pub struct ChatCompletionsData {
|
||||
pub messages: Vec<Message>,
|
||||
pub temperature: Option<f64>,
|
||||
pub top_p: Option<f64>,
|
||||
pub reasoning_effort: Option<String>,
|
||||
pub functions: Option<Vec<FunctionDeclaration>>,
|
||||
pub stream: bool,
|
||||
}
|
||||
@@ -294,6 +295,7 @@ pub struct ChatCompletionsData {
|
||||
pub struct ChatCompletionsOutput {
|
||||
pub text: String,
|
||||
pub tool_calls: Vec<ToolCall>,
|
||||
pub thinking: Vec<ThinkingBlock>,
|
||||
}
|
||||
|
||||
impl ChatCompletionsOutput {
|
||||
@@ -434,6 +436,7 @@ pub async fn call_chat_completions(
|
||||
let ChatCompletionsOutput {
|
||||
mut text,
|
||||
tool_calls,
|
||||
thinking,
|
||||
..
|
||||
} = ret;
|
||||
if !text.is_empty() {
|
||||
@@ -444,7 +447,10 @@ pub async fn call_chat_completions(
|
||||
ctx.app.config.print_markdown(&text)?;
|
||||
}
|
||||
}
|
||||
let tool_results = eval_tool_calls(ctx, tool_calls).await?;
|
||||
let mut tool_results = eval_tool_calls(ctx, tool_calls).await?;
|
||||
if let Some(first) = tool_results.first_mut() {
|
||||
first.thinking = thinking;
|
||||
}
|
||||
tool_results
|
||||
.iter()
|
||||
.for_each(|res| ctx.tool_scope.tool_tracker.record_call(res.call.clone()));
|
||||
@@ -478,13 +484,16 @@ pub async fn call_chat_completions_streaming(
|
||||
|
||||
render_ret?;
|
||||
|
||||
let (text, tool_calls) = handler.take();
|
||||
let (text, tool_calls, thinking) = handler.take();
|
||||
match send_ret {
|
||||
Ok(_) => {
|
||||
if !text.is_empty() && !text.ends_with('\n') {
|
||||
println!();
|
||||
}
|
||||
let tool_results = eval_tool_calls(ctx, tool_calls).await?;
|
||||
let mut tool_results = eval_tool_calls(ctx, tool_calls).await?;
|
||||
if let Some(first) = tool_results.first_mut() {
|
||||
first.thinking = thinking;
|
||||
}
|
||||
tool_results
|
||||
.iter()
|
||||
.for_each(|res| ctx.tool_scope.tool_tracker.record_call(res.call.clone()));
|
||||
|
||||
+27
-2
@@ -118,6 +118,9 @@ impl MessageContent {
|
||||
lines.push(text.clone())
|
||||
}
|
||||
for tool_result in tool_results {
|
||||
if let Some(round_text) = &tool_result.text {
|
||||
lines.push(round_text.clone())
|
||||
}
|
||||
let mut parts = vec!["Call".to_string()];
|
||||
if let Some((agent_name, functions)) = agent_info
|
||||
&& functions.contains(&tool_result.call.name)
|
||||
@@ -133,6 +136,13 @@ impl MessageContent {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_text(&self) -> Option<&str> {
|
||||
match self {
|
||||
MessageContent::Text(text) => Some(text),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn merge_prompt(&mut self, replace_fn: impl Fn(&str) -> String) {
|
||||
match self {
|
||||
MessageContent::Text(text) => *text = replace_fn(text),
|
||||
@@ -178,6 +188,17 @@ pub struct ImageUrl {
|
||||
pub url: String,
|
||||
}
|
||||
|
||||
/// An extended-thinking block returned by Anthropic-protocol models.
|
||||
/// Serialized to match the API wire format (`type: thinking` / `type: redacted_thinking`)
|
||||
/// so blocks can be replayed verbatim, signature intact, in subsequent
|
||||
/// tool-loop rounds as the API requires.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(tag = "type", rename_all = "snake_case")]
|
||||
pub enum ThinkingBlock {
|
||||
Thinking { thinking: String, signature: String },
|
||||
RedactedThinking { data: String },
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct MessageContentToolCalls {
|
||||
pub tool_results: Vec<ToolResult>,
|
||||
@@ -194,9 +215,13 @@ impl MessageContentToolCalls {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn merge(&mut self, tool_results: Vec<ToolResult>, _text: String) {
|
||||
pub fn merge(&mut self, mut tool_results: Vec<ToolResult>, text: String) {
|
||||
if !text.is_empty()
|
||||
&& let Some(first) = tool_results.first_mut()
|
||||
{
|
||||
first.text = Some(text);
|
||||
}
|
||||
self.tool_results.extend(tool_results);
|
||||
self.text.clear();
|
||||
self.sequence = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ mod common;
|
||||
mod gemini_oauth;
|
||||
mod message;
|
||||
pub mod oauth;
|
||||
mod openai_oauth;
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
mod model;
|
||||
|
||||
@@ -289,6 +289,14 @@ impl Model {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn reasoning_levels(&self) -> &[String] {
|
||||
&self.data.reasoning_levels
|
||||
}
|
||||
|
||||
pub fn default_reasoning_effort(&self) -> Option<&str> {
|
||||
self.data.default_reasoning_effort.as_deref()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||
@@ -316,6 +324,10 @@ pub struct ModelData {
|
||||
pub supports_vision: bool,
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
pub supports_function_calling: bool,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub reasoning_levels: Vec<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub default_reasoning_effort: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
no_stream: bool,
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
|
||||
+62
-25
@@ -53,13 +53,28 @@ pub trait OAuthProvider: Send + Sync {
|
||||
fn extra_request_headers(&self) -> Vec<(&str, &str)> {
|
||||
vec![]
|
||||
}
|
||||
|
||||
fn fixed_redirect_uri(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
|
||||
fn extract_account_id(&self, _response: &Value) -> Option<String> {
|
||||
None
|
||||
}
|
||||
|
||||
fn include_state_in_token_exchange(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct OAuthTokens {
|
||||
pub access_token: String,
|
||||
pub refresh_token: String,
|
||||
#[serde(default)]
|
||||
pub refresh_token: Option<String>,
|
||||
pub expires_at: i64,
|
||||
#[serde(default)]
|
||||
pub account_id: Option<String>,
|
||||
}
|
||||
|
||||
pub async fn run_oauth_flow(provider: &dyn OAuthProvider, client_name: &str) -> Result<()> {
|
||||
@@ -72,14 +87,16 @@ pub async fn run_oauth_flow(provider: &dyn OAuthProvider, client_name: &str) ->
|
||||
|
||||
let state = Uuid::new_v4().to_string();
|
||||
|
||||
let redirect_uri = if provider.uses_localhost_redirect() {
|
||||
let (redirect_uri, use_callback_listener) = if let Some(fixed) = provider.fixed_redirect_uri() {
|
||||
(fixed, true)
|
||||
} else if provider.uses_localhost_redirect() {
|
||||
let listener = TcpListener::bind("127.0.0.1:0")?;
|
||||
let port = listener.local_addr()?.port();
|
||||
let uri = format!("http://127.0.0.1:{port}/callback");
|
||||
drop(listener);
|
||||
uri
|
||||
(uri, true)
|
||||
} else {
|
||||
provider.redirect_uri().to_string()
|
||||
(provider.redirect_uri().to_string(), false)
|
||||
};
|
||||
|
||||
let encoded_scopes = urlencoding::encode(provider.scopes());
|
||||
@@ -112,7 +129,7 @@ pub async fn run_oauth_flow(provider: &dyn OAuthProvider, client_name: &str) ->
|
||||
|
||||
let _ = open::that(&authorize_url);
|
||||
|
||||
let (code, returned_state) = if provider.uses_localhost_redirect() {
|
||||
let (code, returned_state) = if use_callback_listener {
|
||||
listen_for_oauth_callback(&redirect_uri)?
|
||||
} else {
|
||||
let input = Text::new("Paste the authorization code:").prompt()?;
|
||||
@@ -131,18 +148,17 @@ pub async fn run_oauth_flow(provider: &dyn OAuthProvider, client_name: &str) ->
|
||||
}
|
||||
|
||||
let client = ReqwestClient::new();
|
||||
let request = build_token_request(
|
||||
&client,
|
||||
provider,
|
||||
&[
|
||||
("grant_type", "authorization_code"),
|
||||
("client_id", provider.client_id()),
|
||||
("code", &code),
|
||||
("code_verifier", &code_verifier),
|
||||
("redirect_uri", &redirect_uri),
|
||||
("state", &state),
|
||||
],
|
||||
);
|
||||
let mut token_params = vec![
|
||||
("grant_type", "authorization_code"),
|
||||
("client_id", provider.client_id()),
|
||||
("code", code.as_str()),
|
||||
("code_verifier", code_verifier.as_str()),
|
||||
("redirect_uri", redirect_uri.as_str()),
|
||||
];
|
||||
if provider.include_state_in_token_exchange() {
|
||||
token_params.push(("state", state.as_str()));
|
||||
}
|
||||
let request = build_token_request(&client, provider, &token_params);
|
||||
|
||||
let response: Value = request.send().await?.json().await?;
|
||||
|
||||
@@ -150,20 +166,20 @@ pub async fn run_oauth_flow(provider: &dyn OAuthProvider, client_name: &str) ->
|
||||
.as_str()
|
||||
.ok_or_else(|| anyhow!("Missing access_token in response: {response}"))?
|
||||
.to_string();
|
||||
let refresh_token = response["refresh_token"]
|
||||
.as_str()
|
||||
.ok_or_else(|| anyhow!("Missing refresh_token in response: {response}"))?
|
||||
.to_string();
|
||||
let refresh_token = response["refresh_token"].as_str().map(|s| s.to_string());
|
||||
let expires_in = response["expires_in"]
|
||||
.as_i64()
|
||||
.ok_or_else(|| anyhow!("Missing expires_in in response: {response}"))?;
|
||||
|
||||
let expires_at = Utc::now().timestamp() + expires_in;
|
||||
|
||||
let account_id = provider.extract_account_id(&response);
|
||||
|
||||
let tokens = OAuthTokens {
|
||||
access_token,
|
||||
refresh_token,
|
||||
expires_at,
|
||||
account_id,
|
||||
};
|
||||
|
||||
save_oauth_tokens(client_name, &tokens)?;
|
||||
@@ -199,13 +215,19 @@ pub async fn refresh_oauth_token(
|
||||
client_name: &str,
|
||||
tokens: &OAuthTokens,
|
||||
) -> Result<OAuthTokens> {
|
||||
let refresh_token_val = tokens.refresh_token.as_deref().ok_or_else(|| {
|
||||
anyhow!(
|
||||
"No refresh token available for '{}'. Please re-authenticate.",
|
||||
client_name
|
||||
)
|
||||
})?;
|
||||
let request = build_token_request(
|
||||
client,
|
||||
provider,
|
||||
&[
|
||||
("grant_type", "refresh_token"),
|
||||
("client_id", provider.client_id()),
|
||||
("refresh_token", &tokens.refresh_token),
|
||||
("refresh_token", refresh_token_val),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -218,17 +240,22 @@ pub async fn refresh_oauth_token(
|
||||
let refresh_token = response["refresh_token"]
|
||||
.as_str()
|
||||
.map(|s| s.to_string())
|
||||
.unwrap_or_else(|| tokens.refresh_token.clone());
|
||||
.or_else(|| tokens.refresh_token.clone());
|
||||
let expires_in = response["expires_in"]
|
||||
.as_i64()
|
||||
.ok_or_else(|| anyhow!("Missing expires_in in refresh response: {response}"))?;
|
||||
|
||||
let expires_at = Utc::now().timestamp() + expires_in;
|
||||
|
||||
let account_id = provider
|
||||
.extract_account_id(&response)
|
||||
.or_else(|| tokens.account_id.clone());
|
||||
|
||||
let new_tokens = OAuthTokens {
|
||||
access_token,
|
||||
refresh_token,
|
||||
expires_at,
|
||||
account_id,
|
||||
};
|
||||
|
||||
save_oauth_tokens(client_name, &new_tokens)?;
|
||||
@@ -256,7 +283,12 @@ pub async fn prepare_oauth_access_token(
|
||||
tokens
|
||||
};
|
||||
|
||||
set_access_token(client_name, tokens.access_token.clone(), tokens.expires_at);
|
||||
set_access_token(
|
||||
client_name,
|
||||
tokens.access_token.clone(),
|
||||
tokens.expires_at,
|
||||
tokens.account_id.clone(),
|
||||
);
|
||||
|
||||
Ok(true)
|
||||
}
|
||||
@@ -365,6 +397,7 @@ pub fn get_oauth_provider(provider_type: &str) -> Option<Box<dyn OAuthProvider>>
|
||||
match provider_type {
|
||||
"claude" => Some(Box::new(super::claude_oauth::ClaudeOAuthProvider)),
|
||||
"gemini" => Some(Box::new(super::gemini_oauth::GeminiOAuthProvider)),
|
||||
"openai" => Some(Box::new(super::openai_oauth::OpenAIOAuthProvider)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -403,7 +436,11 @@ fn client_config_info(client_config: &ClientConfig) -> (&str, &'static str, Opti
|
||||
"claude",
|
||||
c.auth.as_deref(),
|
||||
),
|
||||
ClientConfig::OpenAIConfig(c) => (c.name.as_deref().unwrap_or("openai"), "openai", None),
|
||||
ClientConfig::OpenAIConfig(c) => (
|
||||
c.name.as_deref().unwrap_or("openai"),
|
||||
"openai",
|
||||
c.auth.as_deref(),
|
||||
),
|
||||
ClientConfig::OpenAICompatibleConfig(c) => (
|
||||
c.name.as_deref().unwrap_or("openai-compatible"),
|
||||
"openai-compatible",
|
||||
|
||||
+385
-42
@@ -1,13 +1,17 @@
|
||||
use super::access_token::{get_access_token, get_access_token_account_id};
|
||||
use super::oauth::{self, OAuthProvider};
|
||||
use super::openai_oauth::OpenAIOAuthProvider;
|
||||
use super::*;
|
||||
|
||||
use crate::utils::strip_think_tag;
|
||||
|
||||
use anyhow::{Context, Result, bail};
|
||||
use reqwest::RequestBuilder;
|
||||
use reqwest::{Client as ReqwestClient, RequestBuilder};
|
||||
use serde::Deserialize;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
const API_BASE: &str = "https://api.openai.com/v1";
|
||||
const CODEX_API_ENDPOINT: &str = "https://chatgpt.com/backend-api/codex/responses";
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Default)]
|
||||
pub struct OpenAIConfig {
|
||||
@@ -15,6 +19,7 @@ pub struct OpenAIConfig {
|
||||
pub api_key: Option<String>,
|
||||
pub api_base: Option<String>,
|
||||
pub organization_id: Option<String>,
|
||||
pub auth: Option<String>,
|
||||
#[serde(default)]
|
||||
pub models: Vec<ModelData>,
|
||||
pub patch: Option<RequestPatch>,
|
||||
@@ -25,36 +30,131 @@ impl OpenAIClient {
|
||||
config_get_fn!(api_key, get_api_key);
|
||||
config_get_fn!(api_base, get_api_base);
|
||||
|
||||
create_client_config!([("api_key", "API Key", None, true)]);
|
||||
create_oauth_supported_client_config!();
|
||||
}
|
||||
|
||||
impl_client_trait!(
|
||||
OpenAIClient,
|
||||
(
|
||||
prepare_chat_completions,
|
||||
openai_chat_completions,
|
||||
openai_chat_completions_streaming
|
||||
),
|
||||
(prepare_embeddings, openai_embeddings),
|
||||
(noop_prepare_rerank, noop_rerank),
|
||||
);
|
||||
#[async_trait::async_trait]
|
||||
impl Client for OpenAIClient {
|
||||
client_common_fns!();
|
||||
|
||||
fn prepare_chat_completions(
|
||||
fn supports_oauth(&self) -> bool {
|
||||
self.config.auth.as_deref() == Some("oauth")
|
||||
}
|
||||
|
||||
async fn chat_completions_inner(
|
||||
&self,
|
||||
client: &ReqwestClient,
|
||||
data: ChatCompletionsData,
|
||||
) -> Result<ChatCompletionsOutput> {
|
||||
let uses_codex =
|
||||
self.config.auth.as_deref() == Some("oauth") && self.get_api_base().is_err();
|
||||
let request_data = prepare_chat_completions(self, client, data).await?;
|
||||
let builder = self.request_builder(client, request_data);
|
||||
if uses_codex {
|
||||
openai_responses_chat_completions(builder, self.model()).await
|
||||
} else {
|
||||
openai_chat_completions(builder, self.model()).await
|
||||
}
|
||||
}
|
||||
|
||||
async fn chat_completions_streaming_inner(
|
||||
&self,
|
||||
client: &ReqwestClient,
|
||||
handler: &mut SseHandler,
|
||||
data: ChatCompletionsData,
|
||||
) -> Result<()> {
|
||||
let uses_codex =
|
||||
self.config.auth.as_deref() == Some("oauth") && self.get_api_base().is_err();
|
||||
let request_data = prepare_chat_completions(self, client, data).await?;
|
||||
let builder = self.request_builder(client, request_data);
|
||||
|
||||
if uses_codex {
|
||||
openai_responses_streaming(builder, handler).await
|
||||
} else {
|
||||
openai_chat_completions_streaming(builder, handler, self.model()).await
|
||||
}
|
||||
}
|
||||
|
||||
async fn embeddings_inner(
|
||||
&self,
|
||||
client: &ReqwestClient,
|
||||
data: &EmbeddingsData,
|
||||
) -> Result<EmbeddingsOutput> {
|
||||
let request_data = prepare_embeddings(self, client, data).await?;
|
||||
let builder = self.request_builder(client, request_data);
|
||||
openai_embeddings(builder, self.model()).await
|
||||
}
|
||||
|
||||
async fn rerank_inner(
|
||||
&self,
|
||||
client: &ReqwestClient,
|
||||
data: &RerankData,
|
||||
) -> Result<RerankOutput> {
|
||||
let request_data = noop_prepare_rerank(self, data)?;
|
||||
let builder = self.request_builder(client, request_data);
|
||||
noop_rerank(builder, self.model()).await
|
||||
}
|
||||
}
|
||||
|
||||
async fn prepare_chat_completions(
|
||||
self_: &OpenAIClient,
|
||||
client: &ReqwestClient,
|
||||
data: ChatCompletionsData,
|
||||
) -> Result<RequestData> {
|
||||
let api_key = self_.get_api_key()?;
|
||||
let api_base = self_
|
||||
.get_api_base()
|
||||
.unwrap_or_else(|_| API_BASE.to_string());
|
||||
let uses_oauth = self_.config.auth.as_deref() == Some("oauth");
|
||||
let has_custom_base = self_.get_api_base().is_ok();
|
||||
|
||||
let url = format!("{}/chat/completions", api_base.trim_end_matches('/'));
|
||||
let uses_codex = uses_oauth && !has_custom_base;
|
||||
|
||||
let body = openai_build_chat_completions_body(data, &self_.model);
|
||||
let url = if uses_codex {
|
||||
CODEX_API_ENDPOINT.to_string()
|
||||
} else {
|
||||
let api_base = self_
|
||||
.get_api_base()
|
||||
.unwrap_or_else(|_| API_BASE.to_string());
|
||||
format!("{}/chat/completions", api_base.trim_end_matches('/'))
|
||||
};
|
||||
|
||||
let body = if uses_codex {
|
||||
openai_build_responses_body(data, &self_.model)
|
||||
} else {
|
||||
openai_build_chat_completions_body(data, &self_.model)
|
||||
};
|
||||
|
||||
let mut request_data = RequestData::new(url, body);
|
||||
|
||||
request_data.bearer_auth(api_key);
|
||||
if uses_oauth {
|
||||
let provider = OpenAIOAuthProvider;
|
||||
let ready = oauth::prepare_oauth_access_token(client, &provider, self_.name()).await?;
|
||||
|
||||
if !ready {
|
||||
bail!(
|
||||
"OAuth configured but no tokens found for '{}'. Run: 'coyote --authenticate {}' or '.authenticate' in the REPL",
|
||||
self_.name(),
|
||||
self_.name()
|
||||
);
|
||||
}
|
||||
|
||||
let token = get_access_token(self_.name())?;
|
||||
request_data.bearer_auth(token);
|
||||
|
||||
if let Some(account_id) = get_access_token_account_id(self_.name()) {
|
||||
request_data.header("ChatGPT-Account-Id", account_id);
|
||||
}
|
||||
|
||||
for (key, value) in provider.extra_request_headers() {
|
||||
request_data.header(key, value);
|
||||
}
|
||||
} else if let Ok(api_key) = self_.get_api_key() {
|
||||
request_data.bearer_auth(api_key);
|
||||
} else {
|
||||
bail!(
|
||||
"No authentication configured for '{}'. Set `api_key` or use `auth: oauth` with `coyote --authenticate {}`.",
|
||||
self_.name(),
|
||||
self_.name()
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(organization_id) = &self_.config.organization_id {
|
||||
request_data.header("OpenAI-Organization", organization_id);
|
||||
}
|
||||
@@ -62,8 +162,11 @@ fn prepare_chat_completions(
|
||||
Ok(request_data)
|
||||
}
|
||||
|
||||
fn prepare_embeddings(self_: &OpenAIClient, data: &EmbeddingsData) -> Result<RequestData> {
|
||||
let api_key = self_.get_api_key()?;
|
||||
async fn prepare_embeddings(
|
||||
self_: &OpenAIClient,
|
||||
client: &ReqwestClient,
|
||||
data: &EmbeddingsData,
|
||||
) -> Result<RequestData> {
|
||||
let api_base = self_
|
||||
.get_api_base()
|
||||
.unwrap_or_else(|_| API_BASE.to_string());
|
||||
@@ -74,7 +177,30 @@ fn prepare_embeddings(self_: &OpenAIClient, data: &EmbeddingsData) -> Result<Req
|
||||
|
||||
let mut request_data = RequestData::new(url, body);
|
||||
|
||||
request_data.bearer_auth(api_key);
|
||||
if self_.config.auth.as_deref() == Some("oauth") {
|
||||
let provider = OpenAIOAuthProvider;
|
||||
let ready = oauth::prepare_oauth_access_token(client, &provider, self_.name()).await?;
|
||||
|
||||
if !ready {
|
||||
bail!(
|
||||
"OAuth configured but no tokens found for '{}'. Run: 'coyote --authenticate {}' or '.authenticate' in the REPL",
|
||||
self_.name(),
|
||||
self_.name()
|
||||
);
|
||||
}
|
||||
|
||||
let token = get_access_token(self_.name())?;
|
||||
request_data.bearer_auth(token);
|
||||
} else if let Ok(api_key) = self_.get_api_key() {
|
||||
request_data.bearer_auth(api_key);
|
||||
} else {
|
||||
bail!(
|
||||
"No authentication configured for '{}'. Set `api_key` or use `auth: oauth` with `coyote --authenticate {}`.",
|
||||
self_.name(),
|
||||
self_.name()
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(organization_id) = &self_.config.organization_id {
|
||||
request_data.header("OpenAI-Organization", organization_id);
|
||||
}
|
||||
@@ -230,6 +356,7 @@ pub fn openai_build_chat_completions_body(data: ChatCompletionsData, model: &Mod
|
||||
messages,
|
||||
temperature,
|
||||
top_p,
|
||||
reasoning_effort,
|
||||
functions,
|
||||
stream,
|
||||
} = data;
|
||||
@@ -243,7 +370,7 @@ pub fn openai_build_chat_completions_body(data: ChatCompletionsData, model: &Mod
|
||||
match content {
|
||||
MessageContent::ToolCalls(MessageContentToolCalls {
|
||||
tool_results,
|
||||
text: _,
|
||||
text,
|
||||
sequence,
|
||||
}) => {
|
||||
if !sequence {
|
||||
@@ -260,9 +387,12 @@ pub fn openai_build_chat_completions_body(data: ChatCompletionsData, model: &Mod
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
let mut messages = vec![
|
||||
json!({ "role": MessageRole::Assistant, "tool_calls": tool_calls }),
|
||||
];
|
||||
let mut assistant_message =
|
||||
json!({ "role": MessageRole::Assistant, "tool_calls": tool_calls });
|
||||
if !text.is_empty() {
|
||||
assistant_message["content"] = strip_think_tag(&text).into();
|
||||
}
|
||||
let mut messages = vec![assistant_message];
|
||||
for tool_result in tool_results {
|
||||
messages.push(json!({
|
||||
"role": "tool",
|
||||
@@ -272,21 +402,30 @@ pub fn openai_build_chat_completions_body(data: ChatCompletionsData, model: &Mod
|
||||
}
|
||||
messages
|
||||
} else {
|
||||
tool_results.into_iter().flat_map(|tool_result| {
|
||||
tool_results.into_iter().enumerate().flat_map(|(index, tool_result)| {
|
||||
let round_text = if index == 0 && !text.is_empty() {
|
||||
Some(text.clone())
|
||||
} else {
|
||||
tool_result.text.clone()
|
||||
};
|
||||
let mut assistant_message = json!({
|
||||
"role": MessageRole::Assistant,
|
||||
"tool_calls": [
|
||||
{
|
||||
"id": tool_result.call.id,
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": tool_result.call.name,
|
||||
"arguments": tool_result.call.arguments.to_string(),
|
||||
},
|
||||
}
|
||||
]
|
||||
});
|
||||
if let Some(round_text) = round_text {
|
||||
assistant_message["content"] = strip_think_tag(&round_text).into();
|
||||
}
|
||||
vec![
|
||||
json!({
|
||||
"role": MessageRole::Assistant,
|
||||
"tool_calls": [
|
||||
{
|
||||
"id": tool_result.call.id,
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": tool_result.call.name,
|
||||
"arguments": tool_result.call.arguments.to_string(),
|
||||
},
|
||||
}
|
||||
]
|
||||
}),
|
||||
assistant_message,
|
||||
json!({
|
||||
"role": "tool",
|
||||
"content": tool_result.output.to_string(),
|
||||
@@ -328,6 +467,9 @@ pub fn openai_build_chat_completions_body(data: ChatCompletionsData, model: &Mod
|
||||
if let Some(v) = top_p {
|
||||
body["top_p"] = v.into();
|
||||
}
|
||||
if let Some(v) = reasoning_effort {
|
||||
body["reasoning_effort"] = v.into();
|
||||
}
|
||||
if stream {
|
||||
body["stream"] = true.into();
|
||||
}
|
||||
@@ -391,7 +533,7 @@ pub fn openai_extract_chat_completions(data: &Value) -> Result<ChatCompletionsOu
|
||||
} else {
|
||||
text.to_string()
|
||||
};
|
||||
let output = ChatCompletionsOutput { text, tool_calls };
|
||||
let output = ChatCompletionsOutput { text, tool_calls, ..Default::default() };
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
@@ -402,3 +544,204 @@ fn normalize_function_id(value: &str) -> Option<String> {
|
||||
Some(value.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn openai_build_responses_body(data: ChatCompletionsData, model: &Model) -> Value {
|
||||
let ChatCompletionsData {
|
||||
messages,
|
||||
temperature,
|
||||
top_p,
|
||||
reasoning_effort,
|
||||
functions,
|
||||
stream,
|
||||
} = data;
|
||||
|
||||
let messages_len = messages.len();
|
||||
let input: Vec<Value> = messages
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.flat_map(|(i, message)| {
|
||||
let Message { role, content } = message;
|
||||
match content {
|
||||
MessageContent::ToolCalls(MessageContentToolCalls {
|
||||
tool_results,
|
||||
text,
|
||||
sequence: _,
|
||||
}) => tool_results
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.flat_map(|(index, tool_result)| {
|
||||
let round_text = if index == 0 && !text.is_empty() {
|
||||
Some(text.clone())
|
||||
} else {
|
||||
tool_result.text.clone()
|
||||
};
|
||||
let mut items = vec![];
|
||||
if let Some(round_text) = round_text {
|
||||
items.push(json!({
|
||||
"role": MessageRole::Assistant,
|
||||
"content": strip_think_tag(&round_text),
|
||||
}));
|
||||
}
|
||||
items.push(json!({
|
||||
"type": "function_call",
|
||||
"call_id": tool_result.call.id,
|
||||
"name": tool_result.call.name,
|
||||
"arguments": tool_result.call.arguments.to_string(),
|
||||
}));
|
||||
items.push(json!({
|
||||
"type": "function_call_output",
|
||||
"call_id": tool_result.call.id,
|
||||
"output": tool_result.output.to_string(),
|
||||
}));
|
||||
items
|
||||
})
|
||||
.collect(),
|
||||
MessageContent::Text(text) if role.is_assistant() && i != messages_len - 1 => {
|
||||
vec![json!({ "role": role, "content": strip_think_tag(&text) })]
|
||||
}
|
||||
_ => vec![json!({ "role": role, "content": content })],
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
let mut body = json!({
|
||||
"model": &model.real_name(),
|
||||
"input": input,
|
||||
"store": false,
|
||||
});
|
||||
|
||||
if let Some(v) = model.max_tokens_param() {
|
||||
body["max_output_tokens"] = v.into();
|
||||
}
|
||||
if let Some(v) = temperature {
|
||||
body["temperature"] = v.into();
|
||||
}
|
||||
if let Some(v) = top_p {
|
||||
body["top_p"] = v.into();
|
||||
}
|
||||
if let Some(v) = reasoning_effort {
|
||||
body["reasoning"] = json!({ "effort": v });
|
||||
}
|
||||
if stream {
|
||||
body["stream"] = true.into();
|
||||
}
|
||||
if let Some(functions) = functions {
|
||||
body["tools"] = functions
|
||||
.iter()
|
||||
.map(|v| {
|
||||
let mut tool = serde_json::to_value(v).unwrap_or_default();
|
||||
tool["type"] = "function".into();
|
||||
tool
|
||||
})
|
||||
.collect();
|
||||
}
|
||||
body
|
||||
}
|
||||
|
||||
pub async fn openai_responses_chat_completions(
|
||||
builder: RequestBuilder,
|
||||
_model: &Model,
|
||||
) -> Result<ChatCompletionsOutput> {
|
||||
let res = builder.send().await?;
|
||||
let status = res.status();
|
||||
let data: Value = res.json().await?;
|
||||
|
||||
if !status.is_success() {
|
||||
catch_error(&data, status.as_u16())?;
|
||||
}
|
||||
|
||||
debug!("non-stream-data: {data}");
|
||||
openai_extract_responses(&data)
|
||||
}
|
||||
|
||||
pub fn openai_extract_responses(data: &Value) -> Result<ChatCompletionsOutput> {
|
||||
let mut text = String::new();
|
||||
let mut tool_calls = vec![];
|
||||
|
||||
if let Some(output) = data["output"].as_array() {
|
||||
for item in output {
|
||||
match item["type"].as_str() {
|
||||
Some("message") => {
|
||||
if let Some(content) = item["content"].as_array() {
|
||||
for part in content {
|
||||
if part["type"].as_str() == Some("output_text")
|
||||
&& let Some(t) = part["text"].as_str()
|
||||
{
|
||||
text.push_str(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Some("function_call") => {
|
||||
if let (Some(name), Some(arguments_str), Some(call_id)) = (
|
||||
item["name"].as_str(),
|
||||
item["arguments"].as_str(),
|
||||
item["call_id"].as_str(),
|
||||
) {
|
||||
let arguments: Value = arguments_str.parse().with_context(|| {
|
||||
format!("Tool call '{name}' has non-JSON arguments '{arguments_str}'")
|
||||
})?;
|
||||
tool_calls.push(ToolCall::new(
|
||||
name.to_string(),
|
||||
arguments,
|
||||
Some(call_id.to_string()),
|
||||
));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if text.is_empty() && tool_calls.is_empty() {
|
||||
bail!("Invalid response data: {data}");
|
||||
}
|
||||
Ok(ChatCompletionsOutput { text, tool_calls, ..Default::default() })
|
||||
}
|
||||
|
||||
pub async fn openai_responses_streaming(
|
||||
builder: RequestBuilder,
|
||||
handler: &mut SseHandler,
|
||||
) -> Result<()> {
|
||||
let handle = |message: SseMessage| -> Result<bool> {
|
||||
if message.data == "[DONE]" {
|
||||
return Ok(true);
|
||||
}
|
||||
let data: Value = serde_json::from_str(&message.data)?;
|
||||
debug!("stream-data: {data}");
|
||||
|
||||
match data["type"].as_str() {
|
||||
Some("response.output_text.delta") => {
|
||||
if let Some(delta) = data["delta"].as_str().filter(|v| !v.is_empty()) {
|
||||
handler.text(delta)?;
|
||||
}
|
||||
}
|
||||
Some("response.output_item.done") => {
|
||||
let item = &data["item"];
|
||||
if item["type"].as_str() == Some("function_call")
|
||||
&& let (Some(name), Some(arguments_str), Some(call_id)) = (
|
||||
item["name"].as_str(),
|
||||
item["arguments"].as_str(),
|
||||
item["call_id"].as_str(),
|
||||
)
|
||||
{
|
||||
let arguments: Value = arguments_str.parse().with_context(|| {
|
||||
format!("Tool call '{name}' has non-JSON arguments '{arguments_str}'")
|
||||
})?;
|
||||
handler.tool_call(ToolCall::new(
|
||||
name.to_string(),
|
||||
arguments,
|
||||
Some(call_id.to_string()),
|
||||
))?;
|
||||
}
|
||||
}
|
||||
Some("response.completed") => {
|
||||
return Ok(true);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
Ok(false)
|
||||
};
|
||||
|
||||
sse_stream(builder, handle).await
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
use super::oauth::{OAuthProvider, TokenRequestFormat};
|
||||
use base64::Engine;
|
||||
use base64::engine::general_purpose::URL_SAFE_NO_PAD;
|
||||
use serde_json::Value;
|
||||
|
||||
pub struct OpenAIOAuthProvider;
|
||||
|
||||
impl OAuthProvider for OpenAIOAuthProvider {
|
||||
fn provider_name(&self) -> &str {
|
||||
"openai"
|
||||
}
|
||||
|
||||
fn client_id(&self) -> &str {
|
||||
"app_EMoamEEZ73f0CkXaXp7hrann"
|
||||
}
|
||||
|
||||
fn authorize_url(&self) -> &str {
|
||||
"https://auth.openai.com/oauth/authorize"
|
||||
}
|
||||
|
||||
fn token_url(&self) -> &str {
|
||||
"https://auth.openai.com/oauth/token"
|
||||
}
|
||||
|
||||
fn redirect_uri(&self) -> &str {
|
||||
"http://localhost:1455/auth/callback"
|
||||
}
|
||||
|
||||
fn scopes(&self) -> &str {
|
||||
"openid profile email offline_access"
|
||||
}
|
||||
|
||||
fn token_request_format(&self) -> TokenRequestFormat {
|
||||
TokenRequestFormat::FormUrlEncoded
|
||||
}
|
||||
|
||||
fn extra_authorize_params(&self) -> Vec<(&str, &str)> {
|
||||
vec![
|
||||
("id_token_add_organizations", "true"),
|
||||
("codex_cli_simplified_flow", "true"),
|
||||
]
|
||||
}
|
||||
|
||||
fn fixed_redirect_uri(&self) -> Option<String> {
|
||||
Some("http://localhost:1455/auth/callback".to_string())
|
||||
}
|
||||
|
||||
fn include_state_in_token_exchange(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn extract_account_id(&self, response: &Value) -> Option<String> {
|
||||
let id_token = response["id_token"].as_str().unwrap_or_default();
|
||||
let access_token = response["access_token"].as_str().unwrap_or_default();
|
||||
extract_account_id_from_jwt(id_token).or_else(|| extract_account_id_from_jwt(access_token))
|
||||
}
|
||||
}
|
||||
|
||||
fn extract_account_id_from_jwt(token: &str) -> Option<String> {
|
||||
let parts: Vec<&str> = token.splitn(3, '.').collect();
|
||||
if parts.len() < 2 {
|
||||
return None;
|
||||
}
|
||||
let decoded = URL_SAFE_NO_PAD.decode(parts[1]).ok()?;
|
||||
let claims: Value = serde_json::from_slice(&decoded).ok()?;
|
||||
claims["chatgpt_account_id"]
|
||||
.as_str()
|
||||
.map(|s| s.to_string())
|
||||
.or_else(|| {
|
||||
claims["https://api.openai.com/auth"]["chatgpt_account_id"]
|
||||
.as_str()
|
||||
.map(|s| s.to_string())
|
||||
})
|
||||
.or_else(|| {
|
||||
claims["organizations"][0]["id"]
|
||||
.as_str()
|
||||
.map(|s| s.to_string())
|
||||
})
|
||||
}
|
||||
+15
-6
@@ -1,4 +1,4 @@
|
||||
use super::{ToolCall, catch_error};
|
||||
use super::{ThinkingBlock, ToolCall, catch_error};
|
||||
use crate::utils::AbortSignal;
|
||||
|
||||
use anyhow::{Context, Result, anyhow, bail};
|
||||
@@ -13,6 +13,7 @@ pub struct SseHandler {
|
||||
abort_signal: AbortSignal,
|
||||
buffer: String,
|
||||
tool_calls: Vec<ToolCall>,
|
||||
thinking: Vec<ThinkingBlock>,
|
||||
last_tool_calls: Vec<ToolCall>,
|
||||
max_call_repeats: usize,
|
||||
call_repeat_chain_len: usize,
|
||||
@@ -26,6 +27,7 @@ impl SseHandler {
|
||||
abort_signal,
|
||||
buffer: String::new(),
|
||||
tool_calls: Vec::new(),
|
||||
thinking: Vec::new(),
|
||||
last_tool_calls: Vec::new(),
|
||||
max_call_repeats: 2,
|
||||
call_repeat_chain_len: 3,
|
||||
@@ -170,6 +172,10 @@ impl SseHandler {
|
||||
message
|
||||
}
|
||||
|
||||
pub fn thinking_block(&mut self, block: ThinkingBlock) {
|
||||
self.thinking.push(block);
|
||||
}
|
||||
|
||||
pub fn abort(&self) -> AbortSignal {
|
||||
self.abort_signal.clone()
|
||||
}
|
||||
@@ -179,11 +185,14 @@ impl SseHandler {
|
||||
&self.last_tool_calls
|
||||
}
|
||||
|
||||
pub fn take(self) -> (String, Vec<ToolCall>) {
|
||||
pub fn take(self) -> (String, Vec<ToolCall>, Vec<ThinkingBlock>) {
|
||||
let Self {
|
||||
buffer, tool_calls, ..
|
||||
buffer,
|
||||
tool_calls,
|
||||
thinking,
|
||||
..
|
||||
} = self;
|
||||
(buffer, tool_calls)
|
||||
(buffer, tool_calls, thinking)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,8 +241,8 @@ where
|
||||
.map(|value| value.to_string());
|
||||
let is_event_stream = content_type
|
||||
.as_deref()
|
||||
.map(|ct| ct.starts_with("text/event-stream"))
|
||||
.unwrap_or(false);
|
||||
.map(|ct| ct.is_empty() || ct.starts_with("text/event-stream"))
|
||||
.unwrap_or(true);
|
||||
if !is_event_stream {
|
||||
let header_value = content_type.unwrap_or_default();
|
||||
let text = res.text().await?;
|
||||
|
||||
+17
-6
@@ -322,7 +322,7 @@ fn gemini_extract_chat_completions_text(data: &Value) -> Result<ChatCompletionsO
|
||||
bail!("Invalid response data: {data}");
|
||||
}
|
||||
}
|
||||
let output = ChatCompletionsOutput { text, tool_calls };
|
||||
let output = ChatCompletionsOutput { text, tool_calls, ..Default::default() };
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
@@ -334,6 +334,7 @@ pub fn gemini_build_chat_completions_body(
|
||||
mut messages,
|
||||
temperature,
|
||||
top_p,
|
||||
reasoning_effort,
|
||||
functions,
|
||||
stream: _,
|
||||
} = data;
|
||||
@@ -371,8 +372,15 @@ pub fn gemini_build_chat_completions_body(
|
||||
.collect();
|
||||
vec![json!({ "role": role, "parts": parts })]
|
||||
},
|
||||
MessageContent::ToolCalls(MessageContentToolCalls { tool_results, .. }) => {
|
||||
let model_parts: Vec<Value> = tool_results.iter().map(|tool_result| {
|
||||
MessageContent::ToolCalls(MessageContentToolCalls { tool_results, text, .. }) => {
|
||||
let mut model_parts: Vec<Value> = vec![];
|
||||
if !text.is_empty() {
|
||||
model_parts.push(json!({ "text": text }));
|
||||
}
|
||||
for tool_result in tool_results.iter() {
|
||||
if let Some(round_text) = &tool_result.text {
|
||||
model_parts.push(json!({ "text": round_text }));
|
||||
}
|
||||
let mut part = json!({
|
||||
"functionCall": {
|
||||
"name": tool_result.call.name,
|
||||
@@ -382,8 +390,8 @@ pub fn gemini_build_chat_completions_body(
|
||||
if let Some(sig) = &tool_result.call.thought_signature {
|
||||
part["thoughtSignature"] = json!(sig);
|
||||
}
|
||||
part
|
||||
}).collect();
|
||||
model_parts.push(part);
|
||||
}
|
||||
let function_parts: Vec<Value> = tool_results.into_iter().map(|tool_result| {
|
||||
json!({
|
||||
"functionResponse": {
|
||||
@@ -426,6 +434,9 @@ pub fn gemini_build_chat_completions_body(
|
||||
if let Some(v) = top_p {
|
||||
body["generationConfig"]["topP"] = v.into();
|
||||
}
|
||||
if let Some(v) = reasoning_effort {
|
||||
body["generation_config"]["thinking_level"] = v.into();
|
||||
}
|
||||
|
||||
if let Some(functions) = functions {
|
||||
// Gemini doesn't support functions with parameters that have empty properties, so we need to patch it.
|
||||
@@ -483,7 +494,7 @@ pub async fn prepare_gcloud_access_token(
|
||||
let expires_at = Utc::now()
|
||||
+ Duration::try_seconds(expires_in)
|
||||
.ok_or_else(|| anyhow!("Failed to parse expires_in of access_token"))?;
|
||||
set_access_token(client_name, token, expires_at.timestamp())
|
||||
set_access_token(client_name, token, expires_at.timestamp(), None)
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
+33
-13
@@ -43,6 +43,8 @@ pub struct Agent {
|
||||
graph_rags: HashMap<String, Arc<Rag>>,
|
||||
model: Model,
|
||||
vault: GlobalVault,
|
||||
is_graph: bool,
|
||||
enabled_tools: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
impl Agent {
|
||||
@@ -243,6 +245,8 @@ impl Agent {
|
||||
graph_rags,
|
||||
model,
|
||||
vault: app_state.vault.clone(),
|
||||
is_graph: graph_for_rag.is_some(),
|
||||
enabled_tools: None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -339,6 +343,10 @@ impl Agent {
|
||||
&self.name
|
||||
}
|
||||
|
||||
pub fn is_graph(&self) -> bool {
|
||||
self.is_graph
|
||||
}
|
||||
|
||||
pub fn functions(&self) -> &Functions {
|
||||
&self.functions
|
||||
}
|
||||
@@ -575,8 +583,12 @@ impl RoleLike for Agent {
|
||||
self.config.top_p
|
||||
}
|
||||
|
||||
fn reasoning_effort(&self) -> Option<String> {
|
||||
self.config.reasoning_effort.clone()
|
||||
}
|
||||
|
||||
fn enabled_tools(&self) -> Option<Vec<String>> {
|
||||
None
|
||||
self.enabled_tools.clone()
|
||||
}
|
||||
|
||||
fn enabled_mcp_servers(&self) -> Option<Vec<String>> {
|
||||
@@ -596,19 +608,18 @@ impl RoleLike for Agent {
|
||||
self.config.top_p = value;
|
||||
}
|
||||
|
||||
fn set_reasoning_effort(&mut self, value: Option<String>) {
|
||||
self.config.reasoning_effort = value;
|
||||
}
|
||||
|
||||
fn set_enabled_tools(&mut self, value: Option<Vec<String>>) {
|
||||
match value {
|
||||
Some(tools) => {
|
||||
self.config.global_tools = tools
|
||||
.into_iter()
|
||||
.map(|v| v.trim().to_string())
|
||||
.filter(|v| !v.is_empty())
|
||||
.collect::<Vec<_>>();
|
||||
}
|
||||
None => {
|
||||
self.config.global_tools.clear();
|
||||
}
|
||||
}
|
||||
self.enabled_tools = value.map(|tools| {
|
||||
tools
|
||||
.into_iter()
|
||||
.map(|v| v.trim().to_string())
|
||||
.filter(|v| !v.is_empty())
|
||||
.collect::<Vec<_>>()
|
||||
});
|
||||
}
|
||||
|
||||
fn set_enabled_mcp_servers(&mut self, value: Option<Vec<String>>) {
|
||||
@@ -637,6 +648,8 @@ pub struct AgentConfig {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub top_p: Option<f64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reasoning_effort: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub agent_session: Option<String>,
|
||||
#[serde(default)]
|
||||
pub auto_continue: bool,
|
||||
@@ -732,6 +745,7 @@ impl AgentConfig {
|
||||
model_id: graph.model.clone(),
|
||||
temperature: graph.temperature,
|
||||
top_p: graph.top_p,
|
||||
reasoning_effort: graph.reasoning_effort.clone(),
|
||||
description: graph.description.clone(),
|
||||
global_tools: graph.global_tools.clone(),
|
||||
mcp_servers: graph.mcp_servers.clone(),
|
||||
@@ -766,6 +780,9 @@ impl AgentConfig {
|
||||
if let Some(v) = read_env_value::<f64>(&with_prefix("top_p")) {
|
||||
self.top_p = v;
|
||||
}
|
||||
if let Some(v) = read_env_value::<String>(&with_prefix("reasoning_effort")) {
|
||||
self.reasoning_effort = v;
|
||||
}
|
||||
if let Ok(v) = env::var(with_prefix("global_tools"))
|
||||
&& let Ok(v) = serde_json::from_str(&v)
|
||||
{
|
||||
@@ -921,6 +938,9 @@ async fn init_graph_rags(
|
||||
reranker_model: rag_node.reranker_model.clone(),
|
||||
top_k: rag_node.top_k,
|
||||
batch_size: rag_node.batch_size,
|
||||
extractor_model: rag_node.extractor_model.clone(),
|
||||
extractor_prompt: rag_node.extractor_prompt.clone(),
|
||||
graph_hops: rag_node.graph_hops,
|
||||
};
|
||||
let fully_specified = config.embedding_model.is_some()
|
||||
&& config.chunk_size.is_some()
|
||||
|
||||
+74
-10
@@ -1,4 +1,4 @@
|
||||
use crate::client::{ClientConfig, list_models};
|
||||
use crate::client::{ClientConfig, Model, ModelType, list_models};
|
||||
use crate::render::{MarkdownRender, RenderOptions};
|
||||
use crate::utils::{IS_STDOUT_TERMINAL, NO_COLOR, decode_bin, get_env_name};
|
||||
|
||||
@@ -21,6 +21,7 @@ pub struct AppConfig {
|
||||
pub model_id: String,
|
||||
pub temperature: Option<f64>,
|
||||
pub top_p: Option<f64>,
|
||||
pub reasoning_effort: Option<String>,
|
||||
|
||||
pub dry_run: bool,
|
||||
pub stream: bool,
|
||||
@@ -68,12 +69,18 @@ pub struct AppConfig {
|
||||
pub memory_cap_with_tools: Option<usize>,
|
||||
pub memory_cap_without_tools: Option<usize>,
|
||||
|
||||
pub workspace_instructions: Option<bool>,
|
||||
pub workspace_instructions_files: Option<Vec<String>>,
|
||||
|
||||
pub rag_embedding_model: Option<String>,
|
||||
pub rag_reranker_model: Option<String>,
|
||||
pub rag_top_k: usize,
|
||||
pub rag_chunk_size: Option<usize>,
|
||||
pub rag_chunk_overlap: Option<usize>,
|
||||
pub rag_template: Option<String>,
|
||||
pub rag_extractor_model: Option<String>,
|
||||
pub rag_extractor_prompt: Option<String>,
|
||||
pub rag_graph_hops: usize,
|
||||
|
||||
#[serde(default)]
|
||||
pub document_loaders: HashMap<String, String>,
|
||||
@@ -85,6 +92,7 @@ pub struct AppConfig {
|
||||
|
||||
pub user_agent: Option<String>,
|
||||
pub save_shell_history: bool,
|
||||
pub no_workspace_mcp: bool,
|
||||
pub sync_models_url: Option<String>,
|
||||
|
||||
pub clients: Vec<ClientConfig>,
|
||||
@@ -96,6 +104,7 @@ impl Default for AppConfig {
|
||||
model_id: Default::default(),
|
||||
temperature: None,
|
||||
top_p: None,
|
||||
reasoning_effort: None,
|
||||
|
||||
dry_run: false,
|
||||
stream: true,
|
||||
@@ -140,12 +149,18 @@ impl Default for AppConfig {
|
||||
memory_cap_with_tools: None,
|
||||
memory_cap_without_tools: None,
|
||||
|
||||
workspace_instructions: None,
|
||||
workspace_instructions_files: None,
|
||||
|
||||
rag_embedding_model: None,
|
||||
rag_reranker_model: None,
|
||||
rag_top_k: 5,
|
||||
rag_chunk_size: None,
|
||||
rag_chunk_overlap: None,
|
||||
rag_template: None,
|
||||
rag_extractor_model: None,
|
||||
rag_extractor_prompt: None,
|
||||
rag_graph_hops: 1,
|
||||
|
||||
document_loaders: Default::default(),
|
||||
|
||||
@@ -156,6 +171,7 @@ impl Default for AppConfig {
|
||||
|
||||
user_agent: None,
|
||||
save_shell_history: true,
|
||||
no_workspace_mcp: false,
|
||||
sync_models_url: None,
|
||||
|
||||
clients: vec![],
|
||||
@@ -169,6 +185,7 @@ impl AppConfig {
|
||||
model_id: config.model_id,
|
||||
temperature: config.temperature,
|
||||
top_p: config.top_p,
|
||||
reasoning_effort: None,
|
||||
|
||||
dry_run: config.dry_run,
|
||||
stream: config.stream,
|
||||
@@ -213,12 +230,18 @@ impl AppConfig {
|
||||
memory_cap_with_tools: config.memory_cap_with_tools,
|
||||
memory_cap_without_tools: config.memory_cap_without_tools,
|
||||
|
||||
workspace_instructions: config.workspace_instructions,
|
||||
workspace_instructions_files: config.workspace_instructions_files,
|
||||
|
||||
rag_embedding_model: config.rag_embedding_model,
|
||||
rag_reranker_model: config.rag_reranker_model,
|
||||
rag_top_k: config.rag_top_k,
|
||||
rag_chunk_size: config.rag_chunk_size,
|
||||
rag_chunk_overlap: config.rag_chunk_overlap,
|
||||
rag_template: config.rag_template,
|
||||
rag_extractor_model: config.rag_extractor_model,
|
||||
rag_extractor_prompt: config.rag_extractor_prompt,
|
||||
rag_graph_hops: config.rag_graph_hops,
|
||||
|
||||
document_loaders: config.document_loaders,
|
||||
|
||||
@@ -229,6 +252,7 @@ impl AppConfig {
|
||||
|
||||
user_agent: config.user_agent,
|
||||
save_shell_history: config.save_shell_history,
|
||||
no_workspace_mcp: false,
|
||||
sync_models_url: config.sync_models_url,
|
||||
|
||||
clients: config.clients,
|
||||
@@ -241,6 +265,7 @@ impl AppConfig {
|
||||
app_config.setup_document_loaders();
|
||||
app_config.setup_user_agent();
|
||||
app_config.resolve_model()?;
|
||||
app_config.validate_reasoning_effort()?;
|
||||
Ok(app_config)
|
||||
}
|
||||
|
||||
@@ -261,6 +286,31 @@ impl AppConfig {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_reasoning_effort(&self) -> Result<()> {
|
||||
let Some(ref effort) = self.reasoning_effort else {
|
||||
return Ok(());
|
||||
};
|
||||
let model = Model::retrieve_model(self, &self.model_id, ModelType::Chat)?;
|
||||
let levels = model.reasoning_levels();
|
||||
|
||||
if levels.is_empty() {
|
||||
bail!(
|
||||
"reasoning_effort '{}' is configured but the model does not support reasoning effort",
|
||||
effort
|
||||
);
|
||||
}
|
||||
|
||||
if !levels.iter().any(|l| l == effort) {
|
||||
bail!(
|
||||
"reasoning_effort '{}' is not valid for the model. Supported levels: {}",
|
||||
effort,
|
||||
levels.join(", ")
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn resolve_model(&mut self) -> Result<()> {
|
||||
if self.model_id.is_empty() {
|
||||
let models = list_models(self, crate::client::ModelType::Chat);
|
||||
@@ -299,16 +349,18 @@ impl AppConfig {
|
||||
|
||||
pub fn editor(&self) -> Result<String> {
|
||||
super::EDITOR.get_or_init(move || {
|
||||
let editor = self.editor.clone()
|
||||
if let Some(editor) = self.editor.clone()
|
||||
.or_else(|| env::var("VISUAL").ok().or_else(|| env::var("EDITOR").ok()))
|
||||
.unwrap_or_else(|| {
|
||||
if cfg!(windows) {
|
||||
"notepad".to_string()
|
||||
} else {
|
||||
"nano".to_string()
|
||||
}
|
||||
});
|
||||
which::which(&editor).ok().map(|_| editor)
|
||||
&& which::which(&editor).is_ok()
|
||||
{
|
||||
return Some(editor);
|
||||
}
|
||||
let default = if cfg!(windows) {
|
||||
"notepad".to_string()
|
||||
} else {
|
||||
"nano".to_string()
|
||||
};
|
||||
which::which(&default).ok().map(|_| default)
|
||||
})
|
||||
.clone()
|
||||
.ok_or_else(|| anyhow!("Editor not found. Please add the `editor` configuration or set the $EDITOR or $VISUAL environment variable."))
|
||||
@@ -412,6 +464,9 @@ impl AppConfig {
|
||||
if let Some(v) = super::read_env_value::<f64>(&get_env_name("top_p")) {
|
||||
self.top_p = v;
|
||||
}
|
||||
if let Some(v) = super::read_env_value::<String>(&get_env_name("reasoning_effort")) {
|
||||
self.reasoning_effort = v;
|
||||
}
|
||||
|
||||
if let Some(Some(v)) = super::read_env_bool(&get_env_name("dry_run")) {
|
||||
self.dry_run = v;
|
||||
@@ -512,6 +567,15 @@ impl AppConfig {
|
||||
if let Some(v) = super::read_env_value::<String>(&get_env_name("rag_template")) {
|
||||
self.rag_template = v;
|
||||
}
|
||||
if let Some(v) = super::read_env_value::<String>(&get_env_name("rag_extractor_model")) {
|
||||
self.rag_extractor_model = v;
|
||||
}
|
||||
if let Some(v) = super::read_env_value::<String>(&get_env_name("rag_extractor_prompt")) {
|
||||
self.rag_extractor_prompt = v;
|
||||
}
|
||||
if let Some(v) = super::read_env_value::<usize>(&get_env_name("rag_graph_hops")) {
|
||||
self.rag_graph_hops = v.unwrap_or(1);
|
||||
}
|
||||
|
||||
if let Ok(v) = env::var(get_env_name("document_loaders"))
|
||||
&& let Ok(v) = serde_json::from_str(&v)
|
||||
|
||||
@@ -253,6 +253,10 @@ impl Input {
|
||||
patch_messages(&mut messages, model);
|
||||
model.guard_max_input_tokens(&messages)?;
|
||||
let (temperature, top_p) = (self.role().temperature(), self.role().top_p());
|
||||
let reasoning_effort = self
|
||||
.role()
|
||||
.reasoning_effort()
|
||||
.or_else(|| model.default_reasoning_effort().map(|s| s.to_string()));
|
||||
let functions = if model.supports_function_calling() {
|
||||
let fns = self.functions.clone();
|
||||
if let Some(vec) = &fns {
|
||||
@@ -268,6 +272,7 @@ impl Input {
|
||||
messages,
|
||||
temperature,
|
||||
top_p,
|
||||
reasoning_effort,
|
||||
functions,
|
||||
stream,
|
||||
})
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use log::warn;
|
||||
|
||||
pub const WORKSPACE_INSTRUCTIONS_FILE_NAME: &str = "COYOTE.md";
|
||||
pub const DEFAULT_WORKSPACE_INSTRUCTIONS_FILES: [&str; 4] = [
|
||||
WORKSPACE_INSTRUCTIONS_FILE_NAME,
|
||||
"AGENTS.md",
|
||||
"CLAUDE.md",
|
||||
"GEMINI.md",
|
||||
];
|
||||
const INSTRUCTIONS_SIZE_WARN_THRESHOLD: usize = 24_000;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct WorkspaceInstructions {
|
||||
pub path: PathBuf,
|
||||
pub content: String,
|
||||
}
|
||||
|
||||
pub fn default_workspace_instructions_files() -> Vec<String> {
|
||||
DEFAULT_WORKSPACE_INSTRUCTIONS_FILES
|
||||
.iter()
|
||||
.map(|s| s.to_string())
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn discover_workspace_instructions(
|
||||
start: &Path,
|
||||
file_names: &[String],
|
||||
) -> Option<WorkspaceInstructions> {
|
||||
for dir in start.ancestors() {
|
||||
for name in file_names {
|
||||
let candidate = dir.join(name);
|
||||
if !candidate.is_file() {
|
||||
continue;
|
||||
}
|
||||
match fs::read_to_string(&candidate) {
|
||||
Ok(content) if !content.trim().is_empty() => {
|
||||
return Some(WorkspaceInstructions {
|
||||
path: candidate,
|
||||
content,
|
||||
});
|
||||
}
|
||||
Ok(_) => {}
|
||||
Err(e) => warn!(
|
||||
"failed to read workspace instructions at {}: {e}",
|
||||
candidate.display()
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn build_instructions_section(instructions: &WorkspaceInstructions) -> String {
|
||||
let char_count = instructions.content.chars().count();
|
||||
if char_count > INSTRUCTIONS_SIZE_WARN_THRESHOLD {
|
||||
warn!(
|
||||
"workspace instructions at {} are large ({char_count} chars); \
|
||||
consider moving detail into workspace memory drill files",
|
||||
instructions.path.display()
|
||||
);
|
||||
}
|
||||
|
||||
format!(
|
||||
"<workspace_instructions source=\"{}\">\n{}\n</workspace_instructions>",
|
||||
instructions.path.display(),
|
||||
instructions.content.trim_end()
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::{env, time};
|
||||
use time::SystemTime;
|
||||
|
||||
fn temp_root(label: &str) -> PathBuf {
|
||||
let unique = SystemTime::now()
|
||||
.duration_since(time::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_nanos();
|
||||
let root = env::temp_dir().join(format!("coyote-instructions-{label}-{unique}"));
|
||||
fs::create_dir_all(&root).unwrap();
|
||||
root
|
||||
}
|
||||
|
||||
fn defaults() -> Vec<String> {
|
||||
default_workspace_instructions_files()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn discovery_returns_none_when_no_file_exists() {
|
||||
let root = temp_root("none");
|
||||
|
||||
assert!(discover_workspace_instructions(&root, &defaults()).is_none());
|
||||
|
||||
let _ = fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn discovery_finds_coyote_md() {
|
||||
let root = temp_root("coyote");
|
||||
fs::write(root.join("COYOTE.md"), "coyote instructions").unwrap();
|
||||
|
||||
let found = discover_workspace_instructions(&root, &defaults()).unwrap();
|
||||
assert_eq!(found.path, root.join("COYOTE.md"));
|
||||
assert_eq!(found.content, "coyote instructions");
|
||||
|
||||
let _ = fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn discovery_falls_back_through_chain_in_order() {
|
||||
let root = temp_root("fallback");
|
||||
fs::write(root.join("GEMINI.md"), "gemini instructions").unwrap();
|
||||
|
||||
let found = discover_workspace_instructions(&root, &defaults()).unwrap();
|
||||
assert_eq!(found.path, root.join("GEMINI.md"));
|
||||
|
||||
fs::write(root.join("CLAUDE.md"), "claude instructions").unwrap();
|
||||
let found = discover_workspace_instructions(&root, &defaults()).unwrap();
|
||||
assert_eq!(found.path, root.join("CLAUDE.md"));
|
||||
|
||||
fs::write(root.join("AGENTS.md"), "agents instructions").unwrap();
|
||||
let found = discover_workspace_instructions(&root, &defaults()).unwrap();
|
||||
assert_eq!(found.path, root.join("AGENTS.md"));
|
||||
|
||||
let _ = fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn discovery_prefers_coyote_md_over_fallbacks() {
|
||||
let root = temp_root("precedence");
|
||||
fs::write(root.join("COYOTE.md"), "coyote").unwrap();
|
||||
fs::write(root.join("AGENTS.md"), "agents").unwrap();
|
||||
fs::write(root.join("CLAUDE.md"), "claude").unwrap();
|
||||
|
||||
let found = discover_workspace_instructions(&root, &defaults()).unwrap();
|
||||
assert_eq!(found.path, root.join("COYOTE.md"));
|
||||
|
||||
let _ = fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn discovery_walks_up_from_nested_dir() {
|
||||
let root = temp_root("walk_up");
|
||||
fs::write(root.join("AGENTS.md"), "root instructions").unwrap();
|
||||
let nested = root.join("src").join("deep");
|
||||
fs::create_dir_all(&nested).unwrap();
|
||||
|
||||
let found = discover_workspace_instructions(&nested, &defaults()).unwrap();
|
||||
assert_eq!(found.path, root.join("AGENTS.md"));
|
||||
|
||||
let _ = fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn discovery_prefers_closer_file_over_higher_priority_name_above() {
|
||||
let root = temp_root("depth_first");
|
||||
fs::write(root.join("COYOTE.md"), "root coyote").unwrap();
|
||||
let nested = root.join("packages").join("app");
|
||||
fs::create_dir_all(&nested).unwrap();
|
||||
fs::write(nested.join("CLAUDE.md"), "nested claude").unwrap();
|
||||
|
||||
let found = discover_workspace_instructions(&nested, &defaults()).unwrap();
|
||||
assert_eq!(found.path, nested.join("CLAUDE.md"));
|
||||
|
||||
let _ = fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn discovery_skips_empty_files() {
|
||||
let root = temp_root("empty");
|
||||
fs::write(root.join("COYOTE.md"), " \n").unwrap();
|
||||
fs::write(root.join("AGENTS.md"), "real content").unwrap();
|
||||
|
||||
let found = discover_workspace_instructions(&root, &defaults()).unwrap();
|
||||
assert_eq!(found.path, root.join("AGENTS.md"));
|
||||
|
||||
let _ = fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn discovery_honors_custom_file_chain() {
|
||||
let root = temp_root("custom");
|
||||
fs::write(root.join("CLAUDE.md"), "claude").unwrap();
|
||||
|
||||
let only_agents = vec!["AGENTS.md".to_string()];
|
||||
assert!(discover_workspace_instructions(&root, &only_agents).is_none());
|
||||
|
||||
let empty: Vec<String> = vec![];
|
||||
assert!(discover_workspace_instructions(&root, &empty).is_none());
|
||||
|
||||
let _ = fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_section_wraps_content_with_source_path() {
|
||||
let instructions = WorkspaceInstructions {
|
||||
path: PathBuf::from("/ws/COYOTE.md"),
|
||||
content: "Do the thing.\n".into(),
|
||||
};
|
||||
|
||||
let section = build_instructions_section(&instructions);
|
||||
assert!(section.starts_with("<workspace_instructions source=\"/ws/COYOTE.md\">"));
|
||||
assert!(section.contains("Do the thing."));
|
||||
assert!(section.ends_with("</workspace_instructions>"));
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
use crate::mcp::{ConnectedServer, JsonField, McpServer, McpTransportType, spawn_mcp_server};
|
||||
use crate::mcp::{
|
||||
ConnectedServer, JsonField, McpServer, McpTransportType, is_auth_required_error, oauth,
|
||||
spawn_mcp_server,
|
||||
};
|
||||
|
||||
use anyhow::Result;
|
||||
use parking_lot::Mutex;
|
||||
@@ -99,7 +102,23 @@ impl McpFactory {
|
||||
return Ok(existing);
|
||||
}
|
||||
|
||||
let handle = spawn_mcp_server(spec, log_path).await?;
|
||||
let bearer_token = if spec.is_remote() {
|
||||
oauth::load_valid_mcp_token(name)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let handle = spawn_mcp_server(spec, log_path, bearer_token)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
if is_auth_required_error(&e) {
|
||||
e.context(format!(
|
||||
"MCP server '{name}' requires OAuth authentication. \
|
||||
Run `coyote --auth-mcp {name}` or `.mcp auth {name}` in the REPL to authenticate."
|
||||
))
|
||||
} else {
|
||||
e
|
||||
}
|
||||
})?;
|
||||
self.insert_active(key, &handle);
|
||||
Ok(handle)
|
||||
}
|
||||
@@ -125,6 +144,7 @@ mod tests {
|
||||
cwd: None,
|
||||
url: None,
|
||||
headers: None,
|
||||
oauth: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,6 +161,7 @@ mod tests {
|
||||
cwd: None,
|
||||
url: Some(url.to_string()),
|
||||
headers,
|
||||
oauth: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+34
-45
@@ -7,41 +7,27 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::config::{
|
||||
GIT_DIR_NAME, GITIGNORE_FILE_NAME, MEMORY_DIR_NAME, MEMORY_INDEX_FILE_NAME,
|
||||
WORKSPACE_MEMORY_DIR_NAME, WORKSPACE_MEMORY_FILE_NAME, paths,
|
||||
WORKSPACE_COYOTE_DIR_NAME, paths,
|
||||
};
|
||||
|
||||
pub const DEFAULT_MEMORY_CAP_WITH_TOOLS: usize = 6_000;
|
||||
pub const DEFAULT_MEMORY_CAP_WITHOUT_TOOLS: usize = 12_000;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum WorkspaceMemory {
|
||||
Structured {
|
||||
workspace_root: PathBuf,
|
||||
dir: PathBuf,
|
||||
},
|
||||
Lite {
|
||||
workspace_root: PathBuf,
|
||||
file: PathBuf,
|
||||
},
|
||||
pub struct WorkspaceMemory {
|
||||
pub workspace_root: PathBuf,
|
||||
pub dir: PathBuf,
|
||||
}
|
||||
|
||||
pub fn discover_workspace_memory(start: &Path) -> Option<WorkspaceMemory> {
|
||||
for dir in start.ancestors() {
|
||||
let structured = dir.join(WORKSPACE_MEMORY_DIR_NAME).join(MEMORY_DIR_NAME);
|
||||
let structured = dir.join(WORKSPACE_COYOTE_DIR_NAME).join(MEMORY_DIR_NAME);
|
||||
if structured.join(MEMORY_INDEX_FILE_NAME).exists() {
|
||||
return Some(WorkspaceMemory::Structured {
|
||||
return Some(WorkspaceMemory {
|
||||
workspace_root: dir.to_path_buf(),
|
||||
dir: structured,
|
||||
});
|
||||
}
|
||||
|
||||
let lite = dir.join(WORKSPACE_MEMORY_FILE_NAME);
|
||||
if lite.exists() {
|
||||
return Some(WorkspaceMemory::Lite {
|
||||
workspace_root: dir.to_path_buf(),
|
||||
file: lite,
|
||||
});
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
@@ -82,10 +68,10 @@ pub fn bootstrap_workspace_memory(git_root: &Path) -> Result<PathBuf> {
|
||||
Ok(mem_dir)
|
||||
}
|
||||
|
||||
fn append_gitignore_entry(git_root: &Path) -> Result<bool> {
|
||||
pub fn append_gitignore_entry(git_root: &Path) -> Result<bool> {
|
||||
let gitignore = git_root.join(GITIGNORE_FILE_NAME);
|
||||
let entry = format!("{WORKSPACE_MEMORY_DIR_NAME}/{MEMORY_DIR_NAME}/");
|
||||
let entry_no_slash = format!("{WORKSPACE_MEMORY_DIR_NAME}/{MEMORY_DIR_NAME}");
|
||||
let entry = format!("{WORKSPACE_COYOTE_DIR_NAME}/{MEMORY_DIR_NAME}/");
|
||||
let entry_no_slash = format!("{WORKSPACE_COYOTE_DIR_NAME}/{MEMORY_DIR_NAME}");
|
||||
|
||||
let existing = fs::read_to_string(&gitignore).unwrap_or_default();
|
||||
let already_present = existing.lines().any(|line| {
|
||||
@@ -118,6 +104,14 @@ pub struct MemoryFrontmatter {
|
||||
pub description: Option<String>,
|
||||
#[serde(default, rename = "type")]
|
||||
pub kind: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub created: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub updated: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub superseded_by: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub expires: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -204,9 +198,8 @@ impl MemoryStore {
|
||||
pub fn load_workspace_index(&self) -> Result<Option<String>> {
|
||||
match &self.workspace {
|
||||
None => Ok(None),
|
||||
Some(WorkspaceMemory::Lite { file, .. }) => Ok(Some(fs::read_to_string(file)?)),
|
||||
Some(WorkspaceMemory::Structured { dir, .. }) => {
|
||||
let index = dir.join(MEMORY_INDEX_FILE_NAME);
|
||||
Some(ws) => {
|
||||
let index = ws.dir.join(MEMORY_INDEX_FILE_NAME);
|
||||
if index.exists() {
|
||||
Ok(Some(fs::read_to_string(index)?))
|
||||
} else {
|
||||
@@ -223,8 +216,8 @@ impl MemoryStore {
|
||||
collect_md_files(&self.global_dir, &mut out)?;
|
||||
}
|
||||
|
||||
if let Some(WorkspaceMemory::Structured { dir, .. }) = &self.workspace {
|
||||
collect_md_files(dir, &mut out)?;
|
||||
if let Some(ws) = &self.workspace {
|
||||
collect_md_files(&ws.dir, &mut out)?;
|
||||
}
|
||||
|
||||
Ok(out)
|
||||
@@ -339,7 +332,7 @@ mod tests {
|
||||
let root = temp_root("phase1");
|
||||
let workspace = root.join("workspace");
|
||||
let workspace_memory_dir = workspace
|
||||
.join(WORKSPACE_MEMORY_DIR_NAME)
|
||||
.join(WORKSPACE_COYOTE_DIR_NAME)
|
||||
.join(MEMORY_DIR_NAME);
|
||||
fs::create_dir_all(&workspace_memory_dir).unwrap();
|
||||
fs::write(
|
||||
@@ -370,18 +363,13 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn workspace_discovery_prefers_structured_over_lite() {
|
||||
let root = temp_root("prefer");
|
||||
fn workspace_discovery_ignores_root_instructions_file() {
|
||||
let root = temp_root("no_lite");
|
||||
let workspace = root.join("ws");
|
||||
let structured = workspace
|
||||
.join(WORKSPACE_MEMORY_DIR_NAME)
|
||||
.join(MEMORY_DIR_NAME);
|
||||
fs::create_dir_all(&structured).unwrap();
|
||||
fs::write(structured.join(MEMORY_INDEX_FILE_NAME), "s").unwrap();
|
||||
fs::write(workspace.join(WORKSPACE_MEMORY_FILE_NAME), "l").unwrap();
|
||||
fs::create_dir_all(&workspace).unwrap();
|
||||
fs::write(workspace.join("COYOTE.md"), "instructions, not memory").unwrap();
|
||||
|
||||
let found = discover_workspace_memory(&workspace);
|
||||
assert!(matches!(found, Some(WorkspaceMemory::Structured { .. })));
|
||||
assert!(discover_workspace_memory(&workspace).is_none());
|
||||
|
||||
let _ = fs::remove_dir_all(&root);
|
||||
}
|
||||
@@ -407,7 +395,7 @@ mod tests {
|
||||
let root = temp_root("indexes_only");
|
||||
let workspace = root.join("ws");
|
||||
let structured = workspace
|
||||
.join(WORKSPACE_MEMORY_DIR_NAME)
|
||||
.join(WORKSPACE_COYOTE_DIR_NAME)
|
||||
.join(MEMORY_DIR_NAME);
|
||||
fs::create_dir_all(&structured).unwrap();
|
||||
fs::write(
|
||||
@@ -442,7 +430,7 @@ mod tests {
|
||||
let root = temp_root("drill_bodies");
|
||||
let workspace = root.join("ws");
|
||||
let structured = workspace
|
||||
.join(WORKSPACE_MEMORY_DIR_NAME)
|
||||
.join(WORKSPACE_COYOTE_DIR_NAME)
|
||||
.join(MEMORY_DIR_NAME);
|
||||
fs::create_dir_all(&structured).unwrap();
|
||||
fs::write(structured.join(MEMORY_INDEX_FILE_NAME), "idx").unwrap();
|
||||
@@ -477,7 +465,7 @@ mod tests {
|
||||
let root = temp_root("cap");
|
||||
let workspace = root.join("ws");
|
||||
let structured = workspace
|
||||
.join(WORKSPACE_MEMORY_DIR_NAME)
|
||||
.join(WORKSPACE_COYOTE_DIR_NAME)
|
||||
.join(MEMORY_DIR_NAME);
|
||||
fs::create_dir_all(&structured).unwrap();
|
||||
fs::write(structured.join(MEMORY_INDEX_FILE_NAME), "idx").unwrap();
|
||||
@@ -545,6 +533,7 @@ mod tests {
|
||||
name: "test".into(),
|
||||
description: Some("a test".into()),
|
||||
kind: Some("user".into()),
|
||||
..Default::default()
|
||||
},
|
||||
body: "Hello world\nmore text".into(),
|
||||
};
|
||||
@@ -566,15 +555,15 @@ mod tests {
|
||||
let root = temp_root("walk_up");
|
||||
let workspace = root.join("ws");
|
||||
let mem_dir = workspace
|
||||
.join(WORKSPACE_MEMORY_DIR_NAME)
|
||||
.join(WORKSPACE_COYOTE_DIR_NAME)
|
||||
.join(MEMORY_DIR_NAME);
|
||||
fs::create_dir_all(&mem_dir).unwrap();
|
||||
fs::write(mem_dir.join(MEMORY_INDEX_FILE_NAME), "idx").unwrap();
|
||||
let nested = workspace.join("src").join("deep").join("path");
|
||||
fs::create_dir_all(&nested).unwrap();
|
||||
|
||||
let found = discover_workspace_memory(&nested);
|
||||
assert!(matches!(found, Some(WorkspaceMemory::Structured { .. })));
|
||||
let found = discover_workspace_memory(&nested).expect("workspace memory should be found");
|
||||
assert_eq!(found.dir, mem_dir);
|
||||
|
||||
let _ = fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
+23
-7
@@ -3,6 +3,7 @@ mod app_config;
|
||||
mod app_state;
|
||||
mod input;
|
||||
mod install_remote;
|
||||
pub(crate) mod instructions;
|
||||
mod macros;
|
||||
mod mcp_factory;
|
||||
pub(crate) mod memory;
|
||||
@@ -135,14 +136,15 @@ const RAGS_DIR_NAME: &str = "rags";
|
||||
const FUNCTIONS_DIR_NAME: &str = "functions";
|
||||
const FUNCTIONS_BIN_DIR_NAME: &str = "bin";
|
||||
const AGENTS_DIR_NAME: &str = "agents";
|
||||
const REPL_HISTORY_DIR_NAME: &str = "repl-history";
|
||||
const GLOBAL_TOOLS_DIR_NAME: &str = "tools";
|
||||
const GLOBAL_TOOLS_UTILS_DIR_NAME: &str = "utils";
|
||||
const BASH_PROMPT_UTILS_FILE_NAME: &str = "prompt-utils.sh";
|
||||
const MCP_FILE_NAME: &str = "mcp.json";
|
||||
const HIDDEN_MCP_FILE_NAME: &str = ".mcp.json";
|
||||
const MEMORY_DIR_NAME: &str = "memory";
|
||||
const MEMORY_INDEX_FILE_NAME: &str = "MEMORY.md";
|
||||
const WORKSPACE_MEMORY_FILE_NAME: &str = "COYOTE.md";
|
||||
const WORKSPACE_MEMORY_DIR_NAME: &str = ".coyote";
|
||||
const WORKSPACE_COYOTE_DIR_NAME: &str = ".coyote";
|
||||
const SBX_KIT_DIR_NAME: &str = "sbx-kit";
|
||||
const SBX_KIT_HASH_FILE: &str = "kit.sha256";
|
||||
const SBX_MIXIN_FILE_NAME: &str = "sbx-mixin.yaml";
|
||||
@@ -150,7 +152,7 @@ const SBX_VAULT_MIXINS_DIR_NAME: &str = "sbx-vault-mixins";
|
||||
const SBX_MIXIN_KITS_DIR_NAME: &str = "sbx-mixin-kits";
|
||||
const GIT_DIR_NAME: &str = ".git";
|
||||
const GITIGNORE_FILE_NAME: &str = ".gitignore";
|
||||
const DEFAULT_VISIBLE_TOOLS: [&str; 18] = [
|
||||
const DEFAULT_VISIBLE_TOOLS: [&str; 19] = [
|
||||
"execute_command.sh",
|
||||
"execute_py_code.py",
|
||||
"execute_sql_code.sh",
|
||||
@@ -164,6 +166,7 @@ const DEFAULT_VISIBLE_TOOLS: [&str; 18] = [
|
||||
"fs_read.sh",
|
||||
"fs_rm.sh",
|
||||
"fs_write.sh",
|
||||
"ast_grep.sh",
|
||||
"get_current_time.sh",
|
||||
"get_current_weather.sh",
|
||||
"search_wikipedia.sh",
|
||||
@@ -181,7 +184,7 @@ const SUMMARIZATION_PROMPT: &str =
|
||||
const SUMMARY_CONTEXT_PROMPT: &str = "This is a summary of the chat history as a recap: ";
|
||||
|
||||
const LEFT_PROMPT: &str = "{color.red}{model}){color.green}{?session {?agent {agent}>}{session}{?role /}}{!session {?agent {agent}>}}{role}{?rag @{rag}}{color.cyan}{?session )}{!session >}{color.reset} ";
|
||||
const RIGHT_PROMPT: &str = "{color.purple}{?session {?consume_tokens {consume_tokens}({consume_percent}%)}{!consume_tokens {consume_tokens}}}{color.reset}";
|
||||
const RIGHT_PROMPT: &str = "{color.cyan}{?reasoning_effort [{reasoning_effort}] }{color.purple}{?session {?consume_tokens {consume_tokens}({consume_percent}%)}{!consume_tokens {consume_tokens}}}{color.reset}";
|
||||
|
||||
static EDITOR: OnceLock<Option<String>> = OnceLock::new();
|
||||
|
||||
@@ -242,12 +245,18 @@ pub struct Config {
|
||||
pub memory_cap_with_tools: Option<usize>,
|
||||
pub memory_cap_without_tools: Option<usize>,
|
||||
|
||||
pub workspace_instructions: Option<bool>,
|
||||
pub workspace_instructions_files: Option<Vec<String>>,
|
||||
|
||||
pub rag_embedding_model: Option<String>,
|
||||
pub rag_reranker_model: Option<String>,
|
||||
pub rag_top_k: usize,
|
||||
pub rag_chunk_size: Option<usize>,
|
||||
pub rag_chunk_overlap: Option<usize>,
|
||||
pub rag_template: Option<String>,
|
||||
pub rag_extractor_model: Option<String>,
|
||||
pub rag_extractor_prompt: Option<String>,
|
||||
pub rag_graph_hops: usize,
|
||||
|
||||
#[serde(default)]
|
||||
pub document_loaders: HashMap<String, String>,
|
||||
@@ -314,12 +323,18 @@ impl Default for Config {
|
||||
memory_cap_with_tools: None,
|
||||
memory_cap_without_tools: None,
|
||||
|
||||
workspace_instructions: None,
|
||||
workspace_instructions_files: None,
|
||||
|
||||
rag_embedding_model: None,
|
||||
rag_reranker_model: None,
|
||||
rag_top_k: 5,
|
||||
rag_chunk_size: None,
|
||||
rag_chunk_overlap: None,
|
||||
rag_template: None,
|
||||
rag_extractor_model: None,
|
||||
rag_extractor_prompt: None,
|
||||
rag_graph_hops: 1,
|
||||
|
||||
document_loaders: Default::default(),
|
||||
|
||||
@@ -443,9 +458,10 @@ fn confirm_asset_overwrite(category: AssetCategory, label: &str, target: &Path)
|
||||
}
|
||||
let body = match category {
|
||||
AssetCategory::McpConfig => format!(
|
||||
"This replaces your MCP server configuration at {} with this \
|
||||
build's bundled template. Your configured MCP servers (and any \
|
||||
custom secret references they contain) will be lost.",
|
||||
"This merges the bundled MCP server template into your configuration \
|
||||
at {}. New servers from the bundled template will be added; any \
|
||||
MCP servers you have already configured (including custom secret \
|
||||
references) are left untouched.",
|
||||
target.display()
|
||||
),
|
||||
_ => format!(
|
||||
|
||||
+174
-16
@@ -2,12 +2,14 @@ use super::role::Role;
|
||||
use super::{
|
||||
AGENT_GRAPH_FILE_NAME, AGENTS_DIR_NAME, BASH_PROMPT_UTILS_FILE_NAME, CONFIG_FILE_NAME,
|
||||
ENV_FILE_NAME, FUNCTIONS_BIN_DIR_NAME, FUNCTIONS_DIR_NAME, GLOBAL_TOOLS_DIR_NAME,
|
||||
GLOBAL_TOOLS_UTILS_DIR_NAME, MACROS_DIR_NAME, MCP_FILE_NAME, MEMORY_DIR_NAME,
|
||||
MEMORY_INDEX_FILE_NAME, ModelsOverride, RAGS_DIR_NAME, ROLES_DIR_NAME, SBX_KIT_DIR_NAME,
|
||||
SBX_KIT_HASH_FILE, SBX_MIXIN_FILE_NAME, SBX_MIXIN_KITS_DIR_NAME, SBX_VAULT_MIXINS_DIR_NAME,
|
||||
SKILLS_DIR_NAME, WORKSPACE_MEMORY_DIR_NAME,
|
||||
GLOBAL_TOOLS_UTILS_DIR_NAME, HIDDEN_MCP_FILE_NAME, MACROS_DIR_NAME, MCP_FILE_NAME,
|
||||
MEMORY_DIR_NAME, MEMORY_INDEX_FILE_NAME, ModelsOverride, RAGS_DIR_NAME, ROLES_DIR_NAME,
|
||||
SBX_KIT_DIR_NAME, SBX_KIT_HASH_FILE, SBX_MIXIN_FILE_NAME, SBX_MIXIN_KITS_DIR_NAME,
|
||||
SBX_VAULT_MIXINS_DIR_NAME, SKILLS_DIR_NAME, WORKSPACE_COYOTE_DIR_NAME,
|
||||
};
|
||||
use crate::client::ProviderModels;
|
||||
use crate::config::REPL_HISTORY_DIR_NAME;
|
||||
use crate::config::session::Session;
|
||||
use crate::utils::{get_env_name, list_file_names, normalize_env_name};
|
||||
|
||||
use anyhow::{Context, Result, anyhow, bail};
|
||||
@@ -116,7 +118,7 @@ pub fn global_tools_sbx_mixin_file() -> PathBuf {
|
||||
pub fn find_workspace_sbx_mixin(start: &Path) -> Option<PathBuf> {
|
||||
for dir in start.ancestors() {
|
||||
let candidate = dir
|
||||
.join(WORKSPACE_MEMORY_DIR_NAME)
|
||||
.join(WORKSPACE_COYOTE_DIR_NAME)
|
||||
.join(SBX_MIXIN_FILE_NAME);
|
||||
if candidate.exists() {
|
||||
return Some(candidate);
|
||||
@@ -191,6 +193,40 @@ pub fn skill_file(name: &str) -> PathBuf {
|
||||
skill_dir(name).join("SKILL.md")
|
||||
}
|
||||
|
||||
pub fn workspace_config_dir() -> PathBuf {
|
||||
let workspace_dir_name = match env::var(get_env_name("workspace_config_dir")) {
|
||||
Ok(value) => value,
|
||||
Err(_) => WORKSPACE_COYOTE_DIR_NAME.to_string(),
|
||||
};
|
||||
|
||||
env::current_dir()
|
||||
.unwrap_or_default()
|
||||
.join(workspace_dir_name)
|
||||
}
|
||||
|
||||
pub fn workspace_skills_dir() -> PathBuf {
|
||||
workspace_config_dir().join(SKILLS_DIR_NAME)
|
||||
}
|
||||
|
||||
pub fn workspace_skill_file(name: &str) -> PathBuf {
|
||||
workspace_skills_dir().join(name).join("SKILL.md")
|
||||
}
|
||||
|
||||
pub fn workspace_mcp_config_file() -> Option<PathBuf> {
|
||||
workspace_mcp_config_file_in(&env::current_dir().unwrap_or_default())
|
||||
}
|
||||
|
||||
fn workspace_mcp_config_file_in(workspace_root: &Path) -> Option<PathBuf> {
|
||||
let dir = workspace_config_dir();
|
||||
[
|
||||
dir.join(MCP_FILE_NAME),
|
||||
dir.join(HIDDEN_MCP_FILE_NAME),
|
||||
workspace_root.join(HIDDEN_MCP_FILE_NAME),
|
||||
]
|
||||
.into_iter()
|
||||
.find(|candidate| candidate.is_file())
|
||||
}
|
||||
|
||||
pub fn validate_skill_name(name: &str) -> Result<()> {
|
||||
if name.is_empty() {
|
||||
bail!("Skill name cannot be empty");
|
||||
@@ -316,10 +352,28 @@ pub fn global_memory_index_path() -> PathBuf {
|
||||
|
||||
pub fn workspace_memory_dir_for(workspace_root: &Path) -> PathBuf {
|
||||
workspace_root
|
||||
.join(WORKSPACE_MEMORY_DIR_NAME)
|
||||
.join(WORKSPACE_COYOTE_DIR_NAME)
|
||||
.join(MEMORY_DIR_NAME)
|
||||
}
|
||||
|
||||
pub fn workspace_memory_index_path_for(workspace_root: &Path) -> PathBuf {
|
||||
workspace_memory_dir_for(workspace_root).join(MEMORY_INDEX_FILE_NAME)
|
||||
}
|
||||
|
||||
pub fn repl_history_dir() -> PathBuf {
|
||||
cache_path().join(REPL_HISTORY_DIR_NAME)
|
||||
}
|
||||
|
||||
pub fn repl_history_file(session: &Option<Session>) -> PathBuf {
|
||||
let history_key = if let Some(session) = &session {
|
||||
format!("session_{}", session.name().replace('/', "_"))
|
||||
} else {
|
||||
"default".to_string()
|
||||
};
|
||||
|
||||
repl_history_dir().join(history_key)
|
||||
}
|
||||
|
||||
pub fn log_config() -> Result<(LevelFilter, Option<PathBuf>)> {
|
||||
let log_level = env::var(get_env_name("log_level"))
|
||||
.ok()
|
||||
@@ -389,15 +443,21 @@ pub fn has_macro(name: &str) -> bool {
|
||||
|
||||
pub fn list_skills() -> Vec<String> {
|
||||
let mut names = Vec::new();
|
||||
if let Ok(rd) = read_dir(skills_dir()) {
|
||||
for entry in rd.flatten() {
|
||||
if let Ok(file_type) = entry.file_type()
|
||||
&& file_type.is_dir()
|
||||
&& let Some(name) = entry.file_name().to_str()
|
||||
&& entry.path().join("SKILL.md").is_file()
|
||||
&& validate_skill_name(name).is_ok()
|
||||
{
|
||||
names.push(name.to_string());
|
||||
let mut seen = HashSet::new();
|
||||
|
||||
for dir in [workspace_skills_dir(), skills_dir()] {
|
||||
if let Ok(rd) = read_dir(dir) {
|
||||
for entry in rd.flatten() {
|
||||
if let Ok(file_type) = entry.file_type()
|
||||
&& file_type.is_dir()
|
||||
&& let Some(name) = entry.file_name().to_str()
|
||||
&& !seen.contains(name)
|
||||
&& entry.path().join("SKILL.md").is_file()
|
||||
&& validate_skill_name(name).is_ok()
|
||||
{
|
||||
seen.insert(name.to_string());
|
||||
names.push(name.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -407,7 +467,7 @@ pub fn list_skills() -> Vec<String> {
|
||||
}
|
||||
|
||||
pub fn has_skill(name: &str) -> bool {
|
||||
skill_file(name).is_file()
|
||||
workspace_skill_file(name).is_file() || skill_file(name).is_file()
|
||||
}
|
||||
|
||||
pub fn local_models_override() -> Result<Vec<ProviderModels>> {
|
||||
@@ -642,6 +702,104 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
mod workspace_mcp_resolution {
|
||||
use super::*;
|
||||
use serial_test::serial;
|
||||
|
||||
fn with_workspace_dir<F: FnOnce(&Path, &Path)>(f: F) {
|
||||
let unique = time::SystemTime::now()
|
||||
.duration_since(time::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_nanos();
|
||||
let root = env::temp_dir().join(format!("coyote-workspace-mcp-test-{unique}"));
|
||||
let ws_dir = root.join(WORKSPACE_COYOTE_DIR_NAME);
|
||||
fs::create_dir_all(&ws_dir).unwrap();
|
||||
let env_name = get_env_name("workspace_config_dir");
|
||||
let prev = env::var_os(&env_name);
|
||||
unsafe {
|
||||
env::set_var(&env_name, &ws_dir);
|
||||
}
|
||||
f(&root, &ws_dir);
|
||||
unsafe {
|
||||
match prev {
|
||||
Some(v) => env::set_var(&env_name, v),
|
||||
None => env::remove_var(&env_name),
|
||||
}
|
||||
}
|
||||
let _ = fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn returns_none_when_no_config_exists() {
|
||||
with_workspace_dir(|root, _| {
|
||||
assert_eq!(workspace_mcp_config_file_in(root), None);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn finds_mcp_json() {
|
||||
with_workspace_dir(|root, ws_dir| {
|
||||
fs::write(ws_dir.join("mcp.json"), "{}").unwrap();
|
||||
assert_eq!(
|
||||
workspace_mcp_config_file_in(root),
|
||||
Some(ws_dir.join("mcp.json"))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn falls_back_to_claude_style_hidden_mcp_json() {
|
||||
with_workspace_dir(|root, ws_dir| {
|
||||
fs::write(ws_dir.join(".mcp.json"), "{}").unwrap();
|
||||
assert_eq!(
|
||||
workspace_mcp_config_file_in(root),
|
||||
Some(ws_dir.join(".mcp.json"))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn prefers_mcp_json_when_both_exist() {
|
||||
with_workspace_dir(|root, ws_dir| {
|
||||
fs::write(ws_dir.join("mcp.json"), "{}").unwrap();
|
||||
fs::write(ws_dir.join(".mcp.json"), "{}").unwrap();
|
||||
assert_eq!(
|
||||
workspace_mcp_config_file_in(root),
|
||||
Some(ws_dir.join("mcp.json"))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn falls_back_to_project_root_hidden_mcp_json() {
|
||||
with_workspace_dir(|root, _| {
|
||||
fs::write(root.join(".mcp.json"), "{}").unwrap();
|
||||
assert_eq!(
|
||||
workspace_mcp_config_file_in(root),
|
||||
Some(root.join(".mcp.json"))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn prefers_workspace_dir_config_over_project_root() {
|
||||
with_workspace_dir(|root, ws_dir| {
|
||||
fs::write(ws_dir.join(".mcp.json"), "{}").unwrap();
|
||||
fs::write(root.join(".mcp.json"), "{}").unwrap();
|
||||
assert_eq!(
|
||||
workspace_mcp_config_file_in(root),
|
||||
Some(ws_dir.join(".mcp.json"))
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sandbox_kit_override_reflects_env_var_state() {
|
||||
let env_name = get_env_name("sandbox_kit");
|
||||
|
||||
+12
-2
@@ -18,10 +18,16 @@ pub(crate) const DEFAULT_MEMORY_INSTRUCTIONS: &str = indoc! {"
|
||||
- `memory__read(name)`: Read a specific drill file's full content.
|
||||
- `memory__write(name, content, scope)`: Create or replace a drill file (scope: 'global' | 'workspace').
|
||||
The MEMORY.md index is appended automatically; do not also update the index by hand.
|
||||
Optional `superseded_by` / `expires` (YYYY-MM-DD) mark a memory as stale for later cleanup.
|
||||
- `memory__rename(name, new_name, scope)`: Rename a drill file. Its index entry and every
|
||||
[[wikilink]] to it are rewritten automatically.
|
||||
- `memory__delete(name, scope)`: Delete a drill file and its index entry. Reports any
|
||||
[[wikilinks]] left dangling in other files.
|
||||
- `memory__edit_index(scope, content)`: Replace the entire MEMORY.md at the given scope.
|
||||
Use this to add always-on facts, reorganize, prune stale entries, or fix descriptions.
|
||||
- `memory__list()`: See all known drill files and their metadata.
|
||||
- `memory__lint()`: Health-check memory for orphans, broken links, oversized files.
|
||||
- `memory__lint()`: Health-check memory for orphans, broken links, oversized files,
|
||||
stale (superseded/expired) files, and index descriptions that drifted from the files.
|
||||
|
||||
RULES:
|
||||
- Every interaction has two outputs: your answer AND any memory updates the conversation warrants.
|
||||
@@ -29,7 +35,11 @@ pub(crate) const DEFAULT_MEMORY_INSTRUCTIONS: &str = indoc! {"
|
||||
- All MEMORY.md edits MUST go through `memory__edit_index`. NEVER use `fs_write`, `fs_patch`,
|
||||
or any other generic file tool on MEMORY.md — Coyote manages its location and a stray
|
||||
MEMORY.md outside the managed path is invisible to memory.
|
||||
- All drill files MUST go through `memory__write`. The index updates itself.
|
||||
- All drill files MUST go through `memory__write`. The index updates itself. Renames and
|
||||
deletions MUST go through `memory__rename` / `memory__delete` so links stay intact.
|
||||
- When a fact becomes outdated, update it in place, delete it, or mark the old file with
|
||||
`superseded_by`/`expires` so `memory__lint` flags it later. Never leave contradictory
|
||||
memories side by side.
|
||||
- Use [[wikilink]] notation in memory files to reference other memories by their `name:` slug.
|
||||
- NEVER write secrets, credentials, or API keys to memory — memory is plaintext on disk.
|
||||
Use coyote's Vault for secrets.
|
||||
|
||||
+952
-50
File diff suppressed because it is too large
Load Diff
@@ -32,7 +32,9 @@ pub trait RoleLike {
|
||||
fn enabled_mcp_servers(&self) -> Option<Vec<String>>;
|
||||
fn set_model(&mut self, model: Model);
|
||||
fn set_temperature(&mut self, value: Option<f64>);
|
||||
fn reasoning_effort(&self) -> Option<String>;
|
||||
fn set_top_p(&mut self, value: Option<f64>);
|
||||
fn set_reasoning_effort(&mut self, value: Option<String>);
|
||||
fn set_enabled_tools(&mut self, value: Option<Vec<String>>);
|
||||
fn set_enabled_mcp_servers(&mut self, value: Option<Vec<String>>);
|
||||
}
|
||||
@@ -51,6 +53,8 @@ pub struct Role {
|
||||
temperature: Option<f64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
top_p: Option<f64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
reasoning_effort: Option<String>,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
@@ -116,6 +120,9 @@ impl Role {
|
||||
"model" => role.model_id = value.as_str().map(|v| v.to_string()),
|
||||
"temperature" => role.temperature = value.as_f64(),
|
||||
"top_p" => role.top_p = value.as_f64(),
|
||||
"reasoning_effort" => {
|
||||
role.reasoning_effort = value.as_str().map(|v| v.to_string())
|
||||
}
|
||||
"enabled_tools" => role.enabled_tools = parse_string_or_array(value),
|
||||
"enabled_mcp_servers" => {
|
||||
role.enabled_mcp_servers = parse_string_or_array(value)
|
||||
@@ -170,6 +177,9 @@ impl Role {
|
||||
if let Some(top_p) = self.top_p() {
|
||||
metadata.push(format!("top_p: {top_p}"));
|
||||
}
|
||||
if let Some(reasoning_effort) = self.reasoning_effort() {
|
||||
metadata.push(format!("reasoning_effort: {reasoning_effort}"));
|
||||
}
|
||||
if let Some(enabled_tools) = &self.enabled_tools {
|
||||
let inline = serde_json::to_string(enabled_tools).unwrap_or_else(|_| "[]".to_string());
|
||||
metadata.push(format!("enabled_tools: {inline}"));
|
||||
@@ -256,6 +266,9 @@ impl Role {
|
||||
enabled_tools,
|
||||
enabled_mcp_servers,
|
||||
);
|
||||
if let Some(v) = role_like.reasoning_effort() {
|
||||
self.set_reasoning_effort(Some(v));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn batch_set(
|
||||
@@ -410,6 +423,10 @@ impl RoleLike for Role {
|
||||
self.top_p
|
||||
}
|
||||
|
||||
fn reasoning_effort(&self) -> Option<String> {
|
||||
self.reasoning_effort.clone()
|
||||
}
|
||||
|
||||
fn enabled_tools(&self) -> Option<Vec<String>> {
|
||||
self.enabled_tools.clone()
|
||||
}
|
||||
@@ -433,6 +450,10 @@ impl RoleLike for Role {
|
||||
self.top_p = value;
|
||||
}
|
||||
|
||||
fn set_reasoning_effort(&mut self, value: Option<String>) {
|
||||
self.reasoning_effort = value;
|
||||
}
|
||||
|
||||
fn set_enabled_tools(&mut self, value: Option<Vec<String>>) {
|
||||
self.enabled_tools = value;
|
||||
}
|
||||
|
||||
+32
-1
@@ -24,6 +24,8 @@ pub struct Session {
|
||||
temperature: Option<f64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
top_p: Option<f64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
reasoning_effort: Option<String>,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
@@ -163,6 +165,14 @@ impl Session {
|
||||
self.messages.is_empty() && self.compressed_messages.is_empty()
|
||||
}
|
||||
|
||||
pub fn messages(&self) -> &[Message] {
|
||||
&self.messages
|
||||
}
|
||||
|
||||
pub fn compressed_messages(&self) -> &[Message] {
|
||||
&self.compressed_messages
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
@@ -253,7 +263,7 @@ impl Session {
|
||||
data["messages"] = json!(self.messages);
|
||||
|
||||
let output = serde_yaml::to_string(&data)
|
||||
.with_context(|| format!("Unable to show info about session '{}'", &self.name))?;
|
||||
.with_context(|| format!("Unable to show info about session '{}'", self.name))?;
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
@@ -393,6 +403,7 @@ impl Session {
|
||||
self.model_id = role.model().id();
|
||||
self.temperature = role.temperature();
|
||||
self.top_p = role.top_p();
|
||||
self.reasoning_effort = role.reasoning_effort();
|
||||
self.enabled_tools = role.enabled_tools();
|
||||
self.enabled_mcp_servers = role.enabled_mcp_servers();
|
||||
self.model = role.model().clone();
|
||||
@@ -724,6 +735,15 @@ impl Session {
|
||||
self.update_tokens();
|
||||
}
|
||||
|
||||
pub fn pop_last_exchange(&mut self) -> Option<String> {
|
||||
let user_idx = self.messages.iter().rposition(|m| m.role.is_user())?;
|
||||
let user_text = self.messages[user_idx].content.as_text()?.to_string();
|
||||
self.messages.truncate(user_idx);
|
||||
self.dirty = true;
|
||||
self.update_tokens();
|
||||
Some(user_text)
|
||||
}
|
||||
|
||||
pub fn echo_messages(&self, input: &Input) -> String {
|
||||
let messages = self.build_messages(input);
|
||||
serde_yaml::to_string(&messages).unwrap_or_else(|_| "Unable to echo message".into())
|
||||
@@ -775,6 +795,10 @@ impl RoleLike for Session {
|
||||
self.top_p
|
||||
}
|
||||
|
||||
fn reasoning_effort(&self) -> Option<String> {
|
||||
self.reasoning_effort.clone()
|
||||
}
|
||||
|
||||
fn enabled_tools(&self) -> Option<Vec<String>> {
|
||||
self.enabled_tools.clone()
|
||||
}
|
||||
@@ -806,6 +830,13 @@ impl RoleLike for Session {
|
||||
}
|
||||
}
|
||||
|
||||
fn set_reasoning_effort(&mut self, value: Option<String>) {
|
||||
if self.reasoning_effort != value {
|
||||
self.reasoning_effort = value;
|
||||
self.dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
fn set_enabled_tools(&mut self, value: Option<Vec<String>>) {
|
||||
if self.enabled_tools != value {
|
||||
self.enabled_tools = value;
|
||||
|
||||
+5
-1
@@ -117,7 +117,11 @@ impl Skill {
|
||||
|
||||
pub fn load(name: &str) -> Result<Self> {
|
||||
paths::validate_skill_name(name)?;
|
||||
let path = paths::skill_file(name);
|
||||
let path = if paths::workspace_skill_file(name).is_file() {
|
||||
paths::workspace_skill_file(name)
|
||||
} else {
|
||||
paths::skill_file(name)
|
||||
};
|
||||
let content = read_to_string(&path)
|
||||
.with_context(|| format!("Failed to read skill '{name}' at {}", path.display()))?;
|
||||
Ok(Skill::new(name, &content))
|
||||
|
||||
@@ -68,6 +68,14 @@ fn normalize_version(requested: Option<String>) -> Option<String> {
|
||||
}
|
||||
}
|
||||
|
||||
fn preferred_update_target() -> Option<&'static str> {
|
||||
match (env::consts::OS, env::consts::ARCH) {
|
||||
("linux", "x86_64") => Some("x86_64-unknown-linux-musl"),
|
||||
("linux", "aarch64") => Some("aarch64-unknown-linux-musl"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_dir_writable(dir: &Path) -> bool {
|
||||
let probe = dir.join(format!(".coyote-update-write-test-{}", process::id()));
|
||||
match OpenOptions::new().write(true).create_new(true).open(&probe) {
|
||||
@@ -147,6 +155,9 @@ pub fn run_self_update(requested: Option<String>, force: bool) -> Result<()> {
|
||||
if let Some(tag) = &target_tag {
|
||||
builder.target_version_tag(tag.as_str());
|
||||
}
|
||||
if let Some(target) = preferred_update_target() {
|
||||
builder.target(target);
|
||||
}
|
||||
let status = builder
|
||||
.build()
|
||||
.context("Failed to configure the self-update")?
|
||||
|
||||
+729
-68
@@ -3,6 +3,7 @@ use std::path::{Path, PathBuf};
|
||||
use std::{env, fs};
|
||||
|
||||
use anyhow::{Context, Result, anyhow, bail};
|
||||
use chrono::Local;
|
||||
use indexmap::IndexMap;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
@@ -97,6 +98,32 @@ pub fn memory_function_declarations() -> Vec<FunctionDeclaration> {
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
(
|
||||
"superseded_by".to_string(),
|
||||
JsonSchema {
|
||||
type_value: Some("string".to_string()),
|
||||
description: Some(
|
||||
"Optional `name:` slug of the memory that replaces this one. \
|
||||
`memory__lint` flags superseded files for cleanup. Omitting this \
|
||||
on overwrite clears any previous value."
|
||||
.into(),
|
||||
),
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
(
|
||||
"expires".to_string(),
|
||||
JsonSchema {
|
||||
type_value: Some("string".to_string()),
|
||||
description: Some(
|
||||
"Optional ISO date (YYYY-MM-DD) after which this memory is stale. \
|
||||
`memory__lint` flags expired files. Omitting this on overwrite \
|
||||
clears any previous value."
|
||||
.into(),
|
||||
),
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
])),
|
||||
required: Some(vec![
|
||||
"name".to_string(),
|
||||
@@ -164,6 +191,90 @@ pub fn memory_function_declarations() -> Vec<FunctionDeclaration> {
|
||||
},
|
||||
agent: false,
|
||||
},
|
||||
FunctionDeclaration {
|
||||
name: format!("{MEMORY_FUNCTION_PREFIX}rename"),
|
||||
description:
|
||||
"Rename a memory file. Its MEMORY.md index entry and every [[wikilink]] to it in \
|
||||
other memory files are rewritten automatically."
|
||||
.to_string(),
|
||||
parameters: JsonSchema {
|
||||
type_value: Some("object".to_string()),
|
||||
properties: Some(IndexMap::from([
|
||||
(
|
||||
"name".to_string(),
|
||||
JsonSchema {
|
||||
type_value: Some("string".to_string()),
|
||||
description: Some("Current `name:` slug of the memory file".into()),
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
(
|
||||
"new_name".to_string(),
|
||||
JsonSchema {
|
||||
type_value: Some("string".to_string()),
|
||||
description: Some(
|
||||
"New kebab-case slug for the file (no extension)".into(),
|
||||
),
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
(
|
||||
"scope".to_string(),
|
||||
JsonSchema {
|
||||
type_value: Some("string".to_string()),
|
||||
description: Some(
|
||||
"Scope of the file: 'global' (user-level) or 'workspace' (project-level)"
|
||||
.into(),
|
||||
),
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
])),
|
||||
required: Some(vec![
|
||||
"name".to_string(),
|
||||
"new_name".to_string(),
|
||||
"scope".to_string(),
|
||||
]),
|
||||
..Default::default()
|
||||
},
|
||||
agent: false,
|
||||
},
|
||||
FunctionDeclaration {
|
||||
name: format!("{MEMORY_FUNCTION_PREFIX}delete"),
|
||||
description:
|
||||
"Delete a memory file and remove its MEMORY.md index entry. Reports any \
|
||||
[[wikilinks]] in other memory files left dangling by the deletion."
|
||||
.to_string(),
|
||||
parameters: JsonSchema {
|
||||
type_value: Some("object".to_string()),
|
||||
properties: Some(IndexMap::from([
|
||||
(
|
||||
"name".to_string(),
|
||||
JsonSchema {
|
||||
type_value: Some("string".to_string()),
|
||||
description: Some(
|
||||
"The `name:` slug of the memory file to delete".into(),
|
||||
),
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
(
|
||||
"scope".to_string(),
|
||||
JsonSchema {
|
||||
type_value: Some("string".to_string()),
|
||||
description: Some(
|
||||
"Scope of the file: 'global' (user-level) or 'workspace' (project-level)"
|
||||
.into(),
|
||||
),
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
])),
|
||||
required: Some(vec!["name".to_string(), "scope".to_string()]),
|
||||
..Default::default()
|
||||
},
|
||||
agent: false,
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
@@ -214,47 +325,13 @@ pub fn handle_memory_tool(ctx: &mut RequestContext, cmd_name: &str, args: &Value
|
||||
"workspace": store.workspace.as_ref().map(workspace_label),
|
||||
}))
|
||||
}
|
||||
"write" => {
|
||||
let name = arg_str(args, "name")?;
|
||||
let description = arg_str(args, "description")?;
|
||||
let content = arg_str(args, "content")?;
|
||||
let scope = arg_str(args, "scope")?;
|
||||
let kind = args.get("type").and_then(Value::as_str).map(String::from);
|
||||
|
||||
let target_dir = match scope.as_str() {
|
||||
"global" => paths::global_memory_dir(),
|
||||
"workspace" => workspace_write_dir(&store, &cwd)?,
|
||||
other => bail!("unknown scope '{}': use 'global' or 'workspace'", other),
|
||||
};
|
||||
let file = MemoryFile {
|
||||
path: target_dir.join(format!("{name}.md")),
|
||||
frontmatter: MemoryFrontmatter {
|
||||
name: name.clone(),
|
||||
description: Some(description.clone()),
|
||||
kind,
|
||||
},
|
||||
body: content,
|
||||
};
|
||||
file.save()?;
|
||||
|
||||
let index_path = target_dir.join("MEMORY.md");
|
||||
let index_updated = ensure_index_entry(&index_path, &name, &description)?;
|
||||
|
||||
Ok(json!({
|
||||
"status": "ok",
|
||||
"path": file.path.display().to_string(),
|
||||
"index_path": index_path.display().to_string(),
|
||||
"index_updated": index_updated,
|
||||
}))
|
||||
}
|
||||
"write" => write_memory(&store, &cwd, args),
|
||||
"rename" => rename_memory(&store, &cwd, args),
|
||||
"delete" => delete_memory(&store, &cwd, args),
|
||||
"edit_index" => {
|
||||
let scope = arg_str(args, "scope")?;
|
||||
let content = arg_str(args, "content")?;
|
||||
let target_dir = match scope.as_str() {
|
||||
"global" => paths::global_memory_dir(),
|
||||
"workspace" => workspace_write_dir(&store, &cwd)?,
|
||||
other => bail!("unknown scope '{}': use 'global' or 'workspace'", other),
|
||||
};
|
||||
let target_dir = scope_dir(&store, &cwd, &scope)?;
|
||||
let index_path = write_memory_index(&target_dir, &content)?;
|
||||
|
||||
Ok(json!({
|
||||
@@ -267,19 +344,223 @@ pub fn handle_memory_tool(ctx: &mut RequestContext, cmd_name: &str, args: &Value
|
||||
}
|
||||
}
|
||||
|
||||
fn write_memory(store: &MemoryStore, cwd: &Path, args: &Value) -> Result<Value> {
|
||||
let name = arg_str(args, "name")?;
|
||||
let description = arg_str(args, "description")?;
|
||||
let content = arg_str(args, "content")?;
|
||||
let scope = arg_str(args, "scope")?;
|
||||
let kind = args.get("type").and_then(Value::as_str).map(String::from);
|
||||
let superseded_by = args
|
||||
.get("superseded_by")
|
||||
.and_then(Value::as_str)
|
||||
.map(String::from);
|
||||
let expires = args
|
||||
.get("expires")
|
||||
.and_then(Value::as_str)
|
||||
.map(String::from);
|
||||
|
||||
let target_dir = scope_dir(store, cwd, &scope)?;
|
||||
let path = target_dir.join(format!("{name}.md"));
|
||||
let previous = if path.exists() {
|
||||
MemoryFile::load(&path).ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let today = today_string();
|
||||
let created = previous
|
||||
.as_ref()
|
||||
.and_then(|p| p.frontmatter.created.clone())
|
||||
.unwrap_or_else(|| today.clone());
|
||||
|
||||
let file = MemoryFile {
|
||||
path,
|
||||
frontmatter: MemoryFrontmatter {
|
||||
name: name.clone(),
|
||||
description: Some(description.clone()),
|
||||
kind,
|
||||
created: Some(created),
|
||||
updated: Some(today),
|
||||
superseded_by,
|
||||
expires,
|
||||
},
|
||||
body: content,
|
||||
};
|
||||
file.save()?;
|
||||
|
||||
let index_path = target_dir.join("MEMORY.md");
|
||||
let index_updated = ensure_index_entry(&index_path, &name, &description)?;
|
||||
|
||||
Ok(json!({
|
||||
"status": "ok",
|
||||
"path": file.path.display().to_string(),
|
||||
"index_path": index_path.display().to_string(),
|
||||
"index_updated": index_updated,
|
||||
"replaced": previous.is_some(),
|
||||
"previous_description": previous.and_then(|p| p.frontmatter.description),
|
||||
}))
|
||||
}
|
||||
|
||||
fn rename_memory(store: &MemoryStore, cwd: &Path, args: &Value) -> Result<Value> {
|
||||
let name = arg_str(args, "name")?;
|
||||
let new_name = arg_str(args, "new_name")?;
|
||||
let scope = arg_str(args, "scope")?;
|
||||
if new_name.is_empty()
|
||||
|| !new_name
|
||||
.chars()
|
||||
.all(|c| c.is_alphanumeric() || c == '-' || c == '_')
|
||||
{
|
||||
bail!(
|
||||
"invalid new_name '{}': use a kebab-case slug (alphanumeric, hyphens, underscores)",
|
||||
new_name
|
||||
);
|
||||
}
|
||||
|
||||
if name == new_name {
|
||||
bail!("new_name matches the current name");
|
||||
}
|
||||
|
||||
let target_dir = scope_dir(store, cwd, &scope)?;
|
||||
let files = store.list_files()?;
|
||||
let file = files
|
||||
.iter()
|
||||
.find(|f| f.path.starts_with(&target_dir) && f.frontmatter.name == name)
|
||||
.ok_or_else(|| anyhow!("memory file '{}' not found in scope '{}'", name, scope))?
|
||||
.clone();
|
||||
|
||||
if target_dir.join(format!("{new_name}.md")).exists()
|
||||
|| files
|
||||
.iter()
|
||||
.any(|f| f.path.starts_with(&target_dir) && f.frontmatter.name == new_name)
|
||||
{
|
||||
bail!(
|
||||
"memory file '{}' already exists in scope '{}'",
|
||||
new_name,
|
||||
scope
|
||||
);
|
||||
}
|
||||
|
||||
let needle = format!("[[{name}]]");
|
||||
let replacement = format!("[[{new_name}]]");
|
||||
|
||||
let mut renamed = file.clone();
|
||||
renamed.path = target_dir.join(format!("{new_name}.md"));
|
||||
renamed.frontmatter.name = new_name.clone();
|
||||
renamed.frontmatter.updated = Some(today_string());
|
||||
renamed.body = renamed.body.replace(&needle, &replacement);
|
||||
renamed.save()?;
|
||||
fs::remove_file(&file.path).with_context(|| format!("remove {}", file.path.display()))?;
|
||||
|
||||
let mut rewritten = Vec::new();
|
||||
for f in &files {
|
||||
if f.path == file.path || !f.body.contains(&needle) {
|
||||
continue;
|
||||
}
|
||||
let mut updated = f.clone();
|
||||
updated.body = updated.body.replace(&needle, &replacement);
|
||||
updated.save()?;
|
||||
rewritten.push(f.frontmatter.name.clone());
|
||||
}
|
||||
|
||||
// Own-scope index: rewrite the wikilink, drop any leftover references to the
|
||||
// old name, and guarantee the new name is present.
|
||||
let index_path = target_dir.join("MEMORY.md");
|
||||
if let Ok(existing) = fs::read_to_string(&index_path)
|
||||
&& existing.contains(&needle)
|
||||
{
|
||||
fs::write(&index_path, existing.replace(&needle, &replacement))?;
|
||||
}
|
||||
|
||||
remove_index_entry(&index_path, &name)?;
|
||||
let description = renamed.frontmatter.description.clone().unwrap_or_default();
|
||||
ensure_index_entry(&index_path, &new_name, &description)?;
|
||||
|
||||
// Other indexes (other scope's MEMORY.md): rewrite wikilinks only.
|
||||
for other_index in other_index_paths(store, &target_dir) {
|
||||
if let Ok(existing) = fs::read_to_string(&other_index)
|
||||
&& existing.contains(&needle)
|
||||
{
|
||||
fs::write(&other_index, existing.replace(&needle, &replacement))?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(json!({
|
||||
"status": "ok",
|
||||
"old_path": file.path.display().to_string(),
|
||||
"new_path": renamed.path.display().to_string(),
|
||||
"rewritten_references": rewritten,
|
||||
}))
|
||||
}
|
||||
|
||||
fn delete_memory(store: &MemoryStore, cwd: &Path, args: &Value) -> Result<Value> {
|
||||
let name = arg_str(args, "name")?;
|
||||
let scope = arg_str(args, "scope")?;
|
||||
let target_dir = scope_dir(store, cwd, &scope)?;
|
||||
let files = store.list_files()?;
|
||||
let file = files
|
||||
.iter()
|
||||
.find(|f| f.path.starts_with(&target_dir) && f.frontmatter.name == name)
|
||||
.ok_or_else(|| anyhow!("memory file '{}' not found in scope '{}'", name, scope))?;
|
||||
let deleted_path = file.path.clone();
|
||||
fs::remove_file(&deleted_path).with_context(|| format!("delete {}", deleted_path.display()))?;
|
||||
|
||||
let index_path = target_dir.join("MEMORY.md");
|
||||
let index_updated = remove_index_entry(&index_path, &name)?;
|
||||
|
||||
let dangling: Vec<String> = files
|
||||
.iter()
|
||||
.filter(|f| f.path != deleted_path && extract_wikilinks(&f.body).iter().any(|l| l == &name))
|
||||
.map(|f| f.frontmatter.name.clone())
|
||||
.collect();
|
||||
|
||||
Ok(json!({
|
||||
"status": "ok",
|
||||
"deleted_path": deleted_path.display().to_string(),
|
||||
"index_updated": index_updated,
|
||||
"dangling_references": dangling,
|
||||
}))
|
||||
}
|
||||
|
||||
fn scope_dir(store: &MemoryStore, cwd: &Path, scope: &str) -> Result<PathBuf> {
|
||||
match scope {
|
||||
"global" => Ok(paths::global_memory_dir()),
|
||||
"workspace" => workspace_write_dir(store, cwd),
|
||||
other => bail!("unknown scope '{}': use 'global' or 'workspace'", other),
|
||||
}
|
||||
}
|
||||
|
||||
fn today_string() -> String {
|
||||
Local::now().format("%Y-%m-%d").to_string()
|
||||
}
|
||||
|
||||
fn other_index_paths(store: &MemoryStore, own_dir: &Path) -> Vec<PathBuf> {
|
||||
let mut out = Vec::new();
|
||||
let global_index = store.global_dir.join("MEMORY.md");
|
||||
if store.global_dir.as_path() != own_dir && global_index.exists() {
|
||||
out.push(global_index);
|
||||
}
|
||||
|
||||
if let Some(ws) = &store.workspace {
|
||||
let index = ws.dir.join("MEMORY.md");
|
||||
if ws.dir.as_path() != own_dir && index.exists() {
|
||||
out.push(index);
|
||||
}
|
||||
}
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
fn write_memory_index(target_dir: &Path, content: &str) -> Result<PathBuf> {
|
||||
fs::create_dir_all(target_dir)?;
|
||||
let index_path = target_dir.join("MEMORY.md");
|
||||
|
||||
fs::write(&index_path, content)?;
|
||||
|
||||
Ok(index_path)
|
||||
}
|
||||
|
||||
fn ensure_index_entry(index_path: &Path, name: &str, description: &str) -> Result<bool> {
|
||||
let existing = fs::read_to_string(index_path).unwrap_or_default();
|
||||
let already_referenced =
|
||||
existing.contains(&format!("[[{name}]]")) || existing.contains(&format!("{name}.md"));
|
||||
|
||||
if already_referenced {
|
||||
if index_references(&existing, name) {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
@@ -297,6 +578,40 @@ fn ensure_index_entry(index_path: &Path, name: &str, description: &str) -> Resul
|
||||
}
|
||||
|
||||
fs::write(index_path, new_content)?;
|
||||
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn line_references(line: &str, name: &str) -> bool {
|
||||
let file_name = format!("{name}.md");
|
||||
line.split(|c: char| !(c.is_alphanumeric() || c == '-' || c == '_' || c == '.'))
|
||||
.any(|token| token == file_name || token.trim_matches('.') == name)
|
||||
}
|
||||
|
||||
fn index_references(index: &str, name: &str) -> bool {
|
||||
index.lines().any(|line| line_references(line, name))
|
||||
}
|
||||
|
||||
fn remove_index_entry(index_path: &Path, name: &str) -> Result<bool> {
|
||||
let Ok(existing) = fs::read_to_string(index_path) else {
|
||||
return Ok(false);
|
||||
};
|
||||
let kept: Vec<&str> = existing
|
||||
.lines()
|
||||
.filter(|line| !line_references(line, name))
|
||||
.collect();
|
||||
let mut new_content = kept.join("\n");
|
||||
|
||||
if existing.ends_with('\n') && !new_content.is_empty() {
|
||||
new_content.push('\n');
|
||||
}
|
||||
|
||||
if new_content == existing {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
fs::write(index_path, new_content)?;
|
||||
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
@@ -316,10 +631,7 @@ fn find_file(store: &MemoryStore, name: &str) -> Result<Option<MemoryFile>> {
|
||||
|
||||
fn workspace_write_dir(store: &MemoryStore, cwd: &Path) -> Result<PathBuf> {
|
||||
match &store.workspace {
|
||||
Some(WorkspaceMemory::Structured { dir, .. }) => Ok(dir.clone()),
|
||||
Some(WorkspaceMemory::Lite { workspace_root, .. }) => {
|
||||
Ok(paths::workspace_memory_dir_for(workspace_root))
|
||||
}
|
||||
Some(ws) => Ok(ws.dir.clone()),
|
||||
None => match find_git_root(cwd) {
|
||||
Some(git_root) => bootstrap_workspace_memory(&git_root),
|
||||
None => bail!(
|
||||
@@ -331,28 +643,20 @@ fn workspace_write_dir(store: &MemoryStore, cwd: &Path) -> Result<PathBuf> {
|
||||
}
|
||||
|
||||
fn workspace_label(w: &WorkspaceMemory) -> Value {
|
||||
match w {
|
||||
WorkspaceMemory::Structured { workspace_root, .. } => json!({
|
||||
"mode": "structured",
|
||||
"root": workspace_root.display().to_string(),
|
||||
}),
|
||||
WorkspaceMemory::Lite {
|
||||
workspace_root,
|
||||
file,
|
||||
} => json!({
|
||||
"mode": "lite",
|
||||
"root": workspace_root.display().to_string(),
|
||||
"file": file.display().to_string(),
|
||||
}),
|
||||
}
|
||||
json!({
|
||||
"root": w.workspace_root.display().to_string(),
|
||||
"dir": w.dir.display().to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
fn lint_memory(store: &MemoryStore) -> Result<Value> {
|
||||
let files = store.list_files()?;
|
||||
let names: HashSet<&str> = files.iter().map(|f| f.frontmatter.name.as_str()).collect();
|
||||
let today = today_string();
|
||||
|
||||
let mut oversized = Vec::new();
|
||||
let mut broken_links = Vec::new();
|
||||
let mut stale = Vec::new();
|
||||
for f in &files {
|
||||
if f.char_len() > PER_FILE_SOFT_CAP {
|
||||
oversized.push(json!({"name": &f.frontmatter.name, "chars": f.char_len()}));
|
||||
@@ -362,16 +666,54 @@ fn lint_memory(store: &MemoryStore) -> Result<Value> {
|
||||
broken_links.push(json!({"from": &f.frontmatter.name, "to": link}));
|
||||
}
|
||||
}
|
||||
if let Some(target) = &f.frontmatter.superseded_by {
|
||||
stale.push(json!({
|
||||
"name": &f.frontmatter.name,
|
||||
"reason": "superseded",
|
||||
"superseded_by": target,
|
||||
"target_exists": names.contains(target.as_str()),
|
||||
}));
|
||||
}
|
||||
|
||||
if let Some(expires) = &f.frontmatter.expires
|
||||
&& expires.as_str() < today.as_str()
|
||||
{
|
||||
stale.push(json!({
|
||||
"name": &f.frontmatter.name,
|
||||
"reason": "expired",
|
||||
"expires": expires,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
let index_content = store
|
||||
.load_global_index()?
|
||||
.or_else(|| store.load_workspace_index().ok().flatten())
|
||||
let global_index = store.load_global_index()?.unwrap_or_default();
|
||||
let workspace_index = store
|
||||
.load_workspace_index()
|
||||
.ok()
|
||||
.flatten()
|
||||
.unwrap_or_default();
|
||||
let mut orphans = Vec::new();
|
||||
let mut description_drift = Vec::new();
|
||||
|
||||
for f in &files {
|
||||
if !index_content.contains(&f.frontmatter.name) {
|
||||
let index = if f.path.starts_with(&store.global_dir) {
|
||||
&global_index
|
||||
} else {
|
||||
&workspace_index
|
||||
};
|
||||
|
||||
if !index_references(index, &f.frontmatter.name) {
|
||||
orphans.push(f.frontmatter.name.clone());
|
||||
} else if let (Some(index_desc), Some(file_desc)) = (
|
||||
index_description(index, &f.frontmatter.name),
|
||||
f.frontmatter.description.as_deref(),
|
||||
) && index_desc != file_desc
|
||||
{
|
||||
description_drift.push(json!({
|
||||
"name": &f.frontmatter.name,
|
||||
"index_description": index_desc,
|
||||
"file_description": file_desc,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,13 +722,26 @@ fn lint_memory(store: &MemoryStore) -> Result<Value> {
|
||||
"oversized": oversized,
|
||||
"broken_wikilinks": broken_links,
|
||||
"orphans": orphans,
|
||||
"stale": stale,
|
||||
"description_drift": description_drift,
|
||||
}))
|
||||
}
|
||||
|
||||
fn index_description(index: &str, name: &str) -> Option<String> {
|
||||
let marker = format!("[[{name}]]");
|
||||
index.lines().find_map(|line| {
|
||||
let pos = line.find(&marker)?;
|
||||
let rest = line[pos + marker.len()..].trim_start();
|
||||
let desc = rest.strip_prefix(':')?.trim();
|
||||
(!desc.is_empty()).then(|| desc.to_string())
|
||||
})
|
||||
}
|
||||
|
||||
fn extract_wikilinks(body: &str) -> Vec<String> {
|
||||
let mut out = Vec::new();
|
||||
let bytes = body.as_bytes();
|
||||
let mut i = 0;
|
||||
|
||||
while i + 1 < bytes.len() {
|
||||
if bytes[i] == b'['
|
||||
&& bytes[i + 1] == b'['
|
||||
@@ -498,19 +853,24 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn workspace_write_dir_promotes_lite_to_structured_subdir() {
|
||||
let root = temp_root("ws_lite_promote");
|
||||
fn workspace_write_dir_treats_root_instructions_file_as_no_memory() {
|
||||
let root = temp_root("ws_instructions_only");
|
||||
let workspace = root.join("ws");
|
||||
fs::create_dir_all(&workspace).unwrap();
|
||||
fs::write(workspace.join("COYOTE.md"), "lite").unwrap();
|
||||
fs::create_dir_all(workspace.join(".git")).unwrap();
|
||||
fs::write(workspace.join("COYOTE.md"), "instructions, not memory").unwrap();
|
||||
|
||||
let store = MemoryStore {
|
||||
global_dir: root.join("g"),
|
||||
workspace: discover_workspace_memory(&workspace),
|
||||
};
|
||||
assert!(store.workspace.is_none(), "COYOTE.md must not be memory");
|
||||
|
||||
let dir = workspace_write_dir(&store, &workspace).unwrap();
|
||||
assert_eq!(dir, workspace.join(".coyote").join("memory"));
|
||||
assert!(
|
||||
dir.join("MEMORY.md").exists(),
|
||||
"bootstrap must create index"
|
||||
);
|
||||
|
||||
let _ = fs::remove_dir_all(&root);
|
||||
}
|
||||
@@ -676,4 +1036,305 @@ mod tests {
|
||||
|
||||
let _ = fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn line_references_requires_exact_token_match() {
|
||||
assert!(line_references("- [[auth]]: description", "auth"));
|
||||
assert!(line_references("- auth.md is here", "auth"));
|
||||
assert!(line_references("- referenced", "referenced"));
|
||||
assert!(line_references("see auth.", "auth"));
|
||||
assert!(!line_references("- [[auth-flow]]: description", "auth"));
|
||||
assert!(!line_references("- oauth.md legacy", "auth"));
|
||||
assert!(!line_references("- preauth notes", "auth"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_index_entry_drops_only_matching_lines() {
|
||||
let root = temp_root("index_remove");
|
||||
let index = root.join("MEMORY.md");
|
||||
fs::write(
|
||||
&index,
|
||||
"# Memory Index\n\n- [[keep]]: stays\n- [[gone]]: removed\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert!(remove_index_entry(&index, "gone").unwrap());
|
||||
let content = fs::read_to_string(&index).unwrap();
|
||||
assert!(content.contains("[[keep]]"));
|
||||
assert!(!content.contains("[[gone]]"));
|
||||
|
||||
assert!(!remove_index_entry(&index, "gone").unwrap());
|
||||
|
||||
let _ = fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lint_checks_orphans_against_own_scope_index() {
|
||||
let root = temp_root("lint_scopes");
|
||||
let global = root.join("global");
|
||||
fs::create_dir_all(&global).unwrap();
|
||||
fs::write(global.join("MEMORY.md"), "- [[global-note]]: g\n").unwrap();
|
||||
fs::write(
|
||||
global.join("global-note.md"),
|
||||
"---\nname: global-note\n---\ng\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let workspace = root.join("ws");
|
||||
let structured = workspace.join(".coyote").join("memory");
|
||||
fs::create_dir_all(&structured).unwrap();
|
||||
fs::write(structured.join("MEMORY.md"), "- [[ws-note]]: w\n").unwrap();
|
||||
fs::write(
|
||||
structured.join("ws-note.md"),
|
||||
"---\nname: ws-note\n---\nw\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let store = MemoryStore {
|
||||
global_dir: global,
|
||||
workspace: discover_workspace_memory(&workspace),
|
||||
};
|
||||
|
||||
let report = lint_memory(&store).unwrap();
|
||||
assert!(
|
||||
report["orphans"].as_array().unwrap().is_empty(),
|
||||
"expected no orphans, got: {report}"
|
||||
);
|
||||
|
||||
let _ = fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lint_flags_stale_and_description_drift() {
|
||||
let root = temp_root("lint_stale");
|
||||
let workspace = root.join("ws");
|
||||
let structured = workspace.join(".coyote").join("memory");
|
||||
fs::create_dir_all(&structured).unwrap();
|
||||
fs::write(
|
||||
structured.join("MEMORY.md"),
|
||||
"- [[old-plan]]: old\n- [[bygone]]: e\n- [[drifted]]: index says this\n",
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(
|
||||
structured.join("old-plan.md"),
|
||||
"---\nname: old-plan\nsuperseded_by: new-plan\n---\nx\n",
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(
|
||||
structured.join("bygone.md"),
|
||||
"---\nname: bygone\nexpires: 2000-01-01\n---\nx\n",
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(
|
||||
structured.join("drifted.md"),
|
||||
"---\nname: drifted\ndescription: file says that\n---\nx\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let store = MemoryStore {
|
||||
global_dir: root.join("nonexistent_global"),
|
||||
workspace: discover_workspace_memory(&workspace),
|
||||
};
|
||||
|
||||
let report = lint_memory(&store).unwrap();
|
||||
let stale = report["stale"].as_array().unwrap();
|
||||
let reasons: Vec<(&str, &str)> = stale
|
||||
.iter()
|
||||
.map(|v| (v["name"].as_str().unwrap(), v["reason"].as_str().unwrap()))
|
||||
.collect();
|
||||
assert!(reasons.contains(&("old-plan", "superseded")));
|
||||
assert!(reasons.contains(&("bygone", "expired")));
|
||||
let superseded = stale.iter().find(|v| v["name"] == "old-plan").unwrap();
|
||||
assert_eq!(superseded["target_exists"], false);
|
||||
|
||||
let drift = report["description_drift"].as_array().unwrap();
|
||||
assert_eq!(drift.len(), 1);
|
||||
assert_eq!(drift[0]["name"], "drifted");
|
||||
|
||||
let _ = fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn delete_memory_removes_file_index_entry_and_reports_dangling() {
|
||||
let root = temp_root("delete");
|
||||
let workspace = root.join("ws");
|
||||
let structured = workspace.join(".coyote").join("memory");
|
||||
fs::create_dir_all(&structured).unwrap();
|
||||
fs::write(
|
||||
structured.join("MEMORY.md"),
|
||||
"# Memory Index\n\n- [[doomed]]: bye\n- [[linker]]: links\n",
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(
|
||||
structured.join("doomed.md"),
|
||||
"---\nname: doomed\n---\nbye\n",
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(
|
||||
structured.join("linker.md"),
|
||||
"---\nname: linker\n---\nsee [[doomed]]\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let store = MemoryStore {
|
||||
global_dir: root.join("g"),
|
||||
workspace: discover_workspace_memory(&workspace),
|
||||
};
|
||||
|
||||
let args = json!({"name": "doomed", "scope": "workspace"});
|
||||
let result = delete_memory(&store, &workspace, &args).unwrap();
|
||||
|
||||
assert_eq!(result["status"], "ok");
|
||||
assert_eq!(result["index_updated"], true);
|
||||
assert!(!structured.join("doomed.md").exists());
|
||||
let index = fs::read_to_string(structured.join("MEMORY.md")).unwrap();
|
||||
assert!(!index.contains("doomed"));
|
||||
assert!(index.contains("[[linker]]"));
|
||||
assert_eq!(
|
||||
result["dangling_references"].as_array().unwrap(),
|
||||
&vec![json!("linker")]
|
||||
);
|
||||
|
||||
let _ = fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rename_memory_moves_file_and_rewrites_references() {
|
||||
let root = temp_root("rename");
|
||||
let workspace = root.join("ws");
|
||||
let structured = workspace.join(".coyote").join("memory");
|
||||
fs::create_dir_all(&structured).unwrap();
|
||||
fs::write(
|
||||
structured.join("MEMORY.md"),
|
||||
"# Memory Index\n\n- [[old-name]]: the plan\n- [[linker]]: links\n",
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(
|
||||
structured.join("old-name.md"),
|
||||
"---\nname: old-name\ndescription: the plan\n---\nself link [[old-name]]\n",
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(
|
||||
structured.join("linker.md"),
|
||||
"---\nname: linker\n---\nsee [[old-name]] and [[old-name-extended]]\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let store = MemoryStore {
|
||||
global_dir: root.join("g"),
|
||||
workspace: discover_workspace_memory(&workspace),
|
||||
};
|
||||
|
||||
let args = json!({"name": "old-name", "new_name": "new-name", "scope": "workspace"});
|
||||
let result = rename_memory(&store, &workspace, &args).unwrap();
|
||||
|
||||
assert_eq!(result["status"], "ok");
|
||||
assert!(!structured.join("old-name.md").exists());
|
||||
let renamed = MemoryFile::load(&structured.join("new-name.md")).unwrap();
|
||||
assert_eq!(renamed.frontmatter.name, "new-name");
|
||||
assert!(renamed.body.contains("[[new-name]]"));
|
||||
|
||||
let linker = fs::read_to_string(structured.join("linker.md")).unwrap();
|
||||
assert!(linker.contains("[[new-name]]"));
|
||||
assert!(
|
||||
linker.contains("[[old-name-extended]]"),
|
||||
"unrelated links must be untouched: {linker}"
|
||||
);
|
||||
|
||||
let index = fs::read_to_string(structured.join("MEMORY.md")).unwrap();
|
||||
assert!(index.contains("- [[new-name]]: the plan"));
|
||||
assert!(!index.contains("[[old-name]]"));
|
||||
assert!(index.contains("[[linker]]"));
|
||||
|
||||
assert_eq!(
|
||||
result["rewritten_references"].as_array().unwrap(),
|
||||
&vec![json!("linker")]
|
||||
);
|
||||
|
||||
let _ = fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rename_memory_rejects_collisions_and_bad_slugs() {
|
||||
let root = temp_root("rename_guard");
|
||||
let workspace = root.join("ws");
|
||||
let structured = workspace.join(".coyote").join("memory");
|
||||
fs::create_dir_all(&structured).unwrap();
|
||||
fs::write(structured.join("MEMORY.md"), "- [[a]]: a\n- [[b]]: b\n").unwrap();
|
||||
fs::write(structured.join("a.md"), "---\nname: a\n---\nx\n").unwrap();
|
||||
fs::write(structured.join("b.md"), "---\nname: b\n---\nx\n").unwrap();
|
||||
|
||||
let store = MemoryStore {
|
||||
global_dir: root.join("g"),
|
||||
workspace: discover_workspace_memory(&workspace),
|
||||
};
|
||||
|
||||
let collision = json!({"name": "a", "new_name": "b", "scope": "workspace"});
|
||||
let err = rename_memory(&store, &workspace, &collision).unwrap_err();
|
||||
assert!(err.to_string().contains("already exists"));
|
||||
|
||||
let bad_slug = json!({"name": "a", "new_name": "bad name!", "scope": "workspace"});
|
||||
let err = rename_memory(&store, &workspace, &bad_slug).unwrap_err();
|
||||
assert!(err.to_string().contains("invalid new_name"));
|
||||
|
||||
let _ = fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn write_memory_stamps_timestamps_and_reports_replacement() {
|
||||
let root = temp_root("write_stamps");
|
||||
let workspace = root.join("ws");
|
||||
let structured = workspace.join(".coyote").join("memory");
|
||||
fs::create_dir_all(&structured).unwrap();
|
||||
fs::write(structured.join("MEMORY.md"), "# Memory Index\n").unwrap();
|
||||
|
||||
let store = MemoryStore {
|
||||
global_dir: root.join("g"),
|
||||
workspace: discover_workspace_memory(&workspace),
|
||||
};
|
||||
|
||||
let first = json!({
|
||||
"name": "fact",
|
||||
"description": "first version",
|
||||
"content": "body v1",
|
||||
"scope": "workspace",
|
||||
"expires": "2099-01-01",
|
||||
});
|
||||
let before = today_string();
|
||||
let result = write_memory(&store, &workspace, &first).unwrap();
|
||||
let after = today_string();
|
||||
assert_eq!(result["replaced"], false);
|
||||
assert_eq!(result["previous_description"], Value::Null);
|
||||
|
||||
let saved = MemoryFile::load(&structured.join("fact.md")).unwrap();
|
||||
let created = saved.frontmatter.created.clone().expect("created stamped");
|
||||
assert!(
|
||||
created == before || created == after,
|
||||
"created '{created}' should be stamped with today's date"
|
||||
);
|
||||
assert_eq!(saved.frontmatter.updated, Some(created.clone()));
|
||||
assert_eq!(saved.frontmatter.expires.as_deref(), Some("2099-01-01"));
|
||||
assert_eq!(saved.frontmatter.superseded_by, None);
|
||||
|
||||
let second = json!({
|
||||
"name": "fact",
|
||||
"description": "second version",
|
||||
"content": "body v2",
|
||||
"scope": "workspace",
|
||||
});
|
||||
let result = write_memory(&store, &workspace, &second).unwrap();
|
||||
assert_eq!(result["replaced"], true);
|
||||
assert_eq!(result["previous_description"], "first version");
|
||||
|
||||
let saved = MemoryFile::load(&structured.join("fact.md")).unwrap();
|
||||
assert_eq!(
|
||||
saved.frontmatter.created,
|
||||
Some(created),
|
||||
"creation date must be preserved across overwrites"
|
||||
);
|
||||
assert!(saved.frontmatter.updated.is_some());
|
||||
assert_eq!(saved.frontmatter.expires, None);
|
||||
|
||||
let _ = fs::remove_dir_all(&root);
|
||||
}
|
||||
}
|
||||
|
||||
+136
-24
@@ -5,6 +5,7 @@ pub(crate) mod todo;
|
||||
pub(crate) mod user_interaction;
|
||||
|
||||
use crate::{
|
||||
client::ThinkingBlock,
|
||||
config::{Agent, RequestContext},
|
||||
graph,
|
||||
utils::*,
|
||||
@@ -14,7 +15,7 @@ use crate::config::ensure_parent_exists;
|
||||
use crate::config::paths;
|
||||
use crate::mcp::{
|
||||
MCP_DESCRIBE_META_FUNCTION_NAME_PREFIX, MCP_INVOKE_META_FUNCTION_NAME_PREFIX,
|
||||
MCP_SEARCH_META_FUNCTION_NAME_PREFIX,
|
||||
MCP_SEARCH_META_FUNCTION_NAME_PREFIX, McpServersConfig,
|
||||
};
|
||||
use crate::parsers::{bash, python, typescript};
|
||||
use anyhow::{Context, Result, anyhow, bail};
|
||||
@@ -144,29 +145,19 @@ pub async fn eval_tool_calls(
|
||||
if calls.is_empty() {
|
||||
bail!("The request was aborted because an infinite loop of function calls was detected.")
|
||||
}
|
||||
let mut is_all_null = true;
|
||||
for call in calls {
|
||||
if let Some(msg) = ctx.tool_scope.tool_tracker.check_loop(&call.clone()) {
|
||||
let dup_msg = format!("{{\"tool_call_loop_alert\":{}}}", &msg.trim());
|
||||
let dup_msg = format!("{{\"tool_call_loop_alert\":{}}}", msg.trim());
|
||||
println!(
|
||||
"{}",
|
||||
warning_text(format!("{}: ⚠️ Tool-call loop detected! ⚠️", &call.name).as_str())
|
||||
warning_text(format!("{}: ⚠️ Tool-call loop detected! ⚠️", call.name).as_str())
|
||||
);
|
||||
let val = json!(dup_msg);
|
||||
output.push(ToolResult::new(call, val));
|
||||
is_all_null = false;
|
||||
continue;
|
||||
}
|
||||
let mut result = call.eval(ctx).await?;
|
||||
if result.is_null() {
|
||||
result = json!("DONE");
|
||||
} else {
|
||||
is_all_null = false;
|
||||
}
|
||||
output.push(ToolResult::new(call, result));
|
||||
}
|
||||
if is_all_null {
|
||||
output = vec![];
|
||||
let result = call.eval(ctx).await?;
|
||||
output.push(ToolResult::new(call, normalize_tool_result(result)));
|
||||
}
|
||||
|
||||
if !output.is_empty() {
|
||||
@@ -196,15 +187,37 @@ pub async fn eval_tool_calls(
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
/// Tools that succeed silently (e.g. `mkdir -p` via execute_command) evaluate to
|
||||
/// `Null`. Substitute a concrete `"DONE"` marker so every call produces a
|
||||
/// `ToolResult`: agentic loops (graph llm nodes, spawned agents, the REPL) treat
|
||||
/// an empty `tool_results` as "the LLM concluded", so dropping silent results
|
||||
/// would prematurely terminate a turn that called only silent tools.
|
||||
fn normalize_tool_result(result: Value) -> Value {
|
||||
if result.is_null() {
|
||||
json!("DONE")
|
||||
} else {
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct ToolResult {
|
||||
pub call: ToolCall,
|
||||
pub output: Value,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub text: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub thinking: Vec<ThinkingBlock>,
|
||||
}
|
||||
|
||||
impl ToolResult {
|
||||
pub fn new(call: ToolCall, output: Value) -> Self {
|
||||
Self { call, output }
|
||||
Self {
|
||||
call,
|
||||
output,
|
||||
text: None,
|
||||
thinking: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,14 +279,42 @@ impl Functions {
|
||||
let file_path = paths::mcp_config_file();
|
||||
let embedded = FunctionAssets::get("mcp.json")
|
||||
.ok_or_else(|| anyhow!("Failed to load embedded mcp.json"))?;
|
||||
let content = unsafe { std::str::from_utf8_unchecked(&embedded.data) };
|
||||
let bundled_content = unsafe { std::str::from_utf8_unchecked(&embedded.data) };
|
||||
let bundled: McpServersConfig =
|
||||
serde_json::from_str(bundled_content).context("failed to parse embedded mcp.json")?;
|
||||
|
||||
ensure_parent_exists(&file_path)?;
|
||||
|
||||
info!("Reinstalling MCP config file: {}", file_path.display());
|
||||
let mut merged = if file_path.exists() {
|
||||
let existing =
|
||||
fs::read_to_string(&file_path).context("failed to read existing mcp.json")?;
|
||||
serde_json::from_str::<McpServersConfig>(&existing)
|
||||
.context("failed to parse existing mcp.json")?
|
||||
} else {
|
||||
McpServersConfig {
|
||||
mcp_servers: IndexMap::new(),
|
||||
}
|
||||
};
|
||||
|
||||
let mut config_file = File::create(&file_path)?;
|
||||
config_file.write_all(content.as_bytes())?;
|
||||
let mut added = Vec::new();
|
||||
for (name, server) in bundled.mcp_servers {
|
||||
if !merged.mcp_servers.contains_key(&name) {
|
||||
merged.mcp_servers.insert(name.clone(), server);
|
||||
added.push(name);
|
||||
}
|
||||
}
|
||||
|
||||
info!("Merging bundled MCP config into: {}", file_path.display());
|
||||
|
||||
let serialized =
|
||||
serde_json::to_string_pretty(&merged).context("failed to serialize merged mcp.json")?;
|
||||
let tmp = file_path.with_extension("json.tmp");
|
||||
fs::write(&tmp, &serialized).context("failed to write temporary mcp.json")?;
|
||||
fs::rename(&tmp, &file_path).context("failed to finalize mcp.json")?;
|
||||
|
||||
if !added.is_empty() {
|
||||
println!(" + new MCP servers: {}", added.join(", "));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -702,7 +743,7 @@ impl Functions {
|
||||
let root_dir = paths::functions_dir();
|
||||
let tool_path = format!(
|
||||
"{}/{binary_name}",
|
||||
&paths::global_tools_dir().to_string_lossy()
|
||||
paths::global_tools_dir().to_string_lossy()
|
||||
);
|
||||
content_template
|
||||
.replace("{function_name}", binary_name)
|
||||
@@ -713,7 +754,7 @@ impl Functions {
|
||||
let root_dir = paths::agent_data_dir(agent_name);
|
||||
let tool_path = format!(
|
||||
"{}/{binary_name}",
|
||||
&paths::global_tools_dir().to_string_lossy()
|
||||
paths::global_tools_dir().to_string_lossy()
|
||||
);
|
||||
content_template
|
||||
.replace("{function_name}", binary_name)
|
||||
@@ -842,7 +883,7 @@ impl Functions {
|
||||
let root_dir = paths::functions_dir();
|
||||
let tool_path = format!(
|
||||
"{}/{binary_name}",
|
||||
&paths::global_tools_dir().to_string_lossy()
|
||||
paths::global_tools_dir().to_string_lossy()
|
||||
);
|
||||
content_template
|
||||
.replace("{function_name}", binary_name)
|
||||
@@ -853,7 +894,7 @@ impl Functions {
|
||||
let root_dir = paths::agent_data_dir(agent_name);
|
||||
let tool_path = format!(
|
||||
"{}/{binary_name}",
|
||||
&paths::global_tools_dir().to_string_lossy()
|
||||
paths::global_tools_dir().to_string_lossy()
|
||||
);
|
||||
content_template
|
||||
.replace("{function_name}", binary_name)
|
||||
@@ -1499,6 +1540,21 @@ mod tests {
|
||||
ToolCall::new(name.to_string(), args, Some("id1".to_string()))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normalize_tool_result_substitutes_done_for_null() {
|
||||
assert_eq!(normalize_tool_result(Value::Null), json!("DONE"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normalize_tool_result_preserves_non_null_values() {
|
||||
assert_eq!(
|
||||
normalize_tool_result(json!({"output": "hi"})),
|
||||
json!({"output": "hi"})
|
||||
);
|
||||
assert_eq!(normalize_tool_result(json!("")), json!(""));
|
||||
assert_eq!(normalize_tool_result(json!(false)), json!(false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn toolcall_new_sets_fields() {
|
||||
let tc = ToolCall::new("my_tool".into(), json!({"x": 1}), Some("call-1".into()));
|
||||
@@ -1691,6 +1747,33 @@ mod tests {
|
||||
assert!(f.declarations().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bundled_bash_tools_generate_declarations() {
|
||||
let tools_dir =
|
||||
std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/functions/tools");
|
||||
let mut checked = Vec::new();
|
||||
for entry in std::fs::read_dir(&tools_dir).unwrap() {
|
||||
let path = entry.unwrap().path();
|
||||
if path.extension().and_then(OsStr::to_str) != Some("sh") {
|
||||
continue;
|
||||
}
|
||||
let name = path.file_stem().unwrap().to_string_lossy().to_string();
|
||||
let declarations = Functions::generate_declarations(&path)
|
||||
.unwrap_or_else(|e| panic!("bundled tool '{name}' failed to parse: {e}"));
|
||||
assert!(
|
||||
!declarations.is_empty(),
|
||||
"bundled tool '{name}' produced no function declaration"
|
||||
);
|
||||
checked.push(name);
|
||||
}
|
||||
for expected in ["fs_grep", "ast_grep", "execute_command"] {
|
||||
assert!(
|
||||
checked.iter().any(|n| n == expected),
|
||||
"expected bundled tool '{expected}' to be checked; found {checked:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn functions_append_todo_adds_declarations() {
|
||||
let mut f = Functions::default();
|
||||
@@ -1835,4 +1918,33 @@ mod tests {
|
||||
assert_eq!(result.call.name, "my_tool");
|
||||
assert_eq!(result.output, json!({"result": "ok"}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn thinking_block_matches_anthropic_wire_format() {
|
||||
let block = ThinkingBlock::Thinking {
|
||||
thinking: "chain of thought".to_string(),
|
||||
signature: "sig123".to_string(),
|
||||
};
|
||||
assert_eq!(
|
||||
serde_json::to_value(&block).unwrap(),
|
||||
json!({"type": "thinking", "thinking": "chain of thought", "signature": "sig123"})
|
||||
);
|
||||
|
||||
let redacted = ThinkingBlock::RedactedThinking {
|
||||
data: "opaque".to_string(),
|
||||
};
|
||||
assert_eq!(
|
||||
serde_json::to_value(&redacted).unwrap(),
|
||||
json!({"type": "redacted_thinking", "data": "opaque"})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_result_deserializes_without_text_and_thinking() {
|
||||
let yaml = "call:\n name: my_tool\n arguments: {}\noutput: ok\n";
|
||||
let result: ToolResult = serde_yaml::from_str(yaml).unwrap();
|
||||
assert_eq!(result.call.name, "my_tool");
|
||||
assert!(result.text.is_none());
|
||||
assert!(result.thinking.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,6 +329,9 @@ fn build_inline_role(
|
||||
if let Some(p) = node.top_p {
|
||||
role.set_top_p(Some(p));
|
||||
}
|
||||
if let Some(v) = &node.reasoning_effort {
|
||||
role.set_reasoning_effort(Some(v.clone()));
|
||||
}
|
||||
|
||||
if node.tools.as_deref().unwrap_or_default().is_empty() {
|
||||
role.set_enabled_tools(Some(Vec::new()));
|
||||
@@ -499,6 +502,7 @@ mod tests {
|
||||
model: None,
|
||||
temperature: None,
|
||||
top_p: None,
|
||||
reasoning_effort: None,
|
||||
fallback: None,
|
||||
max_attempts: 1,
|
||||
max_iterations: 10,
|
||||
|
||||
+25
-4
@@ -33,7 +33,7 @@ async fn extract_via_extractor(
|
||||
parent_ctx: &mut RequestContext,
|
||||
is_repair: bool,
|
||||
) -> Result<Value> {
|
||||
let role = build_extractor_role()?;
|
||||
let role = build_extractor_role(parent_ctx);
|
||||
let prompt = build_extractor_prompt(raw, schema, is_repair);
|
||||
|
||||
let saved_role = parent_ctx.role.clone();
|
||||
@@ -53,11 +53,12 @@ async fn extract_via_extractor(
|
||||
}
|
||||
}
|
||||
|
||||
fn build_extractor_role() -> Result<Role> {
|
||||
fn build_extractor_role(ctx: &RequestContext) -> Role {
|
||||
let mut role = Role::new(EXTRACTOR_ROLE_NAME, EXTRACTOR_ROLE_PROMPT);
|
||||
role.set_model(ctx.current_model().clone());
|
||||
role.set_enabled_tools(Some(Vec::new()));
|
||||
role.set_enabled_mcp_servers(Some(Vec::new()));
|
||||
Ok(role)
|
||||
role
|
||||
}
|
||||
|
||||
fn build_extractor_prompt(raw: &str, schema: &Value, is_repair: bool) -> String {
|
||||
@@ -107,8 +108,14 @@ fn strip_code_fences(s: &str) -> &str {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::client::Model;
|
||||
use crate::config::{AppState, WorkingMode};
|
||||
use serde_json::json;
|
||||
|
||||
fn make_ctx() -> RequestContext {
|
||||
RequestContext::new(Arc::new(AppState::test_default()), WorkingMode::Cmd)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn try_parse_json_accepts_plain_object() {
|
||||
let v = try_parse_json(r#"{"a": 1}"#).unwrap();
|
||||
@@ -181,9 +188,23 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn build_extractor_role_disables_tools_and_mcp() {
|
||||
let role = build_extractor_role().expect("builtin role must exist");
|
||||
let ctx = make_ctx();
|
||||
|
||||
let role = build_extractor_role(&ctx);
|
||||
|
||||
assert_eq!(role.enabled_tools().as_deref(), Some([].as_slice()));
|
||||
assert_eq!(role.enabled_mcp_servers().as_deref(), Some([].as_slice()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_extractor_role_uses_parent_context_model() {
|
||||
let mut ctx = make_ctx();
|
||||
let mut parent_role = Role::new("parent", "parent prompt");
|
||||
parent_role.set_model(Model::new("client-x", "model-y"));
|
||||
ctx.role = Some(parent_role);
|
||||
|
||||
let role = build_extractor_role(&ctx);
|
||||
|
||||
assert_eq!(role.model().id(), "client-x:model-y");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@ pub struct Graph {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub top_p: Option<f64>,
|
||||
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub reasoning_effort: Option<String>,
|
||||
|
||||
#[serde(default)]
|
||||
pub global_tools: Vec<String>,
|
||||
|
||||
@@ -288,6 +291,9 @@ pub struct LlmNode {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub top_p: Option<f64>,
|
||||
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub reasoning_effort: Option<String>,
|
||||
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub fallback: Option<String>,
|
||||
|
||||
@@ -352,6 +358,15 @@ pub struct RagNode {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub batch_size: Option<usize>,
|
||||
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub extractor_model: Option<String>,
|
||||
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub extractor_prompt: Option<String>,
|
||||
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub graph_hops: Option<usize>,
|
||||
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub state_updates: Option<HashMap<String, String>>,
|
||||
|
||||
|
||||
@@ -946,6 +946,7 @@ mod tests {
|
||||
model: None,
|
||||
temperature: None,
|
||||
top_p: None,
|
||||
reasoning_effort: None,
|
||||
global_tools: Vec::new(),
|
||||
mcp_servers: Vec::new(),
|
||||
skills_enabled: None,
|
||||
@@ -1027,6 +1028,9 @@ mod tests {
|
||||
chunk_overlap: None,
|
||||
reranker_model: None,
|
||||
batch_size: None,
|
||||
extractor_model: None,
|
||||
extractor_prompt: None,
|
||||
graph_hops: None,
|
||||
state_updates,
|
||||
timeout: None,
|
||||
}),
|
||||
@@ -1045,6 +1049,7 @@ mod tests {
|
||||
model: None,
|
||||
temperature: None,
|
||||
top_p: None,
|
||||
reasoning_effort: None,
|
||||
fallback: fallback.map(String::from),
|
||||
max_attempts: 1,
|
||||
max_iterations: 10,
|
||||
|
||||
+132
-13
@@ -21,25 +21,30 @@ use crate::cli::Cli;
|
||||
use crate::client::{
|
||||
ModelType, call_chat_completions, call_chat_completions_streaming, list_models, oauth,
|
||||
};
|
||||
use crate::config::paths;
|
||||
use crate::config::instructions::WORKSPACE_INSTRUCTIONS_FILE_NAME;
|
||||
use crate::config::{
|
||||
Agent, AppConfig, AppState, CODE_ROLE, Config, EXPLAIN_SHELL_ROLE, Input, MemoryScope,
|
||||
RequestContext, SHELL_ROLE, TEMP_SESSION_NAME, WorkingMode, ensure_parent_exists,
|
||||
install_builtins, list_agents, load_env_file, macro_execute, sync_models,
|
||||
};
|
||||
use crate::config::{memory, paths};
|
||||
use crate::function::supervisor::{GuardrailAction, check_pending_agents_guardrail};
|
||||
use crate::mcp::McpServersConfig;
|
||||
use crate::render::{prompt_theme, render_error};
|
||||
use crate::repl::Repl;
|
||||
use crate::utils::*;
|
||||
use crate::vault::Vault;
|
||||
use anyhow::{Result, anyhow, bail};
|
||||
use crate::vault::{Vault, interpolate_secrets};
|
||||
use anyhow::{Context, Result, anyhow, bail};
|
||||
use clap::{CommandFactory, Parser};
|
||||
use clap_complete::CompleteEnv;
|
||||
use client::ClientConfig;
|
||||
use inquire::{Select, Text, set_global_render_config};
|
||||
use log::{LevelFilter, warn};
|
||||
use log4rs::append::console::ConsoleAppender;
|
||||
use log4rs::append::file::FileAppender;
|
||||
use log4rs::append::rolling_file::RollingFileAppender;
|
||||
use log4rs::append::rolling_file::policy::compound::CompoundPolicy;
|
||||
use log4rs::append::rolling_file::policy::compound::roll::fixed_window::FixedWindowRoller;
|
||||
use log4rs::append::rolling_file::policy::compound::trigger::size::SizeTrigger;
|
||||
use log4rs::config::{Appender, Logger, Root};
|
||||
use log4rs::encode::pattern::PatternEncoder;
|
||||
use oauth::OAuthProvider;
|
||||
@@ -52,6 +57,12 @@ async fn main() -> Result<()> {
|
||||
CompleteEnv::with_factory(Cli::command).complete();
|
||||
let cli = Cli::parse();
|
||||
|
||||
if cli.dangerously_skip_permissions {
|
||||
unsafe {
|
||||
env::set_var("AUTO_CONFIRM", "true");
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(shell) = cli.completions {
|
||||
let mut cmd = Cli::command();
|
||||
shell.generate_completions(&mut cmd);
|
||||
@@ -117,6 +128,56 @@ async fn main() -> Result<()> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(server_name) = &cli.auth_mcp {
|
||||
let cfg = Config::load_with_interpolation(true).await?;
|
||||
let app_config = AppConfig::from_config(cfg)?;
|
||||
let vault = Vault::init(&app_config)?;
|
||||
let mcp_path = paths::mcp_config_file();
|
||||
if !mcp_path.exists() {
|
||||
bail!(
|
||||
"No MCP configuration file found at '{}'",
|
||||
mcp_path.display()
|
||||
);
|
||||
}
|
||||
|
||||
let raw = tokio::fs::read_to_string(&mcp_path)
|
||||
.await
|
||||
.with_context(|| format!("Failed to read MCP config at '{}'", mcp_path.display()))?;
|
||||
|
||||
let (content, missing) = interpolate_secrets(&raw, &vault)?;
|
||||
if !missing.is_empty() {
|
||||
bail!(
|
||||
"MCP config references vault secrets that are missing: {:?}",
|
||||
missing
|
||||
);
|
||||
}
|
||||
|
||||
let mcp_config: McpServersConfig =
|
||||
serde_json::from_str(&content).context("Failed to parse MCP config file")?;
|
||||
let spec = mcp_config
|
||||
.mcp_servers
|
||||
.get(server_name.as_str())
|
||||
.ok_or_else(|| anyhow!("MCP server '{server_name}' not found in mcp.json"))?;
|
||||
if !spec.is_remote() {
|
||||
bail!(
|
||||
"MCP server '{server_name}' is a stdio server; OAuth is only supported for http/sse servers"
|
||||
);
|
||||
}
|
||||
|
||||
let url = spec.url.as_deref().expect("validated: remote spec has url");
|
||||
mcp::oauth::run_mcp_oauth_flow(
|
||||
server_name,
|
||||
url,
|
||||
spec.oauth.as_ref().and_then(|o| o.client_id.as_deref()),
|
||||
spec.oauth.as_ref().and_then(|o| o.callback_port),
|
||||
spec.oauth.as_ref().and_then(|o| o.redirect_host.as_deref()),
|
||||
)
|
||||
.await?;
|
||||
println!("Authentication saved. '{server_name}' is now available for use.");
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if vault_flags {
|
||||
let cfg = Config::load_with_interpolation(true).await?;
|
||||
let app_config = AppConfig::from_config(cfg)?;
|
||||
@@ -127,7 +188,11 @@ async fn main() -> Result<()> {
|
||||
let abort_signal = create_abort_signal();
|
||||
let start_mcp_servers = cli.agent.is_none() && cli.role.is_none();
|
||||
let cfg = Config::load_with_interpolation(info_flag).await?;
|
||||
let app_config: Arc<AppConfig> = Arc::new(AppConfig::from_config(cfg)?);
|
||||
let mut app_config = AppConfig::from_config(cfg)?;
|
||||
if cli.no_workspace_mcp {
|
||||
app_config.no_workspace_mcp = true;
|
||||
}
|
||||
let app_config: Arc<AppConfig> = Arc::new(app_config);
|
||||
let app_state: Arc<AppState> = Arc::new(
|
||||
AppState::init(
|
||||
app_config,
|
||||
@@ -137,7 +202,10 @@ async fn main() -> Result<()> {
|
||||
)
|
||||
.await?,
|
||||
);
|
||||
let ctx = RequestContext::bootstrap(app_state, working_mode, info_flag)?;
|
||||
let mut ctx = RequestContext::bootstrap(app_state, working_mode, info_flag)?;
|
||||
let app_config = Arc::clone(&ctx.app.config);
|
||||
ctx.bootstrap_tools(&app_config, start_mcp_servers, abort_signal.clone())
|
||||
.await?;
|
||||
|
||||
{
|
||||
let app = &*ctx.app.config;
|
||||
@@ -302,6 +370,15 @@ async fn run(
|
||||
if cli.no_memory {
|
||||
update_app_config(&mut ctx, |app| app.memory = Some(false));
|
||||
}
|
||||
if cli.no_workspace_instructions {
|
||||
update_app_config(&mut ctx, |app| app.workspace_instructions = Some(false));
|
||||
}
|
||||
if !cli.workspace_instructions_file.is_empty() {
|
||||
let files = cli.workspace_instructions_file.clone();
|
||||
update_app_config(&mut ctx, |app| {
|
||||
app.workspace_instructions_files = Some(files);
|
||||
});
|
||||
}
|
||||
if cli.empty_session {
|
||||
ctx.empty_session()?;
|
||||
}
|
||||
@@ -314,10 +391,14 @@ async fn run(
|
||||
paths::global_memory_index_path(),
|
||||
"# Global Memory\n\n<!-- Universal facts about you go here. The LLM uses this as always-on context. -->\n<!-- Drill files (when created) are listed below. -->\n",
|
||||
),
|
||||
MemoryScope::Workspace => (
|
||||
env::current_dir()?.join("COYOTE.md"),
|
||||
"# Workspace Memory\n\n<!-- Facts about this project go here. The LLM uses this as always-on context. -->\n",
|
||||
),
|
||||
MemoryScope::Workspace => {
|
||||
let cwd = env::current_dir()?;
|
||||
let root = memory::find_git_root(&cwd).unwrap_or(cwd);
|
||||
(
|
||||
paths::workspace_memory_index_path_for(&root),
|
||||
"# Workspace Memory Index\n\n<!-- Facts about this project go here. The LLM uses this as always-on context. -->\n<!-- Drill files (when created) are listed below. -->\n",
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
if path.exists() {
|
||||
@@ -330,9 +411,34 @@ async fn run(
|
||||
}
|
||||
|
||||
fs::write(&path, content)?;
|
||||
if scope == MemoryScope::Workspace
|
||||
&& let Some(git_root) = memory::find_git_root(&path)
|
||||
{
|
||||
memory::append_gitignore_entry(&git_root)?;
|
||||
}
|
||||
println!("✓ Created memory marker at '{}'.", path.display());
|
||||
return Ok(());
|
||||
}
|
||||
if cli.init_instructions {
|
||||
let path = env::current_dir()?.join(WORKSPACE_INSTRUCTIONS_FILE_NAME);
|
||||
|
||||
if path.exists() {
|
||||
eprintln!(
|
||||
"Workspace instructions already exist at '{}'.",
|
||||
path.display()
|
||||
);
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
fs::write(
|
||||
&path,
|
||||
"# Project Instructions\n\n<!-- Human-curated instructions for AI agents working in this repo. -->\n<!-- Coyote injects this file into the system prompt read-only, in full. -->\n",
|
||||
)?;
|
||||
println!("✓ Created workspace instructions at '{}'.", path.display());
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
if cli.info {
|
||||
let app: Arc<AppConfig> = Arc::clone(&ctx.app.config);
|
||||
let info = ctx.info(app.as_ref())?;
|
||||
@@ -496,7 +602,7 @@ async fn shell_execute(
|
||||
|
||||
match answer_char {
|
||||
'e' => {
|
||||
debug!("{} {:?}", shell.cmd, &[&shell.arg, &eval_str]);
|
||||
debug!("{} {:?}", shell.cmd, [&shell.arg, &eval_str]);
|
||||
let code = run_command(&shell.cmd, &[&shell.arg, &eval_str], None)?;
|
||||
if code == 0 && app.save_shell_history {
|
||||
let _ = append_to_shell_history(&shell.name, &eval_str, code);
|
||||
@@ -582,7 +688,20 @@ fn setup_logger() -> Result<Option<PathBuf>> {
|
||||
}
|
||||
Some(path) => {
|
||||
ensure_parent_exists(&path)?;
|
||||
let file_appender = FileAppender::builder().encoder(encoder.clone()).build(path);
|
||||
|
||||
let archive_pattern = path
|
||||
.with_extension("archived.{}.log")
|
||||
.to_string_lossy()
|
||||
.into_owned();
|
||||
let trigger = SizeTrigger::new(10 * 1024 * 1024);
|
||||
let roller = FixedWindowRoller::builder()
|
||||
.build(&archive_pattern, 5)
|
||||
.unwrap();
|
||||
let policy = CompoundPolicy::new(Box::new(trigger), Box::new(roller));
|
||||
|
||||
let file_appender = RollingFileAppender::builder()
|
||||
.encoder(encoder.clone())
|
||||
.build(path, Box::new(policy));
|
||||
|
||||
match file_appender {
|
||||
Ok(appender) => {
|
||||
@@ -605,7 +724,7 @@ fn setup_logger() -> Result<Option<PathBuf>> {
|
||||
fn init_file_logger(
|
||||
log_level: LevelFilter,
|
||||
log_filter: Option<String>,
|
||||
file_appender: FileAppender,
|
||||
file_appender: RollingFileAppender,
|
||||
) -> log4rs::Config {
|
||||
let root_log_level = if log_filter.is_some() {
|
||||
LevelFilter::Off
|
||||
|
||||
+240
-12
@@ -1,3 +1,4 @@
|
||||
pub(crate) mod oauth;
|
||||
mod sse_transport;
|
||||
|
||||
use crate::config::AppConfig;
|
||||
@@ -5,6 +6,7 @@ use crate::config::paths;
|
||||
use crate::utils::{AbortSignal, abortable_run_with_spinner};
|
||||
use crate::vault::Vault;
|
||||
use crate::vault::interpolate_secrets;
|
||||
use anyhow::Error;
|
||||
use anyhow::{Context, Result, anyhow};
|
||||
use futures_util::{StreamExt, TryStreamExt, stream};
|
||||
use http::{HeaderName, HeaderValue};
|
||||
@@ -56,6 +58,16 @@ pub(crate) struct McpServersConfig {
|
||||
pub mcp_servers: IndexMap<String, McpServer>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
||||
pub(crate) struct McpOAuthConfig {
|
||||
#[serde(rename = "clientId", skip_serializing_if = "Option::is_none")]
|
||||
pub client_id: Option<String>,
|
||||
#[serde(rename = "callbackPort", skip_serializing_if = "Option::is_none")]
|
||||
pub callback_port: Option<u16>,
|
||||
#[serde(rename = "redirectHost", skip_serializing_if = "Option::is_none")]
|
||||
pub redirect_host: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub(crate) struct McpServer {
|
||||
@@ -73,6 +85,8 @@ pub(crate) struct McpServer {
|
||||
pub url: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub headers: Option<IndexMap<String, String>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub oauth: Option<McpOAuthConfig>,
|
||||
}
|
||||
|
||||
impl McpServer {
|
||||
@@ -107,10 +121,10 @@ impl McpServer {
|
||||
"MCP server '{name}' is missing a \"command\" field (required for stdio transport)"
|
||||
));
|
||||
}
|
||||
if self.url.is_some() || self.headers.is_some() {
|
||||
if self.url.is_some() || self.headers.is_some() || self.oauth.is_some() {
|
||||
return Err(anyhow!(
|
||||
"MCP server '{name}' has type \"stdio\" but also specifies remote fields \
|
||||
(url/headers). Remove the remote fields or change the type to \"http\" or \"sse\"."
|
||||
(url/headers/oauth). Remove the remote fields or change the type to \"http\" or \"sse\"."
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -200,7 +214,52 @@ impl McpRegistry {
|
||||
spec.validate(name)?;
|
||||
}
|
||||
|
||||
registry.config = Some(mcp_servers_config);
|
||||
let mut merged = mcp_servers_config;
|
||||
if !app_config.no_workspace_mcp
|
||||
&& let Some(ws_path) = paths::workspace_mcp_config_file()
|
||||
{
|
||||
match tokio::fs::read_to_string(&ws_path).await {
|
||||
Ok(ws_content) if !ws_content.trim().is_empty() => {
|
||||
match interpolate_secrets(&ws_content, vault) {
|
||||
Ok((parsed, missing)) if missing.is_empty() => {
|
||||
match serde_json::from_str::<McpServersConfig>(&parsed) {
|
||||
Ok(ws_config) => {
|
||||
let mut loaded = Vec::new();
|
||||
for (name, spec) in ws_config.mcp_servers {
|
||||
match spec.validate(&name) {
|
||||
Ok(_) => {
|
||||
loaded.push(name.clone());
|
||||
merged.mcp_servers.insert(name, spec);
|
||||
}
|
||||
Err(e) => warn!(
|
||||
"Invalid workspace MCP server '{name}': {e}. Skipping."
|
||||
),
|
||||
}
|
||||
}
|
||||
if !loaded.is_empty() {
|
||||
eprintln!(
|
||||
"Loading workspace MCP servers: {}",
|
||||
loaded.join(", ")
|
||||
);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to parse workspace MCP config: {e}. Skipping.")
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok((_, missing)) => warn!(
|
||||
"Workspace MCP config references missing vault secrets: {missing:?}. Skipping."
|
||||
),
|
||||
Err(e) => {
|
||||
warn!("Failed to process workspace MCP config: {e}. Skipping.")
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
registry.config = Some(merged);
|
||||
|
||||
if start_mcp_servers && app_config.mcp_server_support {
|
||||
abortable_run_with_spinner(
|
||||
@@ -237,7 +296,7 @@ impl McpRegistry {
|
||||
|
||||
debug!("Starting selected MCP servers: {:?}", ids_to_start);
|
||||
|
||||
let results: Vec<(String, Arc<_>, ServerCatalog)> = stream::iter(
|
||||
let results: Vec<Option<(String, Arc<ConnectedServer>, ServerCatalog)>> = stream::iter(
|
||||
ids_to_start
|
||||
.into_iter()
|
||||
.map(|id| async { self.start_server(id).await }),
|
||||
@@ -246,7 +305,7 @@ impl McpRegistry {
|
||||
.try_collect()
|
||||
.await?;
|
||||
|
||||
for (id, server, catalog) in results {
|
||||
for (id, server, catalog) in results.into_iter().flatten() {
|
||||
self.servers.insert(id.clone(), server);
|
||||
self.catalogs.insert(id, catalog);
|
||||
}
|
||||
@@ -257,14 +316,30 @@ impl McpRegistry {
|
||||
async fn start_server(
|
||||
&self,
|
||||
id: String,
|
||||
) -> Result<(String, Arc<ConnectedServer>, ServerCatalog)> {
|
||||
) -> Result<Option<(String, Arc<ConnectedServer>, ServerCatalog)>> {
|
||||
let spec = self
|
||||
.config
|
||||
.as_ref()
|
||||
.and_then(|c| c.mcp_servers.get(&id))
|
||||
.with_context(|| format!("MCP server not found in config: {id}"))?;
|
||||
|
||||
let service = spawn_mcp_server(spec, self.log_path.as_deref()).await?;
|
||||
let bearer_token = if spec.is_remote() {
|
||||
oauth::load_valid_mcp_token(&id)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let service = match spawn_mcp_server(spec, self.log_path.as_deref(), bearer_token).await {
|
||||
Ok(s) => s,
|
||||
Err(e) if is_auth_required_error(&e) => {
|
||||
warn!(
|
||||
"MCP server '{id}' requires OAuth authentication. \
|
||||
Run `coyote --auth-mcp {id}` or `.mcp auth {id}` in the REPL to authenticate."
|
||||
);
|
||||
return Ok(None);
|
||||
}
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
|
||||
let tools = service.list_tools(None).await?;
|
||||
debug!("Available tools for MCP server {id}: {tools:?}");
|
||||
@@ -289,7 +364,7 @@ impl McpRegistry {
|
||||
|
||||
info!("Started MCP server: {id}");
|
||||
|
||||
Ok((id.to_string(), service, catalog))
|
||||
Ok(Some((id.to_string(), service, catalog)))
|
||||
}
|
||||
|
||||
fn resolve_server_ids(&self, enabled_mcp_servers: Option<Vec<String>>) -> Vec<String> {
|
||||
@@ -337,15 +412,18 @@ impl McpRegistry {
|
||||
pub(crate) async fn spawn_mcp_server(
|
||||
spec: &McpServer,
|
||||
log_path: Option<&Path>,
|
||||
bearer_token: Option<String>,
|
||||
) -> Result<Arc<ConnectedServer>> {
|
||||
match spec.transport_type {
|
||||
McpTransportType::Http => {
|
||||
let url = spec.url.as_deref().expect("validated: http spec has url");
|
||||
spawn_http_mcp_server(url, spec.headers.as_ref()).await
|
||||
let headers = merge_bearer_token(spec.headers.as_ref(), bearer_token);
|
||||
spawn_http_mcp_server(url, headers.as_ref()).await
|
||||
}
|
||||
McpTransportType::Sse => {
|
||||
let url = spec.url.as_deref().expect("validated: sse spec has url");
|
||||
spawn_sse_mcp_server(url, spec.headers.as_ref()).await
|
||||
let headers = merge_bearer_token(spec.headers.as_ref(), bearer_token);
|
||||
spawn_sse_mcp_server(url, headers.as_ref()).await
|
||||
}
|
||||
McpTransportType::Stdio => {
|
||||
let command = spec
|
||||
@@ -357,6 +435,31 @@ pub(crate) async fn spawn_mcp_server(
|
||||
}
|
||||
}
|
||||
|
||||
fn merge_bearer_token(
|
||||
headers: Option<&IndexMap<String, String>>,
|
||||
bearer_token: Option<String>,
|
||||
) -> Option<IndexMap<String, String>> {
|
||||
match (headers, bearer_token) {
|
||||
(None, None) => None,
|
||||
(Some(h), None) => Some(h.clone()),
|
||||
(None, Some(token)) => {
|
||||
let mut m = IndexMap::new();
|
||||
m.insert("Authorization".to_string(), format!("Bearer {token}"));
|
||||
Some(m)
|
||||
}
|
||||
(Some(h), Some(token)) => {
|
||||
let mut m = h.clone();
|
||||
m.insert("Authorization".to_string(), format!("Bearer {token}"));
|
||||
Some(m)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn is_auth_required_error(e: &Error) -> bool {
|
||||
e.chain()
|
||||
.any(|cause| cause.to_string().contains("Auth required"))
|
||||
}
|
||||
|
||||
async fn spawn_http_mcp_server(
|
||||
url: &str,
|
||||
headers: Option<&IndexMap<String, String>>,
|
||||
@@ -433,8 +536,12 @@ async fn spawn_stdio_mcp_server(
|
||||
let log_file = OpenOptions::new()
|
||||
.create(true)
|
||||
.append(true)
|
||||
.open(log_path)?;
|
||||
let (transport, _) = TokioChildProcess::builder(cmd).stderr(log_file).spawn()?;
|
||||
.open(log_path)
|
||||
.with_context(|| format!("Failed to open MCP log file at '{}'", log_path.display()))?;
|
||||
let (transport, _) = TokioChildProcess::builder(cmd)
|
||||
.stderr(log_file)
|
||||
.spawn()
|
||||
.with_context(|| format!("Failed to spawn MCP server: {command}"))?;
|
||||
transport
|
||||
} else {
|
||||
TokioChildProcess::new(cmd)?
|
||||
@@ -461,6 +568,7 @@ mod tests {
|
||||
cwd: None,
|
||||
url: None,
|
||||
headers: None,
|
||||
oauth: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -473,6 +581,7 @@ mod tests {
|
||||
cwd: None,
|
||||
url: Some(url.to_string()),
|
||||
headers: None,
|
||||
oauth: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,6 +594,7 @@ mod tests {
|
||||
cwd: None,
|
||||
url: Some(url.to_string()),
|
||||
headers: None,
|
||||
oauth: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -502,6 +612,7 @@ mod tests {
|
||||
#[test]
|
||||
fn validate_stdio_with_command_succeeds() {
|
||||
let spec = stdio_server("npx");
|
||||
|
||||
assert!(spec.validate("test").is_ok());
|
||||
}
|
||||
|
||||
@@ -515,8 +626,11 @@ mod tests {
|
||||
cwd: None,
|
||||
url: None,
|
||||
headers: None,
|
||||
oauth: None,
|
||||
};
|
||||
|
||||
let err = spec.validate("test").unwrap_err();
|
||||
|
||||
assert!(err.to_string().contains("missing a \"command\" field"));
|
||||
}
|
||||
|
||||
@@ -530,8 +644,11 @@ mod tests {
|
||||
cwd: None,
|
||||
url: Some("http://localhost".into()),
|
||||
headers: None,
|
||||
oauth: None,
|
||||
};
|
||||
|
||||
let err = spec.validate("test").unwrap_err();
|
||||
|
||||
assert!(err.to_string().contains("remote fields"));
|
||||
}
|
||||
|
||||
@@ -547,14 +664,18 @@ mod tests {
|
||||
cwd: None,
|
||||
url: None,
|
||||
headers: Some(headers),
|
||||
oauth: None,
|
||||
};
|
||||
|
||||
let err = spec.validate("test").unwrap_err();
|
||||
|
||||
assert!(err.to_string().contains("remote fields"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validate_http_with_url_succeeds() {
|
||||
let spec = http_server("http://localhost:8080");
|
||||
|
||||
assert!(spec.validate("test").is_ok());
|
||||
}
|
||||
|
||||
@@ -568,8 +689,11 @@ mod tests {
|
||||
cwd: None,
|
||||
url: None,
|
||||
headers: None,
|
||||
oauth: None,
|
||||
};
|
||||
|
||||
let err = spec.validate("test").unwrap_err();
|
||||
|
||||
assert!(err.to_string().contains("missing a \"url\" field"));
|
||||
}
|
||||
|
||||
@@ -583,8 +707,11 @@ mod tests {
|
||||
cwd: None,
|
||||
url: Some("http://localhost".into()),
|
||||
headers: None,
|
||||
oauth: None,
|
||||
};
|
||||
|
||||
let err = spec.validate("test").unwrap_err();
|
||||
|
||||
assert!(err.to_string().contains("stdio fields"));
|
||||
}
|
||||
|
||||
@@ -598,8 +725,11 @@ mod tests {
|
||||
cwd: None,
|
||||
url: Some("http://localhost".into()),
|
||||
headers: None,
|
||||
oauth: None,
|
||||
};
|
||||
|
||||
let err = spec.validate("test").unwrap_err();
|
||||
|
||||
assert!(err.to_string().contains("stdio fields"));
|
||||
}
|
||||
|
||||
@@ -613,14 +743,18 @@ mod tests {
|
||||
cwd: Some("/tmp".into()),
|
||||
url: Some("http://localhost".into()),
|
||||
headers: None,
|
||||
oauth: None,
|
||||
};
|
||||
|
||||
let err = spec.validate("test").unwrap_err();
|
||||
|
||||
assert!(err.to_string().contains("stdio fields"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validate_sse_with_url_succeeds() {
|
||||
let spec = sse_server("http://sse.example.com");
|
||||
|
||||
assert!(spec.validate("test").is_ok());
|
||||
}
|
||||
|
||||
@@ -634,8 +768,11 @@ mod tests {
|
||||
cwd: None,
|
||||
url: None,
|
||||
headers: None,
|
||||
oauth: None,
|
||||
};
|
||||
|
||||
let err = spec.validate("test").unwrap_err();
|
||||
|
||||
assert!(err.to_string().contains("missing a \"url\" field"));
|
||||
}
|
||||
|
||||
@@ -661,9 +798,13 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}"#;
|
||||
|
||||
let config: McpServersConfig = serde_json::from_str(json).unwrap();
|
||||
|
||||
assert!(config.mcp_servers.contains_key("my-server"));
|
||||
|
||||
let spec = &config.mcp_servers["my-server"];
|
||||
|
||||
assert_eq!(spec.transport_type, McpTransportType::Stdio);
|
||||
assert_eq!(spec.command.as_deref(), Some("npx"));
|
||||
assert_eq!(
|
||||
@@ -684,7 +825,9 @@ mod tests {
|
||||
}
|
||||
}"#;
|
||||
let config: McpServersConfig = serde_json::from_str(json).unwrap();
|
||||
|
||||
let spec = &config.mcp_servers["remote"];
|
||||
|
||||
assert_eq!(spec.transport_type, McpTransportType::Http);
|
||||
assert_eq!(spec.url.as_deref(), Some("http://localhost:8080/mcp"));
|
||||
assert_eq!(
|
||||
@@ -709,7 +852,9 @@ mod tests {
|
||||
}
|
||||
}"#;
|
||||
let config: McpServersConfig = serde_json::from_str(json).unwrap();
|
||||
|
||||
let env = config.mcp_servers["s"].env.as_ref().unwrap();
|
||||
|
||||
assert!(matches!(env["STR_VAR"], JsonField::Str(ref s) if s == "hello"));
|
||||
assert!(matches!(env["BOOL_VAR"], JsonField::Bool(true)));
|
||||
assert!(matches!(env["INT_VAR"], JsonField::Int(42)));
|
||||
@@ -723,7 +868,9 @@ mod tests {
|
||||
"remote-api": { "type": "http", "url": "http://api.example.com" }
|
||||
}
|
||||
}"#;
|
||||
|
||||
let config: McpServersConfig = serde_json::from_str(json).unwrap();
|
||||
|
||||
assert_eq!(config.mcp_servers.len(), 2);
|
||||
assert!(config.mcp_servers.contains_key("github"));
|
||||
assert!(config.mcp_servers.contains_key("remote-api"));
|
||||
@@ -732,7 +879,9 @@ mod tests {
|
||||
#[test]
|
||||
fn deserialize_empty_servers_map() {
|
||||
let json = r#"{ "mcpServers": {} }"#;
|
||||
|
||||
let config: McpServersConfig = serde_json::from_str(json).unwrap();
|
||||
|
||||
assert!(config.mcp_servers.is_empty());
|
||||
}
|
||||
|
||||
@@ -747,77 +896,96 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}"#;
|
||||
|
||||
let config: McpServersConfig = serde_json::from_str(json).unwrap();
|
||||
|
||||
assert_eq!(config.mcp_servers["s"].cwd.as_deref(), Some("/tmp/work"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolve_all_returns_all_configured_servers() {
|
||||
let registry = make_registry_with_config(&["github", "slack", "jira"]);
|
||||
|
||||
let mut ids = registry.resolve_server_ids(Some(vec!["all".to_string()]));
|
||||
ids.sort();
|
||||
|
||||
assert_eq!(ids, vec!["github", "jira", "slack"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolve_comma_separated_returns_matching_servers() {
|
||||
let registry = make_registry_with_config(&["github", "slack", "jira"]);
|
||||
|
||||
let mut ids =
|
||||
registry.resolve_server_ids(Some(vec!["github".to_string(), "jira".to_string()]));
|
||||
ids.sort();
|
||||
|
||||
assert_eq!(ids, vec!["github", "jira"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolve_single_server_name() {
|
||||
let registry = make_registry_with_config(&["github", "slack"]);
|
||||
|
||||
let ids = registry.resolve_server_ids(Some(vec!["slack".to_string()]));
|
||||
|
||||
assert_eq!(ids, vec!["slack"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolve_none_returns_empty() {
|
||||
let registry = make_registry_with_config(&["github"]);
|
||||
|
||||
let ids = registry.resolve_server_ids(None);
|
||||
|
||||
assert!(ids.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolve_no_config_returns_empty() {
|
||||
let registry = McpRegistry::default();
|
||||
|
||||
let ids = registry.resolve_server_ids(Some(vec!["all".to_string()]));
|
||||
|
||||
assert!(ids.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolve_nonexistent_server_filtered_out() {
|
||||
let registry = make_registry_with_config(&["github"]);
|
||||
|
||||
let ids = registry
|
||||
.resolve_server_ids(Some(vec!["github".to_string(), "nonexistent".to_string()]));
|
||||
|
||||
assert_eq!(ids, vec!["github"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolve_all_nonexistent_returns_empty() {
|
||||
let registry = make_registry_with_config(&["github"]);
|
||||
|
||||
let ids = registry.resolve_server_ids(Some(vec!["foo".to_string(), "bar".to_string()]));
|
||||
|
||||
assert!(ids.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolve_trims_whitespace() {
|
||||
let registry = make_registry_with_config(&["github", "slack"]);
|
||||
|
||||
let mut ids = registry.resolve_server_ids(Some(vec![
|
||||
" github ".to_string(),
|
||||
" slack ".to_string(),
|
||||
]));
|
||||
ids.sort();
|
||||
|
||||
assert_eq!(ids, vec!["github", "slack"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn registry_default_is_empty() {
|
||||
let registry = McpRegistry::default();
|
||||
|
||||
assert!(registry.is_empty());
|
||||
assert!(registry.list_started_servers().is_empty());
|
||||
assert!(registry.mcp_config().is_none());
|
||||
@@ -827,6 +995,7 @@ mod tests {
|
||||
#[test]
|
||||
fn registry_with_config_reports_config() {
|
||||
let registry = make_registry_with_config(&["github"]);
|
||||
|
||||
assert!(registry.mcp_config().is_some());
|
||||
assert!(
|
||||
registry
|
||||
@@ -843,4 +1012,63 @@ mod tests {
|
||||
assert_eq!(MCP_SEARCH_META_FUNCTION_NAME_PREFIX, "mcp_search");
|
||||
assert_eq!(MCP_DESCRIBE_META_FUNCTION_NAME_PREFIX, "mcp_describe");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_bearer_token_both_none_returns_none() {
|
||||
assert!(merge_bearer_token(None, None).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_bearer_token_headers_only_passes_through() {
|
||||
let mut h = IndexMap::new();
|
||||
h.insert("X-Key".to_string(), "val".to_string());
|
||||
|
||||
let result = merge_bearer_token(Some(&h), None).unwrap();
|
||||
|
||||
assert_eq!(result["X-Key"], "val");
|
||||
assert!(!result.contains_key("Authorization"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_bearer_token_token_only_injects_bearer() {
|
||||
let result = merge_bearer_token(None, Some("tok123".to_string())).unwrap();
|
||||
|
||||
assert_eq!(result["Authorization"], "Bearer tok123");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_bearer_token_both_merges_and_overrides_authorization() {
|
||||
let mut h = IndexMap::new();
|
||||
h.insert("Authorization".to_string(), "old".to_string());
|
||||
h.insert("X-Custom".to_string(), "keep".to_string());
|
||||
|
||||
let result = merge_bearer_token(Some(&h), Some("newtoken".to_string())).unwrap();
|
||||
|
||||
assert_eq!(result["Authorization"], "Bearer newtoken");
|
||||
assert_eq!(result["X-Custom"], "keep");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_auth_required_error_matches_rmcp_message() {
|
||||
let e = anyhow!("Auth required, when send initialize request");
|
||||
|
||||
assert!(is_auth_required_error(&e));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_auth_required_error_does_not_match_unrelated() {
|
||||
let e = anyhow!("Connection refused");
|
||||
|
||||
assert!(!is_auth_required_error(&e));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_auth_required_error_survives_context_wrapping() {
|
||||
let e = anyhow!("Auth required, when send initialize request").context(
|
||||
"MCP server 'github' requires OAuth authentication. \
|
||||
Run `coyote --auth-mcp github` or `.mcp auth github` in the REPL to authenticate.",
|
||||
);
|
||||
|
||||
assert!(is_auth_required_error(&e));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,506 @@
|
||||
use crate::client::oauth::{OAuthProvider, TokenRequestFormat, load_oauth_tokens, run_oauth_flow};
|
||||
use crate::config::paths;
|
||||
use anyhow::{Context, Result, anyhow};
|
||||
use chrono::Utc;
|
||||
use inquire::Text;
|
||||
use log::warn;
|
||||
use reqwest::Client;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs;
|
||||
use std::net::TcpListener;
|
||||
use url::Url;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct ProtectedResourceMetadata {
|
||||
#[serde(default)]
|
||||
authorization_servers: Vec<String>,
|
||||
#[serde(default)]
|
||||
scopes_supported: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct OAuthServerMetadata {
|
||||
authorization_endpoint: String,
|
||||
token_endpoint: String,
|
||||
#[serde(default)]
|
||||
scopes_supported: Vec<String>,
|
||||
registration_endpoint: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct McpRegistration {
|
||||
client_id: String,
|
||||
}
|
||||
|
||||
struct McpOAuthProvider {
|
||||
client_id: String,
|
||||
authorize_url: String,
|
||||
token_url: String,
|
||||
scopes: String,
|
||||
fixed_redirect: String,
|
||||
}
|
||||
|
||||
impl OAuthProvider for McpOAuthProvider {
|
||||
fn provider_name(&self) -> &str {
|
||||
"MCP"
|
||||
}
|
||||
|
||||
fn client_id(&self) -> &str {
|
||||
&self.client_id
|
||||
}
|
||||
|
||||
fn authorize_url(&self) -> &str {
|
||||
&self.authorize_url
|
||||
}
|
||||
|
||||
fn token_url(&self) -> &str {
|
||||
&self.token_url
|
||||
}
|
||||
|
||||
fn redirect_uri(&self) -> &str {
|
||||
""
|
||||
}
|
||||
|
||||
fn scopes(&self) -> &str {
|
||||
&self.scopes
|
||||
}
|
||||
|
||||
fn token_request_format(&self) -> TokenRequestFormat {
|
||||
TokenRequestFormat::FormUrlEncoded
|
||||
}
|
||||
|
||||
fn uses_localhost_redirect(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn fixed_redirect_uri(&self) -> Option<String> {
|
||||
Some(self.fixed_redirect.clone())
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn run_mcp_oauth_flow(
|
||||
server_name: &str,
|
||||
server_url: &str,
|
||||
configured_client_id: Option<&str>,
|
||||
callback_port: Option<u16>,
|
||||
redirect_host: Option<&str>,
|
||||
) -> Result<()> {
|
||||
let metadata = discover_oauth_metadata(server_url).await?;
|
||||
|
||||
let host = redirect_host.unwrap_or("127.0.0.1");
|
||||
let bind_addr = format!("127.0.0.1:{}", callback_port.unwrap_or(0));
|
||||
let listener = TcpListener::bind(&bind_addr)?;
|
||||
let port = listener.local_addr()?.port();
|
||||
drop(listener);
|
||||
let redirect_uri = format!("http://{host}:{port}/callback");
|
||||
|
||||
let client_id = if let Some(id) = configured_client_id {
|
||||
id.to_string()
|
||||
} else if let Some(cached) = load_registered_client_id(server_name) {
|
||||
cached
|
||||
} else if let Some(reg_endpoint) = &metadata.registration_endpoint {
|
||||
match register_client(reg_endpoint, &redirect_uri).await {
|
||||
Ok(id) => {
|
||||
let _ = save_registered_client_id(server_name, &id);
|
||||
id
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Dynamic client registration failed: {e}. Falling back to manual entry.");
|
||||
Text::new("Enter the OAuth client ID for this MCP server:")
|
||||
.prompt()
|
||||
.context("Failed to read client ID")?
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Text::new("Enter the OAuth client ID for this MCP server:")
|
||||
.prompt()
|
||||
.context("Failed to read client ID")?
|
||||
};
|
||||
|
||||
let provider = McpOAuthProvider {
|
||||
client_id,
|
||||
authorize_url: metadata.authorization_endpoint,
|
||||
token_url: metadata.token_endpoint,
|
||||
scopes: metadata.scopes_supported.join(" "),
|
||||
fixed_redirect: redirect_uri,
|
||||
};
|
||||
|
||||
run_oauth_flow(&provider, &mcp_token_key(server_name)).await
|
||||
}
|
||||
|
||||
pub fn load_valid_mcp_token(server_name: &str) -> Option<String> {
|
||||
let tokens = load_oauth_tokens(&mcp_token_key(server_name))?;
|
||||
if Utc::now().timestamp() < tokens.expires_at {
|
||||
Some(tokens.access_token)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn mcp_token_key(server_name: &str) -> String {
|
||||
format!("mcp_{server_name}")
|
||||
}
|
||||
|
||||
fn load_registered_client_id(server_name: &str) -> Option<String> {
|
||||
let path = paths::oauth_tokens_path().join(format!("mcp_{server_name}_registration.json"));
|
||||
let content = fs::read_to_string(path).ok()?;
|
||||
let reg: McpRegistration = serde_json::from_str(&content).ok()?;
|
||||
|
||||
Some(reg.client_id)
|
||||
}
|
||||
|
||||
fn save_registered_client_id(server_name: &str, client_id: &str) -> Result<()> {
|
||||
let dir = paths::oauth_tokens_path();
|
||||
fs::create_dir_all(&dir)?;
|
||||
|
||||
let path = dir.join(format!("mcp_{server_name}_registration.json"));
|
||||
let reg = McpRegistration {
|
||||
client_id: client_id.to_string(),
|
||||
};
|
||||
|
||||
fs::write(path, serde_json::to_string_pretty(®)?)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn register_client(endpoint: &str, redirect_uri: &str) -> Result<String> {
|
||||
let body = serde_json::json!({
|
||||
"client_name": "Coyote",
|
||||
"redirect_uris": [redirect_uri],
|
||||
"grant_types": ["authorization_code", "refresh_token"],
|
||||
"response_types": ["code"],
|
||||
"token_endpoint_auth_method": "none"
|
||||
});
|
||||
|
||||
let response: serde_json::Value = Client::new()
|
||||
.post(endpoint)
|
||||
.json(&body)
|
||||
.send()
|
||||
.await
|
||||
.context("Failed to reach registration endpoint")?
|
||||
.json()
|
||||
.await
|
||||
.context("Failed to parse registration response")?;
|
||||
|
||||
response["client_id"]
|
||||
.as_str()
|
||||
.ok_or_else(|| anyhow!("Missing client_id in registration response: {response}"))
|
||||
.map(|s| s.to_string())
|
||||
}
|
||||
|
||||
async fn discover_oauth_metadata(server_url: &str) -> Result<OAuthServerMetadata> {
|
||||
let client = Client::new();
|
||||
let mut tried: Vec<String> = Vec::new();
|
||||
|
||||
// RFC 9728 @ 5.1: an unauthenticated request should yield a 401 whose
|
||||
// WWW-Authenticate challenge advertises the protected resource metadata URL.
|
||||
let mut pr_urls = Vec::new();
|
||||
if let Some(url) = probe_resource_metadata_url(&client, server_url).await {
|
||||
pr_urls.push(url);
|
||||
}
|
||||
|
||||
// RFC 9728 @ 3.1: path-aware well-known URL, then root as legacy fallback.
|
||||
pr_urls.extend(well_known_urls(server_url, "oauth-protected-resource")?);
|
||||
pr_urls.dedup();
|
||||
|
||||
for pr_url in &pr_urls {
|
||||
tried.push(pr_url.clone());
|
||||
let Ok(resp) = client.get(pr_url).send().await else {
|
||||
continue;
|
||||
};
|
||||
if !resp.status().is_success() {
|
||||
continue;
|
||||
}
|
||||
let Ok(pr) = resp.json::<ProtectedResourceMetadata>().await else {
|
||||
continue;
|
||||
};
|
||||
let Some(issuer) = pr.authorization_servers.first() else {
|
||||
continue;
|
||||
};
|
||||
// RFC 8414 @ 3.1: for issuers with a path component the well-known
|
||||
// segment is inserted BEFORE the path (with the legacy appended form
|
||||
// and root as fallbacks).
|
||||
for as_url in well_known_urls(issuer, "oauth-authorization-server")? {
|
||||
tried.push(as_url.clone());
|
||||
if let Ok(resp) = client.get(&as_url).send().await
|
||||
&& resp.status().is_success()
|
||||
&& let Ok(mut meta) = resp.json::<OAuthServerMetadata>().await
|
||||
{
|
||||
// Some auth servers (e.g. GitHub) omit scopes_supported from
|
||||
// their metadata; fall back to the resource's advertised scopes.
|
||||
if meta.scopes_supported.is_empty() {
|
||||
meta.scopes_supported = pr.scopes_supported.clone();
|
||||
}
|
||||
return Ok(meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Last resort: the MCP server itself may host authorization server metadata.
|
||||
for as_url in well_known_urls(server_url, "oauth-authorization-server")? {
|
||||
tried.push(as_url.clone());
|
||||
if let Ok(resp) = client.get(&as_url).send().await
|
||||
&& resp.status().is_success()
|
||||
{
|
||||
return resp
|
||||
.json::<OAuthServerMetadata>()
|
||||
.await
|
||||
.with_context(|| format!("Failed to parse OAuth metadata from {as_url}"));
|
||||
}
|
||||
}
|
||||
|
||||
Err(anyhow!(
|
||||
"Could not discover OAuth metadata for '{server_url}'.\n\
|
||||
Tried:\n {}\n\
|
||||
Ensure the server supports MCP OAuth discovery, or consult its documentation.",
|
||||
tried.join("\n ")
|
||||
))
|
||||
}
|
||||
|
||||
/// Probes the MCP server with an unauthenticated request and extracts the
|
||||
/// `resource_metadata` URL from the 401 `WWW-Authenticate` challenge (RFC 9728 @ 5.1).
|
||||
async fn probe_resource_metadata_url(client: &Client, server_url: &str) -> Option<String> {
|
||||
let resp = client.get(server_url).send().await.ok()?;
|
||||
let header = resp.headers().get(reqwest::header::WWW_AUTHENTICATE)?;
|
||||
|
||||
parse_resource_metadata(header.to_str().ok()?)
|
||||
}
|
||||
|
||||
/// Extracts the `resource_metadata` parameter value from a `WWW-Authenticate`
|
||||
/// challenge, e.g. `Bearer error="...", resource_metadata="https://..."`.
|
||||
fn parse_resource_metadata(challenge: &str) -> Option<String> {
|
||||
let (_, rest) = challenge.split_once("resource_metadata=")?;
|
||||
let rest = rest.trim_start();
|
||||
let value = if let Some(stripped) = rest.strip_prefix('"') {
|
||||
stripped.split('"').next()?
|
||||
} else {
|
||||
rest.split([',', ' ']).next()?
|
||||
};
|
||||
|
||||
if value.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(value.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds candidate well-known metadata URLs for `url`, ordered by spec preference:
|
||||
/// 1. Path-aware (RFC 8414 @ 3.1 / RFC 9728 @ 3.1): `{origin}/.well-known/{suffix}{path}`
|
||||
/// 2. Legacy appended form: `{url}/.well-known/{suffix}`
|
||||
/// 3. Root: `{origin}/.well-known/{suffix}`
|
||||
///
|
||||
/// URLs without a path component yield only the root form.
|
||||
fn well_known_urls(url: &str, suffix: &str) -> Result<Vec<String>> {
|
||||
let parsed = Url::parse(url).with_context(|| format!("Invalid URL: {url}"))?;
|
||||
let origin = extract_base_url(url)?;
|
||||
let path = parsed.path().trim_end_matches('/');
|
||||
|
||||
let mut urls = Vec::new();
|
||||
if !path.is_empty() && path != "/" {
|
||||
urls.push(format!("{origin}/.well-known/{suffix}{path}"));
|
||||
urls.push(format!("{origin}{path}/.well-known/{suffix}"));
|
||||
}
|
||||
urls.push(format!("{origin}/.well-known/{suffix}"));
|
||||
|
||||
Ok(urls)
|
||||
}
|
||||
|
||||
fn extract_base_url(url: &str) -> Result<String> {
|
||||
let parsed = Url::parse(url).with_context(|| format!("Invalid URL: {url}"))?;
|
||||
let scheme = parsed.scheme();
|
||||
let host = parsed
|
||||
.host_str()
|
||||
.ok_or_else(|| anyhow!("No host in URL: {url}"))?;
|
||||
let port = parsed.port().map(|p| format!(":{p}")).unwrap_or_default();
|
||||
|
||||
Ok(format!("{scheme}://{host}{port}"))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::utils::get_env_name;
|
||||
use serial_test::serial;
|
||||
use std::{
|
||||
env, fs,
|
||||
time::{self, SystemTime},
|
||||
};
|
||||
|
||||
fn with_temp_cache<F: FnOnce()>(f: F) {
|
||||
let unique = SystemTime::now()
|
||||
.duration_since(time::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_nanos();
|
||||
let root = env::temp_dir().join(format!("coyote-mcp-oauth-test-{unique}"));
|
||||
fs::create_dir_all(&root).unwrap();
|
||||
let env_key = get_env_name("cache_dir");
|
||||
let prev = env::var_os(&env_key);
|
||||
unsafe {
|
||||
env::set_var(&env_key, &root);
|
||||
}
|
||||
f();
|
||||
unsafe {
|
||||
match prev {
|
||||
Some(v) => env::set_var(&env_key, v),
|
||||
None => env::remove_var(&env_key),
|
||||
}
|
||||
}
|
||||
let _ = fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extract_base_url_strips_path_and_query() {
|
||||
let result = extract_base_url("https://mcp.notion.com/mcp?foo=bar").unwrap();
|
||||
|
||||
assert_eq!(result, "https://mcp.notion.com");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extract_base_url_preserves_explicit_port() {
|
||||
let result = extract_base_url("http://localhost:8080/mcp").unwrap();
|
||||
|
||||
assert_eq!(result, "http://localhost:8080");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extract_base_url_standard_port_omitted() {
|
||||
let result = extract_base_url("https://example.com/mcp/v1").unwrap();
|
||||
|
||||
assert_eq!(result, "https://example.com");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extract_base_url_rejects_invalid_url() {
|
||||
assert!(extract_base_url("not-a-url").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn well_known_urls_path_aware_first_for_url_with_path() {
|
||||
let urls = well_known_urls(
|
||||
"https://api.githubcopilot.com/mcp",
|
||||
"oauth-protected-resource",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
urls,
|
||||
vec![
|
||||
"https://api.githubcopilot.com/.well-known/oauth-protected-resource/mcp",
|
||||
"https://api.githubcopilot.com/mcp/.well-known/oauth-protected-resource",
|
||||
"https://api.githubcopilot.com/.well-known/oauth-protected-resource",
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn well_known_urls_inserts_before_issuer_path() {
|
||||
let urls = well_known_urls(
|
||||
"https://github.com/login/oauth",
|
||||
"oauth-authorization-server",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
urls[0],
|
||||
"https://github.com/.well-known/oauth-authorization-server/login/oauth"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn well_known_urls_root_only_for_url_without_path() {
|
||||
let urls = well_known_urls("https://mcp.notion.com", "oauth-authorization-server").unwrap();
|
||||
|
||||
assert_eq!(
|
||||
urls,
|
||||
vec!["https://mcp.notion.com/.well-known/oauth-authorization-server"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn well_known_urls_ignores_trailing_slash() {
|
||||
let urls = well_known_urls(
|
||||
"https://api.githubcopilot.com/mcp/",
|
||||
"oauth-protected-resource",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
urls[0],
|
||||
"https://api.githubcopilot.com/.well-known/oauth-protected-resource/mcp"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_resource_metadata_extracts_quoted_url() {
|
||||
let challenge = r#"Bearer error="invalid_request", error_description="No access token was provided in this request", resource_metadata="https://api.githubcopilot.com/.well-known/oauth-protected-resource/mcp""#;
|
||||
|
||||
let url = parse_resource_metadata(challenge);
|
||||
|
||||
assert_eq!(
|
||||
url,
|
||||
Some(
|
||||
"https://api.githubcopilot.com/.well-known/oauth-protected-resource/mcp"
|
||||
.to_string()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_resource_metadata_extracts_unquoted_url() {
|
||||
let challenge = "Bearer resource_metadata=https://example.com/.well-known/oauth-protected-resource/mcp, error=\"invalid_token\"";
|
||||
|
||||
let url = parse_resource_metadata(challenge);
|
||||
|
||||
assert_eq!(
|
||||
url,
|
||||
Some("https://example.com/.well-known/oauth-protected-resource/mcp".to_string())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_resource_metadata_returns_none_when_absent() {
|
||||
assert_eq!(
|
||||
parse_resource_metadata(r#"Bearer error="invalid_token""#),
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
parse_resource_metadata(r#"Bearer resource_metadata="""#),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn registered_client_id_roundtrip() {
|
||||
with_temp_cache(|| {
|
||||
save_registered_client_id("notion", "client-xyz-123").unwrap();
|
||||
|
||||
let loaded = load_registered_client_id("notion");
|
||||
|
||||
assert_eq!(loaded, Some("client-xyz-123".to_string()));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn load_registered_client_id_returns_none_for_missing() {
|
||||
with_temp_cache(|| {
|
||||
let loaded = load_registered_client_id("no-such-server");
|
||||
|
||||
assert!(loaded.is_none());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn registered_client_id_second_save_overwrites_first() {
|
||||
with_temp_cache(|| {
|
||||
save_registered_client_id("github", "first-id").unwrap();
|
||||
save_registered_client_id("github", "second-id").unwrap();
|
||||
|
||||
let loaded = load_registered_client_id("github");
|
||||
|
||||
assert_eq!(loaded, Some("second-id".to_string()));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -358,17 +358,16 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::function::JsonSchema;
|
||||
use std::fs;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
|
||||
static PARSE_COUNTER: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
fn parse_source(
|
||||
source: &str,
|
||||
file_name: &str,
|
||||
parent: &Path,
|
||||
) -> Result<Vec<FunctionDeclaration>> {
|
||||
let unique = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.expect("time went backwards")
|
||||
.as_nanos();
|
||||
let unique = PARSE_COUNTER.fetch_add(1, Ordering::Relaxed);
|
||||
let path =
|
||||
std::env::temp_dir().join(format!("coyote_python_parser_{file_name}_{unique}.py"));
|
||||
fs::write(&path, source).expect("failed to write temp python source");
|
||||
|
||||
@@ -0,0 +1,874 @@
|
||||
use super::DocumentId;
|
||||
use crate::client::*;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use indexmap::{IndexMap, IndexSet};
|
||||
use petgraph::Direction;
|
||||
use petgraph::graph::NodeIndex;
|
||||
use petgraph::stable_graph::StableGraph;
|
||||
use petgraph::visit::EdgeRef;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
/// Heuristic upper bound on chunk size before warning the user that the
|
||||
/// extraction LLM call may be truncated. Not a hard limit.
|
||||
const MAX_CHUNK_CHARS: usize = 24_000;
|
||||
|
||||
/// Maximum number of nodes the BFS may visit during a single graph_search.
|
||||
/// Keeps the synchronous traversal bounded on dense graphs.
|
||||
pub const MAX_GRAPH_NODES: usize = 500;
|
||||
|
||||
const EXTRACTION_PROMPT: &str = r#"Extract entities and relationships from the following text chunk.
|
||||
|
||||
Return a JSON object with this exact structure:
|
||||
{
|
||||
"entities": [
|
||||
{"name": "EntityName", "type": "EntityType", "description": "brief description"}
|
||||
],
|
||||
"relationships": [
|
||||
{"from": "EntityA", "to": "EntityB", "type": "relation_verb", "weight": 0.9}
|
||||
]
|
||||
}
|
||||
|
||||
Rules:
|
||||
- Entity types: PERSON, ORGANIZATION, CONCEPT, TECHNOLOGY, LOCATION, EVENT, or OTHER
|
||||
- Relationship types should be short verb phrases (e.g., "uses", "depends_on", "implements", "part_of")
|
||||
- Weight is a float from 0.0 to 1.0 indicating relationship strength (default 1.0)
|
||||
- Only extract entities and relationships clearly stated or strongly implied in the text
|
||||
- Use exact entity names as they appear so relationships can be matched
|
||||
- Return ONLY the JSON object, no markdown fences, no explanation
|
||||
|
||||
Text chunk:
|
||||
__CHUNK__"#;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Entity {
|
||||
pub name: String,
|
||||
pub entity_type: String,
|
||||
pub description: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Relationship {
|
||||
pub relation_type: String,
|
||||
pub weight: f32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ExtractionResult {
|
||||
pub entities: Vec<ExtractedEntity>,
|
||||
pub relationships: Vec<ExtractedRelationship>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ExtractedEntity {
|
||||
pub name: String,
|
||||
#[serde(rename = "type")]
|
||||
pub entity_type: String,
|
||||
pub description: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ExtractedRelationship {
|
||||
pub from: String,
|
||||
pub to: String,
|
||||
#[serde(rename = "type")]
|
||||
pub relation_type: String,
|
||||
pub weight: Option<f32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct KnowledgeGraph {
|
||||
pub graph: StableGraph<Entity, Relationship>,
|
||||
/// Lowercased entity name → raw node index
|
||||
pub entity_index: IndexMap<String, u32>,
|
||||
/// DocumentId inner value → raw node indices for entities in that chunk
|
||||
pub document_entities: IndexMap<usize, Vec<u32>>,
|
||||
}
|
||||
|
||||
impl Default for KnowledgeGraph {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
graph: StableGraph::new(),
|
||||
entity_index: IndexMap::new(),
|
||||
document_entities: IndexMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl KnowledgeGraph {
|
||||
pub fn merge(&mut self, doc_id: DocumentId, result: ExtractionResult) {
|
||||
let mut chunk_nodes: IndexSet<u32> = IndexSet::new();
|
||||
|
||||
for extracted in &result.entities {
|
||||
let key = extracted.name.to_lowercase();
|
||||
let normalized_type = extracted.entity_type.to_uppercase();
|
||||
let node_raw = if let Some(&existing) = self.entity_index.get(&key) {
|
||||
let idx = NodeIndex::new(existing as usize);
|
||||
if self.graph.contains_node(idx) {
|
||||
let node = &mut self.graph[idx];
|
||||
if node.entity_type == "OTHER" && normalized_type != "OTHER" {
|
||||
node.entity_type = normalized_type;
|
||||
}
|
||||
if node.description.is_none() {
|
||||
node.description = extracted.description.clone();
|
||||
}
|
||||
}
|
||||
existing
|
||||
} else {
|
||||
let entity = Entity {
|
||||
name: extracted.name.clone(),
|
||||
entity_type: normalized_type,
|
||||
description: extracted.description.clone(),
|
||||
};
|
||||
let idx = self.graph.add_node(entity);
|
||||
let raw = idx.index() as u32;
|
||||
self.entity_index.insert(key, raw);
|
||||
raw
|
||||
};
|
||||
chunk_nodes.insert(node_raw);
|
||||
}
|
||||
|
||||
for extracted in &result.relationships {
|
||||
let from_key = extracted.from.to_lowercase();
|
||||
let to_key = extracted.to.to_lowercase();
|
||||
if let (Some(&from_raw), Some(&to_raw)) = (
|
||||
self.entity_index.get(&from_key),
|
||||
self.entity_index.get(&to_key),
|
||||
) {
|
||||
let from_idx = NodeIndex::new(from_raw as usize);
|
||||
let to_idx = NodeIndex::new(to_raw as usize);
|
||||
let already_exists = self
|
||||
.graph
|
||||
.edges_connecting(from_idx, to_idx)
|
||||
.any(|e| e.weight().relation_type == extracted.relation_type);
|
||||
if !already_exists {
|
||||
let rel = Relationship {
|
||||
relation_type: extracted.relation_type.clone(),
|
||||
weight: extracted.weight.unwrap_or(1.0).clamp(0.0, 1.0),
|
||||
};
|
||||
self.graph.add_edge(from_idx, to_idx, rel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.document_entities
|
||||
.entry(doc_id.0)
|
||||
.or_default()
|
||||
.extend(chunk_nodes);
|
||||
}
|
||||
|
||||
pub fn remove_documents(&mut self, doc_ids: &[DocumentId]) {
|
||||
if doc_ids.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let removing: HashSet<usize> = doc_ids.iter().map(|d| d.0).collect();
|
||||
for raw_id in &removing {
|
||||
self.document_entities.swap_remove(raw_id);
|
||||
}
|
||||
|
||||
let still_used: HashSet<u32> = self
|
||||
.document_entities
|
||||
.values()
|
||||
.flat_map(|v| v.iter().copied())
|
||||
.collect();
|
||||
|
||||
let to_remove: Vec<u32> = self
|
||||
.entity_index
|
||||
.values()
|
||||
.copied()
|
||||
.filter(|raw| !still_used.contains(raw))
|
||||
.collect();
|
||||
|
||||
if to_remove.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
for raw in to_remove {
|
||||
let idx = NodeIndex::new(raw as usize);
|
||||
if self.graph.contains_node(idx) {
|
||||
let name = self.graph[idx].name.to_lowercase();
|
||||
self.graph.remove_node(idx);
|
||||
self.entity_index.swap_remove(&name);
|
||||
}
|
||||
}
|
||||
|
||||
self.compact();
|
||||
}
|
||||
|
||||
/// Rebuild the internal graph with consecutive node indices. Eliminates
|
||||
/// the null tombstone slots that petgraph's StableGraph accumulates after
|
||||
/// repeated `remove_node` calls, keeping serialized YAML size in check.
|
||||
fn compact(&mut self) {
|
||||
let mut new_graph: StableGraph<Entity, Relationship> = StableGraph::new();
|
||||
let mut old_to_new: HashMap<u32, u32> = HashMap::new();
|
||||
|
||||
for &old_raw in self.entity_index.values() {
|
||||
let old_idx = NodeIndex::new(old_raw as usize);
|
||||
if self.graph.contains_node(old_idx) {
|
||||
let entity = self.graph[old_idx].clone();
|
||||
let new_idx = new_graph.add_node(entity);
|
||||
old_to_new.insert(old_raw, new_idx.index() as u32);
|
||||
}
|
||||
}
|
||||
|
||||
for edge_idx in self.graph.edge_indices() {
|
||||
if let Some((from, to)) = self.graph.edge_endpoints(edge_idx) {
|
||||
let from_raw = from.index() as u32;
|
||||
let to_raw = to.index() as u32;
|
||||
if let (Some(&new_from), Some(&new_to)) =
|
||||
(old_to_new.get(&from_raw), old_to_new.get(&to_raw))
|
||||
{
|
||||
let rel = self.graph[edge_idx].clone();
|
||||
new_graph.add_edge(
|
||||
NodeIndex::new(new_from as usize),
|
||||
NodeIndex::new(new_to as usize),
|
||||
rel,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for raw in self.entity_index.values_mut() {
|
||||
if let Some(&new_raw) = old_to_new.get(raw) {
|
||||
*raw = new_raw;
|
||||
}
|
||||
}
|
||||
|
||||
for node_raws in self.document_entities.values_mut() {
|
||||
*node_raws = node_raws
|
||||
.iter()
|
||||
.filter_map(|raw| old_to_new.get(raw).copied())
|
||||
.collect();
|
||||
}
|
||||
|
||||
self.graph = new_graph;
|
||||
}
|
||||
|
||||
pub fn build_node_to_docs(&self) -> IndexMap<u32, Vec<DocumentId>> {
|
||||
let mut map: IndexMap<u32, Vec<DocumentId>> = IndexMap::new();
|
||||
for (&doc_raw, node_raws) in &self.document_entities {
|
||||
let doc_id = DocumentId(doc_raw);
|
||||
for &node_raw in node_raws {
|
||||
map.entry(node_raw).or_default().push(doc_id);
|
||||
}
|
||||
}
|
||||
map
|
||||
}
|
||||
|
||||
/// BFS from seed nodes with weight-decayed scoring.
|
||||
///
|
||||
/// Seed node scores are provided by the caller (typically token-overlap
|
||||
/// ratios). Each neighbor's score is `edge_weight * parent_score`, so
|
||||
/// strongly-connected neighbors rank higher and weakly-connected ones
|
||||
/// naturally contribute less. Traversal is capped at `MAX_GRAPH_NODES`
|
||||
/// total nodes; the highest-scored frontier nodes are expanded first so
|
||||
/// the budget is spent on the most relevant entities.
|
||||
///
|
||||
/// Returns a map of raw node index → score (includes seed nodes).
|
||||
pub fn expand_neighbors_scored(
|
||||
&self,
|
||||
seed_scores: &[(u32, f32)],
|
||||
hops: usize,
|
||||
) -> IndexMap<u32, f32> {
|
||||
let mut node_scores: IndexMap<u32, f32> = IndexMap::new();
|
||||
for &(raw, score) in seed_scores {
|
||||
node_scores.insert(raw, score);
|
||||
}
|
||||
|
||||
let mut frontier: Vec<(u32, f32)> = seed_scores.to_vec();
|
||||
|
||||
for _ in 0..hops {
|
||||
if node_scores.len() >= MAX_GRAPH_NODES {
|
||||
break;
|
||||
}
|
||||
|
||||
frontier.sort_unstable_by(|a, b| {
|
||||
b.1.partial_cmp(&a.1).unwrap_or(std::cmp::Ordering::Equal)
|
||||
});
|
||||
|
||||
let mut next_frontier: Vec<(u32, f32)> = vec![];
|
||||
|
||||
'nodes: for (raw, parent_score) in &frontier {
|
||||
let idx = NodeIndex::new(*raw as usize);
|
||||
if !self.graph.contains_node(idx) {
|
||||
continue;
|
||||
}
|
||||
for dir in [Direction::Outgoing, Direction::Incoming] {
|
||||
for edge_ref in self.graph.edges_directed(idx, dir) {
|
||||
let neighbor_idx = match dir {
|
||||
Direction::Outgoing => edge_ref.target(),
|
||||
Direction::Incoming => edge_ref.source(),
|
||||
};
|
||||
let neighbor_raw = neighbor_idx.index() as u32;
|
||||
let candidate = edge_ref.weight().weight * parent_score;
|
||||
|
||||
match node_scores.entry(neighbor_raw) {
|
||||
indexmap::map::Entry::Vacant(e) => {
|
||||
e.insert(candidate);
|
||||
next_frontier.push((neighbor_raw, candidate));
|
||||
}
|
||||
indexmap::map::Entry::Occupied(mut e) => {
|
||||
if candidate > *e.get() {
|
||||
*e.get_mut() = candidate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if node_scores.len() >= MAX_GRAPH_NODES {
|
||||
break 'nodes;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
frontier = next_frontier;
|
||||
if frontier.is_empty() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
node_scores
|
||||
}
|
||||
}
|
||||
|
||||
/// Uses chat_completions_inner directly (bypassing Input) because Rag has no
|
||||
/// RequestContext, which Input::from_str requires.
|
||||
pub async fn extract_entities(
|
||||
client: &dyn Client,
|
||||
chunk: &str,
|
||||
prompt_template: Option<&str>,
|
||||
) -> Result<ExtractionResult> {
|
||||
if chunk.len() > MAX_CHUNK_CHARS {
|
||||
warn!(
|
||||
"Entity extraction chunk is {} chars (heuristic limit: {}); \
|
||||
the LLM response may be truncated",
|
||||
chunk.len(),
|
||||
MAX_CHUNK_CHARS
|
||||
);
|
||||
}
|
||||
let template = prompt_template.unwrap_or(EXTRACTION_PROMPT);
|
||||
let prompt = template.replace("__CHUNK__", chunk);
|
||||
let mut messages = vec![Message::new(
|
||||
MessageRole::User,
|
||||
MessageContent::Text(prompt),
|
||||
)];
|
||||
patch_messages(&mut messages, client.model());
|
||||
let reqwest_client = client
|
||||
.build_client()
|
||||
.context("Failed to build HTTP client for entity extraction")?;
|
||||
let data = ChatCompletionsData {
|
||||
messages,
|
||||
temperature: Some(0.0),
|
||||
top_p: None,
|
||||
reasoning_effort: None,
|
||||
functions: None,
|
||||
stream: false,
|
||||
};
|
||||
let output = client
|
||||
.chat_completions_inner(&reqwest_client, data)
|
||||
.await
|
||||
.context("Entity extraction LLM call failed")?;
|
||||
|
||||
let text = output.text.trim();
|
||||
// Strip markdown code fences if the model wraps in ```json ... ```
|
||||
let json: String = if text.starts_with("```") {
|
||||
text.lines()
|
||||
.skip(1)
|
||||
.take_while(|l| !l.trim_start().starts_with("```"))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
} else {
|
||||
text.to_string()
|
||||
};
|
||||
|
||||
serde_json::from_str::<ExtractionResult>(&json)
|
||||
.context("Failed to parse entity extraction JSON")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn entity(name: &str, entity_type: &str) -> ExtractedEntity {
|
||||
ExtractedEntity {
|
||||
name: name.to_string(),
|
||||
entity_type: entity_type.to_string(),
|
||||
description: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn rel(from: &str, to: &str, rel_type: &str, weight: f32) -> ExtractedRelationship {
|
||||
ExtractedRelationship {
|
||||
from: from.to_string(),
|
||||
to: to.to_string(),
|
||||
relation_type: rel_type.to_string(),
|
||||
weight: Some(weight),
|
||||
}
|
||||
}
|
||||
|
||||
fn doc(id: usize) -> DocumentId {
|
||||
DocumentId(id)
|
||||
}
|
||||
|
||||
fn extraction(
|
||||
entities: Vec<ExtractedEntity>,
|
||||
rels: Vec<ExtractedRelationship>,
|
||||
) -> ExtractionResult {
|
||||
ExtractionResult {
|
||||
entities,
|
||||
relationships: rels,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_deduplicates_by_lowercase_name() {
|
||||
let mut kg = KnowledgeGraph::default();
|
||||
kg.merge(
|
||||
doc(0),
|
||||
extraction(
|
||||
vec![
|
||||
entity("Python", "TECHNOLOGY"),
|
||||
entity("python", "TECHNOLOGY"),
|
||||
],
|
||||
vec![],
|
||||
),
|
||||
);
|
||||
assert_eq!(kg.entity_index.len(), 1);
|
||||
assert_eq!(kg.graph.node_count(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_chunk_nodes_no_duplicate_doc_entries() {
|
||||
let mut kg = KnowledgeGraph::default();
|
||||
kg.merge(
|
||||
doc(1),
|
||||
extraction(
|
||||
vec![
|
||||
entity("Python", "TECHNOLOGY"),
|
||||
entity("python", "TECHNOLOGY"),
|
||||
],
|
||||
vec![],
|
||||
),
|
||||
);
|
||||
let count = kg.document_entities.get(&1).map(|v| v.len()).unwrap_or(0);
|
||||
assert_eq!(
|
||||
count, 1,
|
||||
"duplicate entity in one chunk should produce one doc_entity entry"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_normalizes_entity_type_to_uppercase() {
|
||||
let mut kg = KnowledgeGraph::default();
|
||||
kg.merge(
|
||||
doc(0),
|
||||
extraction(vec![entity("Django", "technology")], vec![]),
|
||||
);
|
||||
let raw = kg.entity_index["django"];
|
||||
assert_eq!(
|
||||
kg.graph[NodeIndex::new(raw as usize)].entity_type,
|
||||
"TECHNOLOGY"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_promotes_type_from_other_to_specific() {
|
||||
let mut kg = KnowledgeGraph::default();
|
||||
kg.merge(doc(0), extraction(vec![entity("Python", "OTHER")], vec![]));
|
||||
kg.merge(
|
||||
doc(1),
|
||||
extraction(vec![entity("Python", "TECHNOLOGY")], vec![]),
|
||||
);
|
||||
let raw = kg.entity_index["python"];
|
||||
assert_eq!(
|
||||
kg.graph[NodeIndex::new(raw as usize)].entity_type,
|
||||
"TECHNOLOGY"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_does_not_demote_specific_type_to_other() {
|
||||
let mut kg = KnowledgeGraph::default();
|
||||
kg.merge(
|
||||
doc(0),
|
||||
extraction(vec![entity("Python", "TECHNOLOGY")], vec![]),
|
||||
);
|
||||
kg.merge(doc(1), extraction(vec![entity("Python", "OTHER")], vec![]));
|
||||
let raw = kg.entity_index["python"];
|
||||
assert_eq!(
|
||||
kg.graph[NodeIndex::new(raw as usize)].entity_type,
|
||||
"TECHNOLOGY"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_allows_multiple_relation_types_between_same_pair() {
|
||||
let mut kg = KnowledgeGraph::default();
|
||||
kg.merge(
|
||||
doc(0),
|
||||
extraction(
|
||||
vec![
|
||||
entity("Python", "TECHNOLOGY"),
|
||||
entity("Django", "TECHNOLOGY"),
|
||||
],
|
||||
vec![rel("Python", "Django", "implements", 0.9)],
|
||||
),
|
||||
);
|
||||
kg.merge(
|
||||
doc(1),
|
||||
extraction(
|
||||
vec![
|
||||
entity("Python", "TECHNOLOGY"),
|
||||
entity("Django", "TECHNOLOGY"),
|
||||
],
|
||||
vec![rel("Python", "Django", "uses", 0.8)],
|
||||
),
|
||||
);
|
||||
let from_idx = NodeIndex::new(kg.entity_index["python"] as usize);
|
||||
let to_idx = NodeIndex::new(kg.entity_index["django"] as usize);
|
||||
let count = kg.graph.edges_connecting(from_idx, to_idx).count();
|
||||
assert_eq!(
|
||||
count, 2,
|
||||
"two different relation types should produce two edges"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_deduplicates_same_relation_type() {
|
||||
let mut kg = KnowledgeGraph::default();
|
||||
kg.merge(
|
||||
doc(0),
|
||||
extraction(
|
||||
vec![entity("A", "CONCEPT"), entity("B", "CONCEPT")],
|
||||
vec![rel("A", "B", "uses", 1.0)],
|
||||
),
|
||||
);
|
||||
kg.merge(
|
||||
doc(1),
|
||||
extraction(
|
||||
vec![entity("A", "CONCEPT"), entity("B", "CONCEPT")],
|
||||
vec![rel("A", "B", "uses", 0.5)],
|
||||
),
|
||||
);
|
||||
let from_idx = NodeIndex::new(kg.entity_index["a"] as usize);
|
||||
let to_idx = NodeIndex::new(kg.entity_index["b"] as usize);
|
||||
let count = kg.graph.edges_connecting(from_idx, to_idx).count();
|
||||
assert_eq!(
|
||||
count, 1,
|
||||
"same relation type should not create a duplicate edge"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_documents_preserves_entity_shared_across_docs() {
|
||||
let mut kg = KnowledgeGraph::default();
|
||||
kg.merge(
|
||||
doc(0),
|
||||
extraction(
|
||||
vec![entity("Python", "TECHNOLOGY"), entity("A", "CONCEPT")],
|
||||
vec![],
|
||||
),
|
||||
);
|
||||
kg.merge(
|
||||
doc(1),
|
||||
extraction(
|
||||
vec![entity("Python", "TECHNOLOGY"), entity("B", "CONCEPT")],
|
||||
vec![],
|
||||
),
|
||||
);
|
||||
kg.remove_documents(&[doc(0)]);
|
||||
assert!(
|
||||
kg.entity_index.contains_key("python"),
|
||||
"shared entity should survive"
|
||||
);
|
||||
assert!(
|
||||
!kg.entity_index.contains_key("a"),
|
||||
"exclusive entity should be removed"
|
||||
);
|
||||
assert!(
|
||||
kg.entity_index.contains_key("b"),
|
||||
"other doc's entity should survive"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_documents_noop_on_empty_slice() {
|
||||
let mut kg = KnowledgeGraph::default();
|
||||
kg.merge(doc(0), extraction(vec![entity("X", "CONCEPT")], vec![]));
|
||||
kg.remove_documents(&[]);
|
||||
assert_eq!(kg.entity_index.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_documents_compacts_graph() {
|
||||
let mut kg = KnowledgeGraph::default();
|
||||
// doc 0: A, B with an edge
|
||||
kg.merge(
|
||||
doc(0),
|
||||
extraction(
|
||||
vec![entity("A", "CONCEPT"), entity("B", "CONCEPT")],
|
||||
vec![rel("A", "B", "uses", 1.0)],
|
||||
),
|
||||
);
|
||||
// doc 1: C only
|
||||
kg.merge(doc(1), extraction(vec![entity("C", "CONCEPT")], vec![]));
|
||||
|
||||
kg.remove_documents(&[doc(0)]);
|
||||
|
||||
assert_eq!(kg.graph.node_count(), 1);
|
||||
let c_raw = kg.entity_index["c"];
|
||||
assert_eq!(
|
||||
c_raw, 0,
|
||||
"compacted graph should give surviving node index 0"
|
||||
);
|
||||
let refs = kg.document_entities.get(&1).cloned().unwrap_or_default();
|
||||
assert_eq!(refs, vec![0u32]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expand_zero_hops_returns_seeds_only() {
|
||||
let mut kg = KnowledgeGraph::default();
|
||||
kg.merge(
|
||||
doc(0),
|
||||
extraction(
|
||||
vec![entity("A", "CONCEPT"), entity("B", "CONCEPT")],
|
||||
vec![rel("A", "B", "uses", 0.9)],
|
||||
),
|
||||
);
|
||||
let a_raw = kg.entity_index["a"];
|
||||
let result = kg.expand_neighbors_scored(&[(a_raw, 1.0)], 0);
|
||||
assert_eq!(result.len(), 1);
|
||||
assert_eq!(result[&a_raw], 1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expand_one_hop_decays_score_by_edge_weight() {
|
||||
let mut kg = KnowledgeGraph::default();
|
||||
kg.merge(
|
||||
doc(0),
|
||||
extraction(
|
||||
vec![entity("A", "CONCEPT"), entity("B", "CONCEPT")],
|
||||
vec![rel("A", "B", "uses", 0.8)],
|
||||
),
|
||||
);
|
||||
let a_raw = kg.entity_index["a"];
|
||||
let b_raw = kg.entity_index["b"];
|
||||
let result = kg.expand_neighbors_scored(&[(a_raw, 1.0)], 1);
|
||||
assert_eq!(result.len(), 2);
|
||||
assert_eq!(result[&a_raw], 1.0);
|
||||
let b_score = result[&b_raw];
|
||||
assert!(
|
||||
(b_score - 0.8).abs() < 1e-6,
|
||||
"neighbor score should be edge_weight * parent_score = 0.8, got {b_score}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expand_incoming_edges_also_traversed() {
|
||||
let mut kg = KnowledgeGraph::default();
|
||||
// Edge goes B → A; seeding A should still discover B via incoming edge
|
||||
kg.merge(
|
||||
doc(0),
|
||||
extraction(
|
||||
vec![entity("A", "CONCEPT"), entity("B", "CONCEPT")],
|
||||
vec![rel("B", "A", "uses", 0.7)],
|
||||
),
|
||||
);
|
||||
let a_raw = kg.entity_index["a"];
|
||||
let b_raw = kg.entity_index["b"];
|
||||
let result = kg.expand_neighbors_scored(&[(a_raw, 1.0)], 1);
|
||||
assert!(
|
||||
result.contains_key(&b_raw),
|
||||
"B should be reachable via incoming edge from A"
|
||||
);
|
||||
let b_score = result[&b_raw];
|
||||
assert!((b_score - 0.7).abs() < 1e-6);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expand_picks_best_path_score() {
|
||||
let mut kg = KnowledgeGraph::default();
|
||||
// A(0.5) → C(0.9): score 0.45; B(1.0) → C(0.4): score 0.40 — A→C path wins.
|
||||
kg.merge(
|
||||
doc(0),
|
||||
extraction(
|
||||
vec![
|
||||
entity("A", "CONCEPT"),
|
||||
entity("B", "CONCEPT"),
|
||||
entity("C", "CONCEPT"),
|
||||
],
|
||||
vec![rel("A", "C", "uses", 0.9), rel("B", "C", "uses", 0.4)],
|
||||
),
|
||||
);
|
||||
let a_raw = kg.entity_index["a"];
|
||||
let b_raw = kg.entity_index["b"];
|
||||
let c_raw = kg.entity_index["c"];
|
||||
let seeds = vec![(a_raw, 0.5f32), (b_raw, 1.0f32)];
|
||||
let result = kg.expand_neighbors_scored(&seeds, 1);
|
||||
let c_score = result[&c_raw];
|
||||
// Best path: B(1.0) * 0.4 = 0.4, A(0.5) * 0.9 = 0.45 → should be 0.45
|
||||
assert!(
|
||||
(c_score - 0.45).abs() < 1e-6,
|
||||
"C score should reflect best path (0.45), got {c_score}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_node_to_docs_maps_shared_entity_to_multiple_docs() {
|
||||
let mut kg = KnowledgeGraph::default();
|
||||
kg.merge(
|
||||
doc(0),
|
||||
extraction(vec![entity("Python", "TECHNOLOGY")], vec![]),
|
||||
);
|
||||
kg.merge(
|
||||
doc(1),
|
||||
extraction(vec![entity("Python", "TECHNOLOGY")], vec![]),
|
||||
);
|
||||
let n2d = kg.build_node_to_docs();
|
||||
let raw = kg.entity_index["python"];
|
||||
let docs = &n2d[&raw];
|
||||
assert!(docs.contains(&DocumentId(0)));
|
||||
assert!(docs.contains(&DocumentId(1)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compact_preserves_edges_between_survivors() {
|
||||
let mut kg = KnowledgeGraph::default();
|
||||
kg.merge(doc(0), extraction(vec![entity("A", "CONCEPT")], vec![]));
|
||||
kg.merge(
|
||||
doc(1),
|
||||
extraction(
|
||||
vec![entity("B", "CONCEPT"), entity("C", "CONCEPT")],
|
||||
vec![rel("B", "C", "linked", 0.8)],
|
||||
),
|
||||
);
|
||||
kg.remove_documents(&[doc(0)]);
|
||||
let b_raw = kg.entity_index["b"];
|
||||
let c_raw = kg.entity_index["c"];
|
||||
let b_idx = NodeIndex::new(b_raw as usize);
|
||||
let c_idx = NodeIndex::new(c_raw as usize);
|
||||
assert_eq!(
|
||||
kg.graph.edges_connecting(b_idx, c_idx).count(),
|
||||
1,
|
||||
"B→C edge should survive compaction"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expand_two_hops_reaches_transitive_neighbor() {
|
||||
let mut kg = KnowledgeGraph::default();
|
||||
kg.merge(
|
||||
doc(0),
|
||||
extraction(
|
||||
vec![
|
||||
entity("A", "CONCEPT"),
|
||||
entity("B", "CONCEPT"),
|
||||
entity("C", "CONCEPT"),
|
||||
],
|
||||
vec![rel("A", "B", "uses", 1.0), rel("B", "C", "uses", 0.5)],
|
||||
),
|
||||
);
|
||||
let a_raw = kg.entity_index["a"];
|
||||
let c_raw = kg.entity_index["c"];
|
||||
|
||||
let one_hop = kg.expand_neighbors_scored(&[(a_raw, 1.0)], 1);
|
||||
assert!(
|
||||
!one_hop.contains_key(&c_raw),
|
||||
"C should not be reachable at 1 hop"
|
||||
);
|
||||
|
||||
let two_hop = kg.expand_neighbors_scored(&[(a_raw, 1.0)], 2);
|
||||
assert!(
|
||||
two_hop.contains_key(&c_raw),
|
||||
"C should be reachable at 2 hops"
|
||||
);
|
||||
let c_score = two_hop[&c_raw];
|
||||
assert!(
|
||||
(c_score - 0.5).abs() < 1e-6,
|
||||
"C score should be 1.0 * 1.0 * 0.5 = 0.5, got {c_score}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_clamps_edge_weight_above_one() {
|
||||
let mut kg = KnowledgeGraph::default();
|
||||
kg.merge(
|
||||
doc(0),
|
||||
extraction(
|
||||
vec![entity("A", "CONCEPT"), entity("B", "CONCEPT")],
|
||||
vec![rel("A", "B", "uses", 1.5)],
|
||||
),
|
||||
);
|
||||
let a_raw = kg.entity_index["a"];
|
||||
let b_raw = kg.entity_index["b"];
|
||||
let result = kg.expand_neighbors_scored(&[(a_raw, 1.0)], 1);
|
||||
let b_score = result[&b_raw];
|
||||
assert!(
|
||||
(b_score - 1.0).abs() < 1e-6,
|
||||
"weight 1.5 clamped to 1.0: b_score should be 1.0, got {b_score}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_clamps_edge_weight_below_zero() {
|
||||
let mut kg = KnowledgeGraph::default();
|
||||
kg.merge(
|
||||
doc(0),
|
||||
extraction(
|
||||
vec![entity("A", "CONCEPT"), entity("B", "CONCEPT")],
|
||||
vec![rel("A", "B", "uses", -0.5)],
|
||||
),
|
||||
);
|
||||
let a_raw = kg.entity_index["a"];
|
||||
let b_raw = kg.entity_index["b"];
|
||||
let result = kg.expand_neighbors_scored(&[(a_raw, 1.0)], 1);
|
||||
let b_score = result.get(&b_raw).copied().unwrap_or(0.0);
|
||||
assert!(
|
||||
b_score.abs() < 1e-6,
|
||||
"weight -0.5 clamped to 0.0: b_score should be 0.0, got {b_score}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_fills_missing_description_from_later_chunk() {
|
||||
let mut kg = KnowledgeGraph::default();
|
||||
kg.merge(
|
||||
doc(0),
|
||||
extraction(vec![entity("Python", "TECHNOLOGY")], vec![]),
|
||||
);
|
||||
kg.merge(
|
||||
doc(1),
|
||||
ExtractionResult {
|
||||
entities: vec![ExtractedEntity {
|
||||
name: "python".to_string(),
|
||||
entity_type: "TECHNOLOGY".to_string(),
|
||||
description: Some("A general-purpose language".to_string()),
|
||||
}],
|
||||
relationships: vec![],
|
||||
},
|
||||
);
|
||||
let raw = kg.entity_index["python"];
|
||||
let desc = &kg.graph[NodeIndex::new(raw as usize)].description;
|
||||
assert_eq!(
|
||||
desc.as_deref(),
|
||||
Some("A general-purpose language"),
|
||||
"description should be backfilled from later chunk"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_all_documents_empties_graph() {
|
||||
let mut kg = KnowledgeGraph::default();
|
||||
kg.merge(doc(0), extraction(vec![entity("A", "CONCEPT")], vec![]));
|
||||
kg.merge(doc(1), extraction(vec![entity("B", "CONCEPT")], vec![]));
|
||||
kg.remove_documents(&[doc(0), doc(1)]);
|
||||
assert_eq!(kg.graph.node_count(), 0, "all nodes should be removed");
|
||||
assert_eq!(kg.entity_index.len(), 0, "entity index should be empty");
|
||||
assert!(
|
||||
kg.document_entities.is_empty(),
|
||||
"document_entities should be empty"
|
||||
);
|
||||
}
|
||||
}
|
||||
+449
-22
@@ -4,15 +4,19 @@ use crate::client::*;
|
||||
use crate::config::*;
|
||||
use crate::utils::*;
|
||||
|
||||
mod graph;
|
||||
mod serde_vectors;
|
||||
mod splitter;
|
||||
|
||||
use self::graph::{KnowledgeGraph, extract_entities};
|
||||
|
||||
use anyhow::{Context, Result, anyhow, bail};
|
||||
use bm25::{Language, SearchEngine, SearchEngineBuilder};
|
||||
use hnsw_rs::prelude::*;
|
||||
use indexmap::{IndexMap, IndexSet};
|
||||
use inquire::{Confirm, Select, Text, required, validator::Validation};
|
||||
use parking_lot::RwLock;
|
||||
use petgraph::graph::NodeIndex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use std::{
|
||||
@@ -21,6 +25,8 @@ use std::{
|
||||
};
|
||||
use tokio::time::sleep;
|
||||
|
||||
const BM25_SEED_SCORE: f32 = 0.5;
|
||||
|
||||
const RAG_TEMPLATE: &str = r#"Answer the query based on the context while respecting the rules. (user query, some textual context and rules, all inside xml tags)
|
||||
|
||||
<context>
|
||||
@@ -54,6 +60,7 @@ pub struct Rag {
|
||||
bm25: SearchEngine<DocumentId>,
|
||||
data: RagData,
|
||||
last_sources: RwLock<Option<String>>,
|
||||
node_to_docs: IndexMap<u32, Vec<DocumentId>>,
|
||||
}
|
||||
|
||||
impl Debug for Rag {
|
||||
@@ -76,6 +83,7 @@ impl Clone for Rag {
|
||||
embedding_model: self.embedding_model.clone(),
|
||||
hnsw: self.data.build_hnsw(),
|
||||
bm25: self.data.build_bm25(),
|
||||
node_to_docs: self.data.knowledge_graph.build_node_to_docs(),
|
||||
data: self.data.clone(),
|
||||
last_sources: RwLock::new(None),
|
||||
}
|
||||
@@ -90,6 +98,16 @@ pub struct RagInitConfig {
|
||||
pub reranker_model: Option<String>,
|
||||
pub top_k: Option<usize>,
|
||||
pub batch_size: Option<usize>,
|
||||
pub extractor_model: Option<String>,
|
||||
pub extractor_prompt: Option<String>,
|
||||
pub graph_hops: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct GraphRagConfig {
|
||||
pub extractor_model: Option<String>,
|
||||
pub extractor_prompt: Option<String>,
|
||||
pub graph_hops: Option<usize>,
|
||||
}
|
||||
|
||||
impl Rag {
|
||||
@@ -199,6 +217,17 @@ impl Rag {
|
||||
reranker_model,
|
||||
top_k,
|
||||
batch_size,
|
||||
GraphRagConfig {
|
||||
extractor_model: config
|
||||
.extractor_model
|
||||
.clone()
|
||||
.or_else(|| app.rag_extractor_model.clone()),
|
||||
extractor_prompt: config
|
||||
.extractor_prompt
|
||||
.clone()
|
||||
.or_else(|| app.rag_extractor_prompt.clone()),
|
||||
graph_hops: Some(config.graph_hops.unwrap_or(app.rag_graph_hops)),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
@@ -216,6 +245,16 @@ impl Rag {
|
||||
let (embedding_model, chunk_size, chunk_overlap) = Self::create_config(app)?;
|
||||
let reranker_model = app.rag_reranker_model.clone();
|
||||
let top_k = app.rag_top_k;
|
||||
let extractor_model = match app.rag_extractor_model.clone() {
|
||||
Some(model) => Some(model),
|
||||
None => select_extractor_model(app)?,
|
||||
};
|
||||
let graph_hops = if extractor_model.is_some() {
|
||||
set_graph_hops(app.rag_graph_hops)?
|
||||
} else {
|
||||
app.rag_graph_hops
|
||||
};
|
||||
let extractor_prompt = app.rag_extractor_prompt.clone();
|
||||
let data = RagData::new(
|
||||
embedding_model.id(),
|
||||
chunk_size,
|
||||
@@ -223,6 +262,11 @@ impl Rag {
|
||||
reranker_model,
|
||||
top_k,
|
||||
embedding_model.max_batch_size(),
|
||||
GraphRagConfig {
|
||||
extractor_model,
|
||||
extractor_prompt,
|
||||
graph_hops: Some(graph_hops),
|
||||
},
|
||||
);
|
||||
let mut rag = Self::create(app, name, save_path, data)?;
|
||||
let mut paths = doc_paths.to_vec();
|
||||
@@ -253,6 +297,7 @@ impl Rag {
|
||||
pub fn create(app: &AppConfig, name: &str, path: &Path, data: RagData) -> Result<Self> {
|
||||
let hnsw = data.build_hnsw();
|
||||
let bm25 = data.build_bm25();
|
||||
let node_to_docs = data.knowledge_graph.build_node_to_docs();
|
||||
let embedding_model =
|
||||
Model::retrieve_model(app, &data.embedding_model, ModelType::Embedding)?;
|
||||
let rag = Rag {
|
||||
@@ -263,6 +308,7 @@ impl Rag {
|
||||
embedding_model,
|
||||
hnsw,
|
||||
bm25,
|
||||
node_to_docs,
|
||||
last_sources: RwLock::new(None),
|
||||
};
|
||||
Ok(rag)
|
||||
@@ -413,6 +459,9 @@ impl Rag {
|
||||
"chunk_size": self.data.chunk_size,
|
||||
"chunk_overlap": self.data.chunk_overlap,
|
||||
"reranker_model": self.data.reranker_model,
|
||||
"extractor_model": self.data.extractor_model,
|
||||
"extractor_prompt": self.data.extractor_prompt,
|
||||
"graph_hops": self.data.graph_hops.unwrap_or(1),
|
||||
"top_k": self.data.top_k,
|
||||
"batch_size": self.data.batch_size,
|
||||
"document_paths": self.data.document_paths,
|
||||
@@ -673,13 +722,18 @@ impl Rag {
|
||||
let mut files = vec![];
|
||||
let mut document_ids = vec![];
|
||||
let mut embeddings = vec![];
|
||||
let mut new_doc_contents: Vec<(DocumentId, String)> = vec![];
|
||||
|
||||
if !rag_files.is_empty() {
|
||||
let mut texts = vec![];
|
||||
for file in rag_files.into_iter() {
|
||||
for (document_index, document) in file.documents.iter().enumerate() {
|
||||
document_ids.push(DocumentId::new(next_file_id, document_index));
|
||||
texts.push(document.page_content.clone())
|
||||
let doc_id = DocumentId::new(next_file_id, document_index);
|
||||
document_ids.push(doc_id);
|
||||
texts.push(document.page_content.clone());
|
||||
if self.data.extractor_model.is_some() {
|
||||
new_doc_contents.push((doc_id, document.page_content.clone()));
|
||||
}
|
||||
}
|
||||
files.push((next_file_id, file));
|
||||
next_file_id += 1;
|
||||
@@ -700,9 +754,50 @@ impl Rag {
|
||||
bail!("No RAG files");
|
||||
}
|
||||
|
||||
if !new_doc_contents.is_empty()
|
||||
&& let Some(extractor_model_id) = self.data.extractor_model.clone()
|
||||
{
|
||||
match Model::retrieve_model(&self.app_config, &extractor_model_id, ModelType::Chat) {
|
||||
Ok(model) => match self.create_embeddings_client(model) {
|
||||
Ok(client) => {
|
||||
let total = new_doc_contents.len();
|
||||
let mut failures = 0usize;
|
||||
for (i, (doc_id, content)) in new_doc_contents.into_iter().enumerate() {
|
||||
progress(
|
||||
&spinner,
|
||||
format!("Extracting entities [{}/{}]", i + 1, total),
|
||||
);
|
||||
match extract_entities(
|
||||
client.as_ref(),
|
||||
&content,
|
||||
self.data.extractor_prompt.as_deref(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(result) => self.data.knowledge_graph.merge(doc_id, result),
|
||||
Err(e) => {
|
||||
warn!("Entity extraction failed for doc {doc_id:?}: {e}");
|
||||
failures += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if failures > 0 {
|
||||
progress(
|
||||
&spinner,
|
||||
format!("Entity extraction: {failures}/{total} chunks failed"),
|
||||
);
|
||||
}
|
||||
}
|
||||
Err(e) => warn!("Failed to create extractor client: {e}"),
|
||||
},
|
||||
Err(e) => warn!("Extractor model not found: {e}"),
|
||||
}
|
||||
}
|
||||
|
||||
progress(&spinner, "Building store".into());
|
||||
self.hnsw = self.data.build_hnsw();
|
||||
self.bm25 = self.data.build_bm25();
|
||||
self.node_to_docs = self.data.knowledge_graph.build_node_to_docs();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -755,11 +850,21 @@ impl Rag {
|
||||
ids
|
||||
}
|
||||
None => {
|
||||
let ids = reciprocal_rank_fusion(
|
||||
vec![vector_search_ids, keyword_search_ids],
|
||||
vec![1.125, 1.0],
|
||||
top_k,
|
||||
);
|
||||
let ids = if self.data.extractor_model.is_some() {
|
||||
let graph_ids = self.graph_search(query, top_k);
|
||||
debug!("graph_search_ids: {graph_ids:?}");
|
||||
reciprocal_rank_fusion(
|
||||
vec![vector_search_ids, keyword_search_ids, graph_ids],
|
||||
vec![1.125, 1.0, 0.9],
|
||||
top_k,
|
||||
)
|
||||
} else {
|
||||
reciprocal_rank_fusion(
|
||||
vec![vector_search_ids, keyword_search_ids],
|
||||
vec![1.125, 1.0],
|
||||
top_k,
|
||||
)
|
||||
};
|
||||
debug!("rrf_ids: {ids:?}");
|
||||
ids
|
||||
}
|
||||
@@ -829,6 +934,94 @@ impl Rag {
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
fn graph_search(&self, query: &str, top_k: usize) -> Vec<DocumentId> {
|
||||
let kg = &self.data.knowledge_graph;
|
||||
if kg.entity_index.is_empty() {
|
||||
return vec![];
|
||||
}
|
||||
|
||||
let query_lower = query.to_lowercase();
|
||||
let query_tokens: Vec<&str> = query_lower.split_whitespace().collect();
|
||||
let token_count = query_tokens.len().max(1);
|
||||
|
||||
let score_node = |raw: u32| -> f32 {
|
||||
let idx = NodeIndex::new(raw as usize);
|
||||
if !kg.graph.contains_node(idx) {
|
||||
return 0.0;
|
||||
}
|
||||
let entity = &kg.graph[idx];
|
||||
let combined = format!(
|
||||
"{} {}",
|
||||
entity.name,
|
||||
entity.description.as_deref().unwrap_or("")
|
||||
)
|
||||
.to_lowercase();
|
||||
query_tokens
|
||||
.iter()
|
||||
.filter(|t| combined.contains(*t))
|
||||
.count() as f32
|
||||
/ token_count as f32
|
||||
};
|
||||
|
||||
let mut seed_scores: Vec<(u32, f32)> = kg
|
||||
.entity_index
|
||||
.iter()
|
||||
.filter(|(name, _)| {
|
||||
let name_str = name.as_str();
|
||||
if name_str.contains(' ') {
|
||||
query_lower.contains(name_str)
|
||||
} else {
|
||||
// whole-word match: prevents "go" from seeding on every query containing "Django"
|
||||
query_lower
|
||||
.split_whitespace()
|
||||
.any(|token| token.trim_matches(|c: char| !c.is_alphanumeric()) == name_str)
|
||||
}
|
||||
})
|
||||
.map(|(_, &raw)| (raw, score_node(raw).max(BM25_SEED_SCORE)))
|
||||
.collect();
|
||||
|
||||
if seed_scores.is_empty() {
|
||||
let bm25_results = self.bm25.search(query, top_k * 2);
|
||||
'outer: for result in bm25_results {
|
||||
if let Some(node_raws) = kg.document_entities.get(&result.document.id.0) {
|
||||
for &raw in node_raws {
|
||||
seed_scores.push((raw, BM25_SEED_SCORE));
|
||||
if seed_scores.len() >= top_k {
|
||||
break 'outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if seed_scores.is_empty() {
|
||||
return vec![];
|
||||
}
|
||||
|
||||
let hops = self.data.graph_hops.unwrap_or(1);
|
||||
let mut scored: Vec<(u32, f32)> = kg
|
||||
.expand_neighbors_scored(&seed_scores, hops)
|
||||
.into_iter()
|
||||
.collect();
|
||||
scored.sort_by(|a, b| b.1.partial_cmp(&a.1).unwrap_or(Ordering::Equal));
|
||||
|
||||
let mut result_ids: IndexSet<DocumentId> = IndexSet::new();
|
||||
for (raw, _) in scored {
|
||||
if let Some(doc_ids) = self.node_to_docs.get(&raw) {
|
||||
for &doc_id in doc_ids {
|
||||
result_ids.insert(doc_id);
|
||||
if result_ids.len() >= top_k {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if result_ids.len() >= top_k {
|
||||
break;
|
||||
}
|
||||
}
|
||||
result_ids.into_iter().collect()
|
||||
}
|
||||
|
||||
async fn create_embeddings(
|
||||
&self,
|
||||
data: EmbeddingsData,
|
||||
@@ -902,6 +1095,14 @@ pub struct RagData {
|
||||
pub files: IndexMap<FileId, RagFile>,
|
||||
#[serde(with = "serde_vectors")]
|
||||
pub vectors: IndexMap<DocumentId, Vec<f32>>,
|
||||
#[serde(default)]
|
||||
pub extractor_model: Option<String>,
|
||||
#[serde(default)]
|
||||
pub extractor_prompt: Option<String>,
|
||||
#[serde(default)]
|
||||
pub graph_hops: Option<usize>,
|
||||
#[serde(default)]
|
||||
pub knowledge_graph: KnowledgeGraph,
|
||||
}
|
||||
|
||||
impl Debug for RagData {
|
||||
@@ -916,6 +1117,9 @@ impl Debug for RagData {
|
||||
.field("next_file_id", &self.next_file_id)
|
||||
.field("document_paths", &self.document_paths)
|
||||
.field("files", &self.files)
|
||||
.field("extractor_model", &self.extractor_model)
|
||||
.field("extractor_prompt", &self.extractor_prompt)
|
||||
.field("graph_hops", &self.graph_hops)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
@@ -928,6 +1132,7 @@ impl RagData {
|
||||
reranker_model: Option<String>,
|
||||
top_k: usize,
|
||||
batch_size: Option<usize>,
|
||||
graph: GraphRagConfig,
|
||||
) -> Self {
|
||||
Self {
|
||||
embedding_model,
|
||||
@@ -940,6 +1145,10 @@ impl RagData {
|
||||
document_paths: Default::default(),
|
||||
files: Default::default(),
|
||||
vectors: Default::default(),
|
||||
extractor_model: graph.extractor_model,
|
||||
extractor_prompt: graph.extractor_prompt,
|
||||
graph_hops: graph.graph_hops,
|
||||
knowledge_graph: KnowledgeGraph::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -951,14 +1160,17 @@ impl RagData {
|
||||
}
|
||||
|
||||
pub fn del(&mut self, file_ids: Vec<FileId>) {
|
||||
let mut graph_doc_ids = vec![];
|
||||
for file_id in file_ids {
|
||||
if let Some(file) = self.files.swap_remove(&file_id) {
|
||||
for (document_index, _) in file.documents.iter().enumerate() {
|
||||
let document_id = DocumentId::new(file_id, document_index);
|
||||
self.vectors.swap_remove(&document_id);
|
||||
graph_doc_ids.push(document_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.knowledge_graph.remove_documents(&graph_doc_ids);
|
||||
}
|
||||
|
||||
pub fn add(
|
||||
@@ -1055,29 +1267,70 @@ impl DocumentId {
|
||||
}
|
||||
|
||||
fn select_embedding_model(models: &[&Model]) -> Result<String> {
|
||||
let max_width = models.iter().map(|v| v.id().len()).max().unwrap_or(0);
|
||||
let models: Vec<_> = models
|
||||
.iter()
|
||||
.map(|v| SelectOption::new(v.id(), v.description()))
|
||||
.map(|v| SelectOption::new(v.id(), v.description(), max_width))
|
||||
.collect();
|
||||
let result = Select::new("Select embedding model:", models).prompt()?;
|
||||
let result = Select::new("Select embedding model:", models)
|
||||
.with_formatter(&|opt| opt.value.value.clone())
|
||||
.prompt()?;
|
||||
Ok(result.value)
|
||||
}
|
||||
|
||||
const EXTRACTOR_SKIP: &str = "Skip";
|
||||
|
||||
fn select_extractor_model(app: &AppConfig) -> Result<Option<String>> {
|
||||
let models = list_models(app, ModelType::Chat);
|
||||
if models.is_empty() {
|
||||
return Ok(None);
|
||||
}
|
||||
let pad = models
|
||||
.iter()
|
||||
.map(|v| v.id().len())
|
||||
.max()
|
||||
.unwrap_or(0)
|
||||
.max(EXTRACTOR_SKIP.len());
|
||||
let mut options = vec![SelectOption::new(
|
||||
EXTRACTOR_SKIP.to_string(),
|
||||
"vector + full text search only (no graph)".to_string(),
|
||||
pad,
|
||||
)];
|
||||
options.extend(
|
||||
models
|
||||
.iter()
|
||||
.map(|v| SelectOption::new(v.id(), v.description(), pad)),
|
||||
);
|
||||
let result = Select::new("Extractor model for graph-based RAG (optional):", options)
|
||||
.with_formatter(&|opt| opt.value.value.clone())
|
||||
.prompt()?;
|
||||
Ok(if result.value == EXTRACTOR_SKIP {
|
||||
None
|
||||
} else {
|
||||
Some(result.value)
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct SelectOption {
|
||||
pub value: String,
|
||||
pub description: String,
|
||||
pub display: String,
|
||||
}
|
||||
|
||||
impl SelectOption {
|
||||
pub fn new(value: String, description: String) -> Self {
|
||||
Self { value, description }
|
||||
pub fn new(value: String, description: String, pad: usize) -> Self {
|
||||
let display = if description.is_empty() {
|
||||
format!("{value:<pad$}")
|
||||
} else {
|
||||
format!("{value:<pad$} ({description})")
|
||||
};
|
||||
Self { value, display }
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for SelectOption {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{} ({})", self.value, self.description)
|
||||
write!(f, "{}", self.display)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1103,6 +1356,21 @@ fn set_chunk_size(model: &Model) -> Result<usize> {
|
||||
value.parse().map_err(|_| anyhow!("Invalid chunk_size"))
|
||||
}
|
||||
|
||||
fn set_graph_hops(default_value: usize) -> Result<usize> {
|
||||
let value = Text::new("Set graph expansion hops:")
|
||||
.with_default(&default_value.to_string())
|
||||
.with_help_message("Number of hops to expand from matched entities (0 = seed nodes only, 1 = direct neighbors, 2 = neighbors of neighbors)")
|
||||
.with_validator(move |text: &str| {
|
||||
let out = match text.parse::<usize>() {
|
||||
Ok(_) => Validation::Valid,
|
||||
_ => Validation::Invalid("Must be a non-negative integer".into()),
|
||||
};
|
||||
Ok(out)
|
||||
})
|
||||
.prompt()?;
|
||||
value.parse().map_err(|_| anyhow!("Invalid graph_hops"))
|
||||
}
|
||||
|
||||
fn set_chunk_overlay(default_value: usize) -> Result<usize> {
|
||||
let value = Text::new("Set chunk overlay:")
|
||||
.with_default(&default_value.to_string())
|
||||
@@ -1277,7 +1545,15 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn rag_data_new_defaults() {
|
||||
let data = RagData::new("model".into(), 1000, 20, None, 5, None);
|
||||
let data = RagData::new(
|
||||
"model".into(),
|
||||
1000,
|
||||
20,
|
||||
None,
|
||||
5,
|
||||
None,
|
||||
GraphRagConfig::default(),
|
||||
);
|
||||
assert_eq!(data.embedding_model, "model");
|
||||
assert_eq!(data.chunk_size, 1000);
|
||||
assert_eq!(data.chunk_overlap, 20);
|
||||
@@ -1291,7 +1567,15 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn rag_data_get_returns_document() {
|
||||
let mut data = RagData::new("m".into(), 100, 10, None, 5, None);
|
||||
let mut data = RagData::new(
|
||||
"m".into(),
|
||||
100,
|
||||
10,
|
||||
None,
|
||||
5,
|
||||
None,
|
||||
GraphRagConfig::default(),
|
||||
);
|
||||
let file = RagFile {
|
||||
hash: "abc".into(),
|
||||
path: "test.txt".into(),
|
||||
@@ -1308,13 +1592,29 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn rag_data_get_returns_none_for_missing_file() {
|
||||
let data = RagData::new("m".into(), 100, 10, None, 5, None);
|
||||
let data = RagData::new(
|
||||
"m".into(),
|
||||
100,
|
||||
10,
|
||||
None,
|
||||
5,
|
||||
None,
|
||||
GraphRagConfig::default(),
|
||||
);
|
||||
assert!(data.get(DocumentId::new(99, 0)).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rag_data_get_returns_none_for_missing_document() {
|
||||
let mut data = RagData::new("m".into(), 100, 10, None, 5, None);
|
||||
let mut data = RagData::new(
|
||||
"m".into(),
|
||||
100,
|
||||
10,
|
||||
None,
|
||||
5,
|
||||
None,
|
||||
GraphRagConfig::default(),
|
||||
);
|
||||
let file = RagFile {
|
||||
hash: "abc".into(),
|
||||
path: "test.txt".into(),
|
||||
@@ -1326,7 +1626,15 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn rag_data_del_removes_files_and_vectors() {
|
||||
let mut data = RagData::new("m".into(), 100, 10, None, 5, None);
|
||||
let mut data = RagData::new(
|
||||
"m".into(),
|
||||
100,
|
||||
10,
|
||||
None,
|
||||
5,
|
||||
None,
|
||||
GraphRagConfig::default(),
|
||||
);
|
||||
let file = RagFile {
|
||||
hash: "abc".into(),
|
||||
path: "test.txt".into(),
|
||||
@@ -1347,14 +1655,30 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn rag_data_del_nonexistent_is_noop() {
|
||||
let mut data = RagData::new("m".into(), 100, 10, None, 5, None);
|
||||
let mut data = RagData::new(
|
||||
"m".into(),
|
||||
100,
|
||||
10,
|
||||
None,
|
||||
5,
|
||||
None,
|
||||
GraphRagConfig::default(),
|
||||
);
|
||||
data.del(vec![99]);
|
||||
assert!(data.files.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rag_data_add_inserts_files_and_vectors() {
|
||||
let mut data = RagData::new("m".into(), 100, 10, None, 5, None);
|
||||
let mut data = RagData::new(
|
||||
"m".into(),
|
||||
100,
|
||||
10,
|
||||
None,
|
||||
5,
|
||||
None,
|
||||
GraphRagConfig::default(),
|
||||
);
|
||||
let file = RagFile {
|
||||
hash: "xyz".into(),
|
||||
path: "new.txt".into(),
|
||||
@@ -1414,7 +1738,15 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn rag_data_build_bm25_empty() {
|
||||
let data = RagData::new("m".into(), 100, 10, None, 5, None);
|
||||
let data = RagData::new(
|
||||
"m".into(),
|
||||
100,
|
||||
10,
|
||||
None,
|
||||
5,
|
||||
None,
|
||||
GraphRagConfig::default(),
|
||||
);
|
||||
let engine = data.build_bm25();
|
||||
let results = engine.search("anything", 5);
|
||||
assert!(results.is_empty());
|
||||
@@ -1422,7 +1754,15 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn rag_data_build_bm25_finds_documents() {
|
||||
let mut data = RagData::new("m".into(), 100, 10, None, 5, None);
|
||||
let mut data = RagData::new(
|
||||
"m".into(),
|
||||
100,
|
||||
10,
|
||||
None,
|
||||
5,
|
||||
None,
|
||||
GraphRagConfig::default(),
|
||||
);
|
||||
let file = RagFile {
|
||||
hash: "h".into(),
|
||||
path: "test.txt".into(),
|
||||
@@ -1441,4 +1781,91 @@ mod tests {
|
||||
assert_eq!(file_idx, 0);
|
||||
assert_eq!(doc_idx, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rag_data_del_removes_graph_entities() {
|
||||
use super::graph::{ExtractedEntity, ExtractionResult};
|
||||
let mut data = RagData::new(
|
||||
"m".into(),
|
||||
100,
|
||||
10,
|
||||
None,
|
||||
5,
|
||||
None,
|
||||
GraphRagConfig::default(),
|
||||
);
|
||||
let file = RagFile {
|
||||
hash: "abc".into(),
|
||||
path: "test.txt".into(),
|
||||
documents: vec![RagDocument::new("Python is great")],
|
||||
};
|
||||
data.files.insert(0, file);
|
||||
let doc_id = DocumentId::new(0, 0);
|
||||
data.knowledge_graph.merge(
|
||||
doc_id,
|
||||
ExtractionResult {
|
||||
entities: vec![ExtractedEntity {
|
||||
name: "Python".to_string(),
|
||||
entity_type: "TECHNOLOGY".to_string(),
|
||||
description: None,
|
||||
}],
|
||||
relationships: vec![],
|
||||
},
|
||||
);
|
||||
assert!(
|
||||
data.knowledge_graph.entity_index.contains_key("python"),
|
||||
"entity should exist before del"
|
||||
);
|
||||
data.del(vec![0]);
|
||||
assert!(
|
||||
!data.knowledge_graph.entity_index.contains_key("python"),
|
||||
"entity should be removed after del"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reciprocal_rank_fusion_empty_lists() {
|
||||
let result = super::reciprocal_rank_fusion(vec![], vec![], 5);
|
||||
assert!(result.is_empty(), "empty input should produce empty output");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reciprocal_rank_fusion_deduplicates_across_signals() {
|
||||
let doc_a = DocumentId::new(0, 0);
|
||||
let doc_b = DocumentId::new(0, 1);
|
||||
let result = super::reciprocal_rank_fusion(
|
||||
vec![vec![doc_a, doc_b], vec![doc_a, doc_b]],
|
||||
vec![1.0, 1.0],
|
||||
5,
|
||||
);
|
||||
let unique: std::collections::HashSet<_> = result.iter().collect();
|
||||
assert_eq!(
|
||||
unique.len(),
|
||||
result.len(),
|
||||
"each document should appear at most once"
|
||||
);
|
||||
assert_eq!(result.len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reciprocal_rank_fusion_respects_top_k() {
|
||||
let docs: Vec<DocumentId> = (0..10).map(|i| DocumentId::new(0, i)).collect();
|
||||
let result = super::reciprocal_rank_fusion(vec![docs], vec![1.0], 3);
|
||||
assert_eq!(result.len(), 3, "result should be capped at top_k=3");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reciprocal_rank_fusion_weights_affect_ranking() {
|
||||
let doc_a = DocumentId::new(0, 0);
|
||||
let doc_b = DocumentId::new(0, 1);
|
||||
let result = super::reciprocal_rank_fusion(
|
||||
vec![vec![doc_a, doc_b], vec![doc_b, doc_a]],
|
||||
vec![10.0, 1.0],
|
||||
2,
|
||||
);
|
||||
assert_eq!(
|
||||
result[0], doc_a,
|
||||
"higher-weight signal's top doc should rank first"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+13
-5
@@ -2,7 +2,7 @@ use super::{MarkdownRender, SseEvent};
|
||||
|
||||
use crate::utils::{AbortSignal, poll_abort_signal, spawn_spinner};
|
||||
|
||||
use anyhow::{Error, Result};
|
||||
use anyhow::Result;
|
||||
use crossterm::{
|
||||
cursor, queue, style,
|
||||
terminal::{self, disable_raw_mode, enable_raw_mode},
|
||||
@@ -74,6 +74,8 @@ async fn markdown_stream_inner(
|
||||
let mut buffer_rows = 1;
|
||||
|
||||
let columns = terminal::size()?.0;
|
||||
let mut last_col: u16 = 0;
|
||||
let mut last_row: u16 = 0;
|
||||
|
||||
let mut spinner = Some(spawn_spinner("Generating"));
|
||||
|
||||
@@ -94,9 +96,16 @@ async fn markdown_stream_inner(
|
||||
let mut attempts = 0;
|
||||
let (col, mut row) = loop {
|
||||
match cursor::position() {
|
||||
Ok(pos) => break pos,
|
||||
Err(_) if attempts < 3 => attempts += 1,
|
||||
Err(e) => return Err(Error::from(e)),
|
||||
Ok(pos) => {
|
||||
last_col = pos.0;
|
||||
last_row = pos.1;
|
||||
break pos;
|
||||
}
|
||||
Err(_) if attempts < 5 => {
|
||||
attempts += 1;
|
||||
tokio::time::sleep(Duration::from_millis(20)).await;
|
||||
}
|
||||
Err(_) => break (last_col, last_row),
|
||||
}
|
||||
};
|
||||
|
||||
@@ -142,7 +151,6 @@ async fn markdown_stream_inner(
|
||||
queue!(writer, style::Print(&output))?;
|
||||
buffer_rows = need_rows(&output, columns);
|
||||
}
|
||||
|
||||
writer.flush()?;
|
||||
}
|
||||
SseEvent::Done => {
|
||||
|
||||
@@ -31,6 +31,7 @@ impl Completer for ReplCompleter {
|
||||
|
||||
let ctx = self.ctx.read();
|
||||
let state = ctx.state();
|
||||
let model_has_reasoning = !ctx.current_model().reasoning_levels().is_empty();
|
||||
|
||||
let command_filter = parts
|
||||
.iter()
|
||||
@@ -44,6 +45,7 @@ impl Completer for ReplCompleter {
|
||||
.filter(|cmd| {
|
||||
cmd.is_valid(state)
|
||||
&& (command_filter.len() == 1 || cmd.name.starts_with(&command_filter[..2]))
|
||||
&& (cmd.name != ".reasoning" || model_has_reasoning)
|
||||
})
|
||||
.collect();
|
||||
let commands = fuzzy_filter(commands, |v| v.name, &command_filter);
|
||||
|
||||
+337
-8
@@ -6,7 +6,10 @@ use self::completer::ReplCompleter;
|
||||
use self::highlighter::ReplHighlighter;
|
||||
use self::prompt::ReplPrompt;
|
||||
|
||||
use crate::client::{call_chat_completions, call_chat_completions_streaming, init_client, oauth};
|
||||
use crate::client::{
|
||||
Message, MessageRole, call_chat_completions, call_chat_completions_streaming, init_client,
|
||||
oauth,
|
||||
};
|
||||
use crate::config::{
|
||||
AgentVariables, AppConfig, AssertState, Input, LastMessage, RequestContext, StateFlags,
|
||||
macro_execute,
|
||||
@@ -20,7 +23,7 @@ use crate::utils::{
|
||||
};
|
||||
|
||||
use crate::sandbox::SANDBOX_ENV_FLAG;
|
||||
use crate::{config, graph, resolve_oauth_client};
|
||||
use crate::{config, graph, mcp, resolve_oauth_client};
|
||||
use anyhow::{Context, Result, bail};
|
||||
use crossterm::cursor::SetCursorStyle;
|
||||
use fancy_regex::Regex;
|
||||
@@ -29,9 +32,9 @@ use log::warn;
|
||||
use parking_lot::RwLock;
|
||||
use reedline::CursorConfig;
|
||||
use reedline::{
|
||||
ColumnarMenu, EditCommand, EditMode, Emacs, KeyCode, KeyModifiers, Keybindings, Reedline,
|
||||
ReedlineEvent, ReedlineMenu, ValidationResult, Validator, Vi, default_emacs_keybindings,
|
||||
default_vi_insert_keybindings, default_vi_normal_keybindings,
|
||||
ColumnarMenu, EditCommand, EditMode, Emacs, FileBackedHistory, KeyCode, KeyModifiers,
|
||||
Keybindings, Reedline, ReedlineEvent, ReedlineMenu, ValidationResult, Validator, Vi,
|
||||
default_emacs_keybindings, default_vi_insert_keybindings, default_vi_normal_keybindings,
|
||||
};
|
||||
use reedline::{MenuBuilder, Signal};
|
||||
use std::sync::LazyLock;
|
||||
@@ -49,7 +52,7 @@ pub const DEFAULT_CONTINUATION_PROMPT: &str = indoc! {"
|
||||
4. Continue with the next pending item now. Call tools immediately."
|
||||
};
|
||||
|
||||
static REPL_COMMANDS: LazyLock<[ReplCommand; 49]> = LazyLock::new(|| {
|
||||
static REPL_COMMANDS: LazyLock<[ReplCommand; 57]> = LazyLock::new(|| {
|
||||
[
|
||||
ReplCommand::new(".help", "Show this help guide", AssertState::pass()),
|
||||
ReplCommand::new(".info", "Show system info", AssertState::pass()),
|
||||
@@ -63,6 +66,31 @@ static REPL_COMMANDS: LazyLock<[ReplCommand; 49]> = LazyLock::new(|| {
|
||||
"Authenticate the current model client via OAuth (if configured)",
|
||||
AssertState::pass(),
|
||||
),
|
||||
ReplCommand::new(
|
||||
".mcp auth",
|
||||
"Authenticate with an MCP server via OAuth",
|
||||
AssertState::pass(),
|
||||
),
|
||||
ReplCommand::new(
|
||||
".mcp enable",
|
||||
"Enable a single MCP server in the current context",
|
||||
AssertState::pass(),
|
||||
),
|
||||
ReplCommand::new(
|
||||
".mcp disable",
|
||||
"Disable a single MCP server in the current context",
|
||||
AssertState::pass(),
|
||||
),
|
||||
ReplCommand::new(
|
||||
".tool enable",
|
||||
"Enable a single tool in the current context",
|
||||
AssertState::True(StateFlags::FUNCTION_CALLING),
|
||||
),
|
||||
ReplCommand::new(
|
||||
".tool disable",
|
||||
"Disable a single tool in the current context",
|
||||
AssertState::True(StateFlags::FUNCTION_CALLING),
|
||||
),
|
||||
ReplCommand::new(
|
||||
".edit config",
|
||||
"Modify configuration file",
|
||||
@@ -117,6 +145,11 @@ static REPL_COMMANDS: LazyLock<[ReplCommand; 49]> = LazyLock::new(|| {
|
||||
"Clear session messages",
|
||||
AssertState::True(StateFlags::SESSION),
|
||||
),
|
||||
ReplCommand::new(
|
||||
".undo",
|
||||
"Undo the last exchange and restore the prompt",
|
||||
AssertState::True(StateFlags::SESSION),
|
||||
),
|
||||
ReplCommand::new(
|
||||
".compress session",
|
||||
"Compress session messages",
|
||||
@@ -246,11 +279,21 @@ static REPL_COMMANDS: LazyLock<[ReplCommand; 49]> = LazyLock::new(|| {
|
||||
),
|
||||
ReplCommand::new(".copy", "Copy last response", AssertState::pass()),
|
||||
ReplCommand::new(".set", "Modify runtime settings", AssertState::pass()),
|
||||
ReplCommand::new(
|
||||
".reasoning",
|
||||
"Set the reasoning effort level for the current model",
|
||||
AssertState::pass(),
|
||||
),
|
||||
ReplCommand::new(
|
||||
".delete",
|
||||
"Delete roles, sessions, RAGs, or agents",
|
||||
AssertState::pass(),
|
||||
),
|
||||
ReplCommand::new(
|
||||
".list",
|
||||
"List roles, sessions, agents, RAGs, macros, skills, tools, or MCP servers",
|
||||
AssertState::pass(),
|
||||
),
|
||||
ReplCommand::new(
|
||||
".vault",
|
||||
"View or modify the Coyote vault",
|
||||
@@ -313,6 +356,58 @@ Type ".help" for additional help.
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let (messages_snapshot, compressed_count) = {
|
||||
let ctx = self.ctx.read();
|
||||
if let Some(session) = &ctx.session {
|
||||
let msgs: Vec<Message> = session
|
||||
.messages()
|
||||
.iter()
|
||||
.filter(|m| !m.role.is_system())
|
||||
.cloned()
|
||||
.collect();
|
||||
let compressed = session.compressed_messages().len();
|
||||
(msgs, compressed)
|
||||
} else {
|
||||
(vec![], 0)
|
||||
}
|
||||
};
|
||||
|
||||
if !messages_snapshot.is_empty() || compressed_count > 0 {
|
||||
let app = Arc::clone(&self.ctx.read().app.config);
|
||||
if compressed_count > 0 {
|
||||
println!(
|
||||
"{}",
|
||||
dimmed_text(&format!(
|
||||
"({compressed_count} earlier messages not shown; compressed for context)"
|
||||
))
|
||||
);
|
||||
println!();
|
||||
}
|
||||
|
||||
for message in &messages_snapshot {
|
||||
match message.role {
|
||||
MessageRole::User => {
|
||||
if let Some(text) = message.content.as_text() {
|
||||
println!("{}", dimmed_text("You:"));
|
||||
println!("{text}");
|
||||
println!();
|
||||
}
|
||||
}
|
||||
MessageRole::Assistant => {
|
||||
if let Some(text) = message.content.as_text() {
|
||||
app.print_markdown(text)?;
|
||||
println!();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
println!("{}", dimmed_text("─── ↑ previous conversation ↑ ───"));
|
||||
println!();
|
||||
}
|
||||
}
|
||||
|
||||
loop {
|
||||
if self.abort_signal.aborted_ctrld() {
|
||||
break;
|
||||
@@ -330,6 +425,10 @@ Type ".help" for additional help.
|
||||
if exit {
|
||||
break;
|
||||
}
|
||||
if let Some(text) = self.ctx.write().pending_prefill.take() {
|
||||
self.editor
|
||||
.run_edit_commands(&[EditCommand::InsertString(text)]);
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
render_error(err);
|
||||
@@ -388,6 +487,14 @@ Type ".help" for additional help.
|
||||
editor = editor.with_buffer_editor(command, temp_file);
|
||||
}
|
||||
|
||||
if app.save_shell_history {
|
||||
let ctx = ctx.read();
|
||||
let history_path = paths::repl_history_file(&ctx.session);
|
||||
if let Ok(history) = FileBackedHistory::with_file(1000, history_path) {
|
||||
editor = editor.with_history(Box::new(history));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(editor)
|
||||
}
|
||||
|
||||
@@ -541,6 +648,120 @@ pub async fn run_repl_command(
|
||||
let (client_name, provider) = resolve_oauth_client(Some(client.name()), &clients)?;
|
||||
oauth::run_oauth_flow(&*provider, &client_name).await?;
|
||||
}
|
||||
".mcp" => match args {
|
||||
Some(args) => {
|
||||
let mut parts = args.splitn(2, char::is_whitespace);
|
||||
let sub = parts.next().unwrap_or("").trim();
|
||||
let rest = parts.next().map(str::trim).unwrap_or("");
|
||||
match sub {
|
||||
"auth" => {
|
||||
if rest.is_empty() {
|
||||
println!("Usage: .mcp auth <server_name>");
|
||||
} else {
|
||||
let server_name = rest;
|
||||
let server_spec = ctx
|
||||
.app
|
||||
.mcp_config
|
||||
.as_ref()
|
||||
.and_then(|c| c.mcp_servers.get(server_name))
|
||||
.cloned();
|
||||
match server_spec {
|
||||
None => {
|
||||
bail!("MCP server '{}' not found in mcp.json.", server_name)
|
||||
}
|
||||
Some(spec) if !spec.is_remote() => bail!(
|
||||
"MCP server '{}' uses stdio transport; \
|
||||
OAuth is only supported for http/sse servers.",
|
||||
server_name
|
||||
),
|
||||
Some(spec) => {
|
||||
let url = spec
|
||||
.url
|
||||
.as_deref()
|
||||
.expect("validated: remote spec has url");
|
||||
let client_id = spec
|
||||
.oauth
|
||||
.as_ref()
|
||||
.and_then(|o| o.client_id.as_deref());
|
||||
let callback_port =
|
||||
spec.oauth.as_ref().and_then(|o| o.callback_port);
|
||||
let redirect_host = spec
|
||||
.oauth
|
||||
.as_ref()
|
||||
.and_then(|o| o.redirect_host.as_deref());
|
||||
mcp::oauth::run_mcp_oauth_flow(
|
||||
server_name,
|
||||
url,
|
||||
client_id,
|
||||
callback_port,
|
||||
redirect_host,
|
||||
)
|
||||
.await?;
|
||||
println!("Authentication saved.");
|
||||
if ctx.app.config.mcp_server_support {
|
||||
let app = Arc::clone(&ctx.app.config);
|
||||
ctx.bootstrap_tools(
|
||||
app.as_ref(),
|
||||
true,
|
||||
abort_signal.clone(),
|
||||
)
|
||||
.await?;
|
||||
if ctx.tool_scope.mcp_runtime.get(server_name).is_some()
|
||||
{
|
||||
println!(
|
||||
"✓ MCP server '{server_name}' started and attached to the current context."
|
||||
);
|
||||
} else {
|
||||
println!(
|
||||
"MCP server '{server_name}' is not enabled in the current context. \
|
||||
Run `.mcp enable {server_name}` to attach it."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"enable" | "disable" => {
|
||||
if rest.is_empty() {
|
||||
println!("Usage: .mcp {sub} <server_name>");
|
||||
} else {
|
||||
ctx.toggle_mcp_server(sub, rest, abort_signal.clone())
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
_ => unknown_command()?,
|
||||
}
|
||||
}
|
||||
None => println!(
|
||||
r#"Usage:
|
||||
.mcp auth <server_name> # Authenticate with an MCP server via OAuth
|
||||
.mcp enable <server_name> # Enable a single MCP server in the current context
|
||||
.mcp disable <server_name> # Disable a single MCP server in the current context"#
|
||||
),
|
||||
},
|
||||
".tool" => match args {
|
||||
Some(args) => {
|
||||
let mut parts = args.splitn(2, char::is_whitespace);
|
||||
let sub = parts.next().unwrap_or("").trim();
|
||||
let rest = parts.next().map(str::trim).unwrap_or("");
|
||||
match sub {
|
||||
"enable" | "disable" => {
|
||||
if rest.is_empty() {
|
||||
println!("Usage: .tool {sub} <name>");
|
||||
} else {
|
||||
ctx.toggle_tool(sub, rest)?;
|
||||
}
|
||||
}
|
||||
_ => unknown_command()?,
|
||||
}
|
||||
}
|
||||
None => println!(
|
||||
r#"Usage:
|
||||
.tool enable <name> # Enable a single tool in the current context
|
||||
.tool disable <name> # Disable a single tool in the current context"#
|
||||
),
|
||||
},
|
||||
".prompt" => match args {
|
||||
Some(text) => {
|
||||
let app = Arc::clone(&ctx.app.config);
|
||||
@@ -632,6 +853,46 @@ pub async fn run_repl_command(
|
||||
session.set_autonaming(false);
|
||||
}
|
||||
}
|
||||
if let Some(session) = &ctx.session {
|
||||
let messages_snapshot: Vec<Message> = session
|
||||
.messages()
|
||||
.iter()
|
||||
.filter(|m| !m.role.is_system())
|
||||
.cloned()
|
||||
.collect();
|
||||
let compressed_count = session.compressed_messages().len();
|
||||
if !messages_snapshot.is_empty() || compressed_count > 0 {
|
||||
if compressed_count > 0 {
|
||||
println!(
|
||||
"{}",
|
||||
dimmed_text(&format!(
|
||||
"({compressed_count} earlier messages not shown — compressed for context)"
|
||||
))
|
||||
);
|
||||
println!();
|
||||
}
|
||||
for message in &messages_snapshot {
|
||||
match message.role {
|
||||
MessageRole::User => {
|
||||
if let Some(text) = message.content.as_text() {
|
||||
println!("{}", dimmed_text("You:"));
|
||||
println!("{text}");
|
||||
println!();
|
||||
}
|
||||
}
|
||||
MessageRole::Assistant => {
|
||||
if let Some(text) = message.content.as_text() {
|
||||
app.print_markdown(text)?;
|
||||
println!();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
println!("{}", dimmed_text("─── ↑ previous conversation ↑ ───"));
|
||||
println!();
|
||||
}
|
||||
}
|
||||
}
|
||||
".install" => {
|
||||
let trimmed = args.map(str::trim).unwrap_or("");
|
||||
@@ -686,6 +947,46 @@ pub async fn run_repl_command(
|
||||
let app = Arc::clone(&ctx.app.config);
|
||||
ctx.use_agent(app.as_ref(), agent_name, session_name, abort_signal.clone())
|
||||
.await?;
|
||||
if let Some(session) = &ctx.session {
|
||||
let messages_snapshot: Vec<Message> = session
|
||||
.messages()
|
||||
.iter()
|
||||
.filter(|m| !m.role.is_system())
|
||||
.cloned()
|
||||
.collect();
|
||||
let compressed_count = session.compressed_messages().len();
|
||||
if !messages_snapshot.is_empty() || compressed_count > 0 {
|
||||
if compressed_count > 0 {
|
||||
println!(
|
||||
"{}",
|
||||
dimmed_text(&format!(
|
||||
"({compressed_count} earlier messages not shown — compressed for context)"
|
||||
))
|
||||
);
|
||||
println!();
|
||||
}
|
||||
for message in &messages_snapshot {
|
||||
match message.role {
|
||||
MessageRole::User => {
|
||||
if let Some(text) = message.content.as_text() {
|
||||
println!("{}", dimmed_text("You:"));
|
||||
println!("{text}");
|
||||
println!();
|
||||
}
|
||||
}
|
||||
MessageRole::Assistant => {
|
||||
if let Some(text) = message.content.as_text() {
|
||||
app.print_markdown(text)?;
|
||||
println!();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
println!("{}", dimmed_text("─── ↑ previous conversation ↑ ───"));
|
||||
println!();
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
println!(r#"Usage: .agent <agent-name> [session-name] [key=value]..."#)
|
||||
@@ -799,6 +1100,15 @@ pub async fn run_repl_command(
|
||||
println!(r#"Usage: .empty session"#)
|
||||
}
|
||||
},
|
||||
".undo" => {
|
||||
if let Some(name) = graph::active_agent_graph_name(ctx) {
|
||||
bail!(
|
||||
"Graph-based agent '{name}' does not support .undo. \
|
||||
The graph manages its own state."
|
||||
);
|
||||
}
|
||||
ctx.undo_last_exchange()?;
|
||||
}
|
||||
".rebuild" => match args {
|
||||
Some("rag") => {
|
||||
ctx.rebuild_rag(abort_signal.clone()).await?;
|
||||
@@ -885,6 +1195,15 @@ pub async fn run_repl_command(
|
||||
println!("Usage: .set <key> <value>...")
|
||||
}
|
||||
},
|
||||
".reasoning" => match args {
|
||||
Some(level) => {
|
||||
let set_args = format!("reasoning_effort {level}");
|
||||
ctx.update(&set_args, abort_signal).await?;
|
||||
}
|
||||
None => {
|
||||
println!("Usage: .reasoning <level>")
|
||||
}
|
||||
},
|
||||
".delete" => match args {
|
||||
Some(args) => {
|
||||
ctx.delete(args)?;
|
||||
@@ -893,6 +1212,16 @@ pub async fn run_repl_command(
|
||||
println!("Usage: .delete <role|session|rag|macro|skill|agent-data>")
|
||||
}
|
||||
},
|
||||
".list" => match args {
|
||||
Some(args) => {
|
||||
ctx.list_assets(args.trim())?;
|
||||
}
|
||||
_ => {
|
||||
println!(
|
||||
"Usage: .list <roles|sessions|agents|rags|macros|skills|tools|mcp-servers>"
|
||||
)
|
||||
}
|
||||
},
|
||||
".copy" => {
|
||||
let output = match ctx
|
||||
.last_message
|
||||
@@ -1415,8 +1744,8 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repl_commands_has_49_entries() {
|
||||
assert_eq!(REPL_COMMANDS.len(), 49);
|
||||
fn repl_commands_has_57_entries() {
|
||||
assert_eq!(REPL_COMMANDS.len(), 57);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
+42
-11
@@ -316,6 +316,7 @@ fn sandbox_exists(name: &str) -> Result<bool> {
|
||||
fn create_sandbox(name: &str, kit_path: &Path, mixins: &[DiscoveredMixin]) -> Result<()> {
|
||||
info!("Creating sandbox '{name}'");
|
||||
let args = build_create_args(name, kit_path, mixins)?;
|
||||
debug!("sbx {}", args.join(" "));
|
||||
let status = Command::new(SBX_BINARY)
|
||||
.args(&args)
|
||||
.stdin(Stdio::inherit())
|
||||
@@ -342,6 +343,8 @@ fn build_create_args(
|
||||
|
||||
let mut args = vec![
|
||||
"create".to_string(),
|
||||
"--name".to_string(),
|
||||
name.to_string(),
|
||||
"--kit".to_string(),
|
||||
kit_str.to_string(),
|
||||
];
|
||||
@@ -357,8 +360,6 @@ fn build_create_args(
|
||||
}
|
||||
|
||||
args.push(SANDBOX_AGENT.to_string());
|
||||
args.push("--name".to_string());
|
||||
args.push(name.to_string());
|
||||
args.push(".".to_string());
|
||||
|
||||
Ok(args)
|
||||
@@ -369,10 +370,17 @@ fn copy_host_files(name: &str) -> Result<()> {
|
||||
let home_dir = dirs::home_dir().context("Could not determine home directory")?;
|
||||
|
||||
if config_dir.exists() {
|
||||
ensure_sandbox_dir(name, "/home/agent/.config")?;
|
||||
let src = format!("{}/", config_dir.display());
|
||||
let dest = format!("{name}:/home/agent/.config/");
|
||||
sbx_cp(&src, &dest)?;
|
||||
let sandbox_config_dir = "/home/agent/.config/coyote";
|
||||
ensure_sandbox_dir(name, sandbox_config_dir)?;
|
||||
let dest = format!("{name}:{sandbox_config_dir}/");
|
||||
for entry in fs::read_dir(&config_dir)
|
||||
.with_context(|| format!("Failed to read {}", config_dir.display()))?
|
||||
{
|
||||
let entry = entry?;
|
||||
let path = entry.path();
|
||||
sbx_cp(&path.display().to_string(), &dest)?;
|
||||
}
|
||||
chown_agent_recursive(name, sandbox_config_dir)?;
|
||||
} else {
|
||||
debug!(
|
||||
"Skipping config copy: {} does not exist",
|
||||
@@ -390,6 +398,7 @@ fn copy_host_files(name: &str) -> Result<()> {
|
||||
}
|
||||
let dest = format!("{name}:{dest_path}");
|
||||
sbx_cp(&password_file.display().to_string(), &dest)?;
|
||||
chown_agent_recursive(name, &dest_path)?;
|
||||
}
|
||||
Some(password_file) => {
|
||||
debug!(
|
||||
@@ -505,8 +514,9 @@ fn exec_run(name: &str, kit_path: &Path) -> Result<()> {
|
||||
let kit_str = kit_path
|
||||
.to_str()
|
||||
.ok_or_else(|| anyhow!("Kit path is not valid UTF-8: {}", kit_path.display()))?;
|
||||
debug!("sbx run --name {name} --kit {kit_str}");
|
||||
let status = Command::new(SBX_BINARY)
|
||||
.args(["run", name, "--kit", kit_str])
|
||||
.args(["run", "--name", name, "--kit", kit_str])
|
||||
.stdin(Stdio::inherit())
|
||||
.stdout(Stdio::inherit())
|
||||
.stderr(Stdio::inherit())
|
||||
@@ -520,6 +530,27 @@ fn exec_run(name: &str, kit_path: &Path) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn chown_agent_recursive(sandbox: &str, path: &str) -> Result<()> {
|
||||
let path_q = shell_words::quote(path);
|
||||
let cmd = format!("sudo chown -R agent:agent {path_q}");
|
||||
|
||||
debug!("sbx exec {sandbox}: {cmd}");
|
||||
|
||||
let status = Command::new(SBX_BINARY)
|
||||
.args(["exec", sandbox, "sh", "-c", &cmd])
|
||||
.stdin(Stdio::inherit())
|
||||
.stdout(Stdio::inherit())
|
||||
.stderr(Stdio::inherit())
|
||||
.status()
|
||||
.context("Failed to spawn `sbx exec` to chown copied files")?;
|
||||
|
||||
if !status.success() {
|
||||
bail!("Chowning '{path}' in sandbox failed: sbx exec exited with {status}");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -621,6 +652,8 @@ mod tests {
|
||||
args,
|
||||
vec![
|
||||
"create".to_string(),
|
||||
"--name".to_string(),
|
||||
"my-box".to_string(),
|
||||
"--kit".to_string(),
|
||||
"/cache/sbx-kit".to_string(),
|
||||
"--kit".to_string(),
|
||||
@@ -628,8 +661,6 @@ mod tests {
|
||||
"--kit".to_string(),
|
||||
dir_b.display().to_string(),
|
||||
"coyote".to_string(),
|
||||
"--name".to_string(),
|
||||
"my-box".to_string(),
|
||||
".".to_string(),
|
||||
]
|
||||
);
|
||||
@@ -646,11 +677,11 @@ mod tests {
|
||||
args,
|
||||
vec![
|
||||
"create".to_string(),
|
||||
"--name".to_string(),
|
||||
"box".to_string(),
|
||||
"--kit".to_string(),
|
||||
"/cache/sbx-kit".to_string(),
|
||||
"coyote".to_string(),
|
||||
"--name".to_string(),
|
||||
"box".to_string(),
|
||||
".".to_string(),
|
||||
]
|
||||
);
|
||||
|
||||
+33
-8
@@ -1,9 +1,11 @@
|
||||
use crate::config::paths;
|
||||
use colored::Colorize;
|
||||
use fancy_regex::Regex;
|
||||
use std::fs::File;
|
||||
use std::fs::{self, File};
|
||||
use std::io::{BufRead, BufReader, Seek, SeekFrom};
|
||||
use std::process;
|
||||
use std::time::Duration;
|
||||
use tokio::time::sleep;
|
||||
|
||||
pub async fn tail_logs(no_color: bool) {
|
||||
let re = Regex::new(r"^(?P<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3})\s+<(?P<opid>[^\s>]+)>\s+\[(?P<level>[A-Z]+)\]\s+(?P<logger>[^:]+):(?P<line>\d+)\s+-\s+(?P<message>.*)$").unwrap();
|
||||
@@ -16,20 +18,43 @@ pub async fn tail_logs(no_color: bool) {
|
||||
process::exit(1);
|
||||
};
|
||||
|
||||
let mut lines = reader.lines();
|
||||
let mut line_buf = String::new();
|
||||
|
||||
loop {
|
||||
if let Some(Ok(line)) = lines.next() {
|
||||
if no_color {
|
||||
println!("{line}");
|
||||
} else {
|
||||
let colored_line = colorize_log_line(&line, &re);
|
||||
println!("{colored_line}");
|
||||
match reader.read_line(&mut line_buf) {
|
||||
Ok(0) => {
|
||||
if file_was_rotated(&file_path, &mut reader) {
|
||||
let file = File::open(&file_path).expect("Cannot open file");
|
||||
reader = BufReader::new(file);
|
||||
}
|
||||
sleep(Duration::from_millis(100)).await;
|
||||
}
|
||||
Ok(_) => {
|
||||
let line = line_buf.trim_end();
|
||||
if no_color {
|
||||
println!("{line}");
|
||||
} else {
|
||||
let colored_line = colorize_log_line(line, &re);
|
||||
println!("{colored_line}");
|
||||
}
|
||||
line_buf.clear();
|
||||
}
|
||||
Err(_) => {
|
||||
line_buf.clear();
|
||||
sleep(Duration::from_millis(100)).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn file_was_rotated(path: &std::path::Path, reader: &mut BufReader<File>) -> bool {
|
||||
let current_pos = reader.stream_position().unwrap_or(0);
|
||||
match fs::metadata(path) {
|
||||
Ok(metadata) => metadata.len() < current_pos,
|
||||
Err(_) => true,
|
||||
}
|
||||
}
|
||||
|
||||
fn colorize_log_line(line: &str, re: &Regex) -> String {
|
||||
if let Some(caps) = re.captures(line).expect("Failed to capture log line") {
|
||||
let level = &caps["level"];
|
||||
|
||||
Reference in New Issue
Block a user