@spexcode/transcript-ui 0.7.0-next.7 → 0.7.0-next.9

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/dist/ToolLine.js CHANGED
@@ -3,7 +3,7 @@ import { useEffect, useState } from 'react';
3
3
  import { useTranscriptUi } from './context.js';
4
4
  import { Caret, Spinner } from './icons.js';
5
5
  import { isRunning } from './segments.js';
6
- import { runKinds, splitTarget, toolTarget, toolVerb } from './vocabulary.js';
6
+ import { prettyInput, runKinds, splitTarget, toolName, toolTarget, toolVerb } from './vocabulary.js';
7
7
  // A LIVE FRAME WITHHOLDS OUTPUT BODIES: a recorded result is `null` on the wire, its size told, and the body
8
8
  // is fetched once when a person opens the call, through the host's loader.
9
9
  function WithheldOutput({ tool }) {
@@ -40,10 +40,11 @@ export function ToolLine({ tool, open, onToggle, live = false }) {
40
40
  const canOpen = !!tool.input || tool.output !== undefined || withheld;
41
41
  const running = isRunning(tool, live);
42
42
  const outcome = tool.outcome;
43
- const row = (_jsxs(_Fragment, { children: [_jsx("span", { className: "tx-tool-verb", children: toolVerb(tool.name, vocabulary) }), lead && _jsx("span", { className: "tx-tool-target", children: lead }), trail && _jsx("span", { className: "tx-tool-trail", children: trail }), lines > 0 && _jsx("span", { className: "tx-tool-size", children: labels.lines(lines) }), running && _jsxs("span", { className: "tx-tool-running", children: [_jsx(Spinner, {}), labels.running] }), outcome && _jsx("span", { className: `tx-tool-outcome is-${outcome}`, children: outcome === 'failed' ? labels.failed : labels.rejected }), canOpen && _jsx(Caret, { open: open, className: "tx-tool-caret" })] }));
43
+ const { server } = toolName(tool.name);
44
+ const row = (_jsxs(_Fragment, { children: [_jsx("span", { className: "tx-tool-verb", children: toolVerb(tool.name, vocabulary) }), server && _jsx("span", { className: "tx-tool-server", children: server }), lead && _jsx("span", { className: "tx-tool-target", children: lead }), trail && _jsx("span", { className: "tx-tool-trail", children: trail }), lines > 0 && _jsx("span", { className: "tx-tool-size", children: labels.lines(lines) }), running && _jsxs("span", { className: "tx-tool-running", children: [_jsx(Spinner, {}), labels.running] }), outcome && _jsx("span", { className: `tx-tool-outcome is-${outcome}`, children: outcome === 'failed' ? labels.failed : labels.rejected }), canOpen && _jsx(Caret, { open: open, className: "tx-tool-caret" })] }));
44
45
  return (_jsxs("div", { className: `tx-tool${running ? ' is-running' : ''}${outcome ? ` is-${outcome}` : ''}`, children: [canOpen
45
46
  ? _jsx("button", { type: "button", onClick: onToggle, "aria-expanded": open, className: "tx-tool-row is-openable", children: row })
46
- : _jsx("div", { className: "tx-tool-row", children: row }), open && canOpen && _jsxs(_Fragment, { children: [tool.input && _jsx("pre", { className: "tx-tool-in", children: tool.input }), withheld
47
+ : _jsx("div", { className: "tx-tool-row", children: row }), open && canOpen && _jsxs(_Fragment, { children: [tool.input && _jsx("pre", { className: "tx-tool-in", children: prettyInput(tool.input) }), withheld
47
48
  ? _jsx(WithheldOutput, { tool: tool })
48
49
  : tool.output !== undefined && _jsx("pre", { className: "tx-tool-out", children: tool.output })] })] }));
49
50
  }
@@ -11,11 +11,16 @@ export declare function extendVocabulary(base: Vocabulary, extra: Partial<{
11
11
  quiet: Iterable<string>;
12
12
  targetKeys: readonly string[];
13
13
  }>): Vocabulary;
14
+ export declare function toolName(name: string | undefined): {
15
+ tool: string;
16
+ server: string | null;
17
+ };
14
18
  export declare const toolVerb: (name: string | undefined, vocabulary?: Readonly<{
15
19
  verbs: Readonly<Record<string, string>>;
16
20
  quiet: ReadonlySet<string>;
17
21
  targetKeys: readonly string[];
18
22
  }>) => string;
23
+ export declare function prettyInput(input: string | undefined): string;
19
24
  export declare const isQuietTool: (name: string, vocabulary?: Readonly<{
20
25
  verbs: Readonly<Record<string, string>>;
21
26
  quiet: ReadonlySet<string>;
@@ -3,6 +3,7 @@ export const defaultVocabulary = {
3
3
  Read: 'Read', NotebookRead: 'Read',
4
4
  Grep: 'Searched', Glob: 'Searched', WebSearch: 'Searched the web',
5
5
  Bash: 'Ran', BashOutput: 'Read output',
6
+ exec: 'Ran', shell: 'Ran', wait: 'Waited',
6
7
  Edit: 'Edited', MultiEdit: 'Edited', NotebookEdit: 'Edited',
7
8
  Write: 'Wrote',
8
9
  WebFetch: 'Fetched',
@@ -10,7 +11,7 @@ export const defaultVocabulary = {
10
11
  TodoWrite: 'Updated the plan',
11
12
  },
12
13
  quiet: new Set(['Read', 'NotebookRead', 'Grep', 'Glob', 'WebFetch', 'WebSearch']),
13
- targetKeys: ['file_path', 'filePath', 'path', 'notebook_path', 'pattern', 'query', 'command', 'cmd', 'url', 'description'],
14
+ targetKeys: ['file_path', 'filePath', 'path', 'notebook_path', 'pattern', 'query', 'command', 'cmd', 'url', 'cell_id', 'description'],
14
15
  };
15
16
  export function extendVocabulary(base, extra) {
16
17
  return {
@@ -19,8 +20,42 @@ export function extendVocabulary(base, extra) {
19
20
  targetKeys: extra.targetKeys ? [...extra.targetKeys, ...base.targetKeys.filter((key) => !extra.targetKeys.includes(key))] : base.targetKeys,
20
21
  };
21
22
  }
22
- export const toolVerb = (name, vocabulary = defaultVocabulary) => (name && vocabulary.verbs[name]) || name || 'tool';
23
+ // AN MCP TOOL IS NAMED BY ITS SERVER AND ITS TOOL. Every harness that speaks MCP writes the call as
24
+ // `mcp__<server>__<tool>`; the reader wants both halves, apart — measured across four transcript renderers,
25
+ // three knew the server in their data and lost it on the screen. The vocabulary may name the full id or the
26
+ // bare tool; an unnamed MCP tool reads as its tool half, never the whole mangled id.
27
+ export function toolName(name) {
28
+ const m = name ? /^mcp__(.+?)__(.+)$/.exec(name) : null;
29
+ return m ? { tool: m[2], server: m[1] } : { tool: name || 'tool', server: null };
30
+ }
31
+ export const toolVerb = (name, vocabulary = defaultVocabulary) => {
32
+ if (name && vocabulary.verbs[name])
33
+ return vocabulary.verbs[name];
34
+ const { tool } = toolName(name);
35
+ return vocabulary.verbs[tool] || tool;
36
+ };
37
+ // THE ARGUMENTS, WHEN OPENED, READ AS THE ARGUMENTS: a JSON object pretty-printed one field per line, a bare
38
+ // string (a script, a command) as itself. The wire form is one line; nobody reads one line of JSON.
39
+ export function prettyInput(input) {
40
+ if (typeof input !== 'string' || !input)
41
+ return '';
42
+ try {
43
+ const parsed = JSON.parse(input);
44
+ return parsed && typeof parsed === 'object' ? JSON.stringify(parsed, null, 2) : input;
45
+ }
46
+ catch {
47
+ return input;
48
+ }
49
+ }
23
50
  export const isQuietTool = (name, vocabulary = defaultVocabulary) => vocabulary.quiet.has(name);
51
+ // A command's or a script's head: its first non-empty line, clamped. A one-liner is itself; a multi-line
52
+ // script shows the line that names it, and the CSS ellipsis takes the rest.
53
+ function firstLine(text) {
54
+ const line = text.split(/\r?\n/).map((l) => l.trim()).find(Boolean);
55
+ if (!line)
56
+ return null;
57
+ return line.length <= 160 ? line : line.slice(0, 160);
58
+ }
24
59
  // The target, from the call's own arguments. `input` is the raw JSON of the arguments (or a bare string), so
25
60
  // this reads the field the tool actually names and shows NOTHING when it cannot — a wrong target is worse
26
61
  // than no target, and a truncated blob of JSON is not a target at all.
@@ -28,14 +63,17 @@ export function toolTarget(input, vocabulary = defaultVocabulary) {
28
63
  if (typeof input !== 'string' || !input)
29
64
  return null;
30
65
  let parsed = null;
66
+ // A tool whose input is a bare string is a command or a script (a codex `exec` cell, a shell one-liner). Its
67
+ // FIRST non-empty line names it — a wall of script has a head worth reading, and nothing is worse than a row
68
+ // that says only "exec". JSON is parsed for its named target below; a bare string is its own head.
31
69
  try {
32
70
  parsed = JSON.parse(input);
33
71
  }
34
72
  catch {
35
- return input.length <= 80 ? input : null;
73
+ return firstLine(input);
36
74
  }
37
75
  if (!parsed || typeof parsed !== 'object')
38
- return typeof parsed === 'string' ? parsed : null;
76
+ return typeof parsed === 'string' ? firstLine(parsed) : null;
39
77
  for (const key of vocabulary.targetKeys) {
40
78
  const value = parsed[key];
41
79
  if (typeof value === 'string' && value.trim())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spexcode/transcript-ui",
3
- "version": "0.7.0-next.7",
3
+ "version": "0.7.0-next.9",
4
4
  "type": "module",
5
5
  "description": "React components that draw a normalized agent transcript — the person quoted, the agent as the page, a tool call as a sentence, the work folded behind its answer — with the fold, the prose renderer, the tool vocabulary, the labels and the design tokens all tunable.",
6
6
  "files": [
@@ -24,7 +24,7 @@
24
24
  "test": "npm run build && tsx --test src/*.test.tsx"
25
25
  },
26
26
  "dependencies": {
27
- "@spexcode/transcript": "0.7.0-next.7"
27
+ "@spexcode/transcript": "0.7.0-next.9"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "react": "^18.2.0 || ^19.0.0"
package/styles.css CHANGED
@@ -85,6 +85,7 @@
85
85
  .tx-tool-target { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--tx-ink); }
86
86
  .tx-tool-trail { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--tx-muted); }
87
87
  .tx-tool-size { flex: none; color: var(--tx-muted); font-variant-numeric: tabular-nums; }
88
+ .tx-tool-server { flex: none; color: var(--tx-muted); font-size: var(--tx-type-caption); padding: 0 5px; border: 1px solid var(--tx-edge); border-radius: 999px; }
88
89
  .tx-tool-row.is-run .tx-tool-verb { color: var(--tx-muted); font-weight: inherit; }
89
90
  .tx-tool-kids { display: flex; flex-direction: column; gap: 2px; align-items: flex-start; margin-left: 8px; padding-left: 10px; border-left: 1px solid var(--tx-edge); }
90
91
  .tx-tool-in, .tx-tool-out {