Compare commits
1 Commits
efcec4e122
...
fix/issue-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
798bee0f79 |
@@ -1,18 +0,0 @@
|
|||||||
repos:
|
|
||||||
- repo: https://github.com/shellcheck-py/shellcheck-py
|
|
||||||
rev: v0.9.0.6
|
|
||||||
hooks:
|
|
||||||
- id: shellcheck
|
|
||||||
|
|
||||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
||||||
rev: v0.1.8
|
|
||||||
hooks:
|
|
||||||
- id: ruff
|
|
||||||
args: [--fix]
|
|
||||||
- id: ruff-format
|
|
||||||
|
|
||||||
- repo: https://github.com/commitizen-tools/commitizen
|
|
||||||
rev: v3.2.0
|
|
||||||
hooks:
|
|
||||||
- id: commitizen
|
|
||||||
stages: [commit-msg]
|
|
||||||
@@ -16,38 +16,6 @@
|
|||||||
- Test changes before submitting
|
- Test changes before submitting
|
||||||
- See [VERSIONING.md](VERSIONING.md) for backport compatibility rules
|
- See [VERSIONING.md](VERSIONING.md) for backport compatibility rules
|
||||||
|
|
||||||
## Pre-commit Hooks
|
|
||||||
|
|
||||||
This repository uses [pre-commit](https://pre-commit.com/) for linting and commit message enforcement.
|
|
||||||
|
|
||||||
### Setup
|
|
||||||
|
|
||||||
```bash
|
|
||||||
pip install pre-commit
|
|
||||||
pre-commit install
|
|
||||||
```
|
|
||||||
|
|
||||||
### Hooks
|
|
||||||
|
|
||||||
- **shellcheck** — Lints bash scripts
|
|
||||||
- **ruff** — Lints and formats Python
|
|
||||||
- **commitizen** — Enforces [Conventional Commits](https://www.conventionalcommits.org/) format
|
|
||||||
|
|
||||||
### Commit Message Format
|
|
||||||
|
|
||||||
Use Conventional Commits format:
|
|
||||||
|
|
||||||
```
|
|
||||||
type(scope): message
|
|
||||||
|
|
||||||
# Examples
|
|
||||||
fix(session): handle missing session gracefully
|
|
||||||
feat(pm): add queue daemon for task delegation
|
|
||||||
docs: update contributing guide
|
|
||||||
```
|
|
||||||
|
|
||||||
Types: `fix`, `feat`, `docs`, `refactor`, `chore`, `test`
|
|
||||||
|
|
||||||
## Branches
|
## Branches
|
||||||
|
|
||||||
### Primary Branches
|
### Primary Branches
|
||||||
|
|||||||
@@ -41,11 +41,6 @@ mask_sensitive_vars() {
|
|||||||
echo "$line"
|
echo "$line"
|
||||||
}
|
}
|
||||||
|
|
||||||
strip_ansi_codes() {
|
|
||||||
local line="${1:-}"
|
|
||||||
echo "$line" | sed 's/\x1b\[[0-9;]*m//g' | sed 's/\x1b\[[0-9;]*[a-zA-Z]//g'
|
|
||||||
}
|
|
||||||
|
|
||||||
load_agent_env() {
|
load_agent_env() {
|
||||||
local agent_type="${1:-base}"
|
local agent_type="${1:-base}"
|
||||||
local env_file="$ENV_DIR/${agent_type}.env"
|
local env_file="$ENV_DIR/${agent_type}.env"
|
||||||
|
|||||||
@@ -1,6 +1,40 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
source "$SCRIPT_DIR/kugetsu-config.sh"
|
||||||
|
|
||||||
|
log() {
|
||||||
|
local level="${1:-}"
|
||||||
|
local component="${2:-}"
|
||||||
|
local message="${3:-}"
|
||||||
|
local timestamp
|
||||||
|
timestamp=$(date -Iseconds)
|
||||||
|
|
||||||
|
case "$level" in
|
||||||
|
info|warn|error|debug) ;;
|
||||||
|
*)
|
||||||
|
echo "Error: log level must be info|warn|error|debug" >&2
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -z "$message" ]; then
|
||||||
|
message="$component"
|
||||||
|
component="${level}"
|
||||||
|
level="info"
|
||||||
|
fi
|
||||||
|
|
||||||
|
local masked
|
||||||
|
masked=$(mask_sensitive_vars "$message")
|
||||||
|
echo "[$timestamp] $level $component $masked"
|
||||||
|
}
|
||||||
|
|
||||||
|
log_debug() { log "debug" "$1" "${2:-}"; }
|
||||||
|
log_info() { log "info" "$1" "${2:-}"; }
|
||||||
|
log_warn() { log "warn" "$1" "${2:-}"; }
|
||||||
|
log_error() { log "error" "$1" "${2:-}"; }
|
||||||
|
|
||||||
cmd_logs() {
|
cmd_logs() {
|
||||||
local count="${1:-10}"
|
local count="${1:-10}"
|
||||||
|
|
||||||
@@ -24,9 +58,7 @@ cmd_logs() {
|
|||||||
echo ""
|
echo ""
|
||||||
echo "--- $log ---"
|
echo "--- $log ---"
|
||||||
tail -20 "$LOGS_DIR/$log" | while read line; do
|
tail -20 "$LOGS_DIR/$log" | while read line; do
|
||||||
line=$(strip_ansi_codes "$line")
|
echo " $(mask_sensitive_vars "$line")"
|
||||||
line=$(mask_sensitive_vars "$line")
|
|
||||||
echo " $line"
|
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -225,10 +225,7 @@ cmd_delegate() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local msg_file="$LOGS_DIR/msg-$new_session.txt"
|
nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run '$message' --session '$new_session'" >> "$log_file" 2>&1 &
|
||||||
printf '%s' "$message" > "$msg_file"
|
|
||||||
nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run '@$msg_file' --session '$new_session'" >> "$log_file" 2>&1 &
|
|
||||||
rm -f "$msg_file"
|
|
||||||
echo "Delegated to new session (logged to $(basename "$log_file"))"
|
echo "Delegated to new session (logged to $(basename "$log_file"))"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,22 +238,20 @@ create_session() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
local before_json=$(opencode session list --format=json 2>/dev/null)
|
local before_json=$(opencode session list --format=json 2>/dev/null)
|
||||||
local before_set=$(echo "$before_json" | python3 -c "import sys,json; sessions=json.load(sys.stdin); print('|'.join(s['id'] for s in sessions))" 2>/dev/null || echo "|")
|
local before_ids=$(echo "$before_json" | python3 -c "import sys,json; sessions=json.load(sys.stdin); print(' '.join(s['id'] for s in sessions))" 2>/dev/null || echo "")
|
||||||
|
|
||||||
opencode run --fork --session "$base_session" "new session" >/dev/null 2>&1
|
opencode run --fork --session "$base_session" "new session" 2>/dev/null
|
||||||
|
|
||||||
sleep 1
|
|
||||||
|
|
||||||
local after_json=$(opencode session list --format=json 2>/dev/null)
|
local after_json=$(opencode session list --format=json 2>/dev/null)
|
||||||
local after_sessions=$(echo "$after_json" | python3 -c "import sys,json; sessions=json.load(sys.stdin); [print(s['id']) for s in sessions]" 2>/dev/null || true)
|
local after_ids=$(echo "$after_json" | python3 -c "import sys,json; sessions=json.load(sys.stdin); print(' '.join(s['id'] for s in sessions))" 2>/dev/null || echo "")
|
||||||
|
|
||||||
local new_session_id=""
|
local new_session_id=""
|
||||||
while IFS= read -r sess; do
|
for sess in $after_ids; do
|
||||||
if [[ -n "$sess" ]] && [[ ! "$before_set" =~ \|${sess}\| ]]; then
|
if [[ ! " $before_ids " =~ " $sess " ]] && [[ "$sess" != "$base_session" ]]; then
|
||||||
new_session_id="$sess"
|
new_session_id="$sess"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done <<< "$after_sessions"
|
done
|
||||||
|
|
||||||
echo "$new_session_id"
|
echo "$new_session_id"
|
||||||
}
|
}
|
||||||
@@ -271,28 +266,7 @@ build_dev_agent_message() {
|
|||||||
local number=$(echo "$issue_ref" | grep -oE '#[0-9]+$' | tr -d '#')
|
local number=$(echo "$issue_ref" | grep -oE '#[0-9]+$' | tr -d '#')
|
||||||
local worktree_path=$(issue_ref_to_worktree_path "$issue_ref")
|
local worktree_path=$(issue_ref_to_worktree_path "$issue_ref")
|
||||||
|
|
||||||
if [ -n "$user_message" ]; then
|
local base_message="You are assigned to work on $issue_ref.
|
||||||
cat <<EOF
|
|
||||||
You are continuing work on $issue_ref. A PR likely already exists.
|
|
||||||
|
|
||||||
IMPORTANT - Review workflow:
|
|
||||||
1. First, check if PR exists: curl -s "https://$instance/api/v1/repos/$owner/$repo/pulls?state=open" -H "Authorization: Bearer \$GITEA_TOKEN" | grep -i "$number"
|
|
||||||
2. Get PR comments: curl -s "https://$instance/api/v1/repos/$owner/$repo/issues/$number/comments" -H "Authorization: Bearer \$GITEA_TOKEN"
|
|
||||||
3. Get PR reviews: curl -s "https://$instance/api/v1/repos/$owner/$repo/pulls/$number/reviews" -H "Authorization: Bearer \$GITEA_TOKEN"
|
|
||||||
|
|
||||||
You may need to:
|
|
||||||
- Make code changes and push to the same branch
|
|
||||||
- Reply to PR comments using: curl -X POST "https://$instance/api/v1/repos/$owner/$repo/issues/$number/comments" -H "Authorization: Bearer \$GITEA_TOKEN" -H "Content-Type: application/json" -d '{"body":"Your reply here"}'
|
|
||||||
- Or do both
|
|
||||||
|
|
||||||
Delegator's message:
|
|
||||||
$user_message
|
|
||||||
|
|
||||||
Work directory: $worktree_path (already on the fix branch)
|
|
||||||
EOF
|
|
||||||
else
|
|
||||||
cat <<EOF
|
|
||||||
You are assigned to work on $issue_ref.
|
|
||||||
|
|
||||||
Workflow:
|
Workflow:
|
||||||
1. Read the issue at $instance/$owner/$repo/issues/$number AND all comments on that issue
|
1. Read the issue at $instance/$owner/$repo/issues/$number AND all comments on that issue
|
||||||
@@ -307,17 +281,17 @@ Workflow:
|
|||||||
6. If anything is unclear, post a comment on the issue asking for clarification before implementing
|
6. If anything is unclear, post a comment on the issue asking for clarification before implementing
|
||||||
7. Implement the solution
|
7. Implement the solution
|
||||||
8. Create a branch named fix/issue-$number and implement the fix
|
8. Create a branch named fix/issue-$number and implement the fix
|
||||||
9. Create a PR when the implementation is complete using: tea pr create --repo $owner/$repo --title "Your PR title" --body "PR description"
|
9. Create a PR when the implementation is complete
|
||||||
- Make sure you are logged in with: tea login add --name gitea --token \$GITEA_TOKEN --url https://$instance
|
|
||||||
- If tea is not available, use: curl -X POST "https://$instance/api/v1/repos/$owner/$repo/pulls" -H "Authorization: Bearer \$GITEA_TOKEN" -H "Content-Type: application/json" -d '{"title":"PR Title","head":"branch-name","base":"main","body":"PR description"}'
|
|
||||||
|
|
||||||
Tools for PR interaction:
|
Work directory: $worktree_path"
|
||||||
- Post issue/PR comment: curl -X POST "https://$instance/api/v1/repos/$owner/$repo/issues/$number/comments" -H "Authorization: Bearer \$GITEA_TOKEN" -H "Content-Type: application/json" -d '{"body":"Your comment"}'
|
|
||||||
- List PR comments: curl -s "https://$instance/api/v1/repos/$owner/$repo/issues/$number/comments" -H "Authorization: Bearer \$GITEA_TOKEN"
|
if [ -n "$user_message" ]; then
|
||||||
- List PR reviews: curl -s "https://$instance/api/v1/repos/$owner/$repo/pulls/$number/reviews" -H "Authorization: Bearer \$GITEA_TOKEN"
|
echo "$base_message
|
||||||
|
|
||||||
Work directory: $worktree_path
|
Additional instructions from delegator:
|
||||||
EOF
|
$user_message"
|
||||||
|
else
|
||||||
|
echo "$base_message"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -399,14 +373,7 @@ cmd_start() {
|
|||||||
load_agent_env "dev"
|
load_agent_env "dev"
|
||||||
|
|
||||||
cd "$worktree_path"
|
cd "$worktree_path"
|
||||||
local sanitized_id=$(echo "$new_session_id" | sed 's/[^a-zA-Z0-9_-]/_/g')
|
nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run '$dev_message' --session '$new_session_id'" >> "$LOGS_DIR/dev-$new_session_id.log" 2>&1 &
|
||||||
mkdir -p "$worktree_path/.kugetsu"
|
|
||||||
if [ ! -f "$worktree_path/.gitignore" ] || ! grep -q "^.kugetsu/" "$worktree_path/.gitignore"; then
|
|
||||||
echo ".kugetsu/" >> "$worktree_path/.gitignore" 2>/dev/null || true
|
|
||||||
fi
|
|
||||||
local msg_file="$worktree_path/.kugetsu/msg.txt"
|
|
||||||
printf '%s' "$dev_message" > "$msg_file"
|
|
||||||
nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run '@$msg_file' --session '$new_session_id'" >> "$LOGS_DIR/dev-$sanitized_id.log" 2>&1 &
|
|
||||||
|
|
||||||
echo "Session started for '$issue_ref': $new_session_id"
|
echo "Session started for '$issue_ref': $new_session_id"
|
||||||
echo "Worktree: $worktree_path"
|
echo "Worktree: $worktree_path"
|
||||||
@@ -469,14 +436,7 @@ cmd_continue() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
cd "$worktree_path"
|
cd "$worktree_path"
|
||||||
local sanitized_id=$(echo "$opencode_session_id" | sed 's/[^a-zA-Z0-9_-]/_/g')
|
nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run '$message' --session '$opencode_session_id'" >> "$LOGS_DIR/dev-$opencode_session_id.log" 2>&1 &
|
||||||
mkdir -p "$worktree_path/.kugetsu"
|
|
||||||
if [ ! -f "$worktree_path/.gitignore" ] || ! grep -q "^.kugetsu/" "$worktree_path/.gitignore"; then
|
|
||||||
echo ".kugetsu/" >> "$worktree_path/.gitignore" 2>/dev/null || true
|
|
||||||
fi
|
|
||||||
local msg_file="$worktree_path/.kugetsu/msg.txt"
|
|
||||||
printf '%s' "$message" > "$msg_file"
|
|
||||||
nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run '@$msg_file' --session '$opencode_session_id'" >> "$LOGS_DIR/dev-$sanitized_id.log" 2>&1 &
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_list() {
|
cmd_list() {
|
||||||
|
|||||||
Reference in New Issue
Block a user