Skip to content

Conversation

@marc-romu
Copy link
Member

Description

  • Script tools

    • Added script_generate_and_place_on_canvas wrapper tool that calls script_generate and gh_put in a single operation to generate a script component and place it on the canvas, reducing token usage and tool orchestration complexity.
    • Hid script_generate and script_edit from chat (kept available via AIScriptGenerator component) and added explicit script_edit_and_replace_on_canvas wrapper for GUID-based edit-and-replace flows.
    • Updated script generation flow so script_generate no longer exposes a pre-placement instanceGuid; real instance GUIDs now come from script_generate_and_place_on_canvas / script_edit_and_replace_on_canvas via gh_put.
    • Fixed script_generate_and_place_on_canvas to return the actual Grasshopper instanceGuid assigned on placement instead of the in-memory GUID from script_generate.
    • Improved error handling and partial-success reporting when script generation succeeds but gh_put fails.
  • GhJSON / gh_get tools and runtime data

    • Extended gh_get to support optional runtime/volatile data extraction via a new includeRuntimeData parameter.
    • Implemented GhJsonSerializer.ExtractRuntimeData and ExtractParameterVolatileData:
      • Captures counts and path structure for inputs/outputs.
      • Adds per-branch summaries with sample values (limited to a few items) and hasMore markers.
      • Organizes data by component/parameter InstanceGuid for downstream analysis.
    • Added new wrapper tools around gh_get:
      • gh_get_selected_with_data, gh_get_by_guid_with_data, gh_get_errors_with_data for targeted snapshots that include runtime data.
      • gh_get_selected, gh_get_by_guid, gh_get_errors, gh_get_locked, gh_get_hidden, gh_get_visible for more focused structural queries.
    • Updated tool schemas in gh_get.cs (filters, connection depth, includeRuntimeData, guidFilter) and wired them through GhGetToolAsync, including a forceIncludeRuntimeData flag for the *_with_data wrappers.
    • Relaxed GhJSON validation in GHJsonAnalyzer so missing connections is treated as an empty array (no connections) while still erroring when connections exists but is not an array.
  • gh_put tool

    • Enhanced gh_put result to include an instanceGuids array containing the actual InstanceGuids of all placed components.
    • Updated script wrapper tools to use these real instance GUIDs instead of any pre-computed IDs.
  • Chat UI and conversation session

    • Fixed a critical WebChat UI bug where two identical user messages were collapsed into one:
      • WebChatDialog now assigns a unique TurnId to every outgoing user interaction via InteractionUtility.GenerateTurnId(), ensuring dedup keys remain distinct even for identical content.
    • Fixed ConversationSession TurnId consistency:
      • Tool result interactions now always inherit the TurnId from their originating tool calls (no conditional assignment), ensuring correct per-turn metrics aggregation.
      • Error tool results produced via helpers also preserve the original tool call TurnId.
  • Dialogs and UX

    • Improved StyledMessageDialog positioning by centering dialogs on the active Rhino/Eto window’s working area on OnShown, for more predictable and user-friendly placement.
  • Docs and versioning

    • Bumped solution version to 1.2.1-dev.251207 in Solution.props and updated README badges to reflect the new dev version and unstable development status.
    • Documented new and updated tools in DEV.md (script wrappers and gh_get* variants, including *_with_data tools).
    • Updated CHANGELOG.md under [Unreleased] to record:
      • Newly added script and GhJSON tools and runtime datasets.
      • Script placement bug fix and GhJSON validation improvement.
      • Chat UI / conversation session TurnId fixes.
      • Clarification that script_generate no longer exposes a pre-placement instanceGuid.

Breaking Changes

  • None expected for typical workflows.
    • script_generate no longer returns a pre-placement instanceGuid; instance GUIDs should be obtained via script_generate_and_place_on_canvas / script_edit_and_replace_on_canvas (or directly from gh_put), which aligns with the intended usage pattern.
    • GhJSON validation now treats missing connections as valid (empty) instead of an error, which is a relaxation rather than a breaking change.

Testing Done

  • script_generate_and_place_on_canvas:

    • Generate a new script component and confirm it is placed once on the canvas.
    • Verify the returned instanceGuid matches the component actually placed in Grasshopper.
  • script_edit_and_replace_on_canvas:

    • Edit an existing script component by GUID and confirm it is replaced in place, with wiring preserved and a correct instanceGuid.
  • gh_get* tools:

    • Run gh_get_selected_with_data / gh_get_by_guid_with_data / gh_get_errors_with_data on small and moderate definitions and verify:
      • runtimeData includes correct total counts, branch structure, and sample values.
      • No excessive payloads are generated for large trees (samples limited as expected).
  • Dialog UX:

    • Open StyledMessageDialog and confirm dialogs are centered on the active Rhino window.
  • Automated tests:

    • Run full .NET test suite / CI on the branch.
    • Verify no regressions in existing GhJSON tests (serialization, deserialization, validation).

Checklist

  • This PR is focused on a single feature or bug fix
  • Version in Solution.props was updated, if necessary, and follows semantic versioning
  • CHANGELOG.md has been updated
  • PR title follows Conventional Commits format
  • PR description follows Pull Request Description Template

…on workflow

- Updated version in Solution.props and README badges to 1.2.1-dev.251207
- Added `script_generate_and_place_on_canvas` wrapper tool that combines `script_generate` and `gh_put` in a single call to reduce token consumption
- Added `script_edit_and_replace_on_canvas` wrapper tool documentation in DEV.md
- Moved `script_generate` and `script_edit` tools to Hidden category (only wrapper tools visible to chat agents)
…indow

- Override OnShown to center dialog on the screen containing the owner window or Rhino main window
- Use Screen.FromRectangle to detect the target screen from reference window bounds
- Fall back to PrimaryScreen if no reference window is available
- Calculate center position based on screen's WorkingArea to respect taskbar and system UI
…pt_generate_and_place_on_canvas instanceGuid

- Added `gh_get_selected_with_data`, `gh_get_by_guid_with_data`, and `gh_get_errors_with_data` tools that return components with their runtime/volatile data (actual values flowing through outputs)
- Added `includeRuntimeData` parameter to base `gh_get` tool for optional runtime data extraction
- Runtime data includes total item count, branch structure, and sample values for each parameter
…ds from ToolCalls to ToolResults

- Fixed critical bug where identical user messages were collapsed in UI by assigning unique TurnId via `InteractionUtility.GenerateTurnId()` to each user message
- Fixed TurnId inconsistency by unconditionally inheriting TurnId from ToolCall to ToolResult instead of conditional check that was never true due to `AIBodyBuilder.EnsureTurnId()` pre-assignment
- Updated CHANGELOG.md
@marc-romu marc-romu added this to the 1.2.1-alpha milestone Dec 7, 2025
Copilot AI review requested due to automatic review settings December 7, 2025 09:02
@marc-romu marc-romu added scope: AI Tools Issues related to the AI tools component: AI ScriptGenerator Issues related to the AI Script Generator component scope: Conversation Session Issues related to the Conversation Session logic labels Dec 7, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 7, 2025

🏷️ This PR has been automatically assigned to milestone 1.2.1-alpha based on the version in Solution.props.

@marc-romu marc-romu merged commit b15f60d into dev Dec 7, 2025
14 checks passed
@github-actions github-actions bot deleted the bugfix/1.2.1-script-tools-bugs branch December 7, 2025 09:04
Copy link
Contributor

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

This PR enhances SmartHopper's AI tool ecosystem by adding wrapper tools that combine script generation/editing with canvas placement, implementing runtime data extraction for debugging, and fixing critical chat UI deduplication issues.

Key changes:

  • Added script_generate_and_place_on_canvas and enhanced gh_get tools with runtime data support to reduce token usage and improve debugging capabilities
  • Fixed chat UI bug where identical user messages collapsed into one due to missing unique TurnIds
  • Corrected TurnId inheritance for tool results to ensure proper metrics aggregation

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/SmartHopper.Core.Grasshopper/AITools/script_generate.cs Added script_generate_and_place_on_canvas wrapper tool; removed instanceGuid from base tool result; proper GUID extraction from gh_put result
src/SmartHopper.Core.Grasshopper/AITools/gh_get.cs Added includeRuntimeData parameter and new wrapper tools (gh_get_selected_with_data, gh_get_by_guid_with_data, gh_get_errors_with_data) for runtime data inspection
src/SmartHopper.Core.Grasshopper/AITools/gh_put.cs Enhanced result to include instanceGuids array with actual GUIDs of placed components
src/SmartHopper.Core.Grasshopper/Serialization/GhJson/GhJsonSerializer.cs Implemented ExtractRuntimeData and ExtractParameterVolatileData methods to capture component output values, counts, and branch structure with sample limiting
src/SmartHopper.Core/UI/Chat/WebChatDialog.cs Fixed deduplication bug by assigning unique TurnId to each user message via InteractionUtility.GenerateTurnId()
src/SmartHopper.Infrastructure/AICall/Sessions/ConversationSessionHelpers.cs Changed TurnId assignment for tool results from conditional to unconditional to ensure consistency with originating tool calls
src/SmartHopper.Core/Models/Serialization/GHJsonAnalyzer.cs Relaxed validation to treat missing/null connections as valid empty array instead of error
src/SmartHopper.Infrastructure/Dialogs/StyledMessageDialog.cs Added OnShown override to center dialogs on active window's working area for better UX
Solution.props Bumped version to 1.2.1-dev.251207
README.md Updated version badge to 1.2.1-dev.251207 and status to "Unstable Development"
DEV.md Documented new script wrapper tools and gh_get* variants including runtime data tools
CHANGELOG.md Added comprehensive entries for new tools, bug fixes, and breaking changes under [Unreleased]

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

Comment on lines +344 to +345
(int)(center.X - (this.Width / 2)),
(int)(center.Y - (this.Height / 2)));
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

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

Possible loss of precision: any fraction will be lost.

Suggested change
(int)(center.X - (this.Width / 2)),
(int)(center.Y - (this.Height / 2)));
(int)(center.X - (this.Width / 2.0)),
(int)(center.Y - (this.Height / 2.0)));

Copilot uses AI. Check for mistakes.
Comment on lines +344 to +345
(int)(center.X - (this.Width / 2)),
(int)(center.Y - (this.Height / 2)));
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

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

Possible loss of precision: any fraction will be lost.

Suggested change
(int)(center.X - (this.Width / 2)),
(int)(center.Y - (this.Height / 2)));
(int)Math.Round(center.X - (this.Width / 2.0)),
(int)Math.Round(center.Y - (this.Height / 2.0)));

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: AI ScriptGenerator Issues related to the AI Script Generator component scope: AI Tools Issues related to the AI tools scope: Conversation Session Issues related to the Conversation Session logic

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants