Skip to content

Add agent skill for adding c-api functions#8001

Merged
youknowone merged 2 commits into
RustPython:mainfrom
bschoenmaeckers:c-api-agent-skill
Jun 1, 2026
Merged

Add agent skill for adding c-api functions#8001
youknowone merged 2 commits into
RustPython:mainfrom
bschoenmaeckers:c-api-agent-skill

Conversation

@bschoenmaeckers

@bschoenmaeckers bschoenmaeckers commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Summary by CodeRabbit

  • Documentation
    • Added a new workflow document detailing how to implement missing RustPython C-API functions, including mapping approach, implementation constraints, testing guidance, style requirements, completion checklist, and example prompts for the skill.

@bschoenmaeckers bschoenmaeckers changed the title Add agent skill Add agent skill for adding c-api functions Jun 1, 2026
@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 9a1342e2-5003-4b2f-8e0b-98d725f34e76

📥 Commits

Reviewing files that changed from the base of the PR and between cd09d5b and bb0b825.

📒 Files selected for processing (1)
  • .agents/skills/rustpython-capi-expansion/SKILL.md
✅ Files skipped from review due to trivial changes (1)
  • .agents/skills/rustpython-capi-expansion/SKILL.md

📝 Walkthrough

Walkthrough

This PR adds a skill guide documentation file that defines the workflow and rules for implementing missing RustPython C-API functions, specifying source-of-truth mappings from pyo3-ffi headers to capi modules, implementation procedures, testing expectations, and completion criteria.

Changes

RustPython C-API Expansion Skill Documentation

Layer / File(s) Summary
Skill guide for C-API implementation
.agents/skills/rustpython-capi-expansion/SKILL.md
New skill guide document defining the workflow for implementing missing RustPython C-API functions, including header-to-module mapping strategy, step-by-step implementation and testing procedures, style rules, a completion checklist, and example prompts for the skill to handle.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested reviewers

  • youknowone
  • ShaharNaveh
  • fanninpm

Poem

🐰 A tiny guide in ink and light,
Mapping headers, making right.
Step by step the coder hops,
Tests in place, no loose ends stop.
Hooray—C-API grows tonight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add agent skill for adding c-api functions' clearly summarizes the main change: adding a new agent skill for C-API functions, which directly corresponds to the documentation file added.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ShaharNaveh ShaharNaveh added the skip:ci Skip running the ci label Jun 1, 2026

@ShaharNaveh ShaharNaveh 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.

lgtm!

@ShaharNaveh ShaharNaveh requested a review from youknowone June 1, 2026 13:28

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
.agents/skills/rustpython-capi-expansion/SKILL.md (2)

28-28: ⚡ Quick win

Clarify "direct contract assumptions" terminology.

The phrase "direct contract assumptions" is ambiguous in the context of FFI safety. For AI agents implementing unsafe FFI code, clearer guidance would help prevent safety issues.

Consider rephrasing to be more explicit:

-7. Prefer direct contract assumptions over defensive null checks unless required by the established local style.
+7. Follow the C-API contract directly (e.g., assume non-null where documented) rather than adding defensive checks, unless existing capi modules show a different pattern.

This makes it clear that the guidance is about following documented C-API contracts, not about skipping safety checks arbitrarily.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.agents/skills/rustpython-capi-expansion/SKILL.md at line 28, Replace the
ambiguous phrase "direct contract assumptions" in SKILL.md with an explicit
wording that directs authors to follow the documented C-API/FFI contract
precisely (e.g., "follow documented C-API contracts and preconditions exactly")
and clarify that this guidance means trusting declared non-null/non-ownership
guarantees from the foreign API rather than omitting safety checks arbitrarily;
update the surrounding sentence to mention "FFI/C-API documented preconditions
(e.g., non-null pointers, lifetime/ownership rules)" so readers know the scope
and exceptions.

3-3: 💤 Low value

Consider shortening the description field.

The description spans 277 characters and mixes multiple concerns (what, where, when, and examples). Some YAML parsers or metadata systems may have length constraints. Consider moving detailed examples to the skill body and keeping the description focused on when to trigger this skill.

Example refactor:

-description: Implement missing RustPython C-API functions in crates/capi using the pyo3-ffi header split mapping (`pyo3-ffi/src/*.rs`, mirroring CPython C API headers). Use this whenever the user asks to add or port C-API functions (for example from setobject.h, dictobject.h, unicodeobject.h) or add capi tests.
+description: Implement missing RustPython C-API functions using pyo3-ffi header mappings. Triggered when user requests C-API function additions or capi tests.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.agents/skills/rustpython-capi-expansion/SKILL.md at line 3, The description
field is too long and mixes examples and implementation details; shorten it to a
single focused trigger statement (e.g., "Trigger when implementing RustPython
C-API functions in crates/capi using pyo3-ffi header mappings") and move
examples and file/path details (like "pyo3-ffi/src/*.rs", "crates/capi", and
example headers such as setobject.h, dictobject.h, unicodeobject.h) into the
SKILL.md body or examples section so the description stays concise and under
length limits.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.agents/skills/rustpython-capi-expansion/SKILL.md:
- Line 12: The SKILL.md reference to pyo3-ffi/src/*.rs is incorrect because
pyo3-ffi is a crate dependency not vendored here; update the SKILL.md
instruction (line referencing `pyo3-ffi/src/*.rs`) to tell agents how to obtain
the exact pyo3-ffi sources that match the repo’s Cargo.lock (e.g., instruct to
fetch the crate from the Cargo registry with the version from Cargo.lock, use
`cargo vendor` to vendor pyo3-ffi into the workspace, or point to the matching
docs.rs/crates.io release), and include which file pattern to look for
(`pyo3-ffi/src/*.rs`) once the crate sources are fetched so the CPython
header-split mapping becomes accessible.

---

Nitpick comments:
In @.agents/skills/rustpython-capi-expansion/SKILL.md:
- Line 28: Replace the ambiguous phrase "direct contract assumptions" in
SKILL.md with an explicit wording that directs authors to follow the documented
C-API/FFI contract precisely (e.g., "follow documented C-API contracts and
preconditions exactly") and clarify that this guidance means trusting declared
non-null/non-ownership guarantees from the foreign API rather than omitting
safety checks arbitrarily; update the surrounding sentence to mention "FFI/C-API
documented preconditions (e.g., non-null pointers, lifetime/ownership rules)" so
readers know the scope and exceptions.
- Line 3: The description field is too long and mixes examples and
implementation details; shorten it to a single focused trigger statement (e.g.,
"Trigger when implementing RustPython C-API functions in crates/capi using
pyo3-ffi header mappings") and move examples and file/path details (like
"pyo3-ffi/src/*.rs", "crates/capi", and example headers such as setobject.h,
dictobject.h, unicodeobject.h) into the SKILL.md body or examples section so the
description stays concise and under length limits.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: c58da508-756c-4584-8320-cba5335fabb4

📥 Commits

Reviewing files that changed from the base of the PR and between 1ce37bf and cd09d5b.

📒 Files selected for processing (1)
  • .agents/skills/rustpython-capi-expansion/SKILL.md


## Source of truth for target files

- Use this mapping source: `pyo3-ffi/src/*.rs`, which mirrors the CPython header split used by the C API.

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if pyo3-ffi exists in the repository or is a known external dependency

# Check if pyo3-ffi is a local path in the repository
if fd -t d 'pyo3-ffi' .; then
  echo "Found pyo3-ffi directory in repository"
  fd -t f -e rs . pyo3-ffi/src/ | head -5
else
  echo "pyo3-ffi not found as local directory"
fi

# Check if pyo3-ffi is referenced in Cargo.toml files
rg -n 'pyo3-ffi' -g 'Cargo.toml' -C 2

Repository: RustPython/RustPython

Length of output: 223


Fix pyo3-ffi/src/*.rs reference in SKILL.md (line 12)

  • pyo3-ffi/src/*.rs is not reachable via a local pyo3-ffi/src directory in this repo checkout (the follow-up search path pyo3-ffi/src/ is missing).
  • Since pyo3-ffi is a crate dependency rather than vendored here, update the skill to tell agents where to obtain the pyo3-ffi sources that correspond to the Cargo.lock version (e.g., the Cargo registry checkout / cargo vendor / docs.rs), so the CPython header-split mapping is actually accessible.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.agents/skills/rustpython-capi-expansion/SKILL.md at line 12, The SKILL.md
reference to pyo3-ffi/src/*.rs is incorrect because pyo3-ffi is a crate
dependency not vendored here; update the SKILL.md instruction (line referencing
`pyo3-ffi/src/*.rs`) to tell agents how to obtain the exact pyo3-ffi sources
that match the repo’s Cargo.lock (e.g., instruct to fetch the crate from the
Cargo registry with the version from Cargo.lock, use `cargo vendor` to vendor
pyo3-ffi into the workspace, or point to the matching docs.rs/crates.io
release), and include which file pattern to look for (`pyo3-ffi/src/*.rs`) once
the crate sources are fetched so the CPython header-split mapping becomes
accessible.

@youknowone youknowone merged commit 36a1722 into RustPython:main Jun 1, 2026
17 checks passed
@bschoenmaeckers bschoenmaeckers deleted the c-api-agent-skill branch June 1, 2026 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip:ci Skip running the ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants