feat: cover pi and opencode in link.sh

Generated (concatenated) AGENTS.md for both tools, marked so re-runs
overwrite safely; MACHINE=<name> picks the machine profile. Commands
link into ~/.config/opencode/commands alongside ~/.claude/commands.
This commit is contained in:
Miguel Palhas
2026-08-19 15:13:51 +01:00
parent c10761b1eb
commit 6f84c63a19
+51 -3
View File
@@ -7,14 +7,21 @@ set -euo pipefail
REPO="$(cd "$(dirname "$0")/.." && pwd)"
# targets: agent config skill roots. Claude Code reads ~/.claude/skills,
# Codex reads ~/.agents/skills. Both consume the same SKILL.md dirs.
# Codex and Pi read ~/.agents/skills, opencode auto-loads both dirs.
# All four consume the same SKILL.md dirs.
CLAUDE_SKILLS="$HOME/.claude/skills"
CODEX_SKILLS="$HOME/.agents/skills"
CLAUDE_CMDS="$HOME/.claude/commands" # commands are Claude-only; Codex ignores
OPENCODE_CMDS="${XDG_CONFIG_HOME:-$HOME/.config}/opencode/commands"
CLAUDE_HOOKS="$HOME/.claude/hooks" # hooks are Claude-only
CLAUDE_HOME="$HOME/.claude" # CLAUDE.md fragments, pulled in via @name.md
CLAUDE_RULES="$HOME/.claude/rules" # path-scoped rules
CODEX_HOME="$HOME/.codex" # Codex global config root
PI_HOME="$HOME/.pi/agent" # Pi global config root
OPENCODE_HOME="${XDG_CONFIG_HOME:-$HOME/.config}/opencode"
# Which claude-md/machines/<name>.md to bake into Pi/opencode AGENTS.md.
MACHINE="${MACHINE:-default}"
# Per-FILE links, never a whole-dir link: ~/.claude/hooks and ~/.claude itself hold
# machine-local files this repo does not own, and a dir symlink would hide them.
@@ -34,7 +41,27 @@ link() { # link <src> <dst>
echo "linked $dst -> $src"
}
mkdir -p "$CLAUDE_SKILLS" "$CODEX_SKILLS" "$CLAUDE_CMDS" "$CLAUDE_HOOKS" "$CLAUDE_RULES" "$CODEX_HOME"
gen() { # gen <dst> <fragment...> — writes a generated (concatenated) file
local dst="$1"
shift
if [ -e "$dst" ] && ! grep -q "$GEN_MARK" "$dst" 2>/dev/null; then
mkdir -p "$BACKUP"
mv "$dst" "$BACKUP/$(basename "$(dirname "$dst")")-$(basename "$dst").bak"
echo "backed up existing $dst -> $BACKUP/"
fi
{
echo "$GEN_MARK"
for f in "$@"; do
echo
cat "$f"
done
} >"$dst"
echo "wrote $dst (generated from fragments)"
}
GEN_MARK="<!-- generated by agent-skills/bin/link.sh — edit fragments, re-run -->"
mkdir -p "$CLAUDE_SKILLS" "$CODEX_SKILLS" "$CLAUDE_CMDS" "$CLAUDE_HOOKS" "$CLAUDE_RULES" "$CODEX_HOME" "$PI_HOME" "$OPENCODE_CMDS"
for d in "$REPO"/skills/*/; do
name="$(basename "$d")"
@@ -45,6 +72,7 @@ done
for f in "$REPO"/commands/*.md; do
[ -e "$f" ] || continue
link "$f" "$CLAUDE_CMDS/$(basename "$f")"
link "$f" "$OPENCODE_CMDS/$(basename "$f")"
done
for f in "$REPO"/hooks/*.py "$REPO"/hooks/*.sh; do
@@ -54,9 +82,11 @@ done
# code-comments.md is path-scoped and belongs in rules/, not here — linking it
# into ~/.claude/ as well would load it unconditionally and defeat the scoping.
# opencode-header.md is opencode-only (baked into its generated AGENTS.md).
for f in "$REPO"/claude-md/*.md; do
[ -e "$f" ] || continue
[ "$(basename "$f")" = "code-comments.md" ] && continue
[ "$(basename "$f")" = "opencode-header.md" ] && continue
link "$f" "$CLAUDE_HOME/$(basename "$f")"
done
@@ -71,6 +101,24 @@ link "$REPO/entry/CLAUDE.md" "$CLAUDE_HOME/CLAUDE.md"
link "$REPO/entry/codex-AGENTS.md" "$CODEX_HOME/AGENTS.md"
rm -f "$CODEX_HOME/RTK.md"
# Pi and opencode have no @file imports: their AGENTS.md is generated by
# concatenating the fragments (machine profile first). opencode auto-loads
# skills from ~/.claude/skills and ~/.agents/skills, so it needs no skill links.
gen "$PI_HOME/AGENTS.md" \
"$REPO/claude-md/machines/$MACHINE.md" \
"$REPO/claude-md/operating.md" \
"$REPO/claude-md/writing.md" \
"$REPO/claude-md/code-comments.md" \
"$REPO/claude-md/RTK.md"
gen "$OPENCODE_HOME/AGENTS.md" \
"$REPO/claude-md/opencode-header.md" \
"$REPO/claude-md/machines/$MACHINE.md" \
"$REPO/claude-md/operating.md" \
"$REPO/claude-md/writing.md" \
"$REPO/claude-md/code-comments.md" \
"$REPO/claude-md/RTK.md"
# Linked but never enabled: enabling on every machine would spawn one review
# session per box for the same week.
if [ -d /run/systemd/system ]; then
@@ -81,7 +129,7 @@ if [ -d /run/systemd/system ]; then
done
fi
echo "done."
echo "done. (MACHINE=$MACHINE for generated Pi/opencode AGENTS.md)"
echo "hooks still need wiring in ~/.claude/settings.json — see hooks/README.md"
echo "timers (one machine only):"
echo " systemctl --user daemon-reload"