[PR #1400] [MERGED] Surface legacy script custom tools as preserved-only with migration path #5067

Closed
opened 2026-10-22 04:12:56 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1400
Author: @Romuromylus
Created: 5/27/2026
Status: ✅ Merged
Merged: 5/27/2026
Merged by: @Romuromylus

Base: refactor ← Head: fix/refactor-issue-1353-legacy-script-tools


📝 Commits (7)

  • cd39d68 Surface legacy script custom tools as preserved-only with migration path
  • 8a315da Merge branch 'refactor' into fix/refactor-issue-1353-legacy-script-tools
  • e8d7a57 Address PR review: fix ToolEditor hook order and block save while legacy
  • d81f072 Merge branch 'fix/refactor-issue-1353-legacy-script-tools' of https://github.com/Romuromylus/Marinara-Engine into fix/refactor-issue-1353-legacy-script-tools
  • 6624d3f Merge branch 'refactor' into fix/refactor-issue-1353-legacy-script-tools
  • 713f6ad Address CodeRabbit Major: gate Save & close on handleSave success
  • 8e34e01 Merge branch 'fix/refactor-issue-1353-legacy-script-tools' of https://github.com/Romuromylus/Marinara-Engine into fix/refactor-issue-1353-legacy-script-tools

📊 Changes

6 files changed (+233 additions, -17 deletions)

View changed files

📝 src-tauri/src/commands/storage/custom_tools.rs (+88 -0)
📝 src/engine/contracts/schemas/custom-tool.schema.ts (+7 -1)
📝 src/engine/generation/main-tool-loop.test.ts (+33 -0)
📝 src/engine/generation/tools-runtime.ts (+4 -0)
📝 src/features/catalog/agents/components/ToolEditor.tsx (+99 -16)
📝 src/features/catalog/agents/hooks/use-custom-tools.ts (+2 -0)

📄 Description

Why this change

Issue #1353 reports that the refactor cannot run legacy custom tools with executionType: "script" + a stored scriptBody, while the pre-refactor staging codebase did execute them (gated by CUSTOM_TOOL_SCRIPT_ENABLED env var, default off, sandboxed via node:vm). The refactor has no Node vm equivalent in the Tauri runtime, and embedding a JS engine would re-introduce arbitrary-code-execution risk that even staging shipped disabled-by-default.

The real bug today is worse than "cannot run". On a clean read of the code:

  • customToolRecord in src/engine/generation/tools-runtime.ts silently filters script tools out of the LLM-visible tool set, so the AI never sees them.
  • ToolEditor coerces executionType === "script" to "static" on load, omits scriptBody from the save payload, and has no banner — so opening a legacy script tool and pressing Save destroys the scriptBody field with no warning.
  • The Rust executor returns a generic "Unsupported custom tool execution type: script" with no migration guidance.

This PR implements the "migration-aware preserve + clear error" outcome named in the issue's expected behavior. It does not add a sandboxed script execution path.

What changed

  • src/engine/contracts/schemas/custom-tool.schema.ts: extend toolExecutionTypeSchema to webhook | static | script; add nullable scriptBody field so legacy data round-trips intact through any future schema-validating layer. Comment pins intent.
  • src/engine/generation/tools-runtime.ts: add an explanatory comment to the existing static/webhook filter in customToolRecord so future readers do not accidentally re-admit script tools.
  • src/features/catalog/agents/hooks/use-custom-tools.ts: add scriptBody: string | null to CustomToolRow; isCustomToolSelectable already returns false for script tools, now with a comment noting why.
  • src/features/catalog/agents/components/ToolEditor.tsx: expand the local execution-type union to include "script"; load dbTool.scriptBody into local state; render an amber ShieldAlert banner when the loaded tool is a legacy script; show the script body in a read-only textarea; swap the execution-type picker into a "Convert to Static / Convert to Webhook" pair when the user is editing a legacy script tool; preserve scriptBody in the save payload while the tool is still in legacy state and clear it once the user picks a supported execution type.
  • src-tauri/src/commands/storage/custom_tools.rs: replace the generic "Unsupported {other}" branch with an explicit "script" case returning custom_tool_script_unsupported + a message naming the tool and pointing at the webhook migration path. Generic unknown types still fall through to the original error string. Adds two #[tokio::test] cases covering both branches.
  • src/engine/generation/main-tool-loop.test.ts: add a regression test proving a executionType: "script" custom tool with enabled: true never appears in buildMainToolDefinitions().toolDefs.

Verification

  • pnpm check:architecture → green (boundary guard + Rust structure).
  • pnpm check:frontend (tsc -b) → green.
  • pnpm check:docs → green.
  • pnpm test (vitest) → 24 files / 156 tests pass, including the new row in main-tool-loop.test.ts.
  • pnpm check:rust:clippy (-D warnings) → green.
  • cargo test -p marinara-engine → 118/118 pass, including the two new custom_tools::tests cases.
  • End-to-end Playwright spec against the real Tauri shell (WebView2 CDP) drove the full migration flow: seeded a legacy script-tool row via storage_create with executionType: "script" + scriptBody; opened it through the agents panel in the real ToolEditor; asserted the amber legacy banner, the read-only scriptBody textarea with the exact seeded body, and both Convert to ... buttons; clicked Convert to Webhook, filled a URL, saved, then re-read the row via storage_get and confirmed the post-save shape (executionType: "webhook", webhookUrl preserved, scriptBody: null). No fatal pageerrors. Cleanup ran via storage_delete in afterEach.
  • Manually re-read the diff against the in-repo marinara-architecture-guard, marinara-mode-separation, and marinara-bugfix-discipline skills. Schema in engine/contracts, hook in features, Rust in commands/storage. No cross-boundary imports. No mode-flag patches. No catch-and-ignore. Custom tools are mode-agnostic, so mode-separation is not engaged.

The unrelated marinara-assets::tests::rejects_paths_that_escape_root_through_symlinked_directory fails on this Windows host (no SeCreateSymbolicLinkPrivilege); confirmed identical failure on a clean checkout of refactor HEAD without this PR's changes.

Known caveat: legacy profile import already preserves script-tool rows

The Rust storage layer for custom-tools is schemaless, so import_legacy_profile_tables in src-tauri/src/commands/storage/profile/legacy.rs already round-trips script-type rows intact today. This PR does not change the import path. What it adds is the surface that lets the user see the preserved data and migrate it; before this PR, the data was on disk but invisible (and destroyed on next save).

Follow-ups (not in this PR)

  • Optionally have the useCustomToolCapabilities hook drive the banner copy (today the banner is unconditional for script tools — it does not check the capability flag because scriptExecutionEnabled is hard-coded false in custom_tool_capabilities() and there is no realistic future where it becomes true on the refactor desktop runtime).
  • Optionally expose the custom_tool_script_unsupported error structurally to the chat UI so the user sees the same migration hint when the AI tries to call a script tool via name (currently filtered out before reaching the executor; the executor error is only reachable through the direct custom_tool_execute invoke path).

Linked issue

Closes #1353

Summary by CodeRabbit

  • New Features

    • Added support for viewing legacy script-based custom tools with read-only script content display.
    • Introduced conversion interface to help migrate script tools to webhook or static execution modes with clear guidance.
  • Bug Fixes

    • Script-based custom tools are now explicitly rejected during execution with actionable migration instructions.

Review Change Stack


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/1400 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 5/27/2026 **Status:** ✅ Merged **Merged:** 5/27/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `refactor` ← **Head:** `fix/refactor-issue-1353-legacy-script-tools` --- ### 📝 Commits (7) - [`cd39d68`](https://github.com/Pasta-Devs/Marinara-Engine/commit/cd39d68305a1f0787be42256be92d43412ca0c38) Surface legacy script custom tools as preserved-only with migration path - [`8a315da`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8a315da974a1d213cd4672922e3cfec9e22da352) Merge branch 'refactor' into fix/refactor-issue-1353-legacy-script-tools - [`e8d7a57`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e8d7a57a2dc60e42ed2c6a36bbf291e5ca719832) Address PR review: fix ToolEditor hook order and block save while legacy - [`d81f072`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d81f072f5496a97798654ae3506d3faf28ed104f) Merge branch 'fix/refactor-issue-1353-legacy-script-tools' of https://github.com/Romuromylus/Marinara-Engine into fix/refactor-issue-1353-legacy-script-tools - [`6624d3f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6624d3f31955a8305096307ad8160468aa797921) Merge branch 'refactor' into fix/refactor-issue-1353-legacy-script-tools - [`713f6ad`](https://github.com/Pasta-Devs/Marinara-Engine/commit/713f6ad992a13fc91b85f6bc80bb15c48edeb8ad) Address CodeRabbit Major: gate Save & close on handleSave success - [`8e34e01`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8e34e01160b20e02d311970a9b5569ddfada9a2f) Merge branch 'fix/refactor-issue-1353-legacy-script-tools' of https://github.com/Romuromylus/Marinara-Engine into fix/refactor-issue-1353-legacy-script-tools ### 📊 Changes **6 files changed** (+233 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/src/commands/storage/custom_tools.rs` (+88 -0) 📝 `src/engine/contracts/schemas/custom-tool.schema.ts` (+7 -1) 📝 `src/engine/generation/main-tool-loop.test.ts` (+33 -0) 📝 `src/engine/generation/tools-runtime.ts` (+4 -0) 📝 `src/features/catalog/agents/components/ToolEditor.tsx` (+99 -16) 📝 `src/features/catalog/agents/hooks/use-custom-tools.ts` (+2 -0) </details> ### 📄 Description ## Why this change Issue #1353 reports that the refactor cannot run legacy custom tools with `executionType: "script"` + a stored `scriptBody`, while the pre-refactor staging codebase did execute them (gated by `CUSTOM_TOOL_SCRIPT_ENABLED` env var, default off, sandboxed via `node:vm`). The refactor has no Node `vm` equivalent in the Tauri runtime, and embedding a JS engine would re-introduce arbitrary-code-execution risk that even staging shipped disabled-by-default. The real bug today is worse than "cannot run". On a clean read of the code: - `customToolRecord` in `src/engine/generation/tools-runtime.ts` silently filters script tools out of the LLM-visible tool set, so the AI never sees them. - `ToolEditor` coerces `executionType === "script"` to `"static"` on load, omits `scriptBody` from the save payload, and has no banner — so opening a legacy script tool and pressing Save **destroys the `scriptBody` field** with no warning. - The Rust executor returns a generic `"Unsupported custom tool execution type: script"` with no migration guidance. This PR implements the "migration-aware preserve + clear error" outcome named in the issue's expected behavior. It does **not** add a sandboxed script execution path. ## What changed - `src/engine/contracts/schemas/custom-tool.schema.ts`: extend `toolExecutionTypeSchema` to `webhook | static | script`; add nullable `scriptBody` field so legacy data round-trips intact through any future schema-validating layer. Comment pins intent. - `src/engine/generation/tools-runtime.ts`: add an explanatory comment to the existing static/webhook filter in `customToolRecord` so future readers do not accidentally re-admit script tools. - `src/features/catalog/agents/hooks/use-custom-tools.ts`: add `scriptBody: string | null` to `CustomToolRow`; `isCustomToolSelectable` already returns false for script tools, now with a comment noting why. - `src/features/catalog/agents/components/ToolEditor.tsx`: expand the local execution-type union to include `"script"`; load `dbTool.scriptBody` into local state; render an amber `ShieldAlert` banner when the loaded tool is a legacy script; show the script body in a read-only textarea; swap the execution-type picker into a `"Convert to Static / Convert to Webhook"` pair when the user is editing a legacy script tool; preserve `scriptBody` in the save payload while the tool is still in legacy state and clear it once the user picks a supported execution type. - `src-tauri/src/commands/storage/custom_tools.rs`: replace the generic "Unsupported `{other}`" branch with an explicit `"script"` case returning `custom_tool_script_unsupported` + a message naming the tool and pointing at the webhook migration path. Generic unknown types still fall through to the original error string. Adds two `#[tokio::test]` cases covering both branches. - `src/engine/generation/main-tool-loop.test.ts`: add a regression test proving a `executionType: "script"` custom tool with `enabled: true` never appears in `buildMainToolDefinitions().toolDefs`. ## Verification - `pnpm check:architecture` → green (boundary guard + Rust structure). - `pnpm check:frontend` (`tsc -b`) → green. - `pnpm check:docs` → green. - `pnpm test` (vitest) → 24 files / 156 tests pass, including the new row in `main-tool-loop.test.ts`. - `pnpm check:rust:clippy` (`-D warnings`) → green. - `cargo test -p marinara-engine` → 118/118 pass, including the two new `custom_tools::tests` cases. - **End-to-end Playwright spec against the real Tauri shell (WebView2 CDP)** drove the full migration flow: seeded a legacy script-tool row via `storage_create` with `executionType: "script"` + `scriptBody`; opened it through the agents panel in the real ToolEditor; asserted the amber legacy banner, the read-only `scriptBody` textarea with the exact seeded body, and both `Convert to ...` buttons; clicked Convert to Webhook, filled a URL, saved, then re-read the row via `storage_get` and confirmed the post-save shape (`executionType: "webhook"`, `webhookUrl` preserved, `scriptBody: null`). No fatal pageerrors. Cleanup ran via `storage_delete` in `afterEach`. - Manually re-read the diff against the in-repo `marinara-architecture-guard`, `marinara-mode-separation`, and `marinara-bugfix-discipline` skills. Schema in engine/contracts, hook in features, Rust in commands/storage. No cross-boundary imports. No mode-flag patches. No catch-and-ignore. Custom tools are mode-agnostic, so mode-separation is not engaged. The unrelated `marinara-assets::tests::rejects_paths_that_escape_root_through_symlinked_directory` fails on this Windows host (no `SeCreateSymbolicLinkPrivilege`); confirmed identical failure on a clean checkout of `refactor` HEAD without this PR's changes. ## Known caveat: legacy profile import already preserves script-tool rows The Rust storage layer for `custom-tools` is schemaless, so `import_legacy_profile_tables` in `src-tauri/src/commands/storage/profile/legacy.rs` already round-trips script-type rows intact today. This PR does not change the import path. What it adds is the surface that lets the user *see* the preserved data and migrate it; before this PR, the data was on disk but invisible (and destroyed on next save). ## Follow-ups (not in this PR) - Optionally have the `useCustomToolCapabilities` hook drive the banner copy (today the banner is unconditional for script tools — it does not check the capability flag because `scriptExecutionEnabled` is hard-coded `false` in `custom_tool_capabilities()` and there is no realistic future where it becomes true on the refactor desktop runtime). - Optionally expose the `custom_tool_script_unsupported` error structurally to the chat UI so the user sees the same migration hint when the AI tries to call a script tool via name (currently filtered out before reaching the executor; the executor error is only reachable through the direct `custom_tool_execute` invoke path). ## Linked issue Closes #1353 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added support for viewing legacy script-based custom tools with read-only script content display. * Introduced conversion interface to help migrate script tools to webhook or static execution modes with clear guidance. * **Bug Fixes** * Script-based custom tools are now explicitly rejected during execution with actionable migration instructions. <!-- review_stack_entry_start --> [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Pasta-Devs/Marinara-Engine/pull/1400?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:12:56 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#5067
No description provided.