Skip to content

Conversation

@therealharshit
Copy link
Member

@therealharshit therealharshit commented Sep 6, 2025

Overview

This PR introduces the Pippy Debugger, bringing LLM-powered debugging support into the Pippy activity. Kids can now send their code for analysis and view helpful debugging suggestion.

Key Features

  • Dedicated Debug Terminal
    A new terminal is added alongside the output terminal to show debugging feedback in a clear, separate space.

  • One-Click Debugging
    A toolbar button with a new debug icon lets users easily run their code and request debugging help.

  • Readable AI Feedback
    Debugging tips are displayed with proper formatting like including headings, lists, and code blocks which makes the suggestions easier to follow.

  • Responsive Experience
    Debugging requests no longer freeze the UI, ensuring a smooth experience while results are being fetched.

  • Cleaner Code Context
    Only the relevant code is sent for debugging (ignoring boilerplate like shebang lines), so feedback is more focused.

UI Previews

  • Updated Pippy UI

Pippy-UI01
  • Debugger's output

Pippy-UI02
Pippy-UI03

ToDO

Added dependencies

  • Uses the standard library threading module for background tasks.
  • Introduces the third-party requests library for making API calls.

Notes for Reviewer

@chimosky as you’ve previously reviewed most of this code, could you please review it again.

Project Reference

This work is part of DMP 2025 (#95).

Introduced a new debug-icon.svg
Integrated the icon into the main toolbar for triggering debug functionality
Added _get_current_code() method to read code from active tab's file
Integrated code extraction into _debug_button_cb to support debugging workflow
Sends POST request to /debug endpoint with code payload
Created separate VTE terminal for displaying debug output
Added color theming for debug terminals
Introduced UI with buttons to toggle between output and debug terminals
Implemented logic to feed LLM-generated debug responses into debug terminal
…background thread

Wrapped blocking `requests.post` call in a separate thread to avoid freezing GTK main loop
Used `GLib.idle_add` to safely update VTE terminal from background thread
Format debug tips by stripping markdown and adjusting newlines
Introduced 'output-terminal.svg' and 'debug-terminal.svg' icons.
Set those icons for btn_output and btn_debug.
Applied custom CSS to style the switch_box.
- Parses headings, lists, code blocks, and inline formatting.
- Converts Markdown to ANSI-colored terminal output.
- Integrated parser output into debug terminal via feed.
- Change text color of debug terminal.
- Implements _debug_terminal_cb to send code to /context endpoint.
- Parses response using markdown_parser and renders in debug terminal.
- Uses threading to avoid blocking UI during network call.
- Added API_URL and X_API_KEY constants for easier configuration
- Updated debug and context requests to use shared API settings
- Improved markdown_parser with better heading and list handling
- Filtered out shebang/coding lines when reading files
- Replaced print statements with VTE output for consistency
pippy_app.py Outdated
def _vte_set_debug_colors(self, bg, fg):
if _has_new_vte_api():
foreground = Gdk.RGBA(); foreground.parse(bg)
background = Gdk.RGBA(); background.parse(fg)
Copy link
Member

Choose a reason for hiding this comment

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

This is changing the style in this code, please stick to the existing style here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Resolved in f63b2d9.

pippy_app.py Outdated

def _reset_debug_vte(self):
self._debug_vte.grab_focus()
self._debug_vte.feed(b'\x1B[H\x1B[J\x1B[0;39m')
Copy link
Member

Choose a reason for hiding this comment

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

A comment here saying why this is here would be great.

Copy link
Member Author

Choose a reason for hiding this comment

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

Resolved in f63b2d9.


line = re.sub(r"\*\*(.*?)\*\*", r"\033[2m\1\033[0m", line)

line = re.sub(r"(?<!\*)\*(?!\*)(.*?)\*(?!\*)", r"\033[2m\1\033[0m", line)
Copy link
Member

Choose a reason for hiding this comment

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

While these regexes are great, a comment for each telling what their target is would be awesome.

Copy link
Member Author

Choose a reason for hiding this comment

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

Resolved in f63b2d9.

@chimosky
Copy link
Member

Reviewed cfeb4c1, not tested.

- Added detailed comments to markdown parser for clarity.
- Reformatted code to match existing style guidelines.
- Updated `_reset_debug_vte` to clear screen consistently.
- Extended inverted color toggle to also update debug terminal colors.
@chimosky
Copy link
Member

chimosky commented Nov 7, 2025

@therealharshit there's still these items to handle;

  • Update the API_URL with sugarAI URL after merging of PR. - The PR has been merged.
  • Handling of API_KEY.

@therealharshit
Copy link
Member Author

@therealharshit there's still these items to handle;

  • Update the API_URL with sugarAI URL after merging of PR. - The PR has been merged.
  • Handling of API_KEY.

@chimosky If I recall correctly, we had discussed making the API key handling more central to Sugar, instead of implementing it separately in each activity.
That’s why I haven’t implemented it yet.
Just wanted to confirm if that’s still the plan before I proceed with any changes.

@chimosky
Copy link
Member

@chimosky If I recall correctly, we had discussed making the API key handling more central to Sugar, instead of implementing it separately in each activity. That’s why I haven’t implemented it yet. Just wanted to confirm if that’s still the plan before I proceed with any changes.

I remember the conversation, I haven't been able to get to it.

I'll see what I can do.

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.

2 participants