ework-aio 0.1.1 → 0.1.3

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 (3) hide show
  1. package/README.md +46 -8
  2. package/bin/install.sh +40 -15
  3. package/package.json +3 -2
package/README.md CHANGED
@@ -13,18 +13,56 @@ All-in-one installer for the **ework** self-hosted AI development stack:
13
13
  ## Quick start
14
14
 
15
15
  ```bash
16
- # 1. Make sure prerequisites are on PATH
17
- bun --version # >= 1.1.0 — https://bun.sh
18
- opencode --version # >= 1.14 — https://opencode.ai
19
- npm --version # ships with bun or node
20
- systemctl --version # this installer requires systemd
16
+ npm install -g ework-aio && ework-aio install
17
+ ```
18
+
19
+ That's the whole install. When it finishes it prints your login URL, operator login, and token.
20
+
21
+ ### Prerequisites
22
+
23
+ The install command checks for these and aborts with a hint if any are missing:
21
24
 
22
- # 2. One-shot install
25
+ | Tool | Min ver | Install from |
26
+ | ----------- | ------- | ------------------------------------ |
27
+ | `bun` | 1.1.0 | https://bun.sh |
28
+ | `opencode` | 1.14 | https://opencode.ai |
29
+ | `npm` | any | ships with bun or node |
30
+ | `systemctl` | any | systemd-based Linux |
31
+ | `openssl`/`curl`/`jq`/`awk` | any | your distro package manager |
32
+
33
+ ### One-liner alternatives
34
+
35
+ ```bash
36
+ # Run without installing globally (downloads + runs once)
23
37
  npx ework-aio install
24
- # or: npm install -g ework-aio && ework-aio install
38
+
39
+ # If npm registry is slow on your machine, route through an HTTP proxy
40
+ HTTPS_PROXY=http://127.0.0.1:7890 npm install -g ework-aio && ework-aio install
41
+
42
+ # User-level install (no sudo) — uses ~/.local as npm prefix
43
+ npm install -g ework-aio --prefix ~/.local && ework-aio install
25
44
  ```
26
45
 
27
- The installer prints your login URL and token when it finishes.
46
+ ### Why two steps?
47
+
48
+ `npm install -g ework-aio` **only** lays down files: the bin launcher and the bash installer. It does **not** run the installer. The second `ework-aio install` step is what actually:
49
+
50
+ - writes `.env` files with random tokens,
51
+ - creates systemd units (user-level by default, system-level if you sudo),
52
+ - starts services,
53
+ - bootstraps the bot user,
54
+ - edits `~/.config/opencode/opencode.json`.
55
+
56
+ Keeping these in a separate, explicitly-invoked step is intentional:
57
+
58
+ - **Privilege boundary.** `sudo npm install -g` runs as root; the install step runs as *you*. Folding them together would force system-level systemd units and root-owned files in `$HOME`.
59
+ - **No surprise side-effects.** `npm install -g foo` should lay down files and stop. Creating services, generating tokens, editing your opencode config — that's invasive and belongs in a step you opted into.
60
+ - **npm `--ignore-scripts`.** Many users / CI disable lifecycle scripts. Auto-installing via `postinstall` would silently no-op for them.
61
+ - **`npm uninstall` reversibility.** Files outside npm's tracking (systemd units, `.env`, DBs, bot PAT) can't be cleaned by npm. Keeping them in a separate command means `npm uninstall -g ework-aio` does what people expect (removes files) and `ework-aio uninstall` does the rest.
62
+
63
+ `bin/ework-aio` with no args defaults to `install`, so `npm install -g ework-aio && ework-aio` (no `install`) also works.
64
+
65
+ ---
28
66
 
29
67
  ## What it does
30
68
 
package/bin/install.sh CHANGED
@@ -409,7 +409,32 @@ else
409
409
  fi
410
410
 
411
411
  # ─── Register opencode-ework plugin ────────────────────────────────────────
412
+ # Safety: every edit writes to a temp file, validates with `jq -e .`, only
413
+ # then atomically replaces the original. A timestamped .bak is always kept.
412
414
  mkdir -p "$(dirname "$OPENCODE_CFG")"
415
+
416
+ json_edit() {
417
+ # $1 = file, $2 = jq program, $3 = expected JSON type (optional, e.g. "object").
418
+ # Writes to temp, validates (parses + optional type check), only then swaps.
419
+ # Backup at $file.bak.<epoch>.
420
+ local file="$1" prog="$2" expected="${3:-}" tmp
421
+ tmp=$(mktemp)
422
+ if ! jq "$prog" "$file" > "$tmp" 2>/dev/null; then
423
+ rm -f "$tmp"
424
+ die "jq edit failed on $file (program: $prog)"
425
+ fi
426
+ if ! jq -e . "$tmp" >/dev/null 2>&1; then
427
+ rm -f "$tmp"
428
+ die "jq edit produced invalid JSON on $file — aborted, original untouched"
429
+ fi
430
+ if [[ -n "$expected" ]] && ! jq -e "type == \"$expected\"" "$tmp" >/dev/null 2>&1; then
431
+ rm -f "$tmp"
432
+ die "jq edit produced wrong type on $file (expected $expected) — aborted, original untouched"
433
+ fi
434
+ cp "$file" "$file.bak.$(date +%s)"
435
+ mv "$tmp" "$file"
436
+ }
437
+
413
438
  if [[ ! -f "$OPENCODE_CFG" ]]; then
414
439
  log "Writing $OPENCODE_CFG (registering opencode-ework plugin)"
415
440
  cat > "$OPENCODE_CFG" <<'EOF'
@@ -418,26 +443,26 @@ if [[ ! -f "$OPENCODE_CFG" ]]; then
418
443
  "plugin": ["opencode-ework@latest"]
419
444
  }
420
445
  EOF
421
- elif grep -qE '"opencode-ework(@latest)?"' "$OPENCODE_CFG"; then
422
- if grep -q '"opencode-ework@latest"' "$OPENCODE_CFG"; then
423
- ok "opencode-ework@latest already in $OPENCODE_CFG"
424
- else
425
- log "Upgrading opencode-ework → opencode-ework@latest in $OPENCODE_CFG"
426
- cp "$OPENCODE_CFG" "$OPENCODE_CFG.bak.$(date +%s)"
427
- tmp=$(mktemp)
428
- jq '(.plugin // []) | map(if . == "opencode-ework" then "opencode-ework@latest" else . end)' \
429
- "$OPENCODE_CFG" > "$tmp" && mv "$tmp" "$OPENCODE_CFG"
430
- ok "Plugin upgraded (backup at $OPENCODE_CFG.bak.*)"
431
- fi
446
+ elif grep -q '"opencode-ework@latest"' "$OPENCODE_CFG"; then
447
+ ok "opencode-ework@latest already in $OPENCODE_CFG"
448
+ elif grep -q '"opencode-ework"' "$OPENCODE_CFG"; then
449
+ log "Upgrading opencode-ework → opencode-ework@latest in $OPENCODE_CFG"
450
+ json_edit "$OPENCODE_CFG" \
451
+ '.plugin = ((.plugin // []) | map(if . == "opencode-ework" then "opencode-ework@latest" else . end))' \
452
+ object
453
+ ok "Plugin upgraded (backup at $OPENCODE_CFG.bak.*)"
432
454
  else
433
455
  log "Merging opencode-ework@latest into existing $OPENCODE_CFG"
434
- cp "$OPENCODE_CFG" "$OPENCODE_CFG.bak.$(date +%s)"
435
- tmp=$(mktemp)
436
- jq 'if .plugin then .plugin += ["opencode-ework@latest"] else . + {plugin:["opencode-ework@latest"]} end' \
437
- "$OPENCODE_CFG" > "$tmp" && mv "$tmp" "$OPENCODE_CFG"
456
+ json_edit "$OPENCODE_CFG" \
457
+ 'if .plugin then .plugin += ["opencode-ework@latest"] else . + {plugin:["opencode-ework@latest"]} end' \
458
+ object
438
459
  ok "Plugin registered (backup at $OPENCODE_CFG.bak.*)"
439
460
  fi
440
461
 
462
+ if ! jq -e 'type == "object"' "$OPENCODE_CFG" >/dev/null 2>&1; then
463
+ warn "$OPENCODE_CFG is not a JSON object — check $OPENCODE_CFG.bak.* for restore"
464
+ fi
465
+
441
466
  # ─── Done ──────────────────────────────────────────────────────────────────
442
467
  hr
443
468
  ok "Install complete."
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ework-aio",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "All-in-one installer for ework (issue tracker) + ework-daemon (AI bridge) + opencode-ework (plugin). One command: npm i -g ework-aio && ework-aio install.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -38,7 +38,8 @@
38
38
  },
39
39
  "scripts": {
40
40
  "start": "bun bin/ework-aio.js",
41
- "check": "tsc --noEmit"
41
+ "check": "tsc --noEmit",
42
+ "postinstall": "echo '\\n ework-aio installed. Run \\033[1mework-aio install\\033[0m to set up services.\\n Help: ework-aio --help\\n'"
42
43
  },
43
44
  "dependencies": {
44
45
  "ework-web": "^0.1.0",