workspaces 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 +4 -4
- data/README.md +18 -0
- data/lib/workspaces/cli.rb +31 -6
- data/lib/workspaces/coordinator.rb +15 -4
- data/lib/workspaces/environment_overrides.rb +27 -0
- data/lib/workspaces/registry.rb +6 -1
- data/lib/workspaces/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9d9d7e03d386bd8949baf124281f3ac26eb2b49f7fb109a97a8f0a4fb16263fa
|
|
4
|
+
data.tar.gz: 76ab8e2adfeb5a5daea4526a41d6d33991076000bd4bed0f621df6355511341a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7d5c69e3d6c6201d08b3bd70d100b8adaf1eb53f3aba93ab91ae3656ab67d6350239dff291fa706f67b7350e7296656ddb4f82b57b6fb9aa4469b5d3a45fdbb9
|
|
7
|
+
data.tar.gz: aba50059b56131d6f949f9badc2327fe5a3f4d05e384452299e2e2afc45b7c24be7a93cf7d76a9c2bf5b96d1bb3a71938a3cbe3d74451a28e718430ba1784a20
|
data/README.md
CHANGED
|
@@ -121,6 +121,24 @@ and defining them requires no JavaScript edits. Preset keys must be declared in
|
|
|
121
121
|
`default_editable_env`; recipes reject undeclared keys and secret-like values.
|
|
122
122
|
Hidden environment values are never exposed in the editor or preset choices.
|
|
123
123
|
|
|
124
|
+
Use `create --branch main --preset Demo` to save a preset for a new, still-idle
|
|
125
|
+
workspace. `start ID --preset Demo` applies it before preparing a stopped
|
|
126
|
+
workspace; `restart ID --preset 'Demo off'` switches a running workspace and
|
|
127
|
+
restarts its server. `prepare ID --preset Demo` switches and rebuilds. An
|
|
128
|
+
unknown name is rejected without changing saved settings. Selecting a preset
|
|
129
|
+
replaces the editable settings (including custom editor lines) but preserves
|
|
130
|
+
hidden legacy overrides. A running workspace requires `restart --preset` or
|
|
131
|
+
`prepare --preset`, not `start --preset`.
|
|
132
|
+
|
|
133
|
+
For one-off non-secret tweaks, add repeatable `--set NAME=VALUE` and
|
|
134
|
+
`--unset NAME` flags to `create`, `start`, `prepare`, or `restart`. For example,
|
|
135
|
+
`restart ID --preset Demo --set DEMO_FEATURE=on` applies the preset first,
|
|
136
|
+
then the individual changes, and restarts. Without `--preset`, these flags
|
|
137
|
+
patch current editable settings. Names reserved for the runner and names
|
|
138
|
+
suggesting secrets are rejected; values on the command line may be visible
|
|
139
|
+
in process listings and shell history. Use a secret store, not `--set`, for
|
|
140
|
+
credentials.
|
|
141
|
+
|
|
124
142
|
The front door is not an authentication boundary. Its host and same-origin checks
|
|
125
143
|
protect routing and POST actions, but a publicly reachable instance still needs
|
|
126
144
|
access control such as VPN or SSO. Do not expose workspace backend ports directly.
|
data/lib/workspaces/cli.rb
CHANGED
|
@@ -49,6 +49,28 @@ module Workspaces
|
|
|
49
49
|
options = {}
|
|
50
50
|
OptionParser.new do |parser|
|
|
51
51
|
parse_common_options(parser, options)
|
|
52
|
+
parser.on('--preset NAME') { |value| options[:preset] = value } if %w(create start prepare restart).include?(command)
|
|
53
|
+
if %w(create start prepare restart).include?(command)
|
|
54
|
+
parser.on('--set NAME=VALUE') do |value|
|
|
55
|
+
name, separator, setting = value.partition('=')
|
|
56
|
+
raise OptionParser::InvalidArgument, '--set requires NAME=VALUE' if separator.empty?
|
|
57
|
+
EnvironmentOverrides.validate_name!(name)
|
|
58
|
+
EnvironmentOverrides.validate_value!(setting)
|
|
59
|
+
if name.match?(/(?:SECRET|TOKEN|PASSWORD|API_KEY|PRIVATE_KEY|CREDENTIAL)/i)
|
|
60
|
+
raise OptionParser::InvalidArgument, 'Secret-like names cannot be set on the command line'
|
|
61
|
+
end
|
|
62
|
+
options[:set] ||= {}
|
|
63
|
+
raise OptionParser::InvalidArgument, 'duplicate --set name' if options[:set].key?(name)
|
|
64
|
+
options[:set][name] = setting
|
|
65
|
+
end
|
|
66
|
+
parser.on('--unset NAME') do |value|
|
|
67
|
+
EnvironmentOverrides.validate_name!(value)
|
|
68
|
+
if value.match?(/(?:SECRET|TOKEN|PASSWORD|API_KEY|PRIVATE_KEY|CREDENTIAL)/i)
|
|
69
|
+
raise OptionParser::InvalidArgument, 'Secret-like names cannot be unset on the command line'
|
|
70
|
+
end
|
|
71
|
+
(options[:unset] ||= []) << value
|
|
72
|
+
end
|
|
73
|
+
end
|
|
52
74
|
parse_tls_options(parser, options) if command == 'serve'
|
|
53
75
|
end.parse!(argv)
|
|
54
76
|
options
|
|
@@ -102,7 +124,8 @@ module Workspaces
|
|
|
102
124
|
end
|
|
103
125
|
|
|
104
126
|
def create(_id, options)
|
|
105
|
-
emit(registry.create(**options.slice(:branch, :pr, :new_branch, :from
|
|
127
|
+
emit(registry.create(**options.slice(:branch, :pr, :new_branch, :from, :preset),
|
|
128
|
+
set: options.fetch(:set, {}), unset: options.fetch(:unset, [])).describe, options)
|
|
106
129
|
end
|
|
107
130
|
|
|
108
131
|
def list(_id, options)
|
|
@@ -114,14 +137,16 @@ module Workspaces
|
|
|
114
137
|
end
|
|
115
138
|
|
|
116
139
|
def lifecycle(id, options)
|
|
117
|
-
action = proc { run_lifecycle(options.fetch(:command), id
|
|
140
|
+
action = proc { run_lifecycle(options.fetch(:command), id, preset: options[:preset],
|
|
141
|
+
set: options.fetch(:set, {}), unset: options.fetch(:unset, [])) }
|
|
118
142
|
result = options[:json] ? with_stdout_on_stderr(&action) : action.call
|
|
119
143
|
emit(result, options)
|
|
120
144
|
raise ArgumentError, result['last_error'] if result['status'] == 'error'
|
|
121
145
|
end
|
|
122
146
|
|
|
123
|
-
def run_lifecycle(command, id)
|
|
124
|
-
started = command == 'restart' ? coordinator.restart(id
|
|
147
|
+
def run_lifecycle(command, id, preset: nil, set: {}, unset: [])
|
|
148
|
+
started = command == 'restart' ? coordinator.restart(id, preset: preset, set: set, unset: unset) :
|
|
149
|
+
coordinator.start(id, force: command == 'prepare', preset: preset, set: set, unset: unset)
|
|
125
150
|
if !started && coordinator.snapshot(id)['active']
|
|
126
151
|
raise ArgumentError, 'Workspace is busy; inspect it with show --json'
|
|
127
152
|
end
|
|
@@ -171,8 +196,8 @@ module Workspaces
|
|
|
171
196
|
end
|
|
172
197
|
|
|
173
198
|
def usage
|
|
174
|
-
'Usage: bin/workspaces serve | create (--branch REF | --pr NUMBER | --new-branch NAME [--from REF]) [--json] | ' \
|
|
175
|
-
'list [--pr NUMBER] [--json] | show/start/prepare/restart
|
|
199
|
+
'Usage: bin/workspaces serve | create (--branch REF | --pr NUMBER | --new-branch NAME [--from REF]) [--preset NAME] [--set NAME=VALUE] [--unset NAME] [--json] | ' \
|
|
200
|
+
'list [--pr NUMBER] [--json] | show/start/prepare/restart ID [--preset NAME] [--set NAME=VALUE] [--unset NAME] [--json] | stop ID | ' \
|
|
176
201
|
'exec ID -- COMMAND... | remove ID [--force]'
|
|
177
202
|
end
|
|
178
203
|
|
|
@@ -18,12 +18,12 @@ module Workspaces
|
|
|
18
18
|
@workers_mutex = Mutex.new
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def start(id, force: false)
|
|
22
|
-
launch(id, restart: false, force: force)
|
|
21
|
+
def start(id, force: false, preset: nil, set: {}, unset: [])
|
|
22
|
+
launch(id, restart: false, force: force, prelaunch: settings_update(id, preset, set, unset))
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
def restart(id)
|
|
26
|
-
launch(id, restart: true, force: true)
|
|
25
|
+
def restart(id, preset: nil, set: {}, unset: [])
|
|
26
|
+
launch(id, restart: true, force: true, prelaunch: settings_update(id, preset, set, unset))
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def update_environment(id, set:, remove:)
|
|
@@ -73,6 +73,14 @@ module Workspaces
|
|
|
73
73
|
|
|
74
74
|
private
|
|
75
75
|
|
|
76
|
+
def settings_update(id, preset, set, unset)
|
|
77
|
+
return if !preset && set.empty? && unset.empty?
|
|
78
|
+
|
|
79
|
+
lambda do |_workspace|
|
|
80
|
+
EnvironmentOverrides.new(id).apply_settings(preset: preset, set: set, unset: unset)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
76
84
|
def resolve_status(id, status, busy)
|
|
77
85
|
return busy ? status : 'interrupted' if ACTIVE.include?(status)
|
|
78
86
|
return status if status == 'error'
|
|
@@ -107,6 +115,9 @@ module Workspaces
|
|
|
107
115
|
lock = acquire_lock(id)
|
|
108
116
|
return false unless lock
|
|
109
117
|
|
|
118
|
+
if prelaunch && !restart && !force && Backend.new(id).running?
|
|
119
|
+
raise ArgumentError, 'Workspace is running; use restart --preset to change its environment'
|
|
120
|
+
end
|
|
110
121
|
return false if backend_already_running?(id, force, lock)
|
|
111
122
|
prelaunch&.call(workspace)
|
|
112
123
|
publish_starting(id, restart)
|
|
@@ -75,6 +75,33 @@ module Workspaces
|
|
|
75
75
|
load
|
|
76
76
|
end
|
|
77
77
|
|
|
78
|
+
def apply_preset(name, recipe: Recipe.new)
|
|
79
|
+
apply_settings(preset: name, recipe: recipe)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def self.settings_for(recipe:, preset: nil, set: {}, unset: [], current: nil)
|
|
83
|
+
defaults = recipe.default_editable_env
|
|
84
|
+
preset_values = recipe.environment_presets.fetch(preset) { raise Invalid, "Unknown environment preset: #{preset}" } if preset
|
|
85
|
+
values = preset ? defaults.merge(preset_values) : (current || defaults).dup
|
|
86
|
+
validate_entries!(set)
|
|
87
|
+
unset.each { |name| validate_name!(name) }
|
|
88
|
+
raise Invalid, 'Cannot set and unset the same name' unless (set.keys & unset).empty?
|
|
89
|
+
names = set.keys + unset
|
|
90
|
+
if names.any? { |name| name.match?(/(?:SECRET|TOKEN|PASSWORD|API_KEY|PRIVATE_KEY|CREDENTIAL)/i) }
|
|
91
|
+
raise Invalid, 'Secret-like environment names cannot be stored in the visible editor'
|
|
92
|
+
end
|
|
93
|
+
values.merge!(set)
|
|
94
|
+
unset.each { |name| values.delete(name) }
|
|
95
|
+
validate_entries!(values)
|
|
96
|
+
values
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def apply_settings(preset: nil, set: {}, unset: [], recipe: Recipe.new)
|
|
100
|
+
current = preset ? nil : editable_values(recipe.default_editable_env)
|
|
101
|
+
values = self.class.settings_for(recipe: recipe, preset: preset, set: set, unset: unset, current: current)
|
|
102
|
+
replace_editable(values.sort.map { |key, value| "#{key}=#{value}" }.join("\n"), defaults: recipe.default_editable_env)
|
|
103
|
+
end
|
|
104
|
+
|
|
78
105
|
def apply_patch(set:, remove:)
|
|
79
106
|
validate_patch!(set, remove)
|
|
80
107
|
updated = load_file(file_path).merge(set)
|
data/lib/workspaces/registry.rb
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
require_relative 'worktree'
|
|
2
2
|
require_relative 'state_store'
|
|
3
3
|
require_relative 'backend'
|
|
4
|
+
require_relative 'recipe'
|
|
5
|
+
require_relative 'environment_overrides'
|
|
4
6
|
|
|
5
7
|
module Workspaces
|
|
6
8
|
class Registry
|
|
@@ -17,9 +19,12 @@ module Workspaces
|
|
|
17
19
|
end
|
|
18
20
|
end
|
|
19
21
|
|
|
20
|
-
def create(**options)
|
|
22
|
+
def create(preset: nil, set: {}, unset: [], **options)
|
|
23
|
+
recipe = Recipe.new if preset || !set.empty? || !unset.empty?
|
|
24
|
+
EnvironmentOverrides.settings_for(recipe: recipe, preset: preset, set: set, unset: unset) if recipe
|
|
21
25
|
workspace = Worktree.create(**options)
|
|
22
26
|
StateStore.new(Config.state_file).set(workspace.id, 'status' => 'idle', 'related_pr' => workspace.related_pr)
|
|
27
|
+
EnvironmentOverrides.new(workspace.id).apply_settings(preset: preset, set: set, unset: unset, recipe: recipe) if recipe
|
|
23
28
|
workspace
|
|
24
29
|
end
|
|
25
30
|
|
data/lib/workspaces/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: workspaces
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Workspaces contributors
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rack
|