From 7bed2de2d278b80c6f2c16adba7fc923c2b05103 Mon Sep 17 00:00:00 2001 From: librelad Date: Mon, 25 May 2026 22:13:54 +0100 Subject: [PATCH] feat(tools): auto-discover per-app .tools.json (drop-in tool registration) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit webui_tools.sh now merges any containers//.tools.json into apps-tools.json (jq, sets .apps[]) on top of the central heredoc. So a dropped-in app — e.g. from LibrePortal-Infra — registers its own Tools-tab actions WITHOUT editing this file. Combined with the container scan already sourcing containers//*.sh live, an app can now be fully self-contained (install fn + tool fns in .sh + tool declarations in .tools.json) → true copy-on-top deploy, no array regen, no central edits. Core apps in the heredoc are unaffected; invalid tools files are skipped with a notice. Verified the merge (drop-in registers, core preserved). Co-Authored-By: Claude Opus 4.7 Signed-off-by: librelad --- .../webui/data/generators/apps/webui_tools.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scripts/webui/data/generators/apps/webui_tools.sh b/scripts/webui/data/generators/apps/webui_tools.sh index 5507a14..1769d71 100644 --- a/scripts/webui/data/generators/apps/webui_tools.sh +++ b/scripts/webui/data/generators/apps/webui_tools.sh @@ -414,6 +414,23 @@ webuiGenerateAppsToolsConfig() { } JSON + # Merge per-app tool declarations so a DROPPED-IN app (e.g. from LibrePortal-Infra) + # registers its own Tools tab actions without editing this file. Each app may ship + # containers//.tools.json = { "tools": [ … ] } (same schema as above); + # it sets .apps[]. Core apps declared in the heredoc need no such file. + if command -v jq >/dev/null 2>&1; then + local _tj _app + for _tj in "${install_containers_dir}"*/*.tools.json; do + [[ -f "$_tj" ]] || continue + _app="$(basename "$(dirname "$_tj")")" + if jq -e . "$_tj" >/dev/null 2>&1; then + jq --arg app "$_app" --slurpfile t "$_tj" '.apps[$app] = $t[0]' "$tmp" > "$tmp.m" && mv "$tmp.m" "$tmp" + else + isNotice "Skipping invalid tools file: $_tj" + fi + done + fi + if command -v jq >/dev/null 2>&1; then if ! jq . "$tmp" >/dev/null 2>&1; then isNotice "Generated apps-tools.json failed JSON validation; keeping existing file."