Merge commit 'ac794a6a7051497ff60b947642d44f0f8c04d6c6' into lsp-server

This commit is contained in:
csh
2026-01-08 15:56:37 +08:00
113 changed files with 254751 additions and 176 deletions
@@ -3,7 +3,7 @@ set -eu
# Sync standards snapshot to project root.
# - Copies <snapshot>/.agents/<AGENTS_NS> -> <project-root>/.agents/<AGENTS_NS>
# - Updates <project-root>/.gitattributes (managed block by default)
# - Updates <project-root>/.gitattributes (append missing rules by default)
# Existing targets are backed up before overwrite.
#
# Multi rulesets:
@@ -14,7 +14,11 @@ set -eu
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)"
SRC="$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd -P)"
ROOT="$(git -C "$SCRIPT_DIR" rev-parse --show-toplevel 2>/dev/null || pwd)"
if [ -n "${SYNC_ROOT:-}" ]; then
ROOT="$SYNC_ROOT"
else
ROOT="$(git -C "$SCRIPT_DIR" rev-parse --show-toplevel 2>/dev/null || pwd)"
fi
ROOT="$(CDPATH= cd -- "$ROOT" && pwd -P)"
AGENTS_SRC_ROOT="$SRC/.agents"
GITATTR_SRC="$SRC/.gitattributes"
@@ -43,8 +47,23 @@ if [ "${SYNC_STANDARDS_INNER:-}" != "1" ]; then
if [ -z "${langs:-}" ] && [ "$#" -gt 0 ]; then
langs="$*"
fi
if [ -z "${langs:-}" ] && [ "$#" -eq 0 ] && [ -z "${AGENTS_NS:-}" ]; then
auto_langs=""
if [ -d "$ROOT/.agents" ]; then
for dir in "$ROOT/.agents"/*; do
[ -d "$dir" ] || continue
ns="$(basename "$dir")"
if [ -d "$AGENTS_SRC_ROOT/$ns" ]; then
auto_langs="${auto_langs:+$auto_langs }$ns"
fi
done
fi
if [ -n "$auto_langs" ]; then
langs="$auto_langs"
fi
fi
if [ -n "${langs:-}" ]; then
sync_mode_first="${SYNC_GITATTR_MODE:-block}"
sync_mode_first="${SYNC_GITATTR_MODE:-append}"
first=1
old_ifs="${IFS}"
@@ -121,11 +140,23 @@ EOF
echo "Created .agents/index.md"
fi
AGENTS_MD="$ROOT/AGENTS.md"
if [ ! -f "$AGENTS_MD" ]; then
cat >"$AGENTS_MD" <<'EOF'
# Agent Instructions
请以 `.agents/` 下的规则为准:
- 入口:`.agents/index.md`
EOF
echo "Created AGENTS.md"
fi
echo "Synced agents ruleset to $AGENTS_DST."
GITATTR_DST="$ROOT/.gitattributes"
if [ -f "$GITATTR_SRC" ]; then
: "${SYNC_GITATTR_MODE:=block}"
: "${SYNC_GITATTR_MODE:=append}"
case "$SYNC_GITATTR_MODE" in
skip)
echo "Skip: .gitattributes sync (SYNC_GITATTR_MODE=skip)."
@@ -142,6 +173,75 @@ if [ -f "$GITATTR_SRC" ]; then
echo "Synced .gitattributes from standards (overwrite)."
fi
;;
append)
if [ "$(CDPATH= cd -- "$(dirname -- "$GITATTR_SRC")" && pwd -P)/$(basename -- "$GITATTR_SRC")" = "$GITATTR_DST" ]; then
echo "Skip: .gitattributes source equals destination."
else
missing_tmp="$(mktemp 2>/dev/null || echo "$ROOT/.gitattributes.missing.$timestamp")"
if [ -f "$GITATTR_DST" ]; then
awk '
function norm(line) {
gsub(/^[ \t]+|[ \t]+$/, "", line)
return line
}
FNR==NR {
line=norm($0)
if (line == "" || line ~ /^#/) next
seen[line]=1
next
}
{
line=norm($0)
if (line == "" || line ~ /^#/) next
if (!seen[line] && !out[line]++) print line
}
' "$GITATTR_DST" "$GITATTR_SRC" >"$missing_tmp"
else
awk '
function norm(line) {
gsub(/^[ \t]+|[ \t]+$/, "", line)
return line
}
{
line=norm($0)
if (line == "" || line ~ /^#/) next
if (!out[line]++) print line
}
' "$GITATTR_SRC" >"$missing_tmp"
fi
if [ ! -s "$missing_tmp" ]; then
rm -f "$missing_tmp"
echo "No missing .gitattributes rules to append."
echo "Done."
exit 0
fi
if [ -e "$GITATTR_DST" ]; then
mv "$GITATTR_DST" "$ROOT/.gitattributes.bak.$timestamp"
echo "Backed up existing .gitattributes -> .gitattributes.bak.$timestamp"
fi
source_note="$GITATTR_SRC"
case "$GITATTR_SRC" in
"$ROOT"/*) source_note="${GITATTR_SRC#$ROOT/}" ;;
esac
header="# Added from playbook .gitattributes (source: $source_note)"
{
if [ -f "$ROOT/.gitattributes.bak.$timestamp" ]; then
cat "$ROOT/.gitattributes.bak.$timestamp"
if [ -s "$ROOT/.gitattributes.bak.$timestamp" ]; then
printf "\n"
fi
fi
printf "%s\n" "$header"
cat "$missing_tmp"
} >"$GITATTR_DST"
rm -f "$missing_tmp"
echo "Appended missing .gitattributes rules from standards."
fi
;;
block)
begin="# BEGIN playbook .gitattributes"
end="# END playbook .gitattributes"
@@ -191,7 +291,7 @@ if [ -f "$GITATTR_SRC" ]; then
echo "Updated .gitattributes from standards (managed block)."
;;
*)
echo "ERROR: invalid SYNC_GITATTR_MODE=$SYNC_GITATTR_MODE (use block|overwrite|skip)" >&2
echo "ERROR: invalid SYNC_GITATTR_MODE=$SYNC_GITATTR_MODE (use block|overwrite|append|skip)" >&2
exit 1
;;
esac