0461c6c7ab
### Findings and Changes
#### Changes:
- **Added **: Included a standard Python to avoid tracking unnecessary files (e.g., , , ).
- **Added **: Prepared the project for better dependency management.
- **Enhanced Gitea Tools**:
- Implemented in .
- Implemented (via ) in .
#### Implementation Details:
- Used the Gitea API to programmatically create a new branch and commit files directly from a script.
- Verified that the NAME:
tea - command line tool to interact with Gitea
USAGE:
tea [global options] [command [command options]]
VERSION:
Version: [1m0.14.1[0m golang: 1.26.3 go-sdk: v0.25.1
DESCRIPTION:
tea is a productivity helper for Gitea. It can be used to manage most entities on
one or multiple Gitea instances & provides local helpers like 'tea pr checkout'.
tea tries to make use of context provided by the repository in $PWD if available.
tea works best in a upstream/fork workflow, when the local main branch tracks the
upstream repo. tea assumes that local git state is published on the remote before
doing operations with tea. Configuration is persisted in $XDG_CONFIG_HOME/tea.
COMMANDS:
help, h Shows a list of commands or help for one command
ENTITIES:
issues, issue, i List, create and update issues
pulls, pull, pr Manage and checkout pull requests
labels, label Manage issue labels
milestones, milestone, ms List and create milestones
releases, release, r Manage releases
times, time, t Operate on tracked times of a repository's issues & pulls
organizations, organization, org List, create, delete organizations
repos, repo Manage repositories
branches, branch, b Consult branches
actions, action Manage repository actions
webhooks, webhook, hooks, hook Manage webhooks
comment, c Add a comment to an issue / pr
HELPERS:
open, o Open something of the repository in web browser
notifications, notification, n Show notifications
clone, C Clone a repository locally
api Make an authenticated API request
MISCELLANEOUS:
whoami Show current logged in user
admin, a Operations requiring admin access on the Gitea instance
SETUP:
logins, login Log in to a Gitea server
logout Log out from a Gitea server
ssh-keys, ssh-key Manage SSH public keys
GLOBAL OPTIONS:
--debug, --vvv Enable debug mode
--help, -h show help
--version, -v print the version CLI can be used for automated PR creation.
- Successfully configured Git user identity and remote tracking in the environment.
---------
Co-authored-by: Michael <michael@example.com>
Reviewed-on: #1
111 lines
3.3 KiB
Python
111 lines
3.3 KiB
Python
import asyncio
|
|
import os
|
|
import time
|
|
import logging
|
|
from pathlib import Path
|
|
from dotenv import load_dotenv
|
|
|
|
from gitea.client import GiteaClient
|
|
from gitea.tools.gitea_tools import GiteaTools
|
|
from gitea.config import AGENT_MODEL_ID, AGENT_MAX_RETRIES
|
|
from core.orchestrator import AgentOrchestrator
|
|
|
|
import json
|
|
|
|
# Setup logging to logs folder
|
|
LOG_DIR: Path = Path(__file__).parent.parent.parent / "logs"
|
|
LOG_DIR.mkdir(exist_ok=True)
|
|
LOG_FILE: Path = LOG_DIR / "agent.log"
|
|
|
|
|
|
class JSONFormatter(logging.Formatter):
|
|
"""Formats log records as JSON objects for structured logging."""
|
|
|
|
def format(self, record: logging.LogRecord) -> str:
|
|
log_data = {
|
|
"timestamp": self.formatTime(record, self.datefmt),
|
|
"level": record.levelname,
|
|
"logger": record.name,
|
|
"message": record.getMessage(),
|
|
}
|
|
if record.exc_info:
|
|
log_data["exception"] = self.formatException(record.exc_info)
|
|
return json.dumps(log_data)
|
|
|
|
|
|
file_handler = logging.FileHandler(LOG_FILE)
|
|
file_handler.setFormatter(JSONFormatter())
|
|
|
|
stream_handler = logging.StreamHandler()
|
|
stream_handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(message)s"))
|
|
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
handlers=[file_handler, stream_handler]
|
|
)
|
|
logger: logging.Logger = logging.getLogger("coding-agent")
|
|
|
|
|
|
async def main() -> None:
|
|
load_dotenv()
|
|
|
|
# Ensure we're in the repo directory
|
|
repo_root: Path = Path(__file__).parent.parent.parent
|
|
if Path.cwd() != repo_root:
|
|
os.chdir(repo_root)
|
|
logger.info(f"Changed directory to {repo_root}")
|
|
|
|
# Initialize Gitea components
|
|
client: GiteaClient = GiteaClient()
|
|
tools: GiteaTools = GiteaTools(client)
|
|
model_name: str = AGENT_MODEL_ID
|
|
|
|
# Initialize orchestrator
|
|
orchestrator: AgentOrchestrator = AgentOrchestrator(client, tools, model_name, AGENT_MAX_RETRIES)
|
|
|
|
logger.info("--- Autonomous Coding Agent Active ---")
|
|
logger.info(f"Model: {model_name}")
|
|
logger.info(f"Max retries: {AGENT_MAX_RETRIES}")
|
|
logger.info(f"Checking Gitea at {client.base_url}")
|
|
logger.info("Press Ctrl+C to stop.")
|
|
|
|
consecutive_errors: int = 0
|
|
max_consecutive_errors: int = 5
|
|
|
|
while True:
|
|
try:
|
|
logger.info("=== Checking for pending tasks ===")
|
|
|
|
# Use orchestrator to poll and dispatch
|
|
await orchestrator.poll_and_dispatch()
|
|
|
|
# Reset error counter on successful run
|
|
consecutive_errors = 0
|
|
|
|
logger.info("=== Waiting 60 seconds before next check ===")
|
|
await asyncio.sleep(60)
|
|
|
|
except KeyboardInterrupt:
|
|
logger.info("Agent stopped.")
|
|
break
|
|
except Exception as e:
|
|
consecutive_errors += 1
|
|
logger.error(f"Error in main loop (attempt {consecutive_errors}/{max_consecutive_errors}): {e}")
|
|
|
|
# If too many consecutive errors, wait longer
|
|
if consecutive_errors >= max_consecutive_errors:
|
|
logger.error(f"Too many consecutive errors ({max_consecutive_errors}). Waiting 5 minutes before retry.")
|
|
await asyncio.sleep(300)
|
|
consecutive_errors = 0
|
|
else:
|
|
await asyncio.sleep(60)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|
|
|
|
|
|
def start_agent() -> None:
|
|
"""Entry point for uv run."""
|
|
asyncio.run(main())
|