#!/usr/bin/env bash # ============================================================================= # skills/ingest/scripts/log-append.sh # Append one entry to the append-only ledger wiki/log.md, in the exact format # defined by AGENTS.md / wiki-log.md. Generates run_id. Never edits prior entries. # # log-append.sh --type INGEST --subject "" --model "" \ # --context "[[raw/x]]" --output "[[sources/x]]" \ # --reasoning "One sentence." # ============================================================================= set -euo pipefail LOG_FILE="${LOG_FILE:-wiki/log.md}" type="" subject="" model="" context="" output="" reasoning="" while [[ $# -gt 0 ]]; do case "$1" in --type) type="$2"; shift 2 ;; --subject) subject="$2"; shift 2 ;; --model) model="$2"; shift 2 ;; --context) context="$2"; shift 2 ;; --output) output="$2"; shift 2 ;; --reasoning) reasoning="$2"; shift 2 ;; *) echo "log-append: unknown arg: $1" >&2; exit 1 ;; esac done : "${type:?--type required}" : "${subject:?--subject required}" case "$type" in INGEST|LINT|QUERY|CONFLICT|CONFIG|SECURITY) ;; *) echo "log-append: invalid TYPE '${type}'" >&2; exit 1 ;; esac [[ -f "$LOG_FILE" ]] || { echo "log-append: not found: $LOG_FILE" >&2; exit 1; } run_id="$(uuidgen 2>/dev/null || cat /proc/sys/kernel/random/uuid 2>/dev/null || python3 -c 'import uuid; print(uuid.uuid4())')" today="$(date +%Y-%m-%d)" { printf '\n## [%s] %s | %s\n\n' "$today" "$type" "$subject" printf -- '- run_id: `%s`\n' "$run_id" printf -- '- model: `%s`\n' "${model:-unknown}" printf -- '- context_read: %s\n' "${context:-*(none)*}" printf -- '- output_written: %s\n' "${output:-*(none)*}" printf -- '- reasoning: %s\n' "${reasoning:-No reasoning provided.}" } >> "$LOG_FILE" echo "run_id=${run_id}"