Skip to content

AGENTS.md#91

Open
stephen-derosa wants to merge 1 commit intolivekit:mainfrom
stephen-derosa:sderosa/clt-2485-AGENTS.MD
Open

AGENTS.md#91
stephen-derosa wants to merge 1 commit intolivekit:mainfrom
stephen-derosa:sderosa/clt-2485-AGENTS.MD

Conversation

@stephen-derosa
Copy link
Copy Markdown
Contributor

Overview

An AGENTS.MD file for guiding cursor on development inside the project

Key points

  • Architecture
  • Build preferences
  • Testing
  • Formatting
  • comments on readability vs performance

Any other points?

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an AGENTS.md guidance document intended for development agents working in the LiveKit C++ Client SDK repo, summarizing architecture, build flow, coding conventions, dependencies, testing, and pitfalls.

Changes:

  • Introduces AGENTS.md with project architecture notes and key internal/public types.
  • Documents recommended build and packaging commands, plus dependency/tooling expectations.
  • Captures coding conventions (logging, public API boundaries, error handling) and testing guidance.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +138 to +139
Adhere to the formatting rules if TODO: @alan

Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

The Formatting section is currently a placeholder (“TODO: @alan”), which leaves agents without actionable guidance. Replace with concrete formatting instructions (e.g., clang-format invocation/config) or remove the section until it’s defined.

Suggested change
Adhere to the formatting rules if TODO: @alan
- Match the style of the surrounding code and keep formatting changes limited to the files you touch.
- Use consistent indentation, spacing, and brace style with nearby C++ headers, sources, CMake files, and Markdown.
- Keep `#include` ordering and whitespace consistent with the existing file rather than reformatting unrelated code.
- If the repository or your editor provides formatting configuration, run it before submitting changes; otherwise prefer minimal, manual formatting-only edits.

Copilot uses AI. Check for mistakes.
When adding new client facing functionality, add benchmarking to understand the limiations of the new functionality.

## Formatting
Adhere to the formatting rules if TODO: @alan
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@alan-george-lk i wonder what the best way t provide this is. My reading on Agents.md leads me to believe we should just put code snippets directly inline. Does clang-tidy provide a list or would it be reasonable to ask cursor:
"Write me an AGENTS.md ## Formatting section which has code examples to be followed for clang-tidy cpp formatting" (or a better prompt)

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.

We as a team should come up with a .clang-format style we all like, then the cpp-linter action I am using in the clang-tidy PR can actually run/enforce that for us. But as far as this file, we could point the Agent to the .clang-format file once that becomes a thing. Probably a separate scope of work beyond clang-tidy, easy to implement but harder to align on preferences ;)

See here: https://clang.llvm.org/docs/ClangFormat.html

@stephen-derosa stephen-derosa force-pushed the sderosa/clt-2485-AGENTS.MD branch 2 times, most recently from bc80b84 to cf6bc19 Compare April 13, 2026 18:00
@stephen-derosa stephen-derosa force-pushed the sderosa/clt-2485-AGENTS.MD branch from cf6bc19 to 348ce39 Compare April 13, 2026 18:04
1. windows x64
2. linux x86_64
3. linux arm64
3. macOS x86_64
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

there are two 3 here

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.

I don't know if the Agent would care, but it's good MD practice generally to just do:

1.
1.
1.

and then it'll render the right order

SDK features follow pattern:

1. Serialize a protobuf `FfiRequest` message.
2. Send it to Rust via `FfiClient::instance().sendRequest(req)`.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

there are two types of ffi messages here, one is synchronous call that we send a ffi request to rust ffi layer, and get back the FfiResponse.

Another one is async calls:
c++ setup a async handler that listens to event with a |request_async_id|
Serialize a protobuf FfiRequest message with a |request_async_id|
Send it to Rust via FfiClient::instance().sendRequest(req).
Receive a synchronous FfiResponse and an asynchronous FfiEvent callback.

| `cmake/` | Build helpers (`protobuf.cmake`, `spdlog.cmake`, `LiveKitConfig.cmake.in`) |
| `docker/` | Dockerfile for CI and SDK distribution images |
| `.github/workflows/` | GitHub Actions CI workflows |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I’m wondering if we should add a dedicated section to clarify the FFI design rules. For example, we should explicitly state that the main implementation logic lives in Rust, and that the C++ layer must remain a thin wrapper over the FFI.

It would also be helpful to include a section describing the threading model, covering questions like:

Is FfiClient thread-safe? (this should be clearly defined)
On which threads are RoomDelegate callbacks invoked?
Are they coming from FFI/Tokio threads?
In the FFI layer, are audio callbacks executed on a dedicated high-priority Tokio runtime?
What are the threading models for:
LocalAudioTrack / LocalVideoTrack
AudioStream / VideoStream
DataStream
What are the thread-safety guarantees of the public API?
(explicitly define whether it is thread-safe or not)

If applicable, clarifying these points would make the design much easier to understand and help avoid misuse.

@xianshijing-lk
Copy link
Copy Markdown
Collaborator

xianshijing-lk commented Apr 13, 2026

Do you find it useful to have the agents.md ?

like, if claude / codex / cursor generate better results with this agents.md ? or it does not have much impact?


### Core Principle
Rust owns as much of the business logic as possible. If a feature may be used by another SDK it should be implemented in Rust. Since this is an SDK,
ensure backwards compatibility is maintained when possible.
Copy link
Copy Markdown
Contributor

@alan-george-lk alan-george-lk Apr 14, 2026

Choose a reason for hiding this comment

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

Maybe explicitly list to avoid breaking changes in headers, or if absolutely necessary, prompt the user/flag them explicitly and require opt-in before proceeding?

Edit: looks like this is called out later in the file

1. windows x64
2. linux x86_64
3. linux arm64
3. macOS x86_64
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.

I don't know if the Agent would care, but it's good MD practice generally to just do:

1.
1.
1.

and then it'll render the right order


When making larger scale changes, check with the developer before committing to architecture changes involving changes to the `client-sdk-rust/` submodule.

### Directory Layout
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.

Is this a required feature of this file? I fear this will get out of date quickly.

Or maybe we add a clause saying "whenever directory structure changes, update AGENTS.md file"

- **`LocalParticipant` / `RemoteParticipant`** — Participant objects for publishing and receiving tracks.

## Build
for building, use the build.sh script for Linux and macOS, and the build.cmd script for Windows. Do not invoke CMake directly.
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.

Nit: fully valid markdown has new lines between section headers/content. There's a nice markdownlint VSCode plugin that I use to help with this stuff: https://marketplace.cursorapi.com/items/?itemName=DavidAnson.vscode-markdownlint

for building, use the build.sh script for Linux and macOS, and the build.cmd script for Windows. Do not invoke CMake directly.

```
./build.sh debug # Debug build
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.

Similar comment to the repo directory structure, might be good to call out any adjustments to these script args should be updated in READMEs and this agents file

- `LK_LOG_INFO` — initialization, critical state changes.
- `LK_LOG_DEBUG` — potentially useful diagnostic info.
- Do not spam logs. Keep it concise.
- In production/internal SDK code, do not use `std::cout`, `std::cerr`, `printf`, or raw spdlog calls; use the logging APIs instead. Tests may use standard streams sparingly for ad hoc diagnostics when appropriate.
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.

Good call out -- in my experience I also like using logging APIs for unit tests, that way you can add more detail at a debug/trace level and keep that off for production/CI runs.


### Error Handling

- Throw exceptions for broken/unrecoverable states.
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.

This is probably a larger team discussion: I am fairly anti-exception for robotics/embedded applications. Some safety certification specifications explicitly disallow exceptions. This would apply more to AV/aerospace customers of LiveKit due to safety requirements.

It would be unfortunate to lose a customer opportunity due to C++ feature usage like this. Looking at the existing SDK code we may not be able to undo existing exceptions, but for new code I'd prefer not to use them when possible.

bool, std::optional, Expected<Type, Error> (in STL later), etc. (which I think we're already using in places)

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.

4 participants