#!/usr/bin/env bash # agent-dispatch.sh — Generate a self-contained prompt for any agent # # Usage: agent-dispatch.sh # agent-dispatch.sh manus 42 Timmy_Foundation/the-nexus # # Outputs a prompt to stdout. Copy-paste into the agent's interface. # The prompt includes everything: API URLs, token, git commands, PR creation. set -euo pipefail AGENT_NAME="${1:?Usage: agent-dispatch.sh }" ISSUE_NUM="${2:?Usage: agent-dispatch.sh }" REPO="${3:?Usage: agent-dispatch.sh }" GITEA_URL="http://143.198.27.163:3000" TOKEN_FILE="$HOME/.hermes/${AGENT_NAME}_token" if [ ! -f "$TOKEN_FILE" ]; then echo "ERROR: No token found at $TOKEN_FILE" >&2 echo "Create a Gitea user and token for '$AGENT_NAME' first." >&2 exit 1 fi GITEA_TOKEN=$(cat "$TOKEN_FILE") REPO_OWNER=$(echo "$REPO" | cut -d/ -f1) REPO_NAME=$(echo "$REPO" | cut -d/ -f2) BRANCH="${AGENT_NAME}/issue-${ISSUE_NUM}" # Fetch issue title ISSUE_TITLE=$(curl -sf -H "Authorization: token $GITEA_TOKEN" \ "${GITEA_URL}/api/v1/repos/${REPO}/issues/${ISSUE_NUM}" 2>/dev/null | \ python3 -c "import sys,json; print(json.loads(sys.stdin.read())['title'])" 2>/dev/null || echo "Issue #${ISSUE_NUM}") cat < (#${ISSUE_NUM}) Fixes #${ISSUE_NUM}" git push origin ${BRANCH} == STEP 6: CREATE PR == curl -s -X POST "${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/pulls" \\ -H "Authorization: token ${GITEA_TOKEN}" \\ -H "Content-Type: application/json" \\ -d '{"title": "[${AGENT_NAME}] (#${ISSUE_NUM})", "body": "Fixes #${ISSUE_NUM}\n\n", "head": "${BRANCH}", "base": "main"}' == STEP 7: COMMENT ON ISSUE == curl -s -X POST "${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/issues/${ISSUE_NUM}/comments" \\ -H "Authorization: token ${GITEA_TOKEN}" \\ -H "Content-Type: application/json" \\ -d '{"body": "PR submitted. "}' == RULES == - Read project docs FIRST. - Use the project's own test/lint tools. - Respect git hooks. Do not skip them. - If tests fail twice, STOP and comment on the issue. - ALWAYS push your work. ALWAYS create a PR. No exceptions. - Clean up: remove /tmp/${AGENT_NAME}-work-${ISSUE_NUM} when done. PROMPT