mirror of
https://github.com/boshu2/agentops.git
synced 2026-09-14 15:08:13 +08:00
e431339c40
## What AgentOps 3.0 goes **fully hookless**. This removes the entire hook product surface — the product is now skills + the `ao` CLI with **zero hooks**. CI is the authoritative gate. ## Deleted - `hooks/` — 46 hook scripts + `hooks.json` + examples (whole directory) - `cli/embedded/hooks/` + embedded `hooks.json` + `embedded/lib/hook-helpers.sh` - `lib/hook-helpers.sh` - `ao hooks` CLI command: `cli/cmd/ao/hooks.go`, `hooks_run.go` + 5 hook test files; `cli/internal/bridge/hooks.go`; `cli/internal/doctor/fix_hooks.go` + test - Codex hook manifest (`hooks/codex-hooks.json`) + handler/audit scripts (`scripts/audit-codex-hooks.sh`, `install-dev-hooks.sh`, `test-hooks-output.sh`, `test-codex-hookless-lifecycle.sh`, `test-hookless-rpi-phased.sh`) - Hook lease surface: `docs/contracts/hook-lease-*`, `schemas/hook-lease.v1.schema.json`, `scripts/check-hook-lease-inventory.sh`, `check-hook-port-replacements.sh`, `generate-hook-lease-inventory.py` - Hook docs: `docs/HOOKS.md`, `cli/docs/HOOKS.md`, `docs/architecture/hook-noise-audit.md`, `docs/contracts/hook-runtime-contract.md` - `tests/hooks/` (whole dir) + hook test scripts; 5 hook eval suites + fixtures ## CI gates removed `hook-preflight`, `validate-hooks-doc-parity`, `hook-output-schema-lint` (+ scripts/bats), the hook eval suites, the `test-runtime-codex-smoke` / `test-codex-native-install` / `test-codex-plugin-install` hook-handler assertions, the cli-integration hook-lifecycle steps, the bats `tests/hooks/*` glob + orphan-hooks audit, and the `--with-hooks` install path. `embedded-sync` now validates only lib/skills. Both summary `needs:` lists + the summary echo + `docs/contracts/ci-jobs.yaml` updated; `validate-ci-policy-parity` passes (66 rows). `.codex-plugin/plugin.json` drops the "Hooks" capability. ## Load-bearing PRESERVED (reported, not forced) - **`cli/cmd/ao/codex_runtime.go`** — the codex runtime *lifecycle profile* (`HookCapable`/`HookConfigured` detection) is a runtime-capability abstraction used by 6 `validate-codex-*` CI gates, distinct from the hook product. Deleting it is a separate refactor. - **`hooks-authoring` skill** + `schemas/hooks-manifest.v1.schema.json` — reframed as an opt-in "author your own hooks" guide. Deleting the skill cascades into catalog/domain-map/dispositions/context-map golden files (skill-count sync), out of scope for the hook-product removal. - **`scripts/pre-push-gate.sh`** — retired local gate (not in CI); self-skips deleted hook scripts via `[[ -x ]]` guards; its 55 bats tests still pass. - Domain-enforcement audit keeps the `enforced`-mode schema for backward-compatible JSON readers, but the hookless resolver only returns `audited`/`unavailable`. ## Verification `go build` / `go vet` clean; `go test ./...` = **11849 passed, 0 failed** (68 pkgs). gofmt clean on all touched files. Green: registry `--check` (0 hooks), `regen-codex-hashes --check`, `validate-ci-policy-parity`, `check-wiring-closure`, `validate-embedded-sync`, `validate-manifests`, `validate-agents-split`, `doc-release` (0 broken links), `generate-cli-reference --check`, `heal.sh --strict`, codex/claude/plugin smoke tests, baseline-audit (0 stale). Diff: 231 files, +354 / −39803. Closes-scenario: soc-57b7f#remove-all-hooks Bounded-context: BC5-Runtime Evidence: .github/workflows/validate.yml
452 lines
12 KiB
Bash
Executable File
452 lines
12 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# install-codex-plugin.sh — Install the AgentOps native Codex plugin into CODEX_HOME.
|
|
#
|
|
# Usage:
|
|
# bash scripts/install-codex-plugin.sh
|
|
# bash scripts/install-codex-plugin.sh --repo-root /path/to/agentops --codex-home /tmp/codex-home
|
|
|
|
set -euo pipefail
|
|
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[0;33m'
|
|
NC='\033[0m'
|
|
|
|
info() { echo -e "${GREEN}✓${NC} $*"; }
|
|
warn() { echo -e "${YELLOW}!${NC} $*"; }
|
|
fail() { echo -e "${RED}✗${NC} $*"; exit 1; }
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
CODEX_HOME="${HOME}/.codex"
|
|
PLUGIN_NAME="agentops"
|
|
MARKETPLACE_NAME="agentops-marketplace"
|
|
PLUGIN_KEY="${PLUGIN_NAME}@${MARKETPLACE_NAME}"
|
|
VERSION="${AGENTOPS_INSTALL_VERSION:-unknown}"
|
|
UPDATE_CMD="${AGENTOPS_UPDATE_COMMAND:-curl -fsSL https://raw.githubusercontent.com/boshu2/agentops/main/scripts/install-codex.sh | bash}"
|
|
PLUGIN_SKILLS_SRC=""
|
|
|
|
PLUGIN_MANIFEST="${REPO_ROOT}/.codex-plugin/plugin.json"
|
|
MARKETPLACE_FILE="${REPO_ROOT}/plugins/marketplace.json"
|
|
PLUGIN_CACHE_ROOT="${CODEX_HOME}/plugins/cache/${MARKETPLACE_NAME}/${PLUGIN_NAME}/local"
|
|
PLUGIN_SKILLS_DST="${PLUGIN_CACHE_ROOT}/skills-codex"
|
|
LEGACY_SKILLS_DIR="${CODEX_HOME}/skills"
|
|
USER_SKILLS_DIR="$(dirname "$CODEX_HOME")/.agents/skills"
|
|
CONFIG_FILE="${CODEX_HOME}/config.toml"
|
|
INSTALL_META="${CODEX_HOME}/.agentops-codex-install.json"
|
|
SKILL_MANIFEST_NAME=".agentops-manifest.json"
|
|
PLUGIN_STATE_FILE=""
|
|
LEGACY_BACKUP_DIR=""
|
|
USER_BACKUP_DIR=""
|
|
|
|
usage() {
|
|
cat <<'EOF'
|
|
install-codex-plugin.sh
|
|
|
|
Install the AgentOps native Codex plugin into CODEX_HOME.
|
|
|
|
Options:
|
|
--repo-root <dir> AgentOps repo or extracted release bundle root
|
|
--codex-home <dir> Target Codex home (default: ~/.codex)
|
|
--skills-src <dir> Codex-native skills source root (default: <repo-root>/skills-codex)
|
|
--version <value> Version string to record in install metadata
|
|
--update-command <s> Update command to record in install metadata
|
|
--help Show this help
|
|
EOF
|
|
}
|
|
|
|
detect_bwrap_install_hint() {
|
|
if command -v apt-get >/dev/null 2>&1 || command -v apt >/dev/null 2>&1; then
|
|
printf '%s\n' 'sudo apt-get install -y bubblewrap'
|
|
return
|
|
fi
|
|
if command -v dnf >/dev/null 2>&1; then
|
|
printf '%s\n' 'sudo dnf install -y bubblewrap'
|
|
return
|
|
fi
|
|
if command -v yum >/dev/null 2>&1; then
|
|
printf '%s\n' 'sudo yum install -y bubblewrap'
|
|
return
|
|
fi
|
|
if command -v pacman >/dev/null 2>&1; then
|
|
printf '%s\n' 'sudo pacman -S --needed bubblewrap'
|
|
return
|
|
fi
|
|
if command -v zypper >/dev/null 2>&1; then
|
|
printf '%s\n' 'sudo zypper install bubblewrap'
|
|
return
|
|
fi
|
|
|
|
printf '%s\n' '<your package manager> install bubblewrap'
|
|
}
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--repo-root)
|
|
REPO_ROOT="${2:-}"
|
|
shift 2
|
|
;;
|
|
--codex-home)
|
|
CODEX_HOME="${2:-}"
|
|
shift 2
|
|
;;
|
|
--skills-src)
|
|
PLUGIN_SKILLS_SRC="${2:-}"
|
|
shift 2
|
|
;;
|
|
--version)
|
|
VERSION="${2:-}"
|
|
shift 2
|
|
;;
|
|
--update-command)
|
|
UPDATE_CMD="${2:-}"
|
|
shift 2
|
|
;;
|
|
--help|-h)
|
|
usage
|
|
exit 0
|
|
;;
|
|
*)
|
|
echo "Unknown arg: $1" >&2
|
|
usage >&2
|
|
exit 2
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [[ "$REPO_ROOT" != /* ]]; then
|
|
REPO_ROOT="$(cd "$REPO_ROOT" && pwd)"
|
|
fi
|
|
if [[ "$CODEX_HOME" != /* ]]; then
|
|
CODEX_HOME="$(cd "$CODEX_HOME" && pwd)"
|
|
fi
|
|
|
|
PLUGIN_MANIFEST="${REPO_ROOT}/.codex-plugin/plugin.json"
|
|
MARKETPLACE_FILE="${REPO_ROOT}/plugins/marketplace.json"
|
|
if [[ -z "$PLUGIN_SKILLS_SRC" ]]; then
|
|
PLUGIN_SKILLS_SRC="${REPO_ROOT}/skills-codex"
|
|
fi
|
|
if [[ "$PLUGIN_SKILLS_SRC" != /* ]]; then
|
|
PLUGIN_SKILLS_SRC="${REPO_ROOT}/${PLUGIN_SKILLS_SRC}"
|
|
fi
|
|
PLUGIN_CACHE_ROOT="${CODEX_HOME}/plugins/cache/${MARKETPLACE_NAME}/${PLUGIN_NAME}/local"
|
|
PLUGIN_SKILLS_DST="${PLUGIN_CACHE_ROOT}/skills-codex"
|
|
LEGACY_SKILLS_DIR="${CODEX_HOME}/skills"
|
|
USER_SKILLS_DIR="$(dirname "$CODEX_HOME")/.agents/skills"
|
|
CONFIG_FILE="${CODEX_HOME}/config.toml"
|
|
INSTALL_META="${CODEX_HOME}/.agentops-codex-install.json"
|
|
|
|
require_path() {
|
|
local path="$1"
|
|
local label="$2"
|
|
[[ -e "$path" ]] || fail "Missing ${label}: $path"
|
|
}
|
|
|
|
sha256_file() {
|
|
local path="$1"
|
|
|
|
if command -v shasum >/dev/null 2>&1; then
|
|
shasum -a 256 "$path" | awk '{print $1}'
|
|
return
|
|
fi
|
|
if command -v sha256sum >/dev/null 2>&1; then
|
|
sha256sum "$path" | awk '{print $1}'
|
|
return
|
|
fi
|
|
if command -v openssl >/dev/null 2>&1; then
|
|
openssl dgst -sha256 "$path" | awk '{print $NF}'
|
|
return
|
|
fi
|
|
|
|
fail "Need shasum, sha256sum, or openssl to compute install snapshots"
|
|
}
|
|
|
|
upsert_toml_key() {
|
|
local file="$1"
|
|
local section="$2"
|
|
local key="$3"
|
|
local value="$4"
|
|
local tmp
|
|
|
|
mkdir -p "$(dirname "$file")"
|
|
if [[ ! -f "$file" ]]; then
|
|
printf '%s\n%s = %s\n' "$section" "$key" "$value" > "$file"
|
|
return
|
|
fi
|
|
|
|
tmp="$(mktemp)"
|
|
awk \
|
|
-v section="$section" \
|
|
-v key="$key" \
|
|
-v value="$value" \
|
|
'
|
|
function emit_key() {
|
|
print key " = " value
|
|
}
|
|
BEGIN {
|
|
in_section = 0
|
|
saw_section = 0
|
|
wrote_key = 0
|
|
}
|
|
{
|
|
if ($0 == section) {
|
|
saw_section = 1
|
|
in_section = 1
|
|
print
|
|
next
|
|
}
|
|
|
|
if (in_section && $0 ~ /^\[/) {
|
|
if (!wrote_key) {
|
|
emit_key()
|
|
wrote_key = 1
|
|
}
|
|
in_section = 0
|
|
}
|
|
|
|
if (in_section && $0 ~ ("^[[:space:]]*" key "[[:space:]]*=")) {
|
|
if (!wrote_key) {
|
|
emit_key()
|
|
wrote_key = 1
|
|
}
|
|
next
|
|
}
|
|
|
|
print
|
|
}
|
|
END {
|
|
if (in_section && !wrote_key) {
|
|
emit_key()
|
|
wrote_key = 1
|
|
}
|
|
if (!saw_section) {
|
|
if (NR > 0) {
|
|
print ""
|
|
}
|
|
print section
|
|
emit_key()
|
|
}
|
|
}
|
|
' "$file" > "$tmp"
|
|
mv "$tmp" "$file"
|
|
}
|
|
|
|
remove_toml_key() {
|
|
local file="$1"
|
|
local section="$2"
|
|
local key="$3"
|
|
local tmp
|
|
|
|
[[ -f "$file" ]] || return 0
|
|
|
|
tmp="$(mktemp)"
|
|
awk \
|
|
-v section="$section" \
|
|
-v key="$key" \
|
|
'
|
|
BEGIN {
|
|
in_section = 0
|
|
}
|
|
{
|
|
if ($0 == section) {
|
|
in_section = 1
|
|
print
|
|
next
|
|
}
|
|
|
|
if (in_section && $0 ~ /^\[/) {
|
|
in_section = 0
|
|
}
|
|
|
|
if (in_section && $0 ~ ("^[[:space:]]*" key "[[:space:]]*=")) {
|
|
next
|
|
}
|
|
|
|
print
|
|
}
|
|
' "$file" > "$tmp"
|
|
mv "$tmp" "$file"
|
|
}
|
|
|
|
stage_plugin_source() {
|
|
local staging_root="$1"
|
|
|
|
mkdir -p "$staging_root"
|
|
cp -R "$REPO_ROOT/.codex-plugin" "$staging_root/.codex-plugin"
|
|
cp -R "$PLUGIN_SKILLS_SRC" "$staging_root/skills-codex"
|
|
|
|
if [[ -f "$REPO_ROOT/.mcp.json" ]]; then
|
|
cp "$REPO_ROOT/.mcp.json" "$staging_root/.mcp.json"
|
|
fi
|
|
if [[ -f "$REPO_ROOT/.app.json" ]]; then
|
|
cp "$REPO_ROOT/.app.json" "$staging_root/.app.json"
|
|
fi
|
|
}
|
|
|
|
archive_skill_root() {
|
|
local root="$1"
|
|
local backup_dir="$2"
|
|
local managed_root="$3"
|
|
local skill_dir
|
|
local skill_name
|
|
local root_skill
|
|
local moved=0
|
|
|
|
[[ -d "$root" ]] || return 0
|
|
|
|
while IFS= read -r -d '' skill_dir; do
|
|
skill_name="$(basename "$skill_dir")"
|
|
root_skill="$root/$skill_name"
|
|
[[ -d "$root_skill" ]] || continue
|
|
if [[ "$managed_root" != "true" && ! -f "$root_skill/.agentops-generated.json" ]]; then
|
|
continue
|
|
fi
|
|
mkdir -p "$backup_dir"
|
|
mv "$root_skill" "$backup_dir/$skill_name"
|
|
moved=$((moved + 1))
|
|
done < <(find "$PLUGIN_SKILLS_SRC" -mindepth 1 -maxdepth 1 -type d -print0 | sort -z)
|
|
|
|
if [[ -f "$root/$SKILL_MANIFEST_NAME" ]]; then
|
|
mkdir -p "$backup_dir"
|
|
mv "$root/$SKILL_MANIFEST_NAME" "$backup_dir/$SKILL_MANIFEST_NAME"
|
|
moved=$((moved + 1))
|
|
fi
|
|
if [[ -f "$root/.agentops-codex-state.json" ]]; then
|
|
mkdir -p "$backup_dir"
|
|
mv "$root/.agentops-codex-state.json" "$backup_dir/.agentops-codex-state.json"
|
|
moved=$((moved + 1))
|
|
fi
|
|
|
|
if [[ "$moved" -eq 0 ]]; then
|
|
rmdir "$backup_dir" 2>/dev/null || true
|
|
return 1
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
archive_legacy_codex_skills() {
|
|
local timestamp
|
|
local backup_dir
|
|
|
|
[[ -d "$LEGACY_SKILLS_DIR" ]] || return 0
|
|
|
|
timestamp="$(date +%Y%m%d-%H%M%S)"
|
|
backup_dir="${CODEX_HOME}/skills.backup.${timestamp}"
|
|
if archive_skill_root "$LEGACY_SKILLS_DIR" "$backup_dir" "true"; then
|
|
LEGACY_BACKUP_DIR="$backup_dir"
|
|
fi
|
|
}
|
|
|
|
archive_user_raw_skills() {
|
|
local timestamp
|
|
local backup_dir
|
|
local managed_root="false"
|
|
|
|
[[ -d "$USER_SKILLS_DIR" ]] || return 0
|
|
|
|
if [[ -f "$USER_SKILLS_DIR/$SKILL_MANIFEST_NAME" || -f "$USER_SKILLS_DIR/.agentops-codex-state.json" ]]; then
|
|
managed_root="true"
|
|
fi
|
|
|
|
timestamp="$(date +%Y%m%d-%H%M%S)"
|
|
backup_dir="$(dirname "$USER_SKILLS_DIR")/skills.backup.${timestamp}"
|
|
if archive_skill_root "$USER_SKILLS_DIR" "$backup_dir" "$managed_root"; then
|
|
USER_BACKUP_DIR="$backup_dir"
|
|
fi
|
|
}
|
|
|
|
require_path "$PLUGIN_MANIFEST" "Codex plugin manifest"
|
|
require_path "$MARKETPLACE_FILE" "Codex marketplace manifest"
|
|
require_path "$PLUGIN_SKILLS_SRC" "Codex-native skill bundle"
|
|
require_path "$PLUGIN_SKILLS_SRC/$SKILL_MANIFEST_NAME" "Codex skill manifest"
|
|
PLUGIN_STATE_FILE="${PLUGIN_CACHE_ROOT}/.agentops-codex-state.json"
|
|
|
|
TMP_DIR="$(mktemp -d)"
|
|
cleanup() {
|
|
rm -rf "$TMP_DIR"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
info "Installing AgentOps Codex native plugin..."
|
|
|
|
mkdir -p "$(dirname "$PLUGIN_CACHE_ROOT")"
|
|
rm -rf "$PLUGIN_CACHE_ROOT"
|
|
stage_plugin_source "$TMP_DIR/plugin"
|
|
cp -R "$TMP_DIR/plugin" "$PLUGIN_CACHE_ROOT"
|
|
|
|
upsert_toml_key "$CONFIG_FILE" "[features]" "plugins" "true"
|
|
upsert_toml_key "$CONFIG_FILE" "[plugins.\"${PLUGIN_KEY}\"]" "enabled" "true"
|
|
upsert_toml_key "$CONFIG_FILE" "[ui]" "suppress_unstable_features_warning" "true"
|
|
remove_toml_key "$CONFIG_FILE" "[features]" "codex_hooks"
|
|
|
|
INSTALLED_AT="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
MANIFEST_HASH="$(sha256_file "$PLUGIN_SKILLS_SRC/$SKILL_MANIFEST_NAME")"
|
|
require_path "$PLUGIN_SKILLS_DST/$SKILL_MANIFEST_NAME" "installed Codex skill manifest"
|
|
INSTALLED_MANIFEST_HASH="$(sha256_file "$PLUGIN_SKILLS_DST/$SKILL_MANIFEST_NAME")"
|
|
[[ "$MANIFEST_HASH" == "$INSTALLED_MANIFEST_HASH" ]] || fail "Installed plugin cache manifest hash mismatch; expected $MANIFEST_HASH, got $INSTALLED_MANIFEST_HASH"
|
|
SKILL_COUNT="$(find "$PLUGIN_SKILLS_DST" -mindepth 2 -maxdepth 2 -name SKILL.md 2>/dev/null | wc -l | tr -d ' ')"
|
|
HOOK_RUNTIME="hookless-default"
|
|
HOOKS_INSTALLED=false
|
|
|
|
archive_legacy_codex_skills
|
|
archive_user_raw_skills
|
|
|
|
cat > "$PLUGIN_STATE_FILE" <<EOF
|
|
{
|
|
"installed_at": "$INSTALLED_AT",
|
|
"install_mode": "native-plugin",
|
|
"hook_runtime": "$HOOK_RUNTIME",
|
|
"hooks_installed": $HOOKS_INSTALLED,
|
|
"version": "$VERSION",
|
|
"manifest_hash": "$MANIFEST_HASH",
|
|
"skill_count": $SKILL_COUNT,
|
|
"plugin_root": "$PLUGIN_CACHE_ROOT"
|
|
}
|
|
EOF
|
|
mkdir -p "$(dirname "$INSTALL_META")"
|
|
cat > "$INSTALL_META" <<EOF
|
|
{
|
|
"installed_at": "$INSTALLED_AT",
|
|
"source": "install-codex-plugin.sh",
|
|
"install_mode": "native-plugin",
|
|
"hook_runtime": "$HOOK_RUNTIME",
|
|
"hooks_installed": $HOOKS_INSTALLED,
|
|
"lifecycle_commands": ["ao rpi phased", "ao codex status"],
|
|
"plugin_key": "$PLUGIN_KEY",
|
|
"version": "$VERSION",
|
|
"plugin_root": "$PLUGIN_CACHE_ROOT",
|
|
"manifest_hash": "$MANIFEST_HASH",
|
|
"skill_count": $SKILL_COUNT,
|
|
"plugin_state_file": "$PLUGIN_STATE_FILE",
|
|
"user_skills_root": null,
|
|
"update_command": "$UPDATE_CMD"
|
|
}
|
|
EOF
|
|
|
|
# ── Hookless default ──
|
|
# AgentOps 3.0 ships zero hooks: the Codex lifecycle is driven by skills + the
|
|
# `ao` CLI. Ensure any stale Codex hooks feature flag is disabled.
|
|
remove_toml_key "$CONFIG_FILE" "[features]" "hooks"
|
|
info "Codex hooks not installed (hookless — skills + ao CLI only)"
|
|
|
|
info "Native Codex plugin installed"
|
|
echo " Plugin key: $PLUGIN_KEY"
|
|
echo " Plugin root: $PLUGIN_CACHE_ROOT"
|
|
echo " Skills available: $SKILL_COUNT"
|
|
echo " Config updated: $CONFIG_FILE"
|
|
if [[ "$(uname -s)" == "Linux" ]] && [[ ! -x /usr/bin/bwrap ]]; then
|
|
warn "Codex could not find system bubblewrap at /usr/bin/bwrap."
|
|
echo " Install it to avoid the vendored-bubblewrap startup warning:"
|
|
echo " $(detect_bwrap_install_hint)"
|
|
fi
|
|
if [[ -n "$LEGACY_BACKUP_DIR" ]]; then
|
|
echo " Archived overlapping ~/.codex/skills entries to: $LEGACY_BACKUP_DIR"
|
|
fi
|
|
if [[ -n "$USER_BACKUP_DIR" ]]; then
|
|
echo " Archived overlapping ~/.agents/skills entries to: $USER_BACKUP_DIR"
|
|
fi
|
|
info "Install metadata written: $INSTALL_META"
|
|
echo ""
|
|
echo "Restart Codex to pick up the native plugin."
|