@spexcode/transcript-ui 0.7.0-next.6 → 0.7.0-next.8

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
  }
@@ -8,6 +8,9 @@ export declare function TurnBody({ turn, openIds, onToggle, live, fold }: {
8
8
  live: boolean;
9
9
  fold?: boolean;
10
10
  } & Disclosure): import("react").JSX.Element;
11
+ export declare function QuotedTurn({ turn }: {
12
+ turn: AnyTurn;
13
+ }): import("react").JSX.Element;
11
14
  export declare function WorkSegmentView({ segment, openIds, onToggle, live }: {
12
15
  segment: Work;
13
16
  live: boolean;
@@ -2,6 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
2
2
  import { useTranscriptUi } from './context.js';
3
3
  import { Caret } from './icons.js';
4
4
  import { Quote } from './Quote.js';
5
+ import { parseEnvelope } from './envelope.js';
5
6
  import { segments } from './segments.js';
6
7
  import { ToolRun } from './ToolLine.js';
7
8
  import { useDisclosure } from './useDisclosure.js';
@@ -11,6 +12,12 @@ export function TurnBody({ turn, openIds, onToggle, live, fold = true }) {
11
12
  const { renderText } = useTranscriptUi();
12
13
  return _jsxs("div", { className: "tx-say", children: [turn.text && _jsx("div", { className: "tx-say-text", children: renderText(turn.text) }), _jsx(ToolRun, { tools: turn.tools, openIds: openIds, onToggle: onToggle, live: live, fold: fold })] });
13
14
  }
15
+ // a quoted turn is read through the envelope rows: the sender it names, the body it carried
16
+ export function QuotedTurn({ turn }) {
17
+ const { envelopes } = useTranscriptUi();
18
+ const envelope = parseEnvelope(turn.text || '', envelopes);
19
+ return _jsx(Quote, { who: envelope.who, ts: envelope.at ?? turn.at, text: envelope.body, className: "tx-quote-nested" });
20
+ }
14
21
  export function WorkSegmentView({ segment, openIds, onToggle, live }) {
15
22
  const { labels, vocabulary } = useTranscriptUi();
16
23
  const id = `seg:${segment.work[0]?.id || segment.answer?.id}`;
@@ -25,7 +32,7 @@ export function WorkSegmentView({ segment, openIds, onToggle, live }) {
25
32
  }
26
33
  export function SegmentView({ segment, ...rest }) {
27
34
  if (segment.kind === 'quote')
28
- return _jsx(Quote, { ts: segment.turn.at, text: segment.turn.text || '', className: "tx-quote-nested" });
35
+ return _jsx(QuotedTurn, { turn: segment.turn });
29
36
  return _jsx(WorkSegmentView, { segment: segment, ...rest });
30
37
  }
31
38
  // THE TURNS, in the grammar: quotes where the host wants them, work segments folded behind their answers
package/dist/context.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { type ReactNode } from 'react';
2
2
  import { type Vocabulary } from './vocabulary.js';
3
3
  import type { FoldPolicy, UserTurnPolicy } from './segments.js';
4
+ import { type EnvelopeParser } from './envelope.js';
4
5
  export type ToolOutputResult = {
5
6
  ok: true;
6
7
  output: string | null;
@@ -30,6 +31,7 @@ export type TranscriptUiOptions = Readonly<{
30
31
  loadToolOutput: ((toolId: string) => Promise<ToolOutputResult>) | null;
31
32
  labels: Labels;
32
33
  vocabulary: Vocabulary;
34
+ envelopes: readonly EnvelopeParser[];
33
35
  fold: FoldPolicy;
34
36
  runMin: number;
35
37
  userTurns: UserTurnPolicy;
package/dist/context.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { createContext, useContext } from 'react';
3
3
  import { defaultVocabulary } from './vocabulary.js';
4
+ import { defaultEnvelopes } from './envelope.js';
4
5
  export const defaultLabels = {
5
6
  loading: 'loading…',
6
7
  running: 'running',
@@ -23,6 +24,7 @@ export const defaultOptions = {
23
24
  loadToolOutput: null,
24
25
  labels: defaultLabels,
25
26
  vocabulary: defaultVocabulary,
27
+ envelopes: defaultEnvelopes,
26
28
  fold: 'segments',
27
29
  runMin: 3,
28
30
  userTurns: 'boundary',
@@ -0,0 +1,10 @@
1
+ export type Envelope = Readonly<{
2
+ who: string | null;
3
+ id?: string | null;
4
+ at?: number | null;
5
+ body: string;
6
+ }>;
7
+ export type EnvelopeParser = (text: string) => Envelope | null;
8
+ export declare const spexEnvelope: EnvelopeParser;
9
+ export declare const defaultEnvelopes: readonly EnvelopeParser[];
10
+ export declare function parseEnvelope(text: string, parsers?: readonly EnvelopeParser[]): Envelope;
@@ -0,0 +1,18 @@
1
+ // `— from session "label" (id) on machine m. To reply: spex session send [--ssh addr] id "<your reply>"`
2
+ const SPEX_FOOTER = /\n*— from session (?:"(.*?)" \(([^\s)]+)\)|(\S+))(?: on machine \S+)?\. To reply: spex session send (?:--ssh \S+ )?\S+ "<your reply>"\s*$/;
3
+ export const spexEnvelope = (text) => {
4
+ const m = SPEX_FOOTER.exec(text || '');
5
+ if (!m)
6
+ return null;
7
+ const id = m[2] || m[3] || null;
8
+ return { who: m[1] || id, id, body: text.slice(0, m.index) };
9
+ };
10
+ export const defaultEnvelopes = [spexEnvelope];
11
+ export function parseEnvelope(text, parsers = defaultEnvelopes) {
12
+ for (const parse of parsers) {
13
+ const envelope = parse(text);
14
+ if (envelope)
15
+ return envelope;
16
+ }
17
+ return { who: null, body: text };
18
+ }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './vocabulary.js';
2
+ export * from './envelope.js';
2
3
  export * from './segments.js';
3
4
  export * from './context.js';
4
5
  export * from './icons.js';
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './vocabulary.js';
2
+ export * from './envelope.js';
2
3
  export * from './segments.js';
3
4
  export * from './context.js';
4
5
  export * from './icons.js';
@@ -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>;
@@ -19,7 +19,33 @@ export function extendVocabulary(base, extra) {
19
19
  targetKeys: extra.targetKeys ? [...extra.targetKeys, ...base.targetKeys.filter((key) => !extra.targetKeys.includes(key))] : base.targetKeys,
20
20
  };
21
21
  }
22
- export const toolVerb = (name, vocabulary = defaultVocabulary) => (name && vocabulary.verbs[name]) || name || 'tool';
22
+ // AN MCP TOOL IS NAMED BY ITS SERVER AND ITS TOOL. Every harness that speaks MCP writes the call as
23
+ // `mcp__<server>__<tool>`; the reader wants both halves, apart — measured across four transcript renderers,
24
+ // three knew the server in their data and lost it on the screen. The vocabulary may name the full id or the
25
+ // bare tool; an unnamed MCP tool reads as its tool half, never the whole mangled id.
26
+ export function toolName(name) {
27
+ const m = name ? /^mcp__(.+?)__(.+)$/.exec(name) : null;
28
+ return m ? { tool: m[2], server: m[1] } : { tool: name || 'tool', server: null };
29
+ }
30
+ export const toolVerb = (name, vocabulary = defaultVocabulary) => {
31
+ if (name && vocabulary.verbs[name])
32
+ return vocabulary.verbs[name];
33
+ const { tool } = toolName(name);
34
+ return vocabulary.verbs[tool] || tool;
35
+ };
36
+ // THE ARGUMENTS, WHEN OPENED, READ AS THE ARGUMENTS: a JSON object pretty-printed one field per line, a bare
37
+ // string (a script, a command) as itself. The wire form is one line; nobody reads one line of JSON.
38
+ export function prettyInput(input) {
39
+ if (typeof input !== 'string' || !input)
40
+ return '';
41
+ try {
42
+ const parsed = JSON.parse(input);
43
+ return parsed && typeof parsed === 'object' ? JSON.stringify(parsed, null, 2) : input;
44
+ }
45
+ catch {
46
+ return input;
47
+ }
48
+ }
23
49
  export const isQuietTool = (name, vocabulary = defaultVocabulary) => vocabulary.quiet.has(name);
24
50
  // The target, from the call's own arguments. `input` is the raw JSON of the arguments (or a bare string), so
25
51
  // this reads the field the tool actually names and shows NOTHING when it cannot — a wrong target is worse
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spexcode/transcript-ui",
3
- "version": "0.7.0-next.6",
3
+ "version": "0.7.0-next.8",
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.6"
27
+ "@spexcode/transcript": "0.7.0-next.8"
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 {