codeharbor 0.1.0 → 0.1.2

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.
Files changed (4) hide show
  1. package/.env.example +78 -0
  2. package/README.md +229 -2
  3. package/dist/cli.js +2792 -49
  4. package/package.json +18 -5
package/.env.example ADDED
@@ -0,0 +1,78 @@
1
+ MATRIX_HOMESERVER=https://matrix.biglone.tech
2
+ MATRIX_USER_ID=@codeharbor-bot:example.com
3
+ MATRIX_ACCESS_TOKEN=
4
+
5
+ # Optional explicit trigger in groups; can be empty to disable prefix trigger.
6
+ MATRIX_COMMAND_PREFIX=!code
7
+
8
+ CODEX_BIN=codex
9
+ CODEX_MODEL=
10
+ CODEX_WORKDIR=/Users/biglone/workspace
11
+ CODEX_DANGEROUS_BYPASS=false
12
+ CODEX_EXEC_TIMEOUT_MS=600000
13
+ CODEX_SANDBOX_MODE=
14
+ CODEX_APPROVAL_POLICY=
15
+ # Optional extra CLI args, space separated (example: --search --no-alt-screen)
16
+ CODEX_EXTRA_ARGS=
17
+ # Optional JSON object for additional environment variables passed to codex child process.
18
+ CODEX_EXTRA_ENV_JSON=
19
+
20
+ # SQLite state database path.
21
+ STATE_DB_PATH=data/state.db
22
+ # Legacy JSON path for one-time migration import.
23
+ STATE_PATH=data/state.json
24
+
25
+ MAX_PROCESSED_EVENTS_PER_SESSION=200
26
+ MAX_SESSION_AGE_DAYS=30
27
+ MAX_SESSIONS=5000
28
+ REPLY_CHUNK_SIZE=3500
29
+
30
+ MATRIX_PROGRESS_UPDATES=true
31
+ MATRIX_PROGRESS_MIN_INTERVAL_MS=2500
32
+ MATRIX_TYPING_TIMEOUT_MS=10000
33
+ SESSION_ACTIVE_WINDOW_MINUTES=20
34
+
35
+ # Group trigger defaults.
36
+ GROUP_TRIGGER_ALLOW_MENTION=true
37
+ GROUP_TRIGGER_ALLOW_REPLY=true
38
+ GROUP_TRIGGER_ALLOW_ACTIVE_WINDOW=true
39
+ GROUP_TRIGGER_ALLOW_PREFIX=true
40
+
41
+ # Optional room-level trigger overrides (JSON object).
42
+ # ROOM_TRIGGER_POLICY_JSON={"!room:example.com":{"allowMention":true,"allowReply":true,"allowActiveWindow":false,"allowPrefix":false}}
43
+ ROOM_TRIGGER_POLICY_JSON=
44
+
45
+ # Rate limiting / anti-abuse.
46
+ RATE_LIMIT_WINDOW_SECONDS=60
47
+ RATE_LIMIT_MAX_REQUESTS_PER_USER=20
48
+ RATE_LIMIT_MAX_REQUESTS_PER_ROOM=120
49
+ RATE_LIMIT_MAX_CONCURRENT_GLOBAL=8
50
+ RATE_LIMIT_MAX_CONCURRENT_PER_USER=1
51
+ RATE_LIMIT_MAX_CONCURRENT_PER_ROOM=4
52
+
53
+ # CLI compatibility mode (IM shell approximation of codex CLI).
54
+ CLI_COMPAT_MODE=false
55
+ CLI_COMPAT_PASSTHROUGH_EVENTS=true
56
+ CLI_COMPAT_PRESERVE_WHITESPACE=true
57
+ CLI_COMPAT_DISABLE_REPLY_CHUNK_SPLIT=false
58
+ CLI_COMPAT_PROGRESS_THROTTLE_MS=300
59
+ CLI_COMPAT_FETCH_MEDIA=true
60
+ # Optional JSONL output path for executed prompt recording (for replay benchmarking).
61
+ CLI_COMPAT_RECORD_PATH=
62
+
63
+ DOCTOR_HTTP_TIMEOUT_MS=10000
64
+
65
+ # Admin API server (for config UI/backend).
66
+ ADMIN_BIND_HOST=127.0.0.1
67
+ ADMIN_PORT=8787
68
+ # Token protection for /api/admin/* endpoints.
69
+ # Strongly recommended for any non-localhost access.
70
+ # Required when exposing admin via reverse proxy/tunnel/public domain.
71
+ ADMIN_TOKEN=
72
+ # Optional IP allowlist (comma-separated, for example: 127.0.0.1,192.168.1.10).
73
+ ADMIN_IP_ALLOWLIST=
74
+ # Optional browser origin allowlist for CORS (comma-separated).
75
+ # Example: https://admin.example.com,https://ops.example.com
76
+ ADMIN_ALLOWED_ORIGINS=
77
+
78
+ LOG_LEVEL=info
package/README.md CHANGED
@@ -37,7 +37,7 @@ Matrix Room -> MatrixChannel -> Orchestrator -> CodexExecutor (codex exec/resume
37
37
 
38
38
  ## Prerequisites
39
39
 
40
- - Node.js 20+
40
+ - Node.js 22+
41
41
  - `codex` CLI installed and authenticated (`codex login`)
42
42
  - A Matrix bot user + access token
43
43
 
@@ -49,6 +49,44 @@ Install globally from npm (after publish):
49
49
  npm install -g codeharbor
50
50
  ```
51
51
 
52
+ Linux one-command install (creates `/opt/codeharbor`, sets ownership, installs latest package):
53
+
54
+ ```bash
55
+ curl -fsSL https://raw.githubusercontent.com/biglone/CodeHarbor/main/scripts/install-linux.sh | bash
56
+ ```
57
+
58
+ Linux easy mode (install + write `.env` + enable/start systemd in one run):
59
+
60
+ ```bash
61
+ curl -fsSL https://raw.githubusercontent.com/biglone/CodeHarbor/main/scripts/install-linux-easy.sh | bash -s -- \
62
+ --matrix-homeserver https://matrix.example.com \
63
+ --matrix-user-id @bot:example.com \
64
+ --matrix-access-token 'your-token'
65
+ ```
66
+
67
+ Enable Admin service at install time:
68
+
69
+ ```bash
70
+ curl -fsSL https://raw.githubusercontent.com/biglone/CodeHarbor/main/scripts/install-linux-easy.sh | bash -s -- \
71
+ --matrix-homeserver https://matrix.example.com \
72
+ --matrix-user-id @bot:example.com \
73
+ --matrix-access-token 'your-token' \
74
+ --enable-admin-service \
75
+ --admin-token 'replace-with-strong-token'
76
+ ```
77
+
78
+ Run local script with custom options:
79
+
80
+ ```bash
81
+ ./scripts/install-linux.sh --app-dir /srv/codeharbor --package codeharbor@0.1.1 --init
82
+ ```
83
+
84
+ Runtime home behavior:
85
+
86
+ - By default, all `codeharbor` commands use `/opt/codeharbor` for `.env` and relative data paths.
87
+ - No manual `cd /opt/codeharbor` is required after installation.
88
+ - To use a custom runtime directory, set `CODEHARBOR_HOME` (for example `export CODEHARBOR_HOME=/srv/codeharbor`).
89
+
52
90
  Install directly from GitHub:
53
91
 
54
92
  ```bash
@@ -62,6 +100,64 @@ npm pack
62
100
  npm install -g ./codeharbor-<version>.tgz
63
101
  ```
64
102
 
103
+ ## GitHub CI/CD Publish
104
+
105
+ CodeHarbor supports auto publish to npm from GitHub Actions.
106
+
107
+ Setup once:
108
+
109
+ 1. Add repository secret `NPM_TOKEN` (npm token with publish permission).
110
+ 2. Push to `main` with a publish trigger commit message.
111
+
112
+ Trigger rules:
113
+
114
+ - `push` to `main` + commit message includes `[publish-npm]` -> run publish workflow
115
+ - `push` to `main` + commit message includes both `release` and a semver version -> run publish workflow
116
+ - examples: `release v0.1.1`, `chore: release 0.1.2`
117
+ - `workflow_dispatch` -> manual publish from GitHub Actions UI
118
+
119
+ The workflow runs `typecheck`, `test`, `test:e2e` (Admin UI Playwright), `build`, `node dist/cli.js --help`, `npm pack --dry-run`, then publishes with:
120
+
121
+ ```bash
122
+ npm publish --access public
123
+ ```
124
+
125
+ If the same package version already exists on npm, publish is skipped automatically.
126
+
127
+ Release checklist (recommended):
128
+
129
+ 1. Update version in `package.json` (`npm version patch|minor|major`).
130
+ 2. Push to `main` with `[publish-npm]` or `release vX.Y.Z` in commit message.
131
+ 3. Verify workflow status in GitHub Actions.
132
+ 4. Verify package on npm:
133
+
134
+ ```bash
135
+ npm view codeharbor version
136
+ ```
137
+
138
+ Run e2e locally:
139
+
140
+ ```bash
141
+ npm run test:e2e
142
+ ```
143
+
144
+ If your machine has no system Chrome, run:
145
+
146
+ ```bash
147
+ PLAYWRIGHT_USE_SYSTEM_CHROME=false npm run e2e:install
148
+ PLAYWRIGHT_USE_SYSTEM_CHROME=false npm run test:e2e
149
+ ```
150
+
151
+ ## Planning Docs
152
+
153
+ - `REQUIREMENTS.md`: current baseline + next-stage requirements
154
+ - `TASK_LIST.md`: implementation task breakdown and status
155
+ - `docs/CONFIG_UI_DESIGN.md`: configuration UI MVP design
156
+ - `docs/CONFIG_CATALOG.md`: consolidated configuration matrix (required/runtime/UI/effective timing)
157
+ - `docs/ADMIN_STANDALONE_DEPLOY.md`: standalone admin deployment and Cloudflare Tunnel exposure guide
158
+ - `docs/BACKUP_AUTOMATION.md`: scheduled config backup and restore operations
159
+ - `docs/RELEASE.md`: release process and CI/publish policy
160
+
65
161
  ## Quick Start
66
162
 
67
163
  For local development from source:
@@ -75,7 +171,8 @@ npm install
75
171
  2. Configure environment:
76
172
 
77
173
  ```bash
78
- cp .env.example .env
174
+ export CODEHARBOR_HOME="$(pwd)"
175
+ codeharbor init
79
176
  ```
80
177
 
81
178
  Required values:
@@ -87,6 +184,7 @@ Required values:
87
184
  3. Run in dev mode:
88
185
 
89
186
  ```bash
187
+ export CODEHARBOR_HOME="$(pwd)"
90
188
  npm run dev
91
189
  ```
92
190
 
@@ -94,13 +192,142 @@ npm run dev
94
192
 
95
193
  ```bash
96
194
  npm run build
195
+ export CODEHARBOR_HOME="$(pwd)"
97
196
  node dist/cli.js start
98
197
  ```
99
198
 
199
+ ## Configuration Baseline
200
+
201
+ Use this layered reference to avoid mixing boot-only and runtime tuning items:
202
+
203
+ - [`docs/CONFIG_CATALOG.md`](docs/CONFIG_CATALOG.md)
204
+
205
+ It documents:
206
+
207
+ - which keys are required vs optional
208
+ - which keys can be edited in Admin UI
209
+ - whether changes are immediate or restart-scoped
210
+ - recommended profiles for local/internal/public deployment
211
+
100
212
  ## Commands
101
213
 
214
+ - `codeharbor init`: guided setup for `.env` (supports `--force` to overwrite directly)
102
215
  - `codeharbor start`: start service
103
216
  - `codeharbor doctor`: check `codex` and Matrix connectivity
217
+ - `codeharbor admin serve`: start admin UI + config API server
218
+ - `codeharbor config export`: export current config snapshot as JSON
219
+ - `codeharbor config import <file>`: import config snapshot JSON (supports `--dry-run`)
220
+ - `scripts/install-linux.sh`: Linux bootstrap installer (creates runtime dir + installs npm package)
221
+ - `scripts/install-linux-easy.sh`: one-shot Linux install + config + systemd auto-start
222
+ - `scripts/backup-config.sh`: export timestamped snapshot and keep latest N backups
223
+ - `scripts/install-backup-timer.sh`: install/update user-level systemd timer for automatic backups
224
+ - `npm run test:e2e`: run Admin UI end-to-end tests (Playwright)
225
+
226
+ ### Config Backup Script
227
+
228
+ Create a timestamped snapshot in `backups/config` and keep latest 20 by default:
229
+
230
+ ```bash
231
+ ./scripts/backup-config.sh
232
+ ```
233
+
234
+ Custom directory and retention:
235
+
236
+ ```bash
237
+ ./scripts/backup-config.sh --dir /var/backups/codeharbor --keep 30
238
+ ```
239
+
240
+ Install/update automatic backup timer:
241
+
242
+ ```bash
243
+ ./scripts/install-backup-timer.sh --schedule "*-*-* 03:30:00" --dir /var/backups/codeharbor --keep 30
244
+ ```
245
+
246
+ Full guide:
247
+
248
+ - [`docs/BACKUP_AUTOMATION.md`](docs/BACKUP_AUTOMATION.md)
249
+
250
+ ## Admin UI And API
251
+
252
+ Start server:
253
+
254
+ ```bash
255
+ codeharbor admin serve
256
+ ```
257
+
258
+ Optional overrides:
259
+
260
+ ```bash
261
+ codeharbor admin serve --host 127.0.0.1 --port 8787
262
+ ```
263
+
264
+ If you bind Admin to a non-loopback host and `ADMIN_TOKEN` is empty, startup is rejected by default.
265
+ Explicit bypass exists but is not recommended:
266
+
267
+ ```bash
268
+ codeharbor admin serve --host 0.0.0.0 --allow-insecure-no-token
269
+ ```
270
+
271
+ Open these UI routes in browser:
272
+
273
+ - `/` or `/settings/global`
274
+ - `/settings/rooms`
275
+ - `/health`
276
+ - `/audit`
277
+
278
+ Main endpoints:
279
+
280
+ - `GET /api/admin/config/global`
281
+ - `PUT /api/admin/config/global`
282
+ - `GET /api/admin/config/rooms`
283
+ - `GET /api/admin/config/rooms/:roomId`
284
+ - `PUT /api/admin/config/rooms/:roomId`
285
+ - `DELETE /api/admin/config/rooms/:roomId`
286
+ - `GET /api/admin/health`
287
+ - `GET /api/admin/audit?limit=50`
288
+
289
+ When `ADMIN_TOKEN` is set, requests must include:
290
+
291
+ ```http
292
+ Authorization: Bearer <ADMIN_TOKEN>
293
+ ```
294
+
295
+ Access control options:
296
+
297
+ - `ADMIN_TOKEN`: require bearer token for `/api/admin/*`
298
+ - `ADMIN_IP_ALLOWLIST`: optional comma-separated client IP whitelist (for example `127.0.0.1,192.168.1.10`)
299
+ - `ADMIN_ALLOWED_ORIGINS`: optional CORS origin allowlist for browser-based cross-origin admin access
300
+
301
+ Note: `PUT /api/admin/config/global` writes to `.env` and marks changes as restart-required.
302
+
303
+ ### Admin UI Quick Walkthrough
304
+
305
+ 1. Start server: `codeharbor admin serve`.
306
+ 2. Open `/settings/global`, set `Admin Token` (if enabled), then click `Save Auth`.
307
+ 3. Adjust global fields and click `Save Global Config` (UI shows restart-required warning).
308
+ 4. Open `/settings/rooms`, fill `Room ID + Workdir`, then `Save Room`.
309
+ 5. Open `/health` to run connectivity checks (`codex` + Matrix).
310
+ 6. Open `/audit` to verify config revisions (actor/summary/payload).
311
+
312
+ ## Standalone Admin Deployment
313
+
314
+ `codeharbor admin serve` can run as an independent service on target servers without browser/desktop.
315
+ Access can come from your local browser through a gateway (for example Cloudflare Tunnel).
316
+
317
+ See:
318
+
319
+ - [`docs/ADMIN_STANDALONE_DEPLOY.md`](docs/ADMIN_STANDALONE_DEPLOY.md)
320
+
321
+ ## Startup Preflight
322
+
323
+ Before `codeharbor start` and `codeharbor doctor`, CodeHarbor runs a preflight check for:
324
+
325
+ - required Matrix env vars
326
+ - `CODEX_BIN` availability
327
+ - `CODEX_WORKDIR` validity
328
+ - `.env` presence warning
329
+
330
+ If any check fails, it prints actionable fix commands (for example `codeharbor init`).
104
331
 
105
332
  ## Message Rules
106
333