Skip to content

Commit ba83ff3

Browse files
authored
Merge pull request #942 from web3dev1337/feature/commander-instructions
feat: seed Commander CLAUDE.md/AGENTS.md for desktop
2 parents 9a4c2ba + 957b514 commit ba83ff3

4 files changed

Lines changed: 200 additions & 49 deletions

File tree

CODEBASE_DOCUMENTATION.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,12 @@ server/githubCloneWorktreeService.js - GitHub import flow for Quick Work (`owner
110110
server/portRegistry.js - Port assignment + live service scanner (`/api/ports/scan`)
111111
├─ Windows scan path: uses hidden `netstat`/`tasklist` probes so packaged Tauri builds do not flash console windows when Ports/Dashboard panels refresh
112112
└─ UI metadata: labels orchestrator-assigned ports, known dev servers, and custom user labels
113+
server/commanderService.js - Top-level Commander PTY (Claude/Codex) + launch buffering
114+
├─ Packaged CWD: uses `ORCHESTRATOR_DATA_DIR/commander` so desktop users can edit `CLAUDE.md` / `AGENTS.md` safely
115+
└─ First-run seed: copies the packaged `docs/COMMANDER_CLAUDE.md` into the Commander data directory when missing
113116
scripts/tauri/prepare-backend-resources.js - Tauri backend packager
114117
├─ Bundles: server/client/config/templates/scripts + optional Node runtime into `src-tauri/resources/backend`
118+
├─ Commander instructions: copies `docs/COMMANDER_CLAUDE.md` into `resources/backend/{COMMANDER_CLAUDE.md,CLAUDE.md,AGENTS.md}` for desktop builds
115119
├─ Resource-sync reuse: repeated runs skip recopying server/client/templates/config payloads when the source-tree stamp still matches
116120
├─ Prod-deps reuse: repeated `--install-prod` runs skip `npm ci` when package-lock + bundled Node stamp still match
117121
└─ CI cache: Windows release workflow restores `src-tauri/resources/backend/node_modules` so warm installer builds avoid re-installing backend prod deps

docs/COMMANDER_CLAUDE.md

Lines changed: 65 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
# Commander Claude - API Reference
22

3-
You are Commander Claude. You can control the Agent Workspace by calling these API endpoints via curl.
3+
You are Commander (Claude or Codex). You can control the Claude Orchestrator by calling these HTTP APIs via `curl`.
44

5-
**Base URL:** `http://localhost:4000`
5+
Runtime connection info (desktop builds pick a free port each launch):
6+
- Host: `ORCHESTRATOR_HOST` (default `127.0.0.1`)
7+
- Port: `ORCHESTRATOR_PORT` (default `9460` for `npm start`)
8+
- Auth: if `AUTH_TOKEN` is set, every request must include `-H "X-Auth-Token: $AUTH_TOKEN"` (or `?token=$AUTH_TOKEN`)
9+
10+
**Base URL:** `http://${ORCHESTRATOR_HOST:-127.0.0.1}:${ORCHESTRATOR_PORT:-9460}`
11+
12+
Optional helper (bash):
13+
```bash
14+
BASE_URL="http://${ORCHESTRATOR_HOST:-127.0.0.1}:${ORCHESTRATOR_PORT:-9460}"
15+
# If AUTH_TOKEN is set, add: -H "X-Auth-Token: $AUTH_TOKEN"
16+
```
617

718
---
819

@@ -13,75 +24,86 @@ The Command Registry provides semantic, self-documenting commands. **This is the
1324
### Discover Available Commands
1425
```bash
1526
# See all available commands with descriptions and examples
16-
curl -s http://localhost:4000/api/commander/capabilities | jq
27+
curl -sS "$BASE_URL/api/commander/capabilities" -H "X-Auth-Token: $AUTH_TOKEN" | jq
1728
```
1829

1930
### Get Live Context (Recommended)
2031
```bash
2132
# See current UI/session context (selected queue item, sessions, workspace, etc.)
22-
curl -s http://localhost:4000/api/commander/context | jq
33+
curl -sS "$BASE_URL/api/commander/context" -H "X-Auth-Token: $AUTH_TOKEN" | jq
2334
```
2435

2536
### Get Runtime Help Prompt (Self-Updating)
2637
```bash
2738
# Plain-text prompt generated from the command registry + current context
28-
curl -s http://localhost:4000/api/commander/prompt
39+
curl -sS "$BASE_URL/api/commander/prompt" -H "X-Auth-Token: $AUTH_TOKEN"
2940
```
3041

3142
### Execute Commands
3243
```bash
3344
# General syntax
34-
curl -s http://localhost:4000/api/commander/execute \
45+
curl -sS "$BASE_URL/api/commander/execute" \
46+
-H "X-Auth-Token: $AUTH_TOKEN" \
3547
-H "Content-Type: application/json" \
3648
-d '{"command": "COMMAND_NAME", "params": {...}}'
3749

3850
# Focus on a terminal
39-
curl -s http://localhost:4000/api/commander/execute \
51+
curl -sS "$BASE_URL/api/commander/execute" \
52+
-H "X-Auth-Token: $AUTH_TOKEN" \
4053
-H "Content-Type: application/json" \
4154
-d '{"command": "focus-session", "params": {"sessionId": "work1-claude"}}'
4255

4356
# Switch workspace
44-
curl -s http://localhost:4000/api/commander/execute \
57+
curl -sS "$BASE_URL/api/commander/execute" \
58+
-H "X-Auth-Token: $AUTH_TOKEN" \
4559
-H "Content-Type: application/json" \
4660
-d '{"command": "switch-workspace", "params": {"name": "Epic Survivors"}}'
4761

4862
# Open Commander panel
49-
curl -s http://localhost:4000/api/commander/execute \
63+
curl -sS "$BASE_URL/api/commander/execute" \
64+
-H "X-Auth-Token: $AUTH_TOKEN" \
5065
-H "Content-Type: application/json" \
5166
-d '{"command": "open-commander"}'
5267

5368
# Open New Project wizard
54-
curl -s http://localhost:4000/api/commander/execute \
69+
curl -sS "$BASE_URL/api/commander/execute" \
70+
-H "X-Auth-Token: $AUTH_TOKEN" \
5571
-H "Content-Type: application/json" \
5672
-d '{"command": "open-new-project"}'
5773

5874
# Start Claude in a session
59-
curl -s http://localhost:4000/api/commander/execute \
75+
curl -sS "$BASE_URL/api/commander/execute" \
76+
-H "X-Auth-Token: $AUTH_TOKEN" \
6077
-H "Content-Type: application/json" \
6178
-d '{"command": "start-claude", "params": {"sessionId": "work1-claude"}}'
6279

6380
# Run a shell command
64-
curl -s http://localhost:4000/api/commander/execute \
81+
curl -sS "$BASE_URL/api/commander/execute" \
82+
-H "X-Auth-Token: $AUTH_TOKEN" \
6583
-H "Content-Type: application/json" \
6684
-d '{"command": "run-command", "params": {"sessionId": "work1-server", "command": "npm test"}}'
6785

6886
# Broadcast to multiple sessions
69-
curl -s http://localhost:4000/api/commander/execute \
87+
curl -sS "$BASE_URL/api/commander/execute" \
88+
-H "X-Auth-Token: $AUTH_TOKEN" \
7089
-H "Content-Type: application/json" \
7190
-d '{"command": "broadcast", "params": {"sessionIds": ["work1-claude", "work2-claude"], "input": "git pull\n"}}'
7291

7392
# Highlight a worktree in sidebar
74-
curl -s http://localhost:4000/api/commander/execute \
93+
curl -sS "$BASE_URL/api/commander/execute" \
94+
-H "X-Auth-Token: $AUTH_TOKEN" \
7595
-H "Content-Type: application/json" \
7696
-d '{"command": "highlight-worktree", "params": {"worktreeId": "work1"}}'
7797

7898
# Focus a worktree (show ONLY that worktree's terminals, hide others)
79-
curl -s http://localhost:4000/api/commander/execute \
99+
curl -sS "$BASE_URL/api/commander/execute" \
100+
-H "X-Auth-Token: $AUTH_TOKEN" \
80101
-H "Content-Type: application/json" \
81102
-d '{"command": "focus-worktree", "params": {"worktreeId": "work1"}}'
82103

83104
# Show all worktrees again (unfocus)
84-
curl -s http://localhost:4000/api/commander/execute \
105+
curl -sS "$BASE_URL/api/commander/execute" \
106+
-H "X-Auth-Token: $AUTH_TOKEN" \
85107
-H "Content-Type: application/json" \
86108
-d '{"command": "show-all-worktrees"}'
87109
```
@@ -100,10 +122,11 @@ curl -s http://localhost:4000/api/commander/execute \
100122

101123
```bash
102124
# View all active sessions
103-
curl -s http://localhost:4000/api/commander/sessions | jq
125+
curl -sS "$BASE_URL/api/commander/sessions" -H "X-Auth-Token: $AUTH_TOKEN" | jq
104126

105127
# Send input to a specific session
106-
curl -s http://localhost:4000/api/commander/send-to-session \
128+
curl -sS "$BASE_URL/api/commander/send-to-session" \
129+
-H "X-Auth-Token: $AUTH_TOKEN" \
107130
-H "Content-Type: application/json" \
108131
-d '{"sessionId": "zoo-game-work1-claude", "input": "git status\n"}'
109132
```
@@ -112,18 +135,20 @@ curl -s http://localhost:4000/api/commander/send-to-session \
112135

113136
```bash
114137
# List all workspaces
115-
curl -s http://localhost:4000/api/workspaces | jq
138+
curl -sS "$BASE_URL/api/workspaces" -H "X-Auth-Token: $AUTH_TOKEN" | jq
116139

117140
# Scan for available repos
118-
curl -s http://localhost:4000/api/workspaces/scan-repos | jq
141+
curl -sS "$BASE_URL/api/workspaces/scan-repos" -H "X-Auth-Token: $AUTH_TOKEN" | jq
119142

120143
# Create a new worktree
121-
curl -s http://localhost:4000/api/workspaces/create-worktree \
144+
curl -sS "$BASE_URL/api/workspaces/create-worktree" \
145+
-H "X-Auth-Token: $AUTH_TOKEN" \
122146
-H "Content-Type: application/json" \
123147
-d '{"repoPath": "~/GitHub/games/monogame/zoo-game", "branchName": "feature/new-work"}'
124148

125149
# Remove a worktree
126-
curl -s http://localhost:4000/api/workspaces/remove-worktree \
150+
curl -sS "$BASE_URL/api/workspaces/remove-worktree" \
151+
-H "X-Auth-Token: $AUTH_TOKEN" \
127152
-H "Content-Type: application/json" \
128153
-d '{"worktreePath": "~/GitHub/games/monogame/zoo-game/work5"}'
129154
```
@@ -132,10 +157,11 @@ curl -s http://localhost:4000/api/workspaces/remove-worktree \
132157

133158
```bash
134159
# Get available project templates
135-
curl -s http://localhost:4000/api/greenfield/templates | jq
160+
curl -sS "$BASE_URL/api/greenfield/templates" -H "X-Auth-Token: $AUTH_TOKEN" | jq
136161

137162
# Create new project
138-
curl -s http://localhost:4000/api/greenfield/create \
163+
curl -sS "$BASE_URL/api/greenfield/create" \
164+
-H "X-Auth-Token: $AUTH_TOKEN" \
139165
-H "Content-Type: application/json" \
140166
-d '{"name": "my-project", "path": "~/GitHub", "template": "empty"}'
141167
```
@@ -144,43 +170,44 @@ curl -s http://localhost:4000/api/greenfield/create \
144170

145171
```bash
146172
# Check git status across worktrees
147-
curl -s http://localhost:4000/api/git/status | jq
173+
curl -sS "$BASE_URL/api/git/status" -H "X-Auth-Token: $AUTH_TOKEN" | jq
148174

149175
# Check for updates
150-
curl -s http://localhost:4000/api/git/check-updates | jq
176+
curl -sS "$BASE_URL/api/git/check-updates" -H "X-Auth-Token: $AUTH_TOKEN" | jq
151177

152178
# Pull updates
153-
curl -s http://localhost:4000/api/git/pull -X POST
179+
curl -sS "$BASE_URL/api/git/pull" -H "X-Auth-Token: $AUTH_TOKEN" -X POST
154180
```
155181

156182
## Quick Links & Favorites
157183

158184
```bash
159185
# Get quick links and favorites
160-
curl -s http://localhost:4000/api/quick-links | jq
186+
curl -sS "$BASE_URL/api/quick-links" -H "X-Auth-Token: $AUTH_TOKEN" | jq
161187

162188
# Get recent sessions
163-
curl -s http://localhost:4000/api/quick-links/recent-sessions | jq
189+
curl -sS "$BASE_URL/api/quick-links/recent-sessions" -H "X-Auth-Token: $AUTH_TOKEN" | jq
164190
```
165191

166192
## Continuity (Session Memory)
167193

168194
```bash
169195
# Get continuity ledger for current workspace
170-
curl -s http://localhost:4000/api/continuity/ledger | jq
196+
curl -sS "$BASE_URL/api/continuity/ledger" -H "X-Auth-Token: $AUTH_TOKEN" | jq
171197

172198
# Get workspace continuity info
173-
curl -s http://localhost:4000/api/continuity/workspace | jq
199+
curl -sS "$BASE_URL/api/continuity/workspace" -H "X-Auth-Token: $AUTH_TOKEN" | jq
174200
```
175201

176202
## User Settings
177203

178204
```bash
179205
# Get all user settings
180-
curl -s http://localhost:4000/api/user-settings | jq
206+
curl -sS "$BASE_URL/api/user-settings" -H "X-Auth-Token: $AUTH_TOKEN" | jq
181207

182208
# Update global settings
183-
curl -s http://localhost:4000/api/user-settings/global \
209+
curl -sS "$BASE_URL/api/user-settings/global" \
210+
-H "X-Auth-Token: $AUTH_TOKEN" \
184211
-X PUT -H "Content-Type: application/json" \
185212
-d '{"theme": "dark", "notifications": true}'
186213
```
@@ -189,7 +216,7 @@ curl -s http://localhost:4000/api/user-settings/global \
189216

190217
```bash
191218
# Get all port assignments
192-
curl -s http://localhost:4000/api/ports | jq
219+
curl -sS "$BASE_URL/api/ports" -H "X-Auth-Token: $AUTH_TOKEN" | jq
193220
```
194221

195222
## Direct File System Access
@@ -211,14 +238,15 @@ git -C ~/GitHub/games/monogame/zoo-game worktree list
211238

212239
### Broadcast message to all Claude sessions
213240
```bash
214-
for sid in $(curl -s http://localhost:4000/api/commander/sessions | jq -r '.sessions[] | select(.id | contains("claude")) | .id'); do
215-
curl -s http://localhost:4000/api/commander/send-to-session \
241+
for sid in $(curl -sS "$BASE_URL/api/commander/sessions" -H "X-Auth-Token: $AUTH_TOKEN" | jq -r '.sessions[] | select(.id | contains("claude")) | .id'); do
242+
curl -sS "$BASE_URL/api/commander/send-to-session" \
243+
-H "X-Auth-Token: $AUTH_TOKEN" \
216244
-H "Content-Type: application/json" \
217245
-d "{\"sessionId\": \"$sid\", \"input\": \"# Message from Commander\n\"}"
218246
done
219247
```
220248

221249
### Check what each session is working on
222250
```bash
223-
curl -s http://localhost:4000/api/commander/sessions | jq '.sessions[] | {id, status, branch}'
251+
curl -sS "$BASE_URL/api/commander/sessions" -H "X-Auth-Token: $AUTH_TOKEN" | jq '.sessions[] | {id, status, branch}'
224252
```

scripts/tauri/prepare-backend-resources.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ function buildResourceSyncStamp({
9696
srcLock,
9797
srcConfig,
9898
srcUserDefaults,
99+
srcCommanderInstructions,
99100
srcLicensePublicKey,
100101
srcUpdaterPublicKey,
101102
bundledNodePath
@@ -109,6 +110,7 @@ function buildResourceSyncStamp({
109110
packageLock: statSignature(srcLock),
110111
configJson: statSignature(srcConfig),
111112
userSettingsDefaultJson: statSignature(srcUserDefaults),
113+
commanderInstructions: statSignature(srcCommanderInstructions),
112114
createProjectScript: statSignature(path.join(srcScripts, 'create-project.js')),
113115
licensePublicKey: statSignature(srcLicensePublicKey),
114116
updaterPublicKey: statSignature(srcUpdaterPublicKey),
@@ -231,6 +233,13 @@ function main() {
231233
const srcLock = path.join(repoRoot, 'package-lock.json');
232234
const srcConfig = path.join(repoRoot, 'config.json');
233235
const srcUserDefaults = path.join(repoRoot, 'user-settings.default.json');
236+
const srcCommanderInstructions = (() => {
237+
const docsPath = path.join(repoRoot, 'docs', 'COMMANDER_CLAUDE.md');
238+
if (fs.existsSync(docsPath)) return docsPath;
239+
const rootPath = path.join(repoRoot, 'COMMANDER_CLAUDE.md');
240+
if (fs.existsSync(rootPath)) return rootPath;
241+
return null;
242+
})();
234243
const srcLicensePublicKey =
235244
process.env.ORCHESTRATOR_LICENSE_PUBLIC_KEY_PATH
236245
|| process.env.TAURI_LICENSE_PUBLIC_KEY_PATH
@@ -275,6 +284,7 @@ function main() {
275284
srcLock,
276285
srcConfig,
277286
srcUserDefaults,
287+
srcCommanderInstructions,
278288
srcLicensePublicKey,
279289
srcUpdaterPublicKey,
280290
bundledNodePath
@@ -286,6 +296,13 @@ function main() {
286296
path.join(outDir, 'scripts', 'create-project.js'),
287297
path.join(outDir, 'package.json')
288298
];
299+
if (srcCommanderInstructions) {
300+
requiredResourcePaths.push(
301+
path.join(outDir, 'COMMANDER_CLAUDE.md'),
302+
path.join(outDir, 'CLAUDE.md'),
303+
path.join(outDir, 'AGENTS.md')
304+
);
305+
}
289306

290307
if (canReuseResourceSync({
291308
stampPath: resourceSyncStampPath,
@@ -334,6 +351,17 @@ function main() {
334351
} else {
335352
removeIfExists(path.join(outDir, 'user-settings.default.json'));
336353
}
354+
if (srcCommanderInstructions) {
355+
// Commander runs from the packaged backend root directory, so include a reduced
356+
// CLAUDE.md/AGENTS.md control-surface reference for both Claude Code and Codex CLI.
357+
copyFile(srcCommanderInstructions, path.join(outDir, 'COMMANDER_CLAUDE.md'));
358+
copyFile(srcCommanderInstructions, path.join(outDir, 'CLAUDE.md'));
359+
copyFile(srcCommanderInstructions, path.join(outDir, 'AGENTS.md'));
360+
} else {
361+
removeIfExists(path.join(outDir, 'COMMANDER_CLAUDE.md'));
362+
removeIfExists(path.join(outDir, 'CLAUDE.md'));
363+
removeIfExists(path.join(outDir, 'AGENTS.md'));
364+
}
337365
if (srcLicensePublicKey && fs.existsSync(srcLicensePublicKey)) {
338366
copyFile(srcLicensePublicKey, path.join(outDir, 'license-public-key.pem'));
339367
} else {

0 commit comments

Comments
 (0)