interplane.Get Omega
Read in your language

omega-mcp

aien-dev/omega-mcp

Brought by drakestapleton

branch main Branches Tags History

omega-mcp / tools / register-locked.sh

101 lines · 3829 bytes Raw Blame History
1#!/bin/sh
2# Register agent-maintenance-mcp and agent-qa-mcp in the locked agent files.
3#
4# tools/register-locked.sh --keep /srv/aien-keep --prefix /absolute/release
5#
6# --keep is the aien-keep root. --prefix is the directory that holds the two binaries
7# (a release from tools/install.sh, PREFIX/current). The question store and the consent
8# file are created outside the keep, under $HOME, unless --store and --consent say
9# otherwise. The consent file is created empty: sharing stays off until the person
10# adds a line `allow AGENT`.
11#
12# A locked file is never opened for writing here. The new bytes are staged outside the
13# keep and installed only with `aien-keep update DEST SRC` (sudo -n, unless SUDO is set).
14# That is the keeper's update path; it keeps the previous copy. Drake, 2026-11-15: register
15# both servers this way.
16#
17# Files: KEEP/home/.omp/agent/mcp.json (always), and KEEP/home/.claude.json and
18# KEEP/home/.claude/settings.json when they already exist. A file that is not a JSON
19# object is left untouched and this command exits 2.
20set -eu
21src=$(cd "$(dirname "$0")/.." && pwd -P)
22keep= prefix= store= consent=
23while [ $# -gt 0 ]; do
24 case $1 in
25 --keep) keep=${2:?}; shift ;;
26 --prefix) prefix=${2:?}; shift ;;
27 --store) store=${2:?}; shift ;;
28 --consent) consent=${2:?}; shift ;;
29 *) echo "usage: tools/register-locked.sh --keep KEEP --prefix PREFIX [--store DIR] [--consent FILE]" >&2; exit 2 ;;
30 esac
31 shift
32done
33[ -n "$keep" ] && [ -n "$prefix" ] || { echo "register-locked: --keep and --prefix are required" >&2; exit 2; }
34keep=$(readlink -f "$keep")
35prefix=$(readlink -f "$prefix")
36[ -d "$keep" ] || { echo "register-locked: keep $keep is not a directory" >&2; exit 2; }
37[ -x "$prefix/agent-maintenance-mcp" ] && [ -x "$prefix/agent-qa-mcp" ] || {
38 echo "register-locked: $prefix is missing agent-maintenance-mcp or agent-qa-mcp" >&2; exit 2; }
39home=${HOME:?}
40if [ -z "$store" ]; then store=$home/.local/state/omega-mcp/agent-qa; fi
41if [ -z "$consent" ]; then consent=$home/.config/omega-mcp/qa-consent; fi
42mkdir -p "$(dirname "$store")" "$(dirname "$consent")"
43store=$(readlink -f "$store")
44consent=$(readlink -f "$consent")
45under() {
46 d=$(readlink -f "$1")
47 [ "$d" = "$keep" ] || [ "${d#"$keep"/}" != "$d" ]
48}
49if under "$store" || under "$(dirname "$consent")"; then
50 echo "register-locked: the store and the consent file must sit outside $keep" >&2
51 exit 2
52fi
53mkdir -p "$store"
54if [ ! -e "$consent" ]; then : > "$consent"; fi
55root=$keep/home/.omp/agent
56
57run_keep() {
58 k=${AIEN_KEEP:-aien-keep}
59 if [ -n "${SUDO+x}" ]; then
60 if [ -n "$SUDO" ]; then
61 # SUDO is a command and its flags, such as "sudo -n"
62 $SUDO "$k" "$@"
63 else
64 "$k" "$@"
65 fi
66 else
67 sudo -n "$k" "$@"
68 fi
69}
70
71apply_update() { run_keep update "$1" "$2"; }
72
73merge_one() { # dest agent-name
74 dest=$1 agent=$2
75 stage=$(mktemp)
76 if [ -f "$dest" ]; then
77 status=$(python3 "$src/tools/register_merge.py" --current "$dest" --out "$stage" \
78 --root "$root" --prefix "$prefix" --store "$store" --consent "$consent" --agent "$agent")
79 else
80 status=$(python3 "$src/tools/register_merge.py" --out "$stage" \
81 --root "$root" --prefix "$prefix" --store "$store" --consent "$consent" --agent "$agent")
82 fi
83 if [ "$status" = unchanged ]; then
84 rm -f "$stage"
85 echo "register-locked: unchanged $dest"
86 return 0
87 fi
88 if [ "$status" != changed ]; then
89 echo "register-locked: merge of $dest failed" >&2
90 rm -f "$stage"
91 exit 2
92 fi
93 apply_update "$dest" "$stage"
94 rm -f "$stage"
95 echo "register-locked: updated $dest"
96}
97
98merge_one "$root/mcp.json" omp
99if [ -f "$keep/home/.claude.json" ]; then merge_one "$keep/home/.claude.json" claude; fi
100if [ -f "$keep/home/.claude/settings.json" ]; then merge_one "$keep/home/.claude/settings.json" claude; fi
101exit 0