Skip to content

Add OSC 8 hyperlinks to root-help header#24

Merged
kjanat merged 2 commits into
masterfrom
20-support-osc-8-hyperlinks-in-the-help-header-nameversion
Jun 10, 2026
Merged

Add OSC 8 hyperlinks to root-help header#24
kjanat merged 2 commits into
masterfrom
20-support-osc-8-hyperlinks-in-the-help-header-nameversion

Conversation

@kjanat

@kjanat kjanat commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Summary

Adds support for OSC 8 hyperlinks in the root-help header, allowing the program name and version to become clickable links in supporting terminals. Links can be explicitly configured via .links() or automatically derived from package.json metadata (repository/homepage).

Key Changes

  • New .links() builder method — Configure explicit hyperlink URLs for the program name and version in root help output
  • Automatic link derivation — When .packageJson() is active, missing link URLs are derived from:
    • repository field → normalized to browsable HTTPS URL (supports GitHub, GitLab, Bitbucket shorthands and various formats)
    • homepage field → fallback for the name link
    • Version → forge-specific release tag URL (GitHub: /releases/tag/v{version}, GitLab: /-/releases/v{version})
  • ANSI/OSC-aware text helpers — New ansi.ts module with:
    • osc8(url, text) — Wrap text in OSC 8 hyperlink escape sequences
    • visibleWidth(text) — Measure text width ignoring escape sequences
    • stripAnsi(text) — Remove ANSI CSI and OSC escapes
    • padEnd() and wrapText() — Escape-aware padding and wrapping for aligned help output
  • TTY-gated escapes — Hyperlinks only emit when stdout is a TTY (overridable via help.hyperlinks option); escapes never leak into piped output or non-header sections
  • Package.json parsing enhancements — Extended PackageJsonData to include homepage and repository fields with support for both string and object forms
  • New packageRepositoryUrl() export — Public utility to normalize repository locators to browsable HTTPS URLs

Implementation Details

  • Hyperlinks are only rendered in the root-help header line; usage lines, hints, commands table, and completion scripts remain plain
  • The --version flag output stays plain (no escapes)
  • Link resolution happens during runtime preflight (.run()) or directly from pre-loaded data (.execute())
  • Explicit URLs always take precedence over derived ones
  • All escape sequences use the BEL terminator for maximum compatibility
  • Comprehensive test coverage including TTY detection, derivation from package.json, and escape containment

Closes #20.

The root-help header (`name vX.Y.Z`) can now carry clickable OSC 8
hyperlinks: the name links to the repo/homepage and the version to the
release tag. Both blockers from the issue are addressed:

- New `.links({ name?, version? })` builder method stores header-only
  link targets, so the linked name never leaks into usage lines, the
  `--help` hint, binName, the commands table, or completion scripts.
  Called without arguments, URLs are derived from package.json metadata
  when `.packageJson()` is active (discovery and pre-loaded data forms):
  name → normalized `repository` URL (fallback `homepage`), version →
  forge release tag (GitHub `/releases/tag/v{v}`, GitLab
  `/-/releases/v{v}`). Escapes are gated on TTY detection and
  overridable via the new `help.hyperlinks` option.
- Width helpers are now ANSI/OSC-aware: shared `padEnd()`/`wrapText()`
  in `help/ansi.ts` measure with `visibleWidth()` (strips CSI + OSC
  escapes), replacing the duplicated `.length`-based copies in
  `help/index.ts` and `root-help.ts`.

Also exported: `osc8(url, text)`, `visibleWidth(text)`, and
`packageRepositoryUrl(pkg)` (normalizes git+/scp/shorthand repository
locators to browsable https URLs); package.json parsing now extracts
`homepage` and `repository`.
@kjanat kjanat linked an issue Jun 10, 2026 that may be closed by this pull request
@coderabbitai

This comment was marked as outdated.

@pkg-pr-new

pkg-pr-new Bot commented Jun 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

bun add https://pkg.pr.new/@kjanat/dreamcli@24
npm i https://pkg.pr.new/@kjanat/dreamcli@24

commit: c453898

@kjanat kjanat self-assigned this Jun 10, 2026
@kjanat kjanat marked this pull request as ready for review June 10, 2026 19:28
@coderabbitai coderabbitai Bot added kind: feature New capability or product enhancement area: docs VitePress app, guides, reference pages, and docs UX area: cli CLI dispatch, planning, root UX, or plugins area: config Config discovery, package metadata, and loaders labels Jun 10, 2026
@kjanat kjanat added the cr:skip Skip CodeRabbit review label Jun 10, 2026
@kjanat kjanat force-pushed the 20-support-osc-8-hyperlinks-in-the-help-header-nameversion branch from 6d0fad0 to c453898 Compare June 10, 2026 20:44
@kjanat kjanat merged commit b084f93 into master Jun 10, 2026
11 checks passed
@kjanat kjanat deleted the 20-support-osc-8-hyperlinks-in-the-help-header-nameversion branch June 10, 2026 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli CLI dispatch, planning, root UX, or plugins area: config Config discovery, package metadata, and loaders area: docs VitePress app, guides, reference pages, and docs UX cr:skip Skip CodeRabbit review kind: feature New capability or product enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support OSC 8 hyperlinks in the help header (name/version)

1 participant