Skip to content

Commit c7e6481

Browse files
authored
fix(cli): read stdin on demand (CLI-2223) (#6450)
## TL;DR follow-up to #6290 Piped answers past the 1024th line were dropped. stdin is now read one chunk at a time as prompts ask for it, so nothing is dropped and the rest stays in the pipe... ## what was biting? Bun reads a pipe as fast as it fills and cannot be paused, so #6290 drained it into a queue of 1024 lines to stop `yes | supabase db push` from eating memory. Anything past 1024 lines fell off the queue and those prompts took their default... ## why this approach is better? A file stream over fd 0 honours backpressure, so there is no queue and no cap. Memory is bounded the same way Go's `bufio.Scanner` did it: a line over 64 KiB ends line reading and every prompt from then on takes its default... ## ref: - adds onto issue: #6287 - extends: #6290
1 parent d35e892 commit c7e6481

6 files changed

Lines changed: 525 additions & 162 deletions

File tree

apps/cli/src/legacy/commands/encryption/update-root-key/update-root-key.command.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { BunServices } from "@effect/platform-bun";
21
import { Layer } from "effect";
32
import { Command, Flag } from "effect/unstable/cli";
43
import type * as CliCommand from "effect/unstable/cli/Command";
@@ -20,11 +19,11 @@ const config = {
2019
export type LegacyEncryptionUpdateRootKeyFlags = CliCommand.Command.Config.Infer<typeof config>;
2120

2221
// `Stdin` is new production wiring for this command. Provide it explicitly
23-
// (along with its `Tty` + `Stdio` deps) so the command's layer is self-contained
24-
// and does not rely on sibling-layer leakage inside `Layer.mergeAll`.
22+
// (along with its `Tty` dep) so the command's layer is self-contained and does
23+
// not rely on sibling-layer leakage inside `Layer.mergeAll`.
2524
const updateRuntime = Layer.mergeAll(
2625
legacyManagementApiRuntimeLayer(["encryption", "update-root-key"]),
27-
stdinLayer.pipe(Layer.provide(ttyLayer), Layer.provide(BunServices.layer)),
26+
stdinLayer.pipe(Layer.provide(ttyLayer)),
2827
);
2928

3029
export const legacyEncryptionUpdateRootKeyCommand = Command.make("update-root-key", config).pipe(

apps/cli/src/legacy/commands/logout/logout.layers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { stdinLayer } from "../../../shared/runtime/stdin.layer.ts";
1818
* legacy CLAUDE.md item 5). `Analytics`, `Output`, `Stdio`, `Tty`, `FileSystem`,
1919
* `Path`, `TelemetryRuntime`, and `LegacyYesFlag` come from the root layer;
2020
* `stdinLayer` (the shared piped-stdin reader for the logout confirm) builds its
21-
* `Stdin` from the root `Stdio`/`Tty`, like the migration runtimes.
21+
* `Stdin` from the root `Tty`, like the migration runtimes.
2222
*/
2323
const cliSettings = legacyCliSettingsLayer.pipe(Layer.provide(legacyDebugLoggerLayer));
2424
const credentials = legacyCredentialsLayer.pipe(

0 commit comments

Comments
 (0)