agentleFS
JetBrainsKnown publisherJetBrains/kotlin-desktop-toolkit/native/desktop-win32/docs/AGENTS.md

kotlin-desktop-toolkit / desktop-win32

AGENTS.md201 starsChanged 6 months agoApache-2.0View on GitHub

You are reading this because you've been pointed at the native/desktop-win32 crate (or its Kotlin counterpart at kotlin-desktop-toolkit/src/main/kotlin/org/jetbrains/desktop/win32/) and need to navigate, modify, or debug it. Read this file first; it indexes the rest. Windows backend of the kotlin-desktop-toolkit. Rust crate (cdylib) exposing a flat C ABI via cbindgen, consumed from Kotlin via JExtract-generated bindings plus hand-written wrappers. UI runs on a single thread (OleInitialize STA) with a classic GetMessage pump in event_loop.rs. Composition uses WinRT Windows.UI.Composition via ICompositorDesktopInterop —…

  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.

    Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repository2 other files it gives its agents.

The file

We split this AGENTS.md into the rules it gives an agent

3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    If you only read one section before touching code, read this one.

    line 18
  2. Distinctive:

    Confirm interpretation when offered A vs B: When asked to choose between two approaches, explicitly state which one you're adopting and why.

    line 41
  3. Distinctive:

    Don't let any of these docs claim something the code doesn't do.

    line 58

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

Agent orientation: desktop-win32

You are reading this because you've been pointed at the native/desktop-win32 crate (or its Kotlin counterpart at kotlin-desktop-toolkit/src/main/kotlin/org/jetbrains/desktop/win32/) and need to navigate, modify, or debug it. Read this file first; it indexes the rest.

What this crate is

Windows backend of the kotlin-desktop-toolkit. Rust crate (cdylib) exposing a flat C ABI via cbindgen, consumed from Kotlin via JExtract-generated bindings plus hand-written wrappers. UI runs on a single thread (OleInitialize STA) with a classic GetMessage pump in event_loop.rs. Composition uses WinRT Windows.UI.Composition via ICompositorDesktopInterop — not DirectComposition. Rendering is ANGLE-on-D3D11.

Start here

  • ARCHITECTURE.md — module layout, FFI pipeline, threading and ownership models, error channel, headline data flows.
  • FFI_CONVENTIONS.md — the *_api.rs ↔ Kotlin contract; pointer/array/option type zoo; ffiDownCall scoping rule; COM lifecycle.
  • SUBSYSTEMS.md — per-subsystem reference. Look up the area you're touching.
  • TODO.md — confirmed bugs, capability gaps, smells, open design questions. Cross-reference before claiming something is "broken" or "missing".

Top things that surprise

If you only read one section before touching code, read this one.

  1. This is the Win32-first backend. Default to Win32 APIs (CreateWindowExW, GetMessageW, RegisterDragDrop, IFileOpenDialog, …). Use WinRT only when there's a documented reason — there are exactly four such subsystems today, each justified in ARCHITECTURE.md → Scope. Never propose WinUI 3 or Windows App SDK (Microsoft.UI.*, Microsoft.WindowsAppSDK) APIs in this crate. A WinUI 3 backend, if built, lives in a separate crate.
  2. Composition is Windows.UI.Composition (WinRT), not DirectComposition. They're distinct APIs with different lifetimes and threading. See ARCHITECTURE.md → Composition section.
  3. Single UI thread. OleInitialize STA, DispatcherQueue with DQTYPE_THREAD_CURRENT, the wndproc, and most state assume one thread. Cross-thread work goes through application_dispatcher_invoke. Several pieces are thread_local! (key-message stash, exception store).
  4. Error channel is anyhow::Result through ffi_boundary, not return codes. Rust functions return anyhow::Result<T>; ffi_boundary logs any Err, appends the message to thread-local LAST_EXCEPTION_MSGS, and returns R::default(). Kotlin's ffiDownCall polls after every call and throws NativeError. Panic catching inside ffi_boundary is a safety net for unexpected unwinds, not a designed error path — if Rust code panics, treat it as a bug. Background-thread errors are lost (thread-local store).
  5. ffiDownCall { ... } must wrap only the native call. Not Arena.use, not withPointer, not helpers (which wrap their own native calls). Wider scopes conflate exception attribution. See FFI_CONVENTIONS.md.
  6. Window starts at 1×1 and is then resized. Intentional: managed code uses logical pixels but the DPI scale only exists once an HWND exists (GetDpiForWindow). Consequence: creation emits repeated WM_WINDOWPOSCHANGED notifications; this crate handles that message and returns 0, so it does not rely on a downstream DefWindowProc-generated WM_SIZE path. Size/move handlers must be idempotent.
  7. Coordinates are mostly logical, but with deliberate physical-pixel exceptions. Pointer events' locationOnScreen, several Window events, drag-drop callbacks, and screen_map_to_client carry PhysicalPoint / PhysicalSize. See SUBSYSTEMS.md → Geometry → Exceptions.
  8. EnableMouseInPointer(true) is process-wide and irreversible. Anything in the same process expecting raw WM_MOUSE* will silently break.
  9. The borrow pattern on RustAllocatedRawPtr (ffi_utils.rs) reconstructs and immediately leaks a Box per call to produce a &R. Sound under the toolkit's single-thread-of-ownership assumption; soundness is by convention. Currently under deferred review.

Watch out for in code reviews / edits

  • Kotlin tryRead* wrappers return null only for format-unavailable and throw other clipboard/data-object failures. Use result-bearing FFI for nullable read semantics.
  • COM impls have no // SAFETY: comments anywhere (and desktop-common::ffi_utils has a module-level #![allow(clippy::missing_safety_doc)]). Add one when you touch an unsafe block.
  • Most clipboard / drag-drop work assumes the OLE STA. There is no thread-affinity assertion at the FFI boundary — the synchronous Clipboard API trusts the caller to stay on the dispatcher thread and to handle DataTransferStatus.Busy retries itself.

Working with the human

The high-impact conventions for collaborating on this crate:

  • Outline before executing anything multi-file or API-shaping. Wait for confirmation before reaching for Edit / Write.
  • Confirm interpretation when offered A vs B. When asked to choose between two approaches, explicitly state which one you're adopting and why; don't silently compose hybrids.
  • ffiDownCall scoping: wrap only the native call (not Arena.use, not withPointer, not helpers).
  • Throwing helper naming: require* / check* / ensure* for throwing preconditions; reserve let / if* / takeIf* for genuine no-op semantics.
  • Distinguish documented contract from observed implementation behaviour — never state behaviour observed in source code or experiment as if it were a documented guarantee. Prefix inferred-from-behaviour claims with "implementation-defined" / "in practice" / "per the X implementation". If asked where a claim is documented and you can't cite the source, admit it was inferred — bluffing about the docs erodes trust and leads to design decisions built on false premises.
  • Use authoritative-docs lookup skills when your agent platform exposes them. For Win32 / WinRT questions, Claude Code provides microsoft-docs:microsoft-docs (concept lookup) and microsoft-docs:microsoft-code-reference (API / SDK code verification). Prefer these over speculating from internal knowledge — especially when distinguishing documented contract from observed behaviour (above).
  • Don't add redundant explanatory clauses on top of content that already conveys the same point. Trust the prose to do its job.
  • A wrong claim about current state may still be a valid design suggestion. When you (or a reviewer) correct a factual error of yours, check whether the wrong version was nonetheless what the code should be. If so, voice both halves: "I was wrong that X is Y, but X should be Y, and here's why." Don't silently retract — your hallucination may have surfaced a real bug.
  • Doc-fix sweeps can introduce new overreach. When tightening a stale doc claim, verify the replacement against every reader the claim now covers — a fix scoped to one function can over-promise for a class of callers that doesn't share the new property. Example: a Window::get_scale cache fix restated as "chrome / hit-test code never re-syscalls per frame", missing that on_nchittest still calls GetSystemMetricsForDpi(SM_CYSIZE) live. Enumerate cached fields explicitly rather than relying on broad "never" claims.

When to update this doc set

  • Subsystem refactor (e.g. another _reader cousin, a new _api.rs) → update SUBSYSTEMS.md and probably ARCHITECTURE.md.
  • New FFI primitive in desktop-common::ffi_utils → update FFI_CONVENTIONS.md.
  • Shipped fix for a TODO.md entry → remove the entry (don't leave stale ones).
  • Found a new bug or capability gap → add to TODO.md.
  • The "top surprises" above stop being accurate → update this file.

Don't let any of these docs claim something the code doesn't do. Before recommending an action that names a specific file, line, function, or flag, verify it still exists and behaves as described — docs decay even when carefully maintained.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.