Repository navigation
feat(cli): pre-run render context probe (#69) - #75
Conversation
Content built before `run()` (banners, hand-rendered help) has no `out`, so
consumers re-derive the framework's output decisions from raw argv — and get
it wrong (`argv.includes('--json')` misreads a post-`--` literal). Add
`resolveRenderContext(argv, options?)` returning `{ jsonMode, isTTY, color,
isHyperlinkSupported }`, computed by feeding the same composition
`.execute()`/`.run()` give `createOutput` and reading the channel back, so
the gates cannot drift. Also export the `--`-aware primitives
`includesBeforeSeparator`/`stripBeforeSeparator` from the package root.
Bump to 3.0.0-rc.16.
📝 WalkthroughWalkthroughAdds the exported Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant resolveRenderContext
participant FlagParser
participant OutputChannel
participant HyperlinkResolver
Caller->>resolveRenderContext: Provide argv and options
resolveRenderContext->>FlagParser: Detect flags before --
resolveRenderContext->>OutputChannel: Apply JSON, TTY, and colour gating
resolveRenderContext->>HyperlinkResolver: Resolve hyperlink support
resolveRenderContext-->>Caller: Return render context
Possibly related issues
Possibly related PRs
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 8 | ❌ 3❌ Failed checks (3 warnings)
✅ Passed checks (8 passed)
Comment |
commit: |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
dreamcli | ec856ec | Commit Preview URL Branch Preview URL |
Jul 20 2026, 08:21 PM |
Closes #69.
Problem
Inside a handler,
outanswers every rendering question (jsonMode,isTTY,color,isHyperlinkSupported). Content built beforerun()has noout, so consumers re-derive the decisions from raw argv — in the naive form the framework's own docstring warns against:The consumer and the framework then disagree about the same fact, using the same argv.
Solution — both options from the issue
Option 2 (the probe):
resolveRenderContext(argv, options?)returns{ jsonMode, isTTY, color, isHyperlinkSupported }. It is implemented by feeding the same composition.execute()/.run()givecreateOutput—---aware--jsondetection viaincludesBeforeSeparator, the hyperlink override viaresolveHyperlinkOverride, the color auto-gate — and reading the resolved channel back. No duplicated gating logic, so the probe cannot drift from the channel that will actually render.One deviation from the issue's sketch:
coloris the gatedColorspalette (the same shape asout.color) rather than a bare boolean — consumers want to style, and identity formatters mean they can do so unconditionally.ctx.color.isColorSupportedis the boolean form.optionscarries the host facts core cannot read (isTTY,env) plus explicitjsonMode/coloroverrides — same seams asexecute(). Core stays process-free.Option 1 (the primitives):
includesBeforeSeparatorandstripBeforeSeparatorare exported from the package root for consumers who only need correct---aware flag reads.Tests
render-context.test.ts— pre/post-separator--json, explicit overrides, TTY-default and JSON-mode color gating, explicitcolor: true, and the full hyperlink matrix (NO_HYPERLINKS,FORCE_HYPERLINKS,--no-hyperlinkspre/post-separator). Public-export JSDoc coverage passes.Docs
guide/output.mdgains a "Pre-run Render Context" section with a validated twoslash example; built successfully.Full suite (2893), typecheck, biome, dprint,
deno check, docs build all pass.Bumps to
3.0.0-rc.16.