Skip to content

Commit 2b2b044

Browse files
committed
Start commands sooner, and make decrypting .env values opt-in
Commands that read the config start about 65 ms sooner than in 0.5.0, and `exec` and `run` about 110 ms sooner: - Config validation moves from zod to valibot, which loads in a few ms. Error messages are valibot's own; the formatter only picks the most telling issue inside a failed union. `stackctl` no longer re-exports `z`. - execa is replaced by Node's own spawn (`spawn.ts`, and `hook-exec.ts` for an infra callback's `exec`), which also says why a command couldn't start. - Node's compile cache is on for the CLI. - The log formatter's two colors move to `log-colors.ts`, so a config's `import 'stackctl'` no longer loads colord. - @dotenvx/primitives goes to 4.4.0, pinned, with a pnpm patch that loads its crypto code only once a value is decrypted and keeps a key and a decrypted value for the process. Its eager load cost every command about 8 ms. (The patch reaches npm users once the package is bundled; until then they get the same behavior, unpatched.) `env.decrypt` turns on decrypting values encrypted with dotenvx, with the keys in the workspace's `.env.keys` and in `DOTENV_PRIVATE_KEY*` variables; a session reads and watches `.env.keys` with its `.env` files. Off by default, an `encrypted:` value stays as written: stackctl used to decrypt whenever a key happened to be around, undocumented. An `exec` or `run` inside a command stackctl runs (a dev script's `sctl exec -- …`, marked by STACKCTL_NESTED) only sets up the environment: it no longer logs twice, records an event or keeps a process of its own running. The demo, run-screen and getting-started recordings are re-recorded, since sessions, one-off commands, the clipboard and the footer's git branch run through the new spawn. The picker is skipped: it only matched config.ts and colors.ts, whose output for the example is unchanged.
1 parent faf7a25 commit 2b2b044

85 files changed

Lines changed: 2845 additions & 1366 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
# Changelog
22

3-
## 0.5.1
3+
## 0.6.0
4+
5+
### Features
6+
7+
- **`env.decrypt` decrypts `.env` values encrypted with dotenvx**, so a file of secrets can be
8+
committed. See [docs/config/env.md](docs/config/env.md#envdecrypt).
49

510
### Fixes
611

12+
- **`sctl exec` or `sctl run` in a dev script no longer logs twice, records an event or keeps a process running.**
13+
See [docs/guide/commands.md](docs/guide/commands.md#output-and-exit-code).
714
- **`stackctl events -f` no longer skips a line written as it starts.**
15+
- **Every command that reads the config starts about 65 ms sooner**, and `sctl exec` and
16+
`sctl run` about 110 ms sooner.
17+
- **An infra callback's `exec` says why a command couldn't start**, a missing `cwd` included.
18+
- **stackctl installs 19 fewer packages.**
19+
20+
### Breaking changes
21+
22+
- **`stackctl` no longer exports `z`**: for a `logs.formatter` that validates with zod, add `zod`
23+
to your own dependencies and import `z` from it.
24+
- **An `.env` value encrypted with dotenvx stays encrypted unless `env.decrypt` is set**: add
25+
`env: { decrypt: true }` to `stackctl.config.ts`.
826

927
## 0.5.0
1028

‎CLAUDE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ instead — `expectTypeOf(ctx.port).toEqualTypeOf<number>()`, or
204204
things that are genuinely "this must not compile" (an unknown field, a bad `waitFor` name), and
205205
when you write one, confirm it fails for the intended reason.
206206

207-
A config field lives in two places: its Zod schema in `config-schema.ts`, which validates, and its
207+
A config field lives in two places: its valibot schema in `config-schema.ts`, which validates, and its
208208
type in `config.ts` (`ServiceConfigInput` / `DefineConfigOptions`), which carries its JSDoc. The
209209
schema holds no docs. `config.test-d.ts` compares the two, so `pnpm test:types` fails until a new
210210
or changed field agrees in both. Declare each field directly on those object types, not through

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ during development. You describe your services once, in a small typed config fil
77
starts the ones you pick and the services they need, brings up their infrastructure, loads
88
their environment, and shows it all in one place.
99

10-
![stackctl's terminal UI running the example monorepo](https://raw.githubusercontent.com/rhyek/stackctl/main/docs/public/demo-1794521101.gif)
10+
![stackctl's terminal UI running the example monorepo](https://raw.githubusercontent.com/rhyek/stackctl/main/docs/public/demo-1794549316.gif)
1111

1212
**Documentation: [stackctl.dev](https://stackctl.dev)**
1313

‎docs/config/env.md‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
description: The env option of stackctl.config.ts - env.vars for variables set in the config, env.override to let files win over the shell, and env.additionalFiles for extra .env files.
2+
description: The env option of stackctl.config.ts - env.vars for variables set in the config, env.override to let files win over the shell, env.additionalFiles for extra .env files, and env.decrypt for values encrypted with dotenvx.
33
---
44

55
# Environment
@@ -29,6 +29,7 @@ export default defineConfig({
2929
| [`vars`](#envvars) | Sets variables from the config itself. |
3030
| [`override`](#envoverride) | Names variables where a file wins over the shell. |
3131
| [`additionalFiles`](#envadditionalfiles) | Loads extra `.env` files among stackctl's own. |
32+
| [`decrypt`](#envdecrypt) | Decrypts values encrypted with dotenvx. |
3233

3334
## `env.vars`
3435

@@ -152,3 +153,27 @@ API_PORT=21051
152153

153154
`.env.development.local` couldn't hold them: it loads after `.env.development`, too late for
154155
the references there.
156+
157+
## `env.decrypt`
158+
159+
- **Type:** `boolean` (default `false`)
160+
161+
Decrypts the values [encrypted with dotenvx](https://github.com/dotenvx/dotenvx#encryption),
162+
so a `.env` file of secrets can be committed.
163+
164+
```ts
165+
env: { decrypt: true },
166+
```
167+
168+
```sh
169+
# .env.development (committed), after `dotenvx encrypt -f .env.development`
170+
DOTENV_PUBLIC_KEY_DEVELOPMENT="03f8…"
171+
DATABASE_URL="encrypted:BDqD…"
172+
```
173+
174+
- **The private keys** come from `.env.keys` at the workspace root, which stays out of git,
175+
and from any `DOTENV_PRIVATE_KEY*` variable stackctl is started with, which is how CI gets
176+
one.
177+
- **A value with no key to decrypt it** stays as written, and stackctl prints which one.
178+
- **Editing `.env.keys` restarts every service**, as a workspace `.env` file does.
179+
- **Without it, `encrypted:…` is an ordinary string**, passed on as written.

‎docs/config/infra.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ anything is removed, and a failing `beforeStart` before anything is started.
216216

217217
- **`cwd`** is relative to the workspace root, the default.
218218
- **A non-zero exit rejects**, failing the service, unless you pass `reject: false`.
219+
- **A command that can't start** (not installed, or a `cwd` that doesn't exist) exits 127, and
220+
the service's output says why.
219221
- **Their environment is `envs`**: the workspace-scope variables and `STACKCTL_MODE`. A
220222
variable from one service's own `.env` file isn't there. Pass it with `env`.
221223
- **Use them for anything a callback runs or prints.** A child process you spawn yourself with

‎docs/config/logs.md‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,3 @@ worker: {
113113
filter matching any of them shows the whole block.
114114
- **Don't print a time.** stackctl stamps each line itself.
115115
- **A formatter that throws** falls back to the raw line.
116-
117-
`z` (zod) is re-exported from `stackctl`, for a formatter that validates the shape of a line.

‎docs/guide/commands.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ in a pipeline. The exit code is the command's own.
5959
- **Each call writes a [log file](./logs.md#log-files)**: the command and its directory, every
6060
line that was piped, and how it ended and how long it took. Output that went to a terminal
6161
isn't in it.
62+
- **Inside a command stackctl runs**, such as a dev script `sctl exec -- node --watch
63+
src/main.ts`, a menu command, or another `exec` or `run`, they only set up the environment,
64+
then become the command: no stackctl process stays between them. The outer command keeps
65+
the log and the [event](../reference/events.md), so nothing is recorded twice.
6266

6367
## From a script
6468

‎docs/guide/env.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ At each scope, in this order, each overriding the one before:
3131
4. `.env.<mode>.local`
3232

3333
Only files that exist are read. Commit `.env` and `.env.<mode>`, and keep `.env*.local` out of
34-
git for personal overrides.
34+
git for personal overrides. To commit secrets too, encrypt them with dotenvx and turn on
35+
[`env.decrypt`](../config/env.md#envdecrypt).
3536

3637
## Which value wins
3738

@@ -121,3 +122,5 @@ when stackctl starts. Restart stackctl to pick those up.
121122
it changed. A stackctl started from that process (an e2e suite that calls `startStack()`,
122123
say) drops the first and restores the second, so its own `.env` files load as from the shell
123124
the outer one was started in. It stays in the outer mode unless `--mode` says otherwise.
125+
It also gets `STACKCTL_NESTED`, which makes an `sctl exec` or `sctl run` there part of the
126+
outer command (see [One-off commands](./commands.md#output-and-exit-code)).

‎docs/guide/getting-started.md‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,21 +119,21 @@ pnpm stackctl # or its short alias: pnpm sctl
119119
Pick the services to run, press `⏎`, and the [terminal UI](./terminal-ui.md) takes over: one
120120
combined log, with every service's state in the footer.
121121

122-
<llm-exclude><TerminalPlayer src="/casts/getting-started-1794521159.cast" label="The run screen: the services' combined log, and the footer with each service's state, the keys and the links." still /></llm-exclude>
122+
<llm-exclude><TerminalPlayer src="/casts/getting-started-1794549373.cast" label="The run screen: the services' combined log, and the footer with each service's state, the keys and the links." still /></llm-exclude>
123123
<llm-only>
124124

125125
```text
126126
↑ 15 older lines — press Home to jump to oldest
127-
16:05:44 [backend ] todo api listening on http://localhost:3001
128-
16:05:44 [frontend ] backend ready, starting...
129-
16:05:44 [frontend ] started
130-
16:05:45 [frontend ] VITE v8.3.5 ready in 601 ms
131-
16:05:45 [frontend ] ➜ Local: http://localhost:21060/
132-
16:05:45 [frontend ] ➜ Network: use --host to expose
133-
16:05:45 [frontend ] 4:05:45 PM [vite] (ssr) connected.
127+
23:55:58 [backend ] todo api listening on http://localhost:3001
128+
23:55:58 [frontend ] backend ready, starting...
129+
23:55:58 [frontend ] started
130+
23:55:59 [frontend ] VITE v8.3.5 ready in 559 ms
131+
23:55:59 [frontend ] ➜ Local: http://localhost:21060/
132+
23:55:59 [frontend ] ➜ Network: use --host to expose
133+
23:55:59 [frontend ] 11:55:59 PM [vite] (ssr) connected.
134134
── example ⎇ main ────────────────────────────────────────────────────────
135-
● backend 63M ● frontend 240M
136-
infra: ● db 23M ● mail 8M
135+
● backend 63M ● frontend 231M
136+
infra: ● db 26M ● mail 9M
137137
←→ select r restart s stop m commands
138138
logs: f filter c clear │ ^c quit
139139
backend ↗ public ↗ frontend ↗ root ↗ inbox ↗ mail ↗

‎docs/guide/terminal-ui.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ selection.
4444

4545
The log fills the screen, above a footer:
4646

47-
<llm-exclude><TerminalPlayer src="/casts/run-screen-1794521140.cast" label="The run screen: the focus moves across the services in the footer, then the backend restarts" /></llm-exclude>
47+
<llm-exclude><TerminalPlayer src="/casts/run-screen-1794549354.cast" label="The run screen: the focus moves across the services in the footer, then the backend restarts" /></llm-exclude>
4848
<llm-only>
4949

5050
```text
5151
── example ⎇ main ────────────────────────────────────────────────────────
52-
● backend 62M ● frontend 225M ● worker 24M
53-
infra: ● db 25M ● mail 7M
52+
● backend 63M ● frontend 239M ● worker 25M
53+
infra: ● db 26M ● mail 9M
5454
←→ select r restart s stop m commands
5555
logs: f filter c clear │ ^c quit
5656
backend ↗ public ↗ frontend ↗ root ↗ inbox ↗ mail ↗

0 commit comments

Comments
 (0)