Skip to content

Conversation

@jannden
Copy link
Owner

@jannden jannden commented Jun 3, 2025

feat: Increase player's success chances, also closes #30

Summary by CodeRabbit

  • New Features
    • Introduced a configurable move success probability for game moves.
    • Added a debug instruction to give cards directly to players.
  • Bug Fixes
    • Updated move outcome logic to use probabilistic success instead of direction-based checks.
  • Documentation
    • Improved comments to clarify test mode behavior and probability logic.
  • Refactor
    • Removed unused variables to streamline player initialization.
    • Enhanced transaction log handling in tests to include detailed event and message logs.
    • Simplified event message construction and emission for player actions.
  • Chores
    • Removed deprecated utility function for fetching message logs.
    • Standardized event message formatting and emission across game actions.
    • Updated default network environment to localnet in configuration.
    • Cleaned up console output in tests by removing verbose player and state logs.

@coderabbitai
Copy link

coderabbitai bot commented Jun 3, 2025

## Walkthrough

A new constant for move success probability was introduced, and the move reveal logic was updated to use this probability in determining move outcomes, replacing the previous deterministic direction-based approach. Minor code cleanup and comment updates were also made, without altering any public interfaces.

## Changes

| File(s)                                                          | Change Summary                                                                                     |
|------------------------------------------------------------------|--------------------------------------------------------------------------------------------------|
| programs/blockrunners/src/constants.rs                           | Added `MOVE_SUCCESS_PROBABILITY` constant with documentation and attribute.                       |
| programs/blockrunners/src/instructions/move_reveal.rs           | Refactored move reveal logic to use probabilistic success based on `MOVE_SUCCESS_PROBABILITY`; renamed event message variables; reworded event messages. |
| programs/blockrunners/src/instructions/initialize_player.rs      | Removed unused `game_state` variable from `initialize_player` function.                           |
| programs/blockrunners/src/utils/randomness_reveal.rs             | Updated test-mode comment to clarify always-successful move and card outcome; no code changes.    |
| app/src/idl/blockrunners.json                                   | Added `MOVE_SUCCESS_PROBABILITY` constant with documentation.                                    |
| app/src/idl/blockrunners.ts                                     | Added `moveSuccessProbability` constant with documentation; added `debugGiveCard` instruction.   |
| app/src/lib/utils.ts                                            | Removed `getMsgLogs` function.                                                                   |
| programs/blockrunners/src/instructions/join_game.rs             | Refactored join message construction into a local variable before event emission.                |
| programs/blockrunners/src/instructions/purchase_ciphers.rs      | Created local message variable for purchase success; removed debug log.                          |
| programs/blockrunners/src/utils/give_random_cards.rs             | Created local message variable for max cards collected event emission.                           |
| tests/helpers/utils.ts                                          | Split `getMsgLogs` into `getTxDetails` and updated `getMsgLogs` to accept tx details; added `getEventLogs` for event parsing. |
| tests/initialize_game.ts                                        | Updated tests to use `getTxDetails` before `getMsgLogs` and added `getEventLogs` to log events.  |
| tests/initialize_player.ts                                     | Updated tests to use `getTxDetails` before `getMsgLogs` and added `getEventLogs` to log events.  |
| tests/join_game.ts                                             | Updated tests to use `getTxDetails` before `getMsgLogs` and added `getEventLogs` to log events.  |
| tests/move.ts                                                  | Updated tests to use `getTxDetails` before `getMsgLogs` and added `getEventLogs`; removed one test case and some debug logs. |
| tests/purchase_ciphers.ts                                      | Updated tests to use `getTxDetails` before `getMsgLogs` and added `getEventLogs`; updated one assertion. |
| Anchor.toml                                                    | Changed provider cluster from "devnet" to "localnet".                                           |
| README.md                                                     | Removed "TODO:" prefix from a sentence about default connection in README.                      |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant Player
    participant MoveReveal
    participant Randomness
    participant GameState

    Player->>MoveReveal: Submit move reveal
    MoveReveal->>Randomness: Generate randomness value
    Randomness-->>MoveReveal: Return value
    MoveReveal->>MoveReveal: Compute (randomness % 100 < MOVE_SUCCESS_PROBABILITY)
    alt Success
        MoveReveal->>GameState: handle_correct_move
    else Failure
        MoveReveal->>GameState: handle_incorrect_move
    end
    MoveReveal->>Player: Reset move and cards commitment

Assessment against linked issues

Objective Addressed Explanation
Improve log parsing using EventParser (#30)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected.

Suggested reviewers

  • IhorMuliar

Poem

In the world of hops and chance,
A rabbit tweaks the dance—
Moves now may fail or thrive,
With luck at seventy-five!
Constants set, old paths erased,
The game’s new rhythm, gently traced.
🐇✨


<!-- walkthrough_end -->


---

<details>
<summary>📜 Recent review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**


<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between fc14b1693a2f28515c91e6cca7d1898705bfe034 and 32fd2628bb60cc710d2e3f54229a2d3fd0fa455d.

</details>

<details>
<summary>📒 Files selected for processing (15)</summary>

* `Anchor.toml` (1 hunks)
* `README.md` (1 hunks)
* `app/src/idl/blockrunners.json` (1 hunks)
* `app/src/idl/blockrunners.ts` (2 hunks)
* `app/src/lib/utils.ts` (0 hunks)
* `programs/blockrunners/src/instructions/join_game.rs` (1 hunks)
* `programs/blockrunners/src/instructions/move_reveal.rs` (10 hunks)
* `programs/blockrunners/src/instructions/purchase_ciphers.rs` (1 hunks)
* `programs/blockrunners/src/utils/give_random_cards.rs` (1 hunks)
* `tests/helpers/utils.ts` (4 hunks)
* `tests/initialize_game.ts` (2 hunks)
* `tests/initialize_player.ts` (2 hunks)
* `tests/join_game.ts` (2 hunks)
* `tests/move.ts` (5 hunks)
* `tests/purchase_ciphers.ts` (4 hunks)

</details>

<details>
<summary>💤 Files with no reviewable changes (1)</summary>

* app/src/lib/utils.ts

</details>

<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (14)</summary>

* README.md
* programs/blockrunners/src/instructions/join_game.rs
* programs/blockrunners/src/utils/give_random_cards.rs
* programs/blockrunners/src/instructions/purchase_ciphers.rs
* app/src/idl/blockrunners.json
* tests/initialize_game.ts
* Anchor.toml
* tests/initialize_player.ts
* tests/join_game.ts
* tests/purchase_ciphers.ts
* tests/move.ts
* app/src/idl/blockrunners.ts
* tests/helpers/utils.ts
* programs/blockrunners/src/instructions/move_reveal.rs

</details>

<details>
<summary>⏰ Context from checks skipped due to timeout of 90000ms (1)</summary>

* GitHub Check: test

</details>

</details>
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpETZWaCrKNwSPbABsvkCiQBHbGlcSHFcLz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5A0APcz2dbIogpzW508rEDbJIVQAsQYi2gLrIkWqBLZ+QD2TiD0UkAn53C7WdrLNkPyn5P87+jbPnn0BdQQc8BbLPlmKyqQdAFSs4n0BAA=== -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---

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.

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=jannden/blockrunners&utm_content=65):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Explain this complex logic.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai explain this code block.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and explain its main purpose.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

### Support

Need help? Create a ticket on our [support page](https://www.coderabbit.ai/contact-us/support) for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### CodeRabbit Configuration File (`.coderabbit.yaml`)

- You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository.
- Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json`

### Documentation and Community

- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
programs/blockrunners/src/utils/randomness_reveal.rs (1)

23-23: 💡 Verification agent

🧩 Analysis chain

Verify missing import for RandomnessAccountData.

The code uses RandomnessAccountData::parse() but I don't see the corresponding import statement in the provided code. The AI summary mentions this import was removed, but the type is still being used.


🏁 Script executed:

#!/bin/bash
# Check if RandomnessAccountData is imported or re-exported from another module
rg -A 3 -B 3 "RandomnessAccountData" --type rust

Length of output: 2654


🏁 Script executed:

#!/bin/bash
rg "^use " programs/blockrunners/src/utils/randomness_reveal.rs

Length of output: 154


Add missing RandomnessAccountData import

The file programs/blockrunners/src/utils/randomness_reveal.rs calls RandomnessAccountData::parse(...) but doesn’t import that type. Please add:

 use crate::{errors::BlockrunnersError, state::PlayerState};
+use switchboard_on_demand::RandomnessAccountData;
🧹 Nitpick comments (1)
programs/blockrunners/src/instructions/move_reveal.rs (1)

92-104: Solid probabilistic logic implementation with minor suggestions.

The new probabilistic approach correctly implements a 75% success rate and significantly improves the game mechanics by making success more likely while still maintaining some challenge.

The mathematical logic (random_value % 100) < MOVE_SUCCESS_PROBABILITY is correct and will give exactly the desired success probability.

Consider these improvements:

  1. Extract magic number as constant:
// In constants.rs
+#[constant]
+pub const PERCENTAGE_BASE: u8 = 100;

// In move_reveal.rs imports
-    constants::{GAME_STATE_SEED, MOVE_SUCCESS_PROBABILITY, PLAYER_STATE_SEED},
+    constants::{GAME_STATE_SEED, MOVE_SUCCESS_PROBABILITY, PERCENTAGE_BASE, PLAYER_STATE_SEED},

// In the logic
-    let is_move_successful = (random_value % 100) < MOVE_SUCCESS_PROBABILITY;
+    let is_move_successful = (random_value % PERCENTAGE_BASE) < MOVE_SUCCESS_PROBABILITY;
  1. Add validation for MOVE_SUCCESS_PROBABILITY:
+    // Ensure the probability is valid (should be <= 100)
+    debug_assert!(MOVE_SUCCESS_PROBABILITY <= 100, "Move success probability must be <= 100");
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4231039 and e6262ac.

📒 Files selected for processing (3)
  • programs/blockrunners/src/constants.rs (1 hunks)
  • programs/blockrunners/src/instructions/move_reveal.rs (2 hunks)
  • programs/blockrunners/src/utils/randomness_reveal.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (3)
programs/blockrunners/src/constants.rs (1)

33-35: LGTM! Well-documented constant addition.

The new MOVE_SUCCESS_PROBABILITY constant is properly documented and follows the established patterns. The 75% success rate aligns with the PR objective of increasing player success chances.

programs/blockrunners/src/utils/randomness_reveal.rs (1)

70-70: Good comment update to reflect new logic.

The comment correctly explains that moves are always successful in test mode, which aligns with the new probabilistic approach.

programs/blockrunners/src/instructions/move_reveal.rs (1)

4-4: Good addition of required import.

The import of MOVE_SUCCESS_PROBABILITY is necessary for the new probabilistic logic.

@jannden jannden changed the title WIP Increase player's success chances Jun 16, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (2)
tests/helpers/utils.ts (2)

72-95: confirmTransaction call may mis-confirm & missing null-guard

  1. confirmTransaction is invoked with a fresh latestBlockhash. If the target signature was produced in an earlier slot, the hash/height pair will not match and the confirmation can silently fail.
    Use the simpler overload that takes only the signature (or fetch its block-hash from getTransaction).

  2. txDetails can be null (RPC nodes may prune old data). Subsequent callers assume a non-null object, leading to Cannot read properties of null (reading 'meta').

-const latestBlockHash = await provider.connection.getLatestBlockhash();
-await provider.connection.confirmTransaction(
-  {
-    blockhash: latestBlockHash.blockhash,
-    lastValidBlockHeight: latestBlockHash.lastValidBlockHeight,
-    signature: txSignature,
-  },
-  "confirmed"
-);
+await provider.connection.confirmTransaction(txSignature, "confirmed");
...
-const txDetails = await provider.connection.getTransaction(txSignature, {
+const txDetails = await provider.connection.getTransaction(txSignature, {
   maxSupportedTransactionVersion: 0,
   commitment: "confirmed",
 });
-if (!txDetails) return null;
+if (!txDetails) return null;

97-116: getMsgLogs — stale JSDoc & unsafe access

  • The comment still mentions provider/signature; the function now receives txDetails.
  • Accessing txDetails.meta.logMessages without a null-check will crash when txDetails is null.
  • Returning null when there are simply no logs forces all callers to branch; returning an empty array is simpler.
- * Get logs from program's msg! macro obtained from a transaction
- * @param provider The Anchor provider
- * @param signature The transaction signature
+ * Extract `msg!` logs from an already-fetched transaction
+ * @param txDetails The versioned transaction object
...
-export const getMsgLogs = async (
-  txDetails: anchor.web3.VersionedTransactionResponse
-): Promise<string[] | null> => {
+export const getMsgLogs = (
+  txDetails: anchor.web3.VersionedTransactionResponse | null
+): string[] => {
   try {
-    const logs = txDetails?.meta?.logMessages
+    if (!txDetails?.meta?.logMessages) return [];
+    const logs = txDetails.meta.logMessages
       ?.filter((log) => log.includes("Program log:"))
       .map((log) => log.replace("Program log: ", ""));
-    return logs || null;
+    return logs ?? [];
   } catch (error) {
     console.error("Failed to get transaction logs:", error);
-    return null;
+    return [];
   }
 };
🧹 Nitpick comments (3)
tests/helpers/utils.ts (3)

2-4: Prefer one consistent Program import style

You import Program directly ({ ... , Program }) and later still reference anchor.Program. Importing both names is redundant and may confuse new contributors. Either drop the explicit Program import or replace all anchor.Program usages with the imported symbol, but don’t keep both.

-import { BorshCoder, EventParser, Program } from "@coral-xyz/anchor";
+import { BorshCoder, EventParser } from "@coral-xyz/anchor";

67-71: JSDoc drift — parameters no longer match implementation

getTxDetails now receives only provider and txSignature, yet the JSDoc still documents provider / signature in a style left over from the old API. Keep the comments in sync to avoid stale documentation.


118-140: getEventLogs — same doc mismatch & possible undefined access

Mirror the fixes applied to getMsgLogs:

  1. Update JSDoc to match the parameter.
  2. Guard against null or missing meta.logMessages.
  3. event.data?.message may be undefined; consider JSON-stringifying the whole event or omitting the message when absent to avoid "undefined" strings in test output.
- * Get logs from program's msg! macro obtained from a transaction
- * @param provider The Anchor provider
- * @param signature The transaction signature
+ * Parse Anchor events from a fetched transaction
+ * @param txDetails The versioned transaction object
...
-export const getEventLogs = async (
-  txDetails: anchor.web3.VersionedTransactionResponse
-): Promise<string[] | null> => {
+export const getEventLogs = (
+  txDetails: anchor.web3.VersionedTransactionResponse | null
+): string[] => {
   try {
-    const eventParser = new EventParser(program.programId, new BorshCoder(program.idl));
-    const events = eventParser.parseLogs(txDetails.meta.logMessages);
+    if (!txDetails?.meta?.logMessages) return [];
+    const parser = new EventParser(program.programId, new BorshCoder(program.idl));
+    const events = parser.parseLogs(txDetails.meta.logMessages);
     const eventLogs: string[] = [];
-    for (let event of events) {
-      eventLogs.push(`${event.name}: ${event.data?.message}`);
+    for (const event of events) {
+      eventLogs.push(
+        event.data?.message !== undefined
+          ? `${event.name}: ${event.data.message}`
+          : event.name
+      );
     }
-    return eventLogs || null;
+    return eventLogs;
   } catch (error) {
     console.error("Failed to get transaction logs:", error);
-    return null;
+    return [];
   }
 };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ca16e06 and 44f4641.

📒 Files selected for processing (13)
  • app/src/idl/blockrunners.json (1 hunks)
  • app/src/idl/blockrunners.ts (1 hunks)
  • app/src/lib/utils.ts (0 hunks)
  • programs/blockrunners/src/instructions/join_game.rs (1 hunks)
  • programs/blockrunners/src/instructions/move_reveal.rs (10 hunks)
  • programs/blockrunners/src/instructions/purchase_ciphers.rs (1 hunks)
  • programs/blockrunners/src/utils/give_random_cards.rs (1 hunks)
  • tests/helpers/utils.ts (4 hunks)
  • tests/initialize_game.ts (2 hunks)
  • tests/initialize_player.ts (2 hunks)
  • tests/join_game.ts (2 hunks)
  • tests/move.ts (5 hunks)
  • tests/purchase_ciphers.ts (5 hunks)
💤 Files with no reviewable changes (1)
  • app/src/lib/utils.ts
🚧 Files skipped from review as they are similar to previous changes (10)
  • tests/join_game.ts
  • tests/initialize_game.ts
  • programs/blockrunners/src/utils/give_random_cards.rs
  • tests/move.ts
  • programs/blockrunners/src/instructions/join_game.rs
  • app/src/idl/blockrunners.json
  • tests/initialize_player.ts
  • programs/blockrunners/src/instructions/move_reveal.rs
  • app/src/idl/blockrunners.ts
  • tests/purchase_ciphers.ts
🧰 Additional context used
🧠 Learnings (1)
tests/helpers/utils.ts (1)
Learnt from: jannden
PR: jannden/blockrunners#60
File: app/src/hooks/useProgram.tsx:82-82
Timestamp: 2025-04-22T10:21:47.227Z
Learning: The `@coral-xyz/anchor` library at version ^0.30.1 supports initializing a `Program` instance with just two arguments: `new Program(idl, provider)` although TypeScript may show type errors requiring the `@ts-expect-error` comment.
🧬 Code Graph Analysis (1)
programs/blockrunners/src/instructions/purchase_ciphers.rs (1)
programs/blockrunners/src/utils/save_and_emit_event.rs (1)
  • save_and_emit_event (8-32)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test

@jannden jannden force-pushed the jannden/feats branch 3 times, most recently from 8d2f957 to a0956ed Compare June 17, 2025 06:49
@jannden jannden mentioned this pull request Apr 27, 2025
5 tasks
@jannden jannden merged commit 32fd262 into main Jun 17, 2025
2 checks passed
@jannden jannden deleted the jannden/feats branch June 17, 2025 08:22
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.

Improve log parsing

2 participants