__init__.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import os
  2. from dataclasses import dataclass, field
  3. from opendevin.runtime.plugins.requirement import PluginRequirement
  4. from opendevin.runtime.plugins.swe_agent_commands.parse_commands import (
  5. parse_command_file,
  6. )
  7. def _resolve_to_cur_dir(filename):
  8. return os.path.join(os.path.dirname(os.path.abspath(__file__)), filename)
  9. def check_and_parse_command_file(filepath) -> str:
  10. if filepath is None:
  11. raise FileNotFoundError(f'File not found: {filepath}')
  12. return parse_command_file(filepath)
  13. DEFAULT_SCRIPT_FILEPATHS = [
  14. _resolve_to_cur_dir('defaults.sh'),
  15. _resolve_to_cur_dir('search.sh'),
  16. _resolve_to_cur_dir('edit_linting.sh'),
  17. ]
  18. DEFAULT_DOCUMENTATION = ''.join(
  19. [
  20. check_and_parse_command_file(filepath)
  21. for filepath in DEFAULT_SCRIPT_FILEPATHS
  22. if filepath is not None
  23. ]
  24. )
  25. @dataclass
  26. class SWEAgentCommandsRequirement(PluginRequirement):
  27. name: str = 'swe_agent_commands'
  28. host_src: str = os.path.dirname(os.path.abspath(__file__))
  29. sandbox_dest: str = '/opendevin/plugins/swe_agent_commands'
  30. bash_script_path: str = 'setup_default.sh'
  31. scripts_filepaths: list[str | None] = field(
  32. default_factory=lambda: DEFAULT_SCRIPT_FILEPATHS
  33. )
  34. documentation: str = DEFAULT_DOCUMENTATION
  35. CURSOR_SCRIPT_FILEPATHS = [
  36. _resolve_to_cur_dir('cursors_defaults.sh'),
  37. _resolve_to_cur_dir('cursors_edit_linting.sh'),
  38. _resolve_to_cur_dir('search.sh'),
  39. ]
  40. CURSOR_DOCUMENTATION = ''.join(
  41. [
  42. check_and_parse_command_file(filepath)
  43. for filepath in CURSOR_SCRIPT_FILEPATHS
  44. if filepath is not None
  45. ]
  46. )
  47. @dataclass
  48. class SWEAgentCursorCommandsRequirement(PluginRequirement):
  49. name: str = 'swe_agent_commands'
  50. host_src: str = os.path.dirname(os.path.abspath(__file__))
  51. sandbox_dest: str = '/opendevin/plugins/swe_agent_commands'
  52. bash_script_path: str = 'setup_cursor_mode.sh'
  53. scripts_filepaths: list[str | None] = field(
  54. default_factory=lambda: CURSOR_SCRIPT_FILEPATHS
  55. )
  56. documentation: str = CURSOR_DOCUMENTATION