@linxiraos/pi-tui 1.4.4 → 1.4.7
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.
- package/CHANGELOG.md +208 -207
- package/README.md +34 -34
- package/dist/types/app-keybindings.d.ts +20 -0
- package/dist/types/apps/session-picker.d.ts +5 -0
- package/dist/types/charts/chart-plan.d.ts +9 -7
- package/dist/types/chat/assistant-message.d.ts +15 -3
- package/dist/types/chat/bash-execution.d.ts +2 -0
- package/dist/types/chat/display-preferences.d.ts +2 -0
- package/dist/types/chat/extension-types.d.ts +31 -0
- package/dist/types/chat/reply-write.d.ts +48 -0
- package/dist/types/chat/table-chart.d.ts +4 -3
- package/dist/types/chat/tool-execution.d.ts +1 -2
- package/dist/types/chat/transcript-outline.d.ts +7 -0
- package/dist/types/chat/transcript-render-helpers.d.ts +2 -0
- package/dist/types/chrome/context-map.d.ts +15 -0
- package/dist/types/chrome/context-presentation.d.ts +48 -0
- package/dist/types/chrome/context-view-model.d.ts +77 -0
- package/dist/types/chrome/index.d.ts +1 -0
- package/dist/types/chrome/transcript-notice.d.ts +35 -0
- package/dist/types/chrome/transcript-status.d.ts +20 -8
- package/dist/types/components/editor.d.ts +8 -0
- package/dist/types/components/image.d.ts +20 -0
- package/dist/types/components/loader.d.ts +1 -1
- package/dist/types/components/markdown.d.ts +7 -0
- package/dist/types/native/blobs.d.ts +11 -1
- package/dist/types/native/picker.d.ts +4 -4
- package/dist/types/overlays/advisor-config.d.ts +6 -0
- package/dist/types/overlays/agent-hub-projection.d.ts +3 -1
- package/dist/types/overlays/annotation-overlay.d.ts +7 -1
- package/dist/types/overlays/annotation-types.d.ts +28 -0
- package/dist/types/overlays/ask-dialog.d.ts +12 -3
- package/dist/types/overlays/btw-history-panel.d.ts +16 -2
- package/dist/types/overlays/btw-history.d.ts +7 -0
- package/dist/types/overlays/btw-panel.d.ts +2 -0
- package/dist/types/overlays/context-viewer-format.d.ts +42 -0
- package/dist/types/overlays/context-viewer-overview.d.ts +70 -0
- package/dist/types/overlays/context-viewer.d.ts +25 -0
- package/dist/types/overlays/hook-input.d.ts +1 -0
- package/dist/types/overlays/login-dialog.d.ts +5 -1
- package/dist/types/overlays/mcp-add-wizard.d.ts +2 -0
- package/dist/types/overlays/model-browser.d.ts +10 -1
- package/dist/types/overlays/oauth-selector.d.ts +23 -0
- package/dist/types/overlays/pause-screen.d.ts +13 -3
- package/dist/types/overlays/plan-review-overlay.d.ts +2 -0
- package/dist/types/overlays/rewind-selector.d.ts +1 -1
- package/dist/types/overlays/running-subagent-badge.d.ts +7 -1
- package/dist/types/overlays/session-selector.d.ts +22 -2
- package/dist/types/prompt/composer.d.ts +43 -0
- package/dist/types/prompt/interactive-context-helpers.d.ts +10 -3
- package/dist/types/prompt/macos-spelling.d.ts +2 -2
- package/dist/types/render/extension-links.d.ts +65 -0
- package/dist/types/render/hyperlink.d.ts +38 -7
- package/dist/types/render/index.d.ts +1 -0
- package/dist/types/render/output-pane.d.ts +1 -1
- package/dist/types/render/render-utils.d.ts +7 -1
- package/dist/types/setup/scenes/glyph.d.ts +1 -1
- package/dist/types/setup/scenes/model.d.ts +1 -1
- package/dist/types/setup/scenes/outro.d.ts +5 -4
- package/dist/types/setup/scenes/sign-in.d.ts +13 -8
- package/dist/types/setup/scenes/types.d.ts +16 -1
- package/dist/types/setup/startup-splash.d.ts +1 -1
- package/dist/types/setup/wizard-overlay.d.ts +11 -7
- package/dist/types/setup/wizard.d.ts +5 -1
- package/dist/types/status-line/component.d.ts +3 -3
- package/dist/types/status-line/context-usage.d.ts +42 -35
- package/dist/types/status-line/host.d.ts +6 -2
- package/dist/types/terminal-capabilities.d.ts +7 -0
- package/dist/types/theme/symbols.d.ts +1 -1
- package/dist/types/theme/theme.d.ts +0 -23
- package/dist/types/tools/ask.d.ts +4 -0
- package/dist/types/tools/bash-interactive.d.ts +6 -0
- package/dist/types/tools/bash.d.ts +2 -0
- package/dist/types/tools/default-renderer.d.ts +6 -4
- package/dist/types/tools/edit.d.ts +3 -1
- package/dist/types/tools/fetch.d.ts +1 -0
- package/dist/types/tools/github.d.ts +3 -0
- package/dist/types/tools/grouped-file-output.d.ts +2 -0
- package/dist/types/tools/irc.d.ts +6 -0
- package/dist/types/tools/json-tree.d.ts +23 -4
- package/dist/types/tools/lsp.d.ts +2 -0
- package/dist/types/tools/mcp.d.ts +7 -6
- package/dist/types/tools/native-view.d.ts +1 -1
- package/dist/types/tools/read.d.ts +3 -0
- package/dist/types/tools/renderer.d.ts +2 -0
- package/dist/types/tools/streaming-output.d.ts +11 -0
- package/dist/types/tools/task.d.ts +9 -1
- package/dist/types/tools/url-scheme-host.d.ts +17 -0
- package/dist/types/tools/wait.d.ts +16 -2
- package/dist/types/tools/yield.d.ts +1 -1
- package/dist/types/tui.d.ts +9 -2
- package/dist/types/vim.d.ts +39 -0
- package/package.json +10 -14
- package/src/app-keybindings.d.ts +20 -0
- package/src/app-keybindings.ts +20 -0
- package/src/apps/session-picker.ts +7 -0
- package/src/charts/chart-plan.d.ts +9 -7
- package/src/charts/chart-plan.ts +20 -50
- package/src/chat/advisor-message.ts +2 -0
- package/src/chat/assistant-message.d.ts +15 -3
- package/src/chat/assistant-message.ts +137 -19
- package/src/chat/background-tan-message.ts +4 -0
- package/src/chat/bash-execution.d.ts +2 -0
- package/src/chat/bash-execution.ts +13 -1
- package/src/chat/chat-transcript-builder.ts +58 -28
- package/src/chat/compaction-summary-message.ts +2 -1
- package/src/chat/display-preferences.d.ts +2 -0
- package/src/chat/display-preferences.ts +3 -0
- package/src/chat/extension-types.d.ts +31 -0
- package/src/chat/extension-types.ts +34 -0
- package/src/chat/read-tool-group.ts +1 -2
- package/src/chat/reply-write.d.ts +48 -0
- package/src/chat/reply-write.ts +127 -0
- package/src/chat/skill-message.ts +2 -6
- package/src/chat/table-chart.d.ts +4 -3
- package/src/chat/table-chart.ts +10 -4
- package/src/chat/tool-execution.d.ts +1 -2
- package/src/chat/tool-execution.ts +20 -13
- package/src/chat/transcript-outline.d.ts +7 -0
- package/src/chat/transcript-outline.ts +27 -0
- package/src/chat/transcript-render-helpers.d.ts +2 -0
- package/src/chat/transcript-render-helpers.ts +66 -24
- package/src/chrome/context-map.ts +62 -0
- package/src/chrome/context-presentation.ts +26 -0
- package/src/chrome/context-view-model.ts +73 -0
- package/src/chrome/index.ts +1 -0
- package/src/chrome/transcript-container.ts +89 -59
- package/src/chrome/transcript-notice.d.ts +35 -0
- package/src/chrome/transcript-notice.ts +83 -0
- package/src/chrome/transcript-status.d.ts +20 -8
- package/src/chrome/transcript-status.ts +29 -29
- package/src/components/editor.d.ts +8 -0
- package/src/components/editor.ts +465 -14
- package/src/components/image.d.ts +20 -0
- package/src/components/image.ts +83 -18
- package/src/components/loader.d.ts +1 -1
- package/src/components/loader.ts +1 -1
- package/src/components/markdown.d.ts +7 -0
- package/src/components/markdown.ts +225 -13
- package/src/hotkeys-markdown.ts +2 -0
- package/src/native/backend.ts +5 -66
- package/src/native/blobs.d.ts +11 -1
- package/src/native/blobs.ts +5 -3
- package/src/native/picker.d.ts +4 -4
- package/src/native/picker.ts +4 -4
- package/src/overlays/advisor-config.ts +10 -12
- package/src/overlays/agent-hub-projection.d.ts +3 -1
- package/src/overlays/agent-hub-projection.ts +6 -5
- package/src/overlays/agent-hub.ts +51 -42
- package/src/overlays/annotation-overlay.ts +125 -37
- package/src/overlays/annotation-types.ts +24 -0
- package/src/overlays/ask-dialog.ts +125 -35
- package/src/overlays/btw-history-panel.ts +124 -12
- package/src/overlays/btw-history.ts +11 -0
- package/src/overlays/btw-panel.ts +8 -4
- package/src/overlays/context-viewer-format.ts +145 -0
- package/src/overlays/context-viewer-overview.ts +381 -0
- package/src/overlays/context-viewer.ts +728 -0
- package/src/overlays/hook-input.ts +2 -0
- package/src/overlays/hook-selector.ts +2 -2
- package/src/overlays/login-dialog.ts +31 -5
- package/src/overlays/mcp-add-wizard.ts +6 -1
- package/src/overlays/model-browser.ts +37 -0
- package/src/overlays/model-hub.ts +1 -7
- package/src/overlays/model-picker.ts +1 -10
- package/src/overlays/oauth-selector.ts +44 -6
- package/src/overlays/pause-screen.ts +166 -33
- package/src/overlays/plan-review-overlay.ts +13 -2
- package/src/overlays/rewind-selector.ts +29 -12
- package/src/overlays/running-subagent-badge.ts +12 -1
- package/src/overlays/session-selector.ts +313 -42
- package/src/overlays/settings-defs.ts +1 -0
- package/src/overlays/usage-dashboard.ts +20 -14
- package/src/prompt/composer.ts +216 -1
- package/src/prompt/custom-editor.ts +6 -1
- package/src/prompt/emoji-autocomplete.ts +0 -2
- package/src/prompt/interactive-context-helpers.ts +29 -4
- package/src/prompt/macos-spelling.ts +24 -15
- package/src/render/extension-links.d.ts +65 -0
- package/src/render/extension-links.ts +214 -0
- package/src/render/hyperlink.d.ts +38 -7
- package/src/render/hyperlink.ts +102 -23
- package/src/render/index.d.ts +1 -0
- package/src/render/index.ts +1 -0
- package/src/render/output-pane.d.ts +1 -1
- package/src/render/output-pane.ts +60 -17
- package/src/render/render-utils.d.ts +7 -1
- package/src/render/render-utils.ts +11 -2
- package/src/setup/scenes/composer.ts +2 -0
- package/src/setup/scenes/glyph.ts +3 -1
- package/src/setup/scenes/model.ts +192 -29
- package/src/setup/scenes/outro.ts +33 -15
- package/src/setup/scenes/sign-in.ts +194 -392
- package/src/setup/scenes/theme.ts +2 -0
- package/src/setup/scenes/types.ts +18 -1
- package/src/setup/startup-splash.ts +8 -7
- package/src/setup/wizard-overlay.ts +164 -35
- package/src/setup/wizard.ts +11 -2
- package/src/status-line/component.ts +10 -14
- package/src/status-line/context-usage.ts +122 -597
- package/src/status-line/host.ts +6 -2
- package/src/terminal-capabilities.d.ts +7 -0
- package/src/terminal-capabilities.ts +10 -0
- package/src/terminal.ts +24 -2
- package/src/theme/defaults.json +1 -0
- package/src/theme/loader.ts +1 -1
- package/src/theme/symbols.d.ts +1 -1
- package/src/theme/symbols.ts +16 -0
- package/src/theme/theme.d.ts +0 -23
- package/src/theme/theme.ts +2 -75
- package/src/tools/ask.d.ts +4 -0
- package/src/tools/ask.ts +4 -0
- package/src/tools/ast-grep.ts +3 -2
- package/src/tools/bash-interactive.d.ts +49 -0
- package/src/tools/bash-interactive.ts +6 -1
- package/src/tools/bash.d.ts +2 -0
- package/src/tools/bash.ts +7 -23
- package/src/tools/default-renderer.d.ts +6 -4
- package/src/tools/default-renderer.ts +9 -6
- package/src/tools/edit.d.ts +3 -1
- package/src/tools/edit.ts +8 -4
- package/src/tools/eval.ts +14 -4
- package/src/tools/fetch.d.ts +1 -0
- package/src/tools/fetch.ts +1 -0
- package/src/tools/find.ts +3 -10
- package/src/tools/github.d.ts +3 -0
- package/src/tools/github.ts +23 -3
- package/src/tools/glob.ts +4 -3
- package/src/tools/grep.ts +3 -4
- package/src/tools/grouped-file-output.d.ts +2 -0
- package/src/tools/grouped-file-output.ts +8 -2
- package/src/tools/irc.d.ts +6 -0
- package/src/tools/irc.ts +6 -0
- package/src/tools/job-widget.ts +13 -1
- package/src/tools/json-tree.d.ts +23 -4
- package/src/tools/json-tree.ts +132 -42
- package/src/tools/lsp.d.ts +2 -0
- package/src/tools/lsp.ts +36 -15
- package/src/tools/mcp.d.ts +7 -6
- package/src/tools/mcp.ts +41 -15
- package/src/tools/native-view.d.ts +1 -1
- package/src/tools/native-view.ts +3 -3
- package/src/tools/read.d.ts +3 -0
- package/src/tools/read.ts +3 -1
- package/src/tools/renderer.d.ts +2 -0
- package/src/tools/renderer.ts +2 -0
- package/src/tools/streaming-output.d.ts +11 -0
- package/src/tools/streaming-output.ts +41 -0
- package/src/tools/task.d.ts +9 -1
- package/src/tools/task.ts +59 -16
- package/src/tools/url-scheme-host.d.ts +17 -0
- package/src/tools/url-scheme-host.ts +21 -0
- package/src/tools/vibe.ts +14 -3
- package/src/tools/wait.d.ts +16 -2
- package/src/tools/wait.ts +16 -2
- package/src/tools/yield.d.ts +1 -1
- package/src/tools/yield.ts +18 -9
- package/src/tui.d.ts +9 -2
- package/src/tui.ts +102 -34
- package/src/vim.d.ts +39 -0
- package/src/vim.ts +313 -22
- package/dist/types/theme/defaults/index.d.ts +0 -10289
- package/src/theme/defaults/alabaster.json +0 -103
- package/src/theme/defaults/amethyst.json +0 -106
- package/src/theme/defaults/anthracite.json +0 -103
- package/src/theme/defaults/basalt.json +0 -101
- package/src/theme/defaults/birch.json +0 -105
- package/src/theme/defaults/dark-abyss.json +0 -101
- package/src/theme/defaults/dark-arctic.json +0 -114
- package/src/theme/defaults/dark-aurora.json +0 -105
- package/src/theme/defaults/dark-catppuccin.json +0 -117
- package/src/theme/defaults/dark-cavern.json +0 -101
- package/src/theme/defaults/dark-celestial.json +0 -116
- package/src/theme/defaults/dark-copper.json +0 -105
- package/src/theme/defaults/dark-cosmos.json +0 -100
- package/src/theme/defaults/dark-cyberpunk.json +0 -112
- package/src/theme/defaults/dark-dracula.json +0 -108
- package/src/theme/defaults/dark-eclipse.json +0 -101
- package/src/theme/defaults/dark-ember.json +0 -105
- package/src/theme/defaults/dark-equinox.json +0 -100
- package/src/theme/defaults/dark-forest.json +0 -106
- package/src/theme/defaults/dark-github.json +0 -115
- package/src/theme/defaults/dark-gruvbox.json +0 -122
- package/src/theme/defaults/dark-lavender.json +0 -105
- package/src/theme/defaults/dark-lunar.json +0 -99
- package/src/theme/defaults/dark-midnight.json +0 -105
- package/src/theme/defaults/dark-monochrome.json +0 -104
- package/src/theme/defaults/dark-monokai.json +0 -108
- package/src/theme/defaults/dark-nebula.json +0 -100
- package/src/theme/defaults/dark-neon-noir.json +0 -110
- package/src/theme/defaults/dark-nord.json +0 -108
- package/src/theme/defaults/dark-ocean.json +0 -111
- package/src/theme/defaults/dark-one.json +0 -110
- package/src/theme/defaults/dark-poimandres.json +0 -125
- package/src/theme/defaults/dark-rainforest.json +0 -101
- package/src/theme/defaults/dark-reef.json +0 -101
- package/src/theme/defaults/dark-retro.json +0 -102
- package/src/theme/defaults/dark-rose-pine.json +0 -106
- package/src/theme/defaults/dark-sakura.json +0 -105
- package/src/theme/defaults/dark-slate.json +0 -105
- package/src/theme/defaults/dark-solarized.json +0 -107
- package/src/theme/defaults/dark-solstice.json +0 -100
- package/src/theme/defaults/dark-starfall.json +0 -101
- package/src/theme/defaults/dark-sunset.json +0 -109
- package/src/theme/defaults/dark-swamp.json +0 -100
- package/src/theme/defaults/dark-synthwave.json +0 -113
- package/src/theme/defaults/dark-taiga.json +0 -101
- package/src/theme/defaults/dark-terminal.json +0 -105
- package/src/theme/defaults/dark-tokyo-night.json +0 -111
- package/src/theme/defaults/dark-tundra.json +0 -101
- package/src/theme/defaults/dark-twilight.json +0 -101
- package/src/theme/defaults/dark-volcanic.json +0 -101
- package/src/theme/defaults/graphite.json +0 -102
- package/src/theme/defaults/index.d.ts +0 -10289
- package/src/theme/defaults/index.ts +0 -203
- package/src/theme/defaults/light-arctic.json +0 -117
- package/src/theme/defaults/light-aurora-day.json +0 -101
- package/src/theme/defaults/light-canyon.json +0 -101
- package/src/theme/defaults/light-catppuccin.json +0 -116
- package/src/theme/defaults/light-cirrus.json +0 -100
- package/src/theme/defaults/light-coral.json +0 -105
- package/src/theme/defaults/light-cyberpunk.json +0 -106
- package/src/theme/defaults/light-dawn.json +0 -100
- package/src/theme/defaults/light-dunes.json +0 -101
- package/src/theme/defaults/light-eucalyptus.json +0 -105
- package/src/theme/defaults/light-forest.json +0 -110
- package/src/theme/defaults/light-frost.json +0 -105
- package/src/theme/defaults/light-github.json +0 -125
- package/src/theme/defaults/light-glacier.json +0 -101
- package/src/theme/defaults/light-gruvbox.json +0 -118
- package/src/theme/defaults/light-haze.json +0 -100
- package/src/theme/defaults/light-honeycomb.json +0 -105
- package/src/theme/defaults/light-lagoon.json +0 -101
- package/src/theme/defaults/light-lavender.json +0 -105
- package/src/theme/defaults/light-meadow.json +0 -101
- package/src/theme/defaults/light-mint.json +0 -105
- package/src/theme/defaults/light-monochrome.json +0 -111
- package/src/theme/defaults/light-ocean.json +0 -109
- package/src/theme/defaults/light-one.json +0 -109
- package/src/theme/defaults/light-opal.json +0 -101
- package/src/theme/defaults/light-orchard.json +0 -101
- package/src/theme/defaults/light-paper.json +0 -105
- package/src/theme/defaults/light-poimandres.json +0 -125
- package/src/theme/defaults/light-prism.json +0 -100
- package/src/theme/defaults/light-retro.json +0 -108
- package/src/theme/defaults/light-sand.json +0 -105
- package/src/theme/defaults/light-savanna.json +0 -101
- package/src/theme/defaults/light-solarized.json +0 -112
- package/src/theme/defaults/light-soleil.json +0 -100
- package/src/theme/defaults/light-sunset.json +0 -109
- package/src/theme/defaults/light-synthwave.json +0 -108
- package/src/theme/defaults/light-tokyo-night.json +0 -121
- package/src/theme/defaults/light-wetland.json +0 -101
- package/src/theme/defaults/light-zenith.json +0 -99
- package/src/theme/defaults/limestone.json +0 -104
- package/src/theme/defaults/mahogany.json +0 -107
- package/src/theme/defaults/marble.json +0 -103
- package/src/theme/defaults/obsidian.json +0 -101
- package/src/theme/defaults/onyx.json +0 -101
- package/src/theme/defaults/pearl.json +0 -103
- package/src/theme/defaults/porcelain.json +0 -101
- package/src/theme/defaults/quartz.json +0 -106
- package/src/theme/defaults/sandstone.json +0 -105
- package/src/theme/defaults/titanium.json +0 -100
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Links whose scheme an extension registered (`pi.registerLinkScheme`). Markdown draws them
|
|
3
|
+
* without the ` (url)` suffix. In a plain terminal the rendered row carries an OSC 8 marker with the
|
|
4
|
+
* URL so a click's cell or a hint tag can be traced back to it ({@link extensionLinkLabels}); the TUI
|
|
5
|
+
* strips that marker from every row it writes ({@link stripExtensionLinkMarkers}), so the terminal
|
|
6
|
+
* never receives the link as a hyperlink it could open.
|
|
7
|
+
*/
|
|
8
|
+
import { isNativeRendering, onNativeRenderingChange } from "../native/state";
|
|
9
|
+
import { TERMINAL } from "../terminal-capabilities";
|
|
10
|
+
import { visibleWidth } from "../utils";
|
|
11
|
+
|
|
12
|
+
let schemes: ReadonlySet<string> = new Set();
|
|
13
|
+
let version = 0;
|
|
14
|
+
let pickingProvider: (() => boolean) | undefined;
|
|
15
|
+
// Tern's native view routes its own link clicks, so markers are drawn only for a plain terminal.
|
|
16
|
+
onNativeRenderingChange(() => {
|
|
17
|
+
version++;
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
/** One OSC 8 sequence (BEL or ST terminated); group 1 is its params, group 2 its URI (empty for a close). */
|
|
21
|
+
const OSC8_PATTERN = /\x1b\]8;([^;\x07\x1b]*);([^\x07\x1b]*)(?:\x07|\x1b\\)/g;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The OSC 8 params tagging omp's own markers, so they are stripped from terminal output even after
|
|
25
|
+
* their scheme is no longer registered. Each drawn link gets its own `-<n>` suffix, derived from the
|
|
26
|
+
* link itself so every render of the same text draws the same bytes; a label wrapped across rows
|
|
27
|
+
* repeats its marker, suffix included, on every row.
|
|
28
|
+
*/
|
|
29
|
+
const MARKER_ID = "id=omp-extension-link";
|
|
30
|
+
const MARKER_PARAMS_PATTERN = /^id=omp-extension-link(?:-\d+)?$/;
|
|
31
|
+
const MARKER_OPEN = `\x1b]8;${MARKER_ID}`;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Set the registered schemes (lowercase, without `:`). Bumps {@link extensionLinksVersion} on any
|
|
35
|
+
* change so cached markdown renders are redrawn.
|
|
36
|
+
*/
|
|
37
|
+
export function setExtensionLinks(next: Iterable<string>): void {
|
|
38
|
+
const nextSchemes = new Set(next);
|
|
39
|
+
if (nextSchemes.size === schemes.size && [...nextSchemes].every(s => schemes.has(s))) return;
|
|
40
|
+
schemes = nextSchemes;
|
|
41
|
+
version++;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Changes whenever the scheme set changes; part of the markdown render cache key. */
|
|
45
|
+
export function extensionLinksVersion(): number {
|
|
46
|
+
return version;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Whether activating a registered-scheme link (a click or a hint tag) reaches its extension: a
|
|
51
|
+
* scheme is registered and the terminal is plain.
|
|
52
|
+
*/
|
|
53
|
+
export function extensionLinksRouted(): boolean {
|
|
54
|
+
return schemes.size > 0 && !isNativeRendering();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Set by the interactive product: whether the user has a way to pick a link drawn now (a bound
|
|
59
|
+
* hint key, mouse clicks). `undefined` when nothing in this process can pick one.
|
|
60
|
+
*/
|
|
61
|
+
export function setExtensionLinkPicking(provider: (() => boolean) | undefined): void {
|
|
62
|
+
pickingProvider = provider;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Whether a registered-scheme link drawn now can be activated: links are routed and the product
|
|
67
|
+
* offers a way to pick them. Process-wide, so a UI-less extension runner (a subagent's, whose
|
|
68
|
+
* transcript the user may focus) answers like the interactive one.
|
|
69
|
+
*/
|
|
70
|
+
export function extensionLinkClicksAvailable(): boolean {
|
|
71
|
+
return extensionLinksRouted() && pickingProvider?.() === true;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The registered scheme `href` uses, or `undefined` for every other link. */
|
|
75
|
+
export function extensionLinkScheme(href: string): string | undefined {
|
|
76
|
+
if (schemes.size === 0) return undefined;
|
|
77
|
+
const colon = href.indexOf(":");
|
|
78
|
+
if (colon <= 0) return undefined;
|
|
79
|
+
const scheme = href.slice(0, colon).toLowerCase();
|
|
80
|
+
return schemes.has(scheme) ? scheme : undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Dotted underline (`4:4`) where the terminal draws styled underlines, else the plain one. */
|
|
84
|
+
const UNDERLINE = TERMINAL.styledUnderlines
|
|
85
|
+
? { on: "\x1b[4:4m", off: "\x1b[4:0m" }
|
|
86
|
+
: { on: "\x1b[4m", off: "\x1b[24m" };
|
|
87
|
+
|
|
88
|
+
/** An SGR sequence; group 1 is its params. */
|
|
89
|
+
const SGR_PATTERN = /\x1b\[([0-9:;]*)m/g;
|
|
90
|
+
|
|
91
|
+
/** Whether an SGR with these params turns underlining off: a full reset, `24` or `4:0`. */
|
|
92
|
+
function endsUnderline(params: string): boolean {
|
|
93
|
+
const codes = params.split(";");
|
|
94
|
+
for (let index = 0; index < codes.length; index++) {
|
|
95
|
+
const code = codes[index]!;
|
|
96
|
+
if (code === "" || code === "0" || code === "24" || code === "4:0") return true;
|
|
97
|
+
// Skip a color's arguments: `38;5;n` / `38;2;r;g;b` (also 48 and 58), whose `0`s are no reset.
|
|
98
|
+
if (code === "38" || code === "48" || code === "58") {
|
|
99
|
+
const mode = codes[index + 1];
|
|
100
|
+
index += mode === "5" ? 2 : mode === "2" ? 4 : 0;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Draw an extension link's label: dotted-underlined (plain underline where the terminal has no
|
|
108
|
+
* styled underlines, re-applied after any style reset inside it) and wrapped in the OSC 8 marker
|
|
109
|
+
* {@link extensionLinkLabels} reads back in a plain terminal; as given in Tern's native view. Never
|
|
110
|
+
* followed by a ` (url)` suffix. `key` tells apart links of one URL drawn near each other; it must
|
|
111
|
+
* not change between renders of the same text, or rows rendered twice stop matching.
|
|
112
|
+
*/
|
|
113
|
+
export function formatExtensionLink(label: string, href: string, key: string): string {
|
|
114
|
+
if (isNativeRendering()) return label;
|
|
115
|
+
const safe = href.replaceAll("\x1b", "").replaceAll("\x07", "");
|
|
116
|
+
if (!safe) return label;
|
|
117
|
+
const body = label.replace(SGR_PATTERN, (sequence, params: string) =>
|
|
118
|
+
endsUnderline(params) ? sequence + UNDERLINE.on : sequence,
|
|
119
|
+
);
|
|
120
|
+
const id = Bun.hash.crc32(`${safe}\0${key}`);
|
|
121
|
+
return `${MARKER_OPEN}-${id};${safe}\x07${UNDERLINE.on}${body}${UNDERLINE.off}\x1b]8;;\x07`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Hint tag letters, home row first. */
|
|
125
|
+
const LINK_HINT_ALPHABET = "asdfghjklqwertyuiopzxcvbnm";
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Tags for `count` links in keyboard link-hint mode: single letters while they suffice, otherwise
|
|
129
|
+
* two letters each, so no tag is a prefix of another. At most the alphabet squared (676) are made;
|
|
130
|
+
* links past that stay untagged.
|
|
131
|
+
*/
|
|
132
|
+
export function linkHintTags(count: number): string[] {
|
|
133
|
+
if (count <= LINK_HINT_ALPHABET.length) return LINK_HINT_ALPHABET.slice(0, Math.max(0, count)).split("");
|
|
134
|
+
const tags: string[] = [];
|
|
135
|
+
for (const first of LINK_HINT_ALPHABET) {
|
|
136
|
+
for (const second of LINK_HINT_ALPHABET) {
|
|
137
|
+
if (tags.length === count) return tags;
|
|
138
|
+
tags.push(`${first}${second}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return tags;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* `line` without omp's extension-link markers (the OSC 8 open and close around each label), for
|
|
146
|
+
* terminal output. Every other hyperlink is kept as is.
|
|
147
|
+
*/
|
|
148
|
+
export function stripExtensionLinkMarkers(line: string): string {
|
|
149
|
+
if (!line.includes(MARKER_OPEN)) return line;
|
|
150
|
+
let inside = false;
|
|
151
|
+
return line.replace(OSC8_PATTERN, (sequence: string, params: string, uri: string) => {
|
|
152
|
+
if (uri === "") {
|
|
153
|
+
const closesOwn = inside;
|
|
154
|
+
inside = false;
|
|
155
|
+
return closesOwn ? "" : sequence;
|
|
156
|
+
}
|
|
157
|
+
inside = MARKER_PARAMS_PATTERN.test(params);
|
|
158
|
+
return inside ? "" : sequence;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** One extension link label drawn on a rendered row (before {@link stripExtensionLinkMarkers}). */
|
|
163
|
+
export interface ExtensionLinkLabel {
|
|
164
|
+
readonly url: string;
|
|
165
|
+
/**
|
|
166
|
+
* The marker's params, unique to each drawn link and repeated on every row a wrapped label
|
|
167
|
+
* spans, so a row's parts of one label can be told from an adjacent label of the same URL.
|
|
168
|
+
*/
|
|
169
|
+
readonly id: string;
|
|
170
|
+
/** First 0-based cell the label covers. */
|
|
171
|
+
readonly start: number;
|
|
172
|
+
/** Cell just past the label. */
|
|
173
|
+
readonly end: number;
|
|
174
|
+
/** Whether only blank cells follow the label on its row, so a wrapped label may go on below. */
|
|
175
|
+
readonly endsRow: boolean;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* The extension link labels drawn on a rendered row, left to right. Only omp's own markers with a
|
|
180
|
+
* registered scheme match, so ordinary hyperlinks (even of a registered scheme) and rows drawn for
|
|
181
|
+
* a scheme that is no longer registered never do.
|
|
182
|
+
*/
|
|
183
|
+
export function extensionLinkLabels(line: string): ExtensionLinkLabel[] {
|
|
184
|
+
if (schemes.size === 0 || !line.includes(MARKER_OPEN)) return [];
|
|
185
|
+
const labels: ExtensionLinkLabel[] = [];
|
|
186
|
+
let x = 0;
|
|
187
|
+
let cursor = 0;
|
|
188
|
+
/** Code-unit index where the last pushed label's text ends. */
|
|
189
|
+
let lastClose = 0;
|
|
190
|
+
let open: { url: string; id: string; start: number } | undefined;
|
|
191
|
+
for (const match of line.matchAll(OSC8_PATTERN)) {
|
|
192
|
+
x += visibleWidth(line.slice(cursor, match.index));
|
|
193
|
+
if (open && x > open.start) {
|
|
194
|
+
labels.push({ ...open, end: x, endsRow: false });
|
|
195
|
+
lastClose = match.index;
|
|
196
|
+
}
|
|
197
|
+
open = undefined;
|
|
198
|
+
const params = match[1]!;
|
|
199
|
+
const uri = match[2]!;
|
|
200
|
+
cursor = match.index + match[0].length;
|
|
201
|
+
if (uri && MARKER_PARAMS_PATTERN.test(params) && extensionLinkScheme(uri)) {
|
|
202
|
+
open = { url: uri, id: params, start: x };
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
x += visibleWidth(line.slice(cursor));
|
|
206
|
+
if (open && x > open.start) {
|
|
207
|
+
labels.push({ ...open, end: x, endsRow: true });
|
|
208
|
+
} else {
|
|
209
|
+
const last = labels.at(-1);
|
|
210
|
+
if (last && Bun.stripANSI(line.slice(lastClose)).trim() === "")
|
|
211
|
+
labels[labels.length - 1] = { ...last, endsRow: true };
|
|
212
|
+
}
|
|
213
|
+
return labels;
|
|
214
|
+
}
|
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
import type { TspSpan } from "@linxiraos/pi-wire";
|
|
2
2
|
import { type TerminalId } from "../terminal-capabilities";
|
|
3
|
+
export interface FileLinkConfig {
|
|
4
|
+
scheme?: string;
|
|
5
|
+
host?: string;
|
|
6
|
+
}
|
|
7
|
+
interface FileUriOptions {
|
|
8
|
+
line?: number;
|
|
9
|
+
col?: number;
|
|
10
|
+
/** Native image open actions need a local file URL rather than a desktop handler. */
|
|
11
|
+
local?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Resolve the remote file-link configuration once at host startup. Passing an
|
|
15
|
+
* explicit object lets SDK hosts and tests configure links without changing the
|
|
16
|
+
* process environment; an empty object restores ordinary file links. An invalid
|
|
17
|
+
* scheme or host logs a warning and keeps ordinary links.
|
|
18
|
+
*/
|
|
19
|
+
export declare function applyFileLinkSetting(config?: FileLinkConfig): void;
|
|
20
|
+
/**
|
|
21
|
+
* A file-link target for `filePath`, or `undefined` when Node cannot encode it.
|
|
22
|
+
*
|
|
23
|
+
* Node rejects a malformed UNC target (a UNC path escaped twice by its author,
|
|
24
|
+
* e.g. `\\\wsl.localhost\…`) with `ERR_INVALID_ARG_VALUE: Empty UNC servername`.
|
|
25
|
+
* A stored session keeps whatever a tool call recorded, so a transcript must
|
|
26
|
+
* render such a path without a link rather than throw while it rebuilds.
|
|
27
|
+
*/
|
|
28
|
+
export declare function tryFileUri(filePath: string, opts?: FileUriOptions): string | undefined;
|
|
3
29
|
/**
|
|
4
30
|
* Build the OSC 8 target for a file path on `terminalId`.
|
|
5
31
|
*
|
|
@@ -14,12 +40,16 @@ import { type TerminalId } from "../terminal-capabilities";
|
|
|
14
40
|
* The VS Code family instead navigates the documented
|
|
15
41
|
* `vscode://file/<path>:<line>:<col>` form. Everywhere else the plain `file:`
|
|
16
42
|
* URI is right, with the location left in the visible text — terminals that
|
|
17
|
-
* parse a `path:line:col` suffix resolve that on their own.
|
|
43
|
+
* parse a `path:line:col` suffix resolve that on their own. A configured custom
|
|
44
|
+
* handler takes precedence and receives optional `line`/`col` query parameters.
|
|
45
|
+
*
|
|
46
|
+
* Returns `undefined` when `filePath` cannot be encoded — a malformed UNC
|
|
47
|
+
* target on the `file:` branch, or a lone surrogate on the `vscode://` branch.
|
|
18
48
|
*/
|
|
19
49
|
export declare function fileUriForTerminal(filePath: string, opts: {
|
|
20
50
|
line?: number;
|
|
21
51
|
col?: number;
|
|
22
|
-
} | undefined, terminalId: TerminalId): string;
|
|
52
|
+
} | undefined, terminalId: TerminalId): string | undefined;
|
|
23
53
|
/**
|
|
24
54
|
* Returns true when OSC 8 hyperlinks should be emitted.
|
|
25
55
|
*
|
|
@@ -73,9 +103,8 @@ export declare function urlLinkSpan(target: string, displayText: string, s?: str
|
|
|
73
103
|
/** Whether native link spans and nodes may carry an `href`: everything but an explicit `off` policy. */
|
|
74
104
|
export declare function isNativeLinkEnabled(): boolean;
|
|
75
105
|
/**
|
|
76
|
-
* A native link span to a filesystem path
|
|
77
|
-
*
|
|
78
|
-
* text). Honours an explicit `off` policy.
|
|
106
|
+
* A native link span to a filesystem path using the configured file-link
|
|
107
|
+
* target. Honours an explicit `off` policy.
|
|
79
108
|
*/
|
|
80
109
|
export declare function fileLinkSpan(filePath: string, displayText: string, s?: string): TspSpan;
|
|
81
110
|
/**
|
|
@@ -84,13 +113,15 @@ export declare function fileLinkSpan(filePath: string, displayText: string, s?:
|
|
|
84
113
|
* Returns `displayText` unchanged when hyperlinks are disabled or when
|
|
85
114
|
* the text already contains an OSC 8 sequence (prevents double-wrapping).
|
|
86
115
|
* Relative paths resolve against the current working directory before URI
|
|
87
|
-
* encoding so the OSC 8 target is always a valid `file://` URL.
|
|
116
|
+
* encoding so the OSC 8 target is always a valid `file://` URL. A path Node
|
|
117
|
+
* cannot encode renders as `displayText` with no link.
|
|
88
118
|
*
|
|
89
119
|
* @param filePath - Filesystem path
|
|
90
120
|
* @param displayText - Text to render as the hyperlink anchor (may contain ANSI codes)
|
|
91
|
-
* @param opts - Optional line/col position
|
|
121
|
+
* @param opts - Optional line/col position (custom handlers use query params; VS Code uses a path suffix)
|
|
92
122
|
*/
|
|
93
123
|
export declare function fileHyperlink(filePath: string, displayText: string, opts?: {
|
|
94
124
|
line?: number;
|
|
95
125
|
col?: number;
|
|
96
126
|
}): string;
|
|
127
|
+
export {};
|
package/src/render/hyperlink.ts
CHANGED
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
* sequences when the active terminal supports hyperlinks and the user setting
|
|
6
6
|
* permits it. Falls back to plain text when disabled.
|
|
7
7
|
*/
|
|
8
|
+
import * as os from "node:os";
|
|
8
9
|
import * as url from "node:url";
|
|
10
|
+
import { logger } from "@linxiraos/pi-utils";
|
|
9
11
|
import type { TspSpan } from "@linxiraos/pi-wire";
|
|
10
12
|
import { span } from "../native/describe";
|
|
11
13
|
import { setTerminalHyperlinks, TERMINAL, type TerminalId } from "../terminal-capabilities";
|
|
@@ -24,6 +26,52 @@ const DETECTED_TERMINAL_HYPERLINKS = TERMINAL.hyperlinks;
|
|
|
24
26
|
type HyperlinkMode = "off" | "auto" | "always";
|
|
25
27
|
let hyperlinkMode: HyperlinkMode = "auto";
|
|
26
28
|
|
|
29
|
+
export interface FileLinkConfig {
|
|
30
|
+
scheme?: string;
|
|
31
|
+
host?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface FileUriOptions {
|
|
35
|
+
line?: number;
|
|
36
|
+
col?: number;
|
|
37
|
+
/** Native image open actions need a local file URL rather than a desktop handler. */
|
|
38
|
+
local?: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let fileLinkTarget: { scheme: string; host: string } | undefined;
|
|
42
|
+
|
|
43
|
+
/** URI scheme syntax (RFC 3986 §3.1), matched after lowercasing. */
|
|
44
|
+
const FILE_LINK_SCHEME = /^[a-z][a-z0-9+.-]*$/;
|
|
45
|
+
/** A bare host name with an optional port: no userinfo, path, query, or whitespace that would reshape the URI. */
|
|
46
|
+
const FILE_LINK_HOST = /^[A-Za-z0-9._-]+(?::\d{1,5})?$/;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Resolve the remote file-link configuration once at host startup. Passing an
|
|
50
|
+
* explicit object lets SDK hosts and tests configure links without changing the
|
|
51
|
+
* process environment; an empty object restores ordinary file links. An invalid
|
|
52
|
+
* scheme or host logs a warning and keeps ordinary links.
|
|
53
|
+
*/
|
|
54
|
+
export function applyFileLinkSetting(
|
|
55
|
+
config: FileLinkConfig = {
|
|
56
|
+
scheme: Bun.env.ZETA_LINK_SCHEME,
|
|
57
|
+
host: Bun.env.ZETA_LINK_HOST,
|
|
58
|
+
},
|
|
59
|
+
): void {
|
|
60
|
+
fileLinkTarget = undefined;
|
|
61
|
+
if (!config.scheme) return;
|
|
62
|
+
const scheme = config.scheme.toLowerCase();
|
|
63
|
+
if (!FILE_LINK_SCHEME.test(scheme)) {
|
|
64
|
+
logger.warn("Invalid ZETA_LINK_SCHEME; using ordinary file links", { scheme: config.scheme });
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const host = config.host || os.hostname();
|
|
68
|
+
if (!FILE_LINK_HOST.test(host)) {
|
|
69
|
+
logger.warn("Invalid ZETA_LINK_HOST; using ordinary file links", { host });
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
fileLinkTarget = { scheme, host };
|
|
73
|
+
}
|
|
74
|
+
|
|
27
75
|
/** Stable 8-char hex ID derived from a URI — hints terminals to coalesce identical adjacent links. */
|
|
28
76
|
function buildLinkId(uri: string): string {
|
|
29
77
|
let h = 0;
|
|
@@ -34,6 +82,30 @@ function buildLinkId(uri: string): string {
|
|
|
34
82
|
return (h >>> 0).toString(16).padStart(8, "0");
|
|
35
83
|
}
|
|
36
84
|
|
|
85
|
+
/**
|
|
86
|
+
* A file-link target for `filePath`, or `undefined` when Node cannot encode it.
|
|
87
|
+
*
|
|
88
|
+
* Node rejects a malformed UNC target (a UNC path escaped twice by its author,
|
|
89
|
+
* e.g. `\\\wsl.localhost\…`) with `ERR_INVALID_ARG_VALUE: Empty UNC servername`.
|
|
90
|
+
* A stored session keeps whatever a tool call recorded, so a transcript must
|
|
91
|
+
* render such a path without a link rather than throw while it rebuilds.
|
|
92
|
+
*/
|
|
93
|
+
export function tryFileUri(filePath: string, opts?: FileUriOptions): string | undefined {
|
|
94
|
+
try {
|
|
95
|
+
const fileUrl = url.pathToFileURL(filePath);
|
|
96
|
+
if (!fileLinkTarget || opts?.local) return fileUrl.href;
|
|
97
|
+
// Preserve UNC servers so the handler can reconstruct the network path.
|
|
98
|
+
const targetPath = fileUrl.host ? `//${fileUrl.host}${fileUrl.pathname}` : fileUrl.pathname;
|
|
99
|
+
const position = new URLSearchParams();
|
|
100
|
+
if (opts?.line !== undefined) position.set("line", String(opts.line));
|
|
101
|
+
if (opts?.col !== undefined) position.set("col", String(opts.col));
|
|
102
|
+
const query = position.size ? `?${position}` : "";
|
|
103
|
+
return `${fileLinkTarget.scheme}://${fileLinkTarget.host}${targetPath}${query}`;
|
|
104
|
+
} catch {
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
37
109
|
/**
|
|
38
110
|
* Build the OSC 8 target for a file path on `terminalId`.
|
|
39
111
|
*
|
|
@@ -48,30 +120,35 @@ function buildLinkId(uri: string): string {
|
|
|
48
120
|
* The VS Code family instead navigates the documented
|
|
49
121
|
* `vscode://file/<path>:<line>:<col>` form. Everywhere else the plain `file:`
|
|
50
122
|
* URI is right, with the location left in the visible text — terminals that
|
|
51
|
-
* parse a `path:line:col` suffix resolve that on their own.
|
|
123
|
+
* parse a `path:line:col` suffix resolve that on their own. A configured custom
|
|
124
|
+
* handler takes precedence and receives optional `line`/`col` query parameters.
|
|
125
|
+
*
|
|
126
|
+
* Returns `undefined` when `filePath` cannot be encoded — a malformed UNC
|
|
127
|
+
* target on the `file:` branch, or a lone surrogate on the `vscode://` branch.
|
|
52
128
|
*/
|
|
53
129
|
export function fileUriForTerminal(
|
|
54
130
|
filePath: string,
|
|
55
131
|
opts: { line?: number; col?: number } | undefined,
|
|
56
132
|
terminalId: TerminalId,
|
|
57
|
-
): string {
|
|
58
|
-
if (terminalId !== "vscode") return
|
|
133
|
+
): string | undefined {
|
|
134
|
+
if (fileLinkTarget || terminalId !== "vscode") return tryFileUri(filePath, opts);
|
|
59
135
|
// vscode:// takes a filesystem path with forward slashes. Encode each
|
|
60
136
|
// segment independently so separators and a Windows drive colon stay
|
|
61
137
|
// structural while reserved bytes in file names cannot become URI syntax.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
138
|
+
try {
|
|
139
|
+
const asPath = filePath.replace(/\\/gu, "/");
|
|
140
|
+
const encodedPath = asPath
|
|
141
|
+
.split("/")
|
|
142
|
+
.map((segment, index) => (index === 0 && /^[a-z]:$/iu.test(segment) ? segment : encodeURIComponent(segment)))
|
|
143
|
+
.join("/");
|
|
144
|
+
const position =
|
|
145
|
+
opts?.line === undefined ? "" : opts.col === undefined ? `:${opts.line}` : `:${opts.line}:${opts.col}`;
|
|
146
|
+
return `vscode://file${encodedPath.startsWith("/") ? "" : "/"}${encodedPath}${position}`;
|
|
147
|
+
} catch {
|
|
148
|
+
// `encodeURIComponent` throws URIError on a lone surrogate, which a
|
|
149
|
+
// model-authored path can carry; the row keeps its text and loses the link.
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
75
152
|
}
|
|
76
153
|
|
|
77
154
|
/**
|
|
@@ -202,13 +279,13 @@ export function isNativeLinkEnabled(): boolean {
|
|
|
202
279
|
}
|
|
203
280
|
|
|
204
281
|
/**
|
|
205
|
-
* A native link span to a filesystem path
|
|
206
|
-
*
|
|
207
|
-
* text). Honours an explicit `off` policy.
|
|
282
|
+
* A native link span to a filesystem path using the configured file-link
|
|
283
|
+
* target. Honours an explicit `off` policy.
|
|
208
284
|
*/
|
|
209
285
|
export function fileLinkSpan(filePath: string, displayText: string, s = "path"): TspSpan {
|
|
210
286
|
if (hyperlinkMode === "off") return span(displayText, s);
|
|
211
|
-
const
|
|
287
|
+
const uri = tryFileUri(filePath);
|
|
288
|
+
const href = uri === undefined ? undefined : safeHyperlinkUri(uri);
|
|
212
289
|
return href ? span(displayText, s, { href }) : span(displayText, s);
|
|
213
290
|
}
|
|
214
291
|
|
|
@@ -218,12 +295,14 @@ export function fileLinkSpan(filePath: string, displayText: string, s = "path"):
|
|
|
218
295
|
* Returns `displayText` unchanged when hyperlinks are disabled or when
|
|
219
296
|
* the text already contains an OSC 8 sequence (prevents double-wrapping).
|
|
220
297
|
* Relative paths resolve against the current working directory before URI
|
|
221
|
-
* encoding so the OSC 8 target is always a valid `file://` URL.
|
|
298
|
+
* encoding so the OSC 8 target is always a valid `file://` URL. A path Node
|
|
299
|
+
* cannot encode renders as `displayText` with no link.
|
|
222
300
|
*
|
|
223
301
|
* @param filePath - Filesystem path
|
|
224
302
|
* @param displayText - Text to render as the hyperlink anchor (may contain ANSI codes)
|
|
225
|
-
* @param opts - Optional line/col position
|
|
303
|
+
* @param opts - Optional line/col position (custom handlers use query params; VS Code uses a path suffix)
|
|
226
304
|
*/
|
|
227
305
|
export function fileHyperlink(filePath: string, displayText: string, opts?: { line?: number; col?: number }): string {
|
|
228
|
-
|
|
306
|
+
const uri = fileUriForTerminal(filePath, opts, TERMINAL.id);
|
|
307
|
+
return uri ? wrapHyperlink(uri, displayText) : displayText;
|
|
229
308
|
}
|
package/src/render/index.d.ts
CHANGED
package/src/render/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DescribeContext, NativeNode } from "../native/node";
|
|
2
|
-
import type
|
|
2
|
+
import { type Theme } from "../theme/theme";
|
|
3
3
|
import type { Component } from "../tui";
|
|
4
4
|
/** Which side of an output stream remains visible when the pane is capped. */
|
|
5
5
|
export type OutputPaneEdge = "head" | "tail";
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Text } from "../components/text";
|
|
2
2
|
import { ansi } from "../native/describe";
|
|
3
|
+
import { Memo } from "../native/memo";
|
|
3
4
|
import type { DescribeContext, NativeNode } from "../native/node";
|
|
4
5
|
import { ImageProtocol, TERMINAL } from "../terminal-capabilities";
|
|
5
|
-
import type
|
|
6
|
+
import { getThemeEpoch, type Theme } from "../theme/theme";
|
|
6
7
|
import type { Component } from "../tui";
|
|
7
|
-
import { getPaddingX } from "../utils";
|
|
8
|
+
import { getPaddingX, getWidthConfigEpoch } from "../utils";
|
|
8
9
|
import { truncateToVisualLines } from "../chrome/visual-truncate";
|
|
9
10
|
import { getSixelLineMask } from "./sixel";
|
|
10
11
|
import { formatExpandHint, replaceTabs } from "./render-utils";
|
|
@@ -158,8 +159,17 @@ export class OutputPane implements Component {
|
|
|
158
159
|
#lines: string[] = [];
|
|
159
160
|
#pendingCarriageReturn = false;
|
|
160
161
|
#text: Text;
|
|
161
|
-
|
|
162
|
+
/** The content last handed to the inner `Text`, compared by identity. */
|
|
163
|
+
#renderContent: string | undefined;
|
|
162
164
|
#native: NativeNode | undefined;
|
|
165
|
+
/**
|
|
166
|
+
* The styled-and-joined content of the last render, kept with the inputs
|
|
167
|
+
* that produced it. A pane re-renders every frame while it sits in the live
|
|
168
|
+
* transcript tail, but its content only changes when its rows, presentation,
|
|
169
|
+
* width, theme, or image protocol change — so the styling, joining and
|
|
170
|
+
* hashing would otherwise be repeated work on every frame.
|
|
171
|
+
*/
|
|
172
|
+
#memo = new Memo<string>();
|
|
163
173
|
|
|
164
174
|
constructor(theme: Theme, options: OutputPaneOptions, text = "") {
|
|
165
175
|
this.#theme = theme;
|
|
@@ -276,34 +286,67 @@ export class OutputPane implements Component {
|
|
|
276
286
|
return this.#native;
|
|
277
287
|
}
|
|
278
288
|
|
|
289
|
+
/**
|
|
290
|
+
* The content the last render produced, rebuilt only when one of the
|
|
291
|
+
* inputs it depends on changes.
|
|
292
|
+
*
|
|
293
|
+
* The pane's own state — the stored rows and the options — changes only
|
|
294
|
+
* through methods that call {@link OutputPane.invalidate}, which drops
|
|
295
|
+
* this memo. The dependencies below are the inputs that can change
|
|
296
|
+
* *without* the pane hearing about it, and every one of them shapes the
|
|
297
|
+
* content:
|
|
298
|
+
*
|
|
299
|
+
* - `contentWidth` — the wrapping width that feeds the visual cap as well
|
|
300
|
+
* as the inner `Text` render: `width` minus both horizontal paddings.
|
|
301
|
+
* - `widthConfigEpoch` — the width-affecting runtime configuration (the
|
|
302
|
+
* Hangul compatibility-Jamo width), which `visibleWidth` — and so the
|
|
303
|
+
* visual cap — depends on.
|
|
304
|
+
* - `themeEpoch` — the active theme's colors, which `styleLine` bakes into
|
|
305
|
+
* the styled rows and which the inner `Text` re-resolves on every render.
|
|
306
|
+
* - `imageProtocol` — read by the formatter to decide whether rows carry
|
|
307
|
+
* sixel payload that must not be styled or split.
|
|
308
|
+
*
|
|
309
|
+
* A `styleLine` whose *captured* state changes without the pane hearing
|
|
310
|
+
* about it would break this. Callers must call
|
|
311
|
+
* {@link OutputPane.invalidate} when that happens.
|
|
312
|
+
*/
|
|
313
|
+
#renderDeps(): readonly unknown[] {
|
|
314
|
+
return [getWidthConfigEpoch(), getThemeEpoch(), TERMINAL.imageProtocol];
|
|
315
|
+
}
|
|
316
|
+
|
|
279
317
|
render(width: number): readonly string[] {
|
|
280
318
|
const paddingX = getPaddingX(this.#options.paddingX ?? 0);
|
|
281
319
|
const contentWidth = Math.max(1, width - paddingX * 2);
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
320
|
+
const content = this.#memo.get([...this.#renderDeps(), contentWidth], () => {
|
|
321
|
+
const formatted = formatOutputPaneLines(
|
|
322
|
+
{
|
|
323
|
+
...this.#options,
|
|
324
|
+
lines: this.#lines,
|
|
325
|
+
width: contentWidth,
|
|
326
|
+
},
|
|
327
|
+
this.#theme,
|
|
328
|
+
);
|
|
329
|
+
return `${this.#options.leadingBlank && formatted.lines.length > 0 ? "\n" : ""}${formatted.lines.join("\n")}`;
|
|
330
|
+
});
|
|
331
|
+
// The memo hands back the same string while its inputs hold, so the
|
|
332
|
+
// identity check is a pointer compare — no re-hash of the content.
|
|
333
|
+
if (content !== this.#renderContent) {
|
|
334
|
+
this.#renderContent = content;
|
|
294
335
|
this.#text.setText(content);
|
|
295
336
|
}
|
|
296
337
|
return this.#text.render(width);
|
|
297
338
|
}
|
|
298
339
|
|
|
299
340
|
invalidate(): void {
|
|
300
|
-
this.#
|
|
341
|
+
this.#renderContent = undefined;
|
|
301
342
|
this.#native = undefined;
|
|
343
|
+
this.#memo.clear();
|
|
302
344
|
this.#text.invalidate();
|
|
303
345
|
}
|
|
304
346
|
|
|
305
347
|
releaseRenderCaches(): void {
|
|
306
|
-
this.#
|
|
348
|
+
this.#renderContent = undefined;
|
|
349
|
+
this.#memo.clear();
|
|
307
350
|
this.#text.setText("");
|
|
308
351
|
this.#text.releaseRenderCaches();
|
|
309
352
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* tool renderers to ensure a unified TUI experience.
|
|
6
6
|
*/
|
|
7
7
|
import { ThinkingLevel } from "@linxiraos/pi-agent-core";
|
|
8
|
-
import
|
|
8
|
+
import { Ellipsis } from "@linxiraos/pi-natives";
|
|
9
9
|
import type { Theme } from "../theme/theme";
|
|
10
10
|
import type { Component } from "../tui";
|
|
11
11
|
export { Ellipsis } from "@linxiraos/pi-natives";
|
|
@@ -284,6 +284,12 @@ export declare function capParseErrors(errors: string[] | undefined, limit?: num
|
|
|
284
284
|
export declare function createCachedComponent(getExpanded: () => boolean, compute: (width: number, expanded: boolean) => string[], options?: {
|
|
285
285
|
paddingX?: number;
|
|
286
286
|
}): Component;
|
|
287
|
+
/**
|
|
288
|
+
* Fit a status header plus body rows to `width` for search-style results. The
|
|
289
|
+
* header soft-wraps so its trailing summary meta (counts, `truncated`) stays
|
|
290
|
+
* visible behind a long pattern; body rows keep single-row truncation.
|
|
291
|
+
*/
|
|
292
|
+
export declare function fitHeaderedRows(header: string, rows: readonly string[], width: number): string[];
|
|
287
293
|
/**
|
|
288
294
|
* Single-slot memo for an expensive rendered string (syntax highlighting, diff
|
|
289
295
|
* coloring) keyed by the exact inputs that shape the bytes: theme instance,
|