@whoz-oss/coday-web 0.0.0-workstream-forge.136 → 0.0.0-workstream-setup.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +181 -112
- package/index.js +85 -38
- package/launcher.js +75 -0
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -1,157 +1,226 @@
|
|
|
1
1
|
# Coday Web Package
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@whoz-oss/coday-web` is the launcher of the Coday web interface: it serves the Angular client, the Factory cockpit and
|
|
4
|
+
the Express server, and runs AgentOS and the Factory next to them.
|
|
4
5
|
|
|
5
|
-
##
|
|
6
|
+
## First run
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
┌─────────────────────────────────────────┐
|
|
11
|
-
│ coday-web (index.js) │
|
|
12
|
-
│ ┌───────────────────────────────────┐ │
|
|
13
|
-
│ │ 1. Resolve client package path │ │
|
|
14
|
-
│ │ 2. Set CODAY_CLIENT_PATH env var │ │
|
|
15
|
-
│ │ 3. Import and run server │ │
|
|
16
|
-
│ └───────────────────────────────────┘ │
|
|
17
|
-
└─────────────────────────────────────────┘
|
|
18
|
-
│
|
|
19
|
-
┌───────────┴───────────┐
|
|
20
|
-
▼ ▼
|
|
21
|
-
┌──────────────┐ ┌──────────────┐
|
|
22
|
-
│ coday-server │ │ coday-client │
|
|
23
|
-
│ (Express) │───────▶│ (Angular) │
|
|
24
|
-
└──────────────┘ └──────────────┘
|
|
8
|
+
```bash
|
|
9
|
+
npx @whoz-oss/coday-web
|
|
25
10
|
```
|
|
26
11
|
|
|
27
|
-
|
|
12
|
+
In a terminal (Nx mode, see below) the browser opens by itself. On a **first run** it opens the wizard immediately,
|
|
13
|
+
on **`/welcome`** (`http://localhost:3000/welcome`): the wizard only talks to Coday's own server, so it does not wait
|
|
14
|
+
for AgentOS. Otherwise (setup done) it opens `/` **once AgentOS is healthy**, because the app calls AgentOS straight
|
|
15
|
+
away and would show a blank page until then; if AgentOS never becomes healthy (about 3 minutes: Java missing,
|
|
16
|
+
download failed...) nothing is opened and the `server` pane prints the URL to open yourself. Pass `--no-open` or set
|
|
17
|
+
`CODAY_NO_OPEN=1` to keep it closed. Without a terminal (`--managed`, desktop apps) nothing is opened: open the URL
|
|
18
|
+
printed as `Server is running on http://localhost:PORT` yourself. The wizard is a four-step flow:
|
|
28
19
|
|
|
29
|
-
|
|
20
|
+
1. **Your email.** It becomes your user ID and the AgentOS administrator. AgentOS and Factory JARs start downloading in
|
|
21
|
+
the background as soon as the page is open.
|
|
22
|
+
2. **Providers.** Anthropic, OpenAI and/or Requesty, each with an API key. With several, drag the cards (or use the
|
|
23
|
+
arrows) to rank them: rank 1 is preferred. At least one is required.
|
|
24
|
+
3. **Files folder.** Pick the folder your agent reads and writes (default `~/Coday`, created when missing).
|
|
25
|
+
4. **Checklist.** Download %, Java, AgentOS, providers, models, your personal namespace, the Coday agent, then
|
|
26
|
+
**Start with Coday**.
|
|
30
27
|
|
|
31
|
-
|
|
28
|
+
**Java 25 or newer is required** (AgentOS and Factory run on the JVM). When it is missing the wizard says so and shows the
|
|
29
|
+
install command for your system, then continues by itself.
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
Once done, `<configDir>/web-setup.json` holds `{ identity, setupDone }` (never an API key: the keys go to AgentOS only).
|
|
32
|
+
To run the wizard again on a real install, stop Coday and delete `web-setup.json` **and** `<configDir>/agentos/data`
|
|
33
|
+
(AgentOS fixes its administrator at its first boot). For the local stack of the monorepo, use `web:local -- --fresh`
|
|
34
|
+
instead (see below).
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
```
|
|
36
|
+
The command is always the same, `npx @whoz-oss/coday-web`: the wizard appears only while the setup is not done,
|
|
37
|
+
otherwise the app opens directly.
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
- The web launcher resolves the client package from node_modules
|
|
43
|
-
- Server serves pre-built static files from the client package
|
|
44
|
-
- Single process handles both server and client
|
|
39
|
+
## How it runs
|
|
45
40
|
|
|
46
|
-
|
|
41
|
+
```
|
|
42
|
+
interactive terminal no TTY / --managed / CODAY_NO_NX=1
|
|
43
|
+
──────────────────── ───────────────────────────────────
|
|
44
|
+
coday-web (index.js) coday-web (index.js)
|
|
45
|
+
└─ writes <configDir>/runtime/{nx,project}.json
|
|
46
|
+
└─ nx run coday:status └─ one process: Express + AgentOS + Factory
|
|
47
|
+
provision ─┬─ status (entry task) (what the desktop apps use; prints
|
|
48
|
+
│ ├─ server (pinned next `Server is running on http://localhost:PORT`)
|
|
49
|
+
│ │ to status,
|
|
50
|
+
│ │ opens the browser)
|
|
51
|
+
│ ├─ agentos (own pane)
|
|
52
|
+
│ └─ factory (own pane)
|
|
53
|
+
```
|
|
47
54
|
|
|
48
|
-
|
|
55
|
+
- **Nx mode** (default in a terminal). The launcher generates a tiny Nx workspace under `<configDir>/runtime/`
|
|
56
|
+
(no daemon, no cloud, no cache) and runs the bundled `nx`. `provision` is a quick task (profile, secrets, Java check,
|
|
57
|
+
ports → `runtime/state.json`); `status`, `server`, `agentos` and `factory` are continuous tasks, each with its own
|
|
58
|
+
pane. The launcher runs ONE target, `nx run coday:status`, and `status` depends on the three services, so Nx starts
|
|
59
|
+
them for it. `agentos` prints *Waiting for first-run setup → http://localhost:3000/welcome* until you gave your email;
|
|
60
|
+
`factory` waits for AgentOS to be healthy. Once Express listens, the `server` task opens the browser (see
|
|
61
|
+
*First run* for when); it never does when `--auth`, a non-loopback `--host`, `CI`, `--no-open` or `CODAY_NO_OPEN` say
|
|
62
|
+
so. The wait for AgentOS runs beside the server and never delays it or its shutdown. For an external AgentOS
|
|
63
|
+
(`AGENTOS_URL`) it probes that URL's `/management/health`, which is what the proxy targets.
|
|
64
|
+
- **The `status` pane.** The Nx TUI has no status bar, so a small dedicated task reads `runtime/state.json` and probes
|
|
65
|
+
the health URLs every second. It prints one line per meaningful change only: `agentos download 42%` (one line per
|
|
66
|
+
10%), `java ok` or the install hint, `agentos healthy :8224`, `factory healthy :8241`, `agentos external <origin>`
|
|
67
|
+
for an `AGENTOS_URL`/`FACTORY_URL`, and `Open -> http://localhost:3000/welcome` on a first run (`/` once the setup is
|
|
68
|
+
done; then the line says `(once agentos is healthy)` and is repeated without that note when it is: same rule as
|
|
69
|
+
the browser). In the
|
|
70
|
+
TUI, select a pane and pin it next to another one to keep the download and the URL on screen while you read the
|
|
71
|
+
logs of the others; press `?` for the key help of the Nx TUI. At startup `status` is pinned next to `server`: Nx
|
|
72
|
+
pins the initiating task and its first continuous dependency, but only for a single-target run (`nx run`), which is
|
|
73
|
+
why the launcher does not use `run-many`. That behaviour was derived from reading the Nx 23 sources (the native
|
|
74
|
+
TUI rendering of pinned panes could not be inspected): confirm it visually.
|
|
75
|
+
Because `status` depends on the services, none of them may exit while it runs (Nx would report an exited
|
|
76
|
+
dependency as crashed, and a failed one would skip `status`): a service that cannot start (no Java, download
|
|
77
|
+
failed, port taken) or that is external (`AGENTOS_URL`/`FACTORY_URL`) prints why and stays open until Ctrl+C.
|
|
78
|
+
- **Managed mode** (no TTY, `--managed`, or `CODAY_NO_NX=1`). Same code, one process, no Nx. The desktop apps spawn
|
|
79
|
+
`coday-web` without a terminal and keep working unchanged.
|
|
80
|
+
|
|
81
|
+
All the logic lives in the server package (`apps/server/src/lib/runtime`, `lib/setup`); the Nx workspace is only a
|
|
82
|
+
manifest calling `coday-server provision|agentos|factory|server|status`.
|
|
83
|
+
|
|
84
|
+
### Ports
|
|
85
|
+
|
|
86
|
+
The packaged stack prefers its own ports: **AgentOS 8224, Factory 8241, AgentOS embedded Neo4j Bolt 7788** (each falls
|
|
87
|
+
back to the next free port, the choice is written to `runtime/state.json`). The dev ports **8124 (AgentOS), 8141
|
|
88
|
+
(Factory) and 7688 (Bolt) are reserved for dev mode** (`pnpm web:serve:dev`, `bootRun`), so a packaged instance and a
|
|
89
|
+
dev stack run side by side without colliding or picking up each other's services.
|
|
90
|
+
|
|
91
|
+
### Logs
|
|
92
|
+
|
|
93
|
+
Each process writes to its own file, in addition to its pane / the console:
|
|
49
94
|
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
|
|
95
|
+
```
|
|
96
|
+
<configDir>/logs/server.log
|
|
97
|
+
<configDir>/logs/agentos.log
|
|
98
|
+
<configDir>/logs/factory.log
|
|
53
99
|
```
|
|
54
100
|
|
|
55
|
-
|
|
56
|
-
- Starts the Angular dev server on port 4200 (with HMR)
|
|
57
|
-
- Starts the Express server on port 4100 (with tsx watch)
|
|
58
|
-
- Server proxies non-API requests to Angular dev server
|
|
59
|
-
- Changes to client or server code trigger automatic reloads
|
|
60
|
-
|
|
61
|
-
**How it works in dev mode:**
|
|
62
|
-
1. Client runs with Angular CLI dev server (localhost:4200)
|
|
63
|
-
2. Server runs with tsx watch (localhost:4100)
|
|
64
|
-
3. Server detects `BUILD_ENV=development` and proxies to Angular
|
|
65
|
-
4. API routes (e.g., `/api/*`) are handled by the server
|
|
66
|
-
5. All other routes are proxied to Angular for client-side routing
|
|
101
|
+
`configDir` defaults to `~/.coday` (`--configDir <dir>` to change it).
|
|
67
102
|
|
|
68
|
-
|
|
103
|
+
### Security in laptop mode
|
|
69
104
|
|
|
70
|
-
|
|
105
|
+
Auth mode trusts identity headers, so every listener is bound to loopback: Express `127.0.0.1`, AgentOS
|
|
106
|
+
`--server.address=127.0.0.1`, Factory `FACTORY_BIND_HOST=127.0.0.1`. AgentOS and Factory run with
|
|
107
|
+
`*_SECURITY_MODE=auth`. Secrets (`FACTORY_FAKE_IDP_SECRET`, AgentOS and Factory encryption key/salt) are generated once into
|
|
108
|
+
`<configDir>/runtime/secrets.json` (mode `0600`). An install that already holds unencrypted data keeps `NONE` for that
|
|
109
|
+
service and logs a warning (encrypting existing data is a manual migration).
|
|
71
110
|
|
|
72
|
-
|
|
111
|
+
The first-run setup API (`/api/setup/*`: folder browser, apply) only answers loopback callers and is disabled once the
|
|
112
|
+
setup is done. Deployments (`--auth`), an external AgentOS (`AGENTOS_URL`), an imposed `AGENTOS_EXTERNAL_USERID` and
|
|
113
|
+
existing installs without a wizard identity keep their previous behaviour: no wizard, no redirect.
|
|
73
114
|
|
|
74
|
-
|
|
75
|
-
# Run only the client (Angular dev server)
|
|
76
|
-
pnpm client
|
|
115
|
+
## Environment variables and options
|
|
77
116
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
117
|
+
| Name | Effect |
|
|
118
|
+
|---|---|
|
|
119
|
+
| `--configDir <dir>` | Config directory (default `~/.coday`) |
|
|
120
|
+
| `--host <addr>` / `CODAY_HOST` | Interface Express listens on (default `127.0.0.1`; `0.0.0.0` with `--auth`) |
|
|
121
|
+
| `--managed` / `CODAY_NO_NX=1` | Force the single-process mode (no Nx) |
|
|
122
|
+
| `--no-open` / `CODAY_NO_OPEN=1` | Do not open the browser on start (only Nx mode opens it; never with `--auth`, a non-loopback host or `CI`) |
|
|
123
|
+
| `PORT` | Express port (strict when set; default 3000, 4100 in dev) |
|
|
124
|
+
| `AGENTOS_URL`, `FACTORY_URL` | Use an external AgentOS / Factory instead of managed ones |
|
|
125
|
+
| `AGENTOS_EXTERNAL_USERID` | Impose the identity forwarded to AgentOS (disables the wizard) |
|
|
126
|
+
| `CODAY_AGENTOS_VERSION`, `CODAY_FACTORY_VERSION` | JAR version to run (`dev` = JARs placed by hand in `<configDir>/{agentos,factory}`) |
|
|
127
|
+
| `CODAY_DEFAULT_FILES_DIR` | Folder proposed by the wizard instead of `~/Coday` |
|
|
128
|
+
| `CODAY_CLIENT_PATH`, `CODAY_FACTORY_COCKPIT_PATH` | Set by the launcher: where the static apps are |
|
|
129
|
+
| `BUILD_ENV=development` | Dev mode (proxy to the Angular dev servers) |
|
|
81
130
|
|
|
82
|
-
|
|
131
|
+
## Running the local code like an npx user: `web:local`
|
|
83
132
|
|
|
84
|
-
|
|
133
|
+
End users always run `npx @whoz-oss/coday-web`. In the monorepo the equivalent, one command whatever your setup state,
|
|
134
|
+
is:
|
|
85
135
|
|
|
86
136
|
```bash
|
|
87
|
-
#
|
|
88
|
-
pnpm nx run
|
|
89
|
-
|
|
90
|
-
#
|
|
91
|
-
pnpm nx run
|
|
137
|
+
pnpm nx run web:local # everyday: build local code, run it like an npx user, keeps your setup
|
|
138
|
+
pnpm nx run web:local -- --fresh # test the first-run wizard again (deletes the local config first)
|
|
139
|
+
pnpm nx run web:local -- --managed # single process, plain console (instead of the Nx TUI)
|
|
140
|
+
pnpm nx run web:local -- --no-open # do not open the browser (every restart would otherwise open a tab)
|
|
141
|
+
pnpm nx run web:local -- --port 3100 # pick the port
|
|
92
142
|
```
|
|
93
143
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
1. Modify `apps/web/index.js`
|
|
99
|
-
2. Test with local server: `node apps/web/index.js --no_auth`
|
|
100
|
-
3. Verify client resolution works correctly
|
|
101
|
-
4. Check that server starts and serves the client
|
|
102
|
-
|
|
103
|
-
## Environment Variables
|
|
104
|
-
|
|
105
|
-
- `CODAY_CLIENT_PATH`: Set by the web launcher to tell server where client files are
|
|
106
|
-
- `BUILD_ENV`: Set to `development` by server's serve target for dev mode
|
|
107
|
-
- `PORT`: Override default server port (default: 3000 production, 4100 dev)
|
|
144
|
+
The first time you get the wizard; afterwards the app opens directly on the instance you configured, so you can stop,
|
|
145
|
+
rebuild and restart as often as you like. The target builds the client, factory cockpit, server and web packages plus
|
|
146
|
+
the AgentOS and Factory boot JARs, then `scripts/web-local.ts` works in a **persistent root, `~/.coday-local`**:
|
|
108
147
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
148
|
+
```
|
|
149
|
+
~/.coday-local/
|
|
150
|
+
packs/ pnpm pack tarballs (emptied on every run)
|
|
151
|
+
install/ the tarballs installed with npm (recreated on every run, what npx does minus the registry)
|
|
152
|
+
config/ the --configDir (KEPT: web-setup.json, agentos/data, factory data, secrets)
|
|
153
|
+
files/Coday folder proposed by the wizard instead of ~/Coday
|
|
116
154
|
```
|
|
117
155
|
|
|
118
|
-
|
|
156
|
+
Every run re-packs and re-installs (the code may have changed), overwrites the `dev`-layout JARs in
|
|
157
|
+
`config/{agentos,factory}` (`agentos-service-dev.jar`, plugins in `plugins/`; the data directories are left alone) and
|
|
158
|
+
runs the installed `coday-web --configDir ~/.coday-local/config` with `CODAY_AGENTOS_VERSION=dev
|
|
159
|
+
CODAY_FACTORY_VERSION=dev`. It prints every path and whether this is a **first run** (no `setupDone` in
|
|
160
|
+
`web-setup.json`) or a **resume**. Your `~/.coday` and `~/Coday` are never touched (the script refuses a root that is, or
|
|
161
|
+
lies in, them, your home or the repository), and nothing is published.
|
|
119
162
|
|
|
120
|
-
|
|
163
|
+
| Option / env | Effect |
|
|
164
|
+
|---|---|
|
|
165
|
+
| `--fresh` | Delete `config/` and `files/` (printed) before starting: a brand-new first run |
|
|
166
|
+
| `--managed`, `--port <n>` | Single-process mode, Express port |
|
|
167
|
+
| `--no-open` | Do not open the browser (also `CODAY_NO_OPEN=1`) |
|
|
168
|
+
| `--prepare-only` | Prepare everything, print the paths as JSON on the last line, no server |
|
|
169
|
+
| `--clean` | Delete the **whole** root when the server stops (setup and data included) |
|
|
170
|
+
| `CODAY_LOCAL_DIR=<dir>` | Use another root than `~/.coday-local` (`CODAY_FIRST_RUN_DIR` is a deprecated alias) |
|
|
121
171
|
|
|
122
|
-
|
|
172
|
+
`web:first-run` is kept as an alias of `web:local -- --fresh`.
|
|
123
173
|
|
|
124
|
-
|
|
174
|
+
Automated version: `pnpm nx run client-e2e:first-run-e2e` drives the wizard with Playwright against a real AgentOS
|
|
175
|
+
(dummy keys, no LLM call) and checks the providers, models, personal namespace, Coday agent and shared folder through
|
|
176
|
+
the AgentOS REST API. It runs `web:local --fresh` on its own throwaway root (`FIRST_RUN_E2E_DIR` to choose it, it never
|
|
177
|
+
reads `CODAY_LOCAL_DIR`) and skips itself, with a reason, when Java 25 or the built JARs are missing.
|
|
125
178
|
|
|
126
|
-
|
|
127
|
-
# In development
|
|
128
|
-
pnpm install
|
|
129
|
-
pnpm nx run client:build
|
|
179
|
+
## Development (monorepo)
|
|
130
180
|
|
|
131
|
-
|
|
132
|
-
pnpm web:dev
|
|
181
|
+
```bash
|
|
182
|
+
pnpm web:serve:dev # nx run web:serve:dev: client, factory-cockpit, server, AgentOS and Factory, one pane each
|
|
183
|
+
pnpm web:dev # lighter: client + server only (no AgentOS/Factory; set AGENTOS_URL to use your own)
|
|
184
|
+
pnpm client # Angular dev server only (4200)
|
|
185
|
+
pnpm server # Express with tsx watch only (4100)
|
|
133
186
|
```
|
|
134
187
|
|
|
135
|
-
|
|
188
|
+
`web:serve:dev` is a set of continuous Nx tasks: `client:serve` (4200), `factory-cockpit:serve` (4300),
|
|
189
|
+
`web:dev-server` (Express, 4100), `web:dev-agentos` (`agentos-service:bootRun`, 8124) and `web:dev-factory`
|
|
190
|
+
(`factory-service:bootRun`, 8141). These are the dev-only ports; the packaged stack uses 8224 / 8241 (see *Ports*). The dev server uses the
|
|
191
|
+
external-service mode (`AGENTOS_URL`/`FACTORY_URL`), so the wizard is not shown: use `web:local -- --fresh` to test it.
|
|
136
192
|
|
|
137
|
-
|
|
193
|
+
### Building and testing
|
|
138
194
|
|
|
139
195
|
```bash
|
|
140
|
-
pnpm
|
|
196
|
+
pnpm nx run-many -t build -p client,factory-cockpit,server,web
|
|
197
|
+
pnpm nx run-many -t lint test -p server,web,client,agentos-ui,scripts
|
|
141
198
|
```
|
|
142
199
|
|
|
143
|
-
|
|
200
|
+
## Package dependencies
|
|
201
|
+
|
|
202
|
+
```json
|
|
203
|
+
{
|
|
204
|
+
"@whoz-oss/coday-client": "workspace:*",
|
|
205
|
+
"@whoz-oss/coday-factory-cockpit": "workspace:*",
|
|
206
|
+
"@whoz-oss/coday-server": "workspace:*",
|
|
207
|
+
"nx": "catalog:dev"
|
|
208
|
+
}
|
|
209
|
+
```
|
|
144
210
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
2. Express server should be on port 4100
|
|
148
|
-
3. Access the app via http://localhost:4100
|
|
211
|
+
`nx` is a runtime dependency here (it is the process manager of the interactive mode), which makes the package larger
|
|
212
|
+
than the former thin launcher. Versions of the `platform:npm` packages move in lockstep: never edit them by hand.
|
|
149
213
|
|
|
150
|
-
##
|
|
214
|
+
## Troubleshooting
|
|
151
215
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
216
|
+
- **"Could not resolve @whoz-oss/coday-client package"**: the client is not built or installed. `pnpm install` and
|
|
217
|
+
`pnpm nx run client:build`, or use `pnpm web:serve:dev`.
|
|
218
|
+
- **The Nx panes do not show / garbled output**: use `--managed` (or `CODAY_NO_NX=1`) for plain console output.
|
|
219
|
+
- **"Waiting for first-run setup" never ends**: open the URL printed in the pane (or the `Open ->` line of the `status`
|
|
220
|
+
pane) and answer the wizard.
|
|
221
|
+
- **The browser did not open**: headless Linux or no `xdg-open`, or AgentOS is not healthy yet (the app is only opened
|
|
222
|
+
once it is); the `server` pane logs one line and the `status` pane shows the URL.
|
|
223
|
+
- **A blank page on `/`**: AgentOS is not up yet (the app waits up to 90 s for it). Look at the `agentos` pane / log,
|
|
224
|
+
Java 25 is the usual cause.
|
|
225
|
+
- **Java missing or too old**: install Java 25 (the wizard shows the command), the page continues by itself.
|
|
226
|
+
- **Port already in use**: `PORT=3100 npx @whoz-oss/coday-web`.
|
package/index.js
CHANGED
|
@@ -2,30 +2,30 @@
|
|
|
2
2
|
import { fileURLToPath, pathToFileURL } from 'url';
|
|
3
3
|
import { dirname, resolve } from 'path';
|
|
4
4
|
import { existsSync } from 'fs';
|
|
5
|
+
import { spawn, spawnSync } from 'child_process';
|
|
5
6
|
import { createRequire } from 'module';
|
|
7
|
+
import { chooseMode, nxArgs, nxEnv, parseWorkspaceDir, resolveConfigDir, serverArgs } from './launcher.js';
|
|
6
8
|
|
|
7
9
|
const __filename = fileURLToPath(import.meta.url);
|
|
8
10
|
const __dirname = dirname(__filename);
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* Coday Web Launcher
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* 3.
|
|
14
|
+
*
|
|
15
|
+
* 1. Resolves the client, factory cockpit and server packages at runtime.
|
|
16
|
+
* 2. Interactive terminal: writes a generated Nx workspace under <configDir>/runtime/ and runs the
|
|
17
|
+
* bundled `nx` on it, so the server, AgentOS and the Factory each get their own pane and log file.
|
|
18
|
+
* 3. No TTY (desktop apps), --managed or CODAY_NO_NX=1: runs everything inside the server process,
|
|
19
|
+
* exactly like before (it still prints `Server is running on http://localhost:PORT`).
|
|
17
20
|
*/
|
|
18
21
|
|
|
19
22
|
// Create require function for resolving packages
|
|
20
23
|
const require = createRequire(import.meta.url);
|
|
21
24
|
|
|
22
25
|
/**
|
|
23
|
-
* Resolve
|
|
24
|
-
*
|
|
25
|
-
* Tries multiple resolution strategies:
|
|
26
|
+
* Resolve a static package location. Tries, in order:
|
|
26
27
|
* 1. Standard node_modules resolution (production/npx)
|
|
27
|
-
* 2.
|
|
28
|
-
* 3. Relative path fallback (monorepo development)
|
|
28
|
+
* 2. Relative path fallback (monorepo development)
|
|
29
29
|
*/
|
|
30
30
|
function resolveStaticPackagePath(packageName, developmentPath, displayName) {
|
|
31
31
|
const developmentBrowserPath = resolve(__dirname, developmentPath);
|
|
@@ -65,7 +65,27 @@ function resolveStaticPackagePath(packageName, developmentPath, displayName) {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
function resolveServerMain() {
|
|
69
|
+
try {
|
|
70
|
+
const serverPackagePath = require.resolve('@whoz-oss/coday-server/package.json');
|
|
71
|
+
const packagedServerMainPath = resolve(dirname(serverPackagePath), 'server.js');
|
|
72
|
+
const developmentServerMainPath = resolve(__dirname, '../server/dist/server.js');
|
|
73
|
+
const serverMainPath = existsSync(packagedServerMainPath) ? packagedServerMainPath : developmentServerMainPath;
|
|
74
|
+
if (!existsSync(serverMainPath)) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
`Server entry point is missing. Checked paths: ${packagedServerMainPath}, ${developmentServerMainPath}`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
return serverMainPath;
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error('Could not resolve @whoz-oss/coday-server package.');
|
|
82
|
+
console.error('Please ensure dependencies are installed: pnpm install');
|
|
83
|
+
console.error('Error:', error.message);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Resolve and expose static application paths to the server (and, through env inheritance, to every Nx task).
|
|
69
89
|
const clientPath = resolveStaticPackagePath('@whoz-oss/coday-client', '../client/dist/browser', 'Client');
|
|
70
90
|
const factoryCockpitPath = resolveStaticPackagePath(
|
|
71
91
|
'@whoz-oss/coday-factory-cockpit',
|
|
@@ -78,34 +98,61 @@ process.env.CODAY_FACTORY_COCKPIT_PATH = factoryCockpitPath;
|
|
|
78
98
|
console.log(`Coday Web: Using client files from ${clientPath}`);
|
|
79
99
|
console.log(`Coday Web: Using factory cockpit files from ${factoryCockpitPath}`);
|
|
80
100
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const developmentServerMainPath = resolve(__dirname, '../server/dist/server.js');
|
|
89
|
-
const serverMainPath = existsSync(packagedServerMainPath)
|
|
90
|
-
? packagedServerMainPath
|
|
91
|
-
: developmentServerMainPath;
|
|
92
|
-
|
|
93
|
-
if (!existsSync(serverMainPath)) {
|
|
94
|
-
throw new Error(
|
|
95
|
-
`Server entry point is missing. Checked paths: ${packagedServerMainPath}, ${developmentServerMainPath}`
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Import the server module
|
|
101
|
+
const serverMainPath = resolveServerMain();
|
|
102
|
+
const rawArgs = process.argv.slice(2);
|
|
103
|
+
const { mode, reason } = chooseMode({ argv: rawArgs, env: process.env, isTTY: process.stdout.isTTY });
|
|
104
|
+
|
|
105
|
+
async function runManaged() {
|
|
106
|
+
// The server reads process.argv: hide the launcher-only flags from it.
|
|
107
|
+
process.argv = [process.argv[0], process.argv[1], ...serverArgs(rawArgs)];
|
|
100
108
|
// Convert Windows absolute path to file:// URL for ESM import
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
109
|
+
await import(pathToFileURL(serverMainPath).href);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function runNx() {
|
|
113
|
+
const configDir = resolveConfigDir(rawArgs);
|
|
114
|
+
|
|
115
|
+
let nxBin;
|
|
116
|
+
try {
|
|
117
|
+
nxBin = require.resolve('nx/bin/nx.js');
|
|
118
|
+
} catch (error) {
|
|
119
|
+
console.warn(`Nx is not available (${error.message}): falling back to the in-process mode.`);
|
|
120
|
+
return runManaged();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// 1. Generate the Nx workspace (the bundled server knows how: single implementation).
|
|
124
|
+
const generated = spawnSync(process.execPath, [serverMainPath, 'workspace', ...serverArgs(rawArgs)], {
|
|
125
|
+
encoding: 'utf8',
|
|
126
|
+
stdio: ['ignore', 'pipe', 'inherit'],
|
|
127
|
+
env: process.env,
|
|
128
|
+
});
|
|
129
|
+
const workspaceDir = parseWorkspaceDir(generated.stdout);
|
|
130
|
+
if (generated.status !== 0 || !workspaceDir || !existsSync(workspaceDir)) {
|
|
131
|
+
console.error('Could not generate the runtime workspace; falling back to the in-process mode.');
|
|
132
|
+
return runManaged();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
console.log(`Coday Web: runtime workspace ${workspaceDir} (logs in ${resolve(configDir, 'logs')})`);
|
|
136
|
+
|
|
137
|
+
// 2. Run the continuous tasks. Nx draws one pane per process, in the terminal.
|
|
138
|
+
const nx = spawn(process.execPath, [nxBin, ...nxArgs()], {
|
|
139
|
+
cwd: workspaceDir,
|
|
140
|
+
env: nxEnv(process.env, configDir),
|
|
141
|
+
stdio: 'inherit',
|
|
142
|
+
});
|
|
143
|
+
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
|
|
144
|
+
process.on(signal, () => nx.kill(signal));
|
|
145
|
+
}
|
|
146
|
+
nx.on('error', (error) => {
|
|
147
|
+
console.error('Failed to start nx:', error.message);
|
|
104
148
|
process.exit(1);
|
|
105
149
|
});
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
console.error('Please ensure dependencies are installed: pnpm install');
|
|
109
|
-
console.error('Error:', error.message);
|
|
110
|
-
process.exit(1);
|
|
150
|
+
nx.on('exit', (code) => process.exit(code ?? 0));
|
|
151
|
+
return undefined;
|
|
111
152
|
}
|
|
153
|
+
|
|
154
|
+
console.log(`Coday Web: ${mode} mode (${reason})`);
|
|
155
|
+
(mode === 'nx' ? Promise.resolve().then(runNx) : runManaged()).catch((error) => {
|
|
156
|
+
console.error('Failed to start server:', error);
|
|
157
|
+
process.exit(1);
|
|
158
|
+
});
|
package/launcher.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers of the coday-web launcher (no side effects at import time).
|
|
3
|
+
* Tested with `node --test` (see launcher.test.js, run by the `web:test` Nx target).
|
|
4
|
+
*/
|
|
5
|
+
import { homedir } from 'os';
|
|
6
|
+
import { join } from 'path';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Decide how to run: `nx` (generated workspace, one pane per process) or `managed` (everything in the
|
|
10
|
+
* server process, which is what the desktop apps need).
|
|
11
|
+
*
|
|
12
|
+
* managed when: `--managed` flag, `CODAY_NO_NX=1`, or stdout is not a TTY (desktop apps spawn us
|
|
13
|
+
* without one, and the Nx TUI needs a terminal anyway).
|
|
14
|
+
*/
|
|
15
|
+
export function chooseMode({ argv, env, isTTY }) {
|
|
16
|
+
if (argv.includes('--managed')) return { mode: 'managed', reason: '--managed flag' };
|
|
17
|
+
if (env.CODAY_NO_NX === '1' || env.CODAY_NO_NX === 'true') return { mode: 'managed', reason: 'CODAY_NO_NX is set' };
|
|
18
|
+
if (!isTTY) return { mode: 'managed', reason: 'no TTY (desktop app, CI, pipe)' };
|
|
19
|
+
return { mode: 'nx', reason: 'interactive terminal' };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** `--configDir <dir>` / `--configDir=<dir>` / `--coday_config_dir ...`, default `~/.coday`. */
|
|
23
|
+
export function resolveConfigDir(argv, home = homedir()) {
|
|
24
|
+
for (let i = 0; i < argv.length; i++) {
|
|
25
|
+
const arg = argv[i];
|
|
26
|
+
for (const flag of ['--configDir', '--coday_config_dir']) {
|
|
27
|
+
if (arg === flag && argv[i + 1]) return argv[i + 1];
|
|
28
|
+
if (arg.startsWith(`${flag}=`)) return arg.slice(flag.length + 1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return join(home, '.coday');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The arguments the server must see: the launcher's own (`--managed`) are removed. */
|
|
35
|
+
export function serverArgs(argv) {
|
|
36
|
+
return argv.filter((a) => a !== '--managed');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Marker the server's `workspace` command prints before the directory it generated. */
|
|
40
|
+
export const WORKSPACE_MARKER = 'CODAY_RUNTIME_WORKSPACE=';
|
|
41
|
+
|
|
42
|
+
/** The generated workspace directory, found among any other stdout lines; undefined when absent. */
|
|
43
|
+
export function parseWorkspaceDir(stdout) {
|
|
44
|
+
const line = String(stdout ?? '')
|
|
45
|
+
.split('\n')
|
|
46
|
+
.map((l) => l.trim())
|
|
47
|
+
.reverse()
|
|
48
|
+
.find((l) => l.startsWith(WORKSPACE_MARKER));
|
|
49
|
+
const dir = line?.slice(WORKSPACE_MARKER.length).trim();
|
|
50
|
+
return dir || undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Arguments of `nx run`: ONE target, `coday:status`, whose continuous dependencies are the server, AgentOS and the
|
|
55
|
+
* Factory (each gets its own TUI pane). A single-target run makes the Nx TUI pin the initiating task (`status`) and
|
|
56
|
+
* its first continuous dependency (`server`) at startup; `run-many` pins nothing. The target names are those of
|
|
57
|
+
* NX_ENTRY_TASK / NX_SERVICES in apps/server/src/lib/runtime/workspace.ts (a server spec checks they match).
|
|
58
|
+
* `--parallel` only caps discrete tasks (`provision`): continuous tasks have their own threads.
|
|
59
|
+
*/
|
|
60
|
+
export function nxArgs() {
|
|
61
|
+
return ['run', 'coday:status', '--parallel=5', '--outputStyle=tui'];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Environment of the Nx process: no daemon, no cloud, no cache. */
|
|
65
|
+
export function nxEnv(env, configDir) {
|
|
66
|
+
return {
|
|
67
|
+
...env,
|
|
68
|
+
NX_DAEMON: 'false',
|
|
69
|
+
NX_NO_CLOUD: 'true',
|
|
70
|
+
NX_SKIP_NX_CACHE: 'true',
|
|
71
|
+
NX_TUI: 'true',
|
|
72
|
+
NX_WORKSPACE_DATA_DIRECTORY: join(configDir, 'runtime', '.nx'),
|
|
73
|
+
NX_CACHE_DIRECTORY: join(configDir, 'runtime', '.nx', 'cache'),
|
|
74
|
+
};
|
|
75
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@whoz-oss/coday-web",
|
|
3
|
-
"version": "0.0.0-workstream-
|
|
3
|
+
"version": "0.0.0-workstream-setup.4",
|
|
4
4
|
"repository": "https://github.com/whoz-oss/coday",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -8,12 +8,14 @@
|
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"index.js",
|
|
11
|
+
"launcher.js",
|
|
11
12
|
"README.md"
|
|
12
13
|
],
|
|
13
14
|
"dependencies": {
|
|
14
|
-
"
|
|
15
|
-
"@whoz-oss/coday-
|
|
16
|
-
"@whoz-oss/coday-
|
|
15
|
+
"nx": "23.1.1",
|
|
16
|
+
"@whoz-oss/coday-client": "0.0.0-workstream-setup.4",
|
|
17
|
+
"@whoz-oss/coday-factory-cockpit": "0.0.0-workstream-setup.4",
|
|
18
|
+
"@whoz-oss/coday-server": "0.0.0-workstream-setup.4"
|
|
17
19
|
},
|
|
18
20
|
"publishConfig": {
|
|
19
21
|
"access": "public"
|