@effected/cli 0.25.0 → 0.26.0

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.
Files changed (107) hide show
  1. package/README.md +5 -208
  2. package/bin/effected.js +7 -0
  3. package/commands/root.js +14 -0
  4. package/index.d.ts +19 -3942
  5. package/index.js +3 -26
  6. package/main.d.ts +28 -0
  7. package/main.js +46 -0
  8. package/package.json +17 -52
  9. package/tsdoc-metadata.json +1 -1
  10. package/version.js +11 -0
  11. package/Cancelled.js +0 -43
  12. package/CliAudience.js +0 -177
  13. package/CliColor.js +0 -59
  14. package/CliEnv.js +0 -101
  15. package/CliExit.js +0 -64
  16. package/CliFailure.js +0 -287
  17. package/CliFormat.js +0 -124
  18. package/CliInteractive.js +0 -94
  19. package/CliLinks.js +0 -153
  20. package/CliLog.js +0 -367
  21. package/CliLogger.js +0 -91
  22. package/CliMessage.js +0 -79
  23. package/CliPrompt.js +0 -110
  24. package/CliRuntime.js +0 -254
  25. package/CliTest.js +0 -206
  26. package/CliTheme.js +0 -142
  27. package/ConfigIssueRenderer.js +0 -63
  28. package/Doc.js +0 -548
  29. package/Fmt.js +0 -335
  30. package/GithubAnnotation.js +0 -39
  31. package/Glyphs.js +0 -82
  32. package/NotInteractive.js +0 -41
  33. package/Render.js +0 -280
  34. package/SchemaIssueRenderer.js +0 -47
  35. package/Status.js +0 -165
  36. package/TestTerminal.js +0 -101
  37. package/Token.js +0 -68
  38. package/internal/ExitRequested.js +0 -21
  39. package/internal/HelpRouting.js +0 -35
  40. package/internal/ansi.js +0 -229
  41. package/internal/autoFormat.js +0 -33
  42. package/internal/canPrompt.js +0 -14
  43. package/internal/counts.js +0 -83
  44. package/internal/diagnostics.js +0 -31
  45. package/internal/displayPath.js +0 -46
  46. package/internal/displayWidth.js +0 -42
  47. package/internal/failureTarget.js +0 -195
  48. package/internal/fallbackAnswer.js +0 -17
  49. package/internal/fileSink.js +0 -61
  50. package/internal/format.js +0 -175
  51. package/internal/inspect.js +0 -40
  52. package/internal/isExitCode.js +0 -11
  53. package/internal/layout.js +0 -249
  54. package/internal/linkScheme.js +0 -29
  55. package/internal/linkTarget.js +0 -49
  56. package/internal/logSafety.js +0 -45
  57. package/internal/renderAnsi.js +0 -51
  58. package/internal/renderDoc.js +0 -322
  59. package/internal/renderGithubLog.js +0 -59
  60. package/internal/renderMarkdown.js +0 -367
  61. package/internal/renderPlain.js +0 -49
  62. package/internal/scanAudience.js +0 -105
  63. package/internal/splitFrame.js +0 -55
  64. package/internal/terminalCapabilities.js +0 -23
  65. package/internal/wizardGate.js +0 -17
  66. package/testing.d.ts +0 -246
  67. package/testing.js +0 -4
  68. package/ui/CliUi.js +0 -507
  69. package/ui/CliUiDetached.js +0 -36
  70. package/ui/CliUiLive.js +0 -436
  71. package/ui/CliUiRouteStream.js +0 -72
  72. package/ui/Confirm.js +0 -244
  73. package/ui/DocView.js +0 -76
  74. package/ui/KeyHelp.js +0 -61
  75. package/ui/KeyTable.js +0 -198
  76. package/ui/MultiSelect.js +0 -259
  77. package/ui/Select.js +0 -229
  78. package/ui/Tabs.js +0 -201
  79. package/ui/TextInput.js +0 -289
  80. package/ui/Toggle.js +0 -31
  81. package/ui/UiKey.js +0 -48
  82. package/ui/UiProvider.js +0 -62
  83. package/ui/UiStreams.js +0 -17
  84. package/ui/UiTheme.js +0 -147
  85. package/ui/Viewport.js +0 -203
  86. package/ui/internal/ErrorBoundary.js +0 -29
  87. package/ui/internal/Holder.js +0 -73
  88. package/ui/internal/ScreenContext.js +0 -51
  89. package/ui/internal/UiProviders.js +0 -38
  90. package/ui/internal/ink.js +0 -121
  91. package/ui/internal/inkChalk.js +0 -47
  92. package/ui/internal/inkConsole.js +0 -150
  93. package/ui/internal/lazyView.js +0 -73
  94. package/ui/internal/lineRouter.js +0 -70
  95. package/ui/internal/lineText.js +0 -18
  96. package/ui/internal/mountPermit.js +0 -15
  97. package/ui/internal/processStreams.js +0 -18
  98. package/ui/internal/renderOptions.js +0 -12
  99. package/ui/testing/CliUiTest.js +0 -792
  100. package/ui/testing/fakeStreams.js +0 -104
  101. package/ui/testing/terminalModel.js +0 -67
  102. package/ui-testing-serializer.d.ts +0 -12
  103. package/ui-testing-serializer.js +0 -32
  104. package/ui-testing.d.ts +0 -558
  105. package/ui-testing.js +0 -3
  106. package/ui.d.ts +0 -1990
  107. package/ui.js +0 -17
package/README.md CHANGED
@@ -1,216 +1,13 @@
1
1
  # @effected/cli
2
2
 
3
- [![npm](https://img.shields.io/npm/v/@effected%2Fcli?label=npm&color=cb3837)](https://www.npmjs.com/package/@effected/cli)
4
- [![License: MIT](https://img.shields.io/badge/License-MIT-4caf50.svg)](https://opensource.org/licenses/MIT)
5
- [![Node.js %3E%3D24.11.0](https://img.shields.io/badge/Node.js-%3E%3D24.11.0-5fa04e.svg)](https://nodejs.org/)
6
- [![TypeScript 7.0](https://img.shields.io/badge/TypeScript-7.0-3178c6.svg)](https://www.typescriptlang.org/)
3
+ The `effected` command: the tool's command tree on the kit's front-end runtime (`@effected/cli-kit`).
7
4
 
8
- The presentation boundary of a command-line program built on `effect/cli`: who the output is for, and how it reaches them. Plain log lines on the right stream. Colour, glyphs and links only where the terminal and the reader can use them. Documents rendered for a person, an agent or a CI log. Failures reported through your own logger with the right exit code. Prompts that know when there is nobody to ask. Interactive screens and live progress views drawn with Ink. `effect/cli` still owns argument parsing, flags, the command tree and help; this package adds no parser and no command model.
9
-
10
- > **Pre-`1.0.0`.** This package is part of the `@effected/*` kit, built on stable
11
- > Effect v4 (`effect` `~4.1.0`) and still in `0.x` development. Stable Effect
12
- > makes a kit `1.0.0` possible, not automatic. To keep your `effect` and
13
- > `@effect/*` versions on the line the kit is built and tested against, install
14
- > [`@effected/pnpm-plugin-effected`](https://www.npmjs.com/package/@effected/pnpm-plugin-effected).
15
- >
16
- > **Stability: unstable.** This package's API surface is not yet considered
17
- > complete and may change across `0.x` releases. Pin an exact version — even a
18
- > package marked *stable* before `1.0.0` can introduce a breaking change by
19
- > accident, and an exact pin turns that into a type-check error rather than a
20
- > runtime surprise. Full policy: [release strategy](https://github.com/spencerbeggs/effected#release-strategy).
21
-
22
- ## Why @effected/cli
23
-
24
- Everything here shares one property: **you only discover you needed it by shipping bad output to a person or a machine.** None of it fails a type-check, a test, or a review of the code in isolation.
25
-
26
- Effect's default logger emits `[00:33:56.619] INFO (#2): message`, which is right for a service and noise for a tool someone is watching. A platform `runMain` reports an unhandled failure through that same default logger, outside the layers your program was given, so it prints on **stdout**, the one stream errors must not use. Colour codes end up in an agent's context window. A prompt fires inside a pipe and hangs. A file name containing `::error::` becomes a workflow command in GitHub Actions. And a decode failure arrives as a structured tree when a user needs a sentence naming the key they got wrong.
27
-
28
- This package makes those decisions once, at the edge of the program, from the environment it actually runs in.
29
-
30
- ## Install
31
-
32
- ```bash
33
- npm install @effected/cli @effected/env @effected/glob @effected/walker effect
34
- ```
35
-
36
- ```bash
37
- pnpm add @effected/cli @effected/env @effected/glob @effected/walker effect
38
- ```
39
-
40
- Requires Node.js >=24.11.0. `effect` v4, `@effected/env` (the audience and terminal services), and `@effected/walker` with its `@effected/glob` peer (the project root for editor links) are peer dependencies. The one runtime dependency is `@effected/github-commands`. The package never imports a platform package, so it runs unchanged on Node, Bun and Deno.
41
-
42
- Optional peers:
43
-
44
- - **`ink` and `react`**, plus **`@types/react`** for TypeScript, for the interactive screens and live views in `@effected/cli/ui`. The root never reaches them, and `./ui` loads neither until a screen first mounts. Without `@types/react`, a program compiled with `skipLibCheck` silently types every screen as `any`.
45
-
46
- ```bash
47
- npm install ink react @types/react
48
- ```
49
-
50
- - **`@effected/config-file`**, only for `ConfigIssueRenderer`. It is imported as a type, so nothing at runtime reaches for it.
51
-
52
- All `@effected/*` packages are ESM-only: the exports maps publish only `import` conditions, so `require()` fails with Node's `ERR_PACKAGE_PATH_NOT_EXPORTED`. Import from an ES module.
53
-
54
- ## Quick start
55
-
56
- One wiring serves every program: share the audience flags on the root command, run it through `CliAudience.run`, and hand that to `CliRuntime.main` with an `env`.
57
-
58
- ```ts
59
- import { CliAudience, CliExit, CliMessage, CliRuntime, Doc } from "@effected/cli";
60
- import { NodeRuntime, NodeServices } from "@effect/platform-node";
61
- import { Effect } from "effect";
62
- import { Command } from "effect/cli";
63
-
64
- const sync = Command.make("sync", {}, () =>
65
- Effect.gen(function* () {
66
- yield* CliMessage.info("syncing 2 repositories");
67
- yield* Doc.print([
68
- Doc.table(
69
- [{ header: "Repository" }, { header: "Files", align: "right" }],
70
- [
71
- ["acme/widgets", "12"],
72
- ["acme/gadgets", "3"],
73
- ],
74
- ),
75
- ]);
76
- yield* CliMessage.warning("acme/gadgets has no default branch");
77
- // A finding, not a crash: the handler succeeds and the run still exits 1.
78
- yield* CliExit.set(1);
79
- }),
80
- );
81
-
82
- const root = Command.make("tool").pipe(Command.withSharedFlags(CliAudience.flags()), Command.withSubcommands([sync]));
83
-
84
- NodeRuntime.runMain(
85
- CliRuntime.main(CliAudience.run(root, { version: "1.0.0" }), {
86
- platform: NodeServices.layer,
87
- env: {
88
- audienceEnvVar: "TOOL_AUDIENCE",
89
- stderrIsTerminal: Effect.sync(() => process.stderr.isTTY === true),
90
- },
91
- }),
92
- );
93
- ```
94
-
95
- ```text
96
- $ tool sync
97
- ℹ syncing 2 repositories
98
- Repository Files
99
- ------------ -----
100
- acme/widgets 12
101
- acme/gadgets 3
102
- ⚠ acme/gadgets has no default branch
103
- $ echo $?
104
- 1
105
- ```
106
-
107
- At a colour terminal the glyphs are painted and the header is bold. For an agent (`--agent`, `TOOL_AUDIENCE=agent`, or an agent detected from the environment), in a pipe, or under `NO_COLOR`, the same program writes no escape sequence of any kind. Under GitHub Actions, anything the runner could read as a workflow command is neutralized. A failure anywhere renders as a short report on stderr and exits non-zero.
108
-
109
- ## Audiences
110
-
111
- The audience is decided once per run: an audience flag (`--audience <human|agent|ci>`, `--human`, `--agent`, `--ci`), then the override variable you name, then an agent detected from the environment, then CI, else a human. It decides:
112
-
113
- | | Human | Agent | CI |
114
- | --- | --- | --- | --- |
115
- | Colour | When the stream has it | Never, even with `FORCE_COLOR` | When the stream has it (messages) |
116
- | `Doc.print` | `ansi`: painted, OSC 8 links | `plain` | `githubLog` under GitHub Actions, else `plain` |
117
- | Width | The terminal's | Unbounded | Unbounded |
118
- | Diagnostics (`CliLog`) | Pretty lines | NDJSON | NDJSON |
119
- | Prompts and screens | When interactive | Never | Never |
120
-
121
- Colour follows Node's precedence, per stream: `FORCE_COLOR` decides first and beats `NO_COLOR` (`1`–`3` on, even in a pipe; `0` off). Otherwise there is no colour without a terminal. On a terminal, a non-empty `NO_COLOR`, `NODE_DISABLE_COLORS` or `TERM=dumb` turns it off. `TERM=dumb` also switches to ASCII glyphs and makes the run non-interactive.
122
-
123
- ## Output
124
-
125
- - **`CliMessage`**: `success`, `info`, `warning`, `failure` and `status(vocab, name, text)`. One themed line each, through `Console` rather than the logger, so no log level silences them. Warnings and failures go to stderr.
126
- - **`Doc` and `Render`**: a document IR (headings, paragraphs, lists, tables, trees, counts, count tables, collapsibles, callouts, code blocks, diffs, GitHub annotations) and pure `plain`, `ansi`, `markdown` and `githubLog` renderers. `Doc.print` picks the renderer for the audience, and lays out at the terminal's width only when the stream is a terminal: piped output (`tool | grep`) never wraps. `Doc.line(content, { wrap: false })` keeps one line whole at any width, glyph and colour included. `Render.contextOf` renders outside Effect, for example markdown for a step summary.
127
- - **`CliTheme`, `Token`, `Status`, `Glyphs`**: semantic tokens (`success`, `failure`, `warning`, `info`, `error`, `muted`, `accent`, `emphasis`), an extendable status vocabulary with glyphs and ranks, and Unicode or ASCII glyph sets. Override tokens with `env.theme`.
128
- - **`CliLinks`**: file links that open in VS Code (`vscode://file/…`) or as `file://` URLs, as OSC 8 hyperlinks where the terminal renders them, never for an agent.
129
- - **`Fmt`**: `sanitize`, `width`, `truncate`, `duration`, `percent` and `plural`.
130
-
131
- Every string that enters a document or a message is sanitised: escape sequences and control characters are removed, so data cannot paint the terminal or plant a link.
132
-
133
- ## Failures and exit codes
134
-
135
- `CliRuntime.main` reports a failure as a document on stderr, through the audience's renderer: a status line for a typed failure, a tree of rejected values for a schema failure, and a defect's message with a collapsible stack of your own frames (Effect's, Node's and `node_modules` frames hidden). Give an error class a `[CliDoc]()` method to draw itself, or pass a `render` option. Its `details.lines({ status: false })` keeps the run's colour and paths behind your own prefix. The `in: outer › inner` span trail after a failure names only your own spans by default; `env.spans` (`"app"`, `"all"` or `"off"`) chooses, as `env.stackFrames` does for a defect's frames. `"app"` leaves out spans defined in files under `node_modules/@effected/` or `node_modules/effect/`, and fails open: a kit package linked into a workspace, or a bundled program, shows more, never less. A program that is itself installed under `node_modules/@effected/` passes its bin's `import.meta.url` as `env.appModule` to keep its own spans. `env.spansEnvVar` names a variable (say `TOOL_SPANS`) that sets it at run time, as `log.envVar` sets the level. An `Effect.fn` call and its definition are one entry in the trail.
136
-
137
- - `CliExit.set(code)` records a findings exit code from a handler that still succeeds. Do not provide `CliExit.layer` yourself under `main`, or the code goes to a second, unread cell.
138
- - `Cancelled` (a prompt quit) exits `130`, and `NotInteractive` (a prompt with nobody to ask) exits `64`, each as one fixed line.
139
- - A usage error exits `64`. `helpOnUsageError: "stderr"` keeps stdout clean for a caller piping it into `jq`.
140
- - Without `main`: `CliRuntime.reportFailures()` is the combinator to apply inside your program, and `CliRuntime.reported(error, code)` marks an error you printed yourself.
141
-
142
- `SchemaIssueRenderer.render(issue)` and `ConfigIssueRenderer.render(error)` turn an issue tree into lines like `unknown key at groups.g.rulesetz`.
143
-
144
- ## Logging
145
-
146
- `CliLogger` writes plain lines, with no timestamp, level or fiber id, and routes every level to stderr by default (`stderrFrom` narrows it), so stdout carries only the program's output. Pass `env.log` to `main` for **`CliLog`**: a diagnostics level of its own (`level`, or `envVar` such as `TOOL_LOG_LEVEL`, with core's `--log-level` beating both), pretty lines for a person and NDJSON for an agent or CI, an optional NDJSON log file, and `CliLog.component(name)` tags. `CliLog.status(vocab, name, text)` logs a diagnostic with a painted status glyph (its text still sanitised), and `CliTheme.forAudience` applies the kit's "an agent never gets an escape" rule to a theme you paint with yourself.
147
-
148
- ## Prompts and screens
149
-
150
- A prompt fires only when `CliInteractive` is true: a human audience, a terminal on stdin and stdout, and `TERM` not `dumb`. Otherwise it answers a default you supply, or fails cleanly.
151
-
152
- ```ts
153
- import { CliPrompt } from "@effected/cli";
154
- import { Flag, Prompt } from "effect/cli";
155
-
156
- // Core's prompt as a flag fallback: asks at a terminal, uses "library" in a pipe.
157
- const profile = Flag.String("profile").pipe(
158
- Flag.withFallbackPrompt(
159
- CliPrompt.fallback(
160
- Prompt.Select({ message: "Profile", choices: [{ title: "library", value: "library" }, { title: "application", value: "application" }] }),
161
- { flag: "profile", otherwise: "library" },
162
- ),
163
- ),
164
- );
165
- ```
166
-
167
- `@effected/cli/ui` adds Ink screens: `CliUi.run`, `prompt` (with an `otherwise`) and `fallback` (for a flag), over the widgets `Select`, `TextInput` (with a `mask` for secrets, always, or from the moment a predicate spots one anywhere in the value, latched until the value is cleared: its `validate` message is drawn unmasked, so never echo the value in it), `MultiSelect`, `Confirm` (with toggles), `Toggle`, `Tabs` and `Viewport`. Your own screens use the key layer (`KeyTable`, `useKeys`, `KeyHelp`) and the theme bridge (`Styled`, `useTheme`, `useGlyphs`, `useTerminalSize`).
168
-
169
- ```tsx
170
- import { CliUi, Select } from "@effected/cli/ui";
171
-
172
- const pickProfile = Select.screen({
173
- message: "Profile",
174
- choices: [
175
- { label: "library", value: "library" },
176
- { label: "application", value: "application" },
177
- ],
178
- });
179
-
180
- const profile = CliUi.prompt(pickProfile, { otherwise: "library" });
181
- ```
182
-
183
- `CliUi.map(screen, f)` maps a screen's answer and leaves a cancel alone, so a `Confirm` can back a boolean flag ("confirm, or `--yes`"):
5
+ This release answers `--version` and `--help` only. `effected --version` prints `effected <version>`; when a carrier package launched the bin, it ends with "via" and the carrier's name and version.
184
6
 
185
7
  ```ts
186
- import { CliUi, Confirm } from "@effected/cli/ui";
187
- import { Flag } from "effect/cli";
8
+ import { main } from "@effected/cli/main";
188
9
 
189
- const yes = Flag.Boolean("yes").pipe(
190
- Flag.withFallbackPrompt(
191
- CliUi.fallback(
192
- CliUi.map(Confirm.screen({ message: "Publish?" }), (result) => result.confirmed),
193
- { flag: "yes", otherwise: false },
194
- ),
195
- ),
196
- );
10
+ main({ distribution: { name: "@effected/plugin", version: "1.0.0" } });
197
11
  ```
198
12
 
199
- ## Live views
200
-
201
- `CliUi.live` folds a stream or a `PubSub` subscription of events into state, and draws **runs** with Ink while they are going: a run starts at `isStart`, redraws on a tick, and commits its final frame at `isTerminal`. Log lines go above the frame through `handle.logConsole`. End with `handle.close`, which folds everything still queued. When nobody is watching (a pipe, an agent, CI), each run's final frame prints once instead: give the view a `final: (state) => Document` and that run prints the document with no Ink or React loaded at all; `render` is then never called on such a run, not even to build an unused string. `render: CliUi.lazyView(() => import("./view.js"))` keeps the view's module, and React, off every run until one draws. `DocView` draws a `Doc` document inside a view byte for byte as `Doc.print` would, and `UiProvider` with `CliUi.context` gives an Ink tree you mount yourself the same theme.
202
-
203
- ## Testing
204
-
205
- - **`@effected/cli/testing`**: `CliTest.sandbox` and `CliTest.run` spawn a built bin hermetically and return `{ exitCode, stdout, stderr }` as data. `TestTerminal` drives core's prompts.
206
- - **`@effected/cli/ui/testing`**: `CliUiTest.render` mounts a screen on in-memory streams (`press`, `type`, `chunk`, `frame`, `result`). `view` mounts a display-only element, `session` drives a whole command's screens (its `transcript` shows what reached the terminal, a live view's `logConsole` lines included, `stdoutWritten`/`stderrWritten` each stream alone as raw bytes, `stdoutTranscript`/`stderrTranscript` each stream alone as plain text, and `renderPath: "production"` makes `clear` observable), and `live` mounts a live view on the production render path with a `TestClock` tick. `CliUiTest.serializer` prints frames as token markup in snapshots: register it in the Vitest config with `snapshotSerializers: ["@effected/cli/ui/testing/serializer"]`, or with `expect.addSnapshotSerializer`. Snapshots are the one place a test needs `expect`, since `assert` has no snapshot form.
207
-
208
- In-process, provide `layerTest`s from `@effected/env` and `CliTheme.layerTest`, swap in a capturing `Console`, and assert on both streams. Neither testing entrypoint is reachable from a CLI's runtime imports.
209
-
210
- ## Documentation
211
-
212
- Guides for every part, and the full API reference, are at [effected.spencerbeg.gs/cli](https://effected.spencerbeg.gs/cli): [getting started](https://effected.spencerbeg.gs/cli/getting-started), [audiences and output](https://effected.spencerbeg.gs/cli/output), [prompts and screens](https://effected.spencerbeg.gs/cli/prompts), [live views](https://effected.spencerbeg.gs/cli/live-views), [testing](https://effected.spencerbeg.gs/cli/testing) and [advanced](https://effected.spencerbeg.gs/cli/advanced).
213
-
214
- ## License
215
-
216
- [MIT](LICENSE)
13
+ > **Pre-`1.0.0`.** Part of the `@effected/*` kit; unstable across `0.x` releases. Pin an exact version.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { main } from "../main.js";
3
+
4
+ // src/bin.ts
5
+ main();
6
+
7
+ export { };
@@ -0,0 +1,14 @@
1
+ import { CliAudience } from "@effected/cli-kit";
2
+ import { Command } from "effect/cli";
3
+
4
+ // src/commands/root.ts
5
+ /**
6
+ * The `effected` command tree. This release carries no subcommand: `--version`
7
+ * and `--help` come from the framework, and the audience flags are shared on
8
+ * the root so every future subcommand accepts them.
9
+ *
10
+ * @public
11
+ */
12
+ const rootCommand = Command.make("effected", {}).pipe(Command.withDescription("The effected tool: a toolchain for Effect v4 applications."), Command.withSharedFlags(CliAudience.flags()));
13
+
14
+ export { rootCommand };