ework-aio 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 (2) hide show
  1. package/bin/install.sh +67 -20
  2. package/package.json +1 -1
package/bin/install.sh CHANGED
@@ -94,14 +94,13 @@ ensure_pkg() {
94
94
  }
95
95
  case "$MODE" in
96
96
  install)
97
- log "Ensuring npm packages are installed..."
98
- ensure_pkg "ework-web"
99
- ensure_pkg "ework-daemon"
100
- # opencode-ework is a library, not a bin; check node_modules
101
- if ! [[ -d "$(npm root -g)/opencode-ework" ]] \
102
- && ! [[ -d "$(npm root -g)/ework-aio/node_modules/opencode-ework" ]]; then
103
- npm install -g opencode-ework || die "npm install -g opencode-ework failed"
104
- fi
97
+ log "Installing/updating npm packages globally..."
98
+ # Install each as a top-level global so bins are linked to PATH.
99
+ # (npm v9 doesn't hoist nested deps' bins from `npm i -g ework-aio`.)
100
+ # Always run `npm install -g` (not gated on presence) so re-runs pick up new versions.
101
+ for pkg in ework-web ework-daemon opencode-ework ework-aio; do
102
+ npm install -g "$pkg@latest" || die "npm install -g $pkg@latest failed"
103
+ done
105
104
  ok "npm packages ready"
106
105
 
107
106
  # Absolute paths to the bin shims (resolved once, baked into systemd units)
@@ -410,35 +409,83 @@ else
410
409
  fi
411
410
 
412
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.
413
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
+
414
438
  if [[ ! -f "$OPENCODE_CFG" ]]; then
415
439
  log "Writing $OPENCODE_CFG (registering opencode-ework plugin)"
416
440
  cat > "$OPENCODE_CFG" <<'EOF'
417
441
  {
418
442
  "$schema": "https://opencode.ai/config.json",
419
- "plugin": ["opencode-ework"]
443
+ "plugin": ["opencode-ework@latest"]
420
444
  }
421
445
  EOF
446
+ elif grep -q '"opencode-ework@latest"' "$OPENCODE_CFG"; then
447
+ ok "opencode-ework@latest already in $OPENCODE_CFG"
422
448
  elif grep -q '"opencode-ework"' "$OPENCODE_CFG"; then
423
- ok "opencode-ework already in $OPENCODE_CFG"
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.*)"
424
454
  else
425
- log "Merging opencode-ework into existing $OPENCODE_CFG"
426
- cp "$OPENCODE_CFG" "$OPENCODE_CFG.bak.$(date +%s)"
427
- # Use jq to append to plugin array (creates array if missing)
428
- tmp=$(mktemp)
429
- jq 'if .plugin then .plugin += ["opencode-ework"] else . + {plugin:["opencode-ework"]} end' \
430
- "$OPENCODE_CFG" > "$tmp" && mv "$tmp" "$OPENCODE_CFG"
455
+ log "Merging opencode-ework@latest into existing $OPENCODE_CFG"
456
+ json_edit "$OPENCODE_CFG" \
457
+ 'if .plugin then .plugin += ["opencode-ework@latest"] else . + {plugin:["opencode-ework@latest"]} end' \
458
+ object
431
459
  ok "Plugin registered (backup at $OPENCODE_CFG.bak.*)"
432
460
  fi
433
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
+
434
466
  # ─── Done ──────────────────────────────────────────────────────────────────
435
467
  hr
436
468
  ok "Install complete."
437
469
  hr
438
470
  printf '\n%s→%s Open %shttp://127.0.0.1:%s/login%s\n' \
439
471
  "$c_bold" "$c_reset" "$c_dim" "$WORK_PORT" "$c_reset"
440
- printf ' Login token: %s%s%s\n' "$c_bold" "$WORK_TOKEN_VAL" "$c_reset"
441
- printf ' Logs: ework-aio logs web | ework-aio logs daemon\n'
442
- printf ' Status: ework-aio status\n'
443
- printf ' Uninstall: ework-aio uninstall\n'
472
+ printf ' Operator login: %s%s%s (auto-promoted admin; derived from $USER at install time)\n' \
473
+ "$c_bold" "$USER" "$c_reset"
474
+ printf ' Login token: %s%s%s\n' "$c_bold" "$WORK_TOKEN_VAL" "$c_reset"
475
+ printf ' Bot user: %s%s%s (auto-created, used by ework-daemon)\n' \
476
+ "$c_bold" "$BOT_NAME" "$c_reset"
477
+ printf ' Data dir: %s%s%s\n' "$c_dim" "$DATA_DIR" "$c_reset"
478
+ printf ' Logs: ework-aio logs web | ework-aio logs daemon\n'
479
+ printf ' Status: ework-aio status\n'
480
+ printf ' Uninstall: ework-aio uninstall\n'
481
+ hr
482
+ printf '\n%sNext steps (optional config)%s\n' "$c_bold" "$c_reset"
483
+ printf ' • 朗读 (TTS): %shttp://127.0.0.1:%s/admin/tts%s — needs an OpenAI-compat /audio/speech endpoint\n' \
484
+ "$c_dim" "$WORK_PORT" "$c_reset"
485
+ printf ' • 翻译: edit %s%s/.env%s, set WORK_TRANSLATE_URL + WORK_TRANSLATE_MODEL\n' \
486
+ "$c_dim" "$WEB_DATA_DIR" "$c_reset"
487
+ printf ' (OpenAI-compat /v1/chat/completions endpoint), then: ework-aio install\n'
488
+ printf ' • Per-project webhook: open %s/<owner>/<repo>/webhooks%s to wire downstream\n' \
489
+ "$c_dim" "$c_reset"
490
+ printf ' consumers (GitHub Actions, etc.). Gitea-compat payload + HMAC-SHA256 sig.\n'
444
491
  hr
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ework-aio",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
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",