Skip to content

"Vibe-Trading: Your Personal Trading Agent"

ci: keep internal documents out of tracked files

Haozhe Wu29aa084fb786
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 84a880e4d..48e8a387e 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -116,8 +116,8 @@ jobs:
- name: Repository safety gates
run: bash tools/ci_grep_gates.sh
- - name: Test environment variable gate
- run: pytest tools/test_ci_env_var_gate.py -q
+ - name: Test repository safety gates
+ run: pytest tools/test_ci_env_var_gate.py tools/test_ci_private_files_gate.py -q
- name: Syntax check
run: |
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 00d82ed4d..ec78e9339 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -55,6 +55,27 @@ For AI-assisted or automation-assisted contributions, also see
local checks, higher-risk broker/MCP/credential surfaces, and the expected PR
risk notes for agent-authored changes.
+## Keep internal documents local
+
+The repository-root `docs/` directory holds local working notes and must not
+be committed. Local agent instructions and memory files (`AGENTS.md`,
+`AGENTS.override.md`, `CLAUDE.md`, `CLAUDE.local.md`, `MEMORY.md`,
+`CODEX_MEMORY.md`, and `NOTES.md`) must also remain untracked at any depth.
+Publish project documentation in `wiki/docs/` or the relevant source directory.
+
+Before committing, run:
+
+```bash
+python tools/ci_private_files_gate.py
+```
+
+This check also runs through `bash tools/ci_grep_gates.sh` in CI on pushes and
+pull requests. It reads the Git index, so force-adding an ignored document is
+still rejected; ignored local files and public documentation are allowed.
+It prints filenames only, never document contents. If a file was accidentally
+staged, use `git rm --cached -- <path>` to stop tracking it while preserving the
+local copy. This does not erase copies in previous commits.
+
## Developer Certificate of Origin (DCO)
Every commit in a community pull request MUST carry a `Signed-off-by:`
diff --git a/tools/ci_grep_gates.sh b/tools/ci_grep_gates.sh
index 1ede52178..1d131856d 100644
--- a/tools/ci_grep_gates.sh
+++ b/tools/ci_grep_gates.sh
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# ci_grep_gates.sh — repo-wide safety floor enforced in CI.
#
-# Four gates run sequentially; any failure exits non-zero and names the
+# Gates run sequentially; any failure exits non-zero and names the
# offending files. Run locally before pushing:
#
# bash tools/ci_grep_gates.sh
@@ -20,6 +20,9 @@
# (e) No raw `os.getenv` / `os.environ.get` / `os.environ["KEY"]` reads
# outside the centralized config layer (`agent/src/config/`).
# AST-based; uses `tools/ci_env_var_gate.py`.
+# (f) No process-wide os patches in tests.
+# (g) No internal documents in the Git index, even if force-added.
+# Uses `tools/ci_private_files_gate.py`; ignored local files are allowed.
#
# Exclusions: .git, node_modules, __pycache__, .venv, dist, build, this
# script itself. The HTML scan in (c) is scoped to wiki/alpha-library/**
@@ -58,8 +61,8 @@ fi
# -------------------------------------------------------------- gate (b)
# docs/ is excluded: those are internal planning docs that discuss the
# trademark policy itself (e.g. "the string 'WorldQuant' must not appear in
-# user-facing artifacts"). docs/ is not shipped to PyPI / public consumers
-# (memory: feedback_no_push_docs). The gate's real target is source code,
+# user-facing artifacts"). Gate (g) prevents these local documents from
+# being tracked. This gate's target is source code,
# READMEs, HTML/JSON manifests, and the wiki.
echo "[gate b] no 'WorldQuant' trademark string in shipped artifacts ..."
B_HITS=$(grep -rni --include='*.py' --include='*.md' --include='*.html' --include='*.json' \
@@ -162,6 +165,12 @@ else
echo "${GREEN}ok${NC}"
fi
+# -------------------------------------------------------------- gate (g)
+echo "[gate g] no tracked internal documents ..."
+if ! python tools/ci_private_files_gate.py; then
+ FAILED=1
+fi
+
# --------------------------------------------------------------- result
if [ "$FAILED" -ne 0 ]; then
echo
diff --git a/tools/ci_private_files_gate.py b/tools/ci_private_files_gate.py
new file mode 100644
index 000000000..de11fcc4e
--- /dev/null
+++ b/tools/ci_private_files_gate.py
@@ -0,0 +1,72 @@
+#!/usr/bin/env python3
+"""Reject internal documents in the Git index, including force-added files.
+
+Run before committing with ``python tools/ci_private_files_gate.py``.
+Only indexed paths are inspected; ignored local files and their contents are
+never read. The same index check runs on CI's checked-out commit.
+"""
+
+from __future__ import annotations
+
+import os
+import subprocess
+import sys
+from pathlib import Path, PurePosixPath
+
+
+PRIVATE_DOCUMENT_NAMES = frozenset({
+ "agents.md",
+ "agents.override.md",
+ "claude.md",
+ "claude.local.md",
+ "memory.md",
+ "codex_memory.md",
+ "notes.md",
+})
+
+
+def main(repo_root: Path | None = None) -> int:
+ """Check the Git index for internal document paths.
+
+ Args:
+ repo_root: Repository to check; defaults to this script's repository.
+
+ Returns:
+ Zero for a clean index, one for forbidden paths, or two if Git fails.
+ """
+ root = repo_root if repo_root is not None else Path(__file__).resolve().parent.parent
+ try:
+ result = subprocess.run(
+ ["git", "ls-files", "--cached", "--full-name", "-z"],
+ cwd=root,
+ capture_output=True,
+ check=True,
+ )
+ except (OSError, subprocess.CalledProcessError):
+ print("FAIL: cannot read the Git index; internal-document check did not run.")
+ return 2
+
+ forbidden = []
+ for raw_path in result.stdout.split(b"\0"):
+ if not raw_path:
+ continue
+ name = os.fsdecode(raw_path)
+ path = PurePosixPath(name)
+ if path.parts[0].casefold() == "docs" or path.name.casefold() in PRIVATE_DOCUMENT_NAMES:
+ forbidden.append(name)
+
+ if forbidden:
+ print("FAIL: internal documents are tracked in Git:")
+ for name in sorted(set(forbidden)):
+ # Escape control characters so a filename cannot inject CI output.
+ print(f" {ascii(name)}")
+ print("Use git rm --cached -- <path> to retain the local file without tracking it.")
+ print("Publish project documentation under wiki/docs/ or the relevant source directory.")
+ return 1
+
+ print("OK: no internal documents are tracked in Git.")
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/tools/test_ci_private_files_gate.py b/tools/test_ci_private_files_gate.py
new file mode 100644
index 000000000..2ebe8616e
--- /dev/null
+++ b/tools/test_ci_private_files_gate.py
@@ -0,0 +1,92 @@
+"""Exercise the privacy gate against real temporary Git indexes."""
+
+from __future__ import annotations
+
+import subprocess
+from pathlib import Path
+
+import pytest
+
+from ci_private_files_gate import main
+
+
+def _git(root: Path, *args: str) -> None:
+ """Run Git in an isolated test repository."""
+ subprocess.run(["git", "-C", str(root), *args], check=True, capture_output=True)
+
+
+def repo(tmp_path: Path) -> Path:
+ """Create a real repository with an ignored internal-documents directory."""
+ _git(tmp_path, "init", "-q")
+ (tmp_path / ".gitignore").write_text("/docs/\nAGENTS.md\nCLAUDE.md\n", encoding="utf-8")
+ _git(tmp_path, "add", "--", ".gitignore")
+ return tmp_path
+
+
+ "docs/sessions/private.md",
+ "docs/plans/design.json",
+ "docs",
+ "DOCS/private.md",
+ "AGENTS.md",
+ "agent/AGENTS.override.md",
+ "CLAUDE.md",
+ "frontend/CLAUDE.local.md",
+ "MEMORY.md",
+ "nested/CODEX_MEMORY.md",
+ "NOTES.md",
+ "docs/notes with spaces\nand newline.md",
+])
+def test_force_added_internal_documents_fail(repo: Path, name: str, capsys) -> None:
+ path = repo / name
+ path.parent.mkdir(parents=True, exist_ok=True)
+ path.write_text("private content must never appear in output", encoding="utf-8")
+ _git(repo, "add", "-f", "--", name)
+
+ assert main(repo) == 1
+ output = capsys.readouterr().out
+ assert ascii(name) in output
+ assert "private content" not in output
+
+
+def test_public_docs_and_ignored_local_notes_pass(repo: Path) -> None:
+ for name in ["wiki/docs/guide.md", "agent/src/skills/example/SKILL.md", "README.md"]:
+ path = repo / name
+ path.parent.mkdir(parents=True, exist_ok=True)
+ path.write_text("public documentation", encoding="utf-8")
+ _git(repo, "add", "--", name)
+ (repo / "docs").mkdir()
+ (repo / "docs/private.md").write_text("local notes", encoding="utf-8")
+ (repo / "CLAUDE.md").write_text("local instructions", encoding="utf-8")
+
+ assert main(repo) == 0
+
+
+def test_unstaged_deletion_does_not_hide_an_indexed_file(repo: Path) -> None:
+ path = repo / "docs/private.md"
+ path.parent.mkdir()
+ path.write_text("private", encoding="utf-8")
+ _git(repo, "add", "-f", "--", "docs/private.md")
+ path.unlink()
+
+ assert main(repo) == 1
+
+
+def test_untracking_keeps_local_content_and_clears_failure(repo: Path) -> None:
+ path = repo / "docs/private.md"
+ path.parent.mkdir()
+ original = b"local notes\r\n\x00unchanged\n"
+ path.write_bytes(original)
+ _git(repo, "add", "-f", "--", "docs/private.md")
+ assert main(repo) == 1
+
+ _git(repo, "rm", "--cached", "--", "docs/private.md")
+
+ assert path.read_bytes() == original
+ assert main(repo) == 0
+
+
+def test_missing_git_repository_fails_closed(tmp_path: Path, capsys) -> None:
+ assert main(tmp_path) == 2
+ assert "check did not run" in capsys.readouterr().out