Skip to content

docs: add CLAUDE.md/AGENTS.md agent guide (#759)#1008

Merged
yingjerkao merged 7 commits into
masterfrom
docs/agent-guide
Jul 9, 2026
Merged

docs: add CLAUDE.md/AGENTS.md agent guide (#759)#1008
yingjerkao merged 7 commits into
masterfrom
docs/agent-guide

Conversation

@yingjerkao

Copy link
Copy Markdown
Collaborator

Summary

Seeds the agent-driven workflow proposed in #759 with an operational guide for coding agents (Claude Code, Codex). This is the "Phase 1" safeguard from that issue: a single place that tells an agent how to produce PRs that pass CI, plus the guardrails and domain rules agents otherwise get wrong.

AGENTS.md is a symlink to CLAUDE.md (git mode 120000) so both toolchains read one source of truth — edit CLAUDE.md only. Resolves cleanly on Linux/macOS/WSL, where Cytnx is developed.

Scope of decisions (per discussion)

  • Shared file — one canonical CLAUDE.md, AGENTS.md symlinked to it.
  • Lean operational contract (~126 lines) — loads fast every session, stays current.
  • Mechanical only — the phased roadmap stays in Introducing Agentic Code Generators into Workflow #759; this file is how to work correctly, not what to work on.

Contents

Notes for reviewers

  • All commands were fact-checked against the repo (presets, test_main/gpu_test_main targets, ctest presets).
  • Docs-only change — no CI impact beyond the docs build; the clang-format hook has no C/C++ files to check here.
  • Open questions I'd welcome input on: (1) keep AGENTS.md as a symlink vs. a one-line pointer file (symlink risk on native-Windows checkouts); (2) whether the Co-Authored-By agent-attribution line should be project policy.

Closes #759 is not asserted — this is only Phase 1 of that issue; leaving #759 open for the later phases.

🤖 Generated with Claude Code

Seed the agent-driven workflow from #759 with an operational guide for coding
agents (Claude Code, Codex). Covers the mechanical contract: preset-based build,
C++/GPU/Python test invocation, the clang-format v14 / pre-commit rule, the CI
gates to clear before a PR, commit/PR conventions, the #759 guardrails (scoped
diffs, physics changes need human review), and the domain gotchas that agents
get wrong (dtype enum ordering, Type.type_promote across real/complex, GPU
in-place kernel gaps, the variant-dispatch direction).

AGENTS.md is a symlink to CLAUDE.md so both toolchains read one source of truth.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive guide for coding agents in CLAUDE.md and creates a symlink to it in AGENTS.md. The review feedback suggests replacing the Git symlink with a standard markdown pointer file to avoid compatibility issues on Windows. Additionally, it recommends simplifying the build instructions in CLAUDE.md by leveraging CMake's --preset option during the build phase instead of hardcoding build directories and job flags.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread AGENTS.md Outdated
Comment thread CLAUDE.md Outdated
Comment thread CLAUDE.md Outdated
Comment thread CLAUDE.md Outdated
@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 32.96%. Comparing base (7b4d7dc) to head (670a145).
⚠️ Report is 52 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1008      +/-   ##
==========================================
+ Coverage   30.82%   32.96%   +2.14%     
==========================================
  Files         229      230       +1     
  Lines       33348    33106     -242     
  Branches    14069    13813     -256     
==========================================
+ Hits        10281    10915     +634     
+ Misses      15795    14824     -971     
- Partials     7272     7367      +95     
Flag Coverage Δ
cpp 32.61% <ø> (+2.15%) ⬆️
python 61.84% <ø> (+0.40%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
C++ backend 33.73% <ø> (+1.47%) ⬆️
Python bindings 25.15% <ø> (+6.37%) ⬆️
Python package 61.84% <ø> (+0.40%) ⬆️
see 71 files with indirect coverage changes

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7b4d7dc...670a145. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pcchen

pcchen commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Review

Nice work — this is an unusually well-fact-checked guide. I verified the claims directly against the repo (presets, test_main/gpu_test_main targets, .clang-format, pre-commit v14 pin, submodules, the pyproject preset pin + [dev] extra, the Type.hpp enum ordering, type_promote, CYTNX_FUNC_NAME, cytnx_error_msg, and each CI workflow). Almost everything holds up. One claim is wrong, plus two minor notes.

1. The version-consistency gate is mischaracterized (describes a CI safety net that doesn't exist)

- **version-consistency** — if you change the minimum Python version, update every site listed in CONTRIBUTING.md.

This conflates two unrelated things:

  • The version-consistency workflow (display name "Release metadata consistency") runs tools/check_release_consistency.py and checks version.cmake / docs/site_root/versions.json — the release package version and docs slug. It has nothing to do with the minimum Python version.
  • The minimum Python version has no automated check at all. CONTRIBUTING.md says so explicitly: "There is no automated check for this — please grep for the old version string."

So an agent that bumps requires-python, sees "version-consistency" listed as the enforcing gate, and assumes CI will catch a missed site, will push drift that CI never validates. Suggest describing this gate as guarding version.cmake/versions.json release metadata, and keeping the min-Python-version note with the (accurate) "See also → CONTRIBUTING.md" pointer.

Minor notes (non-blocking)

  • CI-gate identifiers vs. displayed check names. The guide names the gates clang-format-check, ci-cmake_tests, ci-downstream-find-package, version-consistency — these are the workflow filenames, but the checks shown on the PR UI read "Formatting Check", "Tests and Codecov", "Downstream find_package", "Release metadata consistency". An agent scanning the PR status list for those exact strings won't find them verbatim; worth aligning or noting they're filenames.
  • AGENTS.md symlink on native Windows. Already flagged as an open question in the PR description — on a checkout with core.symlinks=false, AGENTS.md materializes as a 9-byte text file containing CLAUDE.md rather than resolving. Given Cytnx is developed on Linux/macOS/WSL this is acceptable, but the fallback content is misleading if a Windows agent reads it.

Everything else I spot-checked — presets, debug-*/ctest presets, tests/gpu/, clang-format v14, dtype enum ordering (ComplexDouble=1 … Int64=5, matching the dtype <= 2 complex idiom in Type.hpp), type_promote, CYTNX_FUNC_NAME, the .[dev] install command, and the pytest invocation — is accurate.

Posted by Claude Code on behalf of @pcchen

yingjerkao and others added 4 commits July 7, 2026 16:56
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Comment thread CLAUDE.md

Python — CI installs editable and runs pytest (pyproject pins `--preset=openblas-cpu`):

```bash

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible to use preset here

Comment thread CLAUDE.md
Green locally before opening a PR. CI enforces:

- **clang-format-check** (v14) — formatting clean.
- **ci-cmake_tests** — `ctest` (`test_main`) *and* `pytest pytests/` both pass; Codecov.

@IvanaGyro IvanaGyro Jul 7, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is able to set up cuda build environment in cloud agent environment. We can consider to ask build cuda to align with the previous section "use cuda preset if touch cuda code"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is able to set up cuda build environment in cloud agent environment. We can consider to ask build cuda to align with the previous section "use cuda preset if touch cuda code"

Does this mean running agents off Github? Or we can subscribe to the Github GPU workers.

@IvanaGyro IvanaGyro Jul 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean running agents off Github?

Yes. In both codex and Claude Code cloud session. cuda compiler and libraries can be installed on a machine without GPU. The limitation is cuda code can be built on those machines but can not be run. We can also build cuda variant with GitHub action without GPU workers.

Comment thread CLAUDE.md Outdated
## Commits & PRs

- Branch off `master`; never push straight to `master`.
- Small, single-purpose commits; conventional subjects: `fix(linalg): …`,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just tell the bots follow conventional commits? It is a commit standard

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be defined in Contribution.md

Comment thread CLAUDE.md

```bash
cmake --preset debug-openblas-cpu
cmake --build --preset debug-openblas-cpu --target test_main

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While building and running debug cuda preset, some env need to be set to suppress ASAN errro

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you provide some examples?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ASAN_OPTIONS='protect_shadow_gap=0:replace_intrin=0:detect_leaks=0'
Refer to:
google/sanitizers#629 (comment)
https://stackoverflow.com/a/68027496

@ianmccul

ianmccul commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

its worth having a separate GEMINI.md because that is used by the Gemini bot for reviews. For example it keeps suggesting changes for C++17 compatibility, which is really annoying and pointless. GEMINI.md can be more focussed on what needs reviewing, rather than developer-orientated CLAUDE.md and AGENTS.md. See for example https://github.com/Uni20-dev/uni20/blob/main/GEMINI.md. Its basically a moving target of "stop bringing up these issues in automated reviews".

Gemini free reviews go away in another week, but you could get a gemini free trial for another month, and maybe worth paying for it longer-term. I have used gemini-cli briefly (now replaced by Antigravity), but only the free tier so I am not sure how good the higher tier models are, but I've been generally impressed with the gemini reviews.

@pcchen

pcchen commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Code Review

Useful, accurate agent guide — I spot-verified the content against the repo: every named preset exists in CMakePresets.json, the clang-format-v14 pin, dtype-enum ordering (lower index = higher precision), type_promote cross-kind behavior, cytnx_error_msgcytnx::errorCytnxError, the variant-dispatch migration direction, and the CI-gates list all check out. The "domain gotchas" section is exactly the right list — it's the traps this month's PRs actually hit.

Findings

1. 🟠 AGENTS.md is a broken symlink. It's committed with git mode 120000 (symlink) but its blob is a 103-byte markdown string — a symlink's blob must be exactly the target path. On POSIX checkout this materializes as a dangling symlink whose "target" is the literal text # Agent Guide⏎⏎Please see…; any non-Claude agent reading AGENTS.md gets ENOENT. (GitHub's web UI renders the target text, which is why the PR view looks fine.) Fix: either a true symlink (blob content exactly CLAUDE.md) or a regular 100644 file with the pointer text — and align the "AGENTS.md is a symlink to it" sentence accordingly.

2. 🟡 Consider folding in the review-attribution policy. There's an (uncommitted) maintainer CLAUDE.md convention in use — agent-authored posts carry "Posted by Claude Code on behalf of @user" attribution. That's an operational-contract item for agents and belongs in this canonical file; it would also avoid a local-file collision when this lands.

3. 🟡 Add the naming conventions @IvanaGyro asked to codify (in the #1001 thread): leading _ = member variable, trailing _ = in-place mutator returning self, snake_case for new code (#836). This PR is the natural home — a short "Naming" section would close that loop.

4. 🟢 Forward-looking gotcha: "a length-1 scalar RHS must stay CPU-resident (#988)" describes post-#980/#992 semantics — neither merged yet. Fine as guidance; consider "(once #980/#992 land)".

Content: LGTM. The symlink defect (finding 1) is the one must-fix.

Posted by Claude Code on behalf of @pcchen

@IvanaGyro

Copy link
Copy Markdown
Member

Add the naming conventions @IvanaGyro asked to codify (in the #1001 thread): leading _ = member variable, trailing _ = in-place mutator returning self, snake_case for new code (#836). This PR is the natural home — a short "Naming" section would close that loop.

I may have bad wording so the bot cannot understand me.

I suggest follow Google style for naming for all new code except that file has consistent naming other than the style guide. Most of C++ files have messy naming now. It is not benefit to try to follow the messy naming if the file has already messy. Google style picked in this project (not by me). Additionally, leading _ should be prohibited for new code strictly.

@ianmccul

ianmccul commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

I suggest also adding to the AI guidance, is to pass simple C++ types by value. The AI tends to follow the surrounding code so it passes simple values by const& when it should pass by value. For Cytnx scalars, passing by reference will never be faster. Even complex<double> is better passed by value, and will actually be passed via CPU registers in some cases. Passing by reference requires pushing the value onto the stack, passing a pointer to that value into the function, and then the function has to load the pointer and dereference it to retrieve the value.

The other thing is if (x) cytnx_error_msg(true, "...... %s", "\n"); But I regard that as Cytnx house style now. Cytnx wouldn't be complete without it. But suggest cytnx_error_msg adds "\033[1A" to the string, to get the extra line back 🤣

@ianmccul

ianmccul commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

I don't like the Google style of T &x. It sort-of makes sense in C code for pointers, T *x, where (*x) is is an object of type T, but in C++ we prefer to think that x is a "pointer to T". And for references, T &x looks very strange to me. There is no sense in which &x functions like something of type T.

@yingjerkao

yingjerkao commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator Author

I think the easiest way to enforce Google C++ style is using Skills, such as Google C++ Style Guide Skill,Google Python Style Guide Skill.

yingjerkao and others added 2 commits July 9, 2026 11:49
Address the style-enforcement review feedback on #1008:

- Add two Claude Code skills that enforce the project's Google style
  baseline for new code: google-cpp-style and google-python-style. They
  encode the Cytnx-specific overrides raised in review — no leading
  underscore in new code (#836), trailing-underscore = in-place mutator
  returning *this, snake_case for new identifiers, and scalars passed by
  value rather than const& (per @ianmccul).
- Add GEMINI.md as a focused list of review-specific reminders for the
  Gemini Code Assist bot, so it stops raising C++17-compat suggestions
  (the project is C++20 / CUDA 20) and other recurring false positives.
- Un-ignore .claude/skills/ so the shared skills are committed while
  per-user .claude config stays ignored.
- Reference the skills and GEMINI.md from CLAUDE.md (AGENTS.md symlink).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- AGENTS.md: replace the dangling symlink (git mode 120000 whose target was
  the pointer text, so it ENOENT'd on POSIX checkouts) with a regular 100644
  pointer file to CLAUDE.md. Resolves the broken-symlink finding; update the
  "AGENTS.md is a symlink" wording in CLAUDE.md to "pointer".
- Document the AddressSanitizer env for debug presets:
  ASAN_OPTIONS='protect_shadow_gap=0:replace_intrin=0:detect_leaks=0'
  (debug-* presets set USE_DEBUG=ON -> -fsanitize=address).
- Note that a *-cuda preset can be built without a GPU to compile-check CUDA
  code (toolkit installs on GPU-less machines / cloud agents; only running GPU
  tests needs hardware).
- Reference the Conventional Commits standard by name in the commit section.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@yingjerkao
yingjerkao merged commit 27d64f8 into master Jul 9, 2026
19 checks passed
@yingjerkao
yingjerkao deleted the docs/agent-guide branch July 9, 2026 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Introducing Agentic Code Generators into Workflow

4 participants