Skip to content

Commit f1c995d

Browse files
authored
fix: refactor codebase (#40)
* fix: refactor codebase * fix: refactor codebase * fix: refactor codebase * fix: refactor codebase * fix: refactor codebase * fix: refactor codebase * fix: refactor codebase * fix
1 parent 437744f commit f1c995d

File tree

193 files changed

+5804
-1485
lines changed

Some content is hidden

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

193 files changed

+5804
-1485
lines changed

.env.example

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ ANTHROPIC_API_KEY=sk-ant-...
1313
# Apps reference this as NEXT_PUBLIC_CONVEX_URL
1414
CONVEX_URL=https://your-deployment.convex.cloud
1515

16-
# Agency gateway authentication token
16+
# SquadHub gateway authentication token
1717
# Auto-generated by scripts/start.sh, or set your own secure random string
18-
AGENCY_TOKEN=your-secure-token-here
18+
SQUADHUB_TOKEN=your-secure-token-here
1919

2020
# =============================================================================
2121
# OPTIONAL
@@ -27,16 +27,46 @@ AGENCY_TOKEN=your-secure-token-here
2727
# Environment: dev or prod
2828
ENVIRONMENT=dev
2929

30-
# Agency gateway URL
30+
# SquadHub gateway URL
3131
# Development: http://localhost:18790 (Docker exposed on host)
32-
# Production: http://agency:18789 (Docker internal network)
33-
AGENCY_URL=http://localhost:18790
32+
# Production: http://squadhub:18789 (Docker internal network)
33+
SQUADHUB_URL=http://localhost:18790
34+
35+
# =============================================================================
36+
# AUTHENTICATION
37+
# =============================================================================
38+
39+
# Authentication provider: "nextauth" (local/self-hosted) or "cognito" (cloud)
40+
# NextAuth uses auto-login with committed dev keys — zero config for local dev.
41+
AUTH_PROVIDER=nextauth
42+
43+
# NextAuth settings (only when AUTH_PROVIDER=nextauth)
44+
NEXTAUTH_SECRET=clawe-dev-secret-change-in-production
45+
NEXTAUTH_URL=http://localhost:3000
46+
47+
# Google OAuth credentials (for NextAuth Google provider)
48+
# Required for self-hosted deployments. Get from Google Cloud Console.
49+
# GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
50+
# GOOGLE_CLIENT_SECRET=your-client-secret
51+
52+
# Auto-login email for local dev (skips Google OAuth, uses Credentials provider)
53+
# Remove or leave empty to require Google sign-in
54+
AUTO_LOGIN_EMAIL=dev@clawe.local
55+
56+
# AWS Cognito settings (only when AUTH_PROVIDER=cognito)
57+
# COGNITO_USER_POOL_ID=us-east-1_xxxxxxxxx
58+
# COGNITO_CLIENT_ID=xxxxxxxxxxxxxxxxxxxxxxxxxx
59+
# COGNITO_DOMAIN=your-domain.auth.us-east-1.amazoncognito.com
3460

3561
# =============================================================================
3662
# ADVANCED (usually don't need to change)
3763
# =============================================================================
3864

39-
# Agency state directory (path to config dir, mounted from Docker)
40-
# Development: ./.agency/config (relative to project root)
41-
# Production: /agency-data/config (shared Docker volume)
42-
AGENCY_STATE_DIR=./.agency/config
65+
# SquadHub state directory (path to config dir, mounted from Docker)
66+
# Development: ./.squadhub/config (relative to project root)
67+
# Production: /squadhub-data/config (shared Docker volume)
68+
SQUADHUB_STATE_DIR=./.squadhub/config
69+
70+
# Watcher system token (must also be set as Convex env var)
71+
# Used by the watcher service for system-level auth (tenants.listActive)
72+
WATCHER_TOKEN=clawe-watcher-dev-token

.gitignore

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,21 @@ yarn-error.log*
4040
# Misc
4141
.DS_Store
4242
*.pem
43+
!packages/backend/convex/dev-jwks/*.pem
4344

4445
# Claude Code local settings (personal permissions)
4546
.claude/settings.local.json
4647

4748
convex/_generated
4849

50+
# auth.config.ts is committed as the NextAuth version (default for local dev).
51+
# scripts/convex-deploy.sh overwrites it for cloud deployments.
52+
4953
# Local data directory (Clawe config)
5054
.data/
5155

52-
# Agency state directory (shared with Docker in dev)
53-
.agency/*
54-
!.agency/.gitkeep
55-
.agency/logs/*
56-
!.agency/logs/.gitkeep
56+
# SquadHub state directory (shared with Docker in dev)
57+
.squadhub/*
58+
!.squadhub/.gitkeep
59+
.squadhub/logs/*
60+
!.squadhub/logs/.gitkeep

.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Template files with shell variable substitution
2-
docker/agency/templates/*.json
2+
docker/squadhub/templates/*.json
File renamed without changes.

CLAUDE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ Core models: `agents`, `tasks`, `messages` (see `packages/backend/convex/schema.
5454
## Environment Variables
5555

5656
- `NEXT_PUBLIC_CONVEX_URL`: Convex deployment URL (required)
57-
- `ANTHROPIC_API_KEY`: Anthropic API key for AI operations (required, passed to agency)
58-
- `AGENCY_TOKEN`: Authentication token for agency gateway (required)
59-
- `AGENCY_URL`: Agency gateway URL (set in `.env.development` / `.env.production`)
57+
- `ANTHROPIC_API_KEY`: Anthropic API key for AI operations (required, passed to squadhub)
58+
- `SQUADHUB_TOKEN`: Authentication token for squadhub gateway (required)
59+
- `SQUADHUB_URL`: SquadHub gateway URL (set in `.env.development` / `.env.production`)
6060
- `NODE_ENV`: local (`development`) vs deployed (`production`) — controls dev tooling
6161
- `ENVIRONMENT`: deployment target (`dev` / `prod`) — controls feature flags
6262

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Edit `.env`:
4545
```bash
4646
# Required
4747
ANTHROPIC_API_KEY=sk-ant-...
48-
AGENCY_TOKEN=your-secure-token
48+
SQUADHUB_TOKEN=your-secure-token
4949
CONVEX_URL=https://your-deployment.convex.cloud
5050

5151
# Optional
@@ -71,15 +71,15 @@ npx convex deploy
7171
This script will:
7272

7373
- Create `.env` from `.env.example` if missing
74-
- Auto-generate a secure `AGENCY_TOKEN`
74+
- Auto-generate a secure `SQUADHUB_TOKEN`
7575
- Validate all required environment variables
7676
- Build necessary packages
7777
- Start the Docker containers
7878

7979
**Development:**
8080

8181
```bash
82-
# Start agency gateway only (use local web dev server)
82+
# Start squadhub gateway only (use local web dev server)
8383
pnpm dev:docker
8484

8585
# In another terminal, start web + Convex
@@ -88,7 +88,7 @@ pnpm dev
8888

8989
The production stack starts:
9090

91-
- **agency**: Gateway running all agents
91+
- **squadhub**: Gateway running all agents
9292
- **watcher**: Notification delivery + cron setup
9393
- **clawe**: Web dashboard at http://localhost:3000
9494

@@ -120,7 +120,7 @@ Schedule recurring tasks that automatically create inbox items:
120120
┌─────────────────────────────────────────────────────────────┐
121121
│ DOCKER COMPOSE │
122122
├─────────────────┬─────────────────────┬─────────────────────┤
123-
agency │ watcher │ clawe │
123+
squadhub │ watcher │ clawe │
124124
│ │ │ │
125125
│ Agent Gateway │ • Register agents │ Web Dashboard │
126126
│ with 4 agents │ • Setup crons │ • Squad status │
@@ -151,10 +151,10 @@ clawe/
151151
├── packages/
152152
│ ├── backend/ # Convex schema & functions
153153
│ ├── cli/ # `clawe` CLI for agents
154-
│ ├── shared/ # Shared agency client
154+
│ ├── shared/ # Shared squadhub client
155155
│ └── ui/ # UI components
156156
└── docker/
157-
└── agency/
157+
└── squadhub/
158158
├── Dockerfile
159159
├── entrypoint.sh
160160
├── scripts/ # init-agents.sh
@@ -221,8 +221,8 @@ Each agent has an isolated workspace with:
221221

222222
### Adding New Agents
223223

224-
1. Create workspace template in `docker/agency/templates/workspaces/{name}/`
225-
2. Add agent to `docker/agency/templates/config.template.json`
224+
1. Create workspace template in `docker/squadhub/templates/workspaces/{name}/`
225+
2. Add agent to `docker/squadhub/templates/config.template.json`
226226
3. Add agent to watcher's `AGENTS` array in `apps/watcher/src/index.ts`
227227
4. Rebuild: `docker compose build && docker compose up -d`
228228

@@ -252,13 +252,13 @@ pnpm install
252252
# Terminal 1: Start Convex dev server
253253
pnpm convex:dev
254254

255-
# Terminal 2: Start agency gateway in Docker
255+
# Terminal 2: Start squadhub gateway in Docker
256256
pnpm dev:docker
257257

258258
# Terminal 3: Start web dashboard
259259
pnpm dev:web
260260

261-
# Or run everything together (Convex + web, but not agency)
261+
# Or run everything together (Convex + web, but not squadhub)
262262
pnpm dev
263263
```
264264

@@ -284,6 +284,6 @@ pnpm convex:deploy
284284
| Variable | Required | Description |
285285
| ------------------- | -------- | --------------------------------- |
286286
| `ANTHROPIC_API_KEY` | Yes | Anthropic API key for Claude |
287-
| `AGENCY_TOKEN` | Yes | Auth token for agency gateway |
287+
| `SQUADHUB_TOKEN` | Yes | Auth token for squadhub gateway |
288288
| `CONVEX_URL` | Yes | Convex deployment URL |
289289
| `OPENAI_API_KEY` | No | OpenAI key (for image generation) |

apps/watcher/.env.example

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44

55
# Required variables (from root .env):
66
# - CONVEX_URL
7-
# - AGENCY_URL
8-
# - AGENCY_TOKEN
7+
# - WATCHER_TOKEN

apps/watcher/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ WORKDIR /app
88
# Watcher
99
COPY apps/watcher/dist/ ./dist/
1010

11-
# Shared package (agency client)
11+
# Shared package (squadhub client)
1212
COPY packages/shared/package.json ./node_modules/@clawe/shared/package.json
1313
COPY packages/shared/dist/ ./node_modules/@clawe/shared/dist/
1414

apps/watcher/README.md

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,17 @@ Coordination watcher for Clawe multi-agent system.
44

55
## What It Does
66

7-
1. **On startup:** Registers all agents in Convex (upsert)
8-
2. **On startup:** Ensures heartbeat crons are configured for all agents
9-
3. **Continuously:** Polls Convex for undelivered notifications and delivers them
7+
1. **Continuously:** Polls Convex for undelivered notifications and delivers them
8+
2. **Continuously:** Checks for due routines and triggers them
109

11-
This enables:
12-
13-
- Automatic agent heartbeat scheduling (no manual cron setup needed)
14-
- Near-instant notification delivery without waiting for heartbeats
10+
Tenant connection info (squadhub URL/token) comes from Convex via `tenants.listActive`.
1511

1612
## Environment Variables
1713

18-
| Variable | Required | Description |
19-
| -------------- | -------- | --------------------------- |
20-
| `CONVEX_URL` | Yes | Convex deployment URL |
21-
| `AGENCY_URL` | Yes | Agency gateway URL |
22-
| `AGENCY_TOKEN` | Yes | Agency authentication token |
14+
| Variable | Required | Description |
15+
| --------------- | -------- | ---------------------------------------------- |
16+
| `CONVEX_URL` | Yes | Convex deployment URL |
17+
| `WATCHER_TOKEN` | Yes | System-level token for querying active tenants |
2318

2419
## Running
2520

@@ -53,7 +48,7 @@ Schedules are staggered to avoid rate limits.
5348
│ │
5449
│ ┌─────────────┐ │
5550
│ │ On Startup │──> Check/create heartbeat crons │
56-
│ └─────────────┘ via agency cron API │
51+
│ └─────────────┘ via squadhub cron API │
5752
│ │
5853
│ ┌─────────────┐ ┌─────────────────────────┐ │
5954
│ │ Poll Loop │───────>│ convex.query( │ │
@@ -62,13 +57,13 @@ Schedules are staggered to avoid rate limits.
6257
│ │ └─────────────────────────┘ │
6358
│ │ │
6459
│ │ ┌─────────────────────────┐ │
65-
│ └──────────────>│ agency.sessionsSend() │ │
60+
│ └──────────────>│ squadhub.sessionsSend() │ │
6661
│ └─────────────────────────┘ │
6762
└─────────────────────────────────────────────────────────┘
6863
│ │
6964
▼ ▼
7065
┌───────────┐ ┌───────────────┐
71-
│ CONVEX │ │ AGENCY
66+
│ CONVEX │ │ SQUADHUB
7267
│ (data) │ │ (delivery) │
7368
└───────────┘ └───────────────┘
7469
```

apps/watcher/src/config.spec.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ describe("config", () => {
1515
describe("validateEnv", () => {
1616
it("exits when CONVEX_URL is missing", async () => {
1717
delete process.env.CONVEX_URL;
18-
process.env.AGENCY_URL = "http://localhost:18789";
19-
process.env.AGENCY_TOKEN = "test-token";
18+
process.env.WATCHER_TOKEN = "test-token";
2019

2120
const mockExit = vi
2221
.spyOn(process, "exit")
@@ -35,10 +34,9 @@ describe("config", () => {
3534
mockError.mockRestore();
3635
});
3736

38-
it("exits when AGENCY_URL is missing", async () => {
37+
it("exits when WATCHER_TOKEN is missing", async () => {
3938
process.env.CONVEX_URL = "https://test.convex.cloud";
40-
delete process.env.AGENCY_URL;
41-
process.env.AGENCY_TOKEN = "test-token";
39+
delete process.env.WATCHER_TOKEN;
4240

4341
const mockExit = vi
4442
.spyOn(process, "exit")
@@ -49,7 +47,7 @@ describe("config", () => {
4947
validateEnv();
5048

5149
expect(mockError).toHaveBeenCalledWith(
52-
expect.stringContaining("AGENCY_URL"),
50+
expect.stringContaining("WATCHER_TOKEN"),
5351
);
5452
expect(mockExit).toHaveBeenCalledWith(1);
5553

@@ -59,8 +57,7 @@ describe("config", () => {
5957

6058
it("does not exit when all required vars are set", async () => {
6159
process.env.CONVEX_URL = "https://test.convex.cloud";
62-
process.env.AGENCY_URL = "http://localhost:18789";
63-
process.env.AGENCY_TOKEN = "test-token";
60+
process.env.WATCHER_TOKEN = "test-token";
6461

6562
const mockExit = vi
6663
.spyOn(process, "exit")
@@ -76,16 +73,14 @@ describe("config", () => {
7673
});
7774

7875
describe("config object", () => {
79-
it("has correct default values", async () => {
76+
it("has correct values from env", async () => {
8077
process.env.CONVEX_URL = "https://test.convex.cloud";
81-
process.env.AGENCY_URL = "http://custom:8080";
82-
process.env.AGENCY_TOKEN = "my-token";
78+
process.env.WATCHER_TOKEN = "my-watcher-token";
8379

8480
const { config } = await import("./config.js");
8581

8682
expect(config.convexUrl).toBe("https://test.convex.cloud");
87-
expect(config.agencyUrl).toBe("http://custom:8080");
88-
expect(config.agencyToken).toBe("my-token");
83+
expect(config.watcherToken).toBe("my-watcher-token");
8984
});
9085
});
9186

0 commit comments

Comments
 (0)