Commit aebad4a
feat(cli): Server Edition server-mode — gateway login/workspace commands, remote transport, headless entry hardening (#81)
### Issue for this PR
Closes #
### Type of change
- [ ] Bug fix
- [x] New feature
- [ ] Refactor / code improvement
- [ ] Documentation
### What does this PR do?
This PR prepares the new CLI (`packages/cli`, `dacode`) and the headless
server to act as a client/data-plane for DeepAgent Server Edition
(design: server-v1 §11/§13/§20). The CLI now connects to a gateway with
JWT auth and routes workspace traffic through the `/w/:workspaceId`
transparent proxy instead of a local daemon.
**CLI changes:**
- `dacode login [gateway] [--email --password]` / `logout` –
authenticate via `POST /control/v1/auth/login`, store state in
`~/.deepagent/code/state/server-mode.json` (0600, atomic temp+rename).
Flags optional; fallback to interactive prompts. Refresh token read from
response body, with `Set-Cookie` as fallback.
- `dacode workspace list` / `dacode workspace use <id>` – list gateway
workspaces and pin a selection; remote base URL becomes
`{gateway}/w/{workspaceId}`.
- The `Connection` service switches to remote transport when server-mode
is active; otherwise uses the existing local daemon (unchanged
behavior).
- Remote transport is a fetch wrapper that injects `Authorization:
Bearer` and, on 401, performs a single-flight token refresh with one
retry. Since the TUI already accepts a custom `fetch`, all TUI/SDK
traffic (including SSE) gets auth + reconnect without any changes to
`packages/tui`.
- `DEEPAGENT_GATEWAY_URL` pins the gateway (server-v1 §20.3
auto-switch); a mismatch with stored login produces a clear error
suggesting `dacode login <url>`.
**Server changes (`packages/deepagent-code`):**
- Add explicit `"./server"` subpath export so `import { listen, openapi
} from "deepagent-code/server"` resolves as documented for the
workspace-agent.
- `/global/capabilities` gains an optional `commit` field from
`DEEPAGENT_CODE_COMMIT` (injected by CI for version-checking, §13.3).
Omitted in local builds; optional in schema for backward compatibility.
- `DEEPAGENT_SERVER_MODE=true` makes `Auth.set`/`Auth.remove` fail with
a clear error – in gateway-managed containers, provider keys come via
env and must not persist to volume (§20.4). Reads (including
`DEEPAGENT_CODE_AUTH_CONTENT`) are unaffected.
> **Note:** The gateway itself (`deepagent-code-server` repo) is not
implemented yet; the refresh-cookie contract may need a follow-up once
the real gateway exists.
### How did you verify your code works?
- `bun typecheck` passes for `packages/cli`, `packages/core`,
`packages/deepagent-code`.
- End-to-end against a mock gateway (`Bun.serve` implementing auth
endpoints, workspace listing, and proxy paths): covered login via
args/env, state file permissions, workspace list/use with expired token
refresh, remote transport URL and auth injection, logout, and gateway
mismatch errors.
- Server tests: started the legacy server via the new subpath export,
confirmed `/global/capabilities` returns the injected commit and
`openapi()` works; `Auth.set`/`Auth.remove` are blocked under
`DEEPAGENT_SERVER_MODE=true`; without it `auth.json` is written with
mode 600.
- Existing related suites pass: `test/auth/auth.test.ts`,
`test/server/httpapi-global.test.ts`,
`test/server/httpapi-public-openapi.test.ts`.
(`test/server/httpapi-listen.test.ts` has PTY failures that reproduce
identically on the base commit in this environment.)
### Screenshots / recordings
_No UI changes._
### Checklist
- [x] I have tested my changes locally
- [x] I have not included unrelated changes in this PR
---------
Co-authored-by: deepagent-ai <jamessmithm539@gmail.com>1 parent f171a9a commit aebad4a
23 files changed
Lines changed: 1269 additions & 28 deletions
File tree
- packages
- cli
- src
- commands
- handlers
- workspace
- framework
- services
- test
- core/src/flag
- deepagent-code
- src
- auth
- server/routes/instance/httpapi
- groups
- handlers
- test/auth
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
15 | 34 | | |
16 | 35 | | |
17 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
| 8 | + | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| |||
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
13 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
14 | 18 | | |
15 | | - | |
| 19 | + | |
16 | 20 | | |
17 | | - | |
| 21 | + | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
15 | 23 | | |
16 | 24 | | |
17 | 25 | | |
| |||
24 | 32 | | |
25 | 33 | | |
26 | 34 | | |
| 35 | + | |
| 36 | + | |
27 | 37 | | |
28 | 38 | | |
29 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
0 commit comments