Files
boshu2__agentops/scripts/generate-index.sh
T
2026-04-13 10:50:44 -04:00

63 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Generate .agents/INDEX.md — canonical catalog of all knowledge artifacts.
# One line per .md file, organized by category. Wikilinks for Obsidian navigation.
set -euo pipefail
AGENTS_DIR="${1:-.agents}"
OUTPUT="$AGENTS_DIR/INDEX.md"
cat > "$OUTPUT" <<'HEADER'
# .agents/ Knowledge Index
> One line per page. Organized by category. **The canonical discovery surface.**
> If a page isn't linked here, it doesn't exist for agents querying this wiki.
>
> Auto-generated by `scripts/generate-index.sh`. Manual edits will be overwritten.
> To add a page: create the .md file, then re-run the script.
HEADER
# Emit one section per known category.
emit_section() {
local title="$1" dir="$2" prefix="$3"
local full_dir="$AGENTS_DIR/$dir"
if [ ! -d "$full_dir" ]; then return; fi
local count
count=$(find "$full_dir" -maxdepth 1 -name '*.md' -type f 2>/dev/null | wc -l | tr -d ' ')
if [ "$count" -eq 0 ]; then return; fi
echo "## $title ($count)" >> "$OUTPUT"
echo "" >> "$OUTPUT"
find "$full_dir" -maxdepth 1 -name '*.md' -type f | sort | while read -r f; do
local base
base=$(basename "$f" .md)
# Extract first H1 heading, fall back to filename
local heading
heading=$(grep -m1 '^# ' "$f" 2>/dev/null | sed 's/^# //' || echo "$base")
[ -z "$heading" ] && heading="$base"
# Truncate to 80 chars
heading="${heading:0:80}"
echo "- [[$prefix/$base]] — $heading" >> "$OUTPUT"
done
echo "" >> "$OUTPUT"
}
emit_section "Learnings" "learnings" "learnings"
emit_section "Wiki Sources" "wiki/sources" "wiki/sources"
emit_section "Wiki Synthesis" "wiki/synthesis" "wiki/synthesis"
emit_section "Wiki Concepts" "wiki/concepts" "wiki/concepts"
emit_section "Wiki Entities" "wiki/entities" "wiki/entities"
emit_section "Plans" "plans" "plans"
emit_section "Research" "research" "research"
emit_section "Council" "council" "council"
emit_section "Patterns" "patterns" "patterns"
emit_section "Findings" "findings" "findings"
emit_section "Brainstorm" "brainstorm" "brainstorm"
emit_section "Design" "design" "design"
# Footer with stable generator provenance.
echo "---" >> "$OUTPUT"
echo "" >> "$OUTPUT"
echo "_Generated by \`scripts/generate-index.sh\`._" >> "$OUTPUT"
echo "INDEX.md written: $(wc -l < "$OUTPUT") lines"