lex-exec 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b2fbeab776f3905427aacc575cfcae9c9e101bb78637b3082f707572709e13f
4
- data.tar.gz: 5c746408c3fb7fc484c8c8da9f54b2319f832aace2e43e78d34d413c60263ce0
3
+ metadata.gz: 7d8694405797d859fb276bf9ffb3fdd2b9ae66ed3f3c1cc35a1b6fb5b43541cd
4
+ data.tar.gz: 2b46aac5a8817673d6ac641d04b4b880c2531f5c79a1b076ef77b83053d1a008
5
5
  SHA512:
6
- metadata.gz: 7ccfc95535ed4c768b5aa50fcfb2d4f8a417f32b0db0d005e9d479cd4e558c9f43e1233273d1cfda8ee6c60d5c1801e2e948610d43d0370ae234c1d61887c681
7
- data.tar.gz: a0193fae4bee505f012cee6ca6e9435d9311b7369ca2751f5781dedfcd1df12953f04d312c03a6fe2524c7eb30cba45cb2036ede4a4ab964e427ec6468270d24
6
+ metadata.gz: 9cd2bd04a54f2c430d9d51cf11b6d356fdcce17664fcddd83d1e2d5a4a63e1f89c2b25aa89855f406ab4b3f69c4b3611d98c47b1ffbf8d6eacce214efeb7b2a5
7
+ data.tar.gz: 4b2fba88d6554fbdf73ab0206f6ada2cf730094d366ee96bfcef61c96240dd0d9e1c5deeda3c4729b99d42a28f0cc14126673a5c001ccda37d1874254137dce6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.7] - 2026-04-09
4
+
5
+ ### Added
6
+ - Python venv integration: route bare `python3`/`pip3` commands to Legion-managed venv (`~/.legionio/python`)
7
+ - `python3`, `python`, `pip3`, `pip` added to sandbox allowlist
8
+ - Runtime venv resolution via `Constants.venv_python`/`.venv_pip`/`.venv_exists?` (no longer frozen at load time)
9
+
3
10
  ## [0.1.6] - 2026-03-30
4
11
 
5
12
  ### Changed
@@ -5,14 +5,24 @@ module Legion
5
5
  module Exec
6
6
  module Helpers
7
7
  module Constants
8
- DEFAULT_TIMEOUT = 120_000 # 120 seconds in ms
9
- MAX_TIMEOUT = 600_000 # 10 minutes in ms
10
- MAX_OUTPUT_BYTES = 1_048_576 # 1 MB
8
+ DEFAULT_TIMEOUT = 120_000 # 120 seconds in ms
9
+ MAX_TIMEOUT = 600_000 # 10 minutes in ms
10
+ MAX_OUTPUT_BYTES = 1_048_576 # 1 MB
11
11
 
12
- ALLOWED_COMMANDS = %w[
12
+ LEGION_PYTHON_VENV = File.expand_path('~/.legionio/python').freeze
13
+
14
+ BASE_ALLOWED_COMMANDS = %w[
13
15
  bundle git gh ruby rspec rubocop ls cat mkdir cp mv rm touch echo wc head tail
16
+ python3 pip3
17
+ ].freeze
18
+
19
+ VENV_ALLOWED_COMMANDS = [
20
+ "#{LEGION_PYTHON_VENV}/bin/python3",
21
+ "#{LEGION_PYTHON_VENV}/bin/pip3"
14
22
  ].freeze
15
23
 
24
+ ALLOWED_COMMANDS = (BASE_ALLOWED_COMMANDS + VENV_ALLOWED_COMMANDS).freeze
25
+
16
26
  BLOCKED_PATTERNS = [
17
27
  %r{rm\s+-rf\s+/},
18
28
  /rm\s+-rf\s+~/,
@@ -25,6 +35,20 @@ module Legion
25
35
  ].freeze
26
36
 
27
37
  AUDIT_FIELDS = %i[command cwd exit_code duration_ms executed_at truncated].freeze
38
+
39
+ module_function
40
+
41
+ def venv_python
42
+ "#{LEGION_PYTHON_VENV}/bin/python3"
43
+ end
44
+
45
+ def venv_pip
46
+ "#{LEGION_PYTHON_VENV}/bin/pip3"
47
+ end
48
+
49
+ def venv_exists?
50
+ File.exist?("#{LEGION_PYTHON_VENV}/pyvenv.cfg")
51
+ end
28
52
  end
29
53
  end
30
54
  end
@@ -14,6 +14,11 @@ module Legion
14
14
  check = default_sandbox.allowed?(command)
15
15
  return { success: false, error: :blocked, reason: check[:reason] } unless check[:allowed]
16
16
 
17
+ # Rewrite bare `python3` / `python` / `pip3` / `pip` invocations to use
18
+ # the Legion-managed venv interpreter so scripts always run inside the
19
+ # correct environment with pre-installed packages (python-pptx, etc.).
20
+ command = rewrite_python_command(command)
21
+
17
22
  start_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
18
23
  timeout_secs = [timeout, Helpers::Constants::MAX_TIMEOUT].min / 1000.0
19
24
 
@@ -59,6 +64,20 @@ module Legion
59
64
 
60
65
  private
61
66
 
67
+ # Replace bare `python3`, `python`, `pip3`, `pip` at the start of a command
68
+ # with the absolute venv paths — but only when the venv actually exists.
69
+ # Full absolute paths that already point into the venv are left unchanged.
70
+ def rewrite_python_command(command)
71
+ return command unless Helpers::Constants.venv_exists? # rubocop:disable Legion/Extension/RunnerReturnHash
72
+
73
+ python = Helpers::Constants.venv_python
74
+ pip = Helpers::Constants.venv_pip
75
+
76
+ command
77
+ .sub(/\Apython3(\s|\z)/, "#{python}\\1")
78
+ .sub(/\Apip3(\s|\z)/, "#{pip}\\1")
79
+ end
80
+
62
81
  def default_sandbox
63
82
  @default_sandbox ||= Helpers::Sandbox.new
64
83
  end
@@ -3,7 +3,7 @@
3
3
  module Legion
4
4
  module Extensions
5
5
  module Exec
6
- VERSION = '0.1.6'
6
+ VERSION = '0.1.7'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lex-exec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esity