From 80fa4c8edae0864b320706d8cae0c0a488b8a60e Mon Sep 17 00:00:00 2001 From: Matteo Cherubini Date: Sun, 21 Jun 2026 00:04:34 +0200 Subject: [PATCH 1/5] chore: Improve script documentation and initial comments --- deploy/nexus/genome-raw-commit.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/deploy/nexus/genome-raw-commit.sh b/deploy/nexus/genome-raw-commit.sh index 3989346..f1f66b8 100644 --- a/deploy/nexus/genome-raw-commit.sh +++ b/deploy/nexus/genome-raw-commit.sh @@ -1,12 +1,11 @@ #!/bin/bash # genome-raw-commit # -# Commits raw files synchronized by Syncthing into the vault and pushes them to origin/. -# - Committer = n8n-bot (robotic identity responsible for pushing) -# - Author = deduced from the Syncthing device ID (modifiedBy field), resolved via .authors.json. -# Falls back to default values if unknown. -# - One commit per author/device to ensure clear attribution. -# - No-op if no changes are present. Excludes infrastructure files and private folders. +# Commit the raw files that Syncthing has placed in the vault and push them to origin/. +# - Committer = n8n-bot (sole pusher); Author = the person who wrote it (Syncthing modifiedBy -> .authors.json) +# - One commit per author (single-device => one commit). No-op if there is nothing. +# - JSON output built with jq (safe escaping), with a `files` array: +# for each raw -> file, author, local_path, local_url (file://), remote_url (Forgejo web). set -euo pipefail genome="${1:?usage: genome-raw-commit }" From fb96578987f2f1332c45b5987247ffe0cd06c8e7 Mon Sep 17 00:00:00 2001 From: Matteo Cherubini Date: Sun, 21 Jun 2026 00:04:34 +0200 Subject: [PATCH 2/5] refactor: Exclude Syncthing special files and streamline author logic --- deploy/nexus/genome-raw-commit.sh | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/deploy/nexus/genome-raw-commit.sh b/deploy/nexus/genome-raw-commit.sh index f1f66b8..0042f5c 100644 --- a/deploy/nexus/genome-raw-commit.sh +++ b/deploy/nexus/genome-raw-commit.sh @@ -37,43 +37,42 @@ git config user.name "$COMMITTER_NAME" git config user.email "$COMMITTER_EMAIL" git config commit.gpgsign false -# Scope restricted to raw/ directory. raw/.stignore is omitted via .git/info/exclude -git add -A -- raw/ -git reset -q -- raw/.stignore 2>/dev/null || true +grep -qxF 'raw/.stignore' "${vault}/.git/info/exclude" 2>/dev/null || echo 'raw/.stignore' >> "${vault}/.git/info/exclude" +grep -qxF 'raw/.stfolder' "${vault}/.git/info/exclude" 2>/dev/null || echo 'raw/.stfolder' >> "${vault}/.git/info/exclude" +git add -A -- raw/ +git reset -q -- raw/.stignore raw/.stfolder 2>/dev/null || true if git diff --cached --quiet; then printf '{"status":"noop","genome":"%s"}\n' "$genome" exit 0 fi -# Map Syncthing device ID to author information (name, email) -resolve_dev() { - # $1 = file path relative to the vault root (e.g., raw/file.txt) +resolve_dev() { # $1 = path relativo al vault (raw/...) -> stampa lo short device id o vuoto [[ -z "${SYNCTHING_API_KEY:-}" ]] && return 0 curl -fsS -H "X-API-Key: ${SYNCTHING_API_KEY}" --get "${SYNCTHING_URL}/rest/db/file" \ --data-urlencode "folder=${fid}" --data-urlencode "file=${1#raw/}" 2>/dev/null \ | jq -r '.local.modifiedBy // empty' 2>/dev/null || true } - -author_for_dev() { - # $1 = device ID +author_for_dev() { # $1 = device id -> stampa "name\temail" local dev="$1" name="$DEFAULT_AUTHOR_NAME" email="$DEFAULT_AUTHOR_EMAIL" if [[ -n "$dev" && -f "$authors_map" ]] && jq -e --arg d "$dev" '.[$d]' "$authors_map" >/dev/null 2>&1; then name="$(jq -r --arg d "$dev" '.[$d].name' "$authors_map")" email="$(jq -r --arg d "$dev" '.[$d].email' "$authors_map")" fi - printf '%s\t%s\t%s' "$name" "$email" "${dev:-unknown}" + printf '%s\t%s' "$name" "$email" } -# Group staged files by author identity -declare -A G_FILES G_NAME G_EMAIL G_DEV +# raccolgo per-file (relpath, author) e raggruppo per autore per il commit +declare -A G_FILES G_NAME G_EMAIL +declare -a ROWS while IFS= read -r f; do [[ -z "$f" ]] && continue dev="$(resolve_dev "$f")" - IFS=$'\t' read -r aname aemail adev <<< "$(author_for_dev "$dev")" + IFS=$'\t' read -r aname aemail <<< "$(author_for_dev "$dev")" + ROWS+=("${f}"$'\t'"${aname}") key="${aname} <${aemail}>" G_FILES["$key"]+="${f}"$'\n' - G_NAME["$key"]="$aname"; G_EMAIL["$key"]="$aemail"; G_DEV["$key"]="$adev" + G_NAME["$key"]="$aname"; G_EMAIL["$key"]="$aemail" done < <(git diff --cached --name-only -- raw/) ts="$(date +%Y-%m-%dT%H:%M:%S%z)" From e1a00d2db708560aad945c8f78b8c55cc7e52058 Mon Sep 17 00:00:00 2001 From: Matteo Cherubini Date: Sun, 21 Jun 2026 00:04:34 +0200 Subject: [PATCH 3/5] feat: Add configurable Forgejo web base URL --- deploy/nexus/genome-raw-commit.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/deploy/nexus/genome-raw-commit.sh b/deploy/nexus/genome-raw-commit.sh index 0042f5c..800322f 100644 --- a/deploy/nexus/genome-raw-commit.sh +++ b/deploy/nexus/genome-raw-commit.sh @@ -19,6 +19,7 @@ set -a; . "${HOME}/.config/knowledge-genome.env"; set +a : "${FORGEJO_USER:=n8n-bot}" : "${FORGEJO_HOST:=127.0.0.1:3001}" : "${FORGEJO_OWNER:=Keru}" +: "${FORGEJO_WEB_BASE:=https://git.keruhomelab.com} : "${SYNCTHING_URL:=http://127.0.0.1:8384}" : "${COMMITTER_NAME:=n8n-bot}" : "${COMMITTER_EMAIL:=n8n-bot@homelab}" From 726a1e2ed405cfcd0c765ba0d6be98e56175c807 Mon Sep 17 00:00:00 2001 From: Matteo Cherubini Date: Sun, 21 Jun 2026 00:04:34 +0200 Subject: [PATCH 4/5] feat: Enhance output with detailed JSON including file URLs --- deploy/nexus/genome-raw-commit.sh | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/deploy/nexus/genome-raw-commit.sh b/deploy/nexus/genome-raw-commit.sh index 800322f..554d7bf 100644 --- a/deploy/nexus/genome-raw-commit.sh +++ b/deploy/nexus/genome-raw-commit.sh @@ -81,20 +81,34 @@ commits=0; summary="" for key in "${!G_FILES[@]}"; do mapfile -t files < <(printf '%s' "${G_FILES[$key]}") short="$(printf '%s\n' "${files[@]}" | sed 's#^raw/##' | paste -sd, -)" - msg="$(printf 'raw(%s): sync %s\n\nAdded-by-device: %s\nSyncthing-device-id: %s\nSource: syncthing-autocommit\nSynced-at: %s\n' \ - "$genome" "$short" "${G_DEV[$key]}" "${G_DEV[$key]}" "$ts")" + msg="$(printf 'raw(%s): sync %s\n\nAdded-by: %s\nSource: syncthing-autocommit\nSynced-at: %s\n' \ + "$genome" "$short" "${G_NAME[$key]}" "$ts")" git commit -q --author="$key" -m "$msg" -- "${files[@]}" commits=$((commits+1)) summary="${summary}${summary:+; }${G_NAME[$key]}:${short}" done -# Fetch updates from origin to merge upstream modifications before pushing +# incorporo eventuali avanzamenti del remoto (es. PR wiki mergiata), poi pusho git fetch -q origin if git show-ref --verify --quiet "refs/remotes/origin/${GENOME_BASE}"; then git rebase -q "origin/${GENOME_BASE}" \ || { git rebase --abort 2>/dev/null || true; printf '{"status":"error","reason":"rebase-conflict","genome":"%s"}\n' "$genome"; exit 1; } fi git push -q "$clone_url" "HEAD:${GENOME_BASE}" +head="$(git rev-parse --short HEAD)" -printf '{"status":"ok","genome":"%s","base":"%s","commits":%d","head":"%s","summary":"%s"}\n' \ - "$genome" "$GENOME_BASE" $commits "$(git rev-parse --short HEAD)" "$summary" +# array `files`: link locale (file://) e remoto (Forgejo web) per ogni raw committata +files_json="$( + for row in "${ROWS[@]}"; do + IFS=$'\t' read -r rel aname <<< "$row" + jq -n --arg file "$rel" --arg author "$aname" \ + --arg lpath "${vault}/${rel}" \ + --arg lurl "file://${vault}/${rel}" \ + --arg rurl "${FORGEJO_WEB_BASE}/${FORGEJO_OWNER}/${genome}/src/branch/${GENOME_BASE}/${rel}" \ + '{file:$file, author:$author, local_path:$lpath, local_url:$lurl, remote_url:$rurl}' + done | jq -s '.' +)" + +jq -n --arg genome "$genome" --arg base "$GENOME_BASE" --argjson commits "$commits" \ + --arg head "$head" --arg summary "$summary" --argjson files "$files_json" \ + '{status:"ok", genome:$genome, base:$base, commits:$commits, head:$head, summary:$summary, files:$files}' From a23b679a109fac8dc3755a58021d02fbae5ba2da Mon Sep 17 00:00:00 2001 From: Matteo Cherubini Date: Sun, 21 Jun 2026 00:05:54 +0200 Subject: [PATCH 5/5] Update version --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0e25953..00c5b77 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # ============================================================================= -# Knowledge Genome - Makefile v. 1.5.0 +# Knowledge Genome - Makefile v. 1.5.1 # Orchestrates the setup and management of the knowledge base. # =============================================================================