-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathcheck_agents_structure.sh
More file actions
executable file
·96 lines (82 loc) · 2.24 KB
/
Copy pathcheck_agents_structure.sh
File metadata and controls
executable file
·96 lines (82 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
set -euo pipefail
# shellcheck source=scripts/lib.sh
# shellcheck disable=SC1091
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
cdroot
echo "--- check agent docs structure"
required_docs=(
".claude/docs/OBSERVABILITY.md"
".claude/docs/DEV_ISOLATION.md"
".claude/docs/AGENT_FAILURES.md"
)
fail=0
for doc in "${required_docs[@]}"; do
if [[ ! -f "$doc" ]]; then
echo "error: required harness doc is missing: $doc"
fail=1
fi
done
if [[ ! -L ".agents/docs" ]]; then
echo "error: agent docs compatibility symlink is missing: .agents/docs -> ../.claude/docs"
fail=1
elif [[ "$(readlink ".agents/docs")" != "../.claude/docs" ]]; then
echo "error: agent docs compatibility symlink points to $(readlink ".agents/docs"), expected ../.claude/docs"
fail=1
fi
is_reference_path() {
local ref="$1"
case "$ref" in
*/* | package.json | AGENTS.local.md)
return 0
;;
*)
return 1
;;
esac
}
# TODO: Add circular AGENTS.md include detection if nested agent docs begin
# referencing each other. Current checks validate file existence only.
mapfile -t agent_files < <(git ls-files '*AGENTS.md' | sort)
for agent_file in "${agent_files[@]}"; do
agent_dir="$(dirname "$agent_file")"
while IFS=$'\t' read -r line_number ref; do
if [[ -z "${line_number:-}" || -z "${ref:-}" ]]; then
continue
fi
if ! is_reference_path "$ref"; then
continue
fi
candidate="$agent_dir/$ref"
candidate="${candidate#./}"
if [[ -e "$candidate" ]]; then
continue
fi
if [[ "$(basename "$ref")" == "AGENTS.local.md" ]]; then
echo "warning: $agent_file:$line_number: optional local agent file is not present: $ref"
continue
fi
echo "error: $agent_file:$line_number: referenced file does not exist: $ref"
fail=1
done < <(
awk '
/^[[:space:]]*(-[[:space:]]+)?@/ {
ref = $0
sub(/^[[:space:]]*(-[[:space:]]+)?@/, "", ref)
sub(/[[:space:]`)>].*$/, "", ref)
sub(/[,:;)]+$/, "", ref)
print FNR "\t" ref
}
' "$agent_file"
)
done
if [[ -f AGENTS.md ]]; then
root_agent_lines=$(wc -l <AGENTS.md)
if ((root_agent_lines > 600)); then
echo "warning: AGENTS.md is $root_agent_lines lines, consider keeping the root guide concise."
fi
fi
if [[ "$fail" -ne 0 ]]; then
exit 1
fi
echo "OK: agent docs structure looks valid."