Skip to content

Refresh stale content in copilot-instructions.md - #2049

Merged
shimat merged 2 commits into
mainfrom
docs/copilot-instructions-staleness-fixes
Jul 15, 2026
Merged

shimat merged 2 commits into
mainfrom
docs/copilot-instructions-staleness-fixes

Conversation

@shimat

@shimat shimat commented Jul 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

Staleness fixes — several sections of .github/copilot-instructions.md still described the pre-OpenCvSharp5 / pre-StdVector<T> state of the repo:

  • NuGet README sync table: listed OpenCvSharp4, OpenCvSharp4.Windows, OpenCvSharp4.Windows.Slim, OpenCvSharp4.Extensions, OpenCvSharp4.WpfExtensions, OpenCvSharp4.runtime.*, OpenCvSharp4.official.runtime.* — but every current PackageId (checked across all .csproj files) is OpenCvSharp5.*. Also missing: OpenCvSharp4.Extensions was renamed to OpenCvSharp5.GdipExtensions, and a new OpenCvSharp5.AvaloniaExtensions package exists.
  • Free-function facade scope list: was missing Shape and VideoIORegistry, which already have Cv2.Shape.cs / Cv2.VideoIORegistry.cs facades.
  • std::vector return values guidance: prescribed VectorOfInt32, VectorOfVec4f, VectorOfVec6d — none of which exist anymore. Blittable/primitive element types now use the generic StdVector<T> directly; dedicated VectorOfXxx classes are only for non-blittable/nested types.
  • "EdgeDrawing as reference implementation": still described the file as using VectorOfVec6d; it now uses StdVector<Vec6d>/StdVector<Vec4f>/StdVector<int>.
  • "Params struct pattern" code sample: prescribed [MarshalAs(UnmanagedType.Bool)] on the P/Invoke struct — current practice uses a plain int field with manual conversion instead.
  • Branch note: said `main`/`5.x` as if a separate 5.x branch exists; only main and 4.x actually exist.

New content — transcribed several conventions and pitfalls that had only been recorded informally across past sessions, so they're now discoverable by anyone (human or AI) editing this repo:

  • Explicit argument-validation rule (ArgumentNullException.ThrowIfNull etc., with the three cases that intentionally stay unconverted).
  • POD value types crossing the extern boundary go in interop:: with a bit_cast-based converter, plus its two exceptions.
  • A "one-shot config classes" alternative to the per-field Params struct pattern (getAll/setAll + blittable POD).
  • Common P/Invoke pitfalls: cv::Ptr<T>* vs. raw T* mismatches, silent LPStr/LPUTF8Str marshaling regressions, and testing a round trip before copying an existing binding pattern.
  • A native-ABI/breaking-change policy section (5.x allows changing both sides, but prefer the smallest natural fix), folding in "justify deletions with a BCL alternative" and "don't add IDisposable for a minor efficiency win."
  • Markdown authoring (no hard-wrapping mid-paragraph) and pull request conventions (match existing merged-PR style, no invented headings).
  • Explicit "all repository content is English" statement, and the Extensions packages (Wpf/Gdip/Avalonia) in the repository-structure overview.

No functional/code changes — documentation only.

Summary by CodeRabbit

  • Documentation
    • Updated AI coding guidance for OpenCvSharp5 package naming, main branch behavior, and 4.x freeze policy.
    • Refined wrapper-generation rules for std::vector/VectorOf* types, including when to use StdVector<T> and when to generate specialized vector wrappers.
    • Clarified P/Invoke parameter handling for boolean fields using int-backed blittable structs and public-facing boolean properties.
    • Refreshed EdgeDrawing guidance and expanded reference material on common interop pitfalls and repo/PULL request conventions.

Several sections still described the pre-OpenCvSharp5 / pre-StdVector<T>
state of the repo: the NuGet README sync table listed OpenCvSharp4.*
package names (actual PackageIds are all OpenCvSharp5.* now, including
the renamed GdipExtensions and the new AvaloniaExtensions package), the
free-function facade scope list was missing Shape/VideoIORegistry, the
std::vector guidance still pointed at VectorOfInt32/VectorOfVec4f/
VectorOfVec6d (none of which exist anymore now that blittable element
types use the generic StdVector<T> directly), the EdgeDrawing reference
description and Params-struct code sample still showed the old
VectorOfVec6d / [MarshalAs(UnmanagedType.Bool)] patterns instead of the
current StdVector<T> / plain-int-field conventions, and the branch note
implied a separate "5.x" branch exists alongside main.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Updated .github/copilot-instructions.md with OpenCvSharp5 packaging and branch conventions, wrapper-generation and interop rules, EdgeDrawing examples, documentation practices, and repository-level contribution guidance.

Changes

OpenCvSharp5 contributor guidance

Layer / File(s) Summary
Packaging and branch conventions
.github/copilot-instructions.md
NuGet synchronization targets, Markdown authoring rules, repository structure, native ABI policy, branch notes, DLL loading guidance, and PR conventions now reflect the OpenCvSharp5 development model.
Wrapper and interop guidance
.github/copilot-instructions.md
Wrapper generation distinguishes StdVector<T> from dedicated vector wrappers, while P/Invoke guidance covers int-backed booleans, POD conversion, validation, namespace access, facade naming, and updated EdgeDrawing examples.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes a documentation refresh in copilot-instructions.md and matches the main change.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/copilot-instructions-staleness-fixes

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.

Add several conventions/pitfalls that came up repeatedly across past
sessions but were only recorded informally, so they're now discoverable
by anyone (human or AI) editing this repo:

- Explicit argument-validation rule (ArgumentNullException.ThrowIfNull
  etc., with the three cases that stay unconverted).
- POD value types crossing the extern boundary go in `interop::` with
  a bit_cast-based converter, with its two exceptions.
- A "one-shot config classes" alternative to the per-field Params
  struct pattern (getAll/setAll + blittable POD).
- Common P/Invoke pitfalls: cv::Ptr<T>* vs. raw T* mismatches, silent
  LPStr/LPUTF8Str marshaling regressions, and testing a round trip
  before copying an existing binding pattern.
- A native-ABI/breaking-change policy section (5.x allows changing
  both sides, but prefer the smallest natural fix), folding in the
  established "justify deletions with a BCL alternative" and "don't
  add IDisposable for a minor efficiency win" judgment calls.
- Markdown authoring (no hard-wrapping mid-paragraph) and pull request
  conventions (match existing merged-PR style, no invented headings).
- Explicit "all repository content is English" statement, and the
  Extensions packages (Wpf/Gdip/Avalonia) in the repository-structure
  overview.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

@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

🤖 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 @.github/copilot-instructions.md:
- Around line 178-182: Update the wording in the first “Common P/Invoke
pitfalls” bullet to clearly state that the incorrect pointer declaration broke
the BackgroundSubtractorGMG/MOG property accessors, replacing the confusing
“this bit” phrasing without changing the technical guidance.
🪄 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.yaml

Review profile: CHILL

Plan: Pro

Run ID: fce2aee4-be7c-495a-a7ce-fb9a3a8bbecb

📥 Commits

Reviewing files that changed from the base of the PR and between 0042d96 and ed6f846.

📒 Files selected for processing (1)
  • .github/copilot-instructions.md

Comment on lines +178 to +182
### Common P/Invoke pitfalls

- **`cv::Ptr<T>*` vs. raw `T*` confusion.** `CvPtrObject.Handle` (used by most property getters/setters) returns a raw `T*`, not the smart pointer — a native binding declared as `cv::Ptr<T>* obj` with `(*obj)->getXxx()` silently misinterprets the raw pointer's vtable as a `cv::Ptr`'s internal layout and reliably crashes (access violation) the first time it's called, not at compile time. Match the parameter type to what the C# side actually passes (`Handle` → raw `T*` parameter with `obj->getXxx()`); this bit `BackgroundSubtractorGMG`/`MOG`'s property accessors and went unnoticed because no test exercised a round trip.
- **Don't change a marshaling attribute (`[MarshalAs(UnmanagedType.LPStr)]` vs. `LPUTF8Str`) without checking every native code path that consumes it.** Different OpenCV backends decode filename strings differently (e.g. `cap_msmf.cpp` uses `MultiByteToWideChar(CP_ACP, ...)`, i.e. it expects ANSI, not UTF-8) — switching the attribute to "fix" one call site can silently corrupt non-ASCII paths on a different backend. This kind of regression doesn't show up in a plain build/test run; it only surfaces when you actually exercise the affected path with non-ASCII input.
- **Write one real get/set (or call/verify) round trip before copying an existing property/method pattern to a new class.** Don't trust an existing, untested binding as a copy-source just because it compiles — verify it actually works first.

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Fix the wording in the P/Invoke pitfall.

“this bit BackgroundSubtractorGMG/MOG's property accessors” should read “this broke the BackgroundSubtractorGMG/MOG property accessors” (or equivalent); the current wording is confusing in guidance about a crash-prone binding error.

🤖 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 @.github/copilot-instructions.md around lines 178 - 182, Update the wording
in the first “Common P/Invoke pitfalls” bullet to clearly state that the
incorrect pointer declaration broke the BackgroundSubtractorGMG/MOG property
accessors, replacing the confusing “this bit” phrasing without changing the
technical guidance.

@shimat shimat self-assigned this Jul 15, 2026
@shimat
shimat merged commit 7bf9d15 into main Jul 15, 2026
14 checks passed
@shimat
shimat deleted the docs/copilot-instructions-staleness-fixes branch July 15, 2026 01:03
@shimat shimat added the enhancement New feature or improvement to OpenCvSharp label Jul 25, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Jul 25, 2026
4 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or improvement to OpenCvSharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant