Skip to content

Commit ce8217a

Browse files
authored
Merge branch 'main' into claude/claude-md-mi046vzfykbhdf3e-013Jr6ZSMb36RdSjthgQZbsr
2 parents 001f2d9 + 7a9abbb commit ce8217a

File tree

102 files changed

+7494
-415
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+7494
-415
lines changed

.github/workflows/go-test.yml

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,44 @@
11
name: Go Tests
22

33
on:
4-
push:
5-
branches: [main]
6-
pull_request:
4+
push:
5+
branches: [main]
6+
pull_request:
77

88
jobs:
9-
test:
10-
runs-on: ubuntu-latest
11-
steps:
12-
- uses: actions/checkout@v4
13-
14-
- name: Set up Go
15-
uses: actions/setup-go@v5
16-
with:
17-
go-version: "stable"
18-
19-
- name: Test
20-
run: CGO_ENABLED=0 go test -count=1 -v ./...
21-
22-
lint:
23-
runs-on: ubuntu-latest
24-
steps:
25-
- uses: actions/checkout@v4
26-
27-
- name: Set up Go
28-
uses: actions/setup-go@v5
29-
with:
30-
go-version: "stable"
31-
32-
- name: golangci-lint
33-
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
34-
with:
35-
version: v2.1
9+
test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Set up Go
15+
uses: actions/setup-go@v5
16+
with:
17+
go-version: "stable"
18+
19+
- name: Test
20+
run: CGO_ENABLED=0 go test -count=1 -v ./...
21+
22+
lint:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v4
26+
27+
- name: Set up Go
28+
uses: actions/setup-go@v5
29+
with:
30+
go-version: "stable"
31+
32+
- name: Set up Bun
33+
uses: oven-sh/setup-bun@v2
34+
35+
- name: Install Chat Dependencies
36+
run: cd chat && bun install
37+
38+
- name: run linters
39+
run: make lint
40+
41+
- name: Check for unstaged changes
42+
run: |
43+
make gen
44+
./check_unstaged.sh
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: PR Preview Build
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
build:
8+
name: Build Release Binaries
9+
runs-on: depot-ubuntu-22.04-4
10+
permissions:
11+
contents: write
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v5
18+
with:
19+
go-version: 'stable'
20+
21+
- name: Set up Bun
22+
uses: oven-sh/setup-bun@v2
23+
24+
- name: Install Chat Dependencies
25+
run: cd chat && bun install
26+
27+
- name: Run make gen and check for unstaged changes
28+
run: |
29+
make gen
30+
./check_unstaged.sh
31+
32+
- name: Build
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
shell: bash
36+
run: |
37+
build_variants=(
38+
"linux amd64 agentapi-linux-amd64"
39+
"linux arm64 agentapi-linux-arm64"
40+
"darwin amd64 agentapi-darwin-amd64"
41+
"darwin arm64 agentapi-darwin-arm64"
42+
"windows amd64 agentapi-windows-amd64.exe"
43+
)
44+
45+
for variant in "${build_variants[@]}"; do
46+
read -r goos goarch artifact_name <<< "$variant"
47+
48+
echo "Building for GOOS=$goos GOARCH=$goarch..."
49+
CGO_ENABLED=0 GOOS=$goos GOARCH=$goarch BINPATH="out/$artifact_name" make build
50+
done
51+
52+
- name: Upload Build Artifact
53+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
54+
with:
55+
name: agentapi-build-${{ github.event.pull_request.number }}
56+
path: ${{ github.workspace }}/out
57+
retention-days: 7
58+
59+
- name: Save PR number
60+
run: |
61+
mkdir -p ./pr
62+
echo ${{ github.event.pull_request.number }} > ./pr/number
63+
64+
- name: Upload PR number
65+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
66+
with:
67+
name: pr-number
68+
path: pr/
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: PR Preview Cleanup
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
cleanup:
12+
name: Delete PR Release
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Delete PR Release
17+
env:
18+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
RELEASE_TAG: 'agentapi_${{ github.event.pull_request.number }}'
20+
run: |
21+
gh release delete "$RELEASE_TAG" --cleanup-tag --yes --repo ${{ github.repository }} || true
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: PR Preview Release
2+
3+
on:
4+
workflow_run:
5+
workflows: ["PR Preview Build"]
6+
types:
7+
- completed
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
release:
15+
name: Create Release
16+
runs-on: ubuntu-latest
17+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
18+
19+
steps:
20+
- name: Download PR number
21+
uses: actions/download-artifact@v4
22+
with:
23+
name: pr-number
24+
github-token: ${{ secrets.GITHUB_TOKEN }}
25+
run-id: ${{ github.event.workflow_run.id }}
26+
27+
- name: Read PR number
28+
id: pr
29+
run: echo "number=$(cat number)" >> "${GITHUB_OUTPUT}"
30+
31+
- name: Download Build Artifacts
32+
uses: actions/download-artifact@v4
33+
with:
34+
name: agentapi-build-${{ steps.pr.outputs.number }}
35+
path: ./out
36+
github-token: ${{ secrets.GITHUB_TOKEN }}
37+
run-id: ${{ github.event.workflow_run.id }}
38+
39+
- name: Create or Update PR Release
40+
id: release
41+
env:
42+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
RELEASE_TAG: "agentapi_${{ steps.pr.outputs.number }}"
44+
PR_NUMBER: ${{ steps.pr.outputs.number }}
45+
run: |
46+
# Check if release exists
47+
if gh release view "$RELEASE_TAG" --repo ${{ github.repository }} &>/dev/null; then
48+
echo "Updating release $RELEASE_TAG"
49+
gh release upload "$RELEASE_TAG" ./out/* --clobber --repo ${{ github.repository }}
50+
echo "should_comment=false" >> "${GITHUB_OUTPUT}"
51+
else
52+
echo "Creating release $RELEASE_TAG"
53+
gh release create "$RELEASE_TAG" ./out/* \
54+
--title "$RELEASE_TAG" \
55+
--notes "Preview release for PR #${PR_NUMBER}" \
56+
--repo ${{ github.repository }} \
57+
--latest=false \
58+
--prerelease
59+
echo "should_comment=true" >> "${GITHUB_OUTPUT}"
60+
fi
61+
62+
- name: Comment on PR
63+
if: steps.release.outputs.should_comment == 'true'
64+
uses: actions/github-script@v7
65+
with:
66+
script: |
67+
const prNumber = ${{ steps.pr.outputs.number }};
68+
const releaseTag = `agentapi_${prNumber}`;
69+
const repoUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}`;
70+
github.rest.issues.createComment({
71+
issue_number: prNumber,
72+
owner: context.repo.owner,
73+
repo: context.repo.repo,
74+
body: `✅ Preview binaries are ready!\n\nTo test with modules: \`\`\`agentapi_version = "agentapi_${prNumber}"\`\`\` or download from: ${repoUrl}/releases/tag/${releaseTag}`
75+
});

.github/workflows/release.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ jobs:
3333
- name: Install Chat Dependencies
3434
run: cd chat && bun install
3535

36+
- name: Run make gen and check for unstaged changes
37+
run: |
38+
make gen
39+
./check_unstaged.sh
40+
3641
- name: Build and Upload
3742
env:
3843
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

AGENTS.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# AGENTS.md
2+
3+
This file provides guidance to AI agents working with code in this repository.
4+
5+
## Build Commands
6+
7+
- `make build` - Build the binary to `out/agentapi` (includes chat UI build)
8+
- `make embed` - Build the chat UI and embed it into Go
9+
- `go build -o out/agentapi main.go` - Direct Go build without chat UI
10+
- `go generate ./...` - Generate OpenAPI schema and version info
11+
12+
## Testing
13+
14+
- `go test ./...` - Run all Go tests
15+
- Tests are located alongside source files (e.g., `lib/httpapi/server_test.go`)
16+
17+
## Development Commands
18+
19+
- `agentapi server -- claude` - Start server with Claude Code agent
20+
- `agentapi server -- aider --model sonnet` - Start server with Aider agent
21+
- `agentapi server -- goose` - Start server with Goose agent
22+
- `agentapi server --type=codex -- codex` - Start server with Codex (requires explicit type)
23+
- `agentapi server --type=gemini -- gemini` - Start server with Gemini (requires explicit type)
24+
- `agentapi attach --url localhost:3284` - Attach to running agent terminal
25+
- Server runs on port 3284 by default
26+
- Chat UI available at http://localhost:3284/chat
27+
- API documentation at http://localhost:3284/docs
28+
29+
## Architecture
30+
31+
This is a Go HTTP API server that controls coding agents (Claude Code, Aider, Goose, etc.) through terminal emulation.
32+
33+
**Core Components:**
34+
- `main.go` - Entry point using cobra CLI framework
35+
- `cmd/` - CLI command definitions (server, attach)
36+
- `lib/httpapi/` - HTTP server, routes, and OpenAPI schema
37+
- `lib/screentracker/` - Terminal output parsing and message splitting
38+
- `lib/termexec/` - Terminal process execution and management
39+
- `lib/msgfmt/` - Message formatting for different agent types (claude, goose, aider, codex, gemini, amp, cursor-agent, cursor, auggie, custom)
40+
- `chat/` - Next.js web UI (embedded into Go binary)
41+
42+
**Key Architecture:**
43+
- Runs agents in an in-memory terminal emulator
44+
- Translates API calls to terminal keystrokes
45+
- Parses terminal output into structured messages
46+
- Supports multiple agent types with different message formats
47+
- Embeds Next.js chat UI as static assets in Go binary
48+
49+
**Message Flow:**
50+
1. User sends message via HTTP API
51+
2. Server takes terminal snapshot
52+
3. Message sent to agent as terminal input
53+
4. Terminal output changes tracked and parsed
54+
5. New content becomes agent response message
55+
6. SSE events stream updates to clients
56+
57+
## API Endpoints
58+
59+
- GET `/messages` - Get all messages in conversation
60+
- POST `/message` - Send message to agent (content, type fields)
61+
- GET `/status` - Get agent status ("stable" or "running")
62+
- GET `/events` - SSE stream of agent events
63+
- GET `/openapi.json` - OpenAPI schema
64+
- GET `/docs` - API documentation UI
65+
- GET `/chat` - Web chat interface
66+
67+
## Supported Agents
68+
69+
Agents with explicit type requirement (use `--type=<agent>`):
70+
- `codex` - OpenAI Codex
71+
- `gemini` - Google Gemini CLI
72+
- `amp` - Sourcegraph Amp CLI
73+
- `cursor` - Cursor CLI
74+
75+
Agents with auto-detection:
76+
- `claude` - Claude Code (default)
77+
- `goose` - Goose
78+
- `aider` - Aider
79+
80+
## Project Structure
81+
82+
- Go module with standard layout
83+
- Chat UI in `chat/` directory (Next.js + TypeScript)
84+
- OpenAPI schema auto-generated to `openapi.json`
85+
- Version managed via `version.sh` script

0 commit comments

Comments
 (0)