Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 30, 2025

Implements Ruby language support in the terminal runtime system, mirroring the existing Python implementation using ruby.wasm.

Changes

New Ruby runtime module (app/terminal/ruby/)

  • runtime.tsx: Context provider implementing RuntimeContext interface with REPL, file execution, and syntax checking
    • Implements interrupt functionality with command history restoration
    • Saves successful commands and replays them after worker restart
  • page.tsx: Demo page with REPL terminal, editor, and file execution components

Web worker implementation

  • public/ruby.worker.js: Web worker loading Ruby 3.3 WASM with stdlib from CDN
    • Loads @ruby/wasm-wasi and @ruby/3.3-wasm-wasi via jsDelivr CDN (not bundled)
    • Captures stdout/stderr via WASI file descriptors
    • Handles code evaluation, file operations, and syntax validation
    • Formats Ruby error messages (filters internal eval frames)
  • public/_headers: Added Cross-Origin headers configuration for Ruby worker to enable WebAssembly execution

Language integration

  • runtime.tsx: Added ruby to RuntimeLang type, integrated RubyProvider into provider tree
  • editor.tsx: Added Ruby mode for Ace editor with syntax highlighting
  • highlight.ts: Added Prism.js Ruby language support for terminal syntax highlighting

Test integration

  • app/terminal/page.tsx: Integrated Ruby runtime into the runtime test page
  • app/terminal/tests.ts: Added comprehensive test cases for Ruby runtime covering:
    • REPL stdout capture, variable preservation, error handling, and interrupt recovery
    • File execution stdout, error handling, and multi-file support

Features

Interrupt Support

The Ruby runtime includes full interrupt functionality that:

  • Tracks command history for all successfully executed commands
  • Terminates the current worker when interrupt is called
  • Reinitializes a fresh Ruby VM
  • Restores the previous state by re-executing all saved commands in order

This allows users to interrupt long-running code while preserving the execution state from previous commands.

Usage

// REPL with IRB-style prompts (>> and ?>)
<ReplTerminal language="ruby" />

// File editor with Ruby syntax
<EditorComponent language="ruby" filename="script.rb" />

// Execute Ruby files
<ExecFile filenames={["script.rb"]} language="ruby" />

Ruby runtime uses same patterns as Python: mutex-based execution, output buffering, virtual filesystem for file I/O.

Note

Ruby WASM packages are loaded from CDN at runtime rather than bundled with the application, reducing bundle size by ~36MB.

Original prompt

app/terminal/ 内に、ruby言語のランタイムAPIを作ってください。pythonのランタイム(app/terminal/python/runtime.tsx)と同様に、ruby.wasm をweb workerで実行する実装にしてください。


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 30, 2025

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
my-code 8b04d28 Commit Preview URL

Branch Preview URL
Oct 31 2025, 07:33 PM

Copilot AI changed the title [WIP] Add Ruby runtime API in app/terminal Add Ruby runtime with ruby.wasm web worker Oct 30, 2025
Copilot AI requested a review from na-trium-144 October 30, 2025 19:21
Copy link
Contributor Author

Copilot AI commented Oct 31, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • workers.cloudflare.com
    • Triggering command: node /home/REDACTED/.npm/_npx/8b377f6eec906bc4/node_modules/.bin/next build (dns block)
    • Triggering command: node /home/REDACTED/work/my-code/my-code/node_modules/.bin/next lint (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copy link
Contributor Author

Copilot AI commented Oct 31, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • workers.cloudflare.com
    • Triggering command: node /home/REDACTED/work/my-code/my-code/node_modules/.bin/next lint (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@na-trium-144
Copy link
Contributor

@copilot mainブランチにRuntimeのテストを実行する機能をpushしました。mainブランチをpullし、app/terminal/page.tsx と app/terminal/tests.ts を編集しrubyのテストが実行されるようにしてください。

@na-trium-144
Copy link
Contributor

@copilot /public/_headers にpyodideと同様にrubyのworkerの記述を追加してください。

Copy link
Contributor Author

Copilot AI commented Oct 31, 2025

@copilot mainブランチにRuntimeのテストを実行する機能をpushしました。mainブランチをpullし、app/terminal/page.tsx と app/terminal/tests.ts を編集しrubyのテストが��...

実装しました (43d5db4)。

変更内容:

  • app/terminal/page.tsx: useRuby() を追加し、runtimeRef に Ruby を含めました
  • app/terminal/tests.ts: 全てのテストケースに Ruby の実装を追加しました
    • REPL のテスト: stdout キャプチャ、変数保持、エラーキャプチャ、interrupt と状態復元
    • ファイル実行のテスト: stdout キャプチャ、エラーキャプチャ、マルチファイル実行

Ruby の構文に合わせてテストコードを作成しています(puts でのコンソール出力、raise でのエラー、require_relative でのファイル読み込みなど)。

Copy link
Contributor Author

Copilot AI commented Oct 31, 2025

@copilot /public/_headers にpyodideと同様にrubyのworkerの記述を追加してください。

追加しました (e0eaed0)。

/public/_headers に Ruby worker 用の Cross-Origin ヘッダー設定を追加しました。Pyodide worker と同じ設定で、WebAssembly の実行に必要な COOP と COEP ヘッダーを設定しています。

@na-trium-144 na-trium-144 deleted the copilot/add-ruby-runtime-api branch November 12, 2025 17:56
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