Compare commits
No commits in common. 'main' and '0.2.13' have entirely different histories.
@ -1 +0,0 @@
|
||||
vsc-dl-x64 export-ignore
|
||||
@ -1,133 +0,0 @@
|
||||
# File: CODEOWNERS
|
||||
* @Pythagora-io/maintainers
|
||||
|
||||
# File: .github/ip_assignment.yml
|
||||
assign_to_owner: true
|
||||
license: FSL-1.1-MIT
|
||||
|
||||
# File: .github/copyright_template.txt
|
||||
Copyright (c) 2024 Pythagora Technologies Inc. All rights reserved.
|
||||
This project is licensed under the terms of the FSL-1.1-MIT license.
|
||||
|
||||
# File: LICENSE
|
||||
FSL-1.1-MIT License
|
||||
|
||||
Copyright (c) 2024 Pythagora Technologies Inc.
|
||||
|
||||
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:
|
||||
|
||||
# Functional Source License, Version 1.1, MIT Future License
|
||||
|
||||
## Abbreviation
|
||||
|
||||
FSL-1.1-MIT
|
||||
|
||||
## Notice
|
||||
|
||||
Copyright 2024 Pythagora Technologies, Inc.
|
||||
|
||||
## Terms and Conditions
|
||||
|
||||
### Licensor ("We")
|
||||
|
||||
The party offering the Software under these Terms and Conditions.
|
||||
|
||||
### The Software
|
||||
|
||||
The "Software" is each version of the software that we make available under
|
||||
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
||||
Conditions with the Software.
|
||||
|
||||
### License Grant
|
||||
|
||||
Subject to your compliance with this License Grant and the Patents,
|
||||
Redistribution and Trademark clauses below, we hereby grant you the right to
|
||||
use, copy, modify, create derivative works, publicly perform, publicly display
|
||||
and redistribute the Software for any Permitted Purpose identified below.
|
||||
|
||||
### Permitted Purpose
|
||||
|
||||
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
||||
means making the Software available to others in a commercial product or
|
||||
service that:
|
||||
|
||||
1. substitutes for the Software;
|
||||
|
||||
2. substitutes for any other product or service we offer using the Software
|
||||
that exists as of the date we make the Software available; or
|
||||
|
||||
3. offers the same or substantially similar functionality as the Software.
|
||||
|
||||
Permitted Purposes specifically include using the Software:
|
||||
|
||||
1. for your internal use and access;
|
||||
|
||||
2. for non-commercial education;
|
||||
|
||||
3. for non-commercial research; and
|
||||
|
||||
4. in connection with professional services that you provide to a licensee
|
||||
using the Software in accordance with these Terms and Conditions.
|
||||
|
||||
### Patents
|
||||
|
||||
To the extent your use for a Permitted Purpose would necessarily infringe our
|
||||
patents, the license grant above includes a license under our patents. If you
|
||||
make a claim against any party that the Software infringes or contributes to
|
||||
the infringement of any patent, then your patent license to the Software ends
|
||||
immediately.
|
||||
|
||||
### Redistribution
|
||||
|
||||
The Terms and Conditions apply to all copies, modifications and derivatives of
|
||||
the Software.
|
||||
|
||||
If you redistribute any copies, modifications or derivatives of the Software,
|
||||
you must include a copy of or a link to these Terms and Conditions and not
|
||||
remove any copyright notices provided in or with the Software.
|
||||
|
||||
### Disclaimer
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
||||
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
||||
|
||||
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
||||
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
||||
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
||||
|
||||
### Trademarks
|
||||
|
||||
Except for displaying the License Details and identifying us as the origin of
|
||||
the Software, you have no right under these Terms and Conditions to use our
|
||||
trademarks, trade names, service marks or product names.
|
||||
|
||||
## Grant of Future License
|
||||
|
||||
We hereby irrevocably grant you an additional license to use the Software under
|
||||
the MIT license that is effective on the second anniversary of the date we make
|
||||
the Software available. On or after that date, you may use the Software under
|
||||
the MIT license, in which case the following will apply:
|
||||
|
||||
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 +0,0 @@
|
||||
Copyright (c) 2024 Pythagora Technologies Inc. All rights reserved.
|
||||
This project is licensed under the terms of the FSL-1.1-MIT license.
|
||||
@ -1,2 +0,0 @@
|
||||
assign_to_owner: true
|
||||
license: FSL-1.1-MIT
|
||||
@ -1,183 +0,0 @@
|
||||
name: Staging Cloud Build and Deploy
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
extension_commit_sha:
|
||||
description: "Extension commit SHA (defaults to latest commit on selected branch)"
|
||||
required: false
|
||||
type: string
|
||||
default: ""
|
||||
extension_branch:
|
||||
description: "Extension branch to use"
|
||||
required: false
|
||||
type: string
|
||||
default: "main"
|
||||
core_commit_sha:
|
||||
description: "Core commit SHA (defaults to latest commit on selected branch)"
|
||||
required: false
|
||||
type: string
|
||||
default: ""
|
||||
core_branch:
|
||||
description: "Core branch to use"
|
||||
required: false
|
||||
type: string
|
||||
default: "main"
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
get-versions:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
extension_sha: ${{ steps.get-extension-sha.outputs.extension_sha }}
|
||||
core_sha: ${{ steps.get-core-sha.outputs.core_sha }}
|
||||
combined_tag: ${{ steps.generate-tag.outputs.combined_tag }}
|
||||
|
||||
steps:
|
||||
- name: Checkout Extension
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: Pythagora-io/gpt-pilot-vs-code-extension
|
||||
token: ${{ secrets.GH_PAT }}
|
||||
path: tmp_extension
|
||||
ref: ${{ inputs.extension_commit_sha || inputs.extension_branch }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Get extension SHA
|
||||
id: get-extension-sha
|
||||
run: |
|
||||
cd tmp_extension
|
||||
SHA=$(git rev-parse HEAD)
|
||||
echo "Extension SHA: $SHA"
|
||||
echo "extension_sha=$SHA" >> $GITHUB_OUTPUT
|
||||
cd ..
|
||||
|
||||
|
||||
- name: Checkout Core
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: Pythagora-io/pythagora-v1
|
||||
token: ${{ secrets.GH_PAT }}
|
||||
path: tmp_core
|
||||
ref: ${{ inputs.core_commit_sha || inputs.core_branch }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Get core SHA
|
||||
id: get-core-sha
|
||||
run: |
|
||||
cd tmp_core
|
||||
SHA=$(git rev-parse HEAD)
|
||||
echo "Core SHA: $SHA"
|
||||
echo "core_sha=$SHA" >> $GITHUB_OUTPUT
|
||||
cd ..
|
||||
|
||||
- name: Generate combined image tag
|
||||
id: generate-tag
|
||||
run: |
|
||||
EXT_SHORT=$(echo "${{ steps.get-extension-sha.outputs.extension_sha }}" | cut -c1-7)
|
||||
CORE_SHORT=$(echo "${{ steps.get-core-sha.outputs.core_sha }}" | cut -c1-7)
|
||||
TAG="ext-${EXT_SHORT}_core-${CORE_SHORT}"
|
||||
echo "Combined tag: $TAG"
|
||||
echo "combined_tag=$TAG" >> $GITHUB_OUTPUT
|
||||
|
||||
deploy:
|
||||
needs: get-versions
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Extension
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: Pythagora-io/gpt-pilot-vs-code-extension
|
||||
token: ${{ secrets.GH_PAT }}
|
||||
path: tmp_extension
|
||||
ref: ${{ needs.get-versions.outputs.extension_sha }} # Use SHA instead of version
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Checkout Core
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: Pythagora-io/pythagora-v1
|
||||
token: ${{ secrets.GH_PAT }}
|
||||
path: tmp_core
|
||||
ref: ${{ needs.get-versions.outputs.core_sha }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.12'
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
|
||||
- name: Setup extension
|
||||
run: |
|
||||
cd tmp_extension
|
||||
npm install -g @vscode/vsce@3.3.2
|
||||
npm run build
|
||||
vsce package
|
||||
cd ..
|
||||
|
||||
- name: Configure AWS credentials
|
||||
uses: aws-actions/configure-aws-credentials@v3
|
||||
with:
|
||||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
aws-region: us-east-1
|
||||
|
||||
- name: Login to ECR
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ secrets.ECR_URL }}
|
||||
username: ${{ vars.AWS_ACCESS_KEY_ID }}
|
||||
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
|
||||
- name: Docker build and push
|
||||
run: |
|
||||
cd tmp_core
|
||||
cp ../tmp_extension/*.vsix ./pythagora-vs-code.vsix
|
||||
docker build --platform=linux/amd64 -f Dockerfile -t ${{ secrets.ECR_URL }}/pythagora/workspace:${{ needs.get-versions.outputs.combined_tag }} .
|
||||
docker push ${{ secrets.ECR_URL }}/pythagora/workspace:${{ needs.get-versions.outputs.combined_tag }}
|
||||
cd ..
|
||||
|
||||
- name: Checkout Workspace Helm
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: Pythagora-io/workspace-helm
|
||||
token: ${{ secrets.GH_PAT }}
|
||||
path: tmp_wh
|
||||
ref: 'staging'
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install yq
|
||||
run: |
|
||||
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/local/bin/yq
|
||||
chmod +x /usr/local/bin/yq
|
||||
|
||||
- name: Commit and push changes
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
cd tmp_wh
|
||||
new_value="${{ needs.get-versions.outputs.combined_tag }}"
|
||||
file_path="chart/values.yaml"
|
||||
current_value=$(yq '.workspace.image.tag' "$file_path")
|
||||
|
||||
|
||||
if [ "$current_value" = "$new_value" ]; then
|
||||
echo "No changes to commit, skipping..."
|
||||
else
|
||||
git config --global user.name "github-actions[bot]"
|
||||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
||||
yq -i ".workspace.image.tag = \"${new_value}\"" "$file_path"
|
||||
git add $file_path
|
||||
VERSION=${{ needs.get-versions.outputs.combined_tag }}
|
||||
git commit -m "version $VERSION"
|
||||
git push origin staging
|
||||
fi
|
||||
cd ..
|
||||
@ -1,9 +0,0 @@
|
||||
# (2025-08-25)
|
||||
|
||||
|
||||
### Reverts
|
||||
|
||||
* Revert "Implemented weekend discount" ([734e0c7](https://github.com/Pythagora-io/pythagora-v1/commit/734e0c726b179a45f235a0fd230a6310c77ae740))
|
||||
|
||||
|
||||
|
||||
@ -1,99 +0,0 @@
|
||||
# Use Ubuntu 22.04 as the base image with multi-arch support
|
||||
FROM ubuntu:22.04
|
||||
|
||||
# Use buildx args for multi-arch support
|
||||
ARG TARGETPLATFORM
|
||||
ARG BUILDPLATFORM
|
||||
|
||||
# Set defaults for TARGETPLATFORM to ensure it's available in scripts
|
||||
ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64}
|
||||
|
||||
# Copy VSIX file first
|
||||
COPY pythagora-vs-code.vsix /var/init_data/pythagora-vs-code.vsix
|
||||
|
||||
# Install all dependencies
|
||||
COPY cloud/setup-dependencies.sh /tmp/setup-dependencies.sh
|
||||
RUN chmod +x /tmp/setup-dependencies.sh && \
|
||||
/tmp/setup-dependencies.sh && \
|
||||
rm /tmp/setup-dependencies.sh
|
||||
|
||||
ENV PYTH_INSTALL_DIR=/pythagora
|
||||
|
||||
# Set up work directory
|
||||
WORKDIR ${PYTH_INSTALL_DIR}/pythagora-core
|
||||
|
||||
# Add Python requirements
|
||||
ADD requirements.txt .
|
||||
|
||||
# Create and activate a virtual environment, then install dependencies
|
||||
RUN python3 -m venv venv && \
|
||||
. venv/bin/activate && \
|
||||
pip install -r requirements.txt
|
||||
|
||||
# Copy application files
|
||||
ADD main.py .
|
||||
ADD core core
|
||||
ADD pyproject.toml .
|
||||
ADD cloud/config-docker.json config.json
|
||||
|
||||
# Set the virtual environment to be automatically activated
|
||||
ENV VIRTUAL_ENV=${PYTH_INSTALL_DIR}/pythagora-core/venv
|
||||
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
|
||||
|
||||
ENV PYTHAGORA_DATA_DIR=${PYTH_INSTALL_DIR}/pythagora-core/data/
|
||||
RUN mkdir -p data
|
||||
|
||||
# Expose MongoDB and application ports
|
||||
EXPOSE 27017 8000 8080 5173 3000
|
||||
|
||||
# Create a group and user
|
||||
RUN groupadd -g 1000 devusergroup && \
|
||||
useradd -m -u 1000 -g devusergroup -s /bin/bash devuser && \
|
||||
echo "devuser:devuser" | chpasswd && \
|
||||
adduser devuser sudo && \
|
||||
echo "devuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
|
||||
|
||||
# Set up entrypoint and VS Code extension
|
||||
ADD cloud/entrypoint.sh /entrypoint.sh
|
||||
ADD cloud/on-event-extension-install.sh /var/init_data/on-event-extension-install.sh
|
||||
ADD cloud/favicon.svg /favicon.svg
|
||||
ADD cloud/favicon.ico /favicon.ico
|
||||
|
||||
# Create necessary directories with proper permissions for code-server
|
||||
RUN mkdir -p /usr/local/share/code-server/data/User/globalStorage && \
|
||||
mkdir -p /usr/local/share/code-server/data/User/History && \
|
||||
mkdir -p /usr/local/share/code-server/data/Machine && \
|
||||
mkdir -p /usr/local/share/code-server/data/logs
|
||||
|
||||
# Add code server settings.json
|
||||
ADD cloud/settings.json /usr/local/share/code-server/data/Machine/settings.json
|
||||
|
||||
RUN chown -R devuser:devusergroup /usr/local/share/code-server && \
|
||||
chmod -R 755 /usr/local/share/code-server && \
|
||||
# Copy icons
|
||||
cp -f /favicon.ico /usr/local/lib/code-server/src/browser/media/favicon.ico && \
|
||||
cp -f /favicon.svg /usr/local/lib/code-server/src/browser/media/favicon-dark-support.svg && \
|
||||
cp -f /favicon.svg /usr/local/lib/code-server/src/browser/media/favicon.svg
|
||||
|
||||
# Configure PostHog analytics integration
|
||||
RUN sed -i "s|'sha256-/r7rqQ+yrxt57sxLuQ6AMYcy/lUpvAIzHjIJt/OeLWU=' ;|'sha256-/r7rqQ+yrxt57sxLuQ6AMYcy/lUpvAIzHjIJt/OeLWU=' https://us-assets.i.posthog.com ;|g" /usr/local/lib/code-server/lib/vscode/out/server-main.js
|
||||
|
||||
COPY cloud/posthog.html /tmp/posthog.html
|
||||
RUN sed -i '/<head>/r /tmp/posthog.html' /usr/local/lib/code-server/lib/vscode/out/vs/code/browser/workbench/workbench.html && \
|
||||
rm /tmp/posthog.html
|
||||
|
||||
RUN chmod +x /entrypoint.sh && \
|
||||
chmod +x /var/init_data/on-event-extension-install.sh && \
|
||||
chown -R devuser:devusergroup /pythagora && \
|
||||
chown -R devuser: /var/init_data/
|
||||
|
||||
# Create workspace directory
|
||||
RUN mkdir -p ${PYTH_INSTALL_DIR}/pythagora-core/workspace && \
|
||||
chown -R devuser:devusergroup ${PYTH_INSTALL_DIR}/pythagora-core/workspace
|
||||
|
||||
# Set up git config
|
||||
RUN su -c "git config --global user.email 'devuser@pythagora.ai'" devuser && \
|
||||
su -c "git config --global user.name 'pythagora'" devuser
|
||||
|
||||
# Remove the USER directive to keep root as the running user
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
@ -1,154 +0,0 @@
|
||||
{
|
||||
"llm": {
|
||||
"openai": {
|
||||
"base_url": null,
|
||||
"api_key": null,
|
||||
"connect_timeout": 60.0,
|
||||
"read_timeout": 60.0,
|
||||
"extra": null
|
||||
},
|
||||
"anthropic": {
|
||||
"base_url": null,
|
||||
"api_key": null,
|
||||
"connect_timeout": 60.0,
|
||||
"read_timeout": 60.0,
|
||||
"extra": null
|
||||
},
|
||||
"relace": {
|
||||
"base_url": null,
|
||||
"api_key": null,
|
||||
"connect_timeout": 60.0,
|
||||
"read_timeout": 60.0,
|
||||
"extra": null
|
||||
}
|
||||
},
|
||||
"agent": {
|
||||
"default": {
|
||||
"provider": "openai",
|
||||
"model": "gpt-4o-2024-05-13",
|
||||
"temperature": 0.5
|
||||
},
|
||||
"BugHunter.check_logs": {
|
||||
"provider": "openai",
|
||||
"model": "claude-sonnet-4-20250514",
|
||||
"temperature": 0.5
|
||||
},
|
||||
"CodeMonkey": {
|
||||
"provider": "openai",
|
||||
"model": "claude-sonnet-4-20250514",
|
||||
"temperature": 0.0
|
||||
},
|
||||
"CodeMonkey.code_review": {
|
||||
"provider": "openai",
|
||||
"model": "claude-3-5-sonnet-20240620",
|
||||
"temperature": 0.0
|
||||
},
|
||||
"CodeMonkey.implement_changes": {
|
||||
"provider": "relace",
|
||||
"model": "relace-code-merge",
|
||||
"temperature": 0.0
|
||||
},
|
||||
"CodeMonkey.describe_files": {
|
||||
"provider": "openai",
|
||||
"model": "gpt-4o-mini-2024-07-18",
|
||||
"temperature": 0.0
|
||||
},
|
||||
"Frontend": {
|
||||
"provider": "openai",
|
||||
"model": "claude-sonnet-4-20250514",
|
||||
"temperature": 0.0
|
||||
},
|
||||
"get_relevant_files": {
|
||||
"provider": "openai",
|
||||
"model": "gpt-4o-2024-05-13",
|
||||
"temperature": 0.5
|
||||
},
|
||||
"Developer.parse_task": {
|
||||
"provider": "openai",
|
||||
"model": "claude-3-5-sonnet-20241022",
|
||||
"temperature": 0.0
|
||||
},
|
||||
"SpecWriter": {
|
||||
"provider": "openai",
|
||||
"model": "claude-sonnet-4-20250514",
|
||||
"temperature": 0.0
|
||||
},
|
||||
"Developer.breakdown_current_task": {
|
||||
"provider": "openai",
|
||||
"model": "claude-sonnet-4-20250514",
|
||||
"temperature": 0.5
|
||||
},
|
||||
"TechLead.plan_epic": {
|
||||
"provider": "openai",
|
||||
"model": "claude-3-5-sonnet-20240620",
|
||||
"temperature": 0.5
|
||||
},
|
||||
"TechLead.epic_breakdown": {
|
||||
"provider": "openai",
|
||||
"model": "claude-3-5-sonnet-20241022",
|
||||
"temperature": 0.5
|
||||
},
|
||||
"Troubleshooter.generate_bug_report": {
|
||||
"provider": "openai",
|
||||
"model": "claude-sonnet-4-20250514",
|
||||
"temperature": 0.5
|
||||
},
|
||||
"Troubleshooter.get_run_command": {
|
||||
"provider": "openai",
|
||||
"model": "claude-sonnet-4-20250514",
|
||||
"temperature": 0.0
|
||||
},
|
||||
"Troubleshooter.define_user_review_goal": {
|
||||
"provider": "anthropic",
|
||||
"model": "claude-sonnet-4-20250514",
|
||||
"temperature": 0.0
|
||||
}
|
||||
},
|
||||
"prompt": {
|
||||
"paths": [
|
||||
"/pythagora/pythagora-core/core/prompts"
|
||||
]
|
||||
},
|
||||
"log": {
|
||||
"level": "DEBUG",
|
||||
"format": "%(asctime)s %(levelname)s [%(name)s] %(message)s",
|
||||
"output": "data/pythagora.log"
|
||||
},
|
||||
"db": {
|
||||
"url": "sqlite+aiosqlite:///data/database/pythagora.db",
|
||||
"debug_sql": false,
|
||||
"save_llm_requests": false
|
||||
},
|
||||
"ui": {
|
||||
"type": "plain"
|
||||
},
|
||||
"fs": {
|
||||
"type": "local",
|
||||
"workspace_root": "/pythagora/pythagora-core/workspace",
|
||||
"ignore_paths": [
|
||||
".git",
|
||||
".gpt-pilot",
|
||||
".idea",
|
||||
".vscode",
|
||||
".next",
|
||||
".DS_Store",
|
||||
"__pycache__",
|
||||
"site-packages",
|
||||
"node_modules",
|
||||
"package-lock.json",
|
||||
"venv",
|
||||
".venv",
|
||||
"dist",
|
||||
"build",
|
||||
"target",
|
||||
"*.min.js",
|
||||
"*.min.css",
|
||||
"*.svg",
|
||||
"*.csv",
|
||||
"*.log",
|
||||
"go.sum",
|
||||
"migration_lock.toml"
|
||||
],
|
||||
"ignore_size_threshold": 50000
|
||||
}
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
# Production instances are slow with date command and stderr
|
||||
# export PS4='+ $(date "+%Y-%m-%d %H:%M:%S") '
|
||||
# set -x
|
||||
|
||||
echo "TASK: Entrypoint script started"
|
||||
# export MONGO_DB_DATA=$PYTHAGORA_DATA_DIR/mongodata
|
||||
# mkdir -p $MONGO_DB_DATA
|
||||
|
||||
# # Start MongoDB in the background
|
||||
# mongod --dbpath "$MONGO_DB_DATA" --bind_ip_all >> $MONGO_DB_DATA/mongo_logs.txt 2>&1 &
|
||||
|
||||
# # Loop until MongoDB is running (use pgrep for speed)
|
||||
# for ((i=0; i<10*5; i++)); do
|
||||
# if pgrep -x mongod > /dev/null; then
|
||||
# echo "TASK: MongoDB started"
|
||||
# break
|
||||
# fi
|
||||
# sleep 0.2
|
||||
# done
|
||||
|
||||
export DB_DIR=$PYTHAGORA_DATA_DIR/database
|
||||
|
||||
chown -R devuser: $PYTHAGORA_DATA_DIR
|
||||
su -c "mkdir -p $DB_DIR" devuser
|
||||
|
||||
# Start the VS Code extension installer/HTTP server script in the background
|
||||
su -c "cd /var/init_data/ && ./on-event-extension-install.sh" devuser
|
||||
|
||||
# Keep container running
|
||||
echo "FINISH: Entrypoint script finished"
|
||||
tail -f /dev/null
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 15 KiB |
@ -1,4 +0,0 @@
|
||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="16" height="16" rx="3.2" fill="#FFD11A"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M7.28507 4.11352C7.07726 4.26999 6.89667 4.60639 6.53548 5.2792L4.16469 9.69538C3.83841 10.3032 3.67527 10.6071 3.65596 10.853C3.61663 11.3538 3.90083 11.8245 4.3641 12.0258C4.59154 12.1246 4.93817 12.1246 5.63143 12.1246H10.373C11.0663 12.1246 11.4129 12.1246 11.6403 12.0258C12.1036 11.8245 12.3878 11.3538 12.3485 10.853C12.3292 10.6071 12.166 10.3032 11.8397 9.69539L9.46896 5.2792C9.10777 4.60639 8.92717 4.26999 8.71936 4.11352C8.29527 3.79419 7.70916 3.79419 7.28507 4.11352ZM7.93448 5.73598C7.78885 5.77551 7.68713 5.9659 7.48369 6.34668L5.40726 10.2332C5.23246 10.5604 5.46491 10.956 5.83758 10.9657C6.4244 10.9808 10.6231 10.3035 9.83641 8.79224L8.56635 6.35243C8.36702 5.96951 8.26736 5.77806 8.12215 5.73698C8.06086 5.71964 7.99596 5.71929 7.93448 5.73598Z" fill="#060218"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 994 B |
@ -1,25 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
VSCODE_SERVER_PORT=8080
|
||||
|
||||
# Create workspace directory and settings
|
||||
mkdir -p /pythagora/pythagora-core/workspace/.vscode
|
||||
printf '{\n "gptPilot.isRemoteWs": true,\n "gptPilot.useRemoteWs": false,\n "workbench.colorTheme": "Default Dark+",\n "remote.autoForwardPorts": false\n}' > /pythagora/pythagora-core/workspace/.vscode/settings.json
|
||||
|
||||
# Start code-server and direct to our workspace
|
||||
echo "Starting code-server..."
|
||||
code-server --disable-proxy --disable-workspace-trust --config /etc/code-server/config.yaml /pythagora/pythagora-core/workspace &
|
||||
CODE_SERVER_PID=$!
|
||||
echo $CODE_SERVER_PID > /tmp/vscode-http-server.pid
|
||||
|
||||
# Wait for code-server to open the port (e.g., 8080)
|
||||
for ((i=0; i<15*2; i++)); do
|
||||
if curl -s "http://localhost:$VSCODE_SERVER_PORT/healthz" > /dev/null; then
|
||||
echo "TASK: VS Code server started"
|
||||
echo "VS Code HTTP server started with PID $CODE_SERVER_PID. Access at http://localhost:$VSCODE_SERVER_PORT"
|
||||
break
|
||||
fi
|
||||
sleep 0.5
|
||||
done
|
||||
@ -1,8 +0,0 @@
|
||||
<script>
|
||||
!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.crossOrigin="anonymous",p.async=!0,p.src=s.api_host.replace(".i.posthog.com","-assets.i.posthog.com")+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="init Re Os As Pe Ms Fs capture Ve calculateEventProperties js register register_once register_for_session unregister unregister_for_session qs getFeatureFlag getFeatureFlagPayload isFeatureEnabled reloadFeatureFlags updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures on onFeatureFlags onSurveysLoaded onSessionId getSurveys getActiveMatchingSurveys renderSurvey canRenderSurvey canRenderSurveyAsync identify setPersonProperties group resetGroups setPersonPropertiesForFlags resetPersonPropertiesForFlags setGroupPropertiesForFlags resetGroupPropertiesForFlags reset get_distinct_id getGroups get_session_id get_session_replay_url alias set_config startSessionRecording stopSessionRecording sessionRecordingStarted captureException loadToolbar get_property getSessionProperty zs Ls createPersonProfile Us Rs Bs opt_in_capturing opt_out_capturing has_opted_in_capturing has_opted_out_capturing clear_opt_in_out_capturing Ds debug I Ns getPageViewId captureTraceFeedback captureTraceMetric".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
|
||||
posthog.init('phc_CPMrohXQJiasSs2PCwK3SItm1mUT6F69dcLo1TMZOz8', {
|
||||
api_host: 'https://us.i.posthog.com',
|
||||
defaults: '2025-05-24',
|
||||
person_profiles: 'identified_only',
|
||||
})
|
||||
</script>
|
||||
@ -1,27 +0,0 @@
|
||||
{
|
||||
"workbench.startupEditor": "none",
|
||||
"workbench.statusBar.visible": false,
|
||||
"workbench.editor.showTabs": "none",
|
||||
"chat.commandCenter.enabled": false,
|
||||
"window.commandCenter": false,
|
||||
"workbench.colorCustomizations": {
|
||||
"commandCenter.background": "#0B0912",
|
||||
"activityBar.foreground": "#F7F8F8",
|
||||
"activityBar.background": "#0B0912",
|
||||
"commandCenter.foreground": "#F7F8F8",
|
||||
"commandCenter.activeBackground": "#0B0912",
|
||||
"titleBar.activeBackground": "#0B0912",
|
||||
"titleBar.inactiveBackground": "#0B0912",
|
||||
"sideBarSectionHeader.background": "#0B0912",
|
||||
"sideBarSectionHeader.foreground": "#F7F8F8",
|
||||
"editorGroupHeader.tabsBackground": "#0B0912",
|
||||
"tab.activeBackground": "#0B0912",
|
||||
"tab.inactiveBackground": "#0B0912",
|
||||
"tab.activeForeground": "#F7F8F8",
|
||||
"tab.inactiveForeground": "#F7F8F8",
|
||||
"editorGroup.emptyBackground": "#0B0912",
|
||||
"editor.background": "#0B0912",
|
||||
"sideBar.background": "#0B0912",
|
||||
"editorGroup.border": "#0B0912"
|
||||
}
|
||||
}
|
||||
@ -1,137 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Set environment variables
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
export TZ=Etc/UTC
|
||||
|
||||
# IMPORTANT: Create a dummy update-ca-certificates script that does nothing
|
||||
# This completely bypasses the problematic ca-certificates update process
|
||||
echo "Creating dummy update-ca-certificates script"
|
||||
if [ -f /usr/sbin/update-ca-certificates ]; then
|
||||
mv /usr/sbin/update-ca-certificates /usr/sbin/update-ca-certificates.orig
|
||||
fi
|
||||
cat > /usr/sbin/update-ca-certificates << 'EOF'
|
||||
#!/bin/sh
|
||||
echo "Dummy update-ca-certificates called, doing nothing"
|
||||
exit 0
|
||||
EOF
|
||||
chmod +x /usr/sbin/update-ca-certificates
|
||||
|
||||
# Update package list and install prerequisites
|
||||
echo "Installing basic packages"
|
||||
apt-get update && apt-get install -y --no-install-recommends \
|
||||
software-properties-common \
|
||||
build-essential \
|
||||
curl \
|
||||
git \
|
||||
gnupg \
|
||||
tzdata \
|
||||
inotify-tools \
|
||||
vim \
|
||||
nano \
|
||||
lsof \
|
||||
procps \
|
||||
ca-certificates
|
||||
echo "Basic packages installed successfully"
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install Python 3.12
|
||||
echo "Adding Python 3.12 PPA"
|
||||
add-apt-repository ppa:deadsnakes/ppa -y && apt-get update
|
||||
echo "Installing Python 3.12"
|
||||
apt-get install -y --no-install-recommends \
|
||||
python3.12 \
|
||||
python3.12-venv \
|
||||
python3.12-dev \
|
||||
python3-pip
|
||||
echo "Python 3.12 installed successfully"
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Set Python 3.12 as default
|
||||
echo "Setting Python 3.12 as default"
|
||||
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1
|
||||
update-alternatives --install /usr/bin/python python /usr/bin/python3 1
|
||||
python --version
|
||||
|
||||
# Install Node.js
|
||||
echo "Installing Node.js"
|
||||
curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
|
||||
apt-get install -y nodejs
|
||||
node --version && npm --version
|
||||
|
||||
# Install MongoDB based on platform architecture
|
||||
echo "Installing MongoDB"
|
||||
case "$TARGETPLATFORM" in
|
||||
"linux/amd64")
|
||||
MONGO_ARCH="amd64"
|
||||
;;
|
||||
"linux/arm64"|"linux/arm64/v8")
|
||||
MONGO_ARCH="arm64"
|
||||
;;
|
||||
*)
|
||||
echo "Using default architecture amd64 for MongoDB"
|
||||
MONGO_ARCH="amd64"
|
||||
;;
|
||||
esac
|
||||
|
||||
curl -fsSL https://www.mongodb.org/static/pgp/server-6.0.asc | gpg --dearmor -o /usr/share/keyrings/mongodb-archive-keyring.gpg
|
||||
echo "deb [arch=$MONGO_ARCH signed-by=/usr/share/keyrings/mongodb-archive-keyring.gpg] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-6.0.list
|
||||
apt-get update && apt-get install -y mongodb-org
|
||||
echo "MongoDB installed successfully"
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install code-server
|
||||
echo "Installing code-server"
|
||||
VERSION="4.97.2"
|
||||
case "$TARGETPLATFORM" in
|
||||
"linux/amd64")
|
||||
PLATFORM="amd64"
|
||||
;;
|
||||
"linux/arm64"|"linux/arm64/v8")
|
||||
PLATFORM="arm64"
|
||||
;;
|
||||
*)
|
||||
echo "Using default platform amd64 for code-server"
|
||||
PLATFORM="amd64"
|
||||
;;
|
||||
esac
|
||||
|
||||
DOWNLOAD_URL="https://github.com/coder/code-server/releases/download/v${VERSION}/code-server-${VERSION}-linux-${PLATFORM}.tar.gz"
|
||||
echo "Downloading code-server from $DOWNLOAD_URL"
|
||||
curl -L "$DOWNLOAD_URL" -o /tmp/code-server.tar.gz
|
||||
|
||||
# Create directories and install
|
||||
mkdir -p /usr/local/lib/code-server
|
||||
mkdir -p /usr/local/bin
|
||||
mkdir -p /usr/local/share/code-server/extensions
|
||||
mkdir -p /usr/local/share/code-server/data
|
||||
mkdir -p /etc/code-server
|
||||
|
||||
# Install code-server
|
||||
tar -xzf /tmp/code-server.tar.gz -C /usr/local/lib/code-server --strip-components=1
|
||||
ln -s /usr/local/lib/code-server/bin/code-server /usr/local/bin/code-server
|
||||
rm /tmp/code-server.tar.gz
|
||||
echo "code-server installed successfully"
|
||||
|
||||
# Create default config
|
||||
cat > /etc/code-server/config.yaml << EOF
|
||||
bind-addr: 0.0.0.0:8080
|
||||
auth: none
|
||||
extensions-dir: /usr/local/share/code-server/extensions
|
||||
user-data-dir: /usr/local/share/code-server/data
|
||||
EOF
|
||||
|
||||
# Pre-install extension
|
||||
echo "Installing VS Code extension..."
|
||||
code-server --config /etc/code-server/config.yaml --install-extension /var/init_data/pythagora-vs-code.vsix || {
|
||||
echo "Extension installation failed but continuing build process..."
|
||||
}
|
||||
|
||||
# Restore original update-ca-certificates if it exists
|
||||
if [ -f /usr/sbin/update-ca-certificates.orig ]; then
|
||||
mv /usr/sbin/update-ca-certificates.orig /usr/sbin/update-ca-certificates
|
||||
echo "Restored original update-ca-certificates"
|
||||
fi
|
||||
|
||||
echo "Setup completed successfully"
|
||||
@ -0,0 +1,326 @@
|
||||
import re
|
||||
from difflib import unified_diff
|
||||
from enum import Enum
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from core.agents.base import BaseAgent
|
||||
from core.agents.convo import AgentConvo
|
||||
from core.agents.response import AgentResponse
|
||||
from core.llm.parser import JSONParser
|
||||
from core.log import get_logger
|
||||
|
||||
log = get_logger(__name__)
|
||||
|
||||
|
||||
# Constant for indicating missing new line at the end of a file in a unified diff
|
||||
NO_EOL = "\\ No newline at end of file"
|
||||
|
||||
# Regular expression pattern for matching hunk headers
|
||||
PATCH_HEADER_PATTERN = re.compile(r"^@@ -(\d+),?(\d+)? \+(\d+),?(\d+)? @@")
|
||||
|
||||
# Maximum number of attempts to ask for review if it can't be parsed
|
||||
MAX_REVIEW_RETRIES = 2
|
||||
|
||||
# Maximum number of code implementation attempts after which we accept the changes unconditionaly
|
||||
MAX_CODING_ATTEMPTS = 3
|
||||
|
||||
|
||||
class Decision(str, Enum):
|
||||
APPLY = "apply"
|
||||
IGNORE = "ignore"
|
||||
REWORK = "rework"
|
||||
|
||||
|
||||
class Hunk(BaseModel):
|
||||
number: int = Field(description="Index of the hunk in the diff. Starts from 1.")
|
||||
reason: str = Field(description="Reason for applying or ignoring this hunk, or for asking for it to be reworked.")
|
||||
decision: Decision = Field(description="Whether to apply this hunk, rework, or ignore it.")
|
||||
|
||||
|
||||
class ReviewChanges(BaseModel):
|
||||
hunks: list[Hunk]
|
||||
review_notes: str = Field(description="Additional review notes (optional, can be empty).")
|
||||
|
||||
|
||||
class CodeReviewer(BaseAgent):
|
||||
agent_type = "code-reviewer"
|
||||
display_name = "Code Reviewer"
|
||||
|
||||
async def run(self) -> AgentResponse:
|
||||
if (
|
||||
not self.prev_response.data["old_content"]
|
||||
or self.prev_response.data["new_content"] == self.prev_response.data["old_content"]
|
||||
or self.prev_response.data["attempt"] >= MAX_CODING_ATTEMPTS
|
||||
):
|
||||
# we always auto-accept new files and unchanged files, or if we've tried too many times
|
||||
return await self.accept_changes(self.prev_response.data["path"], self.prev_response.data["new_content"])
|
||||
|
||||
approved_content, feedback = await self.review_change(
|
||||
self.prev_response.data["path"],
|
||||
self.prev_response.data["instructions"],
|
||||
self.prev_response.data["old_content"],
|
||||
self.prev_response.data["new_content"],
|
||||
)
|
||||
if feedback:
|
||||
return AgentResponse.code_review_feedback(
|
||||
self,
|
||||
new_content=self.prev_response.data["new_content"],
|
||||
approved_content=approved_content,
|
||||
feedback=feedback,
|
||||
attempt=self.prev_response.data["attempt"],
|
||||
)
|
||||
else:
|
||||
return await self.accept_changes(self.prev_response.data["path"], approved_content)
|
||||
|
||||
async def accept_changes(self, path: str, content: str) -> AgentResponse:
|
||||
await self.state_manager.save_file(path, content)
|
||||
self.next_state.complete_step()
|
||||
|
||||
input_required = self.state_manager.get_input_required(content)
|
||||
if input_required:
|
||||
return AgentResponse.input_required(
|
||||
self,
|
||||
[{"file": path, "line": line} for line in input_required],
|
||||
)
|
||||
else:
|
||||
return AgentResponse.done(self)
|
||||
|
||||
def _get_task_convo(self) -> AgentConvo:
|
||||
# FIXME: Current prompts reuse conversation from the developer so we have to resort to this
|
||||
task = self.current_state.current_task
|
||||
current_task_index = self.current_state.tasks.index(task)
|
||||
|
||||
convo = AgentConvo(self).template(
|
||||
"breakdown",
|
||||
task=task,
|
||||
iteration=None,
|
||||
current_task_index=current_task_index,
|
||||
)
|
||||
# TODO: We currently show last iteration to the code monkey; we might need to show the task
|
||||
# breakdown and all the iterations instead? To think about when refactoring prompts
|
||||
if self.current_state.iterations:
|
||||
convo.assistant(self.current_state.iterations[-1]["description"])
|
||||
else:
|
||||
convo.assistant(self.current_state.current_task["instructions"])
|
||||
return convo
|
||||
|
||||
async def review_change(
|
||||
self, file_name: str, instructions: str, old_content: str, new_content: str
|
||||
) -> tuple[str, str]:
|
||||
"""
|
||||
Review changes that were applied to the file.
|
||||
|
||||
This asks the LLM to act as a PR reviewer and for each part (hunk) of the
|
||||
diff, decide if it should be applied (kept) or ignored (removed from the PR).
|
||||
|
||||
:param file_name: name of the file being modified
|
||||
:param instructions: instructions for the reviewer
|
||||
:param old_content: old file content
|
||||
:param new_content: new file content (with proposed changes)
|
||||
:return: tuple with file content update with approved changes, and review feedback
|
||||
|
||||
Diff hunk explanation: https://www.gnu.org/software/diffutils/manual/html_node/Hunks.html
|
||||
"""
|
||||
|
||||
hunks = self.get_diff_hunks(file_name, old_content, new_content)
|
||||
|
||||
llm = self.get_llm()
|
||||
convo = (
|
||||
self._get_task_convo()
|
||||
.template(
|
||||
"review_changes",
|
||||
instructions=instructions,
|
||||
file_name=file_name,
|
||||
old_content=old_content,
|
||||
hunks=hunks,
|
||||
)
|
||||
.require_schema(ReviewChanges)
|
||||
)
|
||||
llm_response: ReviewChanges = await llm(convo, temperature=0, parser=JSONParser(ReviewChanges))
|
||||
|
||||
for i in range(MAX_REVIEW_RETRIES):
|
||||
reasons = {}
|
||||
ids_to_apply = set()
|
||||
ids_to_ignore = set()
|
||||
ids_to_rework = set()
|
||||
for hunk in llm_response.hunks:
|
||||
reasons[hunk.number - 1] = hunk.reason
|
||||
if hunk.decision == "apply":
|
||||
ids_to_apply.add(hunk.number - 1)
|
||||
elif hunk.decision == "ignore":
|
||||
ids_to_ignore.add(hunk.number - 1)
|
||||
elif hunk.decision == "rework":
|
||||
ids_to_rework.add(hunk.number - 1)
|
||||
|
||||
n_hunks = len(hunks)
|
||||
n_review_hunks = len(reasons)
|
||||
if n_review_hunks == n_hunks:
|
||||
break
|
||||
elif n_review_hunks < n_hunks:
|
||||
error = "Not all hunks have been reviewed. Please review all hunks and add 'apply', 'ignore' or 'rework' decision for each."
|
||||
elif n_review_hunks > n_hunks:
|
||||
error = f"Your review contains more hunks ({n_review_hunks}) than in the original diff ({n_hunks}). Note that one hunk may have multiple changed lines."
|
||||
|
||||
# Max two retries; if the reviewer still hasn't reviewed all hunks, we'll just use the entire new content
|
||||
convo.assistant(llm_response.model_dump_json()).user(error)
|
||||
llm_response = await llm(convo, parser=JSONParser(ReviewChanges))
|
||||
else:
|
||||
return new_content, None
|
||||
|
||||
hunks_to_apply = [h for i, h in enumerate(hunks) if i in ids_to_apply]
|
||||
diff_log = f"--- {file_name}\n+++ {file_name}\n" + "\n".join(hunks_to_apply)
|
||||
|
||||
hunks_to_rework = [(i, h) for i, h in enumerate(hunks) if i in ids_to_rework]
|
||||
review_log = (
|
||||
"\n\n".join([f"## Change\n```{hunk}```\nReviewer feedback:\n{reasons[i]}" for (i, hunk) in hunks_to_rework])
|
||||
+ "\n\nReview notes:\n"
|
||||
+ llm_response.review_notes
|
||||
)
|
||||
|
||||
if len(hunks_to_apply) == len(hunks):
|
||||
await self.send_message("Applying entire change")
|
||||
log.info(f"Applying entire change to {file_name}")
|
||||
return new_content, None
|
||||
|
||||
elif len(hunks_to_apply) == 0:
|
||||
if hunks_to_rework:
|
||||
await self.send_message(
|
||||
f"Requesting rework for {len(hunks_to_rework)} changes with reason: {llm_response.review_notes}"
|
||||
)
|
||||
log.info(f"Requesting rework for {len(hunks_to_rework)} changes to {file_name} (0 hunks to apply)")
|
||||
return old_content, review_log
|
||||
else:
|
||||
# If everything can be safely ignored, it's probably because the files already implement the changes
|
||||
# from previous tasks (which can happen often). Insisting on a change here is likely to cause problems.
|
||||
await self.send_message(f"Rejecting entire change with reason: {llm_response.review_notes}")
|
||||
log.info(f"Rejecting entire change to {file_name} with reason: {llm_response.review_notes}")
|
||||
return old_content, None
|
||||
|
||||
log.debug(f"Applying code change to {file_name}:\n{diff_log}")
|
||||
new_content = self.apply_diff(file_name, old_content, hunks_to_apply, new_content)
|
||||
if hunks_to_rework:
|
||||
log.info(f"Requesting further rework for {len(hunks_to_rework)} changes to {file_name}")
|
||||
return new_content, review_log
|
||||
else:
|
||||
return new_content, None
|
||||
|
||||
@staticmethod
|
||||
def get_diff_hunks(file_name: str, old_content: str, new_content: str) -> list[str]:
|
||||
"""
|
||||
Get the diff between two files.
|
||||
|
||||
This uses Python difflib to produce an unified diff, then splits
|
||||
it into hunks that will be separately reviewed by the reviewer.
|
||||
|
||||
:param file_name: name of the file being modified
|
||||
:param old_content: old file content
|
||||
:param new_content: new file content
|
||||
:return: change hunks from the unified diff
|
||||
"""
|
||||
from_name = "old_" + file_name
|
||||
to_name = "to_" + file_name
|
||||
from_lines = old_content.splitlines(keepends=True)
|
||||
to_lines = new_content.splitlines(keepends=True)
|
||||
diff_gen = unified_diff(from_lines, to_lines, fromfile=from_name, tofile=to_name)
|
||||
diff_txt = "".join(diff_gen)
|
||||
|
||||
hunks = re.split(r"\n@@", diff_txt, re.MULTILINE)
|
||||
result = []
|
||||
for i, h in enumerate(hunks):
|
||||
# Skip the prologue (file names)
|
||||
if i == 0:
|
||||
continue
|
||||
txt = h.splitlines()
|
||||
txt[0] = "@@" + txt[0]
|
||||
result.append("\n".join(txt))
|
||||
return result
|
||||
|
||||
def apply_diff(self, file_name: str, old_content: str, hunks: list[str], fallback: str):
|
||||
"""
|
||||
Apply the diff to the original file content.
|
||||
|
||||
This uses the internal `_apply_patch` method to apply the
|
||||
approved diff hunks to the original file content.
|
||||
|
||||
If patch apply fails, the fallback is the full new file content
|
||||
with all the changes applied (as if the reviewer approved everythng).
|
||||
|
||||
:param file_name: name of the file being modified
|
||||
:param old_content: old file content
|
||||
:param hunks: change hunks from the unified diff
|
||||
:param fallback: proposed new file content (with all the changes applied)
|
||||
"""
|
||||
diff = (
|
||||
"\n".join(
|
||||
[
|
||||
f"--- {file_name}",
|
||||
f"+++ {file_name}",
|
||||
]
|
||||
+ hunks
|
||||
)
|
||||
+ "\n"
|
||||
)
|
||||
try:
|
||||
fixed_content = self._apply_patch(old_content, diff)
|
||||
except Exception as e:
|
||||
# This should never happen but if it does, just use the new version from
|
||||
# the LLM and hope for the best
|
||||
print(f"Error applying diff: {e}; hoping all changes are valid")
|
||||
return fallback
|
||||
|
||||
return fixed_content
|
||||
|
||||
# Adapted from https://gist.github.com/noporpoise/16e731849eb1231e86d78f9dfeca3abc (Public Domain)
|
||||
@staticmethod
|
||||
def _apply_patch(original: str, patch: str, revert: bool = False):
|
||||
"""
|
||||
Apply a patch to a string to recover a newer version of the string.
|
||||
|
||||
:param original: The original string.
|
||||
:param patch: The patch to apply.
|
||||
:param revert: If True, treat the original string as the newer version and recover the older string.
|
||||
:return: The updated string after applying the patch.
|
||||
"""
|
||||
original_lines = original.splitlines(True)
|
||||
patch_lines = patch.splitlines(True)
|
||||
|
||||
updated_text = ""
|
||||
index_original = start_line = 0
|
||||
|
||||
# Choose which group of the regex to use based on the revert flag
|
||||
match_index, line_sign = (1, "+") if not revert else (3, "-")
|
||||
|
||||
# Skip header lines of the patch
|
||||
while index_original < len(patch_lines) and patch_lines[index_original].startswith(("---", "+++")):
|
||||
index_original += 1
|
||||
|
||||
while index_original < len(patch_lines):
|
||||
match = PATCH_HEADER_PATTERN.match(patch_lines[index_original])
|
||||
if not match:
|
||||
raise Exception("Bad patch -- regex mismatch [line " + str(index_original) + "]")
|
||||
|
||||
line_number = int(match.group(match_index)) - 1 + (match.group(match_index + 1) == "0")
|
||||
|
||||
if start_line > line_number or line_number > len(original_lines):
|
||||
raise Exception("Bad patch -- bad line number [line " + str(index_original) + "]")
|
||||
|
||||
updated_text += "".join(original_lines[start_line:line_number])
|
||||
start_line = line_number
|
||||
index_original += 1
|
||||
|
||||
while index_original < len(patch_lines) and patch_lines[index_original][0] != "@":
|
||||
if index_original + 1 < len(patch_lines) and patch_lines[index_original + 1][0] == "\\":
|
||||
line_content = patch_lines[index_original][:-1]
|
||||
index_original += 2
|
||||
else:
|
||||
line_content = patch_lines[index_original]
|
||||
index_original += 1
|
||||
|
||||
if line_content:
|
||||
if line_content[0] == line_sign or line_content[0] == " ":
|
||||
updated_text += line_content[1:]
|
||||
start_line += line_content[0] != line_sign
|
||||
|
||||
updated_text += "".join(original_lines[start_line:])
|
||||
return updated_text
|
||||
@ -1,602 +0,0 @@
|
||||
import asyncio
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
from urllib.parse import urljoin
|
||||
|
||||
import httpx
|
||||
|
||||
from core.agents.base import BaseAgent
|
||||
from core.agents.convo import AgentConvo
|
||||
from core.agents.git import GitMixin
|
||||
from core.agents.mixins import FileDiffMixin
|
||||
from core.agents.response import AgentResponse
|
||||
from core.cli.helpers import capture_exception
|
||||
from core.config import FRONTEND_AGENT_NAME, IMPLEMENT_CHANGES_AGENT_NAME, PYTHAGORA_API
|
||||
from core.config.actions import (
|
||||
FE_CHANGE_REQ,
|
||||
FE_CONTINUE,
|
||||
FE_DONE_WITH_UI,
|
||||
FE_ITERATION,
|
||||
FE_ITERATION_DONE,
|
||||
FE_START,
|
||||
)
|
||||
from core.llm.convo import Convo
|
||||
from core.llm.parser import DescriptiveCodeBlockParser, OptionalCodeBlockParser
|
||||
from core.log import get_logger
|
||||
from core.telemetry import telemetry
|
||||
from core.ui.base import ProjectStage
|
||||
|
||||
log = get_logger(__name__)
|
||||
|
||||
|
||||
def has_correct_num_of_backticks(response: str) -> bool:
|
||||
"""
|
||||
Checks if the response has the correct number of backticks.
|
||||
"""
|
||||
return response.count("```") % 2 == 0 and response.count("```") > 0
|
||||
|
||||
|
||||
class Frontend(FileDiffMixin, GitMixin, BaseAgent):
|
||||
agent_type = "frontend"
|
||||
display_name = "Frontend"
|
||||
|
||||
async def run(self) -> AgentResponse:
|
||||
if not self.current_state.epics[-1]["messages"]:
|
||||
finished = await self.start_frontend()
|
||||
elif self.next_state.epics[-1].get("file_paths_to_remove_mock"):
|
||||
finished = await self.remove_mock()
|
||||
if finished is None:
|
||||
return AgentResponse.exit(self)
|
||||
elif not self.next_state.epics[-1].get("fe_iteration_done"):
|
||||
finished = await self.continue_frontend()
|
||||
else:
|
||||
await self.set_app_details()
|
||||
finished = await self.iterate_frontend()
|
||||
if finished is None:
|
||||
return AgentResponse.exit(self)
|
||||
|
||||
return await self.end_frontend_iteration(finished)
|
||||
|
||||
async def start_frontend(self):
|
||||
"""
|
||||
Starts the frontend of the app.
|
||||
"""
|
||||
self.state_manager.fe_auto_debug = True
|
||||
await self.ui.clear_main_logs()
|
||||
await self.ui.send_front_logs_headers(str(self.next_state.id), ["E2 / T1", "working"], "Building frontend")
|
||||
await self.ui.send_back_logs(
|
||||
[
|
||||
{
|
||||
"title": "Building frontend",
|
||||
"project_state_id": str(self.next_state.id),
|
||||
"labels": ["E2 / T1", "Frontend", "working"],
|
||||
}
|
||||
]
|
||||
)
|
||||
self.next_state.action = FE_START
|
||||
await self.send_message("## Building the frontend\n\nThis may take a couple of minutes.")
|
||||
await self.ui.send_project_stage({"stage": ProjectStage.FRONTEND_STARTED})
|
||||
|
||||
await self.ui.set_important_stream(False)
|
||||
llm = self.get_llm(FRONTEND_AGENT_NAME, stream_output=True)
|
||||
convo = AgentConvo(self).template(
|
||||
"build_frontend",
|
||||
summary=self.state_manager.template["template"].get_summary()
|
||||
if self.state_manager.template is not None
|
||||
else self.current_state.specification.template_summary,
|
||||
description=self.next_state.epics[-1]["description"],
|
||||
user_feedback=None,
|
||||
first_time_build=True,
|
||||
)
|
||||
response = await llm(convo, parser=DescriptiveCodeBlockParser())
|
||||
response_blocks = response.blocks
|
||||
convo.assistant(response.original_response)
|
||||
|
||||
# Await the template task if it's not done yet
|
||||
if self.state_manager.async_tasks:
|
||||
if not self.state_manager.async_tasks[-1].done():
|
||||
await self.state_manager.async_tasks[-1]
|
||||
self.state_manager.async_tasks = []
|
||||
|
||||
await self.process_response(response_blocks)
|
||||
|
||||
self.next_state.epics[-1]["messages"] = convo.messages
|
||||
self.next_state.epics[-1]["fe_iteration_done"] = (
|
||||
"done" in response.original_response[-20:].lower().strip() or len(convo.messages) > 11
|
||||
)
|
||||
self.next_state.flag_epics_as_modified()
|
||||
|
||||
return False
|
||||
|
||||
async def continue_frontend(self):
|
||||
"""
|
||||
Continues building the frontend of the app after the initial user input.
|
||||
"""
|
||||
self.state_manager.fe_auto_debug = True
|
||||
self.next_state.action = FE_CONTINUE
|
||||
await self.ui.send_project_stage({"stage": ProjectStage.CONTINUE_FRONTEND})
|
||||
await self.send_message("### Continuing to build UI... This may take a couple of minutes")
|
||||
|
||||
llm = self.get_llm(FRONTEND_AGENT_NAME, stream_output=True)
|
||||
convo = AgentConvo(self)
|
||||
convo.messages = self.current_state.epics[-1]["messages"]
|
||||
convo.user(
|
||||
"Ok, now think carefully about your previous response. If the response ends by mentioning something about continuing with the implementation, continue but don't implement any files that have already been implemented. If your last response finishes with an incomplete file, implement that file and any other that needs implementation. Finally, if your last response doesn't end by mentioning continuing and if there isn't an unfinished file implementation, respond only with `DONE` and with nothing else."
|
||||
)
|
||||
|
||||
response = await llm(convo, parser=DescriptiveCodeBlockParser())
|
||||
response_blocks = response.blocks
|
||||
convo.assistant(response.original_response)
|
||||
|
||||
use_relace = self.current_state.epics[-1].get("use_relace", False)
|
||||
await self.process_response(response_blocks, relace=use_relace)
|
||||
|
||||
if self.next_state.epics[-1].get("manual_iteration", False):
|
||||
self.next_state.epics[-1]["fe_iteration_done"] = (
|
||||
has_correct_num_of_backticks(response.original_response)
|
||||
or self.current_state.epics[-1].get("retry_count", 0) >= 2
|
||||
)
|
||||
self.next_state.epics[-1]["retry_count"] = self.current_state.epics[-1].get("retry_count", 0) + 1
|
||||
else:
|
||||
self.next_state.epics[-1]["fe_iteration_done"] = (
|
||||
"done" in response.original_response[-20:].lower().strip() or len(convo.messages) > 15
|
||||
)
|
||||
|
||||
self.next_state.epics[-1]["messages"] = convo.messages
|
||||
self.next_state.flag_epics_as_modified()
|
||||
|
||||
return False
|
||||
|
||||
async def iterate_frontend(self):
|
||||
"""
|
||||
Iterates over the frontend.
|
||||
|
||||
:return: True if the frontend is fully built, False otherwise.
|
||||
"""
|
||||
self.next_state.epics[-1]["auto_debug_attempts"] = 0
|
||||
self.next_state.epics[-1]["retry_count"] = 0
|
||||
user_input = await self.try_auto_debug()
|
||||
|
||||
frontend_only = self.current_state.branch.project.project_type == "swagger"
|
||||
self.next_state.action = FE_ITERATION
|
||||
# update the pages in the knowledge base
|
||||
await self.state_manager.update_implemented_pages_and_apis()
|
||||
|
||||
await self.ui.send_project_stage({"stage": ProjectStage.ITERATE_FRONTEND, "iteration_index": 1})
|
||||
|
||||
if user_input:
|
||||
await self.send_message("Errors detected, fixing...")
|
||||
else:
|
||||
answer = await self.ask_question(
|
||||
"Do you want to change anything or report a bug?" if frontend_only else FE_CHANGE_REQ,
|
||||
buttons={"yes": "I'm done building the UI"} if not frontend_only else None,
|
||||
default="yes",
|
||||
extra_info={"restart_app": True, "collect_logs": True},
|
||||
placeholder='For example, "I don\'t see anything when I open http://localhost:5173/" or "Nothing happens when I click on the NEW PROJECT button"',
|
||||
)
|
||||
|
||||
if answer.button == "yes":
|
||||
answer = await self.ask_question(
|
||||
FE_DONE_WITH_UI,
|
||||
buttons={
|
||||
"yes": "Yes, let's build the backend",
|
||||
"no": "No, continue working on the UI",
|
||||
},
|
||||
buttons_only=True,
|
||||
default="yes",
|
||||
)
|
||||
|
||||
if answer.button == "yes":
|
||||
fe_states = await self.state_manager.get_fe_states()
|
||||
first_fe_state_id = fe_states[0].id if fe_states else None
|
||||
last_fe_state_id = fe_states[-1].id if fe_states else None
|
||||
|
||||
await self.ui.clear_main_logs()
|
||||
await self.ui.send_front_logs_headers(
|
||||
str(first_fe_state_id) if first_fe_state_id else "fe_0",
|
||||
["E2 / T1", "done"],
|
||||
"Building frontend",
|
||||
)
|
||||
await self.ui.send_back_logs(
|
||||
[
|
||||
{
|
||||
"title": "Building frontend",
|
||||
"project_state_id": str(first_fe_state_id) if first_fe_state_id else "fe_0",
|
||||
"start_id": str(first_fe_state_id) if first_fe_state_id else "fe_0",
|
||||
"end_id": str(last_fe_state_id) if last_fe_state_id else "fe_0",
|
||||
"labels": ["E2 / T1", "Frontend", "done"],
|
||||
}
|
||||
]
|
||||
)
|
||||
await self.ui.send_back_logs(
|
||||
[
|
||||
{
|
||||
"title": "Setting up backend",
|
||||
"disallow_reload": True,
|
||||
"project_state_id": "be_0",
|
||||
"labels": ["E2 / T2", "Backend setup", "working"],
|
||||
}
|
||||
]
|
||||
)
|
||||
await self.ui.send_front_logs_headers("", ["E2 / T2", "working"], "Setting up backend")
|
||||
return True
|
||||
elif answer.button == "no":
|
||||
return False
|
||||
|
||||
if answer.text:
|
||||
user_input = answer.text
|
||||
await self.send_message("Implementing the changes you suggested...")
|
||||
|
||||
llm = self.get_llm(FRONTEND_AGENT_NAME)
|
||||
|
||||
relevant_api_documentation = None
|
||||
|
||||
if frontend_only:
|
||||
convo = AgentConvo(self).template(
|
||||
"is_relevant_for_docs_search",
|
||||
user_feedback=user_input,
|
||||
)
|
||||
|
||||
response = await llm(convo)
|
||||
if str(response).lower() == "yes":
|
||||
error = None
|
||||
for attempt in range(3):
|
||||
try:
|
||||
url = urljoin(PYTHAGORA_API, "rag/search")
|
||||
async with httpx.AsyncClient(transport=httpx.AsyncHTTPTransport()) as client:
|
||||
resp = await client.post(
|
||||
url,
|
||||
json={"text": user_input, "project_id": str(self.state_manager.project.id)},
|
||||
headers={"Authorization": f"Bearer {self.state_manager.get_access_token()}"},
|
||||
)
|
||||
|
||||
if resp.status_code in [200]:
|
||||
relevant_api_documentation = "\n".join(item["content"] for item in resp.json())
|
||||
break
|
||||
elif resp.status_code in [401, 403]:
|
||||
access_token = await self.ui.send_token_expired()
|
||||
self.state_manager.update_access_token(access_token)
|
||||
else:
|
||||
try:
|
||||
error = resp.json()["error"]
|
||||
except Exception as e:
|
||||
error = e
|
||||
log.warning(f"Failed to fetch from RAG service: {error}")
|
||||
await self.send_message(
|
||||
f"Couldn't find any relevant API documentation. Retrying... \nError: {error}"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
error = e
|
||||
capture_exception(e)
|
||||
log.warning(f"Failed to fetch from RAG service: {e}", exc_info=True)
|
||||
if error:
|
||||
await self.send_message(f"Please try reloading the project. \nError: {error}")
|
||||
return None
|
||||
|
||||
llm = self.get_llm(FRONTEND_AGENT_NAME, stream_output=True)
|
||||
|
||||
# try relace first
|
||||
convo = AgentConvo(self).template(
|
||||
"iterate_frontend",
|
||||
description=self.current_state.epics[-1]["description"],
|
||||
user_feedback=user_input,
|
||||
relevant_api_documentation=relevant_api_documentation,
|
||||
first_time_build=False,
|
||||
)
|
||||
|
||||
# replace system prompt because of relace
|
||||
convo.messages[0]["content"] = AgentConvo(self).render("system_relace")
|
||||
|
||||
response = await llm(convo, parser=DescriptiveCodeBlockParser())
|
||||
|
||||
relace_finished = await self.process_response(response.blocks, relace=True)
|
||||
|
||||
if not relace_finished:
|
||||
log.debug("Relace didn't finish, reverting to build_frontend")
|
||||
convo = AgentConvo(self).template(
|
||||
"build_frontend",
|
||||
description=self.current_state.epics[-1]["description"],
|
||||
user_feedback=user_input,
|
||||
relevant_api_documentation=relevant_api_documentation,
|
||||
first_time_build=False,
|
||||
)
|
||||
|
||||
response = await llm(convo, parser=DescriptiveCodeBlockParser())
|
||||
|
||||
await self.process_response(response.blocks)
|
||||
|
||||
convo.assistant(response.original_response)
|
||||
|
||||
self.next_state.epics[-1]["messages"] = convo.messages
|
||||
self.next_state.epics[-1]["use_relace"] = relace_finished
|
||||
self.next_state.epics[-1]["fe_iteration_done"] = has_correct_num_of_backticks(response.original_response)
|
||||
self.next_state.epics[-1]["manual_iteration"] = True
|
||||
self.next_state.flag_epics_as_modified()
|
||||
|
||||
return False
|
||||
|
||||
async def end_frontend_iteration(self, finished: bool) -> AgentResponse:
|
||||
"""
|
||||
Ends the frontend iteration.
|
||||
|
||||
:param finished: Whether the frontend is fully built.
|
||||
:return: AgentResponse.done(self)
|
||||
"""
|
||||
if finished:
|
||||
# TODO Add question if user app is fully finished
|
||||
self.next_state.action = FE_ITERATION_DONE
|
||||
|
||||
self.next_state.complete_epic()
|
||||
await telemetry.trace_code_event(
|
||||
"frontend-finished",
|
||||
{
|
||||
"description": self.current_state.epics[-1]["description"],
|
||||
"messages": self.current_state.epics[-1]["messages"],
|
||||
},
|
||||
)
|
||||
|
||||
if self.state_manager.git_available and self.state_manager.git_used:
|
||||
await self.git_commit(commit_message="Frontend finished")
|
||||
|
||||
inputs = []
|
||||
for file in self.current_state.files:
|
||||
if not file.content:
|
||||
continue
|
||||
input_required = self.state_manager.get_input_required(file.content.content, file.path)
|
||||
if input_required:
|
||||
inputs += [{"file": file.path, "line": line} for line in input_required]
|
||||
|
||||
if inputs:
|
||||
return AgentResponse.input_required(self, inputs)
|
||||
|
||||
return AgentResponse.done(self)
|
||||
|
||||
async def process_response(self, response_blocks: list, removed_mock: bool = False, relace: bool = False) -> bool:
|
||||
"""
|
||||
Processes the response blocks from the LLM.
|
||||
|
||||
:param response_blocks: The response blocks from the LLM.
|
||||
:return: AgentResponse.done(self)
|
||||
"""
|
||||
for block in response_blocks:
|
||||
description = block.description.strip()
|
||||
content = block.content.strip()
|
||||
|
||||
# Split description into lines and check the last line for file path
|
||||
description_lines = description.split("\n")
|
||||
last_line = description_lines[-1].strip()
|
||||
|
||||
if "file:" in last_line:
|
||||
# Extract file path from the last line - get everything after "file:"
|
||||
file_path = last_line[last_line.index("file:") + 5 :].strip()
|
||||
file_path = file_path.strip("\"'`")
|
||||
# Skip empty file paths
|
||||
if file_path.strip() == "":
|
||||
continue
|
||||
new_content = content
|
||||
old_content = self.current_state.get_file_content_by_path(file_path)
|
||||
|
||||
if relace:
|
||||
llm = self.get_llm(IMPLEMENT_CHANGES_AGENT_NAME)
|
||||
convo = Convo().user(
|
||||
{
|
||||
"initialCode": old_content,
|
||||
"editSnippet": new_content,
|
||||
}
|
||||
)
|
||||
|
||||
new_content = await llm(convo, temperature=0, parser=OptionalCodeBlockParser())
|
||||
|
||||
if not new_content or new_content == ("", 0, 0):
|
||||
return False
|
||||
|
||||
n_new_lines, n_del_lines = self.get_line_changes(old_content, new_content)
|
||||
await self.ui.send_file_status(file_path, "done", source=self.ui_source)
|
||||
await self.ui.generate_diff(
|
||||
file_path, old_content, new_content, n_new_lines, n_del_lines, source=self.ui_source
|
||||
)
|
||||
if not removed_mock and self.current_state.branch.project.project_type == "swagger":
|
||||
if "client/src/api" in file_path:
|
||||
if not self.next_state.epics[-1].get("file_paths_to_remove_mock"):
|
||||
self.next_state.epics[-1]["file_paths_to_remove_mock"] = []
|
||||
self.next_state.epics[-1]["file_paths_to_remove_mock"].append(file_path)
|
||||
|
||||
await self.state_manager.save_file(file_path, new_content)
|
||||
|
||||
elif "command:" in last_line:
|
||||
# Split multiple commands and execute them sequentially
|
||||
commands = content.strip().split("\n")
|
||||
for command in commands:
|
||||
command = command.strip()
|
||||
if command:
|
||||
# Add "cd client" prefix if not already present
|
||||
if not command.startswith("cd "):
|
||||
command = f"cd client && {command}"
|
||||
if "run start" in command or "run dev" in command:
|
||||
continue
|
||||
|
||||
# if command is cd client && some_command client/ -> won't work, we need to remove client/ after &&
|
||||
prefix, cmd_part = command.split("&&", 1)
|
||||
cmd_part = cmd_part.strip().replace("client/", "")
|
||||
command = f"{prefix} && {cmd_part}"
|
||||
|
||||
# check if cmd_part contains npm run something, if that something is not in scripts, then skip it
|
||||
if "npm run" in cmd_part:
|
||||
npm_script = cmd_part.split("npm run")[1].strip()
|
||||
|
||||
absolute_path = os.path.join(
|
||||
self.state_manager.get_full_project_root(),
|
||||
os.path.join(
|
||||
"client" if "client" in prefix else "server" if "server" in prefix else "",
|
||||
"package.json",
|
||||
),
|
||||
)
|
||||
with open(absolute_path, "r") as file:
|
||||
package_json = json.load(file)
|
||||
if npm_script not in package_json.get("scripts", {}):
|
||||
log.warning(
|
||||
f"Skipping command: {command} as npm script {npm_script} not found, command is {command}"
|
||||
)
|
||||
continue
|
||||
|
||||
await self.send_message(f"Running command: `{command}`...")
|
||||
await self.process_manager.run_command(command)
|
||||
else:
|
||||
log.info(f"Unknown block description: {description}")
|
||||
|
||||
return True
|
||||
|
||||
async def remove_mock(self):
|
||||
"""
|
||||
Remove mock API from the backend and replace it with api endpoints defined in the external documentation
|
||||
"""
|
||||
new_file_paths = self.current_state.epics[-1]["file_paths_to_remove_mock"]
|
||||
llm = self.get_llm(FRONTEND_AGENT_NAME)
|
||||
|
||||
for file_path in new_file_paths:
|
||||
old_content = self.current_state.get_file_content_by_path(file_path)
|
||||
|
||||
convo = AgentConvo(self).template("create_rag_query", file_content=old_content)
|
||||
topics = await llm(convo)
|
||||
|
||||
if topics != "None":
|
||||
error = None
|
||||
for attempt in range(3):
|
||||
try:
|
||||
url = urljoin(PYTHAGORA_API, "rag/search")
|
||||
async with httpx.AsyncClient(transport=httpx.AsyncHTTPTransport()) as client:
|
||||
resp = await client.post(
|
||||
url,
|
||||
json={"text": topics, "project_id": str(self.state_manager.project.id)},
|
||||
headers={"Authorization": f"Bearer {self.state_manager.get_access_token()}"},
|
||||
)
|
||||
if resp.status_code == 200:
|
||||
resp_json = resp.json()
|
||||
relevant_api_documentation = "\n".join(item["content"] for item in resp_json)
|
||||
|
||||
referencing_files = await self.state_manager.get_referencing_files(
|
||||
self.current_state, file_path
|
||||
)
|
||||
|
||||
convo = AgentConvo(self).template(
|
||||
"remove_mock",
|
||||
relevant_api_documentation=relevant_api_documentation,
|
||||
file_content=old_content,
|
||||
file_path=file_path,
|
||||
referencing_files=referencing_files,
|
||||
lines=len(old_content.splitlines()),
|
||||
)
|
||||
|
||||
response = await llm(convo, parser=DescriptiveCodeBlockParser())
|
||||
response_blocks = response.blocks
|
||||
convo.assistant(response.original_response)
|
||||
await self.process_response(response_blocks, removed_mock=True)
|
||||
self.next_state.epics[-1]["file_paths_to_remove_mock"].remove(file_path)
|
||||
break
|
||||
elif resp.status_code in [401, 403]:
|
||||
access_token = await self.ui.send_token_expired()
|
||||
self.state_manager.update_access_token(access_token)
|
||||
else:
|
||||
try:
|
||||
error = resp.json()["error"]
|
||||
except Exception as e:
|
||||
error = e
|
||||
log.warning(f"Failed to fetch from RAG service: {error}")
|
||||
await self.send_message(
|
||||
f"I couldn't find any relevant API documentation. Retrying... \nError: {error}"
|
||||
)
|
||||
except Exception as e:
|
||||
capture_exception(e)
|
||||
log.warning(f"Failed to fetch from RAG service: {e}", exc_info=True)
|
||||
if error:
|
||||
await self.send_message(f"Please try reloading the project. \nError: {error}")
|
||||
return None
|
||||
|
||||
return False
|
||||
|
||||
async def set_app_details(self):
|
||||
"""
|
||||
Sets the app details.
|
||||
"""
|
||||
command = "npm run start"
|
||||
app_link = "http://localhost:5173"
|
||||
|
||||
self.next_state.run_command = command
|
||||
# todo store app link and send whenever we are sending run_command
|
||||
# self.next_state.app_link = app_link
|
||||
await self.ui.send_run_command(command)
|
||||
await self.ui.send_app_link(app_link)
|
||||
|
||||
async def kill_app(self):
|
||||
is_win = sys.platform.lower().startswith("win")
|
||||
# TODO make ports configurable
|
||||
# kill frontend - both swagger and node
|
||||
if is_win:
|
||||
await self.process_manager.run_command(
|
||||
"""for /f "tokens=5" %a in ('netstat -ano ^| findstr :5173 ^| findstr LISTENING') do taskkill /F /PID %a""",
|
||||
show_output=False,
|
||||
)
|
||||
else:
|
||||
await self.process_manager.run_command("lsof -ti:5173 | xargs -r kill", show_output=False)
|
||||
|
||||
# if node project, kill backend as well
|
||||
if self.state_manager.project.project_type == "node":
|
||||
if is_win:
|
||||
await self.process_manager.run_command(
|
||||
"""for /f "tokens=5" %a in ('netstat -ano ^| findstr :3000 ^| findstr LISTENING') do taskkill /F /PID %a""",
|
||||
show_output=False,
|
||||
)
|
||||
else:
|
||||
await self.process_manager.run_command("lsof -ti:3000 | xargs -r kill", show_output=False)
|
||||
|
||||
async def try_auto_debug(self) -> str:
|
||||
if not self.state_manager.fe_auto_debug:
|
||||
self.state_manager.fe_auto_debug = True
|
||||
return ""
|
||||
if self.next_state.epics[-1].get("auto_debug_attempts", 0) >= 3:
|
||||
return ""
|
||||
|
||||
count = 3
|
||||
|
||||
try:
|
||||
await self.send_message(
|
||||
f"### Auto-debugging the frontend #{self.next_state.epics[-1]['auto_debug_attempts']+1}"
|
||||
)
|
||||
self.next_state.epics[-1]["auto_debug_attempts"] = (
|
||||
self.current_state.epics[-1].get("auto_debug_attempts", 0) + 1
|
||||
)
|
||||
# kill app
|
||||
await self.kill_app()
|
||||
|
||||
npm_proc = await self.process_manager.start_process("npm run start &", show_output=False)
|
||||
|
||||
while True:
|
||||
if count == 3:
|
||||
await asyncio.sleep(5)
|
||||
else:
|
||||
await asyncio.sleep(2)
|
||||
diff_stdout, diff_stderr = await npm_proc.read_output()
|
||||
if (diff_stdout == "" and diff_stderr == "") or count <= 0:
|
||||
break
|
||||
count -= 1
|
||||
|
||||
await self.process_manager.run_command("curl http://localhost:5173", show_output=False)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
diff_stdout, diff_stderr = await npm_proc.read_output()
|
||||
|
||||
# kill app again
|
||||
await self.kill_app()
|
||||
|
||||
if diff_stdout or diff_stderr:
|
||||
await self.send_message(f"### Auto-debugging found an error: \n{diff_stdout}\n{diff_stderr}")
|
||||
log.debug(f"Auto-debugging output:\n{diff_stdout}\n{diff_stderr}")
|
||||
return f"I got an error. Here are the logs:\n{diff_stdout}\n{diff_stderr}"
|
||||
except Exception as e:
|
||||
capture_exception(e)
|
||||
log.error(f"Error during auto-debugging: {e}", exc_info=True)
|
||||
|
||||
await self.send_message("### All good, no errors found.")
|
||||
return ""
|
||||
@ -1,167 +0,0 @@
|
||||
import os
|
||||
from typing import Optional
|
||||
|
||||
from core.agents.convo import AgentConvo
|
||||
from core.config.magic_words import GITIGNORE_CONTENT
|
||||
from core.ui.base import pythagora_source
|
||||
|
||||
|
||||
class GitMixin:
|
||||
"""
|
||||
Mixin class for git commands
|
||||
"""
|
||||
|
||||
async def check_git_installed(self) -> bool:
|
||||
"""Check if git is installed on the system."""
|
||||
status_code, _, _ = await self.process_manager.run_command("git --version", show_output=False)
|
||||
git_available = status_code == 0
|
||||
self.state_manager.git_available = git_available
|
||||
return git_available
|
||||
|
||||
async def is_git_initialized(self) -> bool:
|
||||
"""Check if git is initialized in the workspace."""
|
||||
workspace_path = self.state_manager.get_full_project_root()
|
||||
|
||||
status_code, _, _ = await self.process_manager.run_command(
|
||||
"git rev-parse --git-dir --is-inside-git-dir",
|
||||
cwd=workspace_path,
|
||||
show_output=False,
|
||||
)
|
||||
# Will return status code 0 only if .git exists in the current directory
|
||||
git_used = status_code == 0 and os.path.exists(os.path.join(workspace_path, ".git"))
|
||||
self.state_manager.git_used = git_used
|
||||
return git_used
|
||||
|
||||
async def init_git_if_needed(self) -> bool:
|
||||
"""
|
||||
Initialize git repository if it hasn't been initialized yet.
|
||||
Returns True if initialization was needed and successful.
|
||||
"""
|
||||
|
||||
workspace_path = self.state_manager.get_full_project_root()
|
||||
if await self.is_git_initialized():
|
||||
return False
|
||||
|
||||
answer = await self.ui.ask_question(
|
||||
"Git is not initialized for this project. Do you want to initialize it now?",
|
||||
buttons={"yes": "Yes", "no": "No"},
|
||||
default="yes",
|
||||
buttons_only=True,
|
||||
source=pythagora_source,
|
||||
)
|
||||
|
||||
if answer.button == "no":
|
||||
return False
|
||||
else:
|
||||
status_code, _, stderr = await self.process_manager.run_command("git init", cwd=workspace_path)
|
||||
if status_code != 0:
|
||||
raise RuntimeError(f"Failed to initialize git repository: {stderr}")
|
||||
|
||||
gitignore_path = os.path.join(workspace_path, ".gitignore")
|
||||
try:
|
||||
with open(gitignore_path, "w") as f:
|
||||
f.write(GITIGNORE_CONTENT)
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Failed to create .gitignore file: {str(e)}")
|
||||
|
||||
# First check if there are any changes to commit
|
||||
status_code, stdout, stderr = await self.process_manager.run_command(
|
||||
"git status --porcelain",
|
||||
cwd=workspace_path,
|
||||
)
|
||||
|
||||
if status_code == 0 and stdout.strip(): # If there are changes (stdout is not empty)
|
||||
# Stage all files
|
||||
status_code, _, stderr = await self.process_manager.run_command(
|
||||
"git add .",
|
||||
cwd=workspace_path,
|
||||
)
|
||||
if status_code != 0:
|
||||
raise RuntimeError(f"Failed to stage files: {stderr}")
|
||||
|
||||
# Create initial commit
|
||||
status_code, _, stderr = await self.process_manager.run_command(
|
||||
'git commit -m "initial commit"', cwd=workspace_path
|
||||
)
|
||||
if status_code != 0:
|
||||
raise RuntimeError(f"Failed to create initial commit: {stderr}")
|
||||
|
||||
self.state_manager.git_used = True
|
||||
return True
|
||||
|
||||
async def git_commit(self, commit_message: Optional[str] = None) -> None:
|
||||
"""
|
||||
Create a git commit with the specified message. Commit message is optional.
|
||||
Raises RuntimeError if the commit fails.
|
||||
"""
|
||||
workspace_path = self.state_manager.get_full_project_root()
|
||||
|
||||
# Check if there are any changes to commit
|
||||
status_code, git_status, stderr = await self.process_manager.run_command(
|
||||
"git status --porcelain",
|
||||
cwd=workspace_path,
|
||||
show_output=False,
|
||||
)
|
||||
if status_code != 0:
|
||||
raise RuntimeError(f"Failed to get git status: {stderr}")
|
||||
|
||||
if not git_status.strip():
|
||||
return
|
||||
|
||||
answer = await self.ui.ask_question(
|
||||
"Do you want to create new git commit?",
|
||||
buttons={"yes": "Yes", "no": "No"},
|
||||
default="yes",
|
||||
buttons_only=True,
|
||||
source=pythagora_source,
|
||||
)
|
||||
|
||||
if answer.button == "no":
|
||||
return
|
||||
|
||||
# Stage all changes
|
||||
status_code, _, stderr = await self.process_manager.run_command("git add .", cwd=workspace_path)
|
||||
if status_code != 0:
|
||||
raise RuntimeError(f"Failed to stage changes: {stderr}")
|
||||
|
||||
# Get git diff
|
||||
status_code, git_diff, stderr = await self.process_manager.run_command(
|
||||
"git diff --cached || git diff",
|
||||
cwd=workspace_path,
|
||||
show_output=False,
|
||||
)
|
||||
if status_code != 0:
|
||||
raise RuntimeError(f"Failed to create initial commit: {stderr}")
|
||||
|
||||
if not commit_message:
|
||||
llm = self.get_llm()
|
||||
convo = AgentConvo(self).template(
|
||||
"commit",
|
||||
git_diff=git_diff,
|
||||
)
|
||||
commit_message: str = await llm(convo)
|
||||
|
||||
answer = await self.ui.ask_question(
|
||||
f"Do you accept this 'git commit' message? Here is suggested message: '{commit_message}'",
|
||||
buttons={"yes": "Yes", "edit": "Edit", "no": "No, I don't want to commit changes."},
|
||||
default="yes",
|
||||
buttons_only=True,
|
||||
source=pythagora_source,
|
||||
)
|
||||
|
||||
if answer.button == "no":
|
||||
return
|
||||
elif answer.button == "edit":
|
||||
user_message = await self.ui.ask_question(
|
||||
"Please enter the commit message",
|
||||
source=pythagora_source,
|
||||
initial_text=commit_message,
|
||||
)
|
||||
commit_message = user_message.text
|
||||
|
||||
# Create commit
|
||||
status_code, _, stderr = await self.process_manager.run_command(
|
||||
f'git commit -m "{commit_message}"', cwd=workspace_path
|
||||
)
|
||||
if status_code != 0:
|
||||
raise RuntimeError(f"Failed to create commit: {stderr}")
|
||||
@ -1,14 +0,0 @@
|
||||
from core.agents.base import BaseAgent
|
||||
from core.agents.response import AgentResponse
|
||||
|
||||
|
||||
class LegacyHandler(BaseAgent):
|
||||
agent_type = "legacy-handler"
|
||||
display_name = "Legacy Handler"
|
||||
|
||||
async def run(self) -> AgentResponse:
|
||||
if self.data["type"] == "review_task":
|
||||
self.next_state.complete_step("review_task")
|
||||
return AgentResponse.done(self)
|
||||
|
||||
raise ValueError(f"Unknown reason for calling Legacy Handler with data: {self.data}")
|
||||
@ -0,0 +1,58 @@
|
||||
from core.agents.base import BaseAgent
|
||||
from core.agents.convo import AgentConvo
|
||||
from core.agents.response import AgentResponse
|
||||
from core.log import get_logger
|
||||
|
||||
log = get_logger(__name__)
|
||||
|
||||
|
||||
class TaskReviewer(BaseAgent):
|
||||
agent_type = "task-reviewer"
|
||||
display_name = "Task Reviewer"
|
||||
|
||||
async def run(self) -> AgentResponse:
|
||||
response = await self.review_code_changes()
|
||||
self.next_state.complete_step()
|
||||
return response
|
||||
|
||||
async def review_code_changes(self) -> AgentResponse:
|
||||
"""
|
||||
Review all the code changes during current task.
|
||||
"""
|
||||
|
||||
log.debug(f"Reviewing code changes for task {self.current_state.current_task['description']}")
|
||||
await self.send_message("Reviewing the task implementation ...")
|
||||
all_feedbacks = [
|
||||
iteration["user_feedback"].replace("```", "").strip()
|
||||
for iteration in self.current_state.iterations
|
||||
# Some iterations are created by the task reviewer and have no user feedback
|
||||
if iteration["user_feedback"]
|
||||
]
|
||||
bug_hunter_instructions = [
|
||||
iteration["bug_hunting_cycles"][-1]["human_readable_instructions"].replace("```", "").strip()
|
||||
for iteration in self.current_state.iterations
|
||||
if iteration["bug_hunting_cycles"]
|
||||
]
|
||||
|
||||
files_before_modification = self.current_state.modified_files
|
||||
files_after_modification = [
|
||||
(file.path, file.content.content)
|
||||
for file in self.current_state.files
|
||||
if (file.path in files_before_modification)
|
||||
]
|
||||
|
||||
llm = self.get_llm()
|
||||
# TODO instead of sending files before and after maybe add nice way to show diff for multiple files
|
||||
convo = AgentConvo(self).template(
|
||||
"review_task",
|
||||
all_feedbacks=all_feedbacks,
|
||||
files_before_modification=files_before_modification,
|
||||
files_after_modification=files_after_modification,
|
||||
bug_hunter_instructions=bug_hunter_instructions,
|
||||
)
|
||||
llm_response: str = await llm(convo, temperature=0.7)
|
||||
|
||||
if "done" in llm_response.strip().lower()[-20:]:
|
||||
return AgentResponse.done(self)
|
||||
else:
|
||||
return AgentResponse.task_review_feedback(self, llm_response)
|
||||
@ -1,174 +0,0 @@
|
||||
import json
|
||||
from urllib.parse import urljoin
|
||||
from uuid import uuid4
|
||||
|
||||
import httpx
|
||||
from sqlalchemy import inspect
|
||||
|
||||
from core.agents.base import BaseAgent
|
||||
from core.agents.response import AgentResponse
|
||||
from core.cli.helpers import capture_exception
|
||||
from core.config import PYTHAGORA_API
|
||||
from core.config.actions import FE_INIT
|
||||
from core.db.models import KnowledgeBase
|
||||
from core.log import get_logger
|
||||
from core.telemetry import telemetry
|
||||
|
||||
log = get_logger(__name__)
|
||||
|
||||
|
||||
class Wizard(BaseAgent):
|
||||
agent_type = "wizard"
|
||||
display_name = "Wizard"
|
||||
|
||||
async def run(self) -> AgentResponse:
|
||||
success = await self.init_template()
|
||||
if not success:
|
||||
return AgentResponse.exit(self)
|
||||
return AgentResponse.create_specification(self)
|
||||
|
||||
async def init_template(self) -> bool:
|
||||
"""
|
||||
Sets up the frontend
|
||||
|
||||
:return: AgentResponse.done(self)
|
||||
"""
|
||||
self.next_state.action = FE_INIT
|
||||
self.state_manager.template = {}
|
||||
options = {}
|
||||
auth_data = {}
|
||||
|
||||
if self.state_manager.project.project_type == "swagger":
|
||||
while True:
|
||||
try:
|
||||
docs = await self.ask_question(
|
||||
"Paste the OpenAPI/Swagger JSON or YAML docs here",
|
||||
allow_empty=False,
|
||||
verbose=True,
|
||||
)
|
||||
success, options["external_api_url"], options["types"] = await self.upload_docs(docs.text)
|
||||
if not success:
|
||||
await self.send_message("Please try creating a new project.")
|
||||
return False
|
||||
else:
|
||||
break
|
||||
except Exception as e:
|
||||
log.debug(f"An error occurred: {str(e)}")
|
||||
await self.send_message("Please provide a valid input.")
|
||||
continue
|
||||
|
||||
while True:
|
||||
auth_type_question = await self.ask_question(
|
||||
"Which authentication method does your backend use?",
|
||||
buttons={
|
||||
"none": "No authentication",
|
||||
"api_key": "API Key",
|
||||
"bearer": "HTTP Bearer (coming soon)",
|
||||
"open_id_connect": "OpenID Connect (coming soon)",
|
||||
"oauth2": "OAuth2 (coming soon)",
|
||||
},
|
||||
buttons_only=True,
|
||||
default="api_key",
|
||||
full_screen=True,
|
||||
)
|
||||
|
||||
if auth_type_question.button == "api_key":
|
||||
if auth_data.get("types") is None or "apiKey" not in auth_data["types"]:
|
||||
addit_question = await self.ask_question(
|
||||
"The API key authentication method is not supported by your backend. Do you want to continue?",
|
||||
buttons_only=True,
|
||||
buttons={"yes": "Yes", "no": "Go back"},
|
||||
)
|
||||
if addit_question.button != "yes":
|
||||
continue
|
||||
|
||||
api_key = await self.ask_question(
|
||||
"Enter your API key here. It will be saved in the .env file on the frontend.",
|
||||
allow_empty=False,
|
||||
verbose=True,
|
||||
)
|
||||
options["auth_type"] = "api_key"
|
||||
options["api_key"] = api_key.text.strip()
|
||||
break
|
||||
elif auth_type_question.button == "none":
|
||||
options["auth_type"] = "none"
|
||||
break
|
||||
else:
|
||||
auth_type_question_trace = await self.ask_question(
|
||||
"We are still working on getting this auth method implemented correctly. Can we contact you to get more info on how you would like it to work?",
|
||||
allow_empty=False,
|
||||
buttons={"yes": "Yes", "no": "No"},
|
||||
default="yes",
|
||||
buttons_only=True,
|
||||
)
|
||||
if auth_type_question_trace.button == "yes":
|
||||
await telemetry.trace_code_event(
|
||||
"swagger-auth-method",
|
||||
{"type": auth_type_question.button},
|
||||
)
|
||||
await self.send_message("Thank you for submitting your request. We will be in touch.")
|
||||
else:
|
||||
options["auth_type"] = "login"
|
||||
|
||||
# Create a new knowledge base instance for the project state
|
||||
knowledge_base = KnowledgeBase(pages=[], apis=[], user_options=options, utility_functions=[])
|
||||
session = inspect(self.next_state).async_session
|
||||
session.add(knowledge_base)
|
||||
self.next_state.knowledge_base = knowledge_base
|
||||
|
||||
self.next_state.epics = [
|
||||
{
|
||||
"id": uuid4().hex,
|
||||
"name": "Build frontend",
|
||||
"source": "frontend",
|
||||
"description": "",
|
||||
"messages": [],
|
||||
"summary": None,
|
||||
"completed": False,
|
||||
}
|
||||
]
|
||||
|
||||
return True
|
||||
|
||||
async def upload_docs(self, docs: str) -> (bool, str, list):
|
||||
error = None
|
||||
url = urljoin(PYTHAGORA_API, "rag/upload")
|
||||
for attempt in range(3):
|
||||
log.debug(f"Uploading docs to RAG service... attempt {attempt}")
|
||||
try:
|
||||
async with httpx.AsyncClient(
|
||||
transport=httpx.AsyncHTTPTransport(), timeout=httpx.Timeout(30.0, connect=5.0)
|
||||
) as client:
|
||||
resp = await client.post(
|
||||
url,
|
||||
json={
|
||||
"text": docs.strip(),
|
||||
"project_id": str(self.state_manager.project.id),
|
||||
},
|
||||
headers={"Authorization": f"Bearer {self.state_manager.get_access_token()}"},
|
||||
)
|
||||
|
||||
if resp.status_code == 200:
|
||||
log.debug("Uploading docs to RAG service successful")
|
||||
resp_body = json.loads(resp.text)
|
||||
return True, resp_body["external_api_url"], resp_body["types"]
|
||||
elif resp.status_code == 403:
|
||||
log.debug("Uploading docs to RAG service failed, trying to refresh token")
|
||||
access_token = await self.ui.send_token_expired()
|
||||
self.state_manager.update_access_token(access_token)
|
||||
else:
|
||||
try:
|
||||
error = resp.json()["error"]
|
||||
except Exception as e:
|
||||
capture_exception(e)
|
||||
error = e
|
||||
log.debug(f"Uploading docs to RAG service failed: {error}")
|
||||
|
||||
except Exception as e:
|
||||
log.warning(f"Attempt {attempt + 1} failed: {e}", exc_info=True)
|
||||
capture_exception(e)
|
||||
|
||||
await self.ui.send_message(
|
||||
f"An error occurred while uploading the docs. Error: {error if error else 'unknown'}",
|
||||
)
|
||||
return False
|
||||
@ -1,58 +0,0 @@
|
||||
BH_START_BUG_HUNT = "Start bug hunt for task #{}"
|
||||
BH_WAIT_BUG_REP_INSTRUCTIONS = "Awaiting bug reproduction instructions for task #{}"
|
||||
BH_START_USER_TEST = "Start user testing for task #{}"
|
||||
BH_STARTING_PAIR_PROGRAMMING = "Start pair programming for task #{}"
|
||||
|
||||
CM_UPDATE_FILES = "Updating files"
|
||||
|
||||
|
||||
DEV_WAIT_TEST = "Awaiting user test"
|
||||
DEV_TASK_START = "Task #{} start"
|
||||
DEV_TASK_BREAKDOWN = "Task #{} breakdown"
|
||||
DEV_TROUBLESHOOT = "Troubleshooting #{}"
|
||||
DEV_TASK_REVIEW_FEEDBACK = "Task review feedback"
|
||||
|
||||
TC_TASK_DONE = "Task #{} complete"
|
||||
|
||||
|
||||
FE_INIT = "Frontend init"
|
||||
FE_START = "Frontend start"
|
||||
FE_CONTINUE = "Frontend continue"
|
||||
FE_ITERATION = "Frontend iteration"
|
||||
FE_ITERATION_DONE = "Frontend iteration done"
|
||||
|
||||
TL_CREATE_INITIAL_EPIC = "Create initial project epic"
|
||||
TL_CREATE_PLAN = "Create a development plan for epic: {}"
|
||||
TL_START_FEATURE = "Start of feature #{}"
|
||||
TL_INITIAL_PROJECT_NAME = "Initial Project"
|
||||
|
||||
TW_WRITE = "Write documentation"
|
||||
|
||||
EX_SKIP_COMMAND = 'Skip "{}"'
|
||||
EX_RUN_COMMAND = 'Run "{}"'
|
||||
|
||||
SPEC_CREATE_STEP_NAME = "Create specification"
|
||||
SPEC_CHANGE_STEP_NAME = "Change specification"
|
||||
SPEC_CHANGE_FEATURE_STEP_NAME = "Change specification due to new feature"
|
||||
|
||||
TS_TASK_REVIEWED = "Task #{} reviewed"
|
||||
TS_ALT_SOLUTION = "Alternative solution (attempt #{})"
|
||||
TS_APP_WORKING = "Please check if the app is working"
|
||||
|
||||
PS_EPIC_COMPLETE = "Epic {} completed"
|
||||
|
||||
# other constants
|
||||
TL_EDIT_DEV_PLAN = "Open and edit your development plan in the Progress tab"
|
||||
MIX_BREAKDOWN_CHAT_PROMPT = "Are you happy with the breakdown? Now is a good time to ask questions or suggest changes."
|
||||
FE_CHANGE_REQ = (
|
||||
"Do you want to change anything or report a bug? Keep in mind that currently ONLY frontend is implemented."
|
||||
)
|
||||
FE_DONE_WITH_UI = "Are you sure you're done building the UI and want to start building the backend functionality now?"
|
||||
TS_DESCRIBE_ISSUE = "Please describe the issue you found (one at a time) and share any relevant server logs"
|
||||
BH_HUMAN_TEST_AGAIN = "Please test the app again."
|
||||
BH_IS_BUG_FIXED = "Is the bug you reported fixed now?"
|
||||
BH_ADDITIONAL_FEEDBACK = "Please add any additional feedback that could help Pythagora solve this bug"
|
||||
HUMAN_INTERVENTION_QUESTION = "I need human intervention"
|
||||
CONTINUE_WHEN_DONE = 'When you\'re done, just click "Continue"'
|
||||
RUN_COMMAND = "Can I run command:"
|
||||
DEV_EXECUTE_TASK = "Do you want to execute the above task?"
|
||||
@ -1,2 +0,0 @@
|
||||
CONVO_ITERATIONS_LIMIT = 8
|
||||
LOGS_LINE_LIMIT = 20000
|
||||
@ -1,90 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
import sqlite3
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from alembic import command
|
||||
from alembic.config import Config
|
||||
from alembic.script import ScriptDirectory
|
||||
|
||||
|
||||
def get_latest_revision(alembic_cfg: Config) -> Optional[str]:
|
||||
"""Get the most recent revision from available migration files."""
|
||||
script = ScriptDirectory.from_config(alembic_cfg)
|
||||
if script.get_heads():
|
||||
return script.get_heads()[0]
|
||||
return None
|
||||
|
||||
|
||||
def fix_alembic_version(db_path: str, version: str) -> None:
|
||||
"""Manually update alembic_version table to the specified version."""
|
||||
conn = sqlite3.connect(db_path)
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("UPDATE alembic_version SET version_num = ?", (version,))
|
||||
conn.commit()
|
||||
print(f"Successfully updated alembic_version to {version}")
|
||||
except sqlite3.Error as e:
|
||||
print(f"Error updating database: {e}")
|
||||
raise
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
def main():
|
||||
# Get the project root directory (where core/ is located)
|
||||
project_root = Path(__file__).parent.parent.parent
|
||||
|
||||
# Configure alembic
|
||||
alembic_ini = os.path.join(project_root, "core", "db", "alembic.ini")
|
||||
if not os.path.exists(alembic_ini):
|
||||
print(f"Error: Could not find alembic.ini at {alembic_ini}")
|
||||
return 1
|
||||
|
||||
alembic_cfg = Config(alembic_ini)
|
||||
|
||||
# Get the database path from alembic.ini
|
||||
db_url = alembic_cfg.get_main_option("sqlalchemy.url")
|
||||
if not db_url.startswith("sqlite:///"):
|
||||
print("Error: This script only works with SQLite databases")
|
||||
return 1
|
||||
|
||||
db_path = db_url.replace("sqlite:///", "")
|
||||
db_path = os.path.join(project_root, db_path)
|
||||
|
||||
if not os.path.exists(db_path):
|
||||
print(f"Database file not found at {db_path}")
|
||||
create_new = input("Would you like to create a new database? (y/n): ")
|
||||
if create_new.lower() == "y":
|
||||
print("Creating new database and running migrations...")
|
||||
command.upgrade(alembic_cfg, "head")
|
||||
print("Done!")
|
||||
return 0
|
||||
return 1
|
||||
|
||||
# Get the latest available revision
|
||||
latest_revision = get_latest_revision(alembic_cfg)
|
||||
if not latest_revision:
|
||||
print("Error: No migration versions found")
|
||||
return 1
|
||||
|
||||
print(f"Latest available revision: {latest_revision}")
|
||||
|
||||
try:
|
||||
# Update the version in the database
|
||||
fix_alembic_version(db_path, latest_revision)
|
||||
|
||||
# Run migrations to ensure database schema is up to date
|
||||
print("Running migrations to ensure database schema is current...")
|
||||
command.upgrade(alembic_cfg, "head")
|
||||
|
||||
print("Database successfully fixed and upgraded!")
|
||||
return 0
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
exit(main())
|
||||
@ -1,54 +0,0 @@
|
||||
"""move metadata from file to file content table
|
||||
|
||||
Revision ID: 0173e14719aa
|
||||
Revises: 3968d770dced
|
||||
Create Date: 2025-05-15 15:33:03.084670
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "0173e14719aa"
|
||||
down_revision: Union[str, None] = "3968d770dced"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Add meta column to file_contents
|
||||
with op.batch_alter_table("file_contents", schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column("meta", sa.JSON(), server_default="{}", nullable=False))
|
||||
|
||||
# Copy data from files.meta to file_contents.meta
|
||||
op.execute("""
|
||||
UPDATE file_contents
|
||||
SET meta = files.meta
|
||||
FROM files
|
||||
WHERE file_contents.id = files.content_id
|
||||
""")
|
||||
|
||||
# Drop meta column from files
|
||||
with op.batch_alter_table("files", schema=None) as batch_op:
|
||||
batch_op.drop_column("meta")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# Add meta column back to files
|
||||
with op.batch_alter_table("files", schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column("meta", sa.JSON(), server_default="{}", nullable=False))
|
||||
|
||||
# Copy data from file_contents.meta back to files.meta
|
||||
op.execute("""
|
||||
UPDATE files
|
||||
SET meta = file_contents.meta
|
||||
FROM file_contents
|
||||
WHERE files.content_id = file_contents.id
|
||||
""")
|
||||
|
||||
# Drop meta column from file_contents
|
||||
with op.batch_alter_table("file_contents", schema=None) as batch_op:
|
||||
batch_op.drop_column("meta")
|
||||
@ -1,34 +0,0 @@
|
||||
"""vacuum database
|
||||
|
||||
Revision ID: 0173e14719ab
|
||||
Revises: 69e50fdaf067
|
||||
Create Date: 2025-05-15 15:33:03.084670
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
from sqlalchemy import text
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "0173e14719ab"
|
||||
down_revision: Union[str, None] = "69e50fdaf067"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Get connection
|
||||
connection = op.get_bind()
|
||||
|
||||
# Temporarily disable journal mode
|
||||
connection.execute(text("PRAGMA journal_mode = OFF"))
|
||||
|
||||
# Run VACUUM
|
||||
connection.execute(text("VACUUM"))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# VACUUM is not reversible
|
||||
pass
|
||||
@ -1,34 +0,0 @@
|
||||
"""Add project type to project
|
||||
|
||||
Revision ID: 3968d770dced
|
||||
Revises: f708791b9270
|
||||
Create Date: 2025-02-15 10:30:13.163098
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "3968d770dced"
|
||||
down_revision: Union[str, None] = "f708791b9270"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table("projects", schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column("project_type", sa.String(), nullable=False, server_default="node"))
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table("projects", schema=None) as batch_op:
|
||||
batch_op.drop_column("project_type")
|
||||
|
||||
# ### end Alembic commands ###
|
||||
@ -1,48 +0,0 @@
|
||||
"""Add chat messages and convos
|
||||
|
||||
Revision ID: 675268601278
|
||||
Revises: 0173e14719ab
|
||||
Create Date: 2025-05-14 10:38:19.130649
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import func
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "675268601278"
|
||||
down_revision: Union[str, None] = "0173e14719ab"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Create chat_convos table
|
||||
op.create_table(
|
||||
"chat_convos",
|
||||
sa.Column("id", sa.Integer(), autoincrement=True, primary_key=True),
|
||||
sa.Column("convo_id", sa.Uuid(), nullable=False, unique=True),
|
||||
sa.Column(
|
||||
"project_state_id", sa.Uuid(), sa.ForeignKey("project_states.id", ondelete="CASCADE"), nullable=False
|
||||
),
|
||||
sa.Column("created_at", sa.DateTime, server_default=func.now(), nullable=False),
|
||||
)
|
||||
|
||||
# Create chat_messages table
|
||||
op.create_table(
|
||||
"chat_messages",
|
||||
sa.Column("id", sa.Uuid(), primary_key=True, nullable=False),
|
||||
sa.Column("convo_id", sa.Uuid(), sa.ForeignKey("chat_convos.convo_id", ondelete="CASCADE"), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime, server_default=func.now(), nullable=False),
|
||||
sa.Column("message_type", sa.String(), nullable=False),
|
||||
sa.Column("message", sa.String(), nullable=False),
|
||||
sa.Column("prev_message_id", sa.Uuid(), sa.ForeignKey("chat_messages.id", ondelete="SET NULL"), nullable=True),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table("chat_messages")
|
||||
op.drop_table("chat_convos")
|
||||
@ -1,143 +0,0 @@
|
||||
"""move knowledge base to separate table
|
||||
|
||||
Revision ID: 69e50fdaf067
|
||||
Revises: 0173e14719aa
|
||||
Create Date: 2025-05-15 17:27:50.312917
|
||||
|
||||
"""
|
||||
|
||||
import json
|
||||
from typing import Sequence, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import JSON, Column, Integer, MetaData, Table, insert, text
|
||||
from sqlalchemy.dialects import sqlite
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "69e50fdaf067"
|
||||
down_revision: Union[str, None] = "0173e14719aa"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Create the new knowledge_bases table
|
||||
op.create_table(
|
||||
"knowledge_bases",
|
||||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column("pages", sa.JSON(), server_default="[]", nullable=False),
|
||||
sa.Column("apis", sa.JSON(), server_default="[]", nullable=False),
|
||||
sa.Column("user_options", sa.JSON(), server_default="{}", nullable=False),
|
||||
sa.Column("utility_functions", sa.JSON(), server_default="[]", nullable=False),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_knowledge_bases")),
|
||||
)
|
||||
|
||||
# Add knowledge_base_id column to project_states
|
||||
with op.batch_alter_table("project_states", schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column("knowledge_base_id", sa.Integer(), nullable=True))
|
||||
|
||||
# Get connection for data migration
|
||||
connection = op.get_bind()
|
||||
|
||||
# Create a table object for knowledge_bases
|
||||
metadata = MetaData()
|
||||
knowledge_bases = Table(
|
||||
"knowledge_bases",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True),
|
||||
Column("pages", JSON),
|
||||
Column("apis", JSON),
|
||||
Column("user_options", JSON),
|
||||
Column("utility_functions", JSON),
|
||||
)
|
||||
|
||||
# Keep track of unique knowledge bases to avoid redundancy
|
||||
kb_cache = {}
|
||||
|
||||
# Migrate data from old knowledge_base column to new table
|
||||
project_states = connection.execute(text("SELECT id, knowledge_base FROM project_states")).fetchall()
|
||||
for state_id, kb_data_str in project_states:
|
||||
if kb_data_str:
|
||||
try:
|
||||
# Parse the JSON string into a dictionary
|
||||
kb_data = json.loads(kb_data_str) if isinstance(kb_data_str, str) else kb_data_str
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
# If parsing fails, use empty defaults
|
||||
kb_data = {}
|
||||
|
||||
# Create a cache key from the knowledge base content
|
||||
cache_key = json.dumps(
|
||||
{
|
||||
"pages": kb_data.get("pages", []),
|
||||
"apis": kb_data.get("apis", []),
|
||||
"user_options": kb_data.get("user_options", {}),
|
||||
"utility_functions": kb_data.get("utility_functions", []),
|
||||
},
|
||||
sort_keys=True,
|
||||
)
|
||||
|
||||
if cache_key not in kb_cache:
|
||||
# Insert new knowledge base record
|
||||
stmt = insert(knowledge_bases).values(
|
||||
pages=kb_data.get("pages", []),
|
||||
apis=kb_data.get("apis", []),
|
||||
user_options=kb_data.get("user_options", {}),
|
||||
utility_functions=kb_data.get("utility_functions", []),
|
||||
)
|
||||
result = connection.execute(stmt)
|
||||
kb_cache[cache_key] = result.inserted_primary_key[0]
|
||||
|
||||
# Update project state to reference the knowledge base
|
||||
kb_id = kb_cache[cache_key]
|
||||
connection.execute(
|
||||
text("UPDATE project_states SET knowledge_base_id = :kb_id WHERE id = :state_id"),
|
||||
{"kb_id": kb_id, "state_id": state_id},
|
||||
)
|
||||
|
||||
# Make knowledge_base_id not nullable and add foreign key constraint
|
||||
with op.batch_alter_table("project_states", schema=None) as batch_op:
|
||||
batch_op.alter_column("knowledge_base_id", nullable=False)
|
||||
batch_op.create_foreign_key(
|
||||
batch_op.f("fk_project_states_knowledge_base_id_knowledge_bases"),
|
||||
"knowledge_bases",
|
||||
["knowledge_base_id"],
|
||||
["id"],
|
||||
)
|
||||
batch_op.drop_column("knowledge_base")
|
||||
|
||||
# Clean up llm_requests table
|
||||
op.execute("DELETE FROM llm_requests")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# Add back the knowledge_base column
|
||||
with op.batch_alter_table("project_states", schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column("knowledge_base", sqlite.JSON(), server_default=sa.text("'{}'"), nullable=False))
|
||||
|
||||
# Get connection for data migration
|
||||
connection = op.get_bind()
|
||||
|
||||
# Migrate data back from knowledge_bases table to project_states
|
||||
results = connection.execute(
|
||||
text("""
|
||||
SELECT ps.id, kb.pages, kb.apis, kb.user_options, kb.utility_functions
|
||||
FROM project_states ps
|
||||
JOIN knowledge_bases kb ON ps.knowledge_base_id = kb.id
|
||||
""")
|
||||
).fetchall()
|
||||
|
||||
for state_id, pages, apis, user_options, utility_functions in results:
|
||||
# Create the knowledge base data structure
|
||||
kb_data = {"pages": pages, "apis": apis, "user_options": user_options, "utility_functions": utility_functions}
|
||||
connection.execute(
|
||||
text("UPDATE project_states SET knowledge_base = :kb_data WHERE id = :state_id"),
|
||||
{"kb_data": json.dumps(kb_data), "state_id": state_id},
|
||||
)
|
||||
|
||||
# Remove the knowledge_base_id column and knowledge_bases table
|
||||
with op.batch_alter_table("project_states", schema=None) as batch_op:
|
||||
batch_op.drop_constraint(batch_op.f("fk_project_states_knowledge_base_id_knowledge_bases"), type_="foreignkey")
|
||||
batch_op.drop_column("knowledge_base_id")
|
||||
|
||||
op.drop_table("knowledge_bases")
|
||||
@ -1,34 +0,0 @@
|
||||
"""Adding knowledge_base field to ProjectState
|
||||
|
||||
Revision ID: f708791b9270
|
||||
Revises: c8905d4ce784
|
||||
Create Date: 2024-12-22 12:13:14.979169
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "f708791b9270"
|
||||
down_revision: Union[str, None] = "c8905d4ce784"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table("project_states", schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column("knowledge_base", sa.JSON(), server_default="{}", nullable=False))
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table("project_states", schema=None) as batch_op:
|
||||
batch_op.drop_column("knowledge_base")
|
||||
|
||||
# ### end Alembic commands ###
|
||||
@ -1,48 +0,0 @@
|
||||
from datetime import datetime
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from sqlalchemy import ForeignKey, select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from core.db.models import Base
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.db.models import ChatMessage, ProjectState
|
||||
|
||||
|
||||
class ChatConvo(Base):
|
||||
__tablename__ = "chat_convos"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
convo_id: Mapped[UUID] = mapped_column(default=uuid4, unique=True)
|
||||
project_state_id: Mapped[UUID] = mapped_column(ForeignKey("project_states.id", ondelete="CASCADE"))
|
||||
created_at: Mapped[datetime] = mapped_column(server_default=func.now())
|
||||
|
||||
# Relationships
|
||||
project_state: Mapped["ProjectState"] = relationship(back_populates="chat_convos", lazy="selectin")
|
||||
messages: Mapped[list["ChatMessage"]] = relationship(
|
||||
back_populates="convo", cascade="all,delete-orphan", lazy="selectin"
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
async def get_chat_history(session: AsyncSession, convo_id) -> list["ChatMessage"]:
|
||||
from core.db.models import ChatMessage
|
||||
|
||||
result = await session.execute(select(ChatMessage).where(ChatMessage.convo_id == convo_id))
|
||||
return result.scalars().all()
|
||||
|
||||
@staticmethod
|
||||
async def get_project_state_for_convo_id(session: AsyncSession, convo_id) -> Optional["ProjectState"]:
|
||||
from core.db.models import ChatConvo, ProjectState
|
||||
|
||||
result = await session.execute(select(ChatConvo).where(ChatConvo.convo_id == convo_id))
|
||||
chat_convo = result.scalars().first()
|
||||
|
||||
if not chat_convo:
|
||||
return None
|
||||
|
||||
result = await session.execute(select(ProjectState).where(ProjectState.id == chat_convo.project_state_id))
|
||||
return result.scalars().one_or_none()
|
||||
@ -1,23 +0,0 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from sqlalchemy import ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from core.db.models import Base, ChatConvo
|
||||
|
||||
|
||||
class ChatMessage(Base):
|
||||
__tablename__ = "chat_messages"
|
||||
|
||||
id: Mapped[UUID] = mapped_column(primary_key=True, default=uuid4)
|
||||
convo_id: Mapped[UUID] = mapped_column(ForeignKey("chat_convos.convo_id", ondelete="CASCADE"))
|
||||
created_at: Mapped[datetime] = mapped_column(server_default=func.now())
|
||||
message_type: Mapped[str] = mapped_column()
|
||||
message: Mapped[str] = mapped_column()
|
||||
prev_message_id: Mapped[Optional[UUID]] = mapped_column(ForeignKey("chat_messages.id", ondelete="SET NULL"))
|
||||
|
||||
# Relationships
|
||||
convo: Mapped["ChatConvo"] = relationship(back_populates="messages", lazy="selectin")
|
||||
@ -1,61 +0,0 @@
|
||||
from copy import deepcopy
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import JSON, delete, distinct, select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from core.db.models.base import Base
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.db.models import ProjectState
|
||||
|
||||
|
||||
class KnowledgeBase(Base):
|
||||
"""Model for storing project knowledge base.
|
||||
|
||||
This model stores various pieces of project-related information:
|
||||
- pages: List of implemented frontend pages
|
||||
- apis: List of API endpoints and their implementation status
|
||||
- user_options: User configuration options for the project
|
||||
- utility_functions: List of utility functions with their status, input/output values
|
||||
"""
|
||||
|
||||
__tablename__ = "knowledge_bases"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
pages: Mapped[list[str]] = mapped_column(JSON, default=list, server_default="[]")
|
||||
apis: Mapped[list[dict]] = mapped_column(JSON, default=list, server_default="[]")
|
||||
user_options: Mapped[dict] = mapped_column(JSON, default=dict, server_default="{}")
|
||||
utility_functions: Mapped[list[dict]] = mapped_column(JSON, default=list, server_default="[]")
|
||||
|
||||
# Relationships
|
||||
project_states: Mapped[list["ProjectState"]] = relationship(back_populates="knowledge_base", lazy="raise")
|
||||
|
||||
def clone(self) -> "KnowledgeBase":
|
||||
"""
|
||||
Clone the knowledge base.
|
||||
|
||||
Creates a new KnowledgeBase instance with the same data but new ID.
|
||||
Used when the knowledge base needs to be modified to maintain immutability
|
||||
of previous states.
|
||||
"""
|
||||
return KnowledgeBase(
|
||||
pages=deepcopy(self.pages),
|
||||
apis=deepcopy(self.apis),
|
||||
user_options=deepcopy(self.user_options),
|
||||
utility_functions=deepcopy(self.utility_functions),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
async def delete_orphans(cls, session: AsyncSession):
|
||||
"""
|
||||
Delete KnowledgeBase objects that are not referenced by any ProjectState object.
|
||||
|
||||
:param session: The database session.
|
||||
"""
|
||||
from core.db.models import ProjectState
|
||||
|
||||
await session.execute(
|
||||
delete(KnowledgeBase).where(~KnowledgeBase.id.in_(select(distinct(ProjectState.knowledge_base_id))))
|
||||
)
|
||||
@ -1,62 +0,0 @@
|
||||
from typing import Optional
|
||||
|
||||
import httpx
|
||||
from httpx import AsyncClient
|
||||
|
||||
from core.config import LLMProvider
|
||||
from core.llm.base import BaseLLMClient
|
||||
from core.llm.convo import Convo
|
||||
from core.log import get_logger
|
||||
|
||||
log = get_logger(__name__)
|
||||
|
||||
|
||||
class RelaceClient(BaseLLMClient):
|
||||
provider = LLMProvider.RELACE
|
||||
|
||||
def _init_client(self):
|
||||
self.headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": f"Bearer {self.state_manager.get_access_token() if self.state_manager.get_access_token() is not None else self.config.api_key if self.config.api_key is not None else ''}",
|
||||
}
|
||||
self.client = AsyncClient()
|
||||
|
||||
async def _make_request(
|
||||
self,
|
||||
convo: Convo,
|
||||
temperature: Optional[float] = None,
|
||||
json_mode: bool = False,
|
||||
) -> tuple[str, int, int]:
|
||||
"""
|
||||
Make a POST request to the Relace API to merge code snippets.
|
||||
|
||||
:param convo: Conversation object containing initial code and edit snippet.
|
||||
:param temperature: Not used in this implementation.
|
||||
:param json_mode: Not used in this implementation.
|
||||
:return: Merged code, input tokens (0), and output tokens (0).
|
||||
"""
|
||||
data = {
|
||||
"initialCode": convo.messages[0]["content"]["initialCode"],
|
||||
"editSnippet": convo.messages[0]["content"]["editSnippet"],
|
||||
"model": self.config.model,
|
||||
}
|
||||
|
||||
async with httpx.AsyncClient(transport=httpx.AsyncHTTPTransport()) as client:
|
||||
try:
|
||||
response = await client.post(
|
||||
"https://api.pythagora.io/v1/relace/merge", headers=self.headers, json=data
|
||||
)
|
||||
response.raise_for_status()
|
||||
response_json = response.json()
|
||||
return (
|
||||
response_json.get("content", ""),
|
||||
response_json.get("inputTokens", 0),
|
||||
response_json.get("outputTokens", 0),
|
||||
)
|
||||
except Exception as e:
|
||||
# Fall back to other ai provider
|
||||
log.debug(f"Relace API request failed: {e}")
|
||||
return ("", 0, 0)
|
||||
|
||||
|
||||
__all__ = ["RelaceClient"]
|
||||
@ -1,4 +0,0 @@
|
||||
The developer wants to ask you a question. Here is the question:
|
||||
{{question}}
|
||||
|
||||
Please answer and refer to all the files in the repository and everything we've talked about so far but do not form your answer in any way that was asked for before, just answer the question as if you're talking to a colleague.
|
||||
@ -1,7 +0,0 @@
|
||||
Tell me the most important logs that are relevant for this issue. For each log, tell me the the following:
|
||||
1. line in the code (eg. `print(...)`, `console.log(...)`, etc.) that generated the log
|
||||
2. what file is the log in (eg. `index.js`, `routes/users.js`, etc. - make sure to put the entire path like listed above)
|
||||
2. the current output of that log (make sure not to put the entire log output but maximum 5-10 lines of the output)
|
||||
3. the expected output of that log (also make sure to put maximum of 5-10 lines of the output)
|
||||
4. should the log be different from the current output or are the current and expected output the same
|
||||
5. a brief explanation of why the output is incorrect and what should be different here (use maximum 2-3 sentences)
|
||||
@ -1,6 +0,0 @@
|
||||
The human is sending you a hint about how to solve this bug. Here is what human said:
|
||||
```
|
||||
{{ human_hint }}
|
||||
```
|
||||
|
||||
Now, based on this hint, break down exactly what the problem is, what is the solution to this problem and how can we implement this solution so that the bug is fixed.
|
||||
@ -1,25 +1,13 @@
|
||||
{% if backend_logs and backend_logs|trim %}
|
||||
Here are the logs we added to the backend:
|
||||
{% if backend_logs is not none %}Here are the logs we added to the backend:
|
||||
```
|
||||
{{ backend_logs }}
|
||||
```
|
||||
{% endif %}{% if frontend_logs and frontend_logs|trim %}
|
||||
{% endif %}{% if frontend_logs is not none %}
|
||||
Here are the logs we added to the frontend:
|
||||
```
|
||||
{{ frontend_logs }}
|
||||
```
|
||||
{% endif %}{% if user_feedback and user_feedback|trim %}
|
||||
Finally, here is a hint from a human who tested the app:
|
||||
```
|
||||
{{ user_feedback }}
|
||||
```
|
||||
When you're thinking about what to do next, take into the account human's feedback.
|
||||
{% endif %}{% if fix_attempted %}
|
||||
The problem wasn't solved with the last changes. You have 2 options - to tell me exactly where is the problem happening or to add more logs to better determine where is the problem. If you think we should add more logs around the code to better understand the problem, tell me code snippets in which we should add the logs. If you think you know where the issue is, don't add any new logs but explain what log print tell point you to the problem, what the problem is, what is the solution to this problem and how the solution will fix the problem. What is your answer? Make sure not to repeat mistakes from before that didn't work.
|
||||
{% endif %}
|
||||
{% if not (backend_logs and backend_logs|trim) and
|
||||
not (frontend_logs and frontend_logs|trim) and
|
||||
not (user_feedback and user_feedback|trim) and
|
||||
not fix_attempted %}
|
||||
Human didn't supply any data
|
||||
{% endif %}
|
||||
{% if backend_logs is none and frontend_logs is none and fix_attempted == false %}Human didn't supply any data{% endif %}
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
This also didn't help to solve the issue so we can conclude that you are unable to solve this problem yourself so I got a human here who will help you out.
|
||||
|
||||
First, focus on the problem you're facing and explain it to the human. Explain what is the issue that you're working in and what should the human try to do to solve this problem. Is there anything the human can look at that you don't have access to - a database, API response, etc.? If there is something for the human to look at, specify exactly how can the human obtain this information. Keep the answer short and to the point.
|
||||
|
||||
@ -1 +0,0 @@
|
||||
Please tell me more about the problem we're working on and don't repeat things you said before but tell me something I don't know.
|
||||
@ -1,35 +0,0 @@
|
||||
This is the description of the app you are working with:
|
||||
{{ initial_description }}
|
||||
|
||||
{% if task_description is defined and task_description %}
|
||||
Currently, you are working on the following task:
|
||||
{{ task_description }}
|
||||
{% endif %}
|
||||
|
||||
{% if bug_hunt_cycle_user_feedback is defined and bug_hunt_cycle_user_feedback %}
|
||||
You are currently working on a bug report that the user reported like this:
|
||||
{{ bug_hunt_cycle_user_feedback }}
|
||||
{% endif %}
|
||||
|
||||
{% if testing_instructions is defined and testing_instructions %}
|
||||
The user is currently testing how the task was implemented and was given the following instructions to test the app:
|
||||
{{ testing_instructions }}
|
||||
{% endif %}
|
||||
|
||||
{% if command_run is defined and command_run %}
|
||||
Currently, you're waiting for the user to approve the following command to be run:
|
||||
```text
|
||||
{{ command_run }}
|
||||
```
|
||||
{% endif %}
|
||||
|
||||
{% if human_intervention is defined and human_intervention %}
|
||||
Currently, you asked the human user to do the following steps in order to continue with the development of the app:
|
||||
```text
|
||||
{{ human_intervention }}
|
||||
```
|
||||
{% endif %}
|
||||
|
||||
{% if user_input is defined and user_input %}
|
||||
Now, the human asked said the following: `{{ user_input }}`. Please respond as a professional developer, be helpful and focus on what the human said.
|
||||
{% endif %}
|
||||
@ -1,5 +0,0 @@
|
||||
You are a world class full stack software developer working in a team.
|
||||
|
||||
You write modular, well-organized code split across files that are not too big, so that the codebase is maintainable. You include proper error handling and logging for your clean, readable, production-level quality code.
|
||||
|
||||
Your job is to implement tasks assigned by your tech lead, following task implementation instructions.
|
||||
@ -0,0 +1,2 @@
|
||||
{# This is the same template as for Developer's breakdown because Code Reviewer is reusing it in a conversation #}
|
||||
{% extends "developer/breakdown.prompt" %}
|
||||
@ -0,0 +1,2 @@
|
||||
You are a world class full stack software developer. You write modular, clean, maintainable, production-ready code.
|
||||
Your job is to review changes implemented by your junior team members.
|
||||
@ -1,27 +1,38 @@
|
||||
{% if state.current_task %}
|
||||
We're starting work on a new task for a project we're working on.
|
||||
|
||||
{% include "partials/project_details.prompt" %}
|
||||
{% include "partials/features_list.prompt" %}
|
||||
|
||||
We've broken the development of the project down to these tasks:
|
||||
```
|
||||
{% for task in state.tasks %}
|
||||
{{ loop.index }}. {{ task.description }}{% if task.get("status") == "done" %} (completed){% endif %}
|
||||
|
||||
{% endfor %}
|
||||
```
|
||||
|
||||
The next task we need to work on, and have to focus on, is this task:
|
||||
```
|
||||
{{ state.current_task.description }}
|
||||
```
|
||||
{% endif %}
|
||||
|
||||
{% if user_feedback %}User who was using the app sent you this feedback:
|
||||
```
|
||||
{{ user_feedback }}
|
||||
```
|
||||
{% endif %}
|
||||
|
||||
{% if solution_description %}
|
||||
{% endif %}{% if solution_description %}
|
||||
Focus on solving this issue in the following way:
|
||||
```
|
||||
{{ solution_description }}
|
||||
```
|
||||
{% endif %}
|
||||
|
||||
{% include "partials/files_descriptions.prompt" %}
|
||||
|
||||
**IMPORTANT**
|
||||
The files necessary for a developer to understand, modify, implement, and test the current task are considered to be relevant files.
|
||||
Your job is select which of existing files below are relevant for the current task. You have to select ALL files that are relevant to the current task. Think step by step of everything that has to be done in this task and which files contain needed information.
|
||||
Your job is select which of existing files are relevant for the current task. From the above list of files that app currently contains, you have to select ALL files that are relevant to the current task. Think step by step of everything that has to be done in this task and which files contain needed information.
|
||||
|
||||
{% include "partials/files_descriptions.prompt" %}
|
||||
{% include "partials/filter_files_actions.prompt" %}
|
||||
|
||||
{% include "partials/relative_paths.prompt" %}
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
{% if read_files %}
|
||||
Here are the files that you wanted to read:
|
||||
---START_OF_FILES---
|
||||
{% for file in read_files %}
|
||||
File **`{{ file.path }}`** ({{file.content.content.splitlines()|length}} lines of code):
|
||||
```
|
||||
{{ file.content.content }}```
|
||||
|
||||
{% endfor %}
|
||||
---END_OF_FILES---
|
||||
{% endif %}
|
||||
|
||||
{% include "partials/filter_files_actions.prompt" %}
|
||||
@ -1,64 +0,0 @@
|
||||
{% if user_feedback %}You're currently working on a frontend of an app that has the following description:
|
||||
{% else %}Create a very modern styled app with the following description:{% endif %}
|
||||
|
||||
```
|
||||
{{ description }}
|
||||
```
|
||||
|
||||
{% if summary is defined %}
|
||||
{{ summary }}
|
||||
{% elif state.specification.template_summary is defined %}
|
||||
{{ state.specification.template_summary }}
|
||||
{% endif %}
|
||||
|
||||
{% include "partials/files_list.prompt" %}
|
||||
|
||||
Use material design and nice icons for the design to be appealing and modern. Use the following libraries to make it very modern and slick:
|
||||
1. Shadcn: For the core UI components, providing modern, accessible, and customizable elements. You have already access to all components from this library inside ./src/components/ui folder, so do not modify/code them!
|
||||
2. Use lucide icons (npm install lucide-react)
|
||||
3. Heroicons: For a set of sleek, customizable icons that integrate well with modern designs.
|
||||
4. React Hook Form: For efficient form handling with minimal re-rendering, ensuring a smooth user experience in form-heavy applications.
|
||||
5. Use Tailwind built-in animations to enhance the visual appeal of the app
|
||||
6. Make the app look colorful and modern but also have the colors be subtle.
|
||||
7. Add logs around the code (not too many, just enough) to help with debugging.
|
||||
|
||||
Choose a flat color palette and make sure that the text is readable and follow design best practices to make the text readable. Also, Implement these design features onto the page - gradient background, frosted glass effects, rounded corner, buttons need to be in the brand colors, and interactive feedback on hover and focus.
|
||||
|
||||
IMPORTANT: Text needs to be readable and in positive typography space - this is especially true for modals - they must have a bright background
|
||||
|
||||
You must create all code for all pages of this website. If this is a some sort of a dashboard, put the navigation in the sidebar.
|
||||
|
||||
**IMPORTANT**
|
||||
{% if first_time_build %}
|
||||
Make sure to implement all functionality (button clicks, form submissions, etc.) and use mock data for all interactions to make the app look and feel real. **ALL MOCK DATA MUST** be in the `api/` folder and it **MUST NOT** ever be hardcoded in the components.
|
||||
{% endif %}
|
||||
|
||||
The body content should not overlap with the header navigation bar or footer navigation bar or the side navigation bar.
|
||||
|
||||
|
||||
{% if user_feedback %}
|
||||
User who was using the app "{{ state.branch.project.name }}" sent you this feedback:
|
||||
```
|
||||
{{ user_feedback }}
|
||||
```
|
||||
Now, start by writing all code that's needed to fix the problem that the user reported. Think about how routes are set up, how are variables called, and other important things, and mention files by name and where should all new functionality be called from. Then, tell me all the code that needs to be written to fix this issue.
|
||||
{% else %}
|
||||
Now, start by writing all code that's needed to get the frontend built for this app. Think about how routes are set up, how are variables called, and other important things, and mention files by name and where should all new functionality be called from. Then, tell me all the code that needs to be written to implement the frontend for this app and have it fully working and all commands that need to be run.
|
||||
{% endif %}
|
||||
|
||||
IMPORTANT: When suggesting/making changes in the file you must provide full content of the file! Do not use placeholders, or comments, or truncation in any way, but instead provide the full content of the file even the parts that are unchanged!
|
||||
When you want to run a command you must put `command:` before the command and then the command itself like shown in the examples in system prompt. NEVER run `npm run start` or `npm run dev` commands, user will run them after you provide the code. The user is using {{ os }}, so the commands must run on that operating system
|
||||
|
||||
{% if relevant_api_documentation is defined %}
|
||||
|
||||
Here is relevant API documentation you need to consult and follow as close as possible.
|
||||
You need to write only the frontend code for this app. The backend is already fully built and is documented with OpenAPI specification. You don't know the API endpoints yet so you need to mock all API requests but you must mock them based on the model definitions that are known. Here are the model definitions:
|
||||
~~START_OF_API_MODEL_DEFINITIONS~~
|
||||
{{ relevant_api_documentation }}
|
||||
~~END_OF_API_MODEL_DEFINITIONS~~
|
||||
|
||||
{% endif %}
|
||||
|
||||
**SUPER IMPORTANT**: You must **NEVER** mention or attempt to change any files on backend (`server/` folder) or any of these frontend files: `client/src/contexts/AuthContext.tsx`, `client/src/api/api.ts`, `client/src/api/auth.ts`. Regardless of what the user asks, you must not mention these files. If you can't find a solution without changing these files, just say so.
|
||||
|
||||
**SUPER IMPORTANT**: Never write huge files, always split huge files into smaller files. For example, use React components to split the code into smaller files to make them as reusable as possible.
|
||||
@ -1,6 +0,0 @@
|
||||
{{ file_content }}
|
||||
|
||||
I have external documentation in Swagger Open API format.
|
||||
Create a comma separated list of short words topics of the description of the file so that I can search for the relevant parts of the documentation.
|
||||
Use up to 5 words max.
|
||||
If the file does not need external API documentation, just return "None" and nothing else, no explanation needed.
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue