workspaces 0.1.20 → 0.1.22
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/DESIGN.md +33 -9
- data/README.md +41 -0
- data/lib/workspaces/cli.rb +66 -10
- data/lib/workspaces/config.rb +27 -0
- data/lib/workspaces/coordinator.rb +32 -25
- data/lib/workspaces/dashboard/app.js +60 -8
- data/lib/workspaces/dashboard/arb-palette.css +82 -0
- data/lib/workspaces/dashboard/arb-previews-favicon.svg +11 -0
- data/lib/workspaces/dashboard/card.html.erb +2 -1
- data/lib/workspaces/dashboard/environment.js +2 -2
- data/lib/workspaces/dashboard/styles.css +237 -132
- data/lib/workspaces/dashboard/template.html.erb +2 -2
- data/lib/workspaces/dashboard_view.rb +24 -13
- data/lib/workspaces/front_door.rb +12 -2
- data/lib/workspaces/registry.rb +13 -11
- data/lib/workspaces/version.rb +1 -1
- data/lib/workspaces/workspace_lock.rb +137 -0
- data/lib/workspaces.rb +1 -0
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9b215ed643db37f770915a5da966e4afd5c052ccf8a1bc271ae371f95aed5851
|
|
4
|
+
data.tar.gz: a6c97523fd83b4ccfa72e1d007c60fce8f98e16bcf0ecfcbe6fb7891bc4ae4f0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 54a95866acd2a0b6ec251e06996ff1b366d72d885ac7d87ae4cb2e3c68af2a19f59dc92c435ed61a0aac8278f9e816451cb6c4f7fa866cd0748242d7059f2644
|
|
7
|
+
data.tar.gz: 469c1c9aaed1ff6aabbbe3d515d8b6bd99b0e1e1089f6c7a8f7d90278e37c23a07aea8f0cc067d1b6107fd25f234794c145d358cb56ebcbd6116bba6f5ac06f5
|
data/DESIGN.md
CHANGED
|
@@ -8,17 +8,39 @@ GET is read-only. All creation and lifecycle controls submit same-origin POST fo
|
|
|
8
8
|
|
|
9
9
|
## Visual direction
|
|
10
10
|
|
|
11
|
-
Restrained tooling UI: a
|
|
11
|
+
Restrained tooling UI built on the **Arb design system, Native v1** (`~/code/arb-design-system`, commit `88765ca`): a deep-teal page in the dark theme and limestone in the light one, one slightly lighter card surface with a hairline border and no shadow, a compact spacing rhythm, clear status affordances, and no decorative animation. Every text pairing is at least 4.5:1 against its surface, and `spec/workspaces/arb_design_system_spec.rb` measures each one in both themes.
|
|
12
|
+
|
|
13
|
+
Only colour changed in this migration. Type, spacing, radii and motion timing are the ones the dashboard already had, because the Arb kit defines none of them. No state, label, handler, route or permission changed.
|
|
12
14
|
|
|
13
15
|
## Tokens used
|
|
14
16
|
|
|
15
17
|
### Color
|
|
16
18
|
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
`dashboard/arb-palette.css` is the kit's `tokens/palette.css` copied unchanged (a two-line note on top says where from). It defines 28 `--arb-*` tokens per theme, selected by `data-theme` on `<html>`. **The theme follows the visitor's operating-system setting, with dark as the default**; a one-line script in the `<head>` sets it before anything paints, and a page without script stays dark. There is no theme switch, because the kit says to follow the host's existing behaviour and the dashboard had none.
|
|
20
|
+
|
|
21
|
+
`styles.css` names no colour of its own, which a spec enforces (no hex, `rgb`, `hsl`, `color-mix` or faded opacity). Its `:root` maps a short list of roles onto the palette, and everything below uses the roles or `--arb-*` directly:
|
|
22
|
+
|
|
23
|
+
| Role in `styles.css` | Arb token | Used for |
|
|
24
|
+
|---|---|---|
|
|
25
|
+
| `--bg` | `bg` | the page |
|
|
26
|
+
| `--bg-elevated` | `surface` | panels, the card, inputs, log blocks |
|
|
27
|
+
| `--arb-elevated` | `elevated` | the progress track, neutral pill fill |
|
|
28
|
+
| `--text`, `--muted` | `text`, `muted` | body and supporting text (the old strong, cell and placeholder greys are gone: one text colour, one muted) |
|
|
29
|
+
| `--border` | `border` | every edge and divider, including control edges, so controls now meet 3:1 (the old control edge was about 2:1) |
|
|
30
|
+
| `--accent`, `--accent-hover`, `--accent-pressed`, `--on-accent` | `accent`, `action_hover`, `action_pressed`, `on_accent` | primary buttons and links |
|
|
31
|
+
| `--focus` | `focus` | the focus ring |
|
|
32
|
+
| `--danger` / `--arb-error*`, `--arb-on-error` | `error`, `error_hover`, `error_pressed`, `on_error` | Delete, the setup error callout, the danger zone, failed steps |
|
|
33
|
+
| `--warning`, `--success` | `warning`, `success` | slow-progress fill, vault note, completed step icon |
|
|
34
|
+
| `--arb-selected-bg`, `--arb-selected-border` | `selected_bg`, `selected_border` | the chosen preset, the preset badge, the log tab you are on |
|
|
35
|
+
| `--arb-surface-hover`, `--arb-surface-pressed` | `surface_hover`, `surface_pressed` | hover and pressed on subtle buttons, rows, tabs |
|
|
36
|
+
| `--arb-disabled-*` | `disabled_bg`, `disabled_fg`, `disabled_border` | disabled buttons and fields, at full opacity |
|
|
37
|
+
|
|
38
|
+
- **Focus** is a 2px `focus` ring with a 2px gap, as the kit specifies. The gap is the outline's own offset, which is transparent and so shows the surface actually behind the control.
|
|
39
|
+
- **Selected** is never colour alone: the chosen preset and the current log tab carry a check mark, because the light theme's selected and pressed fills are the same colour.
|
|
40
|
+
- **Disabled** controls use the disabled tokens at full opacity, not a faded copy of the enabled style.
|
|
41
|
+
- **Status pills** pair a glyph with the word the server already sends: ready is a check on `success_bg`, error a cross on `error_bg`, interrupted an exclamation mark on `warning_bg` (a run that was cut off, not one that failed), preparing a ringed dot in `accent`. Idle, stopped and sleeping have no palette role of their own, so they are told apart by glyph and word (empty ring, filled square, half ring) in `steel` on a neutral fill. The earlier design gave each its own hue; the palette has no roles to carry that, and the guide forbids inventing near-matches.
|
|
42
|
+
- **Motion**: the dots that pulsed forever (next to the current step, and on a busy pill) are gone, because a pulse that never stops says "working" whether or not anything is. The bar, the step name and its number carry progress. The step status icon no longer pulses either.
|
|
43
|
+
- **Forced colors**: shapes that carry meaning get a real border so they survive the system palette.
|
|
22
44
|
|
|
23
45
|
### Radius and depth
|
|
24
46
|
|
|
@@ -39,7 +61,7 @@ Restrained tooling UI: a near-black page, one slightly lighter card surface with
|
|
|
39
61
|
|
|
40
62
|
- **Creation form**: four labelled fields in one wrapping row (`flex: 1 1 220px`, 16px gap), each with a real `<label for>`, then a `type="submit"` button on its own line.
|
|
41
63
|
- **Workspace inventory**: a centered column up to 1180px. Rows are ordered by last startup, newest first; workspaces that never started (or whose start time cannot be read) come last, and ties fall back to the id so the list never shuffles between loads. Moments are compared as moments, not text. The page header carries "N managed worktrees · none running" (or "· K running"), counted from the data. The table sits in an `overflow-x: auto` wrapper with `min-width: 820px`, so a phone scrolls it sideways instead of cramming or hiding columns. Rows have 16px padding; workspace names are monospaced links with no underline until hover. Times read "Oct 27, 10:48", are UTC (the headers say so) and keep the full ISO value in a `title`. A missing start reads "Never" and a missing creation time "Unavailable", in the muted colour.
|
|
42
|
-
- **Status pill**: a
|
|
64
|
+
- **Status pill**: a glyph and one word (13px, 600, fully rounded), never colour alone. A busy workspace adds "(busy)" to the word; nothing pulses.
|
|
43
65
|
- **Setup progress**: names and ordered states come from repository run steps; failures are highlighted. Restart shows the background launch and later readiness commands.
|
|
44
66
|
- **Actions by state**: idle/stopped offers Start; active operations show progress without lifecycle buttons; failure offers Retry; ready offers Open workspace plus rebuild/restart/stop.
|
|
45
67
|
- **PR source update**: a secondary Update from PR form only for PR-sourced workspaces; it fetches the latest PR head, fast-forwards the checkout, and preserves local edits without rebuilding or restarting. A persistent result message explains when rebuild is needed or when a retained stash needs manual recovery.
|
|
@@ -79,12 +101,14 @@ Restrained tooling UI: a near-black page, one slightly lighter card surface with
|
|
|
79
101
|
- **Editable environment**: labelled monospace multiline `NAME=value` control for non-secret recipe defaults and added workspace settings; busy state disables the fieldset and save button, values are escaped in HTML, other legacy overrides remain hidden. Omitted default names revert to recipe defaults; omitted added names are unset.
|
|
80
102
|
- **Environment presets (JS-enhanced)**: optional preset selector is hidden by default and revealed only when JavaScript is active and presets exist. Selecting a preset replaces the entire draft editor content and announces unsaved state without submitting. Draft edits remain local until Save & restart.
|
|
81
103
|
- **Danger Zone**: isolated section on the detail page with explicit loss-of-uncommitted-and-untracked-work copy, an exact-workspace-ID confirmation field, and a destructive action. Deletion remains possible without JavaScript, is disabled while setup is busy, and never appears as a list-row action.
|
|
82
|
-
- **Workspace favicon**:
|
|
104
|
+
- **Workspace favicon**: the Arb Previews icon (`dashboard/arb-previews-favicon.svg`, copied unchanged from the design system's `arb-previews/favicon.svg`), served by the dashboard host for local and hosted origins alike. The earlier blue-for-localhost, gold-for-hosted tab signal is gone: the icon is one mark and is not recoloured.
|
|
83
105
|
|
|
84
106
|
## Accessibility constraints
|
|
85
107
|
|
|
86
108
|
- Semantic sections/headings for all regions
|
|
87
|
-
- Focus-visible outlines on actionable controls
|
|
109
|
+
- Focus-visible outlines on actionable controls: a 2px ring with a 2px gap, in the palette's focus colour
|
|
110
|
+
- Selected controls carry a check mark as well as a fill; statuses carry a glyph as well as a colour
|
|
111
|
+
- Forced-colors and reduced-motion are handled
|
|
88
112
|
- `aria-live` limited to phase-change and connection warnings (not full log stream)
|
|
89
113
|
- No-JS refresh path always available
|
|
90
114
|
|
data/README.md
CHANGED
|
@@ -75,6 +75,47 @@ A few things worth knowing:
|
|
|
75
75
|
`workspaces exec <id> -- git lfs pull --include='path/**'`.
|
|
76
76
|
- Workspaces created before this behavior keep their real files; nothing is converted.
|
|
77
77
|
|
|
78
|
+
### Running a command in a workspace
|
|
79
|
+
|
|
80
|
+
`workspaces exec <id> [--timeout SECONDS] -- COMMAND [ARGUMENTS...]` runs a command in the
|
|
81
|
+
workspace's directory with the workspace's environment, and exits with the command's own status.
|
|
82
|
+
|
|
83
|
+
- It holds the workspace's lock while it runs, so a restart, stop or removal is refused until it
|
|
84
|
+
finishes. That is what stops a command racing a rebuild.
|
|
85
|
+
- A command is stopped after **15 minutes** by default, along with everything it started, and
|
|
86
|
+
`exec` exits 124 (what `timeout(1)` uses). Change it with `--timeout SECONDS` or
|
|
87
|
+
`WORKSPACES_EXEC_TIMEOUT_SECONDS`; `0` means no limit. An explicit `--timeout` wins.
|
|
88
|
+
- Anyone refused while it runs is told what holds the lock, for example
|
|
89
|
+
`Workspace is busy: running a command (bin/rails), pid 1365484, for 28m 5s. It will be stopped
|
|
90
|
+
automatically after 15m 0s`. Only the executable is recorded, never its arguments, because
|
|
91
|
+
those can carry secrets.
|
|
92
|
+
- The lock is released by the operating system when its holder exits for any reason, including
|
|
93
|
+
being killed, so a dead command cannot leave a workspace stuck.
|
|
94
|
+
- The preview keeps being served while a command runs, because `exec` leaves the server alone. A
|
|
95
|
+
restart, rebuild, PR update or removal holding the lock still takes the preview offline, since
|
|
96
|
+
those replace the server or its files.
|
|
97
|
+
|
|
98
|
+
### Log tails
|
|
99
|
+
|
|
100
|
+
The dashboard shows the end of each log, not all of it. Normally that is the last 6 KB or 80
|
|
101
|
+
lines of a step's output, and 8 KB or 100 lines of the setup and web server logs, which keeps
|
|
102
|
+
every poll small.
|
|
103
|
+
|
|
104
|
+
When something has failed (a step failed, or a run was interrupted) the page gets far more of
|
|
105
|
+
what matters: the failed step's output, and the setup and server logs, are sent as the last
|
|
106
|
+
**128 KB or 2000 lines**. That is enough for the error and the backtrace after it, which the
|
|
107
|
+
everyday tail would cut off. Steps that did not fail keep the small tail, and a step that is
|
|
108
|
+
merely running does too. The full files stay on disk under the workspaces home (`logs/`), and
|
|
109
|
+
every tail is secret-scrubbed first.
|
|
110
|
+
|
|
111
|
+
### Copying from a log
|
|
112
|
+
|
|
113
|
+
The page refreshes itself, and replacing a log's text drops any selection inside it. So it never
|
|
114
|
+
rewrites a log whose text has not changed, and while part of a log (a step's output, the full
|
|
115
|
+
setup log, the web server log or the error panel) is selected, its new text waits and is applied
|
|
116
|
+
once, when the selection ends. Only the log being read waits; everything else keeps updating. A
|
|
117
|
+
step that finishes while you have text selected in it stays open until you let go.
|
|
118
|
+
|
|
78
119
|
### Step timings
|
|
79
120
|
|
|
80
121
|
Per-step durations are persisted in seconds in workspace step status JSON, so they
|
data/lib/workspaces/cli.rb
CHANGED
|
@@ -225,19 +225,75 @@ module Workspaces
|
|
|
225
225
|
raise ArgumentError, "Could not remove: #{result['problems'].join('; ')}" unless result['problems'].empty?
|
|
226
226
|
end
|
|
227
227
|
|
|
228
|
+
EXEC_USAGE = 'Usage: workspaces exec ID [--timeout SECONDS] -- COMMAND [ARGUMENTS...]'.freeze
|
|
229
|
+
# What `timeout(1)` exits with, so scripts that already handle that keep working.
|
|
230
|
+
EXEC_TIMED_OUT = 124
|
|
231
|
+
|
|
228
232
|
def execute(argv)
|
|
229
233
|
id = argv.shift
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
234
|
+
timeout = nil
|
|
235
|
+
while argv.first && argv.first != '--'
|
|
236
|
+
flag = argv.shift
|
|
237
|
+
raise ArgumentError, EXEC_USAGE unless flag == '--timeout' && !argv.empty?
|
|
238
|
+
|
|
239
|
+
timeout = argv.shift
|
|
240
|
+
end
|
|
241
|
+
raise ArgumentError, EXEC_USAGE unless argv.shift == '--' && !argv.empty?
|
|
242
|
+
|
|
243
|
+
limit = Config.exec_timeout_seconds(timeout)
|
|
244
|
+
# Only the executable goes in the record: arguments can carry secrets, and the record is readable
|
|
245
|
+
# by anyone who can read the lock directory.
|
|
246
|
+
registry.with_lock(id, operation: 'exec', detail: File.basename(argv.first)) do |workspace, lock|
|
|
247
|
+
run_exec(workspace, argv, limit, lock)
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
# Runs the command in its own process group so the limit, or a cancel, can stop it and everything it
|
|
252
|
+
# started, then reports what `timeout(1)` would.
|
|
253
|
+
def run_exec(workspace, argv, limit, lock)
|
|
254
|
+
child_env = ChildEnv.for_workspace(workspace_path: workspace.path)
|
|
255
|
+
pid = Process.spawn(child_env, [argv.first, argv.first], *argv.drop(1),
|
|
256
|
+
chdir: workspace.path.to_s, unsetenv_others: true, pgroup: true)
|
|
257
|
+
lock.update('child_pid' => pid, 'process_group' => pid, 'timeout_seconds' => limit)
|
|
258
|
+
status = wait_for_exec(pid, limit)
|
|
259
|
+
return status.exitstatus || (128 + status.termsig) if status
|
|
260
|
+
|
|
261
|
+
warn "workspaces exec: #{File.basename(argv.first)} timed out after #{DurationFormat.call(limit)} and was stopped"
|
|
262
|
+
EXEC_TIMED_OUT
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
# The exit status, or nil when the limit ran out first and the process group was stopped.
|
|
266
|
+
def wait_for_exec(pid, limit)
|
|
267
|
+
deadline = limit && (Process.clock_gettime(Process::CLOCK_MONOTONIC) + limit)
|
|
268
|
+
loop do
|
|
269
|
+
reaped, status = Process.wait2(pid, Process::WNOHANG)
|
|
270
|
+
return status if reaped
|
|
271
|
+
|
|
272
|
+
if deadline && Process.clock_gettime(Process::CLOCK_MONOTONIC) >= deadline
|
|
273
|
+
stop_group(pid)
|
|
274
|
+
return nil
|
|
275
|
+
end
|
|
276
|
+
sleep 0.05
|
|
233
277
|
end
|
|
278
|
+
end
|
|
234
279
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
280
|
+
# TERM first so a command can clean up, KILL for anything still there after a few seconds.
|
|
281
|
+
def stop_group(pid)
|
|
282
|
+
Process.kill('TERM', -pid)
|
|
283
|
+
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + 5
|
|
284
|
+
until Process.wait2(pid, Process::WNOHANG)
|
|
285
|
+
break if Process.clock_gettime(Process::CLOCK_MONOTONIC) >= deadline
|
|
286
|
+
|
|
287
|
+
sleep 0.05
|
|
288
|
+
end
|
|
289
|
+
Process.kill('KILL', -pid)
|
|
290
|
+
rescue Errno::ESRCH, Errno::ECHILD
|
|
291
|
+
nil
|
|
292
|
+
ensure
|
|
293
|
+
begin
|
|
294
|
+
Process.wait2(pid)
|
|
295
|
+
rescue Errno::ECHILD
|
|
296
|
+
nil
|
|
241
297
|
end
|
|
242
298
|
end
|
|
243
299
|
|
|
@@ -257,7 +313,7 @@ module Workspaces
|
|
|
257
313
|
'Usage: bin/workspaces serve [--require FILE] | create (--branch REF | --pr NUMBER | --new-branch NAME [--from REF]) [--preset NAME] [--set NAME=VALUE] [--unset NAME] [--json] | ' \
|
|
258
314
|
'list [--pr NUMBER] [--json] | show/start/prepare/restart ID [--preset NAME] [--set NAME=VALUE] [--unset NAME] [--json] | ' \
|
|
259
315
|
'resume ID [--from STEP | --only STEP] [--json] | stop ID | keep-awake ID [--off] | ' \
|
|
260
|
-
'exec ID -- COMMAND... | remove ID [--force] | purge-secrets [--dry-run]'
|
|
316
|
+
'exec ID [--timeout SECONDS] -- COMMAND... | remove ID [--force] | purge-secrets [--dry-run]'
|
|
261
317
|
end
|
|
262
318
|
|
|
263
319
|
def help(*)
|
data/lib/workspaces/config.rb
CHANGED
|
@@ -13,6 +13,13 @@ module Workspaces
|
|
|
13
13
|
# Each step shows its own tail, so the per-step bounds are smaller than the combined log's.
|
|
14
14
|
STEP_LOG_BYTES = 6 * 1024
|
|
15
15
|
STEP_LOG_LINES = 80
|
|
16
|
+
# What the page gets once something has failed. The error is at the end of the output, but a failing
|
|
17
|
+
# command prints a backtrace of a hundred lines or more after it, and bundler, yarn and rails print
|
|
18
|
+
# their progress before it, so the everyday tail cuts the message off. Only the step that failed (and
|
|
19
|
+
# the setup and server logs of a workspace that failed) get this; everything else stays small, because
|
|
20
|
+
# every poll sends these.
|
|
21
|
+
FAILURE_LOG_BYTES = 128 * 1024
|
|
22
|
+
FAILURE_LOG_LINES = 2000
|
|
16
23
|
DEFAULT_HOME = File.expand_path('~/.workspaces')
|
|
17
24
|
DEFAULT_SUBDOMAIN_PREFIX = 'ws-'
|
|
18
25
|
DEFAULT_FRONT_DOOR_PORT = 4747
|
|
@@ -20,6 +27,7 @@ module Workspaces
|
|
|
20
27
|
DEFAULT_SLEEP_AFTER_MINUTES = 30
|
|
21
28
|
DEFAULT_WAKE_TIMEOUT_SECONDS = 90
|
|
22
29
|
DEFAULT_SLEEP_SWEEP_SECONDS = 30
|
|
30
|
+
DEFAULT_EXEC_TIMEOUT_SECONDS = 900
|
|
23
31
|
|
|
24
32
|
# Seconds a ready workspace may go without preview traffic before it is put to sleep, or nil when
|
|
25
33
|
# sleeping is switched off (WORKSPACES_SLEEP_AFTER_MINUTES=0). Fractions of a minute are allowed.
|
|
@@ -28,6 +36,19 @@ module Workspaces
|
|
|
28
36
|
minutes.zero? ? nil : minutes * 60
|
|
29
37
|
end
|
|
30
38
|
|
|
39
|
+
# How long `workspaces exec` lets a command run before stopping it, or nil for no limit. An explicit
|
|
40
|
+
# value (the --timeout option) wins over WORKSPACES_EXEC_TIMEOUT_SECONDS, which wins over the default.
|
|
41
|
+
# Zero means no limit.
|
|
42
|
+
def self.exec_timeout_seconds(explicit)
|
|
43
|
+
value = explicit.nil? ? ENV.fetch('WORKSPACES_EXEC_TIMEOUT_SECONDS', DEFAULT_EXEC_TIMEOUT_SECONDS.to_s) : explicit
|
|
44
|
+
seconds = Float(value)
|
|
45
|
+
raise ArgumentError, 'The exec timeout must be a non-negative number of seconds' unless seconds.finite? && seconds >= 0
|
|
46
|
+
|
|
47
|
+
seconds.zero? ? nil : (seconds % 1).zero? ? seconds.to_i : seconds
|
|
48
|
+
rescue ArgumentError, TypeError
|
|
49
|
+
raise ArgumentError, 'The exec timeout must be a non-negative number of seconds'
|
|
50
|
+
end
|
|
51
|
+
|
|
31
52
|
# How long the first request to a sleeping preview waits for the server to be ready.
|
|
32
53
|
def self.wake_timeout_seconds
|
|
33
54
|
positive_number('WORKSPACES_WAKE_TIMEOUT_SECONDS', DEFAULT_WAKE_TIMEOUT_SECONDS)
|
|
@@ -130,6 +151,12 @@ module Workspaces
|
|
|
130
151
|
"#{public_origin}/workspaces/#{validate_id!(id)}"
|
|
131
152
|
end
|
|
132
153
|
|
|
154
|
+
# The list of every workspace. A card on a preview host is a different origin from the dashboard, so it
|
|
155
|
+
# needs the whole URL; a card on the dashboard host can use the path.
|
|
156
|
+
def self.index_url
|
|
157
|
+
"#{public_origin}/workspaces"
|
|
158
|
+
end
|
|
159
|
+
|
|
133
160
|
def self.settings_url(id)
|
|
134
161
|
"#{dashboard_url(id)}/settings"
|
|
135
162
|
end
|
|
@@ -42,7 +42,7 @@ module Workspaces
|
|
|
42
42
|
# message) when the request cannot be honoured.
|
|
43
43
|
def rerun(id, mode: :retry, key: nil)
|
|
44
44
|
workspace = @registry.find(id)
|
|
45
|
-
lock = acquire_lock(id)
|
|
45
|
+
lock = acquire_lock(id, 'resume')
|
|
46
46
|
return false unless lock
|
|
47
47
|
|
|
48
48
|
plan = rerun_plan(id, mode, key)
|
|
@@ -96,7 +96,7 @@ module Workspaces
|
|
|
96
96
|
# the workspace is busy, is kept awake, is not running, or is already asleep.
|
|
97
97
|
def sleep!(id)
|
|
98
98
|
@registry.find(id)
|
|
99
|
-
lock = acquire_lock(id)
|
|
99
|
+
lock = acquire_lock(id, 'sleep')
|
|
100
100
|
return false unless lock
|
|
101
101
|
|
|
102
102
|
begin
|
|
@@ -122,7 +122,7 @@ module Workspaces
|
|
|
122
122
|
# the one holding the workspace lock gets past the check.
|
|
123
123
|
def wake(id)
|
|
124
124
|
workspace = @registry.find(id)
|
|
125
|
-
lock = acquire_lock(id)
|
|
125
|
+
lock = acquire_lock(id, 'wake')
|
|
126
126
|
return false unless lock
|
|
127
127
|
|
|
128
128
|
entry = @state.get(id) || {}
|
|
@@ -142,7 +142,7 @@ module Workspaces
|
|
|
142
142
|
|
|
143
143
|
# Stops the server by hand. A workspace stopped this way is not asleep, so traffic never wakes it.
|
|
144
144
|
def stop(id)
|
|
145
|
-
@registry.with_lock(id) do
|
|
145
|
+
@registry.with_lock(id, operation: 'stop') do
|
|
146
146
|
Backend.new(id).stop!
|
|
147
147
|
@state.set(id, 'status' => 'stopped', 'message' => 'Server stopped', 'sleep_state' => nil, 'slept_at' => nil)
|
|
148
148
|
end
|
|
@@ -249,7 +249,7 @@ module Workspaces
|
|
|
249
249
|
end
|
|
250
250
|
|
|
251
251
|
def finish_interrupted_sleep(id)
|
|
252
|
-
lock = acquire_lock(id)
|
|
252
|
+
lock = acquire_lock(id, 'sleep')
|
|
253
253
|
return unless lock
|
|
254
254
|
|
|
255
255
|
begin
|
|
@@ -262,6 +262,7 @@ module Workspaces
|
|
|
262
262
|
def snapshot_fields(id, entry, busy, status, log, include_log)
|
|
263
263
|
{
|
|
264
264
|
'workspace_id' => id, 'status' => status, 'active' => busy,
|
|
265
|
+
'lock_operation' => busy ? WorkspaceLock.holder(id)&.fetch('operation', nil) : nil,
|
|
265
266
|
'sleeping' => status == 'sleeping', 'slept_at' => entry['slept_at'],
|
|
266
267
|
'keep_awake' => !!entry['keep_awake'], 'sleep_after_seconds' => Config.sleep_after_seconds,
|
|
267
268
|
'message' => status == entry['status'] ? entry['message'] : status.capitalize,
|
|
@@ -273,9 +274,10 @@ module Workspaces
|
|
|
273
274
|
'steps' => entry.fetch('steps', []), 'total_seconds' => entry['total_seconds'],
|
|
274
275
|
'resume' => resume_info(id, entry),
|
|
275
276
|
'estimates' => entry.fetch('estimates', {}),
|
|
276
|
-
'step_logs' => include_log && log == 'setup' ? step_logs(id, entry.fetch('steps', [])) : {},
|
|
277
|
+
'step_logs' => include_log && log == 'setup' ? step_logs(id, entry.fetch('steps', []), status) : {},
|
|
277
278
|
'backend_log_available' => backend_log_available?(id),
|
|
278
|
-
'log_tail' => include_log ? log_tail(id, log) : '', 'log_source' => log,
|
|
279
|
+
'log_tail' => include_log ? log_tail(id, log, failed: failed_status?(status)) : '', 'log_source' => log,
|
|
280
|
+
'port' => entry['port'],
|
|
279
281
|
'environment_keys' => environment_keys(id),
|
|
280
282
|
'editable_environment' => editable_environment(id),
|
|
281
283
|
'secret_names' => secret_names(id),
|
|
@@ -290,7 +292,7 @@ module Workspaces
|
|
|
290
292
|
|
|
291
293
|
def launch(id, restart:, force:, prelaunch: nil)
|
|
292
294
|
workspace = @registry.find(id)
|
|
293
|
-
lock = acquire_lock(id)
|
|
295
|
+
lock = acquire_lock(id, restart ? 'restart' : 'prepare')
|
|
294
296
|
return false unless lock
|
|
295
297
|
|
|
296
298
|
if prelaunch && !restart && !force && Backend.new(id).running?
|
|
@@ -335,12 +337,8 @@ module Workspaces
|
|
|
335
337
|
'prepare_started_at' => now, 'completed_at' => nil, 'last_error' => nil, 'total_seconds' => nil)
|
|
336
338
|
end
|
|
337
339
|
|
|
338
|
-
def acquire_lock(id)
|
|
339
|
-
|
|
340
|
-
# The worker owns this duplicate; closing the request's descriptor must not release its lock.
|
|
341
|
-
File.open(Config.prepare_lock_path(id), File::RDWR | File::CREAT, 0o600) do |file|
|
|
342
|
-
file.dup if file.flock(File::LOCK_EX | File::LOCK_NB)
|
|
343
|
-
end
|
|
340
|
+
def acquire_lock(id, operation)
|
|
341
|
+
WorkspaceLock.acquire(id, operation: operation)
|
|
344
342
|
end
|
|
345
343
|
|
|
346
344
|
def publish_starting(id, restart, extra: {})
|
|
@@ -434,36 +432,45 @@ module Workspaces
|
|
|
434
432
|
end
|
|
435
433
|
|
|
436
434
|
def locked?(id)
|
|
437
|
-
|
|
438
|
-
|
|
435
|
+
WorkspaceLock.held?(id)
|
|
436
|
+
end
|
|
439
437
|
|
|
440
|
-
|
|
438
|
+
# Something went wrong, so the logs are worth reading in full: the larger tail is for these states.
|
|
439
|
+
def failed_status?(status)
|
|
440
|
+
%w(error interrupted).include?(status)
|
|
441
441
|
end
|
|
442
442
|
|
|
443
|
-
def log_tail(id, log)
|
|
443
|
+
def log_tail(id, log, failed: false)
|
|
444
444
|
path = log == 'backend' ? Config.backend_log_path(id, create: false) : Config.setup_log_path(id, create: false)
|
|
445
445
|
return '' unless path.file?
|
|
446
446
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
end
|
|
451
|
-
scrub(raw, id: id).lines.last(Config::SAFE_LOG_LINES).join
|
|
447
|
+
bytes = failed ? Config::FAILURE_LOG_BYTES : Config::SAFE_LOG_BYTES
|
|
448
|
+
lines = failed ? Config::FAILURE_LOG_LINES : Config::SAFE_LOG_LINES
|
|
449
|
+
tail_file(path, id, bytes: bytes, lines: lines).fetch('text')
|
|
452
450
|
end
|
|
453
451
|
|
|
454
452
|
# Output for each recipe step, keyed by step id. Only steps that have written something
|
|
455
453
|
# appear, so a pending step has no entry and the page can show it as not started.
|
|
456
|
-
def step_logs(id, steps)
|
|
454
|
+
def step_logs(id, steps, status = nil)
|
|
457
455
|
steps.each_with_object({}) do |step, logs|
|
|
458
456
|
path = Config.step_log_path(id, step['key'], create: false)
|
|
459
457
|
next unless path.file?
|
|
460
458
|
|
|
461
|
-
|
|
459
|
+
failed = failed_step?(step, status)
|
|
460
|
+
logs[step['key']] = tail_file(path, id, bytes: failed ? Config::FAILURE_LOG_BYTES : Config::STEP_LOG_BYTES,
|
|
461
|
+
lines: failed ? Config::FAILURE_LOG_LINES : Config::STEP_LOG_LINES)
|
|
462
462
|
end
|
|
463
463
|
rescue ArgumentError
|
|
464
464
|
{}
|
|
465
465
|
end
|
|
466
466
|
|
|
467
|
+
# The step that failed, or the one a run was cut off in. A step that is merely running is not one.
|
|
468
|
+
def failed_step?(step, status)
|
|
469
|
+
return true if step['state'] == 'failed'
|
|
470
|
+
|
|
471
|
+
status == 'interrupted' && step['state'] == 'active'
|
|
472
|
+
end
|
|
473
|
+
|
|
467
474
|
def backend_log_available?(id)
|
|
468
475
|
path = Config.backend_log_path(id, create: false)
|
|
469
476
|
path.file? && !path.zero?
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
const output = details.querySelector('pre');
|
|
108
108
|
output.setAttribute('aria-label', step.label + ' output');
|
|
109
109
|
const entry = stepLogs && stepLogs[step.key];
|
|
110
|
-
if (entry
|
|
110
|
+
if (entry) writeLog(output, entry.text);
|
|
111
111
|
applyStepOpenState(details, step);
|
|
112
112
|
});
|
|
113
113
|
}
|
|
@@ -164,11 +164,11 @@
|
|
|
164
164
|
: 'everything, in order';
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
167
|
+
// A step that finished is closed by the page, which hides its log, and text selected inside a hidden
|
|
168
|
+
// element is lost. So a close waits while part of that step is selected, and happens when the selection ends.
|
|
169
|
+
const pendingClose = new Set();
|
|
170
|
+
|
|
171
|
+
function setStepOpen(details, shouldOpen) {
|
|
172
172
|
if (details.open === shouldOpen) return;
|
|
173
173
|
details.dataset.programmatic = 'true';
|
|
174
174
|
details.open = shouldOpen;
|
|
@@ -176,13 +176,63 @@
|
|
|
176
176
|
setTimeout(() => { details.dataset.programmatic = 'false'; }, 0);
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
+
function applyStepOpenState(details, step) {
|
|
180
|
+
const previous = stepState[step.key];
|
|
181
|
+
stepState[step.key] = step.state;
|
|
182
|
+
if (previous === step.state || userToggled.has(step.key)) return;
|
|
183
|
+
const shouldOpen = step.state === 'active' || step.state === 'failed';
|
|
184
|
+
if (shouldOpen) pendingClose.delete(details);
|
|
185
|
+
if (!shouldOpen && details.open && hasSelectionIn(details)) {
|
|
186
|
+
pendingClose.add(details);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
pendingClose.delete(details);
|
|
190
|
+
setStepOpen(details, shouldOpen);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Replacing a log's text drops any selection inside it, which made copying out of a log that keeps
|
|
194
|
+
// updating a race against the next poll. So: text that has not changed is never rewritten, and while
|
|
195
|
+
// part of a log is selected its new text is held back and applied, once, when the selection ends.
|
|
196
|
+
// Only the log being read waits; every other element keeps updating.
|
|
197
|
+
const heldText = new Map();
|
|
198
|
+
|
|
199
|
+
function hasSelectionIn(element) {
|
|
200
|
+
const selection = window.getSelection && window.getSelection();
|
|
201
|
+
if (!selection || selection.isCollapsed) return false;
|
|
202
|
+
if (element.contains(selection.anchorNode) || element.contains(selection.focusNode)) return true;
|
|
203
|
+
// A selection that starts above a log and ends below it contains the log without either end in it.
|
|
204
|
+
return typeof selection.containsNode === 'function' && selection.containsNode(element, true);
|
|
205
|
+
}
|
|
206
|
+
|
|
179
207
|
// Writing a log must not yank a reader who scrolled up; follow the tail only if already there.
|
|
180
208
|
function writeLog(pre, text) {
|
|
209
|
+
const next = text || '';
|
|
210
|
+
if (pre.textContent === next) {
|
|
211
|
+
heldText.delete(pre);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (hasSelectionIn(pre)) {
|
|
215
|
+
heldText.set(pre, next);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
heldText.delete(pre);
|
|
181
219
|
const atBottom = pre.scrollTop + pre.clientHeight >= pre.scrollHeight - 18;
|
|
182
|
-
pre.textContent =
|
|
220
|
+
pre.textContent = next;
|
|
183
221
|
if (atBottom) pre.scrollTop = pre.scrollHeight;
|
|
184
222
|
}
|
|
185
223
|
|
|
224
|
+
// When the selection moves or is cleared, catch up any log that was waiting on it.
|
|
225
|
+
document.addEventListener('selectionchange', () => {
|
|
226
|
+
heldText.forEach((text, pre) => {
|
|
227
|
+
if (!hasSelectionIn(pre)) writeLog(pre, text);
|
|
228
|
+
});
|
|
229
|
+
pendingClose.forEach((details) => {
|
|
230
|
+
if (hasSelectionIn(details)) return;
|
|
231
|
+
pendingClose.delete(details);
|
|
232
|
+
if (!userToggled.has(details.dataset.stepLog)) setStepOpen(details, false);
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
|
|
186
236
|
// Durations read the way people say them: 0.5s, 12.3s, 1m 10s, 1h 5m 3s. This mirrors
|
|
187
237
|
// Workspaces::DurationFormat in Ruby; a spec runs both over the same inputs.
|
|
188
238
|
function formatDuration(seconds) {
|
|
@@ -258,6 +308,8 @@
|
|
|
258
308
|
}
|
|
259
309
|
|
|
260
310
|
function renderLead(view) {
|
|
311
|
+
const lead = node('lead');
|
|
312
|
+
if (lead && view.state) lead.dataset.state = view.state;
|
|
261
313
|
node('status').textContent = view.headline || view.title;
|
|
262
314
|
node('summary').textContent = view.summary || '';
|
|
263
315
|
const note = node('sleep-note');
|
|
@@ -335,7 +387,7 @@
|
|
|
335
387
|
function renderStatus(view) {
|
|
336
388
|
node('preview').hidden = !view.ready;
|
|
337
389
|
reloadWhenReady(view);
|
|
338
|
-
node('error')
|
|
390
|
+
writeLog(node('error'), view.error || '');
|
|
339
391
|
node('error-panel').hidden = !view.error;
|
|
340
392
|
if (window.WorkspaceEnvironment)
|
|
341
393
|
window.WorkspaceEnvironment.updateStatus(view.busy);
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/* Arb design system, Native v1: tokens/palette.css from ~/code/arb-design-system (commit 88765ca), copied unchanged below this note.
|
|
2
|
+
Do not edit by hand. To update, copy the new palette.css over everything after this comment. */
|
|
3
|
+
/* Source: palette.tokens.json. Opaque sRGB pairings only; see README.md. */
|
|
4
|
+
:root {
|
|
5
|
+
--arb-mark-shell: #123A3D;
|
|
6
|
+
--arb-mark-river: #58D9C4;
|
|
7
|
+
--arb-mark-brackets: #F4F1E8;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
[data-theme="dark"] {
|
|
11
|
+
color-scheme: dark;
|
|
12
|
+
--arb-bg: #0B171A;
|
|
13
|
+
--arb-surface: #12262B;
|
|
14
|
+
--arb-elevated: #1B343B;
|
|
15
|
+
--arb-text: #F4F1E8;
|
|
16
|
+
--arb-muted: #B4C3C8;
|
|
17
|
+
--arb-accent: #58D9C4;
|
|
18
|
+
--arb-on-accent: #073A35;
|
|
19
|
+
--arb-steel: #ABC8D2;
|
|
20
|
+
--arb-border: #6F8991;
|
|
21
|
+
--arb-focus: #76CCE5;
|
|
22
|
+
--arb-success: #9DD48E;
|
|
23
|
+
--arb-warning: #F1C56B;
|
|
24
|
+
--arb-error: #FF9B96;
|
|
25
|
+
--arb-action-hover: #78E3D0;
|
|
26
|
+
--arb-action-pressed: #3CBDA9;
|
|
27
|
+
--arb-surface-hover: #1B343B;
|
|
28
|
+
--arb-surface-pressed: #203A41;
|
|
29
|
+
--arb-selected-bg: #173E40;
|
|
30
|
+
--arb-selected-border: #58D9C4;
|
|
31
|
+
--arb-disabled-bg: #1B343B;
|
|
32
|
+
--arb-disabled-fg: #91A5AC;
|
|
33
|
+
--arb-disabled-border: #6F8991;
|
|
34
|
+
--arb-success-bg: #173322;
|
|
35
|
+
--arb-warning-bg: #3E321A;
|
|
36
|
+
--arb-error-bg: #40262A;
|
|
37
|
+
--arb-error-hover: #FFB4AE;
|
|
38
|
+
--arb-error-pressed: #EE817D;
|
|
39
|
+
--arb-on-error: #351415;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
[data-theme="light"] {
|
|
43
|
+
color-scheme: light;
|
|
44
|
+
--arb-bg: #F5F2E9;
|
|
45
|
+
--arb-surface: #FFFFFF;
|
|
46
|
+
--arb-elevated: #E8EEEC;
|
|
47
|
+
--arb-text: #123A3D;
|
|
48
|
+
--arb-muted: #4B676E;
|
|
49
|
+
--arb-accent: #0A766F;
|
|
50
|
+
--arb-on-accent: #FFFFFF;
|
|
51
|
+
--arb-steel: #496B79;
|
|
52
|
+
--arb-border: #71868B;
|
|
53
|
+
--arb-focus: #246C89;
|
|
54
|
+
--arb-success: #2D6D45;
|
|
55
|
+
--arb-warning: #8A5A10;
|
|
56
|
+
--arb-error: #B64344;
|
|
57
|
+
--arb-action-hover: #08655F;
|
|
58
|
+
--arb-action-pressed: #07554F;
|
|
59
|
+
--arb-surface-hover: #E8EEEC;
|
|
60
|
+
--arb-surface-pressed: #E1EFEA;
|
|
61
|
+
--arb-selected-bg: #E1EFEA;
|
|
62
|
+
--arb-selected-border: #0A766F;
|
|
63
|
+
--arb-disabled-bg: #E1E7E5;
|
|
64
|
+
--arb-disabled-fg: #4E656B;
|
|
65
|
+
--arb-disabled-border: #71868B;
|
|
66
|
+
--arb-success-bg: #E5F1E6;
|
|
67
|
+
--arb-warning-bg: #FBF0D7;
|
|
68
|
+
--arb-error-bg: #FBE9E7;
|
|
69
|
+
--arb-error-hover: #A03638;
|
|
70
|
+
--arb-error-pressed: #8B2C2E;
|
|
71
|
+
--arb-on-error: #FFFFFF;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* Optional descriptive aliases. Canonical names mirror JSON keys. */
|
|
75
|
+
[data-theme] {
|
|
76
|
+
--arb-canvas: var(--arb-bg);
|
|
77
|
+
--arb-raised: var(--arb-elevated);
|
|
78
|
+
--arb-text-secondary: var(--arb-muted);
|
|
79
|
+
--arb-river: var(--arb-accent);
|
|
80
|
+
--arb-on-river: var(--arb-on-accent);
|
|
81
|
+
--arb-boundary: var(--arb-border);
|
|
82
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" role="img" aria-labelledby="title desc">
|
|
2
|
+
<title id="title">Arb Previews</title>
|
|
3
|
+
<desc id="desc">A browser window with two preview panes. Original vector artwork in the Arb Native palette. Optically tuned for 16 pixels.</desc>
|
|
4
|
+
<rect id="tile" width="16" height="16" rx="4" fill="#123A3D"/>
|
|
5
|
+
<g id="preview-window" fill="none" stroke-linejoin="round">
|
|
6
|
+
<rect id="window-frame" x="2.5" y="3.5" width="11" height="9" rx="1.5" stroke="#F4F1E8" stroke-width="1.5"/>
|
|
7
|
+
<path id="browser-header" d="M2.5 6.5H13.5" stroke="#F4F1E8" stroke-width="1.5"/>
|
|
8
|
+
<path id="preview-divider" d="M8 7.25V11.75" stroke="#58D9C4" stroke-width="1.5"/>
|
|
9
|
+
<g id="browser-controls" fill="#58D9C4"><circle cx="4.5" cy="5" r="0.5"/><circle cx="6.5" cy="5" r="0.5"/></g>
|
|
10
|
+
</g>
|
|
11
|
+
</svg>
|