homelab-codex-ws/scripts/kb/new-doc.sh
oskar 013eeb429b feat(kb): skill i skrypt do pisania dokumentow kb/ (OKF authoring)
kb-authoring: sciagawka frontmattera OKF v0.1, taksonomia typow z
rozstrzygnieciami decision/incident/runbook/audit wyciagnietymi z historii
migracji (SPLIT commity), domyslne visibility: private, przypomnienie o
check_okf.py po kazdej zmianie. Odrebne od kb-publish (to dotyczy pisania
zrodel, nie wystawki public).

new-doc.sh: scaffolduje kb/<type>s/<slug>.md z poprawnym frontmatterem,
waliduje type, odmawia nadpisania, dokłada as_of dla type: audit.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UXe8RXn1YDY2HAnX3RVwVS
2026-08-26 17:05:04 +02:00

79 lines
2.3 KiB
Bash
Executable file

#!/usr/bin/env bash
# scripts/kb/new-doc.sh — scaffold a new kb/ document with valid OKF v0.1 frontmatter.
#
# Usage: scripts/kb/new-doc.sh <type> <slug> [--public]
#
# <type> one of the kb/ document types (see TYPES below) — plural directory
# kb/<type>s/ must already exist.
# <slug> filename stem (no .md); becomes kb/<type>s/<slug>.md.
# --public sets visibility: public instead of the default private. Only pass
# this when the operator has explicitly decided the doc is public —
# see .claude/skills/kb-authoring/SKILL.md "Visibility default".
#
# Refuses to overwrite an existing file. Does not touch docs/sessions/ —
# session logs are not kb/ documents (type: session-log is out of scope here).
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
TYPES=(node service subsystem decision incident runbook phase audit)
fail() {
echo "[new-doc] BLAD: $*" >&2
exit 1
}
[[ $# -ge 2 ]] || fail "usage: scripts/kb/new-doc.sh <type> <slug> [--public]"
DOC_TYPE="$1"
SLUG="$2"
shift 2
VISIBILITY="private"
for arg in "$@"; do
case "$arg" in
--public) VISIBILITY="public" ;;
*) fail "opcja nieznana: $arg" ;;
esac
done
is_valid_type=false
for t in "${TYPES[@]}"; do
[[ "$t" == "$DOC_TYPE" ]] && is_valid_type=true
done
"$is_valid_type" || fail "type '$DOC_TYPE' spoza listy (${TYPES[*]})"
[[ "$SLUG" =~ ^[a-z0-9][a-z0-9._-]*$ ]] \
|| fail "slug '$SLUG' — dozwolone tylko [a-z0-9._-], zaczynajac od [a-z0-9]"
TARGET_DIR="$REPO_ROOT/kb/${DOC_TYPE}s"
[[ -d "$TARGET_DIR" ]] || fail "katalog $TARGET_DIR nie istnieje"
TARGET_FILE="$TARGET_DIR/$SLUG.md"
[[ -e "$TARGET_FILE" ]] && fail "plik juz istnieje: $TARGET_FILE (nie nadpisuje)"
TODAY="$(date +%F)"
TITLE="$(echo "$SLUG" | tr '-' ' ' | sed 's/\b\(.\)/\u\1/g')"
{
echo "---"
echo 'okf: "0.1"'
echo "type: $DOC_TYPE"
echo "visibility: $VISIBILITY"
echo "status: active"
echo "updated: $TODAY"
if [[ "$DOC_TYPE" == "audit" ]]; then
echo "as_of: $TODAY"
fi
echo "links: []"
echo "---"
echo
echo "# $TITLE"
echo
} > "$TARGET_FILE"
echo "[new-doc] utworzono: kb/${DOC_TYPE}s/$SLUG.md (visibility: $VISIBILITY)"
echo "[new-doc] Uzupelnij tresc, potem scripts/kb/check_okf.py"