cloud-fan commented on code in PR #60555:
URL: https://github.com/apache/spark/pull/60555#discussion_r4594078185


##########
dev/agent_docs_lint.py:
##########
@@ -0,0 +1,295 @@
+#!/usr/bin/env python3
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""
+Checks the repository's agent instruction files (AGENTS.md / CLAUDE.md, and 
the detail files
+in .agents/ directories) for the properties that coding agents such as Claude 
Code and Codex
+depend on:
+
+  pairing   Each directory with agent instructions has both names, one a 
symlink to the
+            other, as the root AGENTS.md asks. Codex reads AGENTS.md and 
ignores CLAUDE.md
+            by default. Claude Code reads AGENTS.md only when no CLAUDE.md 
exists in the
+            working directory or above it, so once the root has a CLAUDE.md, a 
nested
+            directory with only an AGENTS.md is skipped. Two real files let 
the two tools
+            follow different instructions.
+  codex-cap Codex concatenates AGENTS.md from the repo root down to its 
working directory
+            into one budget of project_doc_max_bytes (32768 by default), 
filled root first,
+            and silently truncates past it. Every root-to-directory chain must 
fit.
+  budget    Soft size targets that keep always-loaded instructions small: the 
root file
+            and nested files. Detail belongs in a sibling .agents/ directory 
behind a
+            pointer. Warnings only.
+  pointers  Every `.agents/...`, `AGENTS.md` or `CLAUDE.md` path quoted in an 
instruction
+            file, including the files under .agents/, resolves to an existing 
file.
+
+Known failures that cannot be fixed yet (e.g. vendored third-party docs) can 
be exempted in
+an optional exceptions file, dev/agent_docs_lint_exceptions.txt by default. 
Each line is
+`<check> <subject>`, where the subject is what the error names: the directory 
for pairing,
+the file where truncation starts for codex-cap, and `<file> <target>` for 
pointers. `#`
+starts a comment. Exempted errors are still reported but do not fail --strict. 
An entry that
+no longer matches any error is itself an error, so the list only shrinks as 
files are fixed.
+
+Report-only by default; pass --strict to exit non-zero on errors (not on 
budget warnings).
+CI runs it with --strict.
+
+    $ dev/agent_docs_lint.py
+    $ dev/agent_docs_lint.py --strict --only codex-cap
+"""
+
+import argparse
+import os
+import re
+import subprocess
+import sys
+from collections import defaultdict
+
+CODEX_CAP = 32768
+ROOT_BUDGET = 8 * 1024
+NESTED_BUDGET = 4 * 1024
+CHECKS = ("pairing", "codex-cap", "budget", "pointers")
+EXEMPTIBLE = ("pairing", "codex-cap", "pointers")
+EXCEPTIONS_FILE = "dev/agent_docs_lint_exceptions.txt"
+NAMES = ("AGENTS.md", "CLAUDE.md", "AGENTS.override.md")
+POINTER_RE = 
re.compile(r"`((?:[\w.-]+/)*(?:\.agents/[\w./-]+\.md|AGENTS\.md|CLAUDE\.md))`")
+
+
+def repo_root():
+    return subprocess.check_output(["git", "rev-parse", "--show-toplevel"], 
text=True).strip()
+
+
+def tracked_files():
+    # Tracked plus untracked-but-not-ignored files, so a new AGENTS.md is 
checked before it is
+    # staged. Skip tracked files deleted in the working tree.
+    out = subprocess.check_output(
+        ["git", "ls-files", "--cached", "--others", "--exclude-standard", 
"-z"], text=True
+    )
+    return sorted({p for p in out.split("\0") if p and os.path.lexists(p)})
+
+
+def is_detail_file(path):
+    """A Markdown file under a .agents/ directory."""
+    return path.endswith(".md") and ".agents" in path.split("/")[:-1]
+
+
+def codex_selected(directory):
+    """The one file Codex loads in `directory`, if any (override > 
AGENTS.md)."""
+    for name in ("AGENTS.override.md", "AGENTS.md"):
+        path = os.path.join(directory, name)
+        if os.path.isfile(path):
+            return path
+    return None
+
+
+def size(path):

Review Comment:
   Fixed in 2d07819. `check_codex_cap` now also takes each file's size once per 
chain.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to