Compare commits
330 Commits
v0.7.3
...
7ea3044a37
| Author | SHA1 | Date | |
|---|---|---|---|
| 7ea3044a37 | |||
| ca03f6f9d7 | |||
| 34967f0d97 | |||
| a4365928d7 | |||
| d442dff423 | |||
| 9bb35c82a8 | |||
| ee16ada962 | |||
| 2a58d8398a | |||
| a4fe1ee956 | |||
| f74808c796 | |||
| 98983be609 | |||
| 1bb281b2a0 | |||
| 6c5f696f99 | |||
| 344bb51c9e | |||
| 371329ec9a | |||
| 6dfb9f0601 | |||
| c64494043f | |||
| 30d2ade7a9 | |||
| 6c2c6f9908 | |||
| dc86aaa835 | |||
| ddabba2dde | |||
| 0bb3da091b | |||
| a2b283783a | |||
| 1dc68ca875 | |||
| 227969f3cf | |||
| b32bcf8fbc | |||
| 07bd03625b | |||
| c85adfd00e | |||
| 5b1ddf1848 | |||
| 473ec251e0 | |||
| 402c5a1ec7 | |||
| 4f5ead8545 | |||
| 36cced560a | |||
| 0d6efbf1f3 | |||
| bbfb489a67 | |||
| 0f7548685c | |||
| fab266f7b9 | |||
| 48bb2fce87 | |||
| ad2ab6ed49 | |||
| bb2cad0526 | |||
| 0db5f634a4 | |||
| dbda5abdab | |||
| 3a040ae3bb | |||
| deb25f639f | |||
| 10c38fa612 | |||
| 3a734e27dc | |||
| 41200a71f6 | |||
| b19655087e | |||
| c13cb18d93 | |||
| 0925acf86a | |||
| f8cbb1549e | |||
| a46f6da0d8 | |||
| 7c9fb8eb71 | |||
| 223e7ca4c5 | |||
| 0fdb1bbc42 | |||
| 16cdf47101 | |||
| 6555ecfafc | |||
| a586ca40e2 | |||
| 435667fac8 | |||
| fd3385bad8 | |||
| 16adae7bc3 | |||
| 639f6e2a1a | |||
| cc4d2f6256 | |||
| d8d757b060 | |||
| 32a9861369 | |||
| 922fa05b06 | |||
| 4cc6bccf87 | |||
| de3012e664 | |||
| 3daac0b1cf | |||
| 4260088ed1 | |||
| cb24c7ac91 | |||
| 5fcba4c5ab | |||
| 024dd5ff59 | |||
| 0e931a472e | |||
| 3ff6e3cca9 | |||
| 2e30b19479 | |||
| 208ed838e6 | |||
| 8380ae5d7a | |||
| 97b902441e | |||
| 15df5be307 | |||
| 658f8f32dd | |||
| f3ee71d3f2 | |||
| 719b482be9 | |||
| f7b589ac2b | |||
| cea08d804e | |||
| 53cc3a27fe | |||
| 0f3cf511e0 | |||
| f8b965d801 | |||
| 2cb68846b6 | |||
| 1e18c7a7e2 | |||
| caeed16d36 | |||
| 7ab36dce90 | |||
| f8a72f819e | |||
| 306a880257 | |||
| 59cca849a8 | |||
| 42a1665960 | |||
| 687a4ea3bc | |||
| 77c1c2aa6f | |||
| 3d0bbd59d1 | |||
| 39f1511fea | |||
| b5b3dc5ba8 | |||
| ad8be61a3b | |||
| 4f4db10c8d | |||
| a430d59e9c | |||
| 5f1734d69a | |||
| a34adc5adf | |||
| 96c1d47d7f | |||
| 7701a02b16 | |||
| ece9cadad5 | |||
| 738f39917d | |||
| b95649177d | |||
| 6f977307e6 | |||
| 9a715b2fb2 | |||
| 930861d49b | |||
| 31987c9f94 | |||
| fe7401c935 | |||
| 543e62fe7d | |||
| 0ec8cd4d00 | |||
| a469a6cf06 | |||
| 0e67e0f85a | |||
| bf862d8021 | |||
| c070d151fa | |||
| 3147ad59f3 | |||
| f9d2adf33a | |||
| eaa224aeb9 | |||
| 81a81d035e | |||
| 5c5d70e4d0 | |||
| ad563d4263 | |||
| 016501ef4f | |||
| 0b36d17ea0 | |||
| faf92f9fe8 | |||
| 2c7abace37 | |||
| 3a7128f3de | |||
| 0b8bae64d1 | |||
| 9c4543ceb5 | |||
| 0b7bb7a816 | |||
| ee496e5792 | |||
| 05cb8548cf | |||
| 57d62087f5 | |||
| a1f8250f58 | |||
| 194849eaab | |||
| f8330523db | |||
| 2a7af1531d | |||
| 8f858a3d3c | |||
| 51211ab1a6 | |||
| 4dad7d6c78 | |||
| 1fa9886e7a | |||
| 2370525f38 | |||
| 3a131f19ee | |||
| f59286e7a7 | |||
| 79b0d044a8 | |||
| 423921276d | |||
| b0799e7fc6 | |||
| 1b4adec4c3 | |||
| de0d8114b3 | |||
| 113db42ff5 | |||
| 3715725cbb | |||
| f08d91936b | |||
| 76c2dde2aa | |||
| e9a53afc88 | |||
| 2d4b576977 | |||
| 9d70569878 | |||
| e08220f059 | |||
| a9179a53cc | |||
| d1c3adc565 | |||
| 10d49c86c4 | |||
| 562caeaa16 | |||
| 1ea5003c0c | |||
| 7175f86906 | |||
| 2541f574f6 | |||
| b3c327914a | |||
| 4bc7661efa | |||
| f075a6f0a3 | |||
| c2e8e85b32 | |||
| aff14c9b88 | |||
| 72e99734e6 | |||
| 1af148e767 | |||
| da3c766cfa | |||
| 181acf61d2 | |||
| ff472c61d9 | |||
| 83c13f32e8 | |||
| 108203f763 | |||
| 970705377a | |||
| 35018c1462 | |||
| 0f345a5042 | |||
| 68ec599793 | |||
| a9d5f8a4d7 | |||
| c9bc9952df | |||
| 80ae76b6ec | |||
| 57da3f43e8 | |||
| 365d4510a5 | |||
| 565b37c14a | |||
| 190c15d214 | |||
| faf8fdb213 | |||
| fdc38a0b18 | |||
| c7d72ac22d | |||
| c1a4d021a1 | |||
| 9cb4e4d1bc | |||
| 62ce4f34f8 | |||
| b914e90da5 | |||
| fdc312306d | |||
| 9852245469 | |||
| 2cb099e378 | |||
| fba8e26f5b | |||
| 60dc712bdd | |||
| ba6d8002e1 | |||
| c9781d0062 | |||
| 48a9f84d6c | |||
| b874be4b36 | |||
| 3d34d6e273 | |||
| 040ce15b55 | |||
| 411812875a | |||
| 06bacd47ad | |||
| 7056818808 | |||
| 67b4510d94 | |||
| 2e74619b03 | |||
| 727ff52ff7 | |||
| 33cb6aaf1f | |||
| 2dfab3d399 | |||
| bcbd0e7be1 | |||
| 8ccc61e831 | |||
| a1656da7a2 | |||
| 499d396802 | |||
| bdfc9ca062 | |||
| 120368178d | |||
| 783dc76285 | |||
| cf1f5d39a1 | |||
| beb4c54ea5 | |||
| 9573c88efd | |||
| 7b339e35f8 | |||
| ed3f4b23f8 | |||
| 8b2c23f598 | |||
| 5f227988bb | |||
| 82e2bcbce4 | |||
| 4277226ca1 | |||
| 21ccc7af86 | |||
| f1a2570d41 | |||
| e977864158 | |||
| 4b8085b142 | |||
| 832bc419dd | |||
| 0ceae6a98f | |||
| 922e4f4b1a | |||
| 7b68077f7a | |||
| 7f359af72c | |||
| 1330ff72ce | |||
| 288e1fa234 | |||
| 71f33cb87a | |||
| afeb634b94 | |||
| 72ad69b401 | |||
| c1ac4d9032 | |||
| 9f9ef10da9 | |||
| a44e58547e | |||
| 7d5e5fce76 | |||
| 610bebaae1 | |||
| aa1b7d57a4 | |||
| 2c8daca20c | |||
| a13f771925 | |||
| 0b23f1174b | |||
| f09a06365b | |||
| e9071c8b82 | |||
| 5959cbd809 | |||
| 19597735b8 | |||
| aa171c6e6d | |||
| 22939a53a9 | |||
| f076373859 | |||
| 528c3ae657 | |||
| e0e0f519fb | |||
| 8feb292738 | |||
| 17abfe9aa4 | |||
| 441e472328 | |||
| 89cf081749 | |||
| 872ac62e81 | |||
| 9de95ca21d | |||
| 3af07cabe8 | |||
| 5719ff2e79 | |||
| 84556cb706 | |||
| 0983868196 | |||
| 382926243c | |||
| 467afb6767 | |||
| 73356b4a76 | |||
| 34d4681b38 | |||
| aa980b0a96 | |||
| 397db60782 | |||
| 57c5c35c37 | |||
| 7ab9fea439 | |||
| 4c0514d8e9 | |||
| 2fb9d2fa86 | |||
| f57a134bc0 | |||
| 2ceb0808c8 | |||
| c9b90e8411 | |||
| 8d03b2fc72 | |||
| b172fe8fbf | |||
| bdd3aaa0ab | |||
| 64cbac0dd9 | |||
| 50903c3d03 | |||
| 680b71e13d | |||
| a410818015 | |||
| 6c5bc51a0a | |||
| 38d114808e | |||
| bb37513ef5 | |||
| 85533f665e | |||
| b790041d95 | |||
| bb5419967f | |||
| 21b00c6333 | |||
| 4050997d7b | |||
| 7d7477f4ec | |||
| 7d81b45f92 | |||
| 83f3790d2f | |||
| 4ad20c380d | |||
| a895da9e47 | |||
| 1bfd2b7370 | |||
| 6631ff53f2 | |||
| 6244e337b0 | |||
| d199e9ebe6 | |||
| ca5bfd6e8f | |||
| c8984cf91a | |||
| bf4422ed0d | |||
| e41fbed9cc | |||
| 4e6e8a845f | |||
| e24c056191 | |||
| b56fe7d3cd | |||
| f4c5d9f0d7 | |||
| f9dc61e906 | |||
| ed8dc34ff6 | |||
| a2b57caff5 | |||
| 19a680442d | |||
| 394f1f92a0 | |||
| 044f34b029 | |||
| a250fe98bb | |||
| a7c770120a |
@@ -0,0 +1,4 @@
|
||||
--artifact-server-path=./.act/artifacts
|
||||
--cache-server-path=./.act/cache
|
||||
--container-options --privileged
|
||||
--env ACT=true
|
||||
@@ -0,0 +1,10 @@
|
||||
[tool.commitizen]
|
||||
name = "cz_conventional_commits"
|
||||
tag_format = "v$version"
|
||||
version_scheme = "semver"
|
||||
version_provider = "cargo"
|
||||
update_changelog_on_bump = true
|
||||
major_version_zero = true
|
||||
|
||||
[tool.commitizen.hooks]
|
||||
pre-commit = "git add Cargo.toml Cargo.lock"
|
||||
@@ -0,0 +1 @@
|
||||
github: Dark-Alex-17
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
name: Blank Issue
|
||||
about: Create a blank issue.
|
||||
---
|
||||
@@ -0,0 +1,69 @@
|
||||
name: Bug Report
|
||||
description: Create a report to help us improve
|
||||
labels: bug
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: Thank you for filing a bug report!
|
||||
- type: textarea
|
||||
id: problem
|
||||
attributes:
|
||||
label: Summary
|
||||
description: >
|
||||
Please provide a short summary of the bug, along with any information
|
||||
you feel relevant to replicate the bug.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: reproduction-steps
|
||||
attributes:
|
||||
label: Reproduction Steps
|
||||
value: |
|
||||
I tried this:
|
||||
|
||||
1. `loki`
|
||||
|
||||
I expected this to happen:
|
||||
|
||||
Instead, this happened:
|
||||
- type: textarea
|
||||
id: loki-log
|
||||
attributes:
|
||||
label: Loki log
|
||||
description: Include the Loki log file to help diagnose the issue. (`loki --info` to see the log_path)
|
||||
value: |
|
||||
| OS | Log file location |
|
||||
| ------- | ----------------------------------------------------- |
|
||||
| Linux | `~/.cache/loki/loki.log` |
|
||||
| Mac | `~/Library/Logs/loki/loki.log` |
|
||||
| Windows | `C:\Users\<User>\AppData\Local\loki\loki.log` |
|
||||
|
||||
```
|
||||
please provide a copy of your loki log file here if possible; you may need to redact some of the lines
|
||||
```
|
||||
|
||||
- type: input
|
||||
id: platform
|
||||
attributes:
|
||||
label: Platform
|
||||
placeholder: Linux / macOS / Windows
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: terminal-emulator
|
||||
attributes:
|
||||
label: Terminal Emulator
|
||||
placeholder: wezterm 20220101-133340-7edc5b5a
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: loki-version
|
||||
attributes:
|
||||
label: Loki Version
|
||||
description: >
|
||||
Loki version (`loki --version` if using a release, `git describe` if building
|
||||
from main).
|
||||
**Make sure that you are using the [latest loki release](https://github.com/Dark-Alex-17/loki/releases) or a newer main build**
|
||||
placeholder: "loki 0.1.0"
|
||||
validations:
|
||||
required: true
|
||||
@@ -0,0 +1,13 @@
|
||||
---
|
||||
name: Enhancement
|
||||
about: Suggest an improvement
|
||||
title: ''
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
---
|
||||
|
||||
<!--
|
||||
Your enhancement may already be reported!
|
||||
Please search on the issue tracker before creating a new issue.
|
||||
If this is an idea for a feature, please open an "Idea" Discussion instead.
|
||||
-->
|
||||
@@ -0,0 +1,11 @@
|
||||
### AI assistance (if any):
|
||||
- List tools here and files touched by them
|
||||
|
||||
### Authorship & Understanding
|
||||
|
||||
- [ ] I wrote or heavily modified this code myself
|
||||
- [ ] I understand how it works end-to-end
|
||||
- [ ] I can maintain this code in the future
|
||||
- [ ] No undisclosed AI-generated code was used
|
||||
- [ ] If AI assistance was used, it is documented below
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- '*'
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
jobs:
|
||||
all:
|
||||
name: All
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- macos-latest
|
||||
- windows-latest
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
env:
|
||||
RUSTFLAGS: --deny warnings
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust Toolchain Components
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
|
||||
- name: Test
|
||||
run: cargo test --all
|
||||
|
||||
- name: Clippy
|
||||
run: cargo clippy --all --all-targets -- -D warnings
|
||||
|
||||
- name: Format
|
||||
run: cargo fmt --all --check
|
||||
@@ -0,0 +1,458 @@
|
||||
name: Create release
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: write
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
bump_type:
|
||||
description: "Specify the type of version bump"
|
||||
required: true
|
||||
default: "patch"
|
||||
type: choice
|
||||
options:
|
||||
- patch
|
||||
- minor
|
||||
- major
|
||||
|
||||
jobs:
|
||||
bump-version:
|
||||
name: bump-version
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Configure SSH for Git
|
||||
if: env.ACT != 'true'
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.RELEASE_BOT_SSH_KEY }}" > ~/.ssh/id_ed25519
|
||||
chmod 600 ~/.ssh/id_ed25519
|
||||
ssh-keyscan -H github.com >> ~/.ssh/known_hosts
|
||||
|
||||
- name: Checkout repository
|
||||
if: env.ACT != 'true'
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
ssh-key: ${{ secrets.RELEASE_BOT_SSH_KEY }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Checkout repository
|
||||
if: env.ACT == 'true'
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: "3.10"
|
||||
|
||||
- name: Install Commitizen
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install commitizen
|
||||
npm install -g conventional-changelog-cli
|
||||
|
||||
- name: Configure Git user
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
|
||||
- name: Bump version with Commitizen
|
||||
run: |
|
||||
cz bump --yes --increment ${{ github.event.inputs.bump_type }}
|
||||
|
||||
- name: Amend commit message to include '[skip ci]'
|
||||
run: |
|
||||
git commit --amend --no-edit -m "$(git log -1 --pretty=%B) [skip ci]"
|
||||
|
||||
- name: Install Rust stable
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
|
||||
- name: Get the new version tag
|
||||
id: version
|
||||
run: |
|
||||
mkdir -p artifacts
|
||||
NEW_TAG=$(cz version --project)
|
||||
echo "New version: $NEW_TAG"
|
||||
echo "version=$NEW_TAG" >> $GITHUB_ENV
|
||||
echo "$NEW_TAG" > artifacts/release-version
|
||||
|
||||
- name: Get the previous version tag
|
||||
id: prev_version
|
||||
run: |
|
||||
PREV_TAG=$(git describe --tags --abbrev=0 ${GITHUB_SHA}^)
|
||||
echo "Previous tag: $PREV_TAG"
|
||||
echo "prev_version=$PREV_TAG" >> $GITHUB_ENV
|
||||
|
||||
- name: Bump Cargo.toml version
|
||||
shell: bash
|
||||
working-directory: ${{ github.workspace }}
|
||||
env:
|
||||
VERSION: ${{ env.version }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
: "${VERSION:?env.version is empty}"
|
||||
|
||||
# Ignore Act's local artifact dir noise
|
||||
echo artifacts/ >> .git/info/exclude || true
|
||||
|
||||
# Edit the version line right after name="loki"
|
||||
sed -E -i '
|
||||
/^[[:space:]]*name[[:space:]]*=[[:space:]]*"loki"[[:space:]]*$/ {
|
||||
n
|
||||
s|^[[:space:]]*version[[:space:]]*=[[:space:]]*"[^"]*"|version = "'"$VERSION"'"|
|
||||
}
|
||||
' Cargo.toml
|
||||
|
||||
cargo update || true
|
||||
|
||||
# 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
|
||||
|
||||
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"
|
||||
else
|
||||
echo "No changes to commit (already at $VERSION)"
|
||||
fi
|
||||
|
||||
- name: Generate changelog for the version bump
|
||||
id: changelog
|
||||
run: |
|
||||
conventional-changelog -p conventionalcommits -i CHANGELOG.md --from ${{ env.prev_version }} --to v${{ env.version }} > artifacts/changelog.md
|
||||
|
||||
- name: Push changes
|
||||
if: env.ACT != 'true'
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
git push origin --follow-tags
|
||||
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
|
||||
- name: Upload the changed Cargo files (Act)
|
||||
if: env.ACT == 'true'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: bumped-cargo-files
|
||||
path: |
|
||||
Cargo.toml
|
||||
Cargo.lock
|
||||
|
||||
publish-github-release:
|
||||
name: build-release
|
||||
needs: [bump-version]
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
RUST_BACKTRACE: 1
|
||||
BUILD_CMD: cargo
|
||||
strategy:
|
||||
fail-fast: true
|
||||
matrix:
|
||||
include:
|
||||
- target: aarch64-unknown-linux-musl
|
||||
os: ubuntu-latest
|
||||
use-cross: true
|
||||
cargo-flags: ""
|
||||
- target: aarch64-apple-darwin
|
||||
os: macos-latest
|
||||
use-cross: true
|
||||
cargo-flags: ""
|
||||
- target: aarch64-pc-windows-msvc
|
||||
os: windows-latest
|
||||
use-cross: true
|
||||
cargo-flags: ""
|
||||
- target: x86_64-apple-darwin
|
||||
os: macos-latest
|
||||
cargo-flags: ""
|
||||
- target: x86_64-pc-windows-msvc
|
||||
os: windows-latest
|
||||
cargo-flags: ""
|
||||
- target: x86_64-unknown-linux-musl
|
||||
os: ubuntu-latest
|
||||
use-cross: true
|
||||
cargo-flags: ""
|
||||
- target: x86_64-unknown-linux-gnu
|
||||
os: ubuntu-latest
|
||||
cargo-flags: ""
|
||||
|
||||
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: Download all artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
merge-multiple: true
|
||||
|
||||
- name: Ensure repository is up-to-date
|
||||
if: env.ACT != 'true'
|
||||
run: |
|
||||
git fetch --all
|
||||
git pull
|
||||
|
||||
- name: Set environment variables
|
||||
shell: bash
|
||||
run: |
|
||||
release_version="$(cat ./artifacts/release-version)"
|
||||
echo "RELEASE_VERSION=$release_version" >> $GITHUB_ENV
|
||||
|
||||
- name: Validate release environment variables
|
||||
run: |
|
||||
echo "Release version: ${{ env.RELEASE_VERSION }}"
|
||||
echo "Changelog body: $(cat artifacts/changelog.md)"
|
||||
|
||||
- name: Get bumped Cargo files (Act)
|
||||
if: env.ACT == 'true'
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: bumped-cargo-files
|
||||
path: ${{ github.workspace }}
|
||||
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
name: Set Rust toolchain
|
||||
with:
|
||||
targets: ${{ matrix.target }}
|
||||
|
||||
- name: Install cross
|
||||
if: matrix.use-cross
|
||||
uses: taiki-e/install-action@v2
|
||||
with:
|
||||
tool: cross
|
||||
|
||||
- name: Overwrite build command env variable
|
||||
if: matrix.use-cross
|
||||
shell: bash
|
||||
run: echo "BUILD_CMD=cross" >> $GITHUB_ENV
|
||||
|
||||
- name: Install latest LLVM/Clang
|
||||
if: matrix.os == 'ubuntu-latest'
|
||||
run: |
|
||||
wget https://apt.llvm.org/llvm.sh
|
||||
chmod +x llvm.sh
|
||||
# omit the version to get the latest stable for your Ubuntu (24.04 "noble" on ubuntu-latest)
|
||||
sudo ./llvm.sh all
|
||||
# ensure libclang dev package is present (adjust the "22" if a newer major exists)
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y libclang-20-dev libclang-dev
|
||||
|
||||
- name: Show Version Information (Rust, cargo, GCC)
|
||||
shell: bash
|
||||
run: |
|
||||
gcc --version || true
|
||||
rustup -V
|
||||
rustup toolchain list
|
||||
rustup default
|
||||
cargo -V
|
||||
rustc -V
|
||||
|
||||
- name: Build
|
||||
shell: bash
|
||||
run: $BUILD_CMD build --locked --release --target=${{ matrix.target }} ${{ matrix.cargo-flags }}
|
||||
|
||||
- name: Verify file
|
||||
shell: bash
|
||||
run: |
|
||||
file target/${{ matrix.target }}/release/loki
|
||||
|
||||
- name: Test
|
||||
if: matrix.target != 'aarch64-apple-darwin' && matrix.target != 'aarch64-pc-windows-msvc'
|
||||
shell: bash
|
||||
run: |
|
||||
set -euxo pipefail
|
||||
if [[ "${{ matrix.use-cross || 'false' }}" == 'true' ]]; then
|
||||
cross test --release --locked --target=${{ matrix.target }} --verbose
|
||||
else
|
||||
cargo test --release --locked --target=${{ matrix.target }} --verbose
|
||||
fi
|
||||
|
||||
- name: Build Archive
|
||||
shell: bash
|
||||
id: package
|
||||
env:
|
||||
target: ${{ matrix.target }}
|
||||
run: |
|
||||
set -euxo pipefail
|
||||
|
||||
bin=${GITHUB_REPOSITORY##*/}
|
||||
dist_dir=`pwd`/dist
|
||||
name=$bin-$target
|
||||
executable=target/$target/release/$bin
|
||||
|
||||
if [[ "$RUNNER_OS" == "Windows" ]]; then
|
||||
executable=$executable.exe
|
||||
fi
|
||||
|
||||
mkdir $dist_dir
|
||||
cp $executable $dist_dir
|
||||
cd $dist_dir
|
||||
|
||||
if [[ "$RUNNER_OS" == "Windows" ]]; then
|
||||
archive=$dist_dir/$name.zip
|
||||
sha=$dist_dir/$name.sha256
|
||||
7z a $archive *
|
||||
certutil -hashfile $archive sha256 | grep -E [A-Fa-f0-9]{64} > $sha
|
||||
echo "archive=dist/$name.zip" >> $GITHUB_OUTPUT
|
||||
echo "sha=dist/$name.sha256" >> $GITHUB_OUTPUT
|
||||
else
|
||||
archive=$dist_dir/$name.tar.gz
|
||||
sha=$dist_dir/$name.sha256
|
||||
tar -czf $archive *
|
||||
shasum -a 256 $archive > $sha
|
||||
echo "archive=dist/$name.tar.gz" >> $GITHUB_OUTPUT
|
||||
echo "sha=dist/$name.sha256" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Publish Archive and SHA
|
||||
if: env.ACT != 'true'
|
||||
uses: softprops/action-gh-release@v2
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
files: |
|
||||
${{ steps.package.outputs.archive }}
|
||||
${{ steps.package.outputs.sha }}
|
||||
tag_name: v${{ env.RELEASE_VERSION }}
|
||||
name: "v${{ env.RELEASE_VERSION }}"
|
||||
body_path: artifacts/changelog.md
|
||||
prerelease: false
|
||||
|
||||
- name: Add artifacts
|
||||
shell: bash
|
||||
run: |
|
||||
[[ -d artifacts ]] || mkdir -p artifacts
|
||||
cp ${{ steps.package.outputs.archive }} artifacts/
|
||||
cp ${{ steps.package.outputs.sha }} artifacts/
|
||||
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: artifacts-v${{ env.RELEASE_VERSION }}-${{ matrix.target }}
|
||||
path: artifacts
|
||||
overwrite: true
|
||||
|
||||
publish-homebrew-formula:
|
||||
needs: [publish-github-release]
|
||||
name: Update Homebrew formulas
|
||||
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: Get release artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
merge-multiple: true
|
||||
|
||||
- name: Set release assets and version
|
||||
shell: bash
|
||||
run: |
|
||||
# Set environment variables
|
||||
macos_sha="$(cat ./artifacts/loki-x86_64-apple-darwin.sha256 | awk '{print $1}')"
|
||||
echo "MACOS_SHA=$macos_sha" >> $GITHUB_ENV
|
||||
macos_sha_arm="$(cat ./artifacts/loki-aarch64-apple-darwin.sha256 | awk '{print $1}')"
|
||||
echo "MACOS_SHA_ARM=$macos_sha_arm" >> $GITHUB_ENV
|
||||
linux_sha="$(cat ./artifacts/loki-x86_64-unknown-linux-musl.sha256 | awk '{print $1}')"
|
||||
echo "LINUX_SHA=$linux_sha" >> $GITHUB_ENV
|
||||
release_version="$(cat ./artifacts/release-version)"
|
||||
echo "RELEASE_VERSION=$release_version" >> $GITHUB_ENV
|
||||
|
||||
- name: Validate release environment variables
|
||||
run: |
|
||||
echo "Release SHA macos: ${{ env.MACOS_SHA }}"
|
||||
echo "Release SHA macos-arm: ${{ env.MACOS_SHA_ARM }}"
|
||||
echo "Release SHA linux musl: ${{ env.LINUX_SHA }}"
|
||||
echo "Release version: ${{ env.RELEASE_VERSION }}"
|
||||
|
||||
- name: Execute Homebrew packaging script
|
||||
if: env.ACT != 'true'
|
||||
run: |
|
||||
# run packaging script
|
||||
python "./deployment/homebrew/packager.py" ${{ env.RELEASE_VERSION }} "./deployment/homebrew/loki.rb.template" "./loki.rb" ${{ env.MACOS_SHA }} ${{ env.MACOS_SHA_ARM }} ${{ env.LINUX_SHA }}
|
||||
|
||||
- name: Push changes to Homebrew tap
|
||||
if: env.ACT != 'true'
|
||||
env:
|
||||
TOKEN: ${{ secrets.LOKI_GITHUB_TOKEN }}
|
||||
run: |
|
||||
# push to Git
|
||||
git config --global user.name "Dark-Alex-17"
|
||||
git config --global user.email "alex.j.tusa@gmail.com"
|
||||
git clone https://Dark-Alex-17:${{ secrets.LOKI_GITHUB_TOKEN }}@github.com/Dark-Alex-17/homebrew-loki.git
|
||||
rm homebrew-loki/Formula/loki.rb
|
||||
cp loki.rb homebrew-loki/Formula
|
||||
cd homebrew-loki
|
||||
git add .
|
||||
git diff-index --quiet HEAD || git commit -am "Update formula for Loki release ${{ env.RELEASE_VERSION }}"
|
||||
git push https://$TOKEN@github.com/Dark-Alex-17/homebrew-loki.git
|
||||
|
||||
publish-crate:
|
||||
needs: publish-github-release
|
||||
name: Publish Crate
|
||||
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
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Get bumped Cargo files (Act)
|
||||
if: env.ACT == 'true'
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: bumped-cargo-files
|
||||
path: ${{ github.workspace }}
|
||||
|
||||
- name: Ensure repository is up-to-date
|
||||
if: env.ACT != 'true'
|
||||
run: |
|
||||
git fetch --all
|
||||
git pull
|
||||
|
||||
- name: Install Rust stable
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
|
||||
- uses: katyo/publish-crates@v2
|
||||
if: env.ACT != 'true'
|
||||
with:
|
||||
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
||||
@@ -0,0 +1,7 @@
|
||||
/target
|
||||
/tmp
|
||||
/.env
|
||||
!cli/**
|
||||
.idea/
|
||||
/loki.iml
|
||||
/.idea/
|
||||
@@ -0,0 +1 @@
|
||||
{"type":"rust","build":"cargo build","test":"cargo test","check":"cargo check","_detected_by":"heuristic","_cached_at":"2026-04-13T13:36:33-06:00"}
|
||||
@@ -0,0 +1,8 @@
|
||||
repos:
|
||||
- hooks:
|
||||
- id: commitizen
|
||||
- id: commitizen-branch
|
||||
stages:
|
||||
- pre-push
|
||||
repo: https://github.com/commitizen-tools/commitizen
|
||||
rev: v3.30.0
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
## v0.3.0 (2026-04-02)
|
||||
|
||||
### Feat
|
||||
|
||||
- Added `todo__clear` function to the todo system and updated REPL commands to have a .clear todo as well for significant changes in agent direction
|
||||
- Added available tools to prompts for sisyphus and code-reviewer agent families
|
||||
- Added available tools to coder prompt
|
||||
- Improved token efficiency when delegating from sisyphus -> coder
|
||||
- modified sisyphus agents to use the new ddg-search MCP server for web searches instead of built-in model searches
|
||||
- Added support for specifying a custom response to multiple-choice prompts when nothing suits the user's needs
|
||||
- Supported theming in the inquire prompts in the REPL
|
||||
- Added the duckduckgo-search MCP server for searching the web (in addition to the built-in tools for web searches)
|
||||
- Support for Gemini OAuth
|
||||
- Support authenticating or refreshing OAuth for supported clients from within the REPL
|
||||
- Allow first-runs to select OAuth for supported providers
|
||||
- Support OAuth authentication flows for Claude
|
||||
- Improved MCP server spinup and spindown when switching contexts or settings in the REPL: Modify existing config rather than stopping all servers always and re-initializing if unnecessary
|
||||
- Allow the explore agent to run search queries for understanding docs or API specs
|
||||
- Allow the oracle to perform web searches for deeper research
|
||||
- Added web search support to the main sisyphus agent to answer user queries
|
||||
- Created a CodeRabbit-style code-reviewer agent
|
||||
- Added configuration option in agents to indicate the timeout for user input before proceeding (defaults to 5 minutes)
|
||||
- Added support for sub-agents to escalate user interaction requests from any depth to the parent agents for user interactions
|
||||
- built-in user interaction tools to remove the need for the list/confirm/etc prompts in prompt tools and to enhance user interactions in Loki
|
||||
- Experimental update to sisyphus to use the new parallel agent spawning system
|
||||
- Added an agent configuration property that allows auto-injecting sub-agent spawning instructions (when using the built-in sub-agent spawning system)
|
||||
- Auto-dispatch support of sub-agents and support for the teammate pattern between subagents
|
||||
- Full passive task queue integration for parallelization of subagents
|
||||
- Implemented initial scaffolding for built-in sub-agent spawning tool call operations
|
||||
- Initial models for agent parallelization
|
||||
- Added interactive prompting between the LLM and the user in Sisyphus using the built-in Bash utils scripts
|
||||
|
||||
### Fix
|
||||
|
||||
- Clarified user text input interaction
|
||||
- recursion bug with similarly named Bash search functions in the explore agent
|
||||
- updated the error for unauthenticated oauth to include the REPL .authenticated command
|
||||
- Corrected a bug in the coder agent that wasn't outputting a summary of the changes made, so the parent Sisyphus agent has no idea if the agent worked or not
|
||||
- Claude code system prompt injected into claude requests to make them valid once again
|
||||
- Do not inject tools when models don't support them; detect this conflict before API calls happen
|
||||
- The REPL .authenticate command works from within sessions, agents, and roles with pre-configured models
|
||||
- Implemented the path normalization fix for the oracle and explore agents
|
||||
- Updated the atlassian MCP server endpoint to account for future deprecation
|
||||
- Fixed a bug in the coder agent that was causing the agent to create absolute paths from the current directory
|
||||
- the updated regex for secrets injection broke MCP server secrets interpolation because the regex greedily matched on new lines, replacing too much content. This fix just ignores commented out lines in YAML files by skipping commented out lines.
|
||||
- Don't try to inject secrets into commented-out lines in the config
|
||||
- Removed top_p parameter from some agents so they can work across model providers
|
||||
- Improved sub-agent stdout and stderr output for users to follow
|
||||
- Inject agent variables into environment variables for global tool calls when invoked from agents to modify global tool behavior
|
||||
- Removed the unnecessary execute_commands tool from the oracle agent
|
||||
- Added auto_confirm to the coder agent so sub-agent spawning doesn't freeze
|
||||
- Fixed a bug in the new supervisor and todo built-ins that was causing errors with OpenAI models
|
||||
- Added condition to sisyphus to always output a summary to clearly indicate completion
|
||||
- Updated the sisyphus prompt to explicitly tell it to delegate to the coder agent when it wants to write any code at all except for trivial changes
|
||||
- Added back in the auto_confirm variable into sisyphus
|
||||
- Removed the now unnecessary is_stale_response that was breaking auto-continuing with parallel agents
|
||||
- Bypassed enabled_tools for user interaction tools so if function calling is enabled at all, the LLM has access to the user interaction tools when in REPL mode
|
||||
- When parallel agents run, only write to stdout from the parent and only display the parent's throbber
|
||||
- Forgot to implement support for failing a task and keep all dependents blocked
|
||||
- Clean up orphaned sub-agents when the parent agent
|
||||
- Fixed the bash prompt utils so that they correctly show output when being run by a tool invocation
|
||||
- Forgot to automatically add the bidirectional communication back up to parent agents from sub-agents (i.e. need to be able to check inbox and send messages)
|
||||
- Agent delegation tools were not being passed into the {{__tools__}} placeholder so agents weren't delegating to subagents
|
||||
|
||||
### Refactor
|
||||
|
||||
- Made the oauth module more generic so it can support loopback OAuth (not just manual)
|
||||
- Changed the default session name for Sisyphus to temp (to require users to explicitly name sessions they wish to save)
|
||||
- Updated the sisyphus agent to use the built-in user interaction tools instead of custom bash-based tools
|
||||
- Cleaned up some left-over implementation stubs
|
||||
|
||||
## v0.2.0 (2026-02-14)
|
||||
|
||||
### Feat
|
||||
|
||||
- Simplified sisyphus prompt to improve functionality
|
||||
- Supported the injection of RAG sources into the prompt, not just via the `.sources rag` command in the REPL so models can directly reference the documents that supported their responses
|
||||
- Created the Sisyphus agent to make Loki function like Claude Code, Gemini, Codex, etc.
|
||||
- Created the Oracle agent to handle high-level architectural decisions and design questions about a given codebase
|
||||
- Updated the coder agent to be much more task-focused and to be delegated to by Sisyphus
|
||||
- Created the explore agent for exploring codebases to help answer questions
|
||||
- Use the official atlassian MCP server for the jira-helper agent
|
||||
- Created fs_glob to enable more targeted file exploration utilities
|
||||
- Created a new tool 'fs_grep' to search a given file's contents for relevant lines to reduce token usage for smaller models
|
||||
- Created the new fs_read tool to enable controlled reading of a file
|
||||
- Let agent level variables be defined to bypass guard protections for tool invocations
|
||||
- Implemented a built-in task management system to help smaller LLMs complete larger multistep tasks and minimize context drift
|
||||
- Improved tool and MCP invocation error handling by returning stderr to the model when it is available
|
||||
- Added variable interpolation for conversation starters in agents
|
||||
- Implemented retry logic for failed tool invocations so the LLM can learn from the result and try again; Also implemented chain loop detection to prevent loops
|
||||
- Added gemini-3-pro to the supported vertexai models
|
||||
- Added an environment variable that lets users bypass guard operations in bash scripts. This is useful for agent routing
|
||||
- Added support for thought-signatures for Gemini 3+ models
|
||||
|
||||
### Fix
|
||||
|
||||
- Improved continuation prompt to not make broad todo-items
|
||||
- Allow auto-continuation to work in agents after a session is compressed and if there's still unfinish items in the to-do list
|
||||
- fs_ls and fs_cat outputs should always redirect to "$LLM_OUTPUT" including on errors.
|
||||
- Claude tool calls work incorrectly when tool doesn't require any arguments or flags; would provide an empty JSON object or error on no args
|
||||
- Fixed a bug where --agent-variable values were not being passed to the agents
|
||||
|
||||
## v0.1.3 (2025-12-13)
|
||||
|
||||
### Feat
|
||||
|
||||
- Improved MCP implementation to minimize the tokens needed to utilize it so it doesn't quickly overwhelm the token space for a given model
|
||||
|
||||
## v0.1.2 (2025-11-08)
|
||||
|
||||
### Refactor
|
||||
|
||||
- Gave the GitHub MCP server a default placeholder value that doesn't require the vault
|
||||
|
||||
## v0.1.1 (2025-11-08)
|
||||
|
||||
## v0.1.0 (2025-11-07)
|
||||
|
||||
### Refactor
|
||||
|
||||
- Updated to the most recent Rust version with 2024 syntax
|
||||
|
||||
## v0.0.1 (2025-11-07)
|
||||
|
||||
### Feat
|
||||
|
||||
- Added the agents directory to sysinfo output
|
||||
- Added built-in macros
|
||||
- Updated the example role configuration file to also have the prompt field
|
||||
- Updated the code role
|
||||
- Secret injection as environment variables into agent tools
|
||||
- Removed the server functionality
|
||||
- Require Vault set up for first-time setup so all passed in secrets can be encrypted right off the bat
|
||||
- Added static completions via a --completions flag
|
||||
- Support for secret injection into the global config file (API keys, for example)
|
||||
- Improved MCP handling toggle handling
|
||||
- Secret injection into the MCP configuration
|
||||
- added REPL support for interacting with the Loki vault
|
||||
- Integrated gman with Loki to create a vault and added flags to configure the Loki vault
|
||||
- Added a default session to the jira helper to make interaction more natural
|
||||
- Created the repo-analyzer role
|
||||
- Created the coder and sql agents
|
||||
- Cleaned the built-in functions to not have leftover dependencies
|
||||
- Created additional built-in roles for slack, repo analysis, and github
|
||||
- Install built-in agents
|
||||
- Embedded baseline MCP config and global tools
|
||||
|
||||
### Fix
|
||||
|
||||
- Corrected a typo for sourcing the bash utility script in some agent definitions
|
||||
|
||||
### Refactor
|
||||
|
||||
- Changed the name of the summary_prompt setting to summary_context_prompt
|
||||
- Renamed summarize_prompt setting to summarization_prompt
|
||||
- Renamed the compress_threshold setting to compression_threshold
|
||||
- Migrated around the location of some of the more large documents for documentation
|
||||
- Factored out the macros structs from the large config module
|
||||
- Refactored mcp_servers and function_calling to mcp_server_support and function_calling_support to make the purpose of the fields more clear
|
||||
- Refactored the use_mcp_servers field to enabled_mcp_servers to make the purpose of the field more clear
|
||||
- Refactored use_tools field to enabled_tools field to make the use of the field more clear
|
||||
- Removed the use of the tools.txt file and added tool visibility declarations to the global configuration file
|
||||
- Agents that depend on global tools now have all binaries compiled and stored in the agent's bin directory so multiple agents can run at once
|
||||
- Removed the git MCP server and used the newer, better mcp-server-docker for local docker integration
|
||||
- Renamed the argument for the --completions flag to SHELL
|
||||
- Updated the instructions for the jira-helper agent
|
||||
- Modified the default PS1 look
|
||||
- Fixed a linting issue for Windows builds
|
||||
- Changed the name of agent_prelude to agent_session to make its purpose more clear
|
||||
- Removed leftover javascript function support; will not implement
|
||||
@@ -0,0 +1,128 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
We as members, contributors, and leaders pledge to make participation in our
|
||||
community a harassment-free experience for everyone, regardless of age, body
|
||||
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||
identity and expression, level of experience, education, socio-economic status,
|
||||
nationality, personal appearance, race, religion, or sexual identity
|
||||
and orientation.
|
||||
|
||||
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||
diverse, inclusive, and healthy community.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to a positive environment for our
|
||||
community include:
|
||||
|
||||
* Demonstrating empathy and kindness toward other people
|
||||
* Being respectful of differing opinions, viewpoints, and experiences
|
||||
* Giving and gracefully accepting constructive feedback
|
||||
* Accepting responsibility and apologizing to those affected by our mistakes,
|
||||
and learning from the experience
|
||||
* Focusing on what is best not just for us as individuals, but for the
|
||||
overall community
|
||||
|
||||
Examples of unacceptable behavior include:
|
||||
|
||||
* The use of sexualized language or imagery, and sexual attention or
|
||||
advances of any kind
|
||||
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or email
|
||||
address, without their explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Enforcement Responsibilities
|
||||
|
||||
Community leaders are responsible for clarifying and enforcing our standards of
|
||||
acceptable behavior and will take appropriate and fair corrective action in
|
||||
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||
or harmful.
|
||||
|
||||
Community leaders have the right and responsibility to remove, edit, or reject
|
||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||
decisions when appropriate.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies within all community spaces, and also applies when
|
||||
an individual is officially representing the community in public spaces.
|
||||
Examples of representing our community include using an official e-mail address,
|
||||
posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported to the community leaders responsible for enforcement at
|
||||
alex.j.tusa@gmail.com.
|
||||
All complaints will be reviewed and investigated promptly and fairly.
|
||||
|
||||
All community leaders are obligated to respect the privacy and security of the
|
||||
reporter of any incident.
|
||||
|
||||
## Enforcement Guidelines
|
||||
|
||||
Community leaders will follow these Community Impact Guidelines in determining
|
||||
the consequences for any action they deem in violation of this Code of Conduct:
|
||||
|
||||
### 1. Correction
|
||||
|
||||
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||
unprofessional or unwelcome in the community.
|
||||
|
||||
**Consequence**: A private, written warning from community leaders, providing
|
||||
clarity around the nature of the violation and an explanation of why the
|
||||
behavior was inappropriate. A public apology may be requested.
|
||||
|
||||
### 2. Warning
|
||||
|
||||
**Community Impact**: A violation through a single incident or series
|
||||
of actions.
|
||||
|
||||
**Consequence**: A warning with consequences for continued behavior. No
|
||||
interaction with the people involved, including unsolicited interaction with
|
||||
those enforcing the Code of Conduct, for a specified period of time. This
|
||||
includes avoiding interactions in community spaces as well as external channels
|
||||
like social media. Violating these terms may lead to a temporary or
|
||||
permanent ban.
|
||||
|
||||
### 3. Temporary Ban
|
||||
|
||||
**Community Impact**: A serious violation of community standards, including
|
||||
sustained inappropriate behavior.
|
||||
|
||||
**Consequence**: A temporary ban from any sort of interaction or public
|
||||
communication with the community for a specified period of time. No public or
|
||||
private interaction with the people involved, including unsolicited interaction
|
||||
with those enforcing the Code of Conduct, is allowed during this period.
|
||||
Violating these terms may lead to a permanent ban.
|
||||
|
||||
### 4. Permanent Ban
|
||||
|
||||
**Community Impact**: Demonstrating a pattern of violation of community
|
||||
standards, including sustained inappropriate behavior, harassment of an
|
||||
individual, or aggression toward or disparagement of classes of individuals.
|
||||
|
||||
**Consequence**: A permanent ban from any sort of public interaction within
|
||||
the community.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 2.0, available at
|
||||
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
||||
|
||||
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
||||
enforcement ladder](https://github.com/mozilla/diversity).
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
|
||||
For answers to common questions about this code of conduct, see the FAQ at
|
||||
https://www.contributor-covenant.org/faq. Translations are available at
|
||||
https://www.contributor-covenant.org/translations.
|
||||
@@ -0,0 +1,88 @@
|
||||
# Contributing
|
||||
Contributors are very welcome! **No contribution is too small and all contributions are valued.**
|
||||
|
||||
## Rust
|
||||
You'll need to have the stable Rust toolchain installed in order to develop Loki.
|
||||
|
||||
The Rust toolchain (stable) can be installed via rustup using the following command:
|
||||
|
||||
```shell
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
||||
```
|
||||
|
||||
This will install `rustup`, `rustc` and `cargo`. For more information, refer to the [official Rust installation documentation](https://www.rust-lang.org/tools/install).
|
||||
|
||||
## Commitizen
|
||||
[Commitizen](https://github.com/commitizen-tools/commitizen?tab=readme-ov-file) is a nifty tool that helps us write better commit messages. It ensures that our
|
||||
commits have a consistent style and makes it easier to generate CHANGELOGS. Additionally,
|
||||
Commitizen is used to run pre-commit checks to enforce style constraints.
|
||||
|
||||
To install `commitizen` and the `pre-commit` prerequisite, run the following command:
|
||||
|
||||
```shell
|
||||
python3 -m pip install commitizen pre-commit
|
||||
```
|
||||
|
||||
### Commitizen Quick Guide
|
||||
To see an example commit to get an idea for the Commitizen style, run:
|
||||
|
||||
```shell
|
||||
cz example
|
||||
```
|
||||
|
||||
To see the allowed types of commits and their descriptions, run:
|
||||
|
||||
```shell
|
||||
cz info
|
||||
```
|
||||
|
||||
If you'd like to create a commit using Commitizen with an interactive prompt to help you get
|
||||
comfortable with the style, use:
|
||||
|
||||
```shell
|
||||
cz commit
|
||||
```
|
||||
|
||||
## Setup workspace
|
||||
|
||||
1. Clone this repo
|
||||
2. Run `cargo test` to set up hooks
|
||||
3. Make changes
|
||||
4. Run the application using `just run` or `just run`
|
||||
- Install `just` (`cargo install just`) if you haven't already to use the [justfile](./justfile) in this project.
|
||||
5. Commit changes. This will trigger pre-commit hooks that will run format, test and lint. If there are errors or
|
||||
warnings from Clippy, please fix them.
|
||||
6. Push your code to a new branch named after the feature/bug/etc. you're adding. This will trigger pre-push hooks that
|
||||
will run lint and test.
|
||||
7. Create a PR
|
||||
|
||||
### CI/CD Testing with Act
|
||||
If you also are planning on testing out your changes before pushing them with [Act](https://github.com/nektos/act), you will need to set up `act`,
|
||||
`docker`, and configure your local system to run different architectures:
|
||||
|
||||
1. Install `docker` by following the instructions on the [official Docker installation page](https://docs.docker.com/get-docker/).
|
||||
2. Install `act` by following the instructions on the [official Act installation page](https://nektosact.com/installation/index.html).
|
||||
3. Install `binfmt` on your system once so that `act` can run the correct architecture for the CI/CD workflows.
|
||||
You can do this by running:
|
||||
```shell
|
||||
sudo docker run --rm --privileged tonistiigi/binfmt --install all
|
||||
```
|
||||
|
||||
Then, you can run workflows locally without having to commit and see if the GitHub action passes or fails.
|
||||
|
||||
**For example**: To test the [release.yml](.github/workflows/release.yaml) workflow locally, you can run:
|
||||
|
||||
```shell
|
||||
act -W .github/workflows/release.yml --input_type bump=minor
|
||||
```
|
||||
|
||||
## Authorship Policy
|
||||
|
||||
All code in this repository is written and reviewed by humans. AI-generated code (e.g., Copilot, ChatGPT,
|
||||
Claude, etc.) is not permitted unless explicitly disclosed and approved.
|
||||
|
||||
Submissions must certify that the contributor understands and can maintain the code they submit.
|
||||
|
||||
## Questions? Reach out to me!
|
||||
If you encounter any questions while developing Loki, please don't hesitate to reach out to me at
|
||||
alex.j.tusa@gmail.com. I'm happy to help contributors in any way I can, regardless of if they're new or experienced!
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
# Credits
|
||||
|
||||
## AIChat
|
||||
Loki originally started as a fork of the fantastic
|
||||
[AIChat CLI](https://github.com/sigoden/aichat). The initial goal was simply
|
||||
to fix a bug in how MCP servers worked with AIChat, allowing different MCP
|
||||
servers to be specified per agent. Since then, Loki has evolved far beyond
|
||||
its original scope and grown into a passion project with a life of its own.
|
||||
|
||||
Today, Loki includes first-class MCP server support (for both local and remote
|
||||
servers), a built-in vault for interpolating secrets in configuration files,
|
||||
built-in agents and macros, dynamic tab completions, integrated custom
|
||||
functions (no external `argc` dependency), improved documentation, and much
|
||||
more with many more ideas planned for the future.
|
||||
|
||||
Loki is now developed and maintained as an independent project. Full credit
|
||||
for the original foundation goes to the developers of the wonderful
|
||||
AIChat project.
|
||||
|
||||
This project is not affiliated with or endorsed by the AIChat maintainers.
|
||||
|
||||
## AIChat
|
||||
|
||||
Loki originally began as a fork of [AIChat CLI](https://github.com/sigoden/aichat),
|
||||
created and maintained by the AIChat contributors.
|
||||
|
||||
While Loki has since diverged significantly and is now developed as an
|
||||
independent project, its early foundation and inspiration came from the
|
||||
AIChat project.
|
||||
|
||||
AIChat is licensed under the MIT License.
|
||||
Generated
+7164
File diff suppressed because it is too large
Load Diff
+149
@@ -0,0 +1,149 @@
|
||||
[package]
|
||||
name = "loki-ai"
|
||||
version = "0.3.0"
|
||||
edition = "2024"
|
||||
authors = ["Alex Clarke <alex.j.tusa@gmail.com>"]
|
||||
description = "An all-in-one, batteries included LLM CLI Tool"
|
||||
keywords = ["chatgpt", "llm", "cli", "ai", "repl"]
|
||||
homepage = "https://github.com/Dark-Alex-17/loki"
|
||||
repository = "https://github.com/Dark-Alex-17/loki"
|
||||
categories = ["command-line-utilities"]
|
||||
readme = "README.md"
|
||||
license = "MIT"
|
||||
rust-version = "1.89.0"
|
||||
exclude = [".github", "CONTRIBUTING.md"]
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.69"
|
||||
bytes = "1.4.0"
|
||||
clap = { version = "4.5.40", features = ["cargo", "derive", "wrap_help"] }
|
||||
dirs = "6.0.0"
|
||||
dunce = "1.0.5"
|
||||
futures-util = "0.3.29"
|
||||
inquire = "0.9.4"
|
||||
is-terminal = "0.4.9"
|
||||
reedline = "0.46.0"
|
||||
serde = { version = "1.0.152", features = ["derive"] }
|
||||
serde_json = { version = "1.0.93", features = ["preserve_order"] }
|
||||
serde_yaml = "0.9.17"
|
||||
tokio = { version = "1.34.0", features = [
|
||||
"rt",
|
||||
"time",
|
||||
"macros",
|
||||
"signal",
|
||||
"rt-multi-thread",
|
||||
"full",
|
||||
] }
|
||||
tokio-graceful = "0.2.2"
|
||||
tokio-stream = { version = "0.1.15", default-features = false, features = [
|
||||
"sync",
|
||||
] }
|
||||
crossterm = "0.29.0"
|
||||
chrono = "0.4.23"
|
||||
bincode = { version = "2.0.0", features = [
|
||||
"serde",
|
||||
"std",
|
||||
], default-features = false }
|
||||
parking_lot = "0.12.1"
|
||||
fancy-regex = "0.14.0"
|
||||
base64 = "0.22.0"
|
||||
nu-ansi-term = "0.50.0"
|
||||
async-trait = "0.1.74"
|
||||
textwrap = "0.16.0"
|
||||
ansi_colours = "1.2.2"
|
||||
reqwest-eventsource = "0.6.0"
|
||||
log = "0.4.28"
|
||||
log4rs = { version = "1.4.0", features = ["file_appender"] }
|
||||
shell-words = "1.1.0"
|
||||
sha2 = "0.10.8"
|
||||
unicode-width = "0.2.0"
|
||||
async-recursion = "1.1.1"
|
||||
http = "1.1.0"
|
||||
http-body-util = "0.1"
|
||||
hyper = { version = "1.0", features = ["full"] }
|
||||
hyper-util = { version = "0.1", features = ["server-auto", "client-legacy"] }
|
||||
time = { version = "0.3.36", features = ["macros"] }
|
||||
indexmap = { version = "2.2.6", features = ["serde"] }
|
||||
hmac = "0.12.1"
|
||||
aws-smithy-eventstream = "0.60.4"
|
||||
urlencoding = "2.1.3"
|
||||
unicode-segmentation = "1.11.0"
|
||||
json-patch = { version = "4.0.0", default-features = false }
|
||||
bitflags = "2.5.0"
|
||||
path-absolutize = "3.1.1"
|
||||
hnsw_rs = "0.3.0"
|
||||
rayon = "1.10.0"
|
||||
uuid = { version = "1.9.1", features = ["v4"] }
|
||||
scraper = { version = "0.23.1", default-features = false, features = [
|
||||
"deterministic",
|
||||
] }
|
||||
sys-locale = "0.3.1"
|
||||
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"] }
|
||||
which = "8.0.0"
|
||||
fuzzy-matcher = "0.3.7"
|
||||
terminal-colorsaurus = "0.4.8"
|
||||
duct = "1.0.0"
|
||||
argc = "1.23.0"
|
||||
strum_macros = "0.27.2"
|
||||
indoc = "2.0.6"
|
||||
rmcp = { version = "1.5.0", features = [
|
||||
"client",
|
||||
"transport-child-process",
|
||||
"transport-streamable-http-client-reqwest",
|
||||
"reqwest-native-tls",
|
||||
] }
|
||||
num_cpus = "1.17.0"
|
||||
tree-sitter = "0.26.8"
|
||||
tree-sitter-language = "0.1"
|
||||
tree-sitter-python = "0.25.0"
|
||||
tree-sitter-typescript = "0.23"
|
||||
colored = "3.0.0"
|
||||
clap_complete = { version = "4.5.58", features = ["unstable-dynamic"] }
|
||||
gman = "0.4.1"
|
||||
clap_complete_nushell = "4.5.9"
|
||||
open = "5"
|
||||
rand = { version = "0.10.0", features = ["default"] }
|
||||
url = "2.5.8"
|
||||
|
||||
[dependencies.reqwest]
|
||||
version = "0.12.0"
|
||||
features = [
|
||||
"json",
|
||||
"multipart",
|
||||
"socks",
|
||||
"rustls-tls",
|
||||
"rustls-tls-native-roots",
|
||||
]
|
||||
default-features = false
|
||||
|
||||
[dependencies.syntect]
|
||||
version = "5.0.0"
|
||||
default-features = false
|
||||
features = ["parsing", "regex-onig", "plist-load"]
|
||||
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
crossterm = { version = "0.29.0", features = ["use-dev-tty"] }
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
arboard = { version = "3.3.0", default-features = false, features = [
|
||||
"wayland-data-control",
|
||||
] }
|
||||
|
||||
[target.'cfg(not(any(target_os = "linux", target_os = "android", target_os = "emscripten")))'.dependencies]
|
||||
arboard = { version = "3.3.0", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
pretty_assertions = "1.4.0"
|
||||
serial_test = "3"
|
||||
|
||||
[[bin]]
|
||||
name = "loki"
|
||||
path = "src/main.rs"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
strip = true
|
||||
opt-level = "z"
|
||||
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2025 sigoden
|
||||
Copyright (c) 2025 Alexander J. Clarke
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1,2 +1,279 @@
|
||||
# loki
|
||||
An all-in-one, batteries included LLM CLI tool
|
||||
# Loki: All-in-one, batteries-included LLM CLI Tool
|
||||
|
||||

|
||||

|
||||
[](https://crates.io/crates/loki-ai)
|
||||

|
||||

|
||||
[](https://github.com/Dark-Alex-17/loki/releases)
|
||||
|
||||
Loki is an all-in-one, batteries-included, LLM CLI tool featuring Shell Assistant, CLI & REPL Mode, RAG, AI Tools &
|
||||
Agents, and More.
|
||||
|
||||
It is designed to include a number of useful agents, roles, macros, and more so users can get up and running with Loki
|
||||
in as little time as possible.
|
||||
|
||||

|
||||
|
||||
Coming from [AIChat](https://github.com/sigoden/aichat)? Follow the [migration guide](./docs/AICHAT-MIGRATION.md) to get started.
|
||||
|
||||
## Quick Links
|
||||
* [AIChat Migration Guide](./docs/AICHAT-MIGRATION.md): Coming from AIChat? Follow the migration guide to get started.
|
||||
* [Installation](#install): Install Loki
|
||||
* [Getting Started](#getting-started): Get started with Loki by doing first-run setup steps.
|
||||
* [REPL](./docs/REPL.md): Interactive Read-Eval-Print Loop for conversational interactions with LLMs and Loki.
|
||||
* [Custom REPL Prompt](./docs/REPL-PROMPT.md): Customize the REPL prompt to provide useful contextual information.
|
||||
* [Vault](./docs/VAULT.md): Securely store and manage sensitive information such as API keys and credentials.
|
||||
* [Shell Integrations](./docs/SHELL-INTEGRATIONS.md): Seamlessly integrate Loki with your shell environment for enhanced command-line assistance.
|
||||
* [Function Calling](./docs/function-calling/TOOLS.md#Tools): Leverage function calling capabilities to extend Loki's functionality with custom tools
|
||||
* [Creating Custom Tools](./docs/function-calling/CUSTOM-TOOLS.md): You can create your own custom tools to enhance Loki's capabilities.
|
||||
* [Create Custom Python Tools](./docs/function-calling/CUSTOM-TOOLS.md#custom-python-based-tools)
|
||||
* [Create Custom TypeScript Tools](./docs/function-calling/CUSTOM-TOOLS.md#custom-typescript-based-tools)
|
||||
* [Create Custom Bash Tools](./docs/function-calling/CUSTOM-BASH-TOOLS.md)
|
||||
* [Bash Prompt Utilities](./docs/function-calling/BASH-PROMPT-HELPERS.md)
|
||||
* [First-Class MCP Server Support](./docs/function-calling/MCP-SERVERS.md): Easily connect and interact with MCP servers for advanced functionality.
|
||||
* [Macros](./docs/MACROS.md): Automate repetitive tasks and workflows with Loki "scripts" (macros).
|
||||
* [RAG](./docs/RAG.md): Retrieval-Augmented Generation for enhanced information retrieval and generation.
|
||||
* [Sessions](/docs/SESSIONS.md): Manage and persist conversational contexts and settings across multiple interactions.
|
||||
* [Roles](./docs/ROLES.md): Customize model behavior for specific tasks or domains.
|
||||
* [Agents](/docs/AGENTS.md): Leverage AI agents to perform complex tasks and workflows, including sub-agent spawning, teammate messaging, and user interaction tools.
|
||||
* [Todo System](./docs/TODO-SYSTEM.md): Built-in task tracking for improved agent reliability with smaller models.
|
||||
* [Environment Variables](./docs/ENVIRONMENT-VARIABLES.md): Override and customize your Loki configuration at runtime with environment variables.
|
||||
* [Client Configurations](./docs/clients/CLIENTS.md): Configuration instructions for various LLM providers.
|
||||
* [Authentication (API Key & OAuth)](./docs/clients/CLIENTS.md#authentication): Authenticate with API keys or OAuth for subscription-based access.
|
||||
* [Patching API Requests](./docs/clients/PATCHES.md): Learn how to patch API requests for advanced customization.
|
||||
* [Custom Themes](./docs/THEMES.md): Change the look and feel of Loki to your preferences with custom themes.
|
||||
* [History](#history): A history of how Loki came to be.
|
||||
|
||||
## Prerequisites
|
||||
Loki requires the following tools to be installed on your system:
|
||||
* [jq](https://github.com/jqlang/jq)
|
||||
* `brew install jq`
|
||||
* [jira (optional)](https://github.com/ankitpokhrel/jira-cli/wiki/Installation) (For the `query_jira_issues` tool)
|
||||
* `brew tap ankitpokhrel/jira-cli && brew install jira-cli`
|
||||
* You'll need to [create a JIRA API token](https://id.atlassian.com/manage-profile/security/api-tokens) for authentication
|
||||
* Then, save it as an environment variable to your shell profile:
|
||||
```sh
|
||||
# ~/.bashrc or ~/.zshrc
|
||||
export JIRA_API_TOKEN="your_jira_api_token_here"
|
||||
```
|
||||
* Then run `jira init`, select installation type as `cloud`, and provide the required details to generate a config
|
||||
file for the Jira CLI.
|
||||
* [usql](https://github.com/xo/usql) (For the `sql` agent)
|
||||
* `brew install xo/xo/usql`
|
||||
* [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`
|
||||
|
||||
These tools are used to provide various functionalities within Loki, such as document processing, JSON manipulation,
|
||||
interaction with Jira, and they are used within agents and tools.
|
||||
|
||||
## Install
|
||||
|
||||
### Cargo
|
||||
If you have Cargo installed, then you can install `loki` from Crates.io:
|
||||
|
||||
```shell
|
||||
cargo install loki-ai # Binary name is `loki`
|
||||
|
||||
# If you encounter issues installing, try installing with '--locked'
|
||||
cargo install --locked loki-ai
|
||||
```
|
||||
|
||||
### Homebrew (Mac/Linux)
|
||||
To install Loki from Homebrew, install the `loki` tap. Then you'll be able to install `loki`:
|
||||
|
||||
```shell
|
||||
brew tap Dark-Alex-17/loki
|
||||
brew install loki
|
||||
|
||||
# If you need to be more specific, use:
|
||||
brew install Dark-Alex-17/loki/loki
|
||||
```
|
||||
|
||||
To upgrade `loki` using Homebrew:
|
||||
|
||||
```shell
|
||||
brew upgrade loki
|
||||
```
|
||||
|
||||
### Scripts
|
||||
#### Linux/MacOS (`bash`)
|
||||
You can use the following command to run a bash script that downloads and installs the latest version of `loki` for your
|
||||
OS (Linux/MacOS) and architecture (x86_64/arm64):
|
||||
|
||||
```shell
|
||||
curl -fsSL https://raw.githubusercontent.com/Dark-Alex-17/loki/main/install_loki.sh | bash
|
||||
```
|
||||
|
||||
#### Windows/Linux/MacOS (`PowerShell`)
|
||||
You can use the following command to run a PowerShell script that downloads and installs the latest version of `loki`
|
||||
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/loki/main/scripts/install_loki.ps1 | iex"
|
||||
```
|
||||
|
||||
### Manual
|
||||
Binaries are available on the [releases](https://github.com/Dark-Alex-17/loki/releases) page for the following platforms:
|
||||
|
||||
| Platform | Architecture(s) |
|
||||
|----------------|-----------------|
|
||||
| macOS | x86_64, arm64 |
|
||||
| Linux GNU/MUSL | x86_64, aarch64 |
|
||||
| Windows | x86_64, aarch64 |
|
||||
|
||||
#### Windows Instructions
|
||||
To use a binary from the releases page on Windows, do the following:
|
||||
|
||||
1. Download the latest [binary](https://github.com/Dark-Alex-17/loki/releases) for your OS.
|
||||
2. Use 7-Zip or TarTool to unpack the Tar file.
|
||||
3. Run the executable `loki.exe`!
|
||||
|
||||
#### Linux/MacOS Instructions
|
||||
To use a binary from the releases page on Linux/MacOS, do the following:
|
||||
|
||||
1. Download the latest [binary](https://github.com/Dark-Alex-17/loki/releases) for your OS.
|
||||
2. `cd` to the directory where you downloaded the binary.
|
||||
3. Extract the binary with `tar -C /usr/local/bin -xzf loki-<arch>.tar.gz` (Note: This may require `sudo`)
|
||||
4. Now you can run `loki`!
|
||||
|
||||
## Getting Started
|
||||
After installation, you can generate the configuration files and directories by simply running:
|
||||
|
||||
```sh
|
||||
loki --info
|
||||
```
|
||||
|
||||
Then, you need to set up the Loki vault by creating a vault password file. Loki will do this for you automatically and
|
||||
guide you through the process when you first attempt to access the vault. So, to get started, you can run:
|
||||
|
||||
```sh
|
||||
loki --list-secrets
|
||||
```
|
||||
|
||||
### Authentication
|
||||
Each client in your configuration needs authentication (with a few exceptions; e.g. ollama). Most clients use an API key
|
||||
(set via `api_key` in the config or through the [vault](./docs/VAULT.md)). For providers that support OAuth (e.g. Claude Pro/Max
|
||||
subscribers, Google Gemini), you can authenticate with your existing subscription instead:
|
||||
|
||||
```yaml
|
||||
# In your config.yaml
|
||||
clients:
|
||||
- type: claude
|
||||
name: my-claude-oauth
|
||||
auth: oauth # Indicate you want to authenticate with OAuth instead of an API key
|
||||
```
|
||||
|
||||
```sh
|
||||
loki --authenticate my-claude-oauth
|
||||
# Or via the REPL: .authenticate
|
||||
```
|
||||
|
||||
For full details, see the [authentication documentation](./docs/clients/CLIENTS.md#authentication).
|
||||
|
||||
### Tab-Completions
|
||||
You can also enable tab completions to make using Loki easier. To do so, add the following to your shell profile:
|
||||
```shell
|
||||
# Bash
|
||||
# (add to: `~/.bashrc`)
|
||||
source <(COMPLETE=bash loki)
|
||||
|
||||
# Zsh
|
||||
# (add to: `~/.zshrc`)
|
||||
source <(COMPLETE=zsh loki)
|
||||
|
||||
# Fish
|
||||
# (add to: `~/.config/fish/config.fish`)
|
||||
source <(COMPLETE=fish loki | psub)
|
||||
|
||||
# Elvish
|
||||
# (add to: `~/.elvish/rc.elv`)
|
||||
eval (E:COMPLETE=elvish loki | slurp)
|
||||
|
||||
# PowerShell
|
||||
# (add to: `$PROFILE`)
|
||||
$env:COMPLETE = "powershell"
|
||||
loki | Out-String | Invoke-Expression
|
||||
```
|
||||
|
||||
### Shell Integration
|
||||
You can integrate Loki's Shell Assistant into your shell for enhanced command-line assistance. Add the code in the
|
||||
corresponding [shell integration script](./scripts/shell-integration) to your shell. Then, you can invoke Loki to convert natural language to
|
||||
shell commands by pressing `Alt-e`. For example:
|
||||
|
||||
```shell
|
||||
$ find all markdown files<Alt-e>
|
||||
# Will be converted to:
|
||||
find . -name "*.md"
|
||||
```
|
||||
|
||||
## Configuration
|
||||
The location of the global Loki configuration varies between systems, so you can use the following command to find your
|
||||
`config.yaml` file:
|
||||
|
||||
```shell
|
||||
loki --info | grep 'config_file' | awk '{print $2}'
|
||||
```
|
||||
|
||||
The configuration file consists of a number of settings. To see a full example configuration file with every setting
|
||||
defined, refer to the [example configuration file](./config.example.yaml).
|
||||
|
||||
### Default LLM
|
||||
The following settings are available to configure the default LLM that is used when you start Loki, and its
|
||||
hyperparameters:
|
||||
|
||||
| Setting | Description |
|
||||
|---------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `model` | The default LLM to use when no model is provided |
|
||||
| `temperature` | The default `temperature` parameter for all models (0,1); Used unless explicitly overridden |
|
||||
| `top_p` | The default `top_p` hyperparameter value to use for all models, with a range of (0,1) (or (0,2) for some models); <br>Used unless explicitly overridden |
|
||||
|
||||
### CLI Behavior
|
||||
You can use the following settings to modify the behavior of Loki:
|
||||
|
||||
| Setting | Default Value | Description |
|
||||
|---------------|---------------|-------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `stream` | `true` | Controls whether to use stream-style APIs when querying for completions from LLM providers |
|
||||
| `save` | `true` | Controls whether to save each query/response to every model to `messages.md` for posterity; Useful for debugging |
|
||||
| `keybindings` | `emacs` | Specifies which keybinding schema to use; can either be `emacs` or `vi` |
|
||||
| `editor` | `null` | What text editor Loki should use to edit the input buffer or session (e.g. `vim`, `emacs`, `nano`, `hx`); <br>Defaults to `$EDITOR` |
|
||||
| `wrap` | `no` | Controls whether text is wrapped (can be `no`, `auto`, or some `<max_width>` |
|
||||
| `wrap_code` | `false` | Enables or disables the wrapping of code blocks |
|
||||
|
||||
### Preludes
|
||||
Preludes let you define the default behavior for the different operating modes of Loki. The available settings are
|
||||
shown below:
|
||||
|
||||
| Setting | Description |
|
||||
|-----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `repl_prelude` | This setting lets you specify a default `session` or `role` to use when starting Loki in [REPL](./docs/REPL.md) mode. <br>Values can be <ul><li>`role:<name>` to define a role</li><li>`session:<name>` to define a session</li><li>`<session>:<role>` to define both a session and a role to use</li></ul> |
|
||||
| `cmd_prelude` | This setting lets you specify a default `session` or `role` to use when running one-off queries in Loki via the CLI. <br>Values can be <ul><li>`role:<name>` to define a role</li><li>`session:<name>` to define a session</li><li>`<session>:<role>` to define both a session and a role to use</li></ul> |
|
||||
| `agent_session` | This setting is used to specify a default session that all agents should start into, unless otherwise specified in the agent configuration. (e.g. `temp`, `default`) |
|
||||
|
||||
### Appearance
|
||||
The appearance of Loki can be modified using the following settings:
|
||||
|
||||
| Setting | Default Value | Description |
|
||||
|---------------|---------------|------------------------------------------------------|
|
||||
| `highlight` | `true` | This setting enables or disables syntax highlighting |
|
||||
| `light_theme` | `false` | This setting toggles light mode in Loki |
|
||||
|
||||
### Miscellaneous Settings
|
||||
| Setting | Default Value | Description |
|
||||
|----------------------|---------------|------------------------------------------------------------------------------------------------------------------|
|
||||
| `user_agent` | `null` | The name of the `User-Agent` that should be passed in the `User-Agent` header on all requests to model providers |
|
||||
| `save_shell_history` | `true` | Enables or disables REPL command history |
|
||||
|
||||
---
|
||||
|
||||
## History
|
||||
|
||||
Loki began as a fork of [AIChat CLI](https://github.com/sigoden/aichat) and has since evolved into an independent project.
|
||||
|
||||
See [CREDITS.md](./CREDITS.md) for full attribution and background.
|
||||
|
||||
---
|
||||
|
||||
## Creator
|
||||
* [Alex Clarke](https://github.com/Dark-Alex-17)
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
Only latest version of the software will be supported with security patches.
|
||||
|
||||
| Version | Supported |
|
||||
| -------- | ------------------ |
|
||||
| latest | :white_check_mark: |
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
If you find a vulnerability, please reach out to me via email (alex.j.tusa@gmail.com).
|
||||
If you yourself decide you'd like to tackle a fix, please submit a PR with the fix and I'll review it as soon as
|
||||
possible.
|
||||
Executable
+319
@@ -0,0 +1,319 @@
|
||||
#!/usr/bin/env bash
|
||||
# Shared Agent Utilities - Minimal, focused helper functions
|
||||
set -euo pipefail
|
||||
|
||||
#######################
|
||||
## PROJECT DETECTION ##
|
||||
#######################
|
||||
|
||||
# Cache file name for detected project info
|
||||
_LOKI_PROJECT_CACHE=".loki-project.json"
|
||||
|
||||
# Read cached project detection if valid
|
||||
# Usage: _read_project_cache "/path/to/project"
|
||||
# Returns: cached JSON on stdout (exit 0) or nothing (exit 1)
|
||||
_read_project_cache() {
|
||||
local dir="$1"
|
||||
local cache_file="${dir}/${_LOKI_PROJECT_CACHE}"
|
||||
|
||||
if [[ -f "${cache_file}" ]]; then
|
||||
local cached
|
||||
cached=$(cat "${cache_file}" 2>/dev/null) || return 1
|
||||
if echo "${cached}" | jq -e '.type and .build != null and .test != null and .check != null' &>/dev/null; then
|
||||
echo "${cached}"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
# Write project detection result to cache
|
||||
# Usage: _write_project_cache "/path/to/project" '{"type":"rust",...}'
|
||||
_write_project_cache() {
|
||||
local dir="$1"
|
||||
local json="$2"
|
||||
local cache_file="${dir}/${_LOKI_PROJECT_CACHE}"
|
||||
|
||||
echo "${json}" > "${cache_file}" 2>/dev/null || true
|
||||
}
|
||||
|
||||
_detect_heuristic() {
|
||||
local dir="$1"
|
||||
|
||||
# Rust
|
||||
if [[ -f "${dir}/Cargo.toml" ]]; then
|
||||
echo '{"type":"rust","build":"cargo build","test":"cargo test","check":"cargo check"}'
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Go
|
||||
if [[ -f "${dir}/go.mod" ]]; then
|
||||
echo '{"type":"go","build":"go build ./...","test":"go test ./...","check":"go vet ./..."}'
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Node.JS/Deno/Bun
|
||||
if [[ -f "${dir}/deno.json" ]] || [[ -f "${dir}/deno.jsonc" ]]; then
|
||||
echo '{"type":"deno","build":"deno task build","test":"deno test","check":"deno lint"}'
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ -f "${dir}/package.json" ]]; then
|
||||
local pm="npm"
|
||||
|
||||
[[ -f "${dir}/bun.lockb" ]] || [[ -f "${dir}/bun.lock" ]] && pm="bun"
|
||||
[[ -f "${dir}/pnpm-lock.yaml" ]] && pm="pnpm"
|
||||
[[ -f "${dir}/yarn.lock" ]] && pm="yarn"
|
||||
|
||||
echo "{\"type\":\"nodejs\",\"build\":\"${pm} run build\",\"test\":\"${pm} test\",\"check\":\"${pm} run lint\"}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Python
|
||||
if [[ -f "${dir}/pyproject.toml" ]] || [[ -f "${dir}/setup.py" ]] || [[ -f "${dir}/setup.cfg" ]]; then
|
||||
local test_cmd="pytest"
|
||||
local check_cmd="ruff check ."
|
||||
|
||||
if [[ -f "${dir}/poetry.lock" ]]; then
|
||||
test_cmd="poetry run pytest"
|
||||
check_cmd="poetry run ruff check ."
|
||||
elif [[ -f "${dir}/uv.lock" ]]; then
|
||||
test_cmd="uv run pytest"
|
||||
check_cmd="uv run ruff check ."
|
||||
fi
|
||||
|
||||
echo "{\"type\":\"python\",\"build\":\"\",\"test\":\"${test_cmd}\",\"check\":\"${check_cmd}\"}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# JVM (Maven)
|
||||
if [[ -f "${dir}/pom.xml" ]]; then
|
||||
echo '{"type":"java","build":"mvn compile","test":"mvn test","check":"mvn verify"}'
|
||||
return 0
|
||||
fi
|
||||
|
||||
# JVM (Gradle)
|
||||
if [[ -f "${dir}/build.gradle" ]] || [[ -f "${dir}/build.gradle.kts" ]]; then
|
||||
local gw="gradle"
|
||||
[[ -f "${dir}/gradlew" ]] && gw="./gradlew"
|
||||
echo "{\"type\":\"java\",\"build\":\"${gw} build\",\"test\":\"${gw} test\",\"check\":\"${gw} check\"}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# .NET / C#
|
||||
if compgen -G "${dir}/*.sln" &>/dev/null || compgen -G "${dir}/*.csproj" &>/dev/null; then
|
||||
echo '{"type":"dotnet","build":"dotnet build","test":"dotnet test","check":"dotnet build --warnaserrors"}'
|
||||
return 0
|
||||
fi
|
||||
|
||||
# C/C++ (CMake)
|
||||
if [[ -f "${dir}/CMakeLists.txt" ]]; then
|
||||
echo '{"type":"cmake","build":"cmake --build build","test":"ctest --test-dir build","check":"cmake --build build"}'
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Ruby
|
||||
if [[ -f "${dir}/Gemfile" ]]; then
|
||||
local test_cmd="bundle exec rake test"
|
||||
[[ -f "${dir}/Rakefile" ]] && grep -q "rspec" "${dir}/Gemfile" 2>/dev/null && test_cmd="bundle exec rspec"
|
||||
echo "{\"type\":\"ruby\",\"build\":\"\",\"test\":\"${test_cmd}\",\"check\":\"bundle exec rubocop\"}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Elixir
|
||||
if [[ -f "${dir}/mix.exs" ]]; then
|
||||
echo '{"type":"elixir","build":"mix compile","test":"mix test","check":"mix credo"}'
|
||||
return 0
|
||||
fi
|
||||
|
||||
# PHP
|
||||
if [[ -f "${dir}/composer.json" ]]; then
|
||||
echo '{"type":"php","build":"","test":"./vendor/bin/phpunit","check":"./vendor/bin/phpstan analyse"}'
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Swift
|
||||
if [[ -f "${dir}/Package.swift" ]]; then
|
||||
echo '{"type":"swift","build":"swift build","test":"swift test","check":"swift build"}'
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Zig
|
||||
if [[ -f "${dir}/build.zig" ]]; then
|
||||
echo '{"type":"zig","build":"zig build","test":"zig build test","check":"zig build"}'
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Generic build systems (last resort before LLM)
|
||||
if [[ -f "${dir}/justfile" ]] || [[ -f "${dir}/Justfile" ]]; then
|
||||
echo '{"type":"just","build":"just build","test":"just test","check":"just lint"}'
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ -f "${dir}/Makefile" ]] || [[ -f "${dir}/makefile" ]] || [[ -f "${dir}/GNUmakefile" ]]; then
|
||||
echo '{"type":"make","build":"make build","test":"make test","check":"make lint"}'
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# Gather lightweight evidence about a project for LLM analysis
|
||||
# Usage: _gather_project_evidence "/path/to/project"
|
||||
# Returns: evidence string on stdout
|
||||
_gather_project_evidence() {
|
||||
local dir="$1"
|
||||
local evidence=""
|
||||
|
||||
evidence+="Root files and directories:"$'\n'
|
||||
evidence+=$(ls -1 "${dir}" 2>/dev/null | head -50)
|
||||
evidence+=$'\n\n'
|
||||
|
||||
evidence+="File extension counts:"$'\n'
|
||||
evidence+=$(find "${dir}" -type f \
|
||||
-not -path '*/.git/*' \
|
||||
-not -path '*/node_modules/*' \
|
||||
-not -path '*/target/*' \
|
||||
-not -path '*/dist/*' \
|
||||
-not -path '*/__pycache__/*' \
|
||||
-not -path '*/vendor/*' \
|
||||
-not -path '*/.build/*' \
|
||||
2>/dev/null \
|
||||
| sed 's/.*\.//' | sort | uniq -c | sort -rn | head -10)
|
||||
evidence+=$'\n\n'
|
||||
|
||||
local config_patterns=("*.toml" "*.yaml" "*.yml" "*.json" "*.xml" "*.gradle" "*.gradle.kts" "*.cabal" "*.pro" "Makefile" "justfile" "Justfile" "Dockerfile" "Taskfile*" "BUILD" "WORKSPACE" "flake.nix" "shell.nix" "default.nix")
|
||||
local found_configs=0
|
||||
|
||||
for pattern in "${config_patterns[@]}"; do
|
||||
if [[ ${found_configs} -ge 5 ]]; then
|
||||
break
|
||||
fi
|
||||
|
||||
local files
|
||||
files=$(find "${dir}" -maxdepth 1 -name "${pattern}" -type f 2>/dev/null)
|
||||
|
||||
while IFS= read -r f; do
|
||||
if [[ -n "${f}" && ${found_configs} -lt 5 ]]; then
|
||||
local basename
|
||||
basename=$(basename "${f}")
|
||||
evidence+="--- ${basename} (first 30 lines) ---"$'\n'
|
||||
evidence+=$(head -30 "${f}" 2>/dev/null)
|
||||
evidence+=$'\n\n'
|
||||
found_configs=$((found_configs + 1))
|
||||
fi
|
||||
done <<< "${files}"
|
||||
done
|
||||
|
||||
echo "${evidence}"
|
||||
}
|
||||
|
||||
# LLM-based project detection fallback
|
||||
# Usage: _detect_with_llm "/path/to/project"
|
||||
# Returns: JSON on stdout or empty (exit 1)
|
||||
_detect_with_llm() {
|
||||
local dir="$1"
|
||||
local evidence
|
||||
evidence=$(_gather_project_evidence "${dir}")
|
||||
local prompt
|
||||
prompt=$(cat <<-EOF
|
||||
|
||||
Analyze this project directory and determine the project type, primary language, and the correct shell commands to build, test, and check (lint/typecheck) it.
|
||||
|
||||
EOF
|
||||
)
|
||||
prompt+=$'\n'"${evidence}"$'\n'
|
||||
prompt+=$(cat <<-EOF
|
||||
|
||||
Respond with ONLY a valid JSON object. No markdown fences, no explanation, no extra text.
|
||||
The JSON must have exactly these 4 keys:
|
||||
{"type":"<language>","build":"<build command>","test":"<test command>","check":"<lint or typecheck command>"}
|
||||
|
||||
Rules:
|
||||
- "type" must be a single lowercase word (e.g. rust, go, python, nodejs, java, ruby, elixir, cpp, c, zig, haskell, scala, kotlin, dart, swift, php, dotnet, etc.)
|
||||
- If a command doesn't apply to this project, use an empty string, ""
|
||||
- Use the most standard/common commands for the detected ecosystem
|
||||
- If you detect a package manager lockfile, use that package manager (e.g. pnpm over npm)
|
||||
EOF
|
||||
)
|
||||
|
||||
local llm_response
|
||||
llm_response=$(loki --no-stream "${prompt}" 2>/dev/null) || return 1
|
||||
|
||||
llm_response=$(echo "${llm_response}" | sed 's/^```json//;s/^```//;s/```$//' | tr -d '\n' | sed 's/^[[:space:]]*//')
|
||||
llm_response=$(echo "${llm_response}" | grep -o '{[^}]*}' | head -1)
|
||||
|
||||
if echo "${llm_response}" | jq -e '.type and .build != null and .test != null and .check != null' &>/dev/null; then
|
||||
echo "${llm_response}" | jq -c '{type: (.type // "unknown"), build: (.build // ""), test: (.test // ""), check: (.check // "")}'
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# Detect project type and return build/test commands
|
||||
# Uses: cached result -> fast heuristics -> LLM fallback
|
||||
detect_project() {
|
||||
local dir="${1:-.}"
|
||||
|
||||
local cached
|
||||
if cached=$(_read_project_cache "${dir}"); then
|
||||
echo "${cached}" | jq -c '{type, build, test, check}'
|
||||
return 0
|
||||
fi
|
||||
|
||||
local result
|
||||
if result=$(_detect_heuristic "${dir}"); then
|
||||
local enriched
|
||||
enriched=$(echo "${result}" | jq -c '. + {"_detected_by":"heuristic","_cached_at":"'"$(date -Iseconds)"'"}')
|
||||
|
||||
_write_project_cache "${dir}" "${enriched}"
|
||||
|
||||
echo "${result}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if result=$(_detect_with_llm "${dir}"); then
|
||||
local enriched
|
||||
enriched=$(echo "${result}" | jq -c '. + {"_detected_by":"llm","_cached_at":"'"$(date -Iseconds)"'"}')
|
||||
|
||||
_write_project_cache "${dir}" "${enriched}"
|
||||
|
||||
echo "${result}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo '{"type":"unknown","build":"","test":"","check":""}'
|
||||
}
|
||||
|
||||
###########################
|
||||
## FILE SEARCH UTILITIES ##
|
||||
###########################
|
||||
|
||||
_search_files() {
|
||||
local pattern="$1"
|
||||
local dir="${2:-.}"
|
||||
|
||||
find "${dir}" -type f -name "${pattern}" \
|
||||
-not -path '*/target/*' \
|
||||
-not -path '*/node_modules/*' \
|
||||
-not -path '*/.git/*' \
|
||||
-not -path '*/dist/*' \
|
||||
-not -path '*/__pycache__/*' \
|
||||
2>/dev/null | head -25
|
||||
}
|
||||
|
||||
get_tree() {
|
||||
local dir="${1:-.}"
|
||||
local depth="${2:-3}"
|
||||
|
||||
if command -v tree &>/dev/null; then
|
||||
tree -L "${depth}" --noreport -I 'node_modules|target|dist|.git|__pycache__|*.pyc' "${dir}" 2>/dev/null || find "${dir}" -maxdepth "${depth}" -type f | head -50
|
||||
else
|
||||
find "${dir}" -maxdepth "${depth}" -type f \
|
||||
-not -path '*/target/*' \
|
||||
-not -path '*/node_modules/*' \
|
||||
-not -path '*/.git/*' \
|
||||
2>/dev/null | head -50
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
# Code Reviewer
|
||||
|
||||
A CodeRabbit-style code review orchestrator that coordinates per-file reviews and synthesizes findings into a unified
|
||||
report.
|
||||
|
||||
This agent acts as the manager for the review process, delegating actual file analysis to **[File Reviewer](../file-reviewer/README.md)**
|
||||
agents while handling coordination and final reporting.
|
||||
|
||||
## Features
|
||||
|
||||
- 🤖 **Orchestration**: Spawns parallel reviewers for each changed file.
|
||||
- 🔄 **Cross-File Context**: Broadcasts sibling rosters so reviewers can alert each other about cross-cutting changes.
|
||||
- 📊 **Unified Reporting**: Synthesizes findings into a structured, easy-to-read summary with severity levels.
|
||||
- ⚡ **Parallel Execution**: Runs reviews concurrently for maximum speed.
|
||||
|
||||
## 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
|
||||
them), and modify the agent definition to look like this:
|
||||
|
||||
```yaml
|
||||
# ...
|
||||
|
||||
mcp_servers:
|
||||
- jetbrains # The name of your configured IDE MCP server
|
||||
|
||||
global_tools:
|
||||
- fs_read.sh
|
||||
- fs_grep.sh
|
||||
- fs_glob.sh
|
||||
# - execute_command.sh
|
||||
|
||||
# ...
|
||||
```
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
name: code-reviewer
|
||||
description: CodeRabbit-style code reviewer - spawns per-file reviewers, synthesizes findings
|
||||
version: 1.0.0
|
||||
temperature: 0.1
|
||||
|
||||
auto_continue: true
|
||||
max_auto_continues: 20
|
||||
inject_todo_instructions: true
|
||||
|
||||
can_spawn_agents: true
|
||||
max_concurrent_agents: 10
|
||||
max_agent_depth: 2
|
||||
|
||||
variables:
|
||||
- name: project_dir
|
||||
description: Project directory to review
|
||||
default: '.'
|
||||
|
||||
global_tools:
|
||||
- fs_read.sh
|
||||
- fs_grep.sh
|
||||
- fs_glob.sh
|
||||
- execute_command.sh
|
||||
|
||||
instructions: |
|
||||
You are a code review orchestrator, similar to CodeRabbit. You coordinate per-file reviews and produce a unified report.
|
||||
|
||||
## Workflow
|
||||
|
||||
1. **Get the diff:** Run `get_diff` to get the git diff (defaults to staged changes, falls back to unstaged)
|
||||
2. **Parse changed files:** Extract the list of files from the diff
|
||||
3. **Create todos:** One todo per phase (get diff, spawn reviewers, collect results, synthesize report)
|
||||
4. **Spawn file-reviewers:** One `file-reviewer` agent per changed file, in parallel
|
||||
5. **Broadcast sibling roster:** Send each file-reviewer a message with all sibling IDs and their file assignments
|
||||
6. **Collect all results:** Wait for each file-reviewer to complete
|
||||
7. **Synthesize:** Combine all findings into a CodeRabbit-style report
|
||||
|
||||
## Spawning File Reviewers
|
||||
|
||||
For each changed file, spawn a file-reviewer with a prompt containing:
|
||||
- The file path
|
||||
- The relevant diff hunk(s) for that file
|
||||
- Instructions to review it
|
||||
|
||||
```
|
||||
agent__spawn --agent file-reviewer --prompt "Review the following diff for <file_path>:
|
||||
|
||||
<diff content for this file>
|
||||
|
||||
Focus on bugs, security issues, logic errors, and style. Use the severity format (🔴🟡🟢💡).
|
||||
End with REVIEW_COMPLETE."
|
||||
```
|
||||
|
||||
## Sibling Roster Broadcast
|
||||
|
||||
After spawning ALL file-reviewers (collecting their IDs), send each one a message with the roster:
|
||||
|
||||
```
|
||||
agent__send_message --to <agent_id> --message "SIBLING_ROSTER:
|
||||
- <agent_id_1>: reviewing <file_1>
|
||||
- <agent_id_2>: reviewing <file_2>
|
||||
...
|
||||
Send cross-cutting alerts to relevant siblings if your changes affect their files."
|
||||
```
|
||||
|
||||
## Diff Parsing
|
||||
|
||||
Split the diff by file. Each file's diff starts with `diff --git a/<path> b/<path>`. Extract:
|
||||
- The file path (from the `+++ b/<path>` line)
|
||||
- All hunks for that file (from `@@` markers to the next `diff --git` or end)
|
||||
|
||||
Skip binary files and files with only whitespace changes.
|
||||
|
||||
## Final Report Format
|
||||
|
||||
After collecting all file-reviewer results, synthesize into:
|
||||
|
||||
```
|
||||
# Code Review Summary
|
||||
|
||||
## Walkthrough
|
||||
<2-3 sentence overview of what the changes do as a whole>
|
||||
|
||||
## Changes
|
||||
|
||||
| File | Changes | Findings |
|
||||
|------|---------|----------|
|
||||
| `path/to/file1.rs` | <brief description> | 🔴 1 🟡 2 🟢 1 |
|
||||
| `path/to/file2.rs` | <brief description> | 🟢 2 💡 1 |
|
||||
|
||||
## Detailed Findings
|
||||
|
||||
### `path/to/file1.rs`
|
||||
<paste file-reviewer's findings here, cleaned up>
|
||||
|
||||
### `path/to/file2.rs`
|
||||
<paste file-reviewer's findings here, cleaned up>
|
||||
|
||||
## Cross-File Concerns
|
||||
<any cross-cutting issues identified by the teammate pattern>
|
||||
|
||||
---
|
||||
*Reviewed N files, found X critical, Y warnings, Z suggestions, W nitpicks*
|
||||
```
|
||||
|
||||
## Edge Cases
|
||||
|
||||
- **Single file changed:** Still spawn one file-reviewer (for consistency), skip roster broadcast
|
||||
- **Too many files (>10):** Group small files (< 20 lines changed) and review them together
|
||||
- **No changes found:** Report "No changes to review" and exit
|
||||
- **Binary files:** Skip with a note in the summary
|
||||
|
||||
## Rules
|
||||
|
||||
1. **Always use `get_diff` first:** Don't assume what changed
|
||||
2. **Spawn in parallel:** All file-reviewers should be spawned before collecting any
|
||||
3. **Don't review code yourself:** Delegate ALL review work to file-reviewers
|
||||
4. **Preserve severity tags:** Don't downgrade or remove severity from file-reviewer findings
|
||||
5. **Include ALL findings:** Don't summarize away specific issues
|
||||
|
||||
## Context
|
||||
- Project: {{project_dir}}
|
||||
- CWD: {{__cwd__}}
|
||||
- Shell: {{__shell__}}
|
||||
|
||||
## Available Tools:
|
||||
{{__tools__}}
|
||||
Executable
+478
@@ -0,0 +1,478 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "$LLM_PROMPT_UTILS_FILE"
|
||||
source "$LLM_ROOT_DIR/agents/.shared/utils.sh"
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout
|
||||
# @env LLM_AGENT_VAR_PROJECT_DIR=.
|
||||
# @describe Code review orchestrator tools
|
||||
|
||||
_project_dir() {
|
||||
local dir="${LLM_AGENT_VAR_PROJECT_DIR:-.}"
|
||||
(cd "${dir}" 2>/dev/null && pwd) || echo "${dir}"
|
||||
}
|
||||
|
||||
# @cmd Get git diff for code review. Returns staged changes, or unstaged if nothing is staged, or HEAD~1 diff if working tree is clean.
|
||||
# @option --base Optional base ref to diff against (e.g., "main", "HEAD~3", a commit SHA)
|
||||
get_diff() {
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
# shellcheck disable=SC2154
|
||||
local base="${argc_base:-}"
|
||||
|
||||
local diff_output=""
|
||||
|
||||
if [[ -n "${base}" ]]; then
|
||||
diff_output=$(cd "${project_dir}" && git diff "${base}" 2>&1) || true
|
||||
else
|
||||
diff_output=$(cd "${project_dir}" && git diff --cached 2>&1) || true
|
||||
|
||||
if [[ -z "${diff_output}" ]]; then
|
||||
diff_output=$(cd "${project_dir}" && git diff 2>&1) || true
|
||||
fi
|
||||
|
||||
if [[ -z "${diff_output}" ]]; then
|
||||
diff_output=$(cd "${project_dir}" && git diff HEAD~1 2>&1) || true
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z "${diff_output}" ]]; then
|
||||
warn "No changes found to review" >> "$LLM_OUTPUT"
|
||||
return 0
|
||||
fi
|
||||
|
||||
local file_count
|
||||
file_count=$(echo "${diff_output}" | grep -c '^diff --git' || true)
|
||||
|
||||
{
|
||||
info "Diff contains changes to ${file_count} file(s)"
|
||||
echo ""
|
||||
echo "${diff_output}"
|
||||
} >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
# @cmd Get list of changed files with stats
|
||||
# @option --base Optional base ref to diff against
|
||||
get_changed_files() {
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
local base="${argc_base:-}"
|
||||
|
||||
local stat_output=""
|
||||
|
||||
if [[ -n "${base}" ]]; then
|
||||
stat_output=$(cd "${project_dir}" && git diff --stat "${base}" 2>&1) || true
|
||||
else
|
||||
stat_output=$(cd "${project_dir}" && git diff --cached --stat 2>&1) || true
|
||||
|
||||
if [[ -z "${stat_output}" ]]; then
|
||||
stat_output=$(cd "${project_dir}" && git diff --stat 2>&1) || true
|
||||
fi
|
||||
|
||||
if [[ -z "${stat_output}" ]]; then
|
||||
stat_output=$(cd "${project_dir}" && git diff --stat HEAD~1 2>&1) || true
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z "${stat_output}" ]]; then
|
||||
warn "No changes found" >> "$LLM_OUTPUT"
|
||||
return 0
|
||||
fi
|
||||
|
||||
{
|
||||
info "Changed files:"
|
||||
echo ""
|
||||
echo "${stat_output}"
|
||||
} >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
# @cmd Get project structure and type information
|
||||
get_project_info() {
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
|
||||
local project_info
|
||||
project_info=$(detect_project "${project_dir}")
|
||||
|
||||
{
|
||||
info "Project: ${project_dir}"
|
||||
echo "Type: $(echo "${project_info}" | jq -r '.type')"
|
||||
echo ""
|
||||
get_tree "${project_dir}" 2
|
||||
} >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
# ARGC-BUILD {
|
||||
# This block was generated by argc (https://github.com/sigoden/argc).
|
||||
# Modifying it manually is not recommended
|
||||
|
||||
_argc_run() {
|
||||
if [[ "${1:-}" == "___internal___" ]]; then
|
||||
_argc_die "error: unsupported ___internal___ command"
|
||||
fi
|
||||
if [[ "${OS:-}" == "Windows_NT" ]] && [[ -n "${MSYSTEM:-}" ]]; then
|
||||
set -o igncr
|
||||
fi
|
||||
argc__args=("$(basename "$0" .sh)" "$@")
|
||||
argc__positionals=()
|
||||
_argc_index=1
|
||||
_argc_len="${#argc__args[@]}"
|
||||
_argc_tools=()
|
||||
_argc_parse
|
||||
if [ -n "${argc__fn:-}" ]; then
|
||||
$argc__fn "${argc__positionals[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_usage() {
|
||||
cat <<-'EOF'
|
||||
Code review orchestrator tools
|
||||
|
||||
USAGE: <COMMAND>
|
||||
|
||||
COMMANDS:
|
||||
get_diff Get git diff for code review. Returns staged changes, or unstaged if nothing is staged, or HEAD~1 diff if working tree is clean. [aliases: get-diff]
|
||||
get_changed_files Get list of changed files with stats [aliases: get-changed-files]
|
||||
get_project_info Get project structure and type information [aliases: get-project-info]
|
||||
|
||||
ENVIRONMENTS:
|
||||
LLM_OUTPUT [default: /dev/stdout]
|
||||
LLM_AGENT_VAR_PROJECT_DIR [default: .]
|
||||
EOF
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_version() {
|
||||
echo 0.0.0
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_parse() {
|
||||
local _argc_key _argc_action
|
||||
local _argc_subcmds="get_diff, get-diff, get_changed_files, get-changed-files, get_project_info, get-project-info"
|
||||
while [[ $_argc_index -lt $_argc_len ]]; do
|
||||
_argc_item="${argc__args[_argc_index]}"
|
||||
_argc_key="${_argc_item%%=*}"
|
||||
case "$_argc_key" in
|
||||
--help | -help | -h)
|
||||
_argc_usage
|
||||
;;
|
||||
--version | -version | -V)
|
||||
_argc_version
|
||||
;;
|
||||
--)
|
||||
_argc_dash="${#argc__positionals[@]}"
|
||||
argc__positionals+=("${argc__args[@]:$((_argc_index + 1))}")
|
||||
_argc_index=$_argc_len
|
||||
break
|
||||
;;
|
||||
get_diff | get-diff)
|
||||
_argc_index=$((_argc_index + 1))
|
||||
_argc_action=_argc_parse_get_diff
|
||||
break
|
||||
;;
|
||||
get_changed_files | get-changed-files)
|
||||
_argc_index=$((_argc_index + 1))
|
||||
_argc_action=_argc_parse_get_changed_files
|
||||
break
|
||||
;;
|
||||
get_project_info | get-project-info)
|
||||
_argc_index=$((_argc_index + 1))
|
||||
_argc_action=_argc_parse_get_project_info
|
||||
break
|
||||
;;
|
||||
help)
|
||||
local help_arg="${argc__args[$((_argc_index + 1))]:-}"
|
||||
case "$help_arg" in
|
||||
get_diff | get-diff)
|
||||
_argc_usage_get_diff
|
||||
;;
|
||||
get_changed_files | get-changed-files)
|
||||
_argc_usage_get_changed_files
|
||||
;;
|
||||
get_project_info | get-project-info)
|
||||
_argc_usage_get_project_info
|
||||
;;
|
||||
"")
|
||||
_argc_usage
|
||||
;;
|
||||
*)
|
||||
_argc_die "error: invalid value \`$help_arg\` for \`<command>\`"$'\n'" [possible values: $_argc_subcmds]"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
_argc_die "error: \`\` requires a subcommand but one was not provided"$'\n'" [subcommands: $_argc_subcmds]"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
if [[ -n "${_argc_action:-}" ]]; then
|
||||
$_argc_action
|
||||
else
|
||||
_argc_usage
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_usage_get_diff() {
|
||||
cat <<-'EOF'
|
||||
Get git diff for code review. Returns staged changes, or unstaged if nothing is staged, or HEAD~1 diff if working tree is clean.
|
||||
|
||||
USAGE: get_diff [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
--base <BASE> Optional base ref to diff against (e.g., "main", "HEAD~3", a commit SHA)
|
||||
-h, --help Print help
|
||||
|
||||
ENVIRONMENTS:
|
||||
LLM_OUTPUT [default: /dev/stdout]
|
||||
LLM_AGENT_VAR_PROJECT_DIR [default: .]
|
||||
EOF
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_parse_get_diff() {
|
||||
local _argc_key _argc_action
|
||||
local _argc_subcmds=""
|
||||
while [[ $_argc_index -lt $_argc_len ]]; do
|
||||
_argc_item="${argc__args[_argc_index]}"
|
||||
_argc_key="${_argc_item%%=*}"
|
||||
case "$_argc_key" in
|
||||
--help | -help | -h)
|
||||
_argc_usage_get_diff
|
||||
;;
|
||||
--)
|
||||
_argc_dash="${#argc__positionals[@]}"
|
||||
argc__positionals+=("${argc__args[@]:$((_argc_index + 1))}")
|
||||
_argc_index=$_argc_len
|
||||
break
|
||||
;;
|
||||
--base)
|
||||
_argc_take_args "--base <BASE>" 1 1 "-" ""
|
||||
_argc_index=$((_argc_index + _argc_take_args_len + 1))
|
||||
if [[ -z "${argc_base:-}" ]]; then
|
||||
argc_base="${_argc_take_args_values[0]:-}"
|
||||
else
|
||||
_argc_die "error: the argument \`--base\` cannot be used multiple times"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
if _argc_maybe_flag_option "-" "$_argc_item"; then
|
||||
_argc_die "error: unexpected argument \`$_argc_key\` found"
|
||||
fi
|
||||
argc__positionals+=("$_argc_item")
|
||||
_argc_index=$((_argc_index + 1))
|
||||
;;
|
||||
esac
|
||||
done
|
||||
if [[ -n "${_argc_action:-}" ]]; then
|
||||
$_argc_action
|
||||
else
|
||||
argc__fn=get_diff
|
||||
if [[ "${argc__positionals[0]:-}" == "help" ]] && [[ "${#argc__positionals[@]}" -eq 1 ]]; then
|
||||
_argc_usage_get_diff
|
||||
fi
|
||||
if [[ -z "${LLM_OUTPUT:-}" ]]; then
|
||||
export LLM_OUTPUT=/dev/stdout
|
||||
fi
|
||||
if [[ -z "${LLM_AGENT_VAR_PROJECT_DIR:-}" ]]; then
|
||||
export LLM_AGENT_VAR_PROJECT_DIR=.
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_usage_get_changed_files() {
|
||||
cat <<-'EOF'
|
||||
Get list of changed files with stats
|
||||
|
||||
USAGE: get_changed_files [OPTIONS]
|
||||
|
||||
OPTIONS:
|
||||
--base <BASE> Optional base ref to diff against
|
||||
-h, --help Print help
|
||||
|
||||
ENVIRONMENTS:
|
||||
LLM_OUTPUT [default: /dev/stdout]
|
||||
LLM_AGENT_VAR_PROJECT_DIR [default: .]
|
||||
EOF
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_parse_get_changed_files() {
|
||||
local _argc_key _argc_action
|
||||
local _argc_subcmds=""
|
||||
while [[ $_argc_index -lt $_argc_len ]]; do
|
||||
_argc_item="${argc__args[_argc_index]}"
|
||||
_argc_key="${_argc_item%%=*}"
|
||||
case "$_argc_key" in
|
||||
--help | -help | -h)
|
||||
_argc_usage_get_changed_files
|
||||
;;
|
||||
--)
|
||||
_argc_dash="${#argc__positionals[@]}"
|
||||
argc__positionals+=("${argc__args[@]:$((_argc_index + 1))}")
|
||||
_argc_index=$_argc_len
|
||||
break
|
||||
;;
|
||||
--base)
|
||||
_argc_take_args "--base <BASE>" 1 1 "-" ""
|
||||
_argc_index=$((_argc_index + _argc_take_args_len + 1))
|
||||
if [[ -z "${argc_base:-}" ]]; then
|
||||
argc_base="${_argc_take_args_values[0]:-}"
|
||||
else
|
||||
_argc_die "error: the argument \`--base\` cannot be used multiple times"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
if _argc_maybe_flag_option "-" "$_argc_item"; then
|
||||
_argc_die "error: unexpected argument \`$_argc_key\` found"
|
||||
fi
|
||||
argc__positionals+=("$_argc_item")
|
||||
_argc_index=$((_argc_index + 1))
|
||||
;;
|
||||
esac
|
||||
done
|
||||
if [[ -n "${_argc_action:-}" ]]; then
|
||||
$_argc_action
|
||||
else
|
||||
argc__fn=get_changed_files
|
||||
if [[ "${argc__positionals[0]:-}" == "help" ]] && [[ "${#argc__positionals[@]}" -eq 1 ]]; then
|
||||
_argc_usage_get_changed_files
|
||||
fi
|
||||
if [[ -z "${LLM_OUTPUT:-}" ]]; then
|
||||
export LLM_OUTPUT=/dev/stdout
|
||||
fi
|
||||
if [[ -z "${LLM_AGENT_VAR_PROJECT_DIR:-}" ]]; then
|
||||
export LLM_AGENT_VAR_PROJECT_DIR=.
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_usage_get_project_info() {
|
||||
cat <<-'EOF'
|
||||
Get project structure and type information
|
||||
|
||||
USAGE: get_project_info
|
||||
|
||||
ENVIRONMENTS:
|
||||
LLM_OUTPUT [default: /dev/stdout]
|
||||
LLM_AGENT_VAR_PROJECT_DIR [default: .]
|
||||
EOF
|
||||
exit
|
||||
}
|
||||
|
||||
_argc_parse_get_project_info() {
|
||||
local _argc_key _argc_action
|
||||
local _argc_subcmds=""
|
||||
while [[ $_argc_index -lt $_argc_len ]]; do
|
||||
_argc_item="${argc__args[_argc_index]}"
|
||||
_argc_key="${_argc_item%%=*}"
|
||||
case "$_argc_key" in
|
||||
--help | -help | -h)
|
||||
_argc_usage_get_project_info
|
||||
;;
|
||||
--)
|
||||
_argc_dash="${#argc__positionals[@]}"
|
||||
argc__positionals+=("${argc__args[@]:$((_argc_index + 1))}")
|
||||
_argc_index=$_argc_len
|
||||
break
|
||||
;;
|
||||
*)
|
||||
argc__positionals+=("$_argc_item")
|
||||
_argc_index=$((_argc_index + 1))
|
||||
;;
|
||||
esac
|
||||
done
|
||||
if [[ -n "${_argc_action:-}" ]]; then
|
||||
$_argc_action
|
||||
else
|
||||
argc__fn=get_project_info
|
||||
if [[ "${argc__positionals[0]:-}" == "help" ]] && [[ "${#argc__positionals[@]}" -eq 1 ]]; then
|
||||
_argc_usage_get_project_info
|
||||
fi
|
||||
if [[ -z "${LLM_OUTPUT:-}" ]]; then
|
||||
export LLM_OUTPUT=/dev/stdout
|
||||
fi
|
||||
if [[ -z "${LLM_AGENT_VAR_PROJECT_DIR:-}" ]]; then
|
||||
export LLM_AGENT_VAR_PROJECT_DIR=.
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_take_args() {
|
||||
_argc_take_args_values=()
|
||||
_argc_take_args_len=0
|
||||
local param="$1" min="$2" max="$3" signs="$4" delimiter="$5"
|
||||
if [[ "$min" -eq 0 ]] && [[ "$max" -eq 0 ]]; then
|
||||
return
|
||||
fi
|
||||
local _argc_take_index=$((_argc_index + 1)) _argc_take_value
|
||||
if [[ "$_argc_item" == *=* ]]; then
|
||||
_argc_take_args_values=("${_argc_item##*=}")
|
||||
else
|
||||
while [[ $_argc_take_index -lt $_argc_len ]]; do
|
||||
_argc_take_value="${argc__args[_argc_take_index]}"
|
||||
if _argc_maybe_flag_option "$signs" "$_argc_take_value"; then
|
||||
if [[ "${#_argc_take_value}" -gt 1 ]]; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
_argc_take_args_values+=("$_argc_take_value")
|
||||
_argc_take_args_len=$((_argc_take_args_len + 1))
|
||||
if [[ "$_argc_take_args_len" -ge "$max" ]]; then
|
||||
break
|
||||
fi
|
||||
_argc_take_index=$((_argc_take_index + 1))
|
||||
done
|
||||
fi
|
||||
if [[ "${#_argc_take_args_values[@]}" -lt "$min" ]]; then
|
||||
_argc_die "error: incorrect number of values for \`$param\`"
|
||||
fi
|
||||
if [[ -n "$delimiter" ]] && [[ "${#_argc_take_args_values[@]}" -gt 0 ]]; then
|
||||
local item values arr=()
|
||||
for item in "${_argc_take_args_values[@]}"; do
|
||||
IFS="$delimiter" read -r -a values <<<"$item"
|
||||
arr+=("${values[@]}")
|
||||
done
|
||||
_argc_take_args_values=("${arr[@]}")
|
||||
fi
|
||||
}
|
||||
|
||||
_argc_maybe_flag_option() {
|
||||
local signs="$1" arg="$2"
|
||||
if [[ -z "$signs" ]]; then
|
||||
return 1
|
||||
fi
|
||||
local cond=false
|
||||
if [[ "$signs" == *"+"* ]]; then
|
||||
if [[ "$arg" =~ ^\+[^+].* ]]; then
|
||||
cond=true
|
||||
fi
|
||||
elif [[ "$arg" == -* ]]; then
|
||||
if (( ${#arg} < 3 )) || [[ ! "$arg" =~ ^---.* ]]; then
|
||||
cond=true
|
||||
fi
|
||||
fi
|
||||
if [[ "$cond" == "false" ]]; then
|
||||
return 1
|
||||
fi
|
||||
local value="${arg%%=*}"
|
||||
if [[ "$value" =~ [[:space:]] ]]; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
_argc_die() {
|
||||
if [[ $# -eq 0 ]]; then
|
||||
cat
|
||||
else
|
||||
echo "$*" >&2
|
||||
fi
|
||||
exit 1
|
||||
}
|
||||
|
||||
_argc_run "$@"
|
||||
|
||||
# ARGC-BUILD }
|
||||
@@ -0,0 +1,40 @@
|
||||
# Coder
|
||||
|
||||
An AI agent that assists you with your coding tasks.
|
||||
|
||||
This agent is designed to be delegated to by the **[Sisyphus](../sisyphus/README.md)** agent to implement code specifications. Sisyphus
|
||||
acts as the coordinator/architect, while Coder handles the implementation details.
|
||||
|
||||
## Features
|
||||
|
||||
- 🏗️ Intelligent project structure creation and management
|
||||
- 🖼️ Convert screenshots into clean, functional code
|
||||
- 📁 Comprehensive file system operations (create folders, files, read/write files)
|
||||
- 🧐 Advanced code analysis and improvement suggestions
|
||||
- 📊 Precise diff-based file editing for controlled code modifications
|
||||
|
||||
It can also be used as a standalone tool for direct coding assistance.
|
||||
|
||||
## 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
|
||||
them), and modify the agent definition to look like this:
|
||||
|
||||
```yaml
|
||||
# ...
|
||||
|
||||
mcp_servers:
|
||||
- jetbrains # The name of your configured IDE MCP server
|
||||
|
||||
global_tools:
|
||||
# Keep useful read-only tools for reading files in other non-project directories
|
||||
- fs_read.sh
|
||||
- fs_grep.sh
|
||||
- fs_glob.sh
|
||||
# - fs_write.sh
|
||||
# - fs_patch.sh
|
||||
- execute_command.sh
|
||||
|
||||
# ...
|
||||
```
|
||||
@@ -0,0 +1,129 @@
|
||||
name: coder
|
||||
description: Implementation agent - writes code, follows patterns, verifies with builds
|
||||
version: 1.0.0
|
||||
temperature: 0.1
|
||||
|
||||
auto_continue: true
|
||||
max_auto_continues: 15
|
||||
inject_todo_instructions: true
|
||||
|
||||
variables:
|
||||
- name: project_dir
|
||||
description: Project directory to work in
|
||||
default: '.'
|
||||
- name: auto_confirm
|
||||
description: Auto-confirm command execution
|
||||
default: '1'
|
||||
|
||||
global_tools:
|
||||
- fs_read.sh
|
||||
- fs_grep.sh
|
||||
- fs_glob.sh
|
||||
- fs_write.sh
|
||||
- fs_patch.sh
|
||||
- execute_command.sh
|
||||
|
||||
instructions: |
|
||||
You are a senior engineer. You write code that works on the first try.
|
||||
|
||||
## Your Mission
|
||||
|
||||
Given an implementation task:
|
||||
1. Check for orchestrator context first (see below)
|
||||
2. Fill gaps only. Read files NOT already covered in context
|
||||
3. Write the code (using tools, NOT chat output)
|
||||
4. Verify it compiles/builds
|
||||
5. Signal completion with a summary
|
||||
|
||||
## Using Orchestrator Context (IMPORTANT)
|
||||
|
||||
When spawned by sisyphus, your prompt will often contain a `<context>` block
|
||||
with prior findings: file paths, code patterns, and conventions discovered by
|
||||
explore agents.
|
||||
|
||||
**If context is provided:**
|
||||
1. Use it as your primary reference. Don't re-read files already summarized
|
||||
2. Follow the code patterns shown. Snippets in context ARE the style guide
|
||||
3. Read the referenced files ONLY IF you need more detail (e.g. full function
|
||||
signature, import list, or adjacent code not included in the snippet)
|
||||
4. If context includes a "Conventions" section, follow it exactly
|
||||
|
||||
**If context is NOT provided or is too vague to act on:**
|
||||
Fall back to self-exploration: grep for similar files, read 1-2 examples,
|
||||
match their style.
|
||||
|
||||
**Never ignore provided context.** It represents work already done upstream.
|
||||
|
||||
## Todo System
|
||||
|
||||
For multi-file changes:
|
||||
1. `todo__init` with the implementation goal
|
||||
2. `todo__add` for each file to create/modify
|
||||
3. Implement each, calling `todo__done` immediately after
|
||||
|
||||
## Writing Code
|
||||
|
||||
**CRITICAL**: Write code using `write_file` tool, NEVER paste code in chat.
|
||||
|
||||
Correct:
|
||||
```
|
||||
write_file --path "src/user.rs" --content "pub struct User { ... }"
|
||||
```
|
||||
|
||||
Wrong:
|
||||
```
|
||||
Here's the implementation:
|
||||
\`\`\`rust
|
||||
pub struct User { ... }
|
||||
\`\`\`
|
||||
```
|
||||
|
||||
## File Reading Strategy (IMPORTANT - minimize token usage)
|
||||
|
||||
1. **Use grep to find relevant code** - `fs_grep --pattern "fn handle_request" --include "*.rs"` finds where things are
|
||||
2. **Read only what you need** - `fs_read --path "src/main.rs" --offset 50 --limit 30` reads lines 50-79
|
||||
3. **Never cat entire large files** - If 500+ lines, read the relevant section after grepping for it
|
||||
4. **Use glob to find files** - `fs_glob --pattern "*.rs" --path src/` discovers files by name
|
||||
|
||||
## Pattern Matching
|
||||
|
||||
Before writing ANY file:
|
||||
1. Find a similar existing file (use `fs_grep` to locate, then `fs_read` to examine)
|
||||
2. Match its style: imports, naming, structure
|
||||
3. Follow the same patterns exactly
|
||||
|
||||
## Verification
|
||||
|
||||
After writing files:
|
||||
1. Run `verify_build` to check compilation
|
||||
2. If it fails, fix the error (minimal change)
|
||||
3. Don't move on until build passes
|
||||
|
||||
## Completion Signal
|
||||
|
||||
When done, end your response with a summary so the parent agent knows what happened:
|
||||
|
||||
```
|
||||
CODER_COMPLETE: [summary of what was implemented, which files were created/modified, and build status]
|
||||
```
|
||||
|
||||
Or if something went wrong:
|
||||
```
|
||||
CODER_FAILED: [what went wrong]
|
||||
```
|
||||
|
||||
## Rules
|
||||
|
||||
1. **Write code via tools** - Never output code to chat
|
||||
2. **Follow patterns** - Read existing files first
|
||||
3. **Verify builds** - Don't finish without checking
|
||||
4. **Minimal fixes** - If build fails, fix precisely
|
||||
5. **No refactoring** - Only implement what's asked
|
||||
|
||||
## Context
|
||||
- Project: {{project_dir}}
|
||||
- CWD: {{__cwd__}}
|
||||
- Shell: {{__shell__}}
|
||||
|
||||
## Available tools:
|
||||
{{__tools__}}
|
||||
Executable
+216
@@ -0,0 +1,216 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "$LLM_PROMPT_UTILS_FILE"
|
||||
source "$LLM_ROOT_DIR/agents/.shared/utils.sh"
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout
|
||||
# @env LLM_AGENT_VAR_PROJECT_DIR=.
|
||||
# @describe Coder agent tools for implementing code changes
|
||||
|
||||
_project_dir() {
|
||||
local dir="${LLM_AGENT_VAR_PROJECT_DIR:-.}"
|
||||
(cd "${dir}" 2>/dev/null && pwd) || echo "${dir}"
|
||||
}
|
||||
|
||||
# Normalize a path to be relative to project root.
|
||||
# Strips the project_dir prefix if the LLM passes an absolute path.
|
||||
# Usage: local rel_path; rel_path=$(_normalize_path "/abs/or/rel/path")
|
||||
_normalize_path() {
|
||||
local input_path="$1"
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
|
||||
if [[ "${input_path}" == /* ]]; then
|
||||
input_path="${input_path#"${project_dir}"/}"
|
||||
fi
|
||||
|
||||
input_path="${input_path#./}"
|
||||
echo "${input_path}"
|
||||
}
|
||||
|
||||
# @cmd Read a file's contents before modifying
|
||||
# @option --path! Path to the file (relative to project root)
|
||||
read_file() {
|
||||
local file_path
|
||||
# shellcheck disable=SC2154
|
||||
file_path=$(_normalize_path "${argc_path}")
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
local full_path="${project_dir}/${file_path}"
|
||||
|
||||
if [[ ! -f "${full_path}" ]]; then
|
||||
warn "File not found: ${file_path}" >> "$LLM_OUTPUT"
|
||||
return 0
|
||||
fi
|
||||
|
||||
{
|
||||
info "Reading: ${file_path}"
|
||||
echo ""
|
||||
cat "${full_path}"
|
||||
} >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
# @cmd Write complete file contents
|
||||
# @option --path! Path for the file (relative to project root)
|
||||
# @option --content! Complete file contents to write
|
||||
write_file() {
|
||||
local file_path
|
||||
file_path=$(_normalize_path "${argc_path}")
|
||||
# shellcheck disable=SC2154
|
||||
local content="${argc_content}"
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
local full_path="${project_dir}/${file_path}"
|
||||
|
||||
mkdir -p "$(dirname "${full_path}")"
|
||||
printf '%s' "${content}" > "${full_path}"
|
||||
|
||||
green "Wrote: ${file_path}" >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
# @cmd Find files similar to a given path (for pattern matching)
|
||||
# @option --path! Path to find similar files for
|
||||
find_similar_files() {
|
||||
local file_path
|
||||
file_path=$(_normalize_path "${argc_path}")
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
|
||||
local ext="${file_path##*.}"
|
||||
local dir
|
||||
dir=$(dirname "${file_path}")
|
||||
|
||||
info "Similar files to: ${file_path}" >> "$LLM_OUTPUT"
|
||||
echo "" >> "$LLM_OUTPUT"
|
||||
|
||||
local results
|
||||
results=$(find "${project_dir}/${dir}" -maxdepth 1 -type f -name "*.${ext}" \
|
||||
! -name "$(basename "${file_path}")" \
|
||||
! -name "*test*" \
|
||||
! -name "*spec*" \
|
||||
2>/dev/null | sed "s|^${project_dir}/||" | head -3)
|
||||
|
||||
if [[ -z "${results}" ]]; then
|
||||
results=$(find "${project_dir}/src" -type f -name "*.${ext}" \
|
||||
! -name "*test*" \
|
||||
! -name "*spec*" \
|
||||
-not -path '*/target/*' \
|
||||
2>/dev/null | sed "s|^${project_dir}/||" | head -3)
|
||||
fi
|
||||
|
||||
if [[ -n "${results}" ]]; then
|
||||
echo "${results}" >> "$LLM_OUTPUT"
|
||||
else
|
||||
warn "No similar files found" >> "$LLM_OUTPUT"
|
||||
fi
|
||||
}
|
||||
|
||||
# @cmd Verify the project builds successfully
|
||||
verify_build() {
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
|
||||
local project_info
|
||||
project_info=$(detect_project "${project_dir}")
|
||||
local build_cmd
|
||||
build_cmd=$(echo "${project_info}" | jq -r '.check // .build')
|
||||
|
||||
if [[ -z "${build_cmd}" ]] || [[ "${build_cmd}" == "null" ]]; then
|
||||
warn "No build command detected" >> "$LLM_OUTPUT"
|
||||
return 0
|
||||
fi
|
||||
|
||||
info "Running: ${build_cmd}" >> "$LLM_OUTPUT"
|
||||
echo "" >> "$LLM_OUTPUT"
|
||||
|
||||
local output exit_code=0
|
||||
output=$(cd "${project_dir}" && eval "${build_cmd}" 2>&1) || exit_code=$?
|
||||
|
||||
echo "${output}" >> "$LLM_OUTPUT"
|
||||
echo "" >> "$LLM_OUTPUT"
|
||||
|
||||
if [[ ${exit_code} -eq 0 ]]; then
|
||||
green "BUILD SUCCESS" >> "$LLM_OUTPUT"
|
||||
return 0
|
||||
else
|
||||
error "BUILD FAILED (exit code: ${exit_code})" >> "$LLM_OUTPUT"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# @cmd Run project tests
|
||||
run_tests() {
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
|
||||
local project_info
|
||||
project_info=$(detect_project "${project_dir}")
|
||||
local test_cmd
|
||||
test_cmd=$(echo "${project_info}" | jq -r '.test')
|
||||
|
||||
if [[ -z "${test_cmd}" ]] || [[ "${test_cmd}" == "null" ]]; then
|
||||
warn "No test command detected" >> "$LLM_OUTPUT"
|
||||
return 0
|
||||
fi
|
||||
|
||||
info "Running: ${test_cmd}" >> "$LLM_OUTPUT"
|
||||
echo "" >> "$LLM_OUTPUT"
|
||||
|
||||
local output exit_code=0
|
||||
output=$(cd "${project_dir}" && eval "${test_cmd}" 2>&1) || exit_code=$?
|
||||
|
||||
echo "${output}" >> "$LLM_OUTPUT"
|
||||
echo "" >> "$LLM_OUTPUT"
|
||||
|
||||
if [[ ${exit_code} -eq 0 ]]; then
|
||||
green "TESTS PASSED" >> "$LLM_OUTPUT"
|
||||
return 0
|
||||
else
|
||||
error "TESTS FAILED (exit code: ${exit_code})" >> "$LLM_OUTPUT"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# @cmd Get project structure for context
|
||||
get_project_structure() {
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
|
||||
local project_info
|
||||
project_info=$(detect_project "${project_dir}")
|
||||
|
||||
{
|
||||
info "Project: $(echo "${project_info}" | jq -r '.type')"
|
||||
echo ""
|
||||
|
||||
get_tree "${project_dir}" 2
|
||||
} >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
# @cmd Search for content in the codebase
|
||||
# @option --pattern! Pattern to search for
|
||||
search_code() {
|
||||
# shellcheck disable=SC2154
|
||||
local pattern="${argc_pattern}"
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
|
||||
info "Searching: ${pattern}" >> "$LLM_OUTPUT"
|
||||
echo "" >> "$LLM_OUTPUT"
|
||||
|
||||
local results
|
||||
results=$(grep -rn "${pattern}" "${project_dir}" 2>/dev/null | \
|
||||
grep -v '/target/' | \
|
||||
grep -v '/node_modules/' | \
|
||||
grep -v '/.git/' | \
|
||||
sed "s|^${project_dir}/||" | \
|
||||
head -20) || true
|
||||
|
||||
if [[ -n "${results}" ]]; then
|
||||
echo "${results}" >> "$LLM_OUTPUT"
|
||||
else
|
||||
warn "No matches" >> "$LLM_OUTPUT"
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
# Demo
|
||||
|
||||
This agent serves as a demo to guide agent development and showcase various agent capabilities.
|
||||
|
||||
To enable tools, Loki will look for the first `tools.py` or `tools.sh` file it finds in this directory.
|
||||
|
||||
The base configuration using `tools.py`. To switch to using `tools.sh`, rename or remove `tools.py`.
|
||||
@@ -0,0 +1,36 @@
|
||||
name: Demo
|
||||
description: An AI agent that demonstrates agent capabilities
|
||||
version: 0.1.0
|
||||
global_tools:
|
||||
- execute_command.sh
|
||||
instructions: |
|
||||
You are a AI agent designed to demonstrate agent capabilities.
|
||||
|
||||
<tools>
|
||||
{{__tools__}}
|
||||
</tools>
|
||||
|
||||
<system>
|
||||
os: {{__os__}}
|
||||
os_family: {{__os_family__}}
|
||||
arch: {{__arch__}}
|
||||
shell: {{__shell__}}
|
||||
locale: {{__locale__}}
|
||||
now: {{__now__}}
|
||||
cwd: {{__cwd__}}
|
||||
</system>
|
||||
|
||||
<user>
|
||||
username: {{username}}
|
||||
</user>
|
||||
variables:
|
||||
- name: username
|
||||
description: Your user name
|
||||
conversation_starters:
|
||||
- What is my username?
|
||||
- What is my current shell?
|
||||
- What is my ip?
|
||||
- How much disk space is left on my PC??
|
||||
- How to create an agent?
|
||||
documents:
|
||||
- README.md
|
||||
@@ -0,0 +1,9 @@
|
||||
import urllib.request
|
||||
|
||||
def get_ipinfo():
|
||||
"""
|
||||
Get the ip info
|
||||
"""
|
||||
with urllib.request.urlopen("https://httpbin.org/ip") as response:
|
||||
data = response.read()
|
||||
return data.decode('utf-8')
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
# @cmd Get the ip info
|
||||
get_ipinfo() {
|
||||
curl -fsSL https://httpbin.org/ip >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
# Explore
|
||||
|
||||
An AI agent specialized in exploring codebases, finding patterns, and understanding project structures.
|
||||
|
||||
This agent is designed to be delegated to by the **[Sisyphus](../sisyphus/README.md)** agent to gather information and context. Sisyphus
|
||||
acts as the coordinator/architect, while Explore handles the research and discovery phase.
|
||||
|
||||
It can also be used as a standalone tool for understanding codebases and finding specific information.
|
||||
|
||||
## Features
|
||||
|
||||
- 🔍 Deep codebase exploration and pattern matching
|
||||
- 📂 File system navigation and content analysis
|
||||
- 🧠 Context gathering for complex tasks
|
||||
- 🛡️ Read-only operations for safe investigation
|
||||
|
||||
## 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
|
||||
them), and modify the agent definition to look like this:
|
||||
|
||||
```yaml
|
||||
# ...
|
||||
|
||||
mcp_servers:
|
||||
- jetbrains # The name of your configured IDE MCP server
|
||||
|
||||
global_tools:
|
||||
- fs_read.sh
|
||||
- fs_grep.sh
|
||||
- fs_glob.sh
|
||||
- fs_ls.sh
|
||||
- web_search_loki.sh
|
||||
|
||||
# ...
|
||||
```
|
||||
@@ -0,0 +1,78 @@
|
||||
name: explore
|
||||
description: Fast codebase exploration agent - finds patterns, structures, and relevant files
|
||||
version: 1.0.0
|
||||
temperature: 0.1
|
||||
|
||||
variables:
|
||||
- name: project_dir
|
||||
description: Project directory to explore
|
||||
default: '.'
|
||||
|
||||
mcp_servers:
|
||||
- ddg-search
|
||||
global_tools:
|
||||
- fs_read.sh
|
||||
- fs_grep.sh
|
||||
- fs_glob.sh
|
||||
- fs_ls.sh
|
||||
|
||||
instructions: |
|
||||
You are a codebase explorer. Your job: Search, find, report. Nothing else.
|
||||
|
||||
## Your Mission
|
||||
|
||||
Given a search task, you:
|
||||
1. Search for relevant files and patterns
|
||||
2. Read key files to understand structure
|
||||
3. Report findings concisely
|
||||
4. Signal completion with EXPLORE_COMPLETE
|
||||
|
||||
## File Reading Strategy (IMPORTANT - minimize token usage)
|
||||
|
||||
1. **Find first, read second** - Never read a file without knowing why
|
||||
2. **Use grep to locate** - `fs_grep --pattern "struct User" --include "*.rs"` finds exactly where things are
|
||||
3. **Use glob to discover** - `fs_glob --pattern "*.rs" --path src/` finds files by name
|
||||
4. **Read targeted sections** - `fs_read --path "src/main.rs" --offset 50 --limit 30` reads only lines 50-79
|
||||
5. **Never read entire large files** - If a file is 500+ lines, read the relevant section only
|
||||
|
||||
## Available Actions
|
||||
|
||||
- `fs_grep --pattern "struct User" --include "*.rs"` - Find content across files
|
||||
- `fs_glob --pattern "*.rs" --path src/` - Find files by name pattern
|
||||
- `fs_read --path "src/main.rs"` - Read a file (with line numbers)
|
||||
- `fs_read --path "src/main.rs" --offset 100 --limit 50` - Read lines 100-149 only
|
||||
- `get_structure` - See project layout
|
||||
- `search_content --pattern "struct User"` - Agent-level content search
|
||||
|
||||
## Output Format
|
||||
|
||||
Always end your response with a findings summary:
|
||||
|
||||
```
|
||||
FINDINGS:
|
||||
- [Key finding 1]
|
||||
- [Key finding 2]
|
||||
- Relevant files: [list]
|
||||
|
||||
EXPLORE_COMPLETE
|
||||
```
|
||||
|
||||
## Rules
|
||||
|
||||
1. **Be fast** - Don't read every file, read representative ones
|
||||
2. **Be focused** - Answer the specific question asked
|
||||
3. **Be concise** - Report findings, not your process
|
||||
4. **Never modify files** - You are read-only
|
||||
5. **Limit reads** - Max 5 file reads per exploration
|
||||
|
||||
## Context
|
||||
- Project: {{project_dir}}
|
||||
- CWD: {{__cwd__}}
|
||||
|
||||
## Available Tools:
|
||||
{{__tools__}}
|
||||
|
||||
conversation_starters:
|
||||
- 'Find how authentication is implemented'
|
||||
- 'What patterns are used for API endpoints'
|
||||
- 'Show me the project structure'
|
||||
Executable
+175
@@ -0,0 +1,175 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "$LLM_PROMPT_UTILS_FILE"
|
||||
source "$LLM_ROOT_DIR/agents/.shared/utils.sh"
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout
|
||||
# @env LLM_AGENT_VAR_PROJECT_DIR=.
|
||||
# @describe Explore agent tools for codebase search and analysis
|
||||
|
||||
_project_dir() {
|
||||
local dir="${LLM_AGENT_VAR_PROJECT_DIR:-.}"
|
||||
(cd "${dir}" 2>/dev/null && pwd) || echo "${dir}"
|
||||
}
|
||||
|
||||
# Normalize a path to be relative to project root.
|
||||
# Strips the project_dir prefix if the LLM passes an absolute path.
|
||||
_normalize_path() {
|
||||
local input_path="$1"
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
|
||||
if [[ "${input_path}" == /* ]]; then
|
||||
input_path="${input_path#"${project_dir}"/}"
|
||||
fi
|
||||
|
||||
input_path="${input_path#./}"
|
||||
echo "${input_path}"
|
||||
}
|
||||
|
||||
# @cmd Get project structure and layout
|
||||
get_structure() {
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
|
||||
info "Project structure:" >> "$LLM_OUTPUT"
|
||||
echo "" >> "$LLM_OUTPUT"
|
||||
|
||||
local project_info
|
||||
project_info=$(detect_project "${project_dir}")
|
||||
|
||||
{
|
||||
echo "Type: $(echo "${project_info}" | jq -r '.type')"
|
||||
echo ""
|
||||
|
||||
get_tree "${project_dir}" 3
|
||||
} >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
# @cmd Search for files by name pattern
|
||||
# @option --pattern! File name pattern (e.g., "*.rs", "config*", "*test*")
|
||||
search_files() {
|
||||
# shellcheck disable=SC2154
|
||||
local pattern="${argc_pattern}"
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
|
||||
info "Files matching: ${pattern}" >> "$LLM_OUTPUT"
|
||||
echo "" >> "$LLM_OUTPUT"
|
||||
|
||||
local results
|
||||
results=$(_search_files "${pattern}" "${project_dir}")
|
||||
|
||||
if [[ -n "${results}" ]]; then
|
||||
echo "${results}" >> "$LLM_OUTPUT"
|
||||
else
|
||||
warn "No files found" >> "$LLM_OUTPUT"
|
||||
fi
|
||||
}
|
||||
|
||||
# @cmd Search for content in files
|
||||
# @option --pattern! Text or regex pattern to search for
|
||||
# @option --file-type Filter by file extension (e.g., "rs", "py", "ts")
|
||||
search_content() {
|
||||
local pattern="${argc_pattern}"
|
||||
local file_type="${argc_file_type:-}"
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
|
||||
info "Searching: ${pattern}" >> "$LLM_OUTPUT"
|
||||
echo "" >> "$LLM_OUTPUT"
|
||||
|
||||
local include_arg=""
|
||||
if [[ -n "${file_type}" ]]; then
|
||||
include_arg="--include=*.${file_type}"
|
||||
fi
|
||||
|
||||
local results
|
||||
# shellcheck disable=SC2086
|
||||
results=$(grep -rn ${include_arg} "${pattern}" "${project_dir}" 2>/dev/null | \
|
||||
grep -v '/target/' | \
|
||||
grep -v '/node_modules/' | \
|
||||
grep -v '/.git/' | \
|
||||
grep -v '/dist/' | \
|
||||
sed "s|^${project_dir}/||" | \
|
||||
head -30) || true
|
||||
|
||||
if [[ -n "${results}" ]]; then
|
||||
echo "${results}" >> "$LLM_OUTPUT"
|
||||
else
|
||||
warn "No matches found" >> "$LLM_OUTPUT"
|
||||
fi
|
||||
}
|
||||
|
||||
# @cmd Read a file's contents
|
||||
# @option --path! Path to the file (relative to project root)
|
||||
# @option --lines Maximum lines to read (default: 200)
|
||||
read_file() {
|
||||
local file_path
|
||||
# shellcheck disable=SC2154
|
||||
file_path=$(_normalize_path "${argc_path}")
|
||||
local max_lines="${argc_lines:-200}"
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
|
||||
local full_path="${project_dir}/${file_path}"
|
||||
|
||||
if [[ ! -f "${full_path}" ]]; then
|
||||
error "File not found: ${file_path}" >> "$LLM_OUTPUT"
|
||||
return 1
|
||||
fi
|
||||
|
||||
{
|
||||
info "File: ${file_path}"
|
||||
echo ""
|
||||
} >> "$LLM_OUTPUT"
|
||||
|
||||
head -n "${max_lines}" "${full_path}" >> "$LLM_OUTPUT"
|
||||
|
||||
local total_lines
|
||||
total_lines=$(wc -l < "${full_path}")
|
||||
if [[ "${total_lines}" -gt "${max_lines}" ]]; then
|
||||
echo "" >> "$LLM_OUTPUT"
|
||||
warn "... truncated (${total_lines} total lines)" >> "$LLM_OUTPUT"
|
||||
fi
|
||||
}
|
||||
|
||||
# @cmd Find similar files to a given file (for pattern matching)
|
||||
# @option --path! Path to the reference file
|
||||
find_similar() {
|
||||
local file_path
|
||||
file_path=$(_normalize_path "${argc_path}")
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
|
||||
local ext="${file_path##*.}"
|
||||
local dir
|
||||
dir=$(dirname "${file_path}")
|
||||
|
||||
info "Files similar to: ${file_path}" >> "$LLM_OUTPUT"
|
||||
echo "" >> "$LLM_OUTPUT"
|
||||
|
||||
local results
|
||||
results=$(find "${project_dir}/${dir}" -maxdepth 1 -type f -name "*.${ext}" \
|
||||
! -name "$(basename "${file_path}")" \
|
||||
! -name "*test*" \
|
||||
! -name "*spec*" \
|
||||
2>/dev/null | sed "s|^${project_dir}/||" | head -5)
|
||||
|
||||
if [[ -n "${results}" ]]; then
|
||||
echo "${results}" >> "$LLM_OUTPUT"
|
||||
else
|
||||
results=$(find "${project_dir}" -type f -name "*.${ext}" \
|
||||
! -name "$(basename "${file_path}")" \
|
||||
! -name "*test*" \
|
||||
-not -path '*/target/*' \
|
||||
2>/dev/null | sed "s|^${project_dir}/||" | head -5)
|
||||
if [[ -n "${results}" ]]; then
|
||||
echo "${results}" >> "$LLM_OUTPUT"
|
||||
else
|
||||
warn "No similar files found" >> "$LLM_OUTPUT"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
# File Reviewer
|
||||
|
||||
A specialized worker agent that reviews a single file's diff for bugs, style issues, and cross-cutting concerns.
|
||||
|
||||
This agent is designed to be spawned by the **[Code Reviewer](../code-reviewer/README.md)** agent. It focuses deeply on
|
||||
one file while communicating with sibling agents to catch issues that span multiple files.
|
||||
|
||||
## Features
|
||||
|
||||
- 🔍 **Deep Analysis**: Focuses on bugs, logic errors, security issues, and style problems in a single file.
|
||||
- 🗣️ **Teammate Communication**: Sends and receives alerts to/from sibling reviewers about interface or dependency
|
||||
changes.
|
||||
- 🎯 **Targeted Reading**: Reads only relevant context around changed lines to stay efficient.
|
||||
- 🏷️ **Structured Findings**: Categorizes issues by severity (🔴 Critical, 🟡 Warning, 🟢 Suggestion, 💡 Nitpick).
|
||||
|
||||
## 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
|
||||
them), and modify the agent definition to look like this:
|
||||
|
||||
```yaml
|
||||
# ...
|
||||
|
||||
mcp_servers:
|
||||
- jetbrains # The name of your configured IDE MCP server
|
||||
|
||||
global_tools:
|
||||
- fs_read.sh
|
||||
- fs_grep.sh
|
||||
- fs_glob.sh
|
||||
|
||||
# ...
|
||||
```
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
name: file-reviewer
|
||||
description: Reviews a single file's diff for bugs, style issues, and cross-cutting concerns
|
||||
version: 1.0.0
|
||||
temperature: 0.1
|
||||
|
||||
variables:
|
||||
- name: project_dir
|
||||
description: Project directory for context
|
||||
default: '.'
|
||||
|
||||
global_tools:
|
||||
- fs_read.sh
|
||||
- fs_grep.sh
|
||||
- fs_glob.sh
|
||||
|
||||
instructions: |
|
||||
You are a precise code reviewer. You review ONE file's diff and produce structured findings.
|
||||
|
||||
## Your Mission
|
||||
|
||||
You receive a git diff for a single file. Your job:
|
||||
1. Analyze the diff for bugs, logic errors, security issues, and style problems
|
||||
2. Read surrounding code for context (use `fs_read` with targeted offsets)
|
||||
3. Check your inbox for cross-cutting alerts from sibling reviewers
|
||||
4. Send alerts to siblings if you spot cross-file issues
|
||||
5. Return structured findings
|
||||
|
||||
## Input
|
||||
|
||||
You receive:
|
||||
- The file path being reviewed
|
||||
- The git diff for that file
|
||||
- A sibling roster (other file-reviewers and which files they're reviewing)
|
||||
|
||||
## Cross-Cutting Alerts (Teammate Pattern)
|
||||
|
||||
After analyzing your file, check if changes might affect sibling files:
|
||||
- **Interface changes**: If a function signature changed, alert siblings reviewing callers
|
||||
- **Type changes**: If a type/struct changed, alert siblings reviewing files that use it
|
||||
- **Import changes**: If exports changed, alert siblings reviewing importers
|
||||
- **Config changes**: Alert all siblings if config format changed
|
||||
|
||||
To alert a sibling:
|
||||
```
|
||||
agent__send_message --to <sibling_agent_id> --message "ALERT: <description of cross-file concern>"
|
||||
```
|
||||
|
||||
Check your inbox periodically for alerts from siblings:
|
||||
```
|
||||
agent__check_inbox
|
||||
```
|
||||
|
||||
If you receive an alert, incorporate it into your findings under a "Cross-File Concerns" section.
|
||||
|
||||
## File Reading Strategy
|
||||
|
||||
1. **Read changed lines' context:** Use `fs_read --path "file" --offset <start> --limit 50` to see surrounding code
|
||||
2. **Grep for usage:** `fs_grep --pattern "function_name" --include "*.rs"` to find callers
|
||||
3. **Never read entire large files:** Target the changed regions only
|
||||
4. **Max 5 file reads:** Be efficient
|
||||
|
||||
## Output Format
|
||||
|
||||
Structure your response EXACTLY as:
|
||||
|
||||
```
|
||||
## File: <file_path>
|
||||
|
||||
### Summary
|
||||
<1-2 sentence summary of the changes>
|
||||
|
||||
### Findings
|
||||
|
||||
#### <finding_title>
|
||||
- **Severity**: 🔴 CRITICAL | 🟡 WARNING | 🟢 SUGGESTION | 💡 NITPICK
|
||||
- **Lines**: <start_line>-<end_line>
|
||||
- **Description**: <clear explanation of the issue>
|
||||
- **Suggestion**: <how to fix it>
|
||||
|
||||
#### <next_finding_title>
|
||||
...
|
||||
|
||||
### Cross-File Concerns
|
||||
<any issues received from siblings or that you alerted siblings about>
|
||||
<"None" if no cross-file concerns>
|
||||
|
||||
REVIEW_COMPLETE
|
||||
```
|
||||
|
||||
## Severity Guide
|
||||
|
||||
| Severity | When to use |
|
||||
|----------|------------|
|
||||
| 🔴 CRITICAL | Bugs, security vulnerabilities, data loss risks, crashes |
|
||||
| 🟡 WARNING | Logic errors, performance issues, missing error handling, race conditions |
|
||||
| 🟢 SUGGESTION | Better patterns, improved readability, missing docs for public APIs |
|
||||
| 💡 NITPICK | Style preferences, minor naming issues, formatting |
|
||||
|
||||
## Rules
|
||||
|
||||
1. **Be specific:** Reference exact line numbers and code
|
||||
2. **Be actionable:** Every finding must have a suggestion
|
||||
3. **Don't nitpick formatting:** If a formatter/linter exists (check for .rustfmt.toml, .prettierrc, etc.)
|
||||
4. **Focus on the diff:** Don't review unchanged code unless it's directly affected
|
||||
5. **Never modify files:** You are read-only
|
||||
6. **Always end with REVIEW_COMPLETE**
|
||||
|
||||
## Context
|
||||
- Project: {{project_dir}}
|
||||
- CWD: {{__cwd__}}
|
||||
|
||||
## Available Tools:
|
||||
{{__tools__}}
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "$LLM_PROMPT_UTILS_FILE"
|
||||
source "$LLM_ROOT_DIR/agents/.shared/utils.sh"
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout
|
||||
# @env LLM_AGENT_VAR_PROJECT_DIR=.
|
||||
# @describe File reviewer tools for single-file code review
|
||||
|
||||
_project_dir() {
|
||||
local dir="${LLM_AGENT_VAR_PROJECT_DIR:-.}"
|
||||
(cd "${dir}" 2>/dev/null && pwd) || echo "${dir}"
|
||||
}
|
||||
|
||||
# @cmd Get project structure to understand codebase layout
|
||||
get_structure() {
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
|
||||
info "Project structure:" >> "$LLM_OUTPUT"
|
||||
echo "" >> "$LLM_OUTPUT"
|
||||
|
||||
local project_info
|
||||
project_info=$(detect_project "${project_dir}")
|
||||
|
||||
{
|
||||
echo "Type: $(echo "${project_info}" | jq -r '.type')"
|
||||
echo ""
|
||||
get_tree "${project_dir}" 2
|
||||
} >> "$LLM_OUTPUT"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
# Jira AI Agent
|
||||
|
||||
## Overview
|
||||
|
||||
The Jira AI Agent is designed to assist with managing tasks within Jira projects, providing capabilities such as
|
||||
creating, searching, updating, assigning, linking, and commenting on issues. Its primary purpose is to help software
|
||||
engineers seamlessly integrate Jira into their workflows through an AI-driven interface.
|
||||
|
||||
## Configuration
|
||||
This agent uses the official [Atlassian MCP Server](https://github.com/atlassian/atlassian-mcp-server). To use it,
|
||||
ensure you have Node.js v18+ installed to run the local MCP proxy (`mcp-remote`).
|
||||
|
||||
The server uses OAuth 2.0 so it will automatically open your browser for you to sign in to your account. No manual
|
||||
configuration is necessary!
|
||||
@@ -0,0 +1,37 @@
|
||||
name: Jira Agent
|
||||
description: An AI agent that can assist with Jira tasks such as creating issues, searching for issues, and updating issues.
|
||||
version: 0.1.0
|
||||
agent_session: temp
|
||||
mcp_servers:
|
||||
- atlassian
|
||||
instructions: |
|
||||
You are a AI agent designed to assist with managing Jira tasks and helping software engineers utilize and integrate
|
||||
Jira into their workflows. You can create, search, update, assign, link, and comment on issues in Jira.
|
||||
|
||||
## Create Issue (MANDATORY when creating a issue)
|
||||
When a user prompts you to create a Jira issue:
|
||||
1. Prompt the user for what Jira project they want the ticket created in
|
||||
2. If the ticket type requires a parent issue:
|
||||
a. Query Jira for potentially relevant parents
|
||||
b. Prompt user for which parent to use, displaying the suggested list of parent issues
|
||||
3. Create the issue with the following format:
|
||||
```markdown
|
||||
**Description:**
|
||||
This section gives context and details about the issue.
|
||||
**User Acceptance Criteria:**
|
||||
# This section provides bullet points that function like a checklist of all the things that must be completed in
|
||||
# order for the issue to be considered done.
|
||||
* Example criteria one
|
||||
* Example criteria two
|
||||
```
|
||||
4. Ask the user if the issue should be assigned to them
|
||||
a. If yes, then assign the user to the newly created issue
|
||||
|
||||
|
||||
Available tools:
|
||||
{{__tools__}}
|
||||
conversation_starters:
|
||||
- What are the latest issues in my Jira project?
|
||||
- Can you create a new Jira issue for me?
|
||||
- What are my open Jira issues?
|
||||
- Can you search for issues with the label "bug" in my Jira project?
|
||||
@@ -0,0 +1,39 @@
|
||||
# Oracle
|
||||
|
||||
An AI agent specialized in high-level architecture, complex debugging, and design decisions.
|
||||
|
||||
This agent is designed to be delegated to by the **[Sisyphus](../sisyphus/README.md)** agent when deep reasoning, architectural advice,
|
||||
or complex problem-solving is required. Sisyphus acts as the coordinator, while Oracle provides the expert analysis and
|
||||
recommendations.
|
||||
|
||||
It can also be used as a standalone tool for design reviews and solving difficult technical challenges.
|
||||
|
||||
## Features
|
||||
|
||||
- 🏛️ System architecture and design patterns
|
||||
- 🐛 Complex debugging and root cause analysis
|
||||
- ⚖️ Tradeoff analysis and technology selection
|
||||
- 📝 Code review and best practices advice
|
||||
- 🧠 Deep reasoning for ambiguous problems
|
||||
|
||||
## 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
|
||||
them), and modify the agent definition to look like this:
|
||||
|
||||
```yaml
|
||||
# ...
|
||||
|
||||
mcp_servers:
|
||||
- jetbrains # The name of your configured IDE MCP server
|
||||
|
||||
global_tools:
|
||||
- fs_read.sh
|
||||
- fs_grep.sh
|
||||
- fs_glob.sh
|
||||
- fs_ls.sh
|
||||
- web_search_loki.sh
|
||||
|
||||
# ...
|
||||
```
|
||||
@@ -0,0 +1,85 @@
|
||||
name: oracle
|
||||
description: High-IQ advisor for architecture, debugging, and complex decisions
|
||||
version: 1.0.0
|
||||
temperature: 0.2
|
||||
|
||||
variables:
|
||||
- name: project_dir
|
||||
description: Project directory for context
|
||||
default: '.'
|
||||
|
||||
mcp_servers:
|
||||
- ddg-search
|
||||
global_tools:
|
||||
- fs_read.sh
|
||||
- fs_grep.sh
|
||||
- fs_glob.sh
|
||||
- fs_ls.sh
|
||||
|
||||
instructions: |
|
||||
You are Oracle - a senior architect and debugger consulted for complex decisions.
|
||||
|
||||
## Your Role
|
||||
|
||||
You are READ-ONLY. You analyze, advise, and recommend. You do NOT implement.
|
||||
|
||||
## When You're Consulted
|
||||
|
||||
1. **Architecture Decisions**: Multi-system tradeoffs, design patterns, technology choices
|
||||
2. **Complex Debugging**: After 2+ failed fix attempts, deep analysis needed
|
||||
3. **Code Review**: Evaluating proposed designs or implementations
|
||||
4. **Risk Assessment**: Security, performance, or reliability concerns
|
||||
|
||||
## File Reading Strategy (IMPORTANT - minimize token usage)
|
||||
|
||||
1. **Use grep to find relevant code** - `fs_grep --pattern "auth" --include "*.rs"` finds where things are
|
||||
2. **Read only what you need** - `fs_read --path "src/main.rs" --offset 50 --limit 30` reads lines 50-79
|
||||
3. **Never read entire large files** - If 500+ lines, grep first, then read the relevant section
|
||||
4. **Use glob to discover files** - `fs_glob --pattern "*.rs" --path src/`
|
||||
|
||||
## Your Process
|
||||
|
||||
1. **Understand**: Use grep/glob to find relevant code, then read targeted sections
|
||||
2. **Analyze**: Consider multiple angles and tradeoffs
|
||||
3. **Recommend**: Provide clear, actionable advice
|
||||
4. **Justify**: Explain your reasoning
|
||||
|
||||
## Output Format
|
||||
|
||||
Structure your response as:
|
||||
|
||||
```
|
||||
## Analysis
|
||||
[Your understanding of the situation]
|
||||
|
||||
## Recommendation
|
||||
[Clear, specific advice]
|
||||
|
||||
## Reasoning
|
||||
[Why this is the right approach]
|
||||
|
||||
## Risks/Considerations
|
||||
[What to watch out for]
|
||||
|
||||
ORACLE_COMPLETE
|
||||
```
|
||||
|
||||
## Rules
|
||||
|
||||
1. **Never modify files** - You advise, others implement
|
||||
2. **Be thorough** - Read all relevant context before advising
|
||||
3. **Be specific** - General advice isn't helpful
|
||||
4. **Consider tradeoffs** - There are rarely perfect solutions
|
||||
5. **Stay focused** - Answer the specific question asked
|
||||
|
||||
## Context
|
||||
- Project: {{project_dir}}
|
||||
- CWD: {{__cwd__}}
|
||||
|
||||
## Available Tools:
|
||||
{{__tools__}}
|
||||
|
||||
conversation_starters:
|
||||
- 'Review this architecture design'
|
||||
- 'Help debug this complex issue'
|
||||
- 'Evaluate these implementation options'
|
||||
Executable
+150
@@ -0,0 +1,150 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "$LLM_PROMPT_UTILS_FILE"
|
||||
source "$LLM_ROOT_DIR/agents/.shared/utils.sh"
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout
|
||||
# @env LLM_AGENT_VAR_PROJECT_DIR=.
|
||||
# @describe Oracle agent tools for analysis and consultation (read-only)
|
||||
|
||||
_project_dir() {
|
||||
local dir="${LLM_AGENT_VAR_PROJECT_DIR:-.}"
|
||||
(cd "${dir}" 2>/dev/null && pwd) || echo "${dir}"
|
||||
}
|
||||
|
||||
# Normalize a path to be relative to project root.
|
||||
# Strips the project_dir prefix if the LLM passes an absolute path.
|
||||
_normalize_path() {
|
||||
local input_path="$1"
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
|
||||
if [[ "${input_path}" == /* ]]; then
|
||||
input_path="${input_path#"${project_dir}"/}"
|
||||
fi
|
||||
|
||||
input_path="${input_path#./}"
|
||||
echo "${input_path}"
|
||||
}
|
||||
|
||||
# @cmd Read a file for analysis
|
||||
# @option --path! Path to the file (relative to project root)
|
||||
read_file() {
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
local file_path
|
||||
# shellcheck disable=SC2154
|
||||
file_path=$(_normalize_path "${argc_path}")
|
||||
local full_path="${project_dir}/${file_path}"
|
||||
|
||||
if [[ ! -f "${full_path}" ]]; then
|
||||
error "File not found: ${file_path}" >> "$LLM_OUTPUT"
|
||||
return 1
|
||||
fi
|
||||
|
||||
{
|
||||
info "Reading: ${file_path}"
|
||||
echo ""
|
||||
cat "${full_path}"
|
||||
} >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
# @cmd Get project structure and type
|
||||
get_project_info() {
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
|
||||
local project_info
|
||||
project_info=$(detect_project "${project_dir}")
|
||||
|
||||
{
|
||||
info "Project Analysis" >> "$LLM_OUTPUT"
|
||||
cat <<-EOF
|
||||
|
||||
Type: $(echo "${project_info}" | jq -r '.type')
|
||||
Build: $(echo "${project_info}" | jq -r '.build')
|
||||
Test: $(echo "${project_info}" | jq -r '.test')
|
||||
|
||||
EOF
|
||||
|
||||
info "Structure:" >> "$LLM_OUTPUT"
|
||||
get_tree "${project_dir}" 3
|
||||
} >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
# @cmd Search for patterns in the codebase
|
||||
# @option --pattern! Pattern to search for
|
||||
# @option --file-type Filter by extension (e.g., "rs", "py")
|
||||
search_code() {
|
||||
local file_type="${argc_file_type:-}"
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
info "Searching: ${argc_pattern}" >> "$LLM_OUTPUT"
|
||||
echo "" >> "$LLM_OUTPUT"
|
||||
|
||||
local include_arg=""
|
||||
if [[ -n "${file_type}" ]]; then
|
||||
include_arg="--include=*.${file_type}"
|
||||
fi
|
||||
|
||||
local results
|
||||
# shellcheck disable=SC2086
|
||||
results=$(grep -rn ${include_arg} "${argc_pattern}" "${project_dir}" 2>/dev/null | \
|
||||
grep -v '/target/' | \
|
||||
grep -v '/node_modules/' | \
|
||||
grep -v '/.git/' | \
|
||||
sed "s|^${project_dir}/||" | \
|
||||
head -30) || true
|
||||
|
||||
if [[ -n "${results}" ]]; then
|
||||
echo "${results}" >> "$LLM_OUTPUT"
|
||||
else
|
||||
warn "No matches found" >> "$LLM_OUTPUT"
|
||||
fi
|
||||
}
|
||||
|
||||
# @cmd Run a read-only command for analysis (e.g., git log, cargo tree)
|
||||
# @option --command! Command to run
|
||||
analyze_with_command() {
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
|
||||
local dangerous_patterns="rm |>|>>|mv |cp |chmod |chown |sudo|curl.*\\||wget.*\\|"
|
||||
# shellcheck disable=SC2154
|
||||
if echo "${argc_command}" | grep -qE "${dangerous_patterns}"; then
|
||||
error "Command appears to modify files or be dangerous. Oracle is read-only." >> "$LLM_OUTPUT"
|
||||
return 1
|
||||
fi
|
||||
|
||||
info "Running: ${argc_command}" >> "$LLM_OUTPUT"
|
||||
echo "" >> "$LLM_OUTPUT"
|
||||
|
||||
local output
|
||||
output=$(cd "${project_dir}" && eval "${argc_command}" 2>&1) || true
|
||||
echo "${output}" >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
# @cmd List directory contents
|
||||
# @option --path Path to list (default: project root)
|
||||
list_directory() {
|
||||
local dir_path
|
||||
dir_path=$(_normalize_path "${argc_path:-.}")
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
local full_path="${project_dir}/${dir_path}"
|
||||
|
||||
if [[ ! -d "${full_path}" ]]; then
|
||||
error "Directory not found: ${dir_path}" >> "$LLM_OUTPUT"
|
||||
return 1
|
||||
fi
|
||||
|
||||
{
|
||||
info "Contents of: ${dir_path}"
|
||||
echo ""
|
||||
ls -la "${full_path}"
|
||||
} >> "$LLM_OUTPUT"
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
# Sisyphus
|
||||
|
||||
The main coordinator agent for the Loki coding ecosystem, providing a powerful CLI interface for code generation and
|
||||
project management similar to OpenCode, ClaudeCode, Codex, or Gemini CLI.
|
||||
|
||||
_Inspired by the Sisyphus and Oracle agents of OpenCode._
|
||||
|
||||
Sisyphus acts as the primary entry point, capable of handling complex tasks by coordinating specialized sub-agents:
|
||||
- **[Coder](../coder/README.md)**: For implementation and file modifications.
|
||||
- **[Explore](../explore/README.md)**: For codebase understanding and research.
|
||||
- **[Oracle](../oracle/README.md)**: For architecture and complex reasoning.
|
||||
|
||||
## Features
|
||||
|
||||
- 🤖 **Coordinator**: Manages multi-step workflows and delegates to specialized agents.
|
||||
- 💻 **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.
|
||||
|
||||
## 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
|
||||
them), and modify the agent definition to look like this:
|
||||
|
||||
```yaml
|
||||
# ...
|
||||
|
||||
mcp_servers:
|
||||
- jetbrains
|
||||
|
||||
global_tools:
|
||||
- fs_read.sh
|
||||
- fs_grep.sh
|
||||
- fs_glob.sh
|
||||
- fs_ls.sh
|
||||
- web_search_loki.sh
|
||||
- execute_command.sh
|
||||
|
||||
# ...
|
||||
```
|
||||
@@ -0,0 +1,241 @@
|
||||
name: sisyphus
|
||||
description: OpenCode-style orchestrator - classifies intent, delegates to specialists, tracks progress with todos
|
||||
version: 2.0.0
|
||||
temperature: 0.1
|
||||
|
||||
agent_session: temp
|
||||
auto_continue: true
|
||||
max_auto_continues: 25
|
||||
inject_todo_instructions: true
|
||||
|
||||
can_spawn_agents: true
|
||||
max_concurrent_agents: 4
|
||||
max_agent_depth: 3
|
||||
inject_spawn_instructions: true
|
||||
summarization_threshold: 8000
|
||||
|
||||
variables:
|
||||
- name: project_dir
|
||||
description: Project directory to work in
|
||||
default: '.'
|
||||
- name: auto_confirm
|
||||
description: Auto-confirm command execution
|
||||
default: '1'
|
||||
|
||||
mcp_servers:
|
||||
- ddg-search
|
||||
global_tools:
|
||||
- fs_read.sh
|
||||
- fs_grep.sh
|
||||
- fs_glob.sh
|
||||
- fs_ls.sh
|
||||
- execute_command.sh
|
||||
|
||||
instructions: |
|
||||
You are Sisyphus - an orchestrator that drives coding tasks to completion.
|
||||
|
||||
Your job: Classify -> Delegate -> Verify -> Complete
|
||||
|
||||
## Intent Classification (BEFORE every action)
|
||||
|
||||
| Type | Signal | Action |
|
||||
|------|--------|--------|
|
||||
| Trivial | Single file, known location, typo fix | Do it yourself with tools |
|
||||
| Exploration | "Find X", "Where is Y", "List all Z" | Spawn `explore` agent |
|
||||
| Implementation | "Add feature", "Fix bug", "Write code" | Spawn `coder` agent |
|
||||
| Architecture/Design | See oracle triggers below | Spawn `oracle` agent |
|
||||
| Ambiguous | Unclear scope, multiple interpretations | ASK the user via `user__ask` or `user__input` |
|
||||
|
||||
### Oracle Triggers (MUST spawn oracle when you see these)
|
||||
|
||||
Spawn `oracle` ANY time the user asks about:
|
||||
- **"How should I..."** / **"What's the best way to..."** -- design/approach questions
|
||||
- **"Why does X keep..."** / **"What's wrong with..."** -- complex debugging (not simple errors)
|
||||
- **"Should I use X or Y?"** -- technology or pattern choices
|
||||
- **"How should this be structured?"** -- architecture and organization
|
||||
- **"Review this"** / **"What do you think of..."** -- code/design review
|
||||
- **Tradeoff questions** -- performance vs readability, complexity vs flexibility
|
||||
- **Multi-component questions** -- anything spanning 3+ files or modules
|
||||
- **Vague/open-ended questions** -- "improve this", "make this better", "clean this up"
|
||||
|
||||
**CRITICAL**: Do NOT answer architecture/design questions yourself. You are a coordinator.
|
||||
Even if you think you know the answer, oracle provides deeper, more thorough analysis.
|
||||
The only exception is truly trivial questions about a single file you've already read.
|
||||
|
||||
### Agent Specializations
|
||||
|
||||
| Agent | Use For | Characteristics |
|
||||
|-------|---------|-----------------|
|
||||
| explore | Find patterns, understand code, search | Read-only, returns findings |
|
||||
| coder | Write/edit files, implement features | Creates/modifies files, runs builds |
|
||||
| oracle | Architecture decisions, complex debugging | Advisory, high-quality reasoning |
|
||||
|
||||
## Coder Delegation Format (MANDATORY)
|
||||
|
||||
When spawning the `coder` agent, your prompt MUST include these sections.
|
||||
The coder has NOT seen the codebase. Your prompt IS its entire context.
|
||||
|
||||
### Template:
|
||||
|
||||
```
|
||||
## Goal
|
||||
[1-2 sentences: what to build/modify and where]
|
||||
|
||||
## Reference Files
|
||||
[Files that explore found, with what each demonstrates]
|
||||
- `path/to/file.ext` - what pattern this file shows
|
||||
- `path/to/other.ext` - what convention this file shows
|
||||
|
||||
## Code Patterns to Follow
|
||||
[Paste ACTUAL code snippets from explore results, not descriptions]
|
||||
<code>
|
||||
// From path/to/file.ext - this is the pattern to follow:
|
||||
[actual code explore found, 5-20 lines]
|
||||
</code>
|
||||
|
||||
## Conventions
|
||||
[Naming, imports, error handling, file organization]
|
||||
- Convention 1
|
||||
- Convention 2
|
||||
|
||||
## Constraints
|
||||
[What NOT to do, scope boundaries]
|
||||
- Do NOT modify X
|
||||
- Only touch files in Y/
|
||||
```
|
||||
|
||||
**CRITICAL**: Include actual code snippets, not just file paths.
|
||||
If explore returned code patterns, paste them into the coder prompt.
|
||||
Vague prompts like "follow existing patterns" waste coder's tokens on
|
||||
re-exploration that you already did.
|
||||
|
||||
## Workflow Examples
|
||||
|
||||
### Example 1: Implementation task (explore -> coder, parallel exploration)
|
||||
|
||||
User: "Add a new API endpoint for user profiles"
|
||||
|
||||
```
|
||||
1. todo__init --goal "Add user profiles API endpoint"
|
||||
2. todo__add --task "Explore existing API patterns"
|
||||
3. todo__add --task "Implement profile endpoint"
|
||||
4. todo__add --task "Verify with build/test"
|
||||
5. agent__spawn --agent explore --prompt "Find existing API endpoint patterns, route structures, and controller conventions. Include code snippets."
|
||||
6. agent__spawn --agent explore --prompt "Find existing data models and database query patterns. Include code snippets."
|
||||
7. agent__collect --id <id1>
|
||||
8. agent__collect --id <id2>
|
||||
9. todo__done --id 1
|
||||
10. agent__spawn --agent coder --prompt "<structured prompt using Coder Delegation Format above, including code snippets from explore results>"
|
||||
11. agent__collect --id <coder_id>
|
||||
12. todo__done --id 2
|
||||
13. run_build
|
||||
14. run_tests
|
||||
15. todo__done --id 3
|
||||
```
|
||||
|
||||
### Example 2: Architecture/design question (explore + oracle in parallel)
|
||||
|
||||
User: "How should I structure the authentication for this app?"
|
||||
|
||||
```
|
||||
1. todo__init --goal "Get architecture advice for authentication"
|
||||
2. todo__add --task "Explore current auth-related code"
|
||||
3. todo__add --task "Consult oracle for architecture recommendation"
|
||||
4. agent__spawn --agent explore --prompt "Find any existing auth code, middleware, user models, and session handling"
|
||||
5. agent__spawn --agent oracle --prompt "Recommend authentication architecture for this project. Consider: JWT vs sessions, middleware patterns, security best practices."
|
||||
6. agent__collect --id <explore_id>
|
||||
7. todo__done --id 1
|
||||
8. agent__collect --id <oracle_id>
|
||||
9. todo__done --id 2
|
||||
```
|
||||
|
||||
### Example 3: Vague/open-ended question (oracle directly)
|
||||
|
||||
User: "What do you think of this codebase structure?"
|
||||
|
||||
```
|
||||
agent__spawn --agent oracle --prompt "Review the project structure and provide recommendations for improvement"
|
||||
agent__collect --id <oracle_id>
|
||||
```
|
||||
|
||||
## Rules
|
||||
|
||||
1. **Always classify before acting** - Don't jump into implementation
|
||||
2. **Create todos for multi-step tasks** - Track your progress
|
||||
3. **Spawn agents for specialized work** - You're a coordinator, not an implementer
|
||||
4. **Spawn in parallel when possible** - Independent tasks should run concurrently
|
||||
5. **Verify after collecting agent results** - Don't trust blindly
|
||||
6. **Mark todos done immediately** - Don't batch completions
|
||||
7. **Ask when ambiguous** - Use `user__ask` or `user__input` to clarify with the user interactively
|
||||
8. **Get buy-in for design decisions** - Use `user__ask` to present options before implementing major changes
|
||||
9. **Confirm destructive actions** - Use `user__confirm` before large refactors or deletions
|
||||
10. **Delegate to the coder agent to write code** - IMPORTANT: Use the `coder` agent to write code. Do not try to write code yourself except for trivial changes
|
||||
11. **Always output a summary of changes when finished** - Make it clear to user's that you've completed your tasks
|
||||
|
||||
## When to Do It Yourself
|
||||
|
||||
- Simple command execution
|
||||
- Trivial changes (typos, renames)
|
||||
- Quick file searches
|
||||
|
||||
## When to NEVER Do It Yourself
|
||||
|
||||
- Architecture or design questions -> ALWAYS oracle
|
||||
- "How should I..." / "What's the best way to..." -> ALWAYS oracle
|
||||
- Debugging after 2+ failed attempts -> ALWAYS oracle
|
||||
- Code review or design review requests -> ALWAYS oracle
|
||||
- Open-ended improvement questions -> ALWAYS oracle
|
||||
|
||||
## User Interaction (CRITICAL - get buy-in before major decisions)
|
||||
|
||||
You have built-in tools to prompt the user for input. Use them to get user buy-in before making design decisions, and
|
||||
to clarify ambiguities interactively. **Do NOT guess when you can ask.**
|
||||
|
||||
### When to Prompt the User
|
||||
|
||||
| Situation | Tool | Example |
|
||||
|-----------|------|---------|
|
||||
| Multiple valid design approaches | `user__ask` | "How should we structure this?" with options |
|
||||
| Confirming a destructive or major action | `user__confirm` | "This will refactor 12 files. Proceed?" |
|
||||
| User should pick which features/items to include | `user__checkbox` | "Which endpoints should we add?" |
|
||||
| Need specific input (names, paths, values) | `user__input` | "What should the new module be called?" |
|
||||
| Ambiguous request with different effort levels | `user__ask` | Present interpretation options |
|
||||
|
||||
### Design Review Pattern
|
||||
|
||||
For implementation tasks with design decisions, follow this pattern:
|
||||
|
||||
1. **Explore** the codebase to understand existing patterns
|
||||
2. **Formulate** 2-3 design options based on findings
|
||||
3. **Present options** to the user via `user__ask` with your recommendation marked `(Recommended)`
|
||||
4. **Confirm** the chosen approach before delegating to `coder`
|
||||
5. Proceed with implementation
|
||||
|
||||
### Rules for User Prompts
|
||||
|
||||
1. **Always include (Recommended)** on the option you think is best in `user__ask`
|
||||
2. **Respect user choices** - never override or ignore a selection
|
||||
3. **Don't over-prompt** - trivial decisions (variable names in small functions, formatting) don't need prompts
|
||||
4. **DO prompt for**: architecture choices, file/module naming, which of multiple valid approaches to take, destructive operations, anything you're genuinely unsure about
|
||||
5. **Confirm before large changes** - if a task will touch 5+ files, confirm the plan first
|
||||
|
||||
## Escalation Handling
|
||||
|
||||
If you see `pending_escalations` in your tool results, a child agent needs user input and is blocked.
|
||||
Reply promptly via `agent__reply_escalation` to unblock it. You can answer from context or prompt the user
|
||||
yourself first, then relay the answer.
|
||||
|
||||
## Available Tools
|
||||
{{__tools__}}
|
||||
|
||||
## Context
|
||||
- Project: {{project_dir}}
|
||||
- OS: {{__os__}}
|
||||
- Shell: {{__shell__}}
|
||||
- CWD: {{__cwd__}}
|
||||
|
||||
conversation_starters:
|
||||
- 'Add a new feature to the project'
|
||||
- 'Fix a bug in the codebase'
|
||||
- 'Refactor the authentication module'
|
||||
- 'Help me understand how X works'
|
||||
Executable
+97
@@ -0,0 +1,97 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
# shellcheck disable=SC1090
|
||||
source "$LLM_PROMPT_UTILS_FILE"
|
||||
source "$LLM_ROOT_DIR/agents/.shared/utils.sh"
|
||||
export AUTO_CONFIRM=true
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout
|
||||
# @env LLM_AGENT_VAR_PROJECT_DIR=.
|
||||
# @describe Sisyphus orchestrator tools (project info, build, test)
|
||||
|
||||
_project_dir() {
|
||||
local dir="${LLM_AGENT_VAR_PROJECT_DIR:-.}"
|
||||
(cd "${dir}" 2>/dev/null && pwd) || echo "${dir}"
|
||||
}
|
||||
|
||||
# @cmd Get project information and structure
|
||||
get_project_info() {
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
|
||||
info "Project: ${project_dir}" >> "$LLM_OUTPUT"
|
||||
echo "" >> "$LLM_OUTPUT"
|
||||
|
||||
local project_info
|
||||
project_info=$(detect_project "${project_dir}")
|
||||
|
||||
cat <<-EOF >> "$LLM_OUTPUT"
|
||||
Type: $(echo "${project_info}" | jq -r '.type')
|
||||
Build: $(echo "${project_info}" | jq -r '.build')
|
||||
Test: $(echo "${project_info}" | jq -r '.test')
|
||||
|
||||
$(info "Directory structure:")
|
||||
$(get_tree "${project_dir}" 2)
|
||||
EOF
|
||||
}
|
||||
|
||||
# @cmd Run build command for the project
|
||||
run_build() {
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
|
||||
local project_info
|
||||
project_info=$(detect_project "${project_dir}")
|
||||
local build_cmd
|
||||
build_cmd=$(echo "${project_info}" | jq -r '.build')
|
||||
|
||||
if [[ -z "${build_cmd}" ]] || [[ "${build_cmd}" == "null" ]]; then
|
||||
warn "No build command detected for this project" >> "$LLM_OUTPUT"
|
||||
return 0
|
||||
fi
|
||||
|
||||
info "Running: ${build_cmd}" >> "$LLM_OUTPUT"
|
||||
echo "" >> "$LLM_OUTPUT"
|
||||
|
||||
local output
|
||||
if output=$(cd "${project_dir}" && eval "${build_cmd}" 2>&1); then
|
||||
green "BUILD SUCCESS" >> "$LLM_OUTPUT"
|
||||
echo "${output}" >> "$LLM_OUTPUT"
|
||||
return 0
|
||||
else
|
||||
error "BUILD FAILED" >> "$LLM_OUTPUT"
|
||||
echo "${output}" >> "$LLM_OUTPUT"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# @cmd Run tests for the project
|
||||
run_tests() {
|
||||
local project_dir
|
||||
project_dir=$(_project_dir)
|
||||
|
||||
local project_info
|
||||
project_info=$(detect_project "${project_dir}")
|
||||
local test_cmd
|
||||
test_cmd=$(echo "${project_info}" | jq -r '.test')
|
||||
|
||||
if [[ -z "${test_cmd}" ]] || [[ "${test_cmd}" == "null" ]]; then
|
||||
warn "No test command detected for this project" >> "$LLM_OUTPUT"
|
||||
return 0
|
||||
fi
|
||||
|
||||
info "Running: ${test_cmd}" >> "$LLM_OUTPUT"
|
||||
echo "" >> "$LLM_OUTPUT"
|
||||
|
||||
local output
|
||||
if output=$(cd "${project_dir}" && eval "${test_cmd}" 2>&1); then
|
||||
green "TESTS PASSED" >> "$LLM_OUTPUT"
|
||||
echo "${output}" >> "$LLM_OUTPUT"
|
||||
return 0
|
||||
else
|
||||
error "TESTS FAILED" >> "$LLM_OUTPUT"
|
||||
echo "${output}" >> "$LLM_OUTPUT"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
# SQL
|
||||
|
||||
An AI agent that helps you manage a SQL database.
|
||||
|
||||
> The tool script uses [usql](https://github.com/xo/usql) to interact with SQL, it supports all mainstream databases.
|
||||
@@ -0,0 +1,17 @@
|
||||
name: Sql
|
||||
description: An AI agent that helps you manage any SQL database
|
||||
version: 0.1.0
|
||||
instructions: |
|
||||
You are an AI agent that manages a SQL database.
|
||||
Prefix all referenced tables with the name of the schema that they are in.
|
||||
|
||||
For all sqlite databases, prefix each table name with 'main' as the schema
|
||||
|
||||
|
||||
Available tools:
|
||||
{{__tools__}}
|
||||
variables:
|
||||
- name: dsn
|
||||
description: The database connection url. e.g. pgsql://user:pass@host:port
|
||||
conversation_starters:
|
||||
- What you can do?
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
# @meta require-tools usql
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
# @env LLM_AGENT_VAR_DSN! The database connection url. e.g. pgsql://user:pass@host:port
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "$LLM_PROMPT_UTILS_FILE"
|
||||
|
||||
# @cmd Execute a SELECT query
|
||||
# @option --query! SELECT SQL query to execute
|
||||
read_query() {
|
||||
# shellcheck disable=SC2154
|
||||
if ! grep -qi '^select' <<<"$argc_query"; then
|
||||
error "only SELECT queries are allowed" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
_run_sql "$argc_query"
|
||||
}
|
||||
|
||||
# @cmd Execute an SQL query
|
||||
# @option --query! SQL query to execute
|
||||
write_query() {
|
||||
guard_operation "Execute SQL?"
|
||||
_run_sql "$argc_query"
|
||||
}
|
||||
|
||||
# @cmd List all tables
|
||||
list_tables() {
|
||||
_run_sql "\dt+"
|
||||
}
|
||||
|
||||
# @cmd Get the schema information for a specific table
|
||||
# @option --table-name! Name of the table to describe
|
||||
describe_table() {
|
||||
# shellcheck disable=SC2154
|
||||
_run_sql "\d $argc_table_name"
|
||||
}
|
||||
|
||||
_run_sql() {
|
||||
usql "$LLM_AGENT_VAR_DSN" -c "$1" >> "$LLM_OUTPUT"
|
||||
}
|
||||
+1106
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"mcpServers": {
|
||||
"github": {
|
||||
"type": "stdio",
|
||||
"command": "docker",
|
||||
"args": [
|
||||
"run",
|
||||
"-i",
|
||||
"--rm",
|
||||
"-e",
|
||||
"GITHUB_PERSONAL_ACCESS_TOKEN",
|
||||
"ghcr.io/github/github-mcp-server"
|
||||
],
|
||||
"env": {
|
||||
"GITHUB_PERSONAL_ACCESS_TOKEN": "YOUR_GITHUB_TOKEN"
|
||||
}
|
||||
},
|
||||
"atlassian": {
|
||||
"type": "stdio",
|
||||
"command": "npx",
|
||||
"args": ["-y", "mcp-remote@0.1.13", "https://mcp.atlassian.com/v1/mcp"]
|
||||
},
|
||||
"docker": {
|
||||
"type": "stdio",
|
||||
"command": "uvx",
|
||||
"args": ["mcp-server-docker"]
|
||||
},
|
||||
"ddg-search": {
|
||||
"type": "stdio",
|
||||
"command": "uvx",
|
||||
"args": ["duckduckgo-mcp-server"]
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+160
@@ -0,0 +1,160 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Usage: ./{agent_name}.py <agent-func> <agent-data>
|
||||
|
||||
import os
|
||||
import re
|
||||
import json
|
||||
import sys
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
def _ensure_cwd_venv():
|
||||
cwd = Path.cwd()
|
||||
venv_dir = cwd / ".venv"
|
||||
if not venv_dir.is_dir():
|
||||
return
|
||||
|
||||
py = venv_dir / ("Scripts/python.exe" if os.name == "nt" else "bin/python")
|
||||
if not py.exists():
|
||||
return
|
||||
|
||||
if Path(sys.prefix).resolve() == venv_dir.resolve():
|
||||
return
|
||||
|
||||
os.execv(str(py), [str(py)] + sys.argv)
|
||||
|
||||
_ensure_cwd_venv()
|
||||
|
||||
|
||||
def main():
|
||||
(agent_func, raw_data) = parse_argv()
|
||||
agent_data = parse_raw_data(raw_data)
|
||||
|
||||
root_dir = "{config_dir}"
|
||||
setup_env(root_dir, agent_func)
|
||||
|
||||
agent_tools_path = os.path.join(root_dir, "agents/{agent_name}/tools.py")
|
||||
run(agent_tools_path, agent_func, agent_data)
|
||||
|
||||
|
||||
def parse_raw_data(data):
|
||||
if not data:
|
||||
raise ValueError("No JSON data")
|
||||
|
||||
try:
|
||||
return json.loads(data)
|
||||
except Exception:
|
||||
raise ValueError("Invalid JSON data")
|
||||
|
||||
|
||||
def parse_argv():
|
||||
agent_func = sys.argv[1]
|
||||
|
||||
tool_data_file = os.environ.get("LLM_TOOL_DATA_FILE")
|
||||
if tool_data_file and os.path.isfile(tool_data_file):
|
||||
with open(tool_data_file, "r", encoding="utf-8") as f:
|
||||
agent_data = f.read()
|
||||
else:
|
||||
agent_data = sys.argv[2]
|
||||
|
||||
if (not agent_data) or (not agent_func):
|
||||
print("Usage: ./{agent_name}.py <agent-func> <agent-data>", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
return agent_func, agent_data
|
||||
|
||||
|
||||
def setup_env(root_dir, agent_func):
|
||||
load_env(os.path.join(root_dir, ".env"))
|
||||
os.environ["LLM_ROOT_DIR"] = root_dir
|
||||
os.environ["LLM_AGENT_NAME"] = "{agent_name}"
|
||||
os.environ["LLM_AGENT_FUNC"] = agent_func
|
||||
os.environ["LLM_AGENT_ROOT_DIR"] = os.path.join(root_dir, "agents", "{agent_name}")
|
||||
os.environ["LLM_AGENT_CACHE_DIR"] = os.path.join(root_dir, "cache", "{agent_name}")
|
||||
|
||||
|
||||
def load_env(file_path):
|
||||
try:
|
||||
with open(file_path, "r") as f:
|
||||
lines = f.readlines()
|
||||
except:
|
||||
return
|
||||
|
||||
env_vars = {}
|
||||
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
if line.startswith("#") or not line:
|
||||
continue
|
||||
|
||||
key, *value_parts = line.split("=")
|
||||
env_name = key.strip()
|
||||
|
||||
if env_name not in os.environ:
|
||||
env_value = "=".join(value_parts).strip()
|
||||
if (env_value.startswith('"') and env_value.endswith('"')) or (env_value.startswith("'") and env_value.endswith("'")):
|
||||
env_value = env_value[1:-1]
|
||||
env_vars[env_name] = env_value
|
||||
|
||||
os.environ.update(env_vars)
|
||||
|
||||
|
||||
def run(agent_path, agent_func, agent_data):
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
os.path.basename(agent_path), agent_path
|
||||
)
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(mod)
|
||||
|
||||
if not hasattr(mod, agent_func):
|
||||
raise Exception(f"Not module function '{agent_func}' at '{agent_path}'")
|
||||
|
||||
value = getattr(mod, agent_func)(**agent_data)
|
||||
return_to_llm(value)
|
||||
dump_result('{agent_name}' + f':{agent_func}')
|
||||
|
||||
|
||||
def return_to_llm(value):
|
||||
if value is None:
|
||||
return
|
||||
|
||||
if "LLM_OUTPUT" in os.environ:
|
||||
writer = open(os.environ["LLM_OUTPUT"], "w")
|
||||
else:
|
||||
writer = sys.stdout
|
||||
|
||||
value_type = type(value).__name__
|
||||
if value_type in ("str", "int", "float", "bool"):
|
||||
writer.write(str(value))
|
||||
elif value_type == "dict" or value_type == "list":
|
||||
value_str = json.dumps(value, indent=2)
|
||||
assert value == json.loads(value_str)
|
||||
writer.write(value_str)
|
||||
|
||||
|
||||
def dump_result(name):
|
||||
if (not os.getenv("LLM_DUMP_RESULTS")) or (not os.getenv("LLM_OUTPUT")) or (not os.isatty(1)):
|
||||
return
|
||||
|
||||
show_result = False
|
||||
try:
|
||||
if re.search(rf'\b({os.environ["LLM_DUMP_RESULTS"]})\b', name):
|
||||
show_result = True
|
||||
except:
|
||||
pass
|
||||
|
||||
if not show_result:
|
||||
return
|
||||
|
||||
try:
|
||||
with open(os.environ["LLM_OUTPUT"], "r", encoding="utf-8") as f:
|
||||
data = f.read()
|
||||
except:
|
||||
return
|
||||
|
||||
print(f"\x1b[2m----------------------\n{data}\n----------------------\x1b[0m")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,124 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Usage: ./{agent_name}.sh <agent-func> <agent-data>
|
||||
|
||||
set -e
|
||||
|
||||
main() {
|
||||
root_dir="{config_dir}"
|
||||
parse_argv "$@"
|
||||
setup_env
|
||||
tools_path="$root_dir/agents/{agent_name}/tools.sh"
|
||||
run
|
||||
}
|
||||
|
||||
parse_argv() {
|
||||
agent_func="$1"
|
||||
if [[ -n "$LLM_TOOL_DATA_FILE" ]] && [[ -f "$LLM_TOOL_DATA_FILE" ]]; then
|
||||
agent_data="$(cat "$LLM_TOOL_DATA_FILE")"
|
||||
else
|
||||
agent_data="$2"
|
||||
fi
|
||||
if [[ -z "$agent_data" ]] || [[ -z "$agent_func" ]]; then
|
||||
die "usage: ./{agent_name}.sh <agent-func> <agent-data>"
|
||||
fi
|
||||
}
|
||||
|
||||
setup_env() {
|
||||
load_env "$root_dir/.env"
|
||||
export LLM_ROOT_DIR="$root_dir"
|
||||
export LLM_AGENT_NAME="{agent_name}"
|
||||
export LLM_AGENT_FUNC="$agent_func"
|
||||
export LLM_AGENT_ROOT_DIR="$LLM_ROOT_DIR/agents/{agent_name}"
|
||||
export LLM_AGENT_CACHE_DIR="$LLM_ROOT_DIR/cache/{agent_name}"
|
||||
export LLM_PROMPT_UTILS_FILE="{prompt_utils_file}"
|
||||
}
|
||||
|
||||
load_env() {
|
||||
local env_file="$1" env_vars
|
||||
if [[ -f "$env_file" ]]; then
|
||||
while IFS='=' read -r key value; do
|
||||
if [[ "$key" == $'#'* ]] || [[ -z "$key" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ -z "${!key+x}" ]]; then
|
||||
env_vars="$env_vars $key=$value"
|
||||
fi
|
||||
done < <(cat "$env_file"; echo "")
|
||||
|
||||
if [[ -n "$env_vars" ]]; then
|
||||
eval "export $env_vars"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
run() {
|
||||
if [[ -z "$agent_data" ]]; then
|
||||
die "error: no JSON data"
|
||||
fi
|
||||
|
||||
if [[ "$OS" == "Windows_NT" ]]; then
|
||||
set -o igncr
|
||||
tools_path="$(cygpath -w "$tools_path")"
|
||||
fi
|
||||
|
||||
jq_script="$(cat <<-'EOF'
|
||||
def escape_shell_word:
|
||||
tostring
|
||||
| gsub("'"; "'\"'\"'")
|
||||
| gsub("\n"; "'$'\\n''")
|
||||
| "'\(.)'";
|
||||
def to_args:
|
||||
to_entries | .[] |
|
||||
(.key | split("_") | join("-")) as $key |
|
||||
if .value | type == "array" then
|
||||
.value | .[] | "--\($key) \(. | escape_shell_word)"
|
||||
elif .value | type == "boolean" then
|
||||
if .value then "--\($key)" else "" end
|
||||
else
|
||||
"--\($key) \(.value | escape_shell_word)"
|
||||
end;
|
||||
[ to_args ] | join(" ")
|
||||
EOF
|
||||
)"
|
||||
args="$(echo "$agent_data" | jq -r "$jq_script" 2>/dev/null)" || {
|
||||
die "error: invalid JSON data"
|
||||
}
|
||||
|
||||
if [[ -z "$LLM_OUTPUT" ]]; then
|
||||
is_temp_llm_output=1
|
||||
# shellcheck disable=SC2155
|
||||
export LLM_OUTPUT="$(mktemp)"
|
||||
fi
|
||||
|
||||
eval "'$tools_path' '$agent_func' $args"
|
||||
|
||||
if [[ "$is_temp_llm_output" -eq 1 ]]; then
|
||||
cat "$LLM_OUTPUT"
|
||||
else
|
||||
dump_result "{agent_name}:${LLM_AGENT_FUNC}"
|
||||
fi
|
||||
}
|
||||
|
||||
dump_result() {
|
||||
if [[ "$LLM_OUTPUT" == "/dev/stdout" ]] || [[ -z "$LLM_DUMP_RESULTS" ]] || [[ ! -t 1 ]]; then
|
||||
return;
|
||||
fi
|
||||
|
||||
if grep -q -w -E "$LLM_DUMP_RESULTS" <<<"$1"; then
|
||||
cat <<EOF
|
||||
$(echo -e "\e[2m")----------------------
|
||||
$(cat "$LLM_OUTPUT")
|
||||
----------------------$(echo -e "\e[0m")
|
||||
EOF
|
||||
fi
|
||||
}
|
||||
|
||||
die() {
|
||||
echo "$*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
#!/usr/bin/env tsx
|
||||
|
||||
// Usage: ./{agent_name}.ts <agent-func> <agent-data>
|
||||
|
||||
import { readFileSync, writeFileSync, existsSync } from "fs";
|
||||
import { join } from "path";
|
||||
import { pathToFileURL } from "url";
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const { agentFunc, rawData } = parseArgv();
|
||||
const agentData = parseRawData(rawData);
|
||||
|
||||
const configDir = "{config_dir}";
|
||||
setupEnv(configDir, agentFunc);
|
||||
|
||||
const agentToolsPath = join(configDir, "agents", "{agent_name}", "tools.ts");
|
||||
await run(agentToolsPath, agentFunc, agentData);
|
||||
}
|
||||
|
||||
function parseRawData(data: string): Record<string, unknown> {
|
||||
if (!data) {
|
||||
throw new Error("No JSON data");
|
||||
}
|
||||
|
||||
try {
|
||||
return JSON.parse(data);
|
||||
} catch {
|
||||
throw new Error("Invalid JSON data");
|
||||
}
|
||||
}
|
||||
|
||||
function parseArgv(): { agentFunc: string; rawData: string } {
|
||||
const agentFunc = process.argv[2];
|
||||
|
||||
const toolDataFile = process.env["LLM_TOOL_DATA_FILE"];
|
||||
let agentData: string;
|
||||
if (toolDataFile && existsSync(toolDataFile)) {
|
||||
agentData = readFileSync(toolDataFile, "utf-8");
|
||||
} else {
|
||||
agentData = process.argv[3];
|
||||
}
|
||||
|
||||
if (!agentFunc || !agentData) {
|
||||
process.stderr.write("Usage: ./{agent_name}.ts <agent-func> <agent-data>\n");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
return { agentFunc, rawData: agentData };
|
||||
}
|
||||
|
||||
function setupEnv(configDir: string, agentFunc: string): void {
|
||||
loadEnv(join(configDir, ".env"));
|
||||
process.env["LLM_ROOT_DIR"] = configDir;
|
||||
process.env["LLM_AGENT_NAME"] = "{agent_name}";
|
||||
process.env["LLM_AGENT_FUNC"] = agentFunc;
|
||||
process.env["LLM_AGENT_ROOT_DIR"] = join(configDir, "agents", "{agent_name}");
|
||||
process.env["LLM_AGENT_CACHE_DIR"] = join(configDir, "cache", "{agent_name}");
|
||||
}
|
||||
|
||||
function loadEnv(filePath: string): void {
|
||||
let lines: string[];
|
||||
try {
|
||||
lines = readFileSync(filePath, "utf-8").split("\n");
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const raw of lines) {
|
||||
const line = raw.trim();
|
||||
if (line.startsWith("#") || !line) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const eqIdx = line.indexOf("=");
|
||||
if (eqIdx === -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const key = line.slice(0, eqIdx).trim();
|
||||
if (key in process.env) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let value = line.slice(eqIdx + 1).trim();
|
||||
if (
|
||||
(value.startsWith('"') && value.endsWith('"')) ||
|
||||
(value.startsWith("'") && value.endsWith("'"))
|
||||
) {
|
||||
value = value.slice(1, -1);
|
||||
}
|
||||
process.env[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
function extractParamNames(fn: Function): string[] {
|
||||
const src = fn.toString();
|
||||
const match = src.match(/^(?:async\s+)?function\s*\w*\s*\(([^)]*)\)/);
|
||||
if (!match) {
|
||||
return [];
|
||||
}
|
||||
return match[1]
|
||||
.split(",")
|
||||
.map((p) => p.trim().replace(/[:=?].*/s, "").trim())
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
function spreadArgs(
|
||||
fn: Function,
|
||||
data: Record<string, unknown>,
|
||||
): unknown[] {
|
||||
const names = extractParamNames(fn);
|
||||
if (names.length === 0) {
|
||||
return [];
|
||||
}
|
||||
return names.map((name) => data[name]);
|
||||
}
|
||||
|
||||
async function run(
|
||||
agentPath: string,
|
||||
agentFunc: string,
|
||||
agentData: Record<string, unknown>,
|
||||
): Promise<void> {
|
||||
const mod = await import(pathToFileURL(agentPath).href);
|
||||
|
||||
if (typeof mod[agentFunc] !== "function") {
|
||||
throw new Error(`No module function '${agentFunc}' at '${agentPath}'`);
|
||||
}
|
||||
|
||||
const fn = mod[agentFunc] as Function;
|
||||
const args = spreadArgs(fn, agentData);
|
||||
const value = await fn(...args);
|
||||
returnToLlm(value);
|
||||
dumpResult(`{agent_name}:${agentFunc}`);
|
||||
}
|
||||
|
||||
function returnToLlm(value: unknown): void {
|
||||
if (value === null || value === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
const output = process.env["LLM_OUTPUT"];
|
||||
const write = (s: string) => {
|
||||
if (output) {
|
||||
writeFileSync(output, s, "utf-8");
|
||||
} else {
|
||||
process.stdout.write(s);
|
||||
}
|
||||
};
|
||||
|
||||
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
||||
write(String(value));
|
||||
} else if (typeof value === "object") {
|
||||
write(JSON.stringify(value, null, 2));
|
||||
}
|
||||
}
|
||||
|
||||
function dumpResult(name: string): void {
|
||||
const dumpResults = process.env["LLM_DUMP_RESULTS"];
|
||||
const llmOutput = process.env["LLM_OUTPUT"];
|
||||
|
||||
if (!dumpResults || !llmOutput || !process.stdout.isTTY) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const pattern = new RegExp(`\\b(${dumpResults})\\b`);
|
||||
if (!pattern.test(name)) {
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
|
||||
let data: string;
|
||||
try {
|
||||
data = readFileSync(llmOutput, "utf-8");
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
|
||||
process.stdout.write(
|
||||
`\x1b[2m----------------------\n${data}\n----------------------\x1b[0m\n`,
|
||||
);
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
process.stderr.write(`${err}\n`);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,158 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Usage: ./{function_name}.py <tool-data>
|
||||
|
||||
import os
|
||||
import re
|
||||
import json
|
||||
import sys
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
def _ensure_cwd_venv():
|
||||
cwd = Path.cwd()
|
||||
venv_dir = cwd / ".venv"
|
||||
if not venv_dir.is_dir():
|
||||
return
|
||||
|
||||
py = venv_dir / ("Scripts/python.exe" if os.name == "nt" else "bin/python")
|
||||
if not py.exists():
|
||||
return
|
||||
|
||||
if Path(sys.prefix).resolve() == venv_dir.resolve():
|
||||
return
|
||||
|
||||
os.execv(str(py), [str(py)] + sys.argv)
|
||||
|
||||
_ensure_cwd_venv()
|
||||
|
||||
|
||||
def main():
|
||||
raw_data = parse_argv()
|
||||
tool_data = parse_raw_data(raw_data)
|
||||
|
||||
root_dir = "{root_dir}"
|
||||
setup_env(root_dir)
|
||||
|
||||
tool_path = "{tool_path}.py"
|
||||
run(tool_path, "run", tool_data)
|
||||
|
||||
|
||||
def parse_raw_data(data):
|
||||
if not data:
|
||||
raise ValueError("No JSON data")
|
||||
|
||||
try:
|
||||
return json.loads(data)
|
||||
except Exception:
|
||||
raise ValueError("Invalid JSON data")
|
||||
|
||||
|
||||
def parse_argv():
|
||||
tool_data_file = os.environ.get("LLM_TOOL_DATA_FILE")
|
||||
if tool_data_file and os.path.isfile(tool_data_file):
|
||||
with open(tool_data_file, "r", encoding="utf-8") as f:
|
||||
return f.read()
|
||||
|
||||
argv = sys.argv[:] + [None] * max(0, 2 - len(sys.argv))
|
||||
|
||||
tool_data = argv[1]
|
||||
|
||||
if (not tool_data):
|
||||
print("Usage: ./{function_name}.py <tool-data>", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
return tool_data
|
||||
|
||||
|
||||
def setup_env(root_dir):
|
||||
load_env(os.path.join(root_dir, ".env"))
|
||||
os.environ["LLM_ROOT_DIR"] = root_dir
|
||||
os.environ["LLM_TOOL_NAME"] = "{function_name}"
|
||||
os.environ["LLM_TOOL_CACHE_DIR"] = os.path.join(root_dir, "cache", "{function_name}")
|
||||
|
||||
|
||||
def load_env(file_path):
|
||||
try:
|
||||
with open(file_path, "r") as f:
|
||||
lines = f.readlines()
|
||||
except:
|
||||
return
|
||||
|
||||
env_vars = {}
|
||||
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
if line.startswith("#") or not line:
|
||||
continue
|
||||
|
||||
key, *value_parts = line.split("=")
|
||||
env_name = key.strip()
|
||||
|
||||
if env_name not in os.environ:
|
||||
env_value = "=".join(value_parts).strip()
|
||||
if (env_value.startswith('"') and env_value.endswith('"')) or (env_value.startswith("'") and env_value.endswith("'")):
|
||||
env_value = env_value[1:-1]
|
||||
env_vars[env_name] = env_value
|
||||
|
||||
os.environ.update(env_vars)
|
||||
|
||||
|
||||
def run(tool_path, tool_func, tool_data):
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
os.path.basename(tool_path), tool_path
|
||||
)
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(mod)
|
||||
|
||||
if not hasattr(mod, tool_func):
|
||||
raise Exception(f"No module function '{tool_func}' at '{tool_path}'")
|
||||
|
||||
value = getattr(mod, tool_func)(**tool_data)
|
||||
return_to_llm(value)
|
||||
dump_result("{function_name}")
|
||||
|
||||
|
||||
def return_to_llm(value):
|
||||
if value is None:
|
||||
return
|
||||
|
||||
if "LLM_OUTPUT" in os.environ:
|
||||
writer = open(os.environ["LLM_OUTPUT"], "w")
|
||||
else:
|
||||
writer = sys.stdout
|
||||
|
||||
value_type = type(value).__name__
|
||||
if value_type in ("str", "int", "float", "bool"):
|
||||
writer.write(str(value))
|
||||
elif value_type == "dict" or value_type == "list":
|
||||
value_str = json.dumps(value, indent=2)
|
||||
assert value == json.loads(value_str)
|
||||
writer.write(value_str)
|
||||
|
||||
|
||||
def dump_result(name):
|
||||
if (not os.getenv("LLM_DUMP_RESULTS")) or (not os.getenv("LLM_OUTPUT")) or (not os.isatty(1)):
|
||||
return
|
||||
|
||||
show_result = False
|
||||
try:
|
||||
if re.search(rf'\b({os.environ["LLM_DUMP_RESULTS"]})\b', name):
|
||||
show_result = True
|
||||
except:
|
||||
pass
|
||||
|
||||
if not show_result:
|
||||
return
|
||||
|
||||
try:
|
||||
with open(os.environ["LLM_OUTPUT"], "r", encoding="utf-8") as f:
|
||||
data = f.read()
|
||||
except:
|
||||
return
|
||||
|
||||
print(f"\x1b[2m----------------------\n{data}\n----------------------\x1b[0m")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,120 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Usage: ./{function_name}.sh <tool-data>
|
||||
|
||||
set -e
|
||||
|
||||
main() {
|
||||
root_dir="{root_dir}"
|
||||
parse_argv "$@"
|
||||
setup_env
|
||||
tool_path="{tool_path}.sh"
|
||||
run
|
||||
}
|
||||
|
||||
parse_argv() {
|
||||
if [[ -n "$LLM_TOOL_DATA_FILE" ]] && [[ -f "$LLM_TOOL_DATA_FILE" ]]; then
|
||||
tool_data="$(cat "$LLM_TOOL_DATA_FILE")"
|
||||
else
|
||||
tool_data="$1"
|
||||
fi
|
||||
if [[ -z "$tool_data" ]]; then
|
||||
die "usage: ./{function_name}.sh <tool-data>"
|
||||
fi
|
||||
}
|
||||
|
||||
setup_env() {
|
||||
load_env "$root_dir/.env"
|
||||
export LLM_ROOT_DIR="$root_dir"
|
||||
export LLM_TOOL_NAME="{function_name}"
|
||||
export LLM_TOOL_CACHE_DIR="$LLM_ROOT_DIR/cache/{function_name}"
|
||||
export LLM_PROMPT_UTILS_FILE="{prompt_utils_file}"
|
||||
}
|
||||
|
||||
load_env() {
|
||||
local env_file="$1" env_vars
|
||||
if [[ -f "$env_file" ]]; then
|
||||
while IFS='=' read -r key value; do
|
||||
if [[ "$key" == $'#'* ]] || [[ -z "$key" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ -z "${!key+x}" ]]; then
|
||||
env_vars="$env_vars $key=$value"
|
||||
fi
|
||||
done < <(cat "$env_file"; echo "")
|
||||
|
||||
if [[ -n "$env_vars" ]]; then
|
||||
eval "export $env_vars"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
run() {
|
||||
if [[ -z "$tool_data" ]]; then
|
||||
die "error: no JSON data"
|
||||
fi
|
||||
|
||||
if [[ "$OS" == "Windows_NT" ]]; then
|
||||
set -o igncr
|
||||
tool_path="$(cygpath -w "$tool_path")"
|
||||
fi
|
||||
|
||||
jq_script="$(cat <<-'EOF'
|
||||
def escape_shell_word:
|
||||
tostring
|
||||
| gsub("'"; "'\"'\"'")
|
||||
| gsub("\n"; "'$'\\n''")
|
||||
| "'\(.)'";
|
||||
def to_args:
|
||||
to_entries | .[] |
|
||||
(.key | split("_") | join("-")) as $key |
|
||||
if .value | type == "array" then
|
||||
.value | .[] | "--\($key) \(. | escape_shell_word)"
|
||||
elif .value | type == "boolean" then
|
||||
if .value then "--\($key)" else "" end
|
||||
else
|
||||
"--\($key) \(.value | escape_shell_word)"
|
||||
end;
|
||||
[ to_args ] | join(" ")
|
||||
EOF
|
||||
)"
|
||||
args="$(echo "$tool_data" | jq -r "$jq_script" 2>/dev/null)" || {
|
||||
die "error: invalid JSON data"
|
||||
}
|
||||
|
||||
if [[ -z "$LLM_OUTPUT" ]]; then
|
||||
is_temp_llm_output=1
|
||||
# shellcheck disable=SC2155
|
||||
export LLM_OUTPUT="$(mktemp)"
|
||||
fi
|
||||
|
||||
eval "'$tool_path' $args"
|
||||
|
||||
if [[ "$is_temp_llm_output" -eq 1 ]]; then
|
||||
cat "$LLM_OUTPUT"
|
||||
else
|
||||
dump_result "{function_name}"
|
||||
fi
|
||||
}
|
||||
|
||||
dump_result() {
|
||||
if [[ "$LLM_OUTPUT" == "/dev/stdout" ]] || [[ -z "$LLM_DUMP_RESULTS" ]] || [[ ! -t 1 ]]; then
|
||||
return;
|
||||
fi
|
||||
|
||||
if grep -q -w -E "$LLM_DUMP_RESULTS" <<<"$1"; then
|
||||
cat <<EOF
|
||||
$(echo -e "\e[2m")----------------------
|
||||
$(cat "$LLM_OUTPUT")
|
||||
----------------------$(echo -e "\e[0m")
|
||||
EOF
|
||||
fi
|
||||
}
|
||||
|
||||
die() {
|
||||
echo "$*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -0,0 +1,184 @@
|
||||
#!/usr/bin/env tsx
|
||||
|
||||
// Usage: ./{function_name}.ts <tool-data>
|
||||
|
||||
import { readFileSync, writeFileSync, existsSync } from "fs";
|
||||
import { join } from "path";
|
||||
import { pathToFileURL } from "url";
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const rawData = parseArgv();
|
||||
const toolData = parseRawData(rawData);
|
||||
|
||||
const rootDir = "{root_dir}";
|
||||
setupEnv(rootDir);
|
||||
|
||||
const toolPath = "{tool_path}.ts";
|
||||
await run(toolPath, "run", toolData);
|
||||
}
|
||||
|
||||
function parseRawData(data: string): Record<string, unknown> {
|
||||
if (!data) {
|
||||
throw new Error("No JSON data");
|
||||
}
|
||||
|
||||
try {
|
||||
return JSON.parse(data);
|
||||
} catch {
|
||||
throw new Error("Invalid JSON data");
|
||||
}
|
||||
}
|
||||
|
||||
function parseArgv(): string {
|
||||
const toolDataFile = process.env["LLM_TOOL_DATA_FILE"];
|
||||
if (toolDataFile && existsSync(toolDataFile)) {
|
||||
return readFileSync(toolDataFile, "utf-8");
|
||||
}
|
||||
|
||||
const toolData = process.argv[2];
|
||||
|
||||
if (!toolData) {
|
||||
process.stderr.write("Usage: ./{function_name}.ts <tool-data>\n");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
return toolData;
|
||||
}
|
||||
|
||||
function setupEnv(rootDir: string): void {
|
||||
loadEnv(join(rootDir, ".env"));
|
||||
process.env["LLM_ROOT_DIR"] = rootDir;
|
||||
process.env["LLM_TOOL_NAME"] = "{function_name}";
|
||||
process.env["LLM_TOOL_CACHE_DIR"] = join(rootDir, "cache", "{function_name}");
|
||||
}
|
||||
|
||||
function loadEnv(filePath: string): void {
|
||||
let lines: string[];
|
||||
try {
|
||||
lines = readFileSync(filePath, "utf-8").split("\n");
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const raw of lines) {
|
||||
const line = raw.trim();
|
||||
if (line.startsWith("#") || !line) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const eqIdx = line.indexOf("=");
|
||||
if (eqIdx === -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const key = line.slice(0, eqIdx).trim();
|
||||
if (key in process.env) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let value = line.slice(eqIdx + 1).trim();
|
||||
if (
|
||||
(value.startsWith('"') && value.endsWith('"')) ||
|
||||
(value.startsWith("'") && value.endsWith("'"))
|
||||
) {
|
||||
value = value.slice(1, -1);
|
||||
}
|
||||
process.env[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
function extractParamNames(fn: Function): string[] {
|
||||
const src = fn.toString();
|
||||
const match = src.match(/^(?:async\s+)?function\s*\w*\s*\(([^)]*)\)/);
|
||||
if (!match) {
|
||||
return [];
|
||||
}
|
||||
return match[1]
|
||||
.split(",")
|
||||
.map((p) => p.trim().replace(/[:=?].*/s, "").trim())
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
function spreadArgs(
|
||||
fn: Function,
|
||||
data: Record<string, unknown>,
|
||||
): unknown[] {
|
||||
const names = extractParamNames(fn);
|
||||
if (names.length === 0) {
|
||||
return [];
|
||||
}
|
||||
return names.map((name) => data[name]);
|
||||
}
|
||||
|
||||
async function run(
|
||||
toolPath: string,
|
||||
toolFunc: string,
|
||||
toolData: Record<string, unknown>,
|
||||
): Promise<void> {
|
||||
const mod = await import(pathToFileURL(toolPath).href);
|
||||
|
||||
if (typeof mod[toolFunc] !== "function") {
|
||||
throw new Error(`No module function '${toolFunc}' at '${toolPath}'`);
|
||||
}
|
||||
|
||||
const fn = mod[toolFunc] as Function;
|
||||
const args = spreadArgs(fn, toolData);
|
||||
const value = await fn(...args);
|
||||
returnToLlm(value);
|
||||
dumpResult("{function_name}");
|
||||
}
|
||||
|
||||
function returnToLlm(value: unknown): void {
|
||||
if (value === null || value === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
const output = process.env["LLM_OUTPUT"];
|
||||
const write = (s: string) => {
|
||||
if (output) {
|
||||
writeFileSync(output, s, "utf-8");
|
||||
} else {
|
||||
process.stdout.write(s);
|
||||
}
|
||||
};
|
||||
|
||||
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
||||
write(String(value));
|
||||
} else if (typeof value === "object") {
|
||||
write(JSON.stringify(value, null, 2));
|
||||
}
|
||||
}
|
||||
|
||||
function dumpResult(name: string): void {
|
||||
const dumpResults = process.env["LLM_DUMP_RESULTS"];
|
||||
const llmOutput = process.env["LLM_OUTPUT"];
|
||||
|
||||
if (!dumpResults || !llmOutput || !process.stdout.isTTY) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const pattern = new RegExp(`\\b(${dumpResults})\\b`);
|
||||
if (!pattern.test(name)) {
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
|
||||
let data: string;
|
||||
try {
|
||||
data = readFileSync(llmOutput, "utf-8");
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
|
||||
process.stdout.write(
|
||||
`\x1b[2m----------------------\n${data}\n----------------------\x1b[0m\n`,
|
||||
);
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
process.stderr.write(`${err}\n`);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,51 @@
|
||||
import os
|
||||
from typing import List, Literal, Optional
|
||||
|
||||
|
||||
def run(
|
||||
string: str,
|
||||
string_enum: Literal["foo", "bar"],
|
||||
boolean: bool,
|
||||
integer: int,
|
||||
number: float,
|
||||
array: List[str],
|
||||
string_optional: Optional[str] = None,
|
||||
integer_with_default: int = 42,
|
||||
boolean_with_default: bool = True,
|
||||
number_with_default: float = 3.14,
|
||||
string_with_default: str = "hello",
|
||||
array_optional: Optional[List[str]] = None,
|
||||
):
|
||||
"""Demonstrates all supported Python parameter types and variations.
|
||||
Args:
|
||||
string: A required string property
|
||||
string_enum: A required string property constrained to specific values
|
||||
boolean: A required boolean property
|
||||
integer: A required integer property
|
||||
number: A required number (float) property
|
||||
array: A required string array property
|
||||
string_optional: An optional string property (Optional[str] with None default)
|
||||
integer_with_default: An optional integer with a non-None default value
|
||||
boolean_with_default: An optional boolean with a default value
|
||||
number_with_default: An optional number with a default value
|
||||
string_with_default: An optional string with a default value
|
||||
array_optional: An optional string array property
|
||||
"""
|
||||
output = f"""string: {string}
|
||||
string_enum: {string_enum}
|
||||
boolean: {boolean}
|
||||
integer: {integer}
|
||||
number: {number}
|
||||
array: {array}
|
||||
string_optional: {string_optional}
|
||||
integer_with_default: {integer_with_default}
|
||||
boolean_with_default: {boolean_with_default}
|
||||
number_with_default: {number_with_default}
|
||||
string_with_default: {string_with_default}
|
||||
array_optional: {array_optional}"""
|
||||
|
||||
for key, value in os.environ.items():
|
||||
if key.startswith("LLM_"):
|
||||
output = f"{output}\n{key}: {value}"
|
||||
|
||||
return output
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Demonstrate how to create a tool using Bash and how to use comment tags.
|
||||
# @option --string! Define a required string property
|
||||
# @option --string-enum![foo|bar] Define a required string property with enum
|
||||
# @option --string-optional Define a optional string property
|
||||
# @flag --boolean Define a boolean property
|
||||
# @option --integer! <INT> Define a required integer property
|
||||
# @option --number! <NUM> Define a required number property
|
||||
# @option --array+ <VALUE> Define a required string array property
|
||||
# @option --array-optional* Define a optional string array property
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
cat <<EOF >> "$LLM_OUTPUT"
|
||||
string: ${argc_string}
|
||||
string_enum: ${argc_string_enum}
|
||||
string_optional: ${argc_string_optional}
|
||||
boolean: ${argc_boolean}
|
||||
integer: ${argc_integer}
|
||||
number: ${argc_number}
|
||||
array: ${argc_array[@]}
|
||||
array_optional: ${argc_array_optional[@]}
|
||||
$(printenv | grep '^LLM_')
|
||||
EOF
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Demonstrates all supported TypeScript parameter types and variations.
|
||||
*
|
||||
* @param string - A required string property
|
||||
* @param string_enum - A required string property constrained to specific values
|
||||
* @param boolean - A required boolean property
|
||||
* @param number - A required number property
|
||||
* @param array_bracket - A required string array using bracket syntax
|
||||
* @param array_generic - A required string array using generic syntax
|
||||
* @param string_optional - An optional string using the question mark syntax
|
||||
* @param string_nullable - An optional string using the union-with-null syntax
|
||||
* @param number_with_default - An optional number with a default value
|
||||
* @param boolean_with_default - An optional boolean with a default value
|
||||
* @param string_with_default - An optional string with a default value
|
||||
* @param array_optional - An optional string array using the question mark syntax
|
||||
*/
|
||||
export function run(
|
||||
string: string,
|
||||
string_enum: "foo" | "bar",
|
||||
boolean: boolean,
|
||||
number: number,
|
||||
array_bracket: string[],
|
||||
array_generic: Array<string>,
|
||||
string_optional?: string,
|
||||
string_nullable: string | null = null,
|
||||
number_with_default: number = 42,
|
||||
boolean_with_default: boolean = true,
|
||||
string_with_default: string = "hello",
|
||||
array_optional?: string[],
|
||||
): string {
|
||||
const parts = [
|
||||
`string: ${string}`,
|
||||
`string_enum: ${string_enum}`,
|
||||
`boolean: ${boolean}`,
|
||||
`number: ${number}`,
|
||||
`array_bracket: ${JSON.stringify(array_bracket)}`,
|
||||
`array_generic: ${JSON.stringify(array_generic)}`,
|
||||
`string_optional: ${string_optional}`,
|
||||
`string_nullable: ${string_nullable}`,
|
||||
`number_with_default: ${number_with_default}`,
|
||||
`boolean_with_default: ${boolean_with_default}`,
|
||||
`string_with_default: ${string_with_default}`,
|
||||
`array_optional: ${JSON.stringify(array_optional)}`,
|
||||
];
|
||||
|
||||
for (const [key, value] of Object.entries(process.env)) {
|
||||
if (key.startsWith("LLM_")) {
|
||||
parts.push(`${key}: ${value}`);
|
||||
}
|
||||
}
|
||||
|
||||
return parts.join("\n");
|
||||
}
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Execute the shell command.
|
||||
# @option --command! The command to execute.
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "$LLM_PROMPT_UTILS_FILE"
|
||||
|
||||
main() {
|
||||
guard_operation
|
||||
# shellcheck disable=SC2154
|
||||
eval "$argc_command" >> "$LLM_OUTPUT"
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import ast
|
||||
import io
|
||||
from contextlib import redirect_stdout
|
||||
|
||||
|
||||
def run(code: str):
|
||||
"""Execute the given Python code.
|
||||
Args:
|
||||
code: The Python code to execute, such as `print("hello world")`
|
||||
"""
|
||||
output = io.StringIO()
|
||||
with redirect_stdout(output):
|
||||
value = exec_with_return(code, {}, {})
|
||||
|
||||
if value is not None:
|
||||
output.write(str(value))
|
||||
|
||||
return output.getvalue()
|
||||
|
||||
|
||||
def exec_with_return(code: str, globals: dict, locals: dict):
|
||||
a = ast.parse(code)
|
||||
last_expression = None
|
||||
if a.body:
|
||||
if isinstance(a_last := a.body[-1], ast.Expr):
|
||||
last_expression = ast.unparse(a.body.pop())
|
||||
elif isinstance(a_last, ast.Assign):
|
||||
last_expression = ast.unparse(a_last.targets[0])
|
||||
elif isinstance(a_last, (ast.AnnAssign, ast.AugAssign)):
|
||||
last_expression = ast.unparse(a_last.target)
|
||||
exec(ast.unparse(a), globals, locals)
|
||||
if last_expression:
|
||||
return eval(last_expression, globals, locals)
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Execute sql code.
|
||||
# @option --code! The code to execute.
|
||||
|
||||
# @meta require-tools usql
|
||||
|
||||
# @env USQL_DSN! The database connection url. e.g. pgsql://user:pass@host:port
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "$LLM_PROMPT_UTILS_FILE"
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
if ! grep -qi '^select' <<<"$argc_code"; then
|
||||
guard_operation ""
|
||||
fi
|
||||
usql -c "$argc_code" "$USQL_DSN" >> "$LLM_OUTPUT"
|
||||
}
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Extract the content from a given URL.
|
||||
# @option --url! The URL to scrape.
|
||||
|
||||
# @meta require-tools pandoc
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
# span and div tags are dropped from the HTML https://pandoc.org/MANUAL.html#raw-htmltex and sed removes any inline SVG images in image tags from the Markdown content.
|
||||
curl -fsSL "$argc_url" | \
|
||||
pandoc -f html-native_divs-native_spans -t gfm-raw_html --wrap=none | \
|
||||
sed -E 's/!\[[^]]*\]\([^)]*\)//g' \
|
||||
>> "$LLM_OUTPUT"
|
||||
}
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Extract the content from a given URL.
|
||||
# @option --url! The URL to scrape.
|
||||
|
||||
# @env JINA_API_KEY Your Jina API key
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
curl_args=()
|
||||
if [[ -n "$JINA_API_KEY" ]]; then
|
||||
curl_args+=("-H" "Authorization: Bearer $JINA_API_KEY")
|
||||
fi
|
||||
curl -fsSL "${curl_args[@]}" "https://r.jina.ai/$argc_url" >> "$LLM_OUTPUT"
|
||||
}
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Read the contents of a file at the specified path.
|
||||
# Use this when you need to examine the contents of an existing file.
|
||||
|
||||
# @option --path! The path of the file to read
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
main() {
|
||||
# shellcheck disable=SC2154
|
||||
cat "$argc_path" >> "$LLM_OUTPUT" 2>&1 || echo "No such file or path: $argc_path" >> "$LLM_OUTPUT"
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Find files by glob pattern. Returns matching file paths sorted by modification time.
|
||||
# Use this to discover files before reading them.
|
||||
|
||||
# @option --pattern! The glob pattern to match files against (e.g. "**/*.rs", "src/**/*.ts", "*.yaml")
|
||||
# @option --path The directory to search in (defaults to current working directory)
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
MAX_RESULTS=100
|
||||
|
||||
main() {
|
||||
# shellcheck disable=SC2154
|
||||
local glob_pattern="$argc_pattern"
|
||||
local search_path="${argc_path:-.}"
|
||||
|
||||
if [[ ! -d "$search_path" ]]; then
|
||||
echo "Error: directory not found: $search_path" >> "$LLM_OUTPUT"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local results
|
||||
if command -v fd &>/dev/null; then
|
||||
results=$(fd --type f --glob "$glob_pattern" "$search_path" \
|
||||
--exclude '.git' \
|
||||
--exclude 'node_modules' \
|
||||
--exclude 'target' \
|
||||
--exclude 'dist' \
|
||||
--exclude '__pycache__' \
|
||||
--exclude 'vendor' \
|
||||
--exclude '.build' \
|
||||
2>/dev/null | head -n "$MAX_RESULTS") || true
|
||||
else
|
||||
results=$(find "$search_path" -type f -name "$glob_pattern" \
|
||||
-not -path '*/.git/*' \
|
||||
-not -path '*/node_modules/*' \
|
||||
-not -path '*/target/*' \
|
||||
-not -path '*/dist/*' \
|
||||
-not -path '*/__pycache__/*' \
|
||||
-not -path '*/vendor/*' \
|
||||
-not -path '*/.build/*' \
|
||||
2>/dev/null | head -n "$MAX_RESULTS") || true
|
||||
fi
|
||||
|
||||
if [[ -z "$results" ]]; then
|
||||
echo "No files found matching: $glob_pattern" >> "$LLM_OUTPUT"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "$results" >> "$LLM_OUTPUT"
|
||||
|
||||
local count
|
||||
count=$(echo "$results" | wc -l)
|
||||
if [[ "$count" -ge "$MAX_RESULTS" ]]; then
|
||||
printf "\n(Results limited to %s files. Use a more specific pattern.)\n" "$MAX_RESULTS" >> "$LLM_OUTPUT"
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Search file contents using regular expressions. Returns matching file paths and lines.
|
||||
# Use this to find relevant code before reading files. Much faster than reading files to search.
|
||||
|
||||
# @option --pattern! The regex pattern to search for in file contents
|
||||
# @option --path The directory to search in (defaults to current working directory)
|
||||
# @option --include File pattern to filter by (e.g. "*.rs", "*.{ts,tsx}", "*.py")
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
MAX_RESULTS=50
|
||||
MAX_LINE_LENGTH=2000
|
||||
|
||||
main() {
|
||||
# shellcheck disable=SC2154
|
||||
local search_pattern="$argc_pattern"
|
||||
local search_path="${argc_path:-.}"
|
||||
local include_filter="${argc_include:-}"
|
||||
|
||||
if [[ ! -d "$search_path" ]]; then
|
||||
echo "Error: directory not found: $search_path" >> "$LLM_OUTPUT"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local grep_args=(-rn --color=never)
|
||||
|
||||
grep_args+=(
|
||||
--exclude-dir='.git'
|
||||
--exclude-dir='node_modules'
|
||||
--exclude-dir='target'
|
||||
--exclude-dir='dist'
|
||||
--exclude-dir='build'
|
||||
--exclude-dir='__pycache__'
|
||||
--exclude-dir='vendor'
|
||||
--exclude-dir='.build'
|
||||
--exclude-dir='.next'
|
||||
--exclude='*.min.js'
|
||||
--exclude='*.min.css'
|
||||
--exclude='*.map'
|
||||
--exclude='*.lock'
|
||||
--exclude='package-lock.json'
|
||||
)
|
||||
|
||||
if [[ -n "$include_filter" ]]; then
|
||||
grep_args+=("--include=$include_filter")
|
||||
fi
|
||||
|
||||
local results
|
||||
results=$(grep "${grep_args[@]}" -E "$search_pattern" "$search_path" 2>/dev/null | head -n "$MAX_RESULTS") || true
|
||||
|
||||
if [[ -z "$results" ]]; then
|
||||
echo "No matches found for: $search_pattern" >> "$LLM_OUTPUT"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "$results" | while IFS= read -r line; do
|
||||
if [[ ${#line} -gt $MAX_LINE_LENGTH ]]; then
|
||||
line="${line:0:$MAX_LINE_LENGTH}... (truncated)"
|
||||
fi
|
||||
|
||||
echo "$line"
|
||||
done >> "$LLM_OUTPUT"
|
||||
|
||||
local count
|
||||
count=$(echo "$results" | wc -l)
|
||||
if [[ "$count" -ge "$MAX_RESULTS" ]]; then
|
||||
printf "\n(Results limited to %s matches. Narrow your search with --include or a more specific pattern.)\n" "$MAX_RESULTS" >> "$LLM_OUTPUT"
|
||||
fi
|
||||
}
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe List all files and directories at the specified path.
|
||||
|
||||
# @option --path! The path of the directory to list
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
main() {
|
||||
# shellcheck disable=SC2154
|
||||
ls -1 "$argc_path" >> "$LLM_OUTPUT" 2>&1 || echo "No such path: $argc_path" >> "$LLM_OUTPUT"
|
||||
}
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Create a new directory at the specified path.
|
||||
|
||||
# @option --path! The path of the directory to create
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
main() {
|
||||
# shellcheck disable=SC2154
|
||||
mkdir -p "$argc_path"
|
||||
echo "Directory created: $argc_path" >> "$LLM_OUTPUT"
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Apply a patch to a file at the specified path.
|
||||
# This can be used to edit a file without having to rewrite the whole file.
|
||||
|
||||
# @option --path! The path of the file to apply the patch to
|
||||
# @option --contents! The patch to apply to the file
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "$LLM_PROMPT_UTILS_FILE"
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
if [[ ! -f "$argc_path" ]]; then
|
||||
error "Unable to find the specified file: $argc_path"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
new_contents="$(patch_file "$argc_path" <(printf "%s" "$argc_contents"))"
|
||||
printf "%s" "$new_contents" | git diff --no-index "$argc_path" - || true
|
||||
|
||||
guard_operation "Apply changes?"
|
||||
|
||||
printf "%s" "$new_contents" > "$argc_path"
|
||||
|
||||
info "Applied the patch to: $argc_path" >> "$LLM_OUTPUT"
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Read a file with line numbers, offset, and limit. For directories, lists entries.
|
||||
# Prefer this over fs_cat for controlled reading. Use offset/limit to read specific sections.
|
||||
# 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)
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
MAX_LINE_LENGTH=2000
|
||||
MAX_BYTES=51200
|
||||
|
||||
main() {
|
||||
# shellcheck disable=SC2154
|
||||
local target="$argc_path"
|
||||
local offset="${argc_offset:-1}"
|
||||
local limit="${argc_limit:-2000}"
|
||||
|
||||
if [[ ! -e "$target" ]]; then
|
||||
echo "Error: path not found: $target" >> "$LLM_OUTPUT"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ -d "$target" ]]; then
|
||||
ls -1 "$target" >> "$LLM_OUTPUT" 2>&1
|
||||
return 0
|
||||
fi
|
||||
|
||||
local total_lines file_bytes
|
||||
total_lines=$(wc -l < "$target" 2>/dev/null || echo 0)
|
||||
file_bytes=$(wc -c < "$target" 2>/dev/null || echo 0)
|
||||
|
||||
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."
|
||||
echo "Use --offset and --limit to read specific sections, or use the grep tool to find relevant lines first."
|
||||
echo ""
|
||||
} >> "$LLM_OUTPUT"
|
||||
fi
|
||||
|
||||
local end_line=$((offset + limit - 1))
|
||||
|
||||
sed -n "${offset},${end_line}p" "$target" 2>/dev/null | {
|
||||
local line_num=$offset
|
||||
while IFS= read -r line; do
|
||||
if [[ ${#line} -gt $MAX_LINE_LENGTH ]]; then
|
||||
line="${line:0:$MAX_LINE_LENGTH}... (truncated)"
|
||||
fi
|
||||
printf "%d: %s\n" "$line_num" "$line"
|
||||
line_num=$((line_num + 1))
|
||||
done
|
||||
} >> "$LLM_OUTPUT"
|
||||
|
||||
if [[ "$end_line" -lt "$total_lines" ]]; then
|
||||
echo "" >> "$LLM_OUTPUT"
|
||||
echo "(${total_lines} total lines. Use --offset $((end_line + 1)) to read more.)" >> "$LLM_OUTPUT"
|
||||
fi
|
||||
}
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Remove the file or directory at the specified path.
|
||||
|
||||
# @option --path! The path of the file or directory to remove
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "$LLM_PROMPT_UTILS_FILE"
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
if [[ -f "$argc_path" ]]; then
|
||||
guard_path "$argc_path" "Remove '$argc_path'?"
|
||||
rm -rf "$argc_path"
|
||||
fi
|
||||
|
||||
echo "Path removed: $argc_path" >> "$LLM_OUTPUT"
|
||||
}
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Write the full file contents to a file at the specified path.
|
||||
|
||||
# @option --path! The path of the file to write to
|
||||
# @option --contents! The full contents to write to the file
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "$LLM_PROMPT_UTILS_FILE"
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
if [[ -f "$argc_path" ]]; then
|
||||
printf "%s" "$argc_contents" | git diff --no-index "$argc_path" - || true
|
||||
guard_operation "Apply changes?"
|
||||
else
|
||||
guard_path "$argc_path" "Write '$argc_path'?"
|
||||
mkdir -p "$(dirname "$argc_path")"
|
||||
fi
|
||||
|
||||
printf "%s" "$argc_contents" > "$argc_path"
|
||||
echo "The File contents were written to: $argc_path" >> "$LLM_OUTPUT"
|
||||
}
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Get the current time.
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
main() {
|
||||
date >> "$LLM_OUTPUT"
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from urllib.parse import quote_plus
|
||||
from urllib.request import urlopen
|
||||
|
||||
|
||||
def run(
|
||||
location: str,
|
||||
llm_output: Optional[str] = None,
|
||||
) -> str:
|
||||
"""Get the current weather in a given location
|
||||
|
||||
Args:
|
||||
location (str): The city and optionally the state or country (e.g., "London", "San Francisco, CA").
|
||||
|
||||
Returns:
|
||||
str: A single-line formatted weather string from wttr.in (``format=4`` with metric units).
|
||||
"""
|
||||
url = f"https://wttr.in/{quote_plus(location)}?format=4&M"
|
||||
|
||||
with urlopen(url, timeout=10) as resp:
|
||||
weather = resp.read().decode("utf-8", errors="replace")
|
||||
|
||||
dest = llm_output if llm_output is not None else os.environ.get("LLM_OUTPUT", "/dev/stdout")
|
||||
|
||||
if dest not in {"-", "/dev/stdout"}:
|
||||
path = Path(dest)
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with path.open("a", encoding="utf-8") as fh:
|
||||
fh.write(weather)
|
||||
else:
|
||||
pass
|
||||
|
||||
return weather
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Get the current weather in a given location.
|
||||
# @option --location! The city and optionally the state or country, e.g., "London", "San Francisco, CA".
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
main() {
|
||||
curl -fsSL "https://wttr.in/$(echo "$argc_location" | sed 's/ /+/g')?format=4&M" \
|
||||
>> "$LLM_OUTPUT"
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env tsx
|
||||
|
||||
import { appendFileSync, mkdirSync } from "fs";
|
||||
import { dirname } from "path";
|
||||
|
||||
/**
|
||||
* Get the current weather in a given location
|
||||
* @param location - The city and optionally the state or country (e.g., "London", "San Francisco, CA").
|
||||
*/
|
||||
export async function run(location: string): string {
|
||||
const encoded = encodeURIComponent(location);
|
||||
const url = `https://wttr.in/${encoded}?format=4`;
|
||||
|
||||
const resp = await fetch(url);
|
||||
const data = await resp.text();
|
||||
|
||||
const dest = process.env["LLM_OUTPUT"] ?? "/dev/stdout";
|
||||
if (dest !== "-" && dest !== "/dev/stdout") {
|
||||
mkdirSync(dirname(dest), { recursive: true });
|
||||
appendFileSync(dest, data, "utf-8");
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @meta require-tools jira
|
||||
# @describe Query for jira issues using a Jira Query Language (JQL) query
|
||||
# @option --jql-query! The Jira Query Language query to execute
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
main() {
|
||||
jira issue ls -q "$argc_jql_query" --plain >> "$LLM_OUTPUT"
|
||||
}
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Search arXiv using the given search query and return the top papers.
|
||||
|
||||
# @option --query! The search query.
|
||||
|
||||
# @env ARXIV_MAX_RESULTS=3 The max results to return.
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
main() {
|
||||
# shellcheck disable=SC2154
|
||||
encoded_query="$(jq -nr --arg q "$argc_query" '$q|@uri')"
|
||||
url="http://export.arxiv.org/api/query?search_query=all:$encoded_query&max_results=$ARXIV_MAX_RESULTS"
|
||||
curl -fsSL "$url" >> "$LLM_OUTPUT"
|
||||
}
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Search Wikipedia using the given search query.
|
||||
# Use it to get detailed information about a public figure, interpretation of a complex scientific concept or in-depth connectivity of a significant historical event, etc.
|
||||
|
||||
# @option --query! The search query.
|
||||
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
encoded_query="$(jq -nr --arg q "$argc_query" '$q|@uri')"
|
||||
base_url="https://en.wikipedia.org/w/api.php"
|
||||
url="$base_url?action=query&list=search&srprop=&srlimit=1&limit=1&srsearch=$encoded_query&srinfo=suggestion&format=json"
|
||||
json="$(curl -fsSL "$url")"
|
||||
# suggestion="$(echo "$json" | jq -r '.query.searchinfo.suggestion // empty')"
|
||||
title="$(echo "$json" | jq -r '.query.search[0].title // empty')"
|
||||
pageid="$(echo "$json" | jq -r '.query.search[0].pageid // empty')"
|
||||
|
||||
if [[ -z "$title" || -z "$pageid" ]]; then
|
||||
echo "error: no results for '$argc_query'" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
title="$(echo "$title" | tr ' ' '_')"
|
||||
url="$base_url?action=query&prop=extracts&explaintext=&titles=$title&exintro=&format=json"
|
||||
curl -fsSL "$url" | jq -r '.query.pages["'"$pageid"'"].extract' >> "$LLM_OUTPUT"
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Get an answer to a question using Wolfram Alpha. The input query should be in English.
|
||||
# Use it to answer user questions that require computation, detailed facts, data analysis, or complex queries.
|
||||
|
||||
# @option --query! The search/computation query to pass to Wolfram Alpha
|
||||
|
||||
# @env WOLFRAM_API_ID! Your Wolfram Alpha API ID
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
encoded_query="$(jq -nr --arg q "$argc_query" '$q|@uri')"
|
||||
url="https://api.wolframalpha.com/v2/query?appid=${WOLFRAM_API_ID}&input=$encoded_query&output=json&format=plaintext"
|
||||
|
||||
curl -fsSL "$url" | jq '[.queryresult | .pods[] | {title:.title, values:[.subpods[].plaintext | select(. != "")]}]' \
|
||||
>> "$LLM_OUTPUT"
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Send an email.
|
||||
# @option --recipient! The recipient of the email.
|
||||
# @option --subject! The subject of the email.
|
||||
# @option --body! The body of the email.
|
||||
|
||||
# @env EMAIL_SMTP_ADDR! The SMTP Address, e.g. smtps://smtp.gmail.com:465
|
||||
# @env EMAIL_SMTP_USER! The SMTP User, e.g. alice@gmail.com
|
||||
# @env EMAIL_SMTP_PASS! The SMTP Password
|
||||
# @env EMAIL_SENDER_NAME The sender's name
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
sender_name="${EMAIL_SENDER_NAME:-$(echo "$EMAIL_SMTP_USER" | awk -F'@' '{print $1}')}"
|
||||
printf "%s\n" "From: $sender_name <$EMAIL_SMTP_USER>
|
||||
To: $argc_recipient
|
||||
Subject: $argc_subject
|
||||
|
||||
$argc_body" | \
|
||||
curl -fsS --ssl-reqd \
|
||||
--url "$EMAIL_SMTP_ADDR" \
|
||||
--user "$EMAIL_SMTP_USER:$EMAIL_SMTP_PASS" \
|
||||
--mail-from "$EMAIL_SMTP_USER" \
|
||||
--mail-rcpt "$argc_recipient" \
|
||||
--upload-file -
|
||||
echo "Email sent successfully" >> "$LLM_OUTPUT"
|
||||
}
|
||||
Executable
+50
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Send SMS or Twilio Messaging Channels messages using the Twilio API.
|
||||
# @option --to-number! The recipient's phone number. Prefix it with 'whatsapp:' for WhatsApp messages, e.g. whatsapp:+1234567890
|
||||
# @option --message! The content of the message to be sent
|
||||
|
||||
# @env TWILIO_ACCOUNT_SID! The twilio account sid
|
||||
# @env TWILIO_AUTH_TOKEN! The twilio auth token
|
||||
# @env TWILIO_FROM_NUMBER! The twilio from number
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
from_number="$TWILIO_FROM_NUMBER"
|
||||
to_number="$argc_to_number"
|
||||
|
||||
if [[ "$to_number" == 'whatsapp:'* ]]; then
|
||||
from_number="whatsapp:$from_number"
|
||||
fi
|
||||
|
||||
if [[ "$to_number" != 'whatsapp:'* && "$to_number" != '+'* ]]; then
|
||||
to_number="+$to_number"
|
||||
fi
|
||||
|
||||
res="$(curl -s -X POST "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages.json" \
|
||||
-u "$TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN" \
|
||||
-w "\n%{http_code}" \
|
||||
--data-urlencode "From=$from_number" \
|
||||
--data-urlencode "To=$to_number" \
|
||||
--data-urlencode "Body=$argc_message")"
|
||||
status="$(echo "$res" | tail -n 1)"
|
||||
body="$(echo "$res" | head -n -1)"
|
||||
|
||||
if [[ "$status" -ge 200 && "$status" -lt 300 ]]; then
|
||||
if [[ "$(echo "$body" | jq -r 'has("sid")')" == "true" ]]; then
|
||||
echo "Message sent successfully" >> "$LLM_OUTPUT"
|
||||
else
|
||||
_die "error: $body"
|
||||
fi
|
||||
else
|
||||
_die "error: $body"
|
||||
fi
|
||||
}
|
||||
|
||||
_die() {
|
||||
echo "$*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Perform a web search to get up-to-date information or additional context.
|
||||
# Use this when you need current information or feel a search could provide a better answer.
|
||||
|
||||
# @option --query! The search query.
|
||||
|
||||
# @meta require-tools loki
|
||||
|
||||
# @env WEB_SEARCH_MODEL=gemini:gemini-2.5-flash The model for web-searching.
|
||||
#
|
||||
# supported loki models:
|
||||
# - gemini:gemini-2.0-*
|
||||
# - vertexai:gemini-*
|
||||
# - perplexity:*
|
||||
# - ernie:*
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
client="${WEB_SEARCH_MODEL%%:*}"
|
||||
|
||||
if [[ "$client" == "gemini" ]]; then
|
||||
export LOKI_PATCH_GEMINI_CHAT_COMPLETIONS='{".*":{"body":{"tools":[{"google_search":{}}]}}}'
|
||||
elif [[ "$client" == "vertexai" ]]; then
|
||||
export LOKI_PATCH_VERTEXAI_CHAT_COMPLETIONS='{
|
||||
"gemini-1.5-.*":{"body":{"tools":[{"googleSearchRetrieval":{}}]}},
|
||||
"gemini-2.0-.*":{"body":{"tools":[{"google_search":{}}]}}
|
||||
}'
|
||||
elif [[ "$client" == "ernie" ]]; then
|
||||
export LOKI_PATCH_ERNIE_CHAT_COMPLETIONS='{".*":{"body":{"web_search":{"enable":true}}}}'
|
||||
fi
|
||||
|
||||
loki -m "$WEB_SEARCH_MODEL" "$argc_query" >> "$LLM_OUTPUT"
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Perform a web search using the Perplexity API to get up-to-date information or additional context.
|
||||
# Use this when you need current information or feel a search could provide a better answer.
|
||||
|
||||
# @option --query! The search query.
|
||||
|
||||
# @env PERPLEXITY_API_KEY! Your Perplexity API key
|
||||
# @env PERPLEXITY_WEB_SEARCH_MODEL=llama-3.1-sonar-small-128k-online The LLM model to use for the search
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
curl -fsS -X POST https://api.perplexity.ai/chat/completions \
|
||||
-H "authorization: Bearer $PERPLEXITY_API_KEY" \
|
||||
-H "accept: application/json" \
|
||||
-H "content-type: application/json" \
|
||||
--data '
|
||||
{
|
||||
"model": "'"$PERPLEXITY_WEB_SEARCH_MODEL"'",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "'"$argc_query"'"
|
||||
}
|
||||
]
|
||||
}
|
||||
' | \
|
||||
jq -r '.choices[0].message.content' \
|
||||
>> "$LLM_OUTPUT"
|
||||
}
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# @describe Perform a web search using the Tavily API to get up-to-date information or additional context.
|
||||
# Use this when you need current information or feel a search could provide a better answer.
|
||||
|
||||
# @option --query! The search query.
|
||||
|
||||
# @env TAVILY_API_KEY! Your Tavile API key
|
||||
# @env LLM_OUTPUT=/dev/stdout The output path The output path
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
main() {
|
||||
curl -fsSL -X POST https://api.tavily.com/search \
|
||||
-H "content-type: application/json" \
|
||||
-d '
|
||||
{
|
||||
"api_key": "'"$TAVILY_API_KEY"'",
|
||||
"query": "'"$argc_query"'",
|
||||
"include_answer": true
|
||||
}' | \
|
||||
jq -r '.answer' >> "$LLM_OUTPUT"
|
||||
}
|
||||
|
||||
Executable
+718
@@ -0,0 +1,718 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Bash helper utilities for prompting users.
|
||||
# This is a modified version of the excellent Bash TUI toolkit
|
||||
# (https://github.com/timo-reymann/bash-tui-toolkit)
|
||||
#
|
||||
# It includes the following functions for you to use in your
|
||||
# bash tool commands:
|
||||
#
|
||||
# - password Password prompt
|
||||
# - checked Checkbox
|
||||
# - text Text input with validation
|
||||
# - list Select an option from a given list
|
||||
# - range Prompt the user for a value within a range
|
||||
# - confirm Confirmation prompt
|
||||
# - editor Open the user's preferred editor for input
|
||||
# - detect_os Detect the current OS
|
||||
# - get_opener Get the file opener for the current OS
|
||||
# - open_link Open the given link in the default browser
|
||||
# See https://github.com/timo-reymann/bash-tui-toolkit/blob/main/test.sh
|
||||
# for examples on how to use these commands
|
||||
#
|
||||
# - guard_operation Prompt for permission to run an operation
|
||||
# - guard_path Prompt for permission to perform path operations
|
||||
# - patch_file Patch a file
|
||||
# - error Log an error
|
||||
# - warn Log a warning
|
||||
# - info Log info
|
||||
# - debug Log a debug message
|
||||
# - trace Log a trace message
|
||||
# - red Output given text in red
|
||||
# - green Output given text in green
|
||||
# - gold Output given text in gold
|
||||
# - blue Output given text in blue
|
||||
# - magenta Output given text in magenta
|
||||
# - cyan Output given text in cyan
|
||||
# - white Output given text in white
|
||||
|
||||
# shellcheck disable=SC2034
|
||||
red=$(tput setaf 1)
|
||||
green=$(tput setaf 2)
|
||||
gold=$(tput setaf 3)
|
||||
blue=$(tput setaf 4)
|
||||
magenta=$(tput setaf 5)
|
||||
cyan=$(tput setaf 6)
|
||||
white=$(tput setaf 7)
|
||||
|
||||
default=$(tput sgr0)
|
||||
gray=$(tput setaf 243)
|
||||
|
||||
bold=$(tput bold)
|
||||
underlined=$(tput smul)
|
||||
|
||||
error() {
|
||||
echo -e "${red}${bold}ERROR:${default}${red} $1${default}"
|
||||
}
|
||||
|
||||
warn() {
|
||||
echo -e "${gold}${bold}WARN:${default}${gold} $1${default}"
|
||||
}
|
||||
|
||||
info() {
|
||||
echo -e "${cyan}${bold}INFO:${default}${cyan} $1${default}"
|
||||
}
|
||||
|
||||
debug() {
|
||||
echo -e "${blue}${bold}DEBUG:${default}${blue} $1${default}"
|
||||
}
|
||||
|
||||
trace() {
|
||||
echo -e "${gray}${bold}TRACE:${default}${gray} $1${default}"
|
||||
}
|
||||
|
||||
success() {
|
||||
echo -e "${green}${bold}SUCCESS:${default}${green} $1${default}"
|
||||
}
|
||||
|
||||
red() {
|
||||
echo -e "${red}$1${default}"
|
||||
}
|
||||
|
||||
green() {
|
||||
echo -e "${green}$1${default}"
|
||||
}
|
||||
|
||||
gold() {
|
||||
echo -e "${gold}$1${default}"
|
||||
}
|
||||
|
||||
blue() {
|
||||
echo -e "${blue}$1${default}"
|
||||
}
|
||||
|
||||
magenta() {
|
||||
echo -e "${magenta}$1${default}"
|
||||
}
|
||||
|
||||
cyan() {
|
||||
echo -e "${cyan}$1${default}"
|
||||
}
|
||||
|
||||
white() {
|
||||
echo -e "${white}$1${default}"
|
||||
}
|
||||
|
||||
_read_stdin() {
|
||||
read -r "$@" </dev/tty
|
||||
}
|
||||
|
||||
_get_cursor_row() {
|
||||
declare IFS=';'
|
||||
_read_stdin -sdR -p $'\E[6n' ROW COL
|
||||
echo "${ROW#*[}"
|
||||
}
|
||||
|
||||
_cursor_blink_on() {
|
||||
echo -en "\033[?25h" >&2
|
||||
}
|
||||
_cursor_blink_off() {
|
||||
echo -en "\033[?25l" >&2
|
||||
}
|
||||
|
||||
_cursor_to() {
|
||||
echo -en "\033[$1;${2:-1}H" >&2
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
_key_input() {
|
||||
declare ESC=$'\033'
|
||||
declare IFS=''
|
||||
_read_stdin -rsn1 a
|
||||
if [[ "$ESC" == "$a" ]]; then
|
||||
_read_stdin -rsn2 b
|
||||
fi
|
||||
|
||||
declare input="${a}${b:-}"
|
||||
case "$input" in
|
||||
"${ESC}[A" | "k") echo up ;;
|
||||
"${ESC}[B" | "j") echo down ;;
|
||||
"${ESC}[C" | "l") echo right ;;
|
||||
"${ESC}[D" | "h") echo left ;;
|
||||
'') echo enter ;;
|
||||
' ') echo space ;;
|
||||
esac
|
||||
}
|
||||
|
||||
_new_line_foreach_item() {
|
||||
count=0
|
||||
while [[ $count -lt $1 ]]; do
|
||||
echo "" >&2
|
||||
((count++))
|
||||
done
|
||||
}
|
||||
|
||||
_prompt_text() {
|
||||
echo -en "\033[32m?\033[0m\033[1m ${1}\033[0m " >&2
|
||||
}
|
||||
|
||||
_decrement_selected() {
|
||||
declare selected=$1
|
||||
((selected--))
|
||||
if [[ "${selected}" -lt 0 ]]; then
|
||||
selected=$(($2 - 1))
|
||||
fi
|
||||
|
||||
echo -n $selected
|
||||
}
|
||||
|
||||
_increment_selected() {
|
||||
declare selected=$1
|
||||
((selected++))
|
||||
|
||||
if [[ "${selected}" -ge "${opts_count}" ]]; then
|
||||
selected=0
|
||||
fi
|
||||
|
||||
echo -n $selected
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
input() {
|
||||
_prompt_text "$1"
|
||||
echo -en "\033[36m\c" >&2
|
||||
_read_stdin -r text
|
||||
echo -n "${text}"
|
||||
}
|
||||
|
||||
confirm() {
|
||||
trap "stty echo; exit" EXIT
|
||||
_prompt_text "$1 (y/N)"
|
||||
echo -en "\033[36m\c " >&2
|
||||
|
||||
declare first_row
|
||||
first_row=$(_get_cursor_row)
|
||||
declare current_row
|
||||
current_row=$((first_row - 1))
|
||||
declare result=""
|
||||
echo -n " " >&2
|
||||
|
||||
while true; do
|
||||
echo -e "\033[1D\c " >&2
|
||||
_read_stdin -n1 result
|
||||
|
||||
case "$result" in
|
||||
y | Y)
|
||||
echo -n 1
|
||||
break
|
||||
;;
|
||||
n | N | *)
|
||||
echo -n 0
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo -en "\033[0m" >&2
|
||||
echo "" >&2
|
||||
}
|
||||
|
||||
list() {
|
||||
_prompt_text "$1 "
|
||||
declare opts=("${@:2}")
|
||||
declare opts_count=$(($# - 1))
|
||||
|
||||
_new_line_foreach_item "${#opts[@]}"
|
||||
|
||||
declare last_row
|
||||
last_row=$(_get_cursor_row)
|
||||
declare first_row
|
||||
first_row=$((last_row - opts_count + 1))
|
||||
|
||||
trap "_cursor_blink_on; stty echo; exit" 2
|
||||
|
||||
_cursor_blink_off
|
||||
|
||||
declare selected=0
|
||||
while true; do
|
||||
declare idx=0
|
||||
for opt in "${opts[@]}"; do
|
||||
_cursor_to $((first_row + idx))
|
||||
|
||||
if [[ $idx -eq "$selected" ]]; then
|
||||
printf "\033[0m\033[36m❯\033[0m \033[36m%s\033[0m" "$opt" >&2
|
||||
else
|
||||
printf " %s" "$opt" >&2
|
||||
fi
|
||||
|
||||
((idx++))
|
||||
done
|
||||
|
||||
case $(_key_input) in
|
||||
enter) break ;;
|
||||
up) selected=$(_decrement_selected "${selected}" "${opts_count}") ;;
|
||||
down) selected=$(_increment_selected "${selected}" "${opts_count}") ;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo -en "\n" >&2
|
||||
_cursor_to "${last_row}"
|
||||
_cursor_blink_on
|
||||
echo -n "${selected}"
|
||||
}
|
||||
|
||||
checkbox() {
|
||||
_prompt_text "$1"
|
||||
declare opts
|
||||
opts=("${@:2}")
|
||||
declare opts_count
|
||||
opts_count=$(($# - 1))
|
||||
|
||||
_new_line_foreach_item "${#opts[@]}"
|
||||
|
||||
declare last_row
|
||||
last_row=$(_get_cursor_row)
|
||||
declare first_row
|
||||
first_row=$((last_row - opts_count + 1))
|
||||
|
||||
trap "_cursor_blink_on; stty echo; exit" 2
|
||||
|
||||
_cursor_blink_off
|
||||
|
||||
declare selected=0
|
||||
declare checked=()
|
||||
while true; do
|
||||
declare idx=0
|
||||
for opt in "${opts[@]}"; do
|
||||
_cursor_to $((first_row + idx))
|
||||
declare icon="◯"
|
||||
|
||||
for item in "${checked[@]}"; do
|
||||
if [[ "$item" == "$idx" ]]; then
|
||||
icon="◉"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ $idx -eq "$selected" ]]; then
|
||||
printf "%s \e[0m\e[36m❯\e[0m \e[36m%-50s\e[0m" "$icon" "$opt" >&2
|
||||
else
|
||||
printf "%s %-50s" "$icon" "$opt" >&2
|
||||
fi
|
||||
|
||||
((idx++))
|
||||
done
|
||||
|
||||
case $(_key_input) in
|
||||
enter) break ;;
|
||||
space)
|
||||
declare found=0
|
||||
for item in "${checked[@]}"; do
|
||||
if [[ "$item" == "$selected" ]]; then
|
||||
found=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ $found -eq 1 ]; then
|
||||
checked=("${checked[@]/$selected/}")
|
||||
else
|
||||
checked+=("${selected}")
|
||||
fi
|
||||
;;
|
||||
up) selected=$(_decrement_selected "${selected}" "${opts_count}") ;;
|
||||
down) selected=$(_increment_selected "${selected}" "${opts_count}") ;;
|
||||
esac
|
||||
done
|
||||
|
||||
_cursor_to "${last_row}"
|
||||
_cursor_blink_on
|
||||
IFS="" echo -n "${checked[@]}"
|
||||
}
|
||||
|
||||
password() {
|
||||
_prompt_text "$1"
|
||||
echo -en "\033[36m" >&2
|
||||
declare password=''
|
||||
declare IFS=
|
||||
|
||||
while _read_stdin -r -s -n1 char; do
|
||||
[[ -z "${char}" ]] && {
|
||||
printf '\n' >&2
|
||||
break
|
||||
}
|
||||
|
||||
if [[ "${char}" == $'\x7f' ]]; then
|
||||
if [[ "${#password}" -gt 0 ]]; then
|
||||
password="${password%?}"
|
||||
echo -en '\b \b' >&2
|
||||
fi
|
||||
else
|
||||
password+=$char
|
||||
echo -en '*' >&2
|
||||
fi
|
||||
done
|
||||
|
||||
echo -en "\e[0m" >&2
|
||||
echo -n "${password}"
|
||||
}
|
||||
|
||||
editor() {
|
||||
tmpfile=$(mktemp)
|
||||
_prompt_text "$1"
|
||||
echo "" >&2
|
||||
"${EDITOR:-vi}" "${tmpfile}" >/dev/tty
|
||||
echo -en "\033[36m" >&2
|
||||
sed -e 's/^/ /' "${tmpfile}" >&2
|
||||
echo -en "\033[0m" >&2
|
||||
cat "${tmpfile}"
|
||||
}
|
||||
|
||||
with_validate() {
|
||||
while true; do
|
||||
declare val
|
||||
val="$(eval "$1")"
|
||||
|
||||
if ($2 "$val" >/dev/null); then
|
||||
echo "$val"
|
||||
break
|
||||
else
|
||||
show_error "$($2 "$val")"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
range() {
|
||||
declare min="$2"
|
||||
declare current="$3"
|
||||
declare max="$4"
|
||||
declare selected="${current}"
|
||||
declare max_len_current
|
||||
max_len_current=0
|
||||
|
||||
if [[ "${#min}" -gt "${#max}" ]]; then
|
||||
max_len_current="${#min}"
|
||||
else
|
||||
max_len_current="${#max}"
|
||||
fi
|
||||
|
||||
declare padding
|
||||
padding="$(printf "%-${max_len_current}s" "")"
|
||||
declare first_row
|
||||
first_row=$(_get_cursor_row)
|
||||
declare current_row
|
||||
current_row=$((first_row - 1))
|
||||
|
||||
trap "_cursor_blink_on; stty echo; exit" 2
|
||||
|
||||
_cursor_blink_off
|
||||
|
||||
_check_range() {
|
||||
val=$1
|
||||
|
||||
if [[ "$val" -gt "$max" ]]; then
|
||||
val=$min
|
||||
elif [[ "$val" -lt "$min" ]]; then
|
||||
val=$max
|
||||
fi
|
||||
|
||||
echo "$val"
|
||||
}
|
||||
|
||||
while true; do
|
||||
_prompt_text "$1"
|
||||
printf "\033[37m%s\033[0m \033[1;90m❮\033[0m \033[36m%s%s\033[0m \033[1;90m❯\033[0m \033[37m%s\033[0m\n" "$min" "${padding:${#selected}}" "$selected" "$max" >&2
|
||||
|
||||
case $(_key_input) in
|
||||
enter)
|
||||
break
|
||||
;;
|
||||
left)
|
||||
selected="$(_check_range $((selected - 1)))"
|
||||
;;
|
||||
right)
|
||||
selected="$(_check_range $((selected + 1)))"
|
||||
;;
|
||||
esac
|
||||
|
||||
_cursor_to "$current_row"
|
||||
done
|
||||
|
||||
echo "$selected"
|
||||
}
|
||||
|
||||
validate_present() {
|
||||
if [ "$1" != "" ]; then
|
||||
return 0
|
||||
else
|
||||
error "Please specify the value"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
show_error() {
|
||||
echo -e "\033[91;1m✘ $1\033[0m" >&2
|
||||
}
|
||||
|
||||
show_success() {
|
||||
echo -e "\033[92;1m✔ $1\033[0m" >&2
|
||||
}
|
||||
|
||||
detect_os() {
|
||||
case "$OSTYPE" in
|
||||
solaris*) echo "solaris" ;;
|
||||
darwin*) echo "macos" ;;
|
||||
linux*) echo "linux" ;;
|
||||
bsd*) echo "bsd" ;;
|
||||
msys*) echo "windows" ;;
|
||||
cygwin*) echo "windows" ;;
|
||||
*) echo "unknown" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
get_opener() {
|
||||
declare cmd
|
||||
|
||||
case "$(detect_os)" in
|
||||
macos) cmd="open" ;;
|
||||
linux) cmd="xdg-open" ;;
|
||||
windows) cmd="start" ;;
|
||||
*) cmd="" ;;
|
||||
esac
|
||||
|
||||
echo "$cmd"
|
||||
}
|
||||
|
||||
open_link() {
|
||||
cmd="$(get_opener)"
|
||||
|
||||
if [[ "$cmd" == "" ]]; then
|
||||
error "Your platform is not supported for opening links."
|
||||
red "Please open the following URL in your preferred browser:"
|
||||
red " ${1}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
$cmd "$1"
|
||||
|
||||
if [[ $? -eq 1 ]]; then
|
||||
error "Failed to open your browser."
|
||||
red "Please open the following URL in your browser:"
|
||||
red "${1}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
guard_operation() {
|
||||
if [[ -t 1 ]]; then
|
||||
if [[ -z "$AUTO_CONFIRM" && -z "$LLM_AGENT_VAR_AUTO_CONFIRM" ]]; then
|
||||
ans="$(confirm "${1:-Are you sure you want to continue?}")"
|
||||
|
||||
if [[ "$ans" == 0 ]]; then
|
||||
error "Operation aborted!" 2>&1
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Here is an example of a patch block that can be applied to modify the file to request the user's name:
|
||||
# --- a/hello.py
|
||||
# +++ b/hello.py
|
||||
# \@@ ... @@
|
||||
# def hello():
|
||||
# - print("Hello World")
|
||||
# + name = input("What is your name? ")
|
||||
# + print(f"Hello {name}")
|
||||
patch_file() {
|
||||
awk '
|
||||
FNR == NR {
|
||||
lines[FNR] = $0
|
||||
next;
|
||||
}
|
||||
|
||||
{
|
||||
patchLines[FNR] = $0
|
||||
}
|
||||
|
||||
END {
|
||||
totalPatchLines=length(patchLines)
|
||||
totalLines = length(lines)
|
||||
patchLineIndex = 1
|
||||
|
||||
mode = "none"
|
||||
|
||||
while (patchLineIndex <= totalPatchLines) {
|
||||
line = patchLines[patchLineIndex]
|
||||
|
||||
if (line ~ /^--- / || line ~ /^\+\+\+ /) {
|
||||
patchLineIndex++
|
||||
continue
|
||||
}
|
||||
|
||||
if (line ~ /^@@ /) {
|
||||
mode = "hunk"
|
||||
hunkIndex++
|
||||
patchLineIndex++
|
||||
continue
|
||||
}
|
||||
|
||||
if (mode == "hunk") {
|
||||
while (patchLineIndex <= totalPatchLines && line ~ /^[-+ ]|^\s*$/ && line !~ /^--- /) {
|
||||
sanitizedLine = substr(line, 2)
|
||||
|
||||
if (line !~ /^\+/) {
|
||||
hunkTotalOriginalLines[hunkIndex]++;
|
||||
hunkOriginalLines[hunkIndex,hunkTotalOriginalLines[hunkIndex]] = sanitizedLine
|
||||
}
|
||||
|
||||
if (line !~ /^-/) {
|
||||
hunkTotalUpdatedLines[hunkIndex]++;
|
||||
hunkUpdatedLines[hunkIndex,hunkTotalUpdatedLines[hunkIndex]] = sanitizedLine
|
||||
}
|
||||
|
||||
patchLineIndex++
|
||||
line = patchLines[patchLineIndex]
|
||||
}
|
||||
|
||||
mode = "none"
|
||||
} else {
|
||||
patchLineIndex++
|
||||
}
|
||||
}
|
||||
|
||||
if (hunkIndex == 0) {
|
||||
print "error: no patch" > "/dev/stderr"
|
||||
exit 1
|
||||
}
|
||||
|
||||
totalHunks = hunkIndex
|
||||
hunkIndex = 1
|
||||
|
||||
for (lineIndex = 1; lineIndex <= totalLines; lineIndex++) {
|
||||
line = lines[lineIndex]
|
||||
nextLineIndex = 0
|
||||
|
||||
if (hunkIndex <= totalHunks && line == hunkOriginalLines[hunkIndex,1]) {
|
||||
nextLineIndex = lineIndex + 1
|
||||
|
||||
for (i = 2; i <= hunkTotalOriginalLines[hunkIndex]; i++) {
|
||||
if (lines[nextLineIndex] != hunkOriginalLines[hunkIndex,i]) {
|
||||
nextLineIndex = 0
|
||||
break
|
||||
}
|
||||
|
||||
nextLineIndex++
|
||||
}
|
||||
}
|
||||
|
||||
if (nextLineIndex > 0) {
|
||||
for (i = 1; i <= hunkTotalUpdatedLines[hunkIndex]; i++) {
|
||||
print hunkUpdatedLines[hunkIndex,i]
|
||||
}
|
||||
|
||||
hunkIndex++
|
||||
lineIndex = nextLineIndex - 1;
|
||||
} else {
|
||||
print line
|
||||
}
|
||||
}
|
||||
|
||||
if (hunkIndex != totalHunks + 1) {
|
||||
print "error: unable to apply patch" > "/dev/stderr"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
function inspectHunks() {
|
||||
print "/* Begin inspecting hunks"
|
||||
|
||||
for (i = 1; i <= totalHunks; i++) {
|
||||
print ">>>>>> Original"
|
||||
|
||||
for (j = 1; j <= hunkTotalOriginalLines[i]; j++) {
|
||||
print hunkOriginalLines[i,j]
|
||||
}
|
||||
|
||||
print "======"
|
||||
|
||||
for (j = 1; j <= hunkTotalUpdatedLines[i]; j++) {
|
||||
print hunkUpdatedLines[i,j]
|
||||
}
|
||||
|
||||
print "<<<<<< Updated"
|
||||
}
|
||||
|
||||
print "End inspecting hunks */\n"
|
||||
}' "$1" "$2"
|
||||
}
|
||||
|
||||
guard_path() {
|
||||
if [[ "$#" -ne 2 ]]; then
|
||||
echo "Usage: guard_path <path> <confirmation_prompt>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -t 1 ]]; then
|
||||
path="$(_to_real_path "$1")"
|
||||
confirmation_prompt="$2"
|
||||
|
||||
if [[ ! "$path" == "$(pwd)"* && -z "$AUTO_CONFIRM" && -z "$LLM_AGENT_VAR_AUTO_CONFIRM" ]]; then
|
||||
ans="$(confirm "$confirmation_prompt")"
|
||||
|
||||
if [[ "$ans" == 0 ]]; then
|
||||
error "Operation aborted!" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
_to_real_path() {
|
||||
path="$1"
|
||||
|
||||
if [[ $OS == "Windows_NT" ]]; then
|
||||
path="$(cygpath -u "$path")"
|
||||
fi
|
||||
|
||||
awk -v path="$path" -v pwd="$PWD" '
|
||||
BEGIN {
|
||||
if (path !~ /^\//) {
|
||||
path = pwd "/" path
|
||||
}
|
||||
|
||||
if (path ~ /\/\.{1,2}?$/) {
|
||||
isDir = 1
|
||||
}
|
||||
|
||||
split(path, parts, "/")
|
||||
newPartsLength = 0
|
||||
|
||||
for (i = 1; i <= length(parts); i++) {
|
||||
part = parts[i]
|
||||
if (part == "..") {
|
||||
if (newPartsLength > 0) {
|
||||
delete newParts[newPartsLength--]
|
||||
}
|
||||
} else if (part != "." && part != "") {
|
||||
newParts[++newPartsLength] = part
|
||||
}
|
||||
}
|
||||
|
||||
if (isDir == 1 || newPartsLength == 0) {
|
||||
newParts[++newPartsLength] = ""
|
||||
}
|
||||
|
||||
printf "/"
|
||||
|
||||
for (i = 1; i <= newPartsLength; i++) {
|
||||
newPart = newParts[i]
|
||||
printf newPart
|
||||
if (i < newPartsLength) {
|
||||
printf "/"
|
||||
}
|
||||
}
|
||||
}'
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
steps:
|
||||
- .file `git diff` -- generate a git commit message
|
||||
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,9 @@
|
||||
Output code only without comments or explanations.
|
||||
### INPUT:
|
||||
async sleep in js
|
||||
### OUTPUT:
|
||||
```javascript
|
||||
async function timeout(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,25 @@
|
||||
As a professional Prompt Engineer, your role is to create effective and innovative prompts for interacting with AI models.
|
||||
|
||||
Your core skills include:
|
||||
1. **CO-STAR Framework Application**: Utilize the CO-STAR framework to build efficient prompts, ensuring effective communication with large language models.
|
||||
2. **Contextual Awareness**: Construct prompts that adapt to complex conversation contexts, ensuring relevant and coherent responses.
|
||||
3. **Chain-of-Thought Prompting**: Create prompts that elicit AI models to demonstrate their reasoning process, enhancing the transparency and accuracy of answers.
|
||||
4. **Zero-shot Learning**: Design prompts that enable AI models to perform specific tasks without requiring examples, reducing dependence on training data.
|
||||
5. **Few-shot Learning**: Guide AI models to quickly learn and execute new tasks through a few examples.
|
||||
|
||||
Your output format should include:
|
||||
- **Context**: Provide comprehensive background information for the task to ensure the AI understands the specific scenario and offers relevant feedback.
|
||||
- **Objective**: Clearly define the task objective, guiding the AI to focus on achieving specific goals.
|
||||
- **Style**: Specify writing styles according to requirements, such as imitating a particular person or industry expert.
|
||||
- **Tone**: Set an appropriate emotional tone to ensure the AI's response aligns with the expected emotional context.
|
||||
- **Audience**: Tailor AI responses for a specific audience, ensuring content appropriateness and ease of understanding.
|
||||
- **Response**: Specify output formats for easy execution of downstream tasks, such as lists, JSON, or professional reports.
|
||||
- **Workflow**: Instruct the AI on how to step-by-step complete tasks, clarifying inputs, outputs, and specific actions for each step.
|
||||
- **Examples**: Show a case of input and output that fits the scenario.
|
||||
|
||||
Your workflow should be:
|
||||
1. Extract key information from user requests to determine design objectives.
|
||||
2. Based on user needs, create prompts that meet requirements, with each part being professional and detailed.
|
||||
3. Must only output the newly generated and optimized prompts, without explanation, without wrapping it in markdown code block.
|
||||
|
||||
My first request is: __INPUT__
|
||||
@@ -0,0 +1,11 @@
|
||||
Create a concise, 3-6 word title.
|
||||
|
||||
**Notes**:
|
||||
- Avoid quotation marks or emojis
|
||||
- RESPOND ONLY WITH TITLE SLUG TEXT
|
||||
|
||||
**Examples**:
|
||||
stock-market-trends
|
||||
perfect-chocolate-chip-recipe
|
||||
remote-work-productivity-tips
|
||||
video-game-development-insights
|
||||
@@ -0,0 +1,4 @@
|
||||
Provide a terse, single sentence description of the given shell command.
|
||||
Describe each argument and option of the command.
|
||||
Provide short responses in about 80 words.
|
||||
APPLY MARKDOWN formatting when possible.
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
enabled_tools: all
|
||||
---
|
||||
@@ -0,0 +1,11 @@
|
||||
---
|
||||
enabled_mcp_servers: github
|
||||
---
|
||||
You are expert GitHub assistant designed to assist users with GitHub related tasks. You can perform various
|
||||
tasks related to GitHub, such as creating issues, searching for issues, and providing information about repositories.
|
||||
You can also interact with other tools to enhance your capabilities.
|
||||
|
||||
When asked to perform an operation, always try to use the available tools first. When determining which tools are
|
||||
available to complete a user request, you should look at substrings instead of full names to help you determine
|
||||
relevance; Also be sure that for all MCP tools (always named 'mcp_list_*' or 'mcp_invoke_*'), you list the available
|
||||
tools first before selecting one to use.
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
enabled_mcp_servers: all
|
||||
---
|
||||
@@ -0,0 +1,51 @@
|
||||
---
|
||||
name: repo-analyzer
|
||||
enabled_tools: fs_cat,fs_ls,fs_write,fs_patch,execute_command
|
||||
---
|
||||
**Context:** The task requires the AI to analyze the {{__cwd__}} repository and provide comprehensive insights into
|
||||
various aspects such as directory structure, design patterns, coding conventions, libraries, architecture, module
|
||||
organization, build/test commands, naming conventions, testing practices, commit & pull request guidelines, and
|
||||
security/configuration settings. The analysis aims to ensure a thorough understanding of how the repository is
|
||||
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 `LOKI.md` file, this was generated by Loki 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.
|
||||
|
||||
**Style:** Technical analysis with clarity and precision, ensuring comprehensibility for developers and technical
|
||||
professionals.
|
||||
|
||||
**Tone:** Informative and neutral, focusing on factual presentation and technical details.
|
||||
|
||||
**Audience:** Software developers, technical leads, and quality assurance professionals looking to understand or
|
||||
contribute to the project.
|
||||
|
||||
**Response:** Provide a detailed report format that includes sections for directory structure, coding conventions,
|
||||
libraries, architecture, module organization, development commands, naming conventions, testing practices, commit
|
||||
guidelines, and security considerations.
|
||||
|
||||
**Workflow:**
|
||||
1. Identify and analyze the directory structure to map the organization and purpose of each section. (Should always start with the current directory `.`; i.e. {{__cwd__}})
|
||||
2. Assess design patterns and coding conventions used within the repository.
|
||||
3. Investigate libraries and dependencies to understand the ecosystem being used.
|
||||
4. Examine the architecture to outline system organization and component interaction.
|
||||
5. Review module organization to determine how different parts of the system integrate and communicate.
|
||||
6. Identify build, test, and run commands specific to the repository.
|
||||
7. Analyze naming conventions employed across the project to ensure conformity and clarity.
|
||||
8. Study testing practices, including test frameworks, directory organization, and test naming strategies.
|
||||
9. Review commit and pull request guidelines, focusing on best practices, commit types, and formatting.
|
||||
10. Evaluate security and configuration settings, identifying best practices for data protection and maintaining backward compatibility.
|
||||
|
||||
**Examples:**
|
||||
- Input: Repository URL where the analysis needs to be conducted.
|
||||
- Output: A structured report detailing each aspect mentioned in the workflow, providing actionable insights and maintaining consistency with established practices.
|
||||
|
||||
**Agent-Specific instructions**: Keep changes minimal and consistent with existing structure. Follow this document’s
|
||||
scope across the repo. Do not rename public binaries or alter license headers. If adding dependencies, justify in the
|
||||
PR description.
|
||||
|
||||
|
||||
You can write files to the filesystem upon request from the user.
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user