Skip to content

Conversation

ammar-agent
Copy link
Collaborator

Overview

Implements Phase 1 of pluggable runtime system with minimal Runtime interface that allows tools to execute in different environments (local, docker, ssh). This is a pure refactoring with zero user-facing changes.

Changes

Runtime Abstraction

  • Runtime interface with 5 core methods: exec(), readFile(), writeFile(), stat(), exists()
  • LocalRuntime implementation using Node.js APIs (spawn, fs/promises)
  • RuntimeError class for consistent error handling

Tool Refactoring

  • Refactored file_read.ts to use runtime.readFile() and runtime.stat()
  • Refactored file_edit_replace.ts to use runtime for all file operations
  • Refactored file_edit_insert.ts to use runtime for all file operations
  • Updated fileCommon.ts to work with FileStat interface instead of fs.Stats
  • Note: bash.ts kept unchanged (complex overflow handling)

Integration

  • Updated ToolConfiguration to include runtime: Runtime field
  • Inject LocalRuntime in aiService and ipcMain
  • Updated tsconfig to ES2023 for Disposable type support

Testing

  • All 90 tool tests pass with zero failures
  • Updated tests to inject LocalRuntime
  • Updated error message assertions for RuntimeError format

Architecture Benefits

Easy to test: Runtime implementations are isolated (< 250 lines each), no dependencies between runtimes.

Easy to extend: Adding DockerRuntime or SSHRuntime = implement 5-method interface. Tools automatically work with new runtimes.

Backwards compatible: LocalRuntime is default, no config changes = no behavior changes.

Next Steps

Foundation is now in place for:

  • Phase 2: DockerRuntime implementation
  • Phase 3: SSHRuntime implementation
  • Add runtimeConfig to WorkspaceMetadata
  • UI for configuring runtime per workspace

Testing

✅ 90 pass, 0 fail (274 expect() calls)
✅ Type checking passes
✅ Build succeeds

Generated with cmux

Implements Phase 1 of pluggable runtime system with minimal Runtime interface
that allows tools to execute in different environments (local, docker, ssh).

Changes:
- Add Runtime interface with 5 core methods: exec, readFile, writeFile, stat, exists
- Implement LocalRuntime using Node.js APIs (spawn, fs/promises)
- Refactor file tools (file_read, file_edit_*) to use runtime abstraction
- Update ToolConfiguration to include runtime field
- Inject LocalRuntime in aiService and ipcMain
- Update tsconfig to ES2023 for Disposable type support
- Update all tests to inject LocalRuntime (90 tests pass)

This is a pure refactoring with zero user-facing changes. All existing
functionality remains identical. Sets foundation for Docker and SSH runtimes.

_Generated with `cmux`_
- Add SSHRuntime class implementing Runtime interface
- Add runtime configuration types (local, ssh)
- Add runtime factory to create runtime based on config
- Use native ssh2 SFTP for file operations
- Support SSH key and password authentication
- Connection pooling and automatic reconnection
- Add runtimeConfig to WorkspaceMetadata
- Update AIService to use runtime factory with workspace config
- Update all tests and ipcMain to use runtime factory
- Default to local runtime if no config specified
- Use async fs.readFile instead of sync readFileSync
- Remove async from close() method (no await needed)
- Fix any type usage in runtime factory error message
electron-builder tries to run 'rebuild' for native modules, but ssh2
doesn't have native dependencies that need rebuilding. Add a no-op
script to satisfy electron-builder.
- Create src/constants/env.ts with NON_INTERACTIVE_ENV_VARS
- Update LocalRuntime and bash tool to use shared constant
- Eliminates duplicate environment variable definitions
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.

1 participant