@linxiraos/pi-tui 1.4.6 → 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 +194 -195
- package/README.md +34 -34
- package/dist/types/app-keybindings.d.ts +15 -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/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/markdown.d.ts +7 -0
- package/dist/types/native/blobs.d.ts +2 -1
- package/dist/types/native/picker.d.ts +4 -4
- package/dist/types/overlays/annotation-overlay.d.ts +7 -1
- package/dist/types/overlays/annotation-types.d.ts +28 -0
- package/dist/types/overlays/login-dialog.d.ts +5 -1
- package/dist/types/overlays/model-browser.d.ts +10 -1
- package/dist/types/overlays/oauth-selector.d.ts +23 -0
- 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/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/render/extension-links.d.ts +65 -0
- package/dist/types/render/hyperlink.d.ts +25 -7
- package/dist/types/render/index.d.ts +1 -0
- 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 +1 -1
- package/dist/types/status-line/context-usage.d.ts +28 -6
- package/dist/types/status-line/host.d.ts +6 -2
- package/dist/types/theme/theme.d.ts +0 -23
- 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/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 +6 -5
- package/dist/types/tools/native-view.d.ts +1 -1
- 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/yield.d.ts +1 -1
- package/dist/types/tui.d.ts +7 -2
- package/package.json +10 -14
- package/src/app-keybindings.d.ts +15 -0
- package/src/app-keybindings.ts +15 -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 +6 -0
- 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/reply-write.d.ts +48 -0
- package/src/chat/reply-write.ts +127 -0
- 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/index.ts +1 -0
- 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 +10 -1
- package/src/components/markdown.d.ts +7 -0
- package/src/components/markdown.ts +116 -6
- package/src/hotkeys-markdown.ts +1 -0
- package/src/native/backend.ts +5 -66
- package/src/native/blobs.d.ts +2 -1
- package/src/native/blobs.ts +3 -2
- package/src/native/picker.d.ts +4 -4
- package/src/native/picker.ts +4 -4
- package/src/overlays/advisor-config.ts +1 -10
- package/src/overlays/annotation-overlay.ts +125 -37
- package/src/overlays/annotation-types.ts +24 -0
- package/src/overlays/hook-selector.ts +2 -2
- package/src/overlays/login-dialog.ts +31 -5
- package/src/overlays/mcp-add-wizard.ts +1 -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/plan-review-overlay.ts +13 -2
- package/src/overlays/rewind-selector.ts +29 -12
- package/src/overlays/session-selector.ts +313 -42
- package/src/overlays/usage-dashboard.ts +5 -12
- 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/render/extension-links.d.ts +65 -0
- package/src/render/extension-links.ts +214 -0
- package/src/render/hyperlink.d.ts +25 -7
- package/src/render/hyperlink.ts +65 -9
- package/src/render/index.d.ts +1 -0
- package/src/render/index.ts +1 -0
- 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 +196 -400
- 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 +4 -10
- package/src/status-line/context-usage.ts +72 -21
- package/src/status-line/host.ts +6 -2
- package/src/terminal.ts +24 -2
- package/src/theme/defaults.json +1 -0
- package/src/theme/loader.ts +1 -1
- package/src/theme/theme.d.ts +0 -23
- package/src/theme/theme.ts +2 -75
- 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 +2 -0
- package/src/tools/default-renderer.d.ts +6 -4
- package/src/tools/default-renderer.ts +9 -6
- package/src/tools/eval.ts +14 -4
- 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 +6 -5
- package/src/tools/mcp.ts +20 -12
- package/src/tools/native-view.d.ts +1 -1
- package/src/tools/native-view.ts +1 -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/yield.d.ts +1 -1
- package/src/tools/yield.ts +18 -9
- package/src/tui.d.ts +7 -2
- package/src/tui.ts +43 -15
- 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
package/src/tools/json-tree.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* JSON tree rendering utilities shared across tool renderers.
|
|
3
3
|
*/
|
|
4
4
|
import { INTENT_FIELD, type TspSpan, type TspTreeNode } from "@linxiraos/pi-wire";
|
|
5
|
-
import { sanitizeText } from "@linxiraos/pi-utils";
|
|
5
|
+
import { sanitizeText, sanitizeTextDeep } from "@linxiraos/pi-utils";
|
|
6
6
|
import { TreeView, treeRowPrefix } from "../components/tree-view";
|
|
7
7
|
import { truncateToWidth } from "../render/render-utils";
|
|
8
8
|
import type { Theme, ThemeColor } from "../theme/theme";
|
|
@@ -22,6 +22,8 @@ export const JSON_TREE_MAX_LINES_EXPANDED = 200;
|
|
|
22
22
|
export const JSON_TREE_SCALAR_LEN_COLLAPSED = 60;
|
|
23
23
|
/** Maximum expanded JSON scalar width. */
|
|
24
24
|
export const JSON_TREE_SCALAR_LEN_EXPANDED = 2000;
|
|
25
|
+
/** Characters a container's one-line form may take before a JSON tree lists its entries instead. */
|
|
26
|
+
export const JSON_TREE_INLINE_LEN = 60;
|
|
25
27
|
|
|
26
28
|
const HIDDEN_ARG_KEYS = { [INTENT_FIELD]: 1, __partialJson: 1 };
|
|
27
29
|
const DEFAULT_HIDDEN_ROOT_KEYS: readonly string[] = Object.keys(HIDDEN_ARG_KEYS);
|
|
@@ -83,7 +85,7 @@ export function formatArgsInline(
|
|
|
83
85
|
const pairs: string[] = [];
|
|
84
86
|
let length = 0;
|
|
85
87
|
for (const key in args) {
|
|
86
|
-
if (!Object.hasOwn(args, key)) continue;
|
|
88
|
+
if (!Object.hasOwn(args, key) || key in HIDDEN_ARG_KEYS) continue;
|
|
87
89
|
const pair = `${options.sanitizeText?.(key) ?? key}=${formatScalar(args[key], 24, options)}`;
|
|
88
90
|
const added = pair.length + (pairs.length > 0 ? 2 : 0);
|
|
89
91
|
if (length + added > maxWidth && pairs.length > 0) {
|
|
@@ -155,6 +157,57 @@ export function formatOutputInline(data: unknown, maxWidth = 80): string {
|
|
|
155
157
|
return `Output: ${formatArgsInline(data as Record<string, unknown>, maxWidth - "Output: ".length, options) || "{}"}`;
|
|
156
158
|
}
|
|
157
159
|
|
|
160
|
+
/** Object keys a one-line JSON form shows unquoted. */
|
|
161
|
+
const BARE_KEY = /^[\w$-]+$/;
|
|
162
|
+
|
|
163
|
+
/** One styled run of a one-line JSON form. */
|
|
164
|
+
type InlineRun = readonly [text: string, color: ThemeColor];
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* A container's one-line form (`[[3, "vt"], 98]`, `{lines: 70, done: true}`)
|
|
168
|
+
* as styled runs, so tree rows show small containers whole instead of one row
|
|
169
|
+
* per value; undefined for a scalar or a form past {@link JSON_TREE_INLINE_LEN}
|
|
170
|
+
* characters. Keys stay bare unless {@link BARE_KEY} rejects them, strings are
|
|
171
|
+
* JSON-escaped, and `clean` sanitizes both first.
|
|
172
|
+
*/
|
|
173
|
+
function inlineJson(value: unknown, clean: (text: string) => string): InlineRun[] | undefined {
|
|
174
|
+
if (!Array.isArray(value) && !isRecord(value)) return undefined;
|
|
175
|
+
const runs: InlineRun[] = [];
|
|
176
|
+
let length = 0;
|
|
177
|
+
// Every container pushes a bracket before descending, so cycles hit the cap too.
|
|
178
|
+
const push = (text: string, color: ThemeColor): boolean => {
|
|
179
|
+
length += text.length;
|
|
180
|
+
if (length > JSON_TREE_INLINE_LEN) return false;
|
|
181
|
+
const last = runs.at(-1);
|
|
182
|
+
if (last?.[1] === color) runs[runs.length - 1] = [last[0] + text, color];
|
|
183
|
+
else runs.push([text, color]);
|
|
184
|
+
return true;
|
|
185
|
+
};
|
|
186
|
+
const walk = (entry: unknown): boolean => {
|
|
187
|
+
if (Array.isArray(entry)) {
|
|
188
|
+
if (!push("[", "muted")) return false;
|
|
189
|
+
for (let index = 0; index < entry.length; index++) {
|
|
190
|
+
if ((index > 0 && !push(", ", "muted")) || !walk(entry[index])) return false;
|
|
191
|
+
}
|
|
192
|
+
return push("]", "muted");
|
|
193
|
+
}
|
|
194
|
+
if (isRecord(entry)) {
|
|
195
|
+
if (!push("{", "muted")) return false;
|
|
196
|
+
let sep = "";
|
|
197
|
+
for (const key in entry) {
|
|
198
|
+
const name = clean(key);
|
|
199
|
+
if (!push(`${sep}${BARE_KEY.test(name) ? name : JSON.stringify(name)}: `, "muted")) return false;
|
|
200
|
+
if (!walk(entry[key])) return false;
|
|
201
|
+
sep = ", ";
|
|
202
|
+
}
|
|
203
|
+
return push("}", "muted");
|
|
204
|
+
}
|
|
205
|
+
if (typeof entry === "string") return push(JSON.stringify(clean(entry)), "syntaxString");
|
|
206
|
+
return push(clean(formatScalar(entry, JSON_TREE_INLINE_LEN)), jsonScalarToken(entry));
|
|
207
|
+
};
|
|
208
|
+
return walk(value) ? runs : undefined;
|
|
209
|
+
}
|
|
210
|
+
|
|
158
211
|
/** JSON hierarchy policy accepted by {@link renderJsonTreeLines}. */
|
|
159
212
|
export interface JsonTreeRenderOptions {
|
|
160
213
|
maxDepth: number;
|
|
@@ -176,7 +229,7 @@ export interface JsonTreeRenderOptions {
|
|
|
176
229
|
rootConnectors?: "hooked" | "siblings";
|
|
177
230
|
}
|
|
178
231
|
|
|
179
|
-
type JsonTreeNodeKind = "array" | "object" | "scalar" | "placeholder";
|
|
232
|
+
type JsonTreeNodeKind = "array" | "object" | "inline" | "scalar" | "placeholder";
|
|
180
233
|
|
|
181
234
|
interface JsonTreeNode {
|
|
182
235
|
id: number;
|
|
@@ -184,6 +237,10 @@ interface JsonTreeNode {
|
|
|
184
237
|
value: unknown;
|
|
185
238
|
depth: number;
|
|
186
239
|
kind: JsonTreeNodeKind;
|
|
240
|
+
/** The key's color: `dim` for array indices, else `muted`. */
|
|
241
|
+
keyColor?: ThemeColor;
|
|
242
|
+
/** The one-line form of an `inline` container. */
|
|
243
|
+
inline?: readonly InlineRun[];
|
|
187
244
|
placeholder?: "…";
|
|
188
245
|
children?: readonly JsonTreeNode[];
|
|
189
246
|
}
|
|
@@ -195,7 +252,8 @@ function jsonNodeKind(value: unknown): JsonTreeNodeKind {
|
|
|
195
252
|
}
|
|
196
253
|
|
|
197
254
|
/**
|
|
198
|
-
* Render a JSON value as bounded tree lines
|
|
255
|
+
* Render a JSON value as bounded tree lines, containers that fit
|
|
256
|
+
* {@link JSON_TREE_INLINE_LEN} on one row. The positional form remains the
|
|
199
257
|
* public tool-renderer contract; the options form exposes sanitization and root
|
|
200
258
|
* connector policy for specialized adapters such as nested task output.
|
|
201
259
|
*/
|
|
@@ -236,26 +294,18 @@ export function renderJsonTreeLines(
|
|
|
236
294
|
const hookedRoots = (options.rootConnectors ?? "hooked") === "hooked";
|
|
237
295
|
let nextId = 0;
|
|
238
296
|
|
|
239
|
-
const node = (nodeValue: unknown, key: string | undefined, depth: number): JsonTreeNode =>
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
value: nodeValue,
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
297
|
+
const node = (nodeValue: unknown, key: string | undefined, depth: number, keyColor?: ThemeColor): JsonTreeNode => {
|
|
298
|
+
const inline = inlineJson(nodeValue, sanitize);
|
|
299
|
+
const kind = inline ? "inline" : jsonNodeKind(nodeValue);
|
|
300
|
+
return { id: nextId++, key, value: nodeValue, depth, kind, keyColor, inline };
|
|
301
|
+
};
|
|
302
|
+
const entryNodes = (entries: readonly JsonEntry[], depth: number): JsonTreeNode[] =>
|
|
303
|
+
entries.map(([key, child, keyColor]) => node(child, key, depth, keyColor));
|
|
246
304
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
if (!hiddenRootKeys.includes(key)) objectRoots.push(node(value[key], key, 1));
|
|
252
|
-
}
|
|
253
|
-
roots = objectRoots;
|
|
254
|
-
} else if (Array.isArray(value)) {
|
|
255
|
-
roots = value.map((child, index) => node(child, `[${index}]`, 1));
|
|
256
|
-
} else {
|
|
257
|
-
roots = [node(value, undefined, 0)];
|
|
258
|
-
}
|
|
305
|
+
const roots: readonly JsonTreeNode[] =
|
|
306
|
+
Array.isArray(value) || isRecord(value)
|
|
307
|
+
? entryNodes(jsonEntries(value, hiddenRootKeys), 1)
|
|
308
|
+
: [node(value, undefined, 0)];
|
|
259
309
|
|
|
260
310
|
const prefixStyle = { vertical: (symbol: string) => symbol };
|
|
261
311
|
const hook = theme.tree.hook;
|
|
@@ -288,7 +338,7 @@ export function renderJsonTreeLines(
|
|
|
288
338
|
},
|
|
289
339
|
];
|
|
290
340
|
} else {
|
|
291
|
-
children =
|
|
341
|
+
children = entryNodes(jsonEntries(values), item.depth + 1);
|
|
292
342
|
}
|
|
293
343
|
} else if (item.kind === "object" && isRecord(item.value)) {
|
|
294
344
|
const record = item.value;
|
|
@@ -307,9 +357,7 @@ export function renderJsonTreeLines(
|
|
|
307
357
|
} else if (keys.length === 0) {
|
|
308
358
|
children = [];
|
|
309
359
|
} else {
|
|
310
|
-
|
|
311
|
-
for (const key in record) objectChildren.push(node(record[key], key, item.depth + 1));
|
|
312
|
-
children = objectChildren;
|
|
360
|
+
children = entryNodes(jsonEntries(record), item.depth + 1);
|
|
313
361
|
}
|
|
314
362
|
}
|
|
315
363
|
item.children = children;
|
|
@@ -331,11 +379,13 @@ export function renderJsonTreeLines(
|
|
|
331
379
|
let body: readonly string[];
|
|
332
380
|
const displayKey = item.key ? sanitize(item.key) : undefined;
|
|
333
381
|
const label = theme.fg(
|
|
334
|
-
"muted",
|
|
382
|
+
item.keyColor ?? "muted",
|
|
335
383
|
displayKey || (item.kind === "array" ? "array" : item.kind === "object" ? "object" : "value"),
|
|
336
384
|
);
|
|
337
385
|
if (item.kind === "placeholder") {
|
|
338
386
|
body = [theme.fg("dim", item.placeholder ?? "…")];
|
|
387
|
+
} else if (item.kind === "inline") {
|
|
388
|
+
body = [`${label}: ${(item.inline ?? []).map(([text, color]) => theme.fg(color, text)).join("")}`];
|
|
339
389
|
} else if (item.kind === "array") {
|
|
340
390
|
body = [`${label} ${theme.fg("dim", `[${(item.value as unknown[]).length}]`)}`];
|
|
341
391
|
} else if (item.kind === "object") {
|
|
@@ -406,34 +456,42 @@ export interface JsonTreeDescribeOptions {
|
|
|
406
456
|
onTruncated?: () => void;
|
|
407
457
|
}
|
|
408
458
|
|
|
409
|
-
type JsonEntry = readonly [key: string, value: unknown];
|
|
459
|
+
type JsonEntry = readonly [key: string, value: unknown, keyColor: ThemeColor];
|
|
410
460
|
|
|
411
461
|
function clipScalar(value: string, maxLen: number): string {
|
|
412
462
|
return value.length > maxLen ? `${value.slice(0, maxLen)}…` : value;
|
|
413
463
|
}
|
|
414
464
|
|
|
465
|
+
/**
|
|
466
|
+
* `value`'s entries: an array's indices dim and right-aligned like line
|
|
467
|
+
* numbers, an object's keys (less `hidden`) muted.
|
|
468
|
+
*/
|
|
415
469
|
function jsonEntries(value: unknown[] | Record<string, unknown>, hidden?: readonly string[]): JsonEntry[] {
|
|
416
470
|
const out: JsonEntry[] = [];
|
|
417
471
|
if (Array.isArray(value)) {
|
|
418
|
-
|
|
472
|
+
const width = String(value.length - 1).length;
|
|
473
|
+
for (let index = 0; index < value.length; index++) {
|
|
474
|
+
out.push([String(index).padStart(width), value[index], "dim"]);
|
|
475
|
+
}
|
|
419
476
|
return out;
|
|
420
477
|
}
|
|
421
478
|
for (const key in value) {
|
|
422
|
-
if (!hidden?.includes(key)) out.push([key, value[key]]);
|
|
479
|
+
if (!hidden?.includes(key)) out.push([key, value[key], "muted"]);
|
|
423
480
|
}
|
|
424
481
|
return out;
|
|
425
482
|
}
|
|
426
483
|
|
|
427
|
-
function jsonScalarToken(value: unknown):
|
|
484
|
+
function jsonScalarToken(value: unknown): ThemeColor {
|
|
428
485
|
if (typeof value === "number" || typeof value === "bigint") return "syntaxNumber";
|
|
429
486
|
if (typeof value === "boolean" || value === null || value === undefined) return "syntaxKeyword";
|
|
430
487
|
return "dim";
|
|
431
488
|
}
|
|
432
489
|
|
|
433
490
|
/**
|
|
434
|
-
* TSP `tree` of a JSON value: containers
|
|
435
|
-
*
|
|
436
|
-
*
|
|
491
|
+
* TSP `tree` of a JSON value: containers that fit {@link JSON_TREE_INLINE_LEN}
|
|
492
|
+
* become `key: [1, "a"]` leaves, larger ones expandable nodes labelled with
|
|
493
|
+
* their key and size, scalars `key: value` leaves styled by type. Bounded by
|
|
494
|
+
* depth, node count and scalar length; no width math.
|
|
437
495
|
*/
|
|
438
496
|
export function describeJsonTree(value: unknown, options: JsonTreeDescribeOptions = {}): NativeNode {
|
|
439
497
|
const maxDepth = Math.max(0, options.maxDepth ?? JSON_TREE_MAX_DEPTH_EXPANDED);
|
|
@@ -452,26 +510,29 @@ export function describeJsonTree(value: unknown, options: JsonTreeDescribeOption
|
|
|
452
510
|
out.push(leaf([span(`… ${entries.length - index} more`, "dim")]));
|
|
453
511
|
break;
|
|
454
512
|
}
|
|
455
|
-
|
|
456
|
-
out.push(describeValue(key, child, depth));
|
|
513
|
+
out.push(describeValue(entries[index], depth));
|
|
457
514
|
}
|
|
458
515
|
return out;
|
|
459
516
|
};
|
|
460
517
|
|
|
461
|
-
const describeValue = (
|
|
518
|
+
const describeValue = (
|
|
519
|
+
[key, entry, keyColor]: readonly [key: string | undefined, value: unknown, keyColor?: ThemeColor],
|
|
520
|
+
depth: number,
|
|
521
|
+
): TspTreeNode => {
|
|
462
522
|
budget--;
|
|
463
523
|
const id = `${nextId++}`;
|
|
464
|
-
const keySpans: TspSpan[] = key === undefined ? [] : [span(plainText(key),
|
|
524
|
+
const keySpans: TspSpan[] = key === undefined ? [] : [span(plainText(key), keyColor)];
|
|
525
|
+
const prefix = keySpans.length > 0 ? [...keySpans, span(": ", "muted")] : [];
|
|
526
|
+
const inline = inlineJson(entry, plainText);
|
|
527
|
+
if (inline) return { id, label: [...prefix, ...inline.map(([text, color]) => span(text, color))] };
|
|
465
528
|
if (Array.isArray(entry) || isRecord(entry)) {
|
|
466
529
|
const entries = jsonEntries(entry);
|
|
467
530
|
const size = Array.isArray(entry) ? `[${entry.length}]` : `{${entries.length}}`;
|
|
468
531
|
const label = keySpans.length > 0 ? [...keySpans, span(` ${size}`, "dim")] : [span(size, "dim")];
|
|
469
|
-
if (entries.length === 0) return { id, label };
|
|
470
532
|
if (depth >= maxDepth) truncated = true;
|
|
471
533
|
const children = depth >= maxDepth ? [leaf([span("…", "dim")])] : describeEntries(entries, depth + 1);
|
|
472
534
|
return { id, label, open: depth < openDepth, children };
|
|
473
535
|
}
|
|
474
|
-
const prefix = keySpans.length > 0 ? [...keySpans, span(": ", "muted")] : [];
|
|
475
536
|
if (typeof entry === "string") {
|
|
476
537
|
const lines = plainText(entry).split("\n");
|
|
477
538
|
if (lines.some(line => line.length > maxScalarLen)) truncated = true;
|
|
@@ -504,8 +565,37 @@ export function describeJsonTree(value: unknown, options: JsonTreeDescribeOption
|
|
|
504
565
|
nodes =
|
|
505
566
|
entries.length > 0 ? describeEntries(entries, 1) : [leaf([span(Array.isArray(value) ? "[]" : "{}", "dim")])];
|
|
506
567
|
} else {
|
|
507
|
-
nodes = [describeValue(undefined, value, 0)];
|
|
568
|
+
nodes = [describeValue([undefined, value], 0)];
|
|
508
569
|
}
|
|
509
570
|
if (truncated) options.onTruncated?.();
|
|
510
571
|
return node("tree", { nodes });
|
|
511
572
|
}
|
|
573
|
+
|
|
574
|
+
/** Options of {@link describeJsonValue}: the `json` node's own, plus the fallback tree's. */
|
|
575
|
+
export interface JsonValueDescribeOptions extends JsonTreeDescribeOptions {
|
|
576
|
+
/** The host draws the `json` kind (`cx.supports("json")`). */
|
|
577
|
+
native?: boolean;
|
|
578
|
+
/** `json` node: container levels expanded below the top-level entries (default 0). */
|
|
579
|
+
open?: number;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* A JSON value for a TSP host: the terminal's own `json` viewer when it draws
|
|
584
|
+
* the kind, which folds and previews containers itself and never cuts (so
|
|
585
|
+
* `onTruncated` never fires), else {@link describeJsonTree} with the same
|
|
586
|
+
* options. Root keys the tree would hide are left out of the sent value too;
|
|
587
|
+
* strings are sanitized like the tree's labels.
|
|
588
|
+
*/
|
|
589
|
+
export function describeJsonValue(value: unknown, options: JsonValueDescribeOptions = {}): NativeNode {
|
|
590
|
+
if (!options.native) return describeJsonTree(value, options);
|
|
591
|
+
let shown = value;
|
|
592
|
+
if (isRecord(value)) {
|
|
593
|
+
const hidden = options.hiddenRootKeys ?? DEFAULT_HIDDEN_ROOT_KEYS;
|
|
594
|
+
if (hidden.some(key => Object.hasOwn(value, key))) {
|
|
595
|
+
const kept: Record<string, unknown> = {};
|
|
596
|
+
for (const key in value) if (!hidden.includes(key)) kept[key] = value[key];
|
|
597
|
+
shown = kept;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
return node("json", { value: sanitizeTextDeep(shown), open: options.open || undefined });
|
|
601
|
+
}
|
package/src/tools/lsp.d.ts
CHANGED
|
@@ -31,6 +31,8 @@ export interface FileDiagnosticsResult {
|
|
|
31
31
|
summary: string;
|
|
32
32
|
/** Whether there are any errors (severity 1) */
|
|
33
33
|
errored: boolean;
|
|
34
|
+
/** Servers that sent no fresh report in time: the file is unverified for them, not clean. */
|
|
35
|
+
unreported?: string[];
|
|
34
36
|
/** Whether the file was formatted */
|
|
35
37
|
formatter?: FileFormatResult;
|
|
36
38
|
}
|
package/src/tools/lsp.ts
CHANGED
|
@@ -83,6 +83,8 @@ export interface FileDiagnosticsResult {
|
|
|
83
83
|
summary: string;
|
|
84
84
|
/** Whether there are any errors (severity 1) */
|
|
85
85
|
errored: boolean;
|
|
86
|
+
/** Servers that sent no fresh report in time: the file is unverified for them, not clean. */
|
|
87
|
+
unreported?: string[];
|
|
86
88
|
/** Whether the file was formatted */
|
|
87
89
|
formatter?: FileFormatResult;
|
|
88
90
|
}
|
|
@@ -163,6 +165,9 @@ export function renderCall(args: LspParams, _options: RenderResultOptions, theme
|
|
|
163
165
|
// Result Rendering
|
|
164
166
|
// =============================================================================
|
|
165
167
|
|
|
168
|
+
/** A diagnostics status line for a file no server reported on in time: unverified, never "No issues". */
|
|
169
|
+
const UNREPORTED_LINE_RE = /\bno diagnostics report yet\b/;
|
|
170
|
+
|
|
166
171
|
/**
|
|
167
172
|
* Render LSP tool result with intelligent formatting based on result type.
|
|
168
173
|
* Detects hover, diagnostics, references, symbols, etc. and formats accordingly.
|
|
@@ -190,6 +195,7 @@ export function renderResult(
|
|
|
190
195
|
const refMatch = text.match(/(\d+)\s+reference\(s\)/);
|
|
191
196
|
const symbolsMatch = text.match(/Symbols in (.+):/);
|
|
192
197
|
const hasStatusError = text.includes(theme.status.error);
|
|
198
|
+
const unreportedCount = lines.filter(line => UNREPORTED_LINE_RE.test(line)).length;
|
|
193
199
|
|
|
194
200
|
// Static request info
|
|
195
201
|
const request = args ?? result.details?.request;
|
|
@@ -218,12 +224,12 @@ export function renderResult(
|
|
|
218
224
|
bodyLines: renderHover(codeBlockMatch, text, lines, expanded, theme),
|
|
219
225
|
};
|
|
220
226
|
}
|
|
221
|
-
if (errorMatch || warningMatch || hasStatusError) {
|
|
227
|
+
if (errorMatch || warningMatch || hasStatusError || unreportedCount > 0) {
|
|
222
228
|
const errorCount = errorMatch ? Number.parseInt(errorMatch[1], 10) : 0;
|
|
223
229
|
const warnCount = warningMatch ? Number.parseInt(warningMatch[1], 10) : 0;
|
|
224
230
|
return {
|
|
225
231
|
label: "Diagnostics",
|
|
226
|
-
state: errorCount > 0 ? "error" : warnCount > 0 ? "warning" : "success",
|
|
232
|
+
state: errorCount > 0 ? "error" : warnCount > 0 || unreportedCount > 0 ? "warning" : "success",
|
|
227
233
|
bodyLines: renderDiagnostics(errorMatch, warningMatch, lines, expanded, theme),
|
|
228
234
|
};
|
|
229
235
|
}
|
|
@@ -384,17 +390,19 @@ function renderDiagnostics(
|
|
|
384
390
|
): string[] {
|
|
385
391
|
const errorCount = errorMatch ? Number.parseInt(errorMatch[1], 10) : 0;
|
|
386
392
|
const warnCount = warningMatch ? Number.parseInt(warningMatch[1], 10) : 0;
|
|
393
|
+
const unreportedLines = lines.filter(line => UNREPORTED_LINE_RE.test(line));
|
|
387
394
|
|
|
388
395
|
const icon =
|
|
389
396
|
errorCount > 0
|
|
390
397
|
? theme.styledSymbol("status.error", "error")
|
|
391
|
-
: warnCount > 0
|
|
398
|
+
: warnCount > 0 || unreportedLines.length > 0
|
|
392
399
|
? theme.styledSymbol("status.warning", "warning")
|
|
393
400
|
: theme.styledSymbol("tool.lsp", "accent");
|
|
394
401
|
|
|
395
402
|
const meta: string[] = [];
|
|
396
403
|
if (errorCount > 0) meta.push(`${errorCount} error${errorCount !== 1 ? "s" : ""}`);
|
|
397
404
|
if (warnCount > 0) meta.push(`${warnCount} warning${warnCount !== 1 ? "s" : ""}`);
|
|
405
|
+
if (unreportedLines.length > 0) meta.push(formatCount("unverified file", unreportedLines.length));
|
|
398
406
|
if (meta.length === 0) meta.push("No issues");
|
|
399
407
|
|
|
400
408
|
const diagLines = lines.filter(l => l.includes(theme.status.error) || /:\d+:\d+/.test(l));
|
|
@@ -404,10 +412,14 @@ function renderDiagnostics(
|
|
|
404
412
|
const fallbackDiagnostics: RawDiagnostic[] = diagLines.map(line => ({
|
|
405
413
|
raw: sanitizeDiagnosticDisplayText(line.trim()),
|
|
406
414
|
}));
|
|
415
|
+
// Unverified files lead: they are the rows a reader must not miss among diagnostics.
|
|
416
|
+
const items: DiagnosticItem[] = [
|
|
417
|
+
...unreportedLines.map(line => ({ raw: sanitizeDiagnosticDisplayText(line.trim()) })),
|
|
418
|
+
...(parsedDiagnostics.length > 0 ? parsedDiagnostics : fallbackDiagnostics),
|
|
419
|
+
];
|
|
407
420
|
|
|
408
421
|
if (expanded) {
|
|
409
422
|
let output = `${icon} ${theme.fg("dim", meta.join(theme.sep.dot))}`;
|
|
410
|
-
const items: DiagnosticItem[] = parsedDiagnostics.length > 0 ? parsedDiagnostics : fallbackDiagnostics;
|
|
411
423
|
for (let i = 0; i < items.length; i++) {
|
|
412
424
|
const item = items[i];
|
|
413
425
|
const isLast = i === items.length - 1;
|
|
@@ -432,10 +444,8 @@ function renderDiagnostics(
|
|
|
432
444
|
}
|
|
433
445
|
|
|
434
446
|
// Collapsed view
|
|
435
|
-
const previewItems
|
|
436
|
-
|
|
437
|
-
const remaining =
|
|
438
|
-
(parsedDiagnostics.length > 0 ? parsedDiagnostics.length : fallbackDiagnostics.length) - previewItems.length;
|
|
447
|
+
const previewItems = items.slice(0, 3);
|
|
448
|
+
const remaining = items.length - previewItems.length;
|
|
439
449
|
const clipped = previewItems.some(
|
|
440
450
|
item => !("raw" in item) && visibleWidth(formatDiagnosticMessage(item)) > TRUNCATE_LENGTHS.CONTENT,
|
|
441
451
|
);
|
|
@@ -788,6 +798,8 @@ interface LspDiagnosticsParse {
|
|
|
788
798
|
diagnostics: ParsedDiagnostic[];
|
|
789
799
|
failures: string[];
|
|
790
800
|
warnings: string[];
|
|
801
|
+
/** Files a server sent no report for in time: unverified, never "No issues". */
|
|
802
|
+
unreported: string[];
|
|
791
803
|
/** Lines neither a diagnostic nor a status line (kept verbatim). */
|
|
792
804
|
other: string[];
|
|
793
805
|
}
|
|
@@ -803,10 +815,10 @@ const FILE_SUMMARY_RE = /: (?:no issues|\d+ \w+\(s\)(?:, \d+ \w+\(s\))*)$/;
|
|
|
803
815
|
* Parse a diagnostics response: grouped (`# dir/`, `## file`, ` 12:5 [error] …`)
|
|
804
816
|
* or flat (`file:12:5 [error] …`) diagnostic lines, and the per-file status
|
|
805
817
|
* lines (`✗ file: all language servers failed (…)`, `⚠ …some servers failed`,
|
|
806
|
-
* `✓ file: no issues`, `✗ file: 2 error(s)`).
|
|
818
|
+
* `⚠ file: no diagnostics report yet from …`, `✓ file: no issues`, `✗ file: 2 error(s)`).
|
|
807
819
|
*/
|
|
808
820
|
function parseLspDiagnostics(lines: readonly string[]): LspDiagnosticsParse {
|
|
809
|
-
const out: LspDiagnosticsParse = { diagnostics: [], failures: [], warnings: [], other: [] };
|
|
821
|
+
const out: LspDiagnosticsParse = { diagnostics: [], failures: [], warnings: [], unreported: [], other: [] };
|
|
810
822
|
let file: string | undefined;
|
|
811
823
|
for (const event of walkGroupedOutput(lines)) {
|
|
812
824
|
if (event.kind !== "line") {
|
|
@@ -824,6 +836,10 @@ function parseLspDiagnostics(lines: readonly string[]): LspDiagnosticsParse {
|
|
|
824
836
|
out.warnings.push(line.replace(STATUS_GLYPH_RE, ""));
|
|
825
837
|
continue;
|
|
826
838
|
}
|
|
839
|
+
if (UNREPORTED_LINE_RE.test(line)) {
|
|
840
|
+
out.unreported.push(line.replace(STATUS_GLYPH_RE, ""));
|
|
841
|
+
continue;
|
|
842
|
+
}
|
|
827
843
|
if (FILE_SUMMARY_RE.test(line)) continue;
|
|
828
844
|
const parsed = parseDiagnosticMessage(file && DIAGNOSTIC_AT_RE.test(line) ? `${file}:${line}` : line);
|
|
829
845
|
if (parsed) out.diagnostics.push(parsed);
|
|
@@ -888,25 +904,30 @@ function statusRow(message: string, tone: "error" | "warning", key: string): Nat
|
|
|
888
904
|
}
|
|
889
905
|
|
|
890
906
|
/**
|
|
891
|
-
* Diagnostics view: a card when there are diagnostics or
|
|
892
|
-
* severity icon · `file:line:col` · source · message), an inline `No issues`
|
|
893
|
-
* otherwise. A failed server is
|
|
907
|
+
* Diagnostics view: a card when there are diagnostics, failures or unverified files
|
|
908
|
+
* (rows of severity icon · `file:line:col` · source · message), an inline `No issues`
|
|
909
|
+
* otherwise. A failed server or a missing report is a row, never "No issues".
|
|
894
910
|
*/
|
|
895
911
|
function describeLspDiagnostics(request: Partial<LspParams> | undefined, fallbackAction: string, lines: string[]) {
|
|
896
912
|
const parsed = parseLspDiagnostics(lines);
|
|
897
913
|
const counts = diagnosticCounts(parsed.diagnostics);
|
|
898
914
|
const failed =
|
|
899
915
|
parsed.failures.length > 0 ? [span(formatCount("server failure", parsed.failures.length), "error")] : undefined;
|
|
916
|
+
const unverified =
|
|
917
|
+
parsed.unreported.length > 0
|
|
918
|
+
? [span(formatCount("unverified file", parsed.unreported.length), "warning")]
|
|
919
|
+
: undefined;
|
|
900
920
|
const rows: NativeNode[] = [
|
|
901
921
|
...parsed.failures.map((message, i) => statusRow(message, "error", `x${i}`)),
|
|
922
|
+
...parsed.unreported.map((message, i) => statusRow(message, "warning", `u${i}`)),
|
|
902
923
|
...parsed.diagnostics.map((diag, i) => diagnosticRow(diag, `d${i}`)),
|
|
903
924
|
...parsed.warnings.map((message, i) => statusRow(message, "warning", `w${i}`)),
|
|
904
925
|
];
|
|
905
926
|
if (parsed.other.length > 0) rows.push(keyed(code(parsed.other.join("\n"), { wrap: true }), "other"));
|
|
906
927
|
const hasErrors = parsed.failures.length > 0 || parsed.diagnostics.some(d => d.severity === "error");
|
|
907
|
-
const meta = compact<TspText>([counts, failed, !counts && !failed && "No issues"]);
|
|
928
|
+
const meta = compact<TspText>([counts, failed, unverified, !counts && !failed && !unverified && "No issues"]);
|
|
908
929
|
const head = lspNativeHead(request, fallbackAction, meta);
|
|
909
|
-
if (parsed.diagnostics.length === 0 && parsed.failures.length === 0) {
|
|
930
|
+
if (parsed.diagnostics.length === 0 && parsed.failures.length === 0 && parsed.unreported.length === 0) {
|
|
910
931
|
return { tool: head, inline: true, body: rows.length > 0 ? rows : undefined } satisfies NativeToolView;
|
|
911
932
|
}
|
|
912
933
|
return {
|
package/src/tools/mcp.d.ts
CHANGED
|
@@ -23,11 +23,12 @@ export declare function renderMCPResult(result: {
|
|
|
23
23
|
isError?: boolean;
|
|
24
24
|
}, options: RenderResultOptions, theme: Theme, args?: Record<string, unknown>): Component;
|
|
25
25
|
/** Native MCP call view: the head plus the folded args, inline while pending. */
|
|
26
|
-
export declare function describeMCPCall(args: Record<string, unknown>, label: string): NativeToolView;
|
|
26
|
+
export declare function describeMCPCall(args: Record<string, unknown>, label: string, options?: RenderResultOptions): NativeToolView;
|
|
27
27
|
/**
|
|
28
|
-
* Native MCP result view: JSON output as
|
|
29
|
-
*
|
|
30
|
-
*
|
|
28
|
+
* Native MCP result view: JSON output as the host's `json` viewer (when it
|
|
29
|
+
* draws one) or a JSON tree, Markdown when the preference is on, otherwise
|
|
30
|
+
* the raw text as tool output; the folded Args section follows, so the
|
|
31
|
+
* collapsed preview still leads with the output.
|
|
31
32
|
*/
|
|
32
33
|
export declare function describeMCPResult(result: {
|
|
33
34
|
content: Array<{
|
|
@@ -36,7 +37,7 @@ export declare function describeMCPResult(result: {
|
|
|
36
37
|
}>;
|
|
37
38
|
details?: MCPToolDetails;
|
|
38
39
|
isError?: boolean;
|
|
39
|
-
},
|
|
40
|
+
}, options: RenderResultOptions, args?: Record<string, unknown>): NativeToolView | undefined;
|
|
40
41
|
import type { OutputMeta } from "./output-meta";
|
|
41
42
|
/** Set whether plain MCP text results render as Markdown. */
|
|
42
43
|
export declare function setMcpRenderMarkdownResults(enabled: boolean): void;
|
package/src/tools/mcp.ts
CHANGED
|
@@ -16,7 +16,7 @@ import { plainText } from "../native/spans";
|
|
|
16
16
|
import { errorText, noteText, truncationNotice } from "./native-view";
|
|
17
17
|
import { getMarkdownTheme, type Theme } from "../theme/theme";
|
|
18
18
|
import {
|
|
19
|
-
|
|
19
|
+
describeJsonValue,
|
|
20
20
|
formatArgsInline,
|
|
21
21
|
JSON_TREE_MAX_DEPTH_COLLAPSED,
|
|
22
22
|
JSON_TREE_MAX_DEPTH_EXPANDED,
|
|
@@ -302,38 +302,46 @@ function mcpHead(title: string, entries: readonly [string, unknown][]): NativeTo
|
|
|
302
302
|
/**
|
|
303
303
|
* Native counterpart of the ANSI card's Args tree: the complete arguments,
|
|
304
304
|
* folded under an `Args` section because the head summary clips each value.
|
|
305
|
+
* The host's `json` viewer, when it draws one, lists the arguments with their
|
|
306
|
+
* containers folded to one-line previews.
|
|
305
307
|
*/
|
|
306
|
-
function mcpArgsSection(entries: readonly [string, unknown][]): NativeNode | undefined {
|
|
308
|
+
function mcpArgsSection(entries: readonly [string, unknown][], json: boolean): NativeNode | undefined {
|
|
307
309
|
if (entries.length === 0) return undefined;
|
|
308
310
|
return node(
|
|
309
311
|
"section",
|
|
310
312
|
{ head: [span("Args", "muted")], collapsible: true, collapsed: true },
|
|
311
|
-
[
|
|
313
|
+
[describeJsonValue(Object.fromEntries(entries), { native: json })],
|
|
312
314
|
"args",
|
|
313
315
|
);
|
|
314
316
|
}
|
|
315
317
|
|
|
316
318
|
/** Native MCP call view: the head plus the folded args, inline while pending. */
|
|
317
|
-
export function describeMCPCall(
|
|
319
|
+
export function describeMCPCall(
|
|
320
|
+
args: Record<string, unknown>,
|
|
321
|
+
label: string,
|
|
322
|
+
options?: RenderResultOptions,
|
|
323
|
+
): NativeToolView {
|
|
318
324
|
const entries = visibleMcpArgs(args);
|
|
319
|
-
const section = mcpArgsSection(entries);
|
|
325
|
+
const section = mcpArgsSection(entries, options?.json === true);
|
|
320
326
|
return { tool: mcpHead(label, entries), body: section ? [section] : undefined, inline: true };
|
|
321
327
|
}
|
|
322
328
|
|
|
323
329
|
const mcpResultMemo = new OwnerMemo<NativeToolView | undefined>();
|
|
324
330
|
|
|
325
331
|
/**
|
|
326
|
-
* Native MCP result view: JSON output as
|
|
327
|
-
*
|
|
328
|
-
*
|
|
332
|
+
* Native MCP result view: JSON output as the host's `json` viewer (when it
|
|
333
|
+
* draws one) or a JSON tree, Markdown when the preference is on, otherwise
|
|
334
|
+
* the raw text as tool output; the folded Args section follows, so the
|
|
335
|
+
* collapsed preview still leads with the output.
|
|
329
336
|
*/
|
|
330
337
|
export function describeMCPResult(
|
|
331
338
|
result: { content: Array<{ type: string; text?: string }>; details?: MCPToolDetails; isError?: boolean },
|
|
332
|
-
|
|
339
|
+
options: RenderResultOptions,
|
|
333
340
|
args?: Record<string, unknown>,
|
|
334
341
|
): NativeToolView | undefined {
|
|
342
|
+
const json = options.json === true;
|
|
335
343
|
// Callers allocate a fresh args object per streamed delta, so identity is a sound dep.
|
|
336
|
-
return mcpResultMemo.get(result, [renderMarkdownResults, args], () => {
|
|
344
|
+
return mcpResultMemo.get(result, [renderMarkdownResults, args, json], () => {
|
|
337
345
|
const textContent = (result.content ?? [])
|
|
338
346
|
.filter(block => block.type === "text")
|
|
339
347
|
.map(block => block.text ?? "")
|
|
@@ -355,13 +363,13 @@ export function describeMCPResult(
|
|
|
355
363
|
}
|
|
356
364
|
if (!output) body.push(noteText("(no output)"));
|
|
357
365
|
else if (isError) body.push(errorText(output));
|
|
358
|
-
else if (isJson) body.push(
|
|
366
|
+
else if (isJson) body.push(describeJsonValue(parsed, { native: json }));
|
|
359
367
|
else if (renderMarkdownResults) body.push(md(output));
|
|
360
368
|
else body.push(ansi(output));
|
|
361
369
|
const warning = truncationNotice(result.details?.meta);
|
|
362
370
|
if (warning) body.push(warning);
|
|
363
371
|
const entries = visibleMcpArgs(args);
|
|
364
|
-
const section = mcpArgsSection(entries);
|
|
372
|
+
const section = mcpArgsSection(entries, json);
|
|
365
373
|
if (section) body.push(section);
|
|
366
374
|
return {
|
|
367
375
|
tool: mcpHead(title, entries),
|
|
@@ -6,7 +6,7 @@ import { type OutputMeta } from "./output-meta";
|
|
|
6
6
|
import type { NativeToolHead, NativeToolView, ToolRenderResult } from "./renderer";
|
|
7
7
|
/** A path for native heads: relative to the working directory when inside it, else `~`-shortened. */
|
|
8
8
|
export declare function displayPath(filePath: string): string;
|
|
9
|
-
/**
|
|
9
|
+
/** Configured file link for a head's path target, when the path is absolute. */
|
|
10
10
|
export declare function fileHref(filePath: string | undefined): string | undefined;
|
|
11
11
|
/** Diff stats as one head `meta` string, `+8 −1` (U+2212 minus), or undefined when nothing changed. */
|
|
12
12
|
export declare function diffStatsMeta(added: number, removed: number): string | undefined;
|
package/src/tools/native-view.ts
CHANGED
|
@@ -23,7 +23,7 @@ export function displayPath(filePath: string): string {
|
|
|
23
23
|
return shortenPath(filePath);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
/**
|
|
26
|
+
/** Configured file link for a head's path target, when the path is absolute. */
|
|
27
27
|
export function fileHref(filePath: string | undefined): string | undefined {
|
|
28
28
|
return filePath && path.isAbsolute(filePath) ? tryFileUri(filePath) : undefined;
|
|
29
29
|
}
|
package/src/tools/renderer.d.ts
CHANGED
|
@@ -36,6 +36,8 @@ export interface RenderResultOptions {
|
|
|
36
36
|
cancelled?: boolean;
|
|
37
37
|
/** The native host shows files by path (`cx.supports("media")`). Native describe hooks only. */
|
|
38
38
|
media?: boolean;
|
|
39
|
+
/** The native host draws raw JSON values (`cx.supports("json")`). Native describe hooks only. */
|
|
40
|
+
json?: boolean;
|
|
39
41
|
}
|
|
40
42
|
/** Render options for a result, plus the tool-specific context the transcript threads through. */
|
|
41
43
|
export type RenderResultContextOptions = RenderResultOptions & {
|
package/src/tools/renderer.ts
CHANGED
|
@@ -37,6 +37,8 @@ export interface RenderResultOptions {
|
|
|
37
37
|
cancelled?: boolean;
|
|
38
38
|
/** The native host shows files by path (`cx.supports("media")`). Native describe hooks only. */
|
|
39
39
|
media?: boolean;
|
|
40
|
+
/** The native host draws raw JSON values (`cx.supports("json")`). Native describe hooks only. */
|
|
41
|
+
json?: boolean;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
/** Render options for a result, plus the tool-specific context the transcript threads through. */
|
|
@@ -177,6 +177,17 @@ export declare function truncateLineBytes(line: string, maxBytes?: number): {
|
|
|
177
177
|
text: string;
|
|
178
178
|
wasTruncated: boolean;
|
|
179
179
|
};
|
|
180
|
+
/**
|
|
181
|
+
* Where `text` shows in `output` written through an {@link OutputSink} with
|
|
182
|
+
* `maxColumns`, searching from `from`: each of its lines whole, or, where the
|
|
183
|
+
* cap cut the output line, a head of it and `…` ending that output line.
|
|
184
|
+
* Only the first line can be cut short of its first 16 characters (after
|
|
185
|
+
* other text on its output line); such text is not found.
|
|
186
|
+
*/
|
|
187
|
+
export declare function findColumnCapped(output: string, text: string, from?: number): {
|
|
188
|
+
start: number;
|
|
189
|
+
end: number;
|
|
190
|
+
} | undefined;
|
|
180
191
|
/** Shared helper to build a no-truncation result. */
|
|
181
192
|
export declare function noTruncResult(content: string, totalLines?: number, totalBytes?: number): TruncationResult;
|
|
182
193
|
/**
|