@pi-kaush/pi-tool-call-markers 0.3.18 → 0.3.20
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/package.json +1 -1
- package/src/index.ts +93 -70
- package/src/question-block.ts +31 -23
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -325,14 +325,11 @@ const MCP_MODE_KEYS = [
|
|
|
325
325
|
"action",
|
|
326
326
|
] as const;
|
|
327
327
|
|
|
328
|
-
//
|
|
329
|
-
//
|
|
330
|
-
|
|
331
|
-
// empty, or unrecognized selectors return undefined so the caller shows the
|
|
332
|
-
// complete compact args instead of claiming which operation executed.
|
|
333
|
-
function mcpProxyCallLabel(
|
|
328
|
+
// Only one valid selector can name an operation. Unknown or conflicting
|
|
329
|
+
// shapes stay raw because the adapter's dispatch order is internal.
|
|
330
|
+
function mcpProxySelectors(
|
|
334
331
|
record: Record<string, unknown>,
|
|
335
|
-
): string | undefined {
|
|
332
|
+
): string[] | undefined {
|
|
336
333
|
const selectors: string[] = [];
|
|
337
334
|
// An empty search still runs a search; every other selector must be a
|
|
338
335
|
// non-empty string to name an operation at all.
|
|
@@ -345,6 +342,25 @@ function mcpProxyCallLabel(
|
|
|
345
342
|
if (typeof value !== "string" || value.length === 0) return undefined;
|
|
346
343
|
selectors.push(key);
|
|
347
344
|
}
|
|
345
|
+
return selectors;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// Append compact arguments left after the selector to an MCP label.
|
|
349
|
+
function appendMcpRemainder(
|
|
350
|
+
label: string,
|
|
351
|
+
rest: Record<string, unknown>,
|
|
352
|
+
): string {
|
|
353
|
+
const remainder = squashJsonish(rest);
|
|
354
|
+
return remainder ? `${label} ${remainder}` : label;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// A concise one-line label for the adapter's "mcp" proxy from the call's
|
|
358
|
+
// shape alone. Ambiguous shapes keep their complete compact args.
|
|
359
|
+
function mcpProxyCallLabel(
|
|
360
|
+
record: Record<string, unknown>,
|
|
361
|
+
): string | undefined {
|
|
362
|
+
const selectors = mcpProxySelectors(record);
|
|
363
|
+
if (!selectors) return undefined;
|
|
348
364
|
|
|
349
365
|
const server =
|
|
350
366
|
typeof record.server === "string" && record.server.length > 0
|
|
@@ -357,8 +373,7 @@ function mcpProxyCallLabel(
|
|
|
357
373
|
if (selectors.length === 0) {
|
|
358
374
|
// No mode selector: the adapter lists a named server or reports status.
|
|
359
375
|
const label = server === undefined ? "mcp status" : `mcp list ${server}`;
|
|
360
|
-
|
|
361
|
-
return restJson ? `${label} ${restJson}` : label;
|
|
376
|
+
return appendMcpRemainder(label, rest);
|
|
362
377
|
}
|
|
363
378
|
if (selectors.length !== 1) return undefined;
|
|
364
379
|
|
|
@@ -374,8 +389,7 @@ function mcpProxyCallLabel(
|
|
|
374
389
|
if (key === "search") {
|
|
375
390
|
const label =
|
|
376
391
|
`mcp search ${String(record.search)}`.trimEnd() + serverSuffix;
|
|
377
|
-
|
|
378
|
-
return restJson ? `${label} ${restJson}` : label;
|
|
392
|
+
return appendMcpRemainder(label, rest);
|
|
379
393
|
}
|
|
380
394
|
if (key === "action") {
|
|
381
395
|
const name = String(record.action);
|
|
@@ -386,17 +400,16 @@ function mcpProxyCallLabel(
|
|
|
386
400
|
const input = squashJsonish(record.args);
|
|
387
401
|
if (input) label += ` ${input}`;
|
|
388
402
|
}
|
|
389
|
-
|
|
390
|
-
return restJson ? `${label} ${restJson}` : label;
|
|
403
|
+
return appendMcpRemainder(label, rest);
|
|
391
404
|
}
|
|
392
405
|
// connect / describe / instructions: the adapter dispatches these modes
|
|
393
406
|
// without params.server, so a server argument is shown raw rather than as
|
|
394
407
|
// a scope suffix that implies an operation that never ran.
|
|
395
408
|
const label = `mcp ${key} ${String(record[key])}`;
|
|
396
|
-
|
|
409
|
+
return appendMcpRemainder(
|
|
410
|
+
label,
|
|
397
411
|
server === undefined ? rest : { ...rest, server },
|
|
398
412
|
);
|
|
399
|
-
return restJson ? `${label} ${restJson}` : label;
|
|
400
413
|
}
|
|
401
414
|
|
|
402
415
|
// Builds a one-line "tool {args}" label from the call arguments. The
|
|
@@ -785,54 +798,55 @@ function renderedCallSummary(
|
|
|
785
798
|
width: number,
|
|
786
799
|
theme: ThemeLike,
|
|
787
800
|
): string {
|
|
801
|
+
const fallback = () => {
|
|
802
|
+
const args = compactArgs(row.args);
|
|
803
|
+
return args
|
|
804
|
+
? fgCollapsed(theme, "toolOutput", args)
|
|
805
|
+
: fgCollapsed(theme, "muted", "(no arguments)");
|
|
806
|
+
};
|
|
788
807
|
let component = row.callRendererComponent;
|
|
789
808
|
if (!component && Array.isArray(row.contentBox?.children)) {
|
|
790
809
|
component = row.contentBox.children[0] as ComponentLike | undefined;
|
|
791
810
|
}
|
|
792
|
-
if (component
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
const fallback = compactArgs(row.args);
|
|
833
|
-
return fallback
|
|
834
|
-
? fgCollapsed(theme, "toolOutput", fallback)
|
|
835
|
-
: fgCollapsed(theme, "muted", "(no arguments)");
|
|
811
|
+
if (!component || typeof component.render !== "function") return fallback();
|
|
812
|
+
|
|
813
|
+
const visibleLines = component
|
|
814
|
+
.render(Math.max(1, width))
|
|
815
|
+
.filter(hasVisibleContent);
|
|
816
|
+
const rendered = visibleLines.slice(0, 3);
|
|
817
|
+
const line = rendered[0];
|
|
818
|
+
if (!line) return fallback();
|
|
819
|
+
|
|
820
|
+
const first = trimRenderedLine(line);
|
|
821
|
+
const plain = stripAnsi(first);
|
|
822
|
+
const match = /^(\s*)(\S+)(\s*)/.exec(plain);
|
|
823
|
+
if (!match) return fallback();
|
|
824
|
+
|
|
825
|
+
const expectedToken = row.toolName === "bash" ? "$" : row.toolName;
|
|
826
|
+
const hasKnownHeading =
|
|
827
|
+
match[2] === expectedToken ||
|
|
828
|
+
(row.toolName === "read" &&
|
|
829
|
+
(match[2] === "read" || match[2] === "[skill]"));
|
|
830
|
+
const summaryStart = hasKnownHeading
|
|
831
|
+
? visibleWidth((match[1] ?? "") + (match[2] ?? "") + (match[3] ?? ""))
|
|
832
|
+
: 0;
|
|
833
|
+
const firstSummary = removeTrailingExpandHint(
|
|
834
|
+
sliceByColumn(
|
|
835
|
+
first,
|
|
836
|
+
summaryStart,
|
|
837
|
+
Math.max(0, visibleWidth(first) - summaryStart),
|
|
838
|
+
),
|
|
839
|
+
);
|
|
840
|
+
const continuations = rendered
|
|
841
|
+
.slice(1)
|
|
842
|
+
.map(trimRenderedLine)
|
|
843
|
+
.filter(hasVisibleContent);
|
|
844
|
+
if (visibleLines.length > rendered.length)
|
|
845
|
+
continuations.push(fgCollapsed(theme, "muted", "…"));
|
|
846
|
+
const compact = [firstSummary, ...continuations]
|
|
847
|
+
.filter(hasVisibleContent)
|
|
848
|
+
.join(fgCollapsed(theme, "muted", " · "));
|
|
849
|
+
return hasVisibleContent(compact) ? compact : fallback();
|
|
836
850
|
}
|
|
837
851
|
|
|
838
852
|
// Codemode carries its tunables in the script's first line —
|
|
@@ -1217,6 +1231,25 @@ function subagentProgressText(row: ToolExecutionRow): string | undefined {
|
|
|
1217
1231
|
return parts.length > 0 ? parts.join(" · ") : undefined;
|
|
1218
1232
|
}
|
|
1219
1233
|
|
|
1234
|
+
function subagentPlanOutcome(
|
|
1235
|
+
row: ToolExecutionRow,
|
|
1236
|
+
failed: boolean,
|
|
1237
|
+
progress: string | undefined,
|
|
1238
|
+
budget: number,
|
|
1239
|
+
theme: ThemeLike,
|
|
1240
|
+
): string | undefined {
|
|
1241
|
+
if (failed) return collapsedOutcome(row, budget, theme);
|
|
1242
|
+
if (isLiveRow(row))
|
|
1243
|
+
return theme.fg("warning", progress ? `→ ${progress}` : "…");
|
|
1244
|
+
if (row.result)
|
|
1245
|
+
return fgCollapsed(
|
|
1246
|
+
theme,
|
|
1247
|
+
"toolOutput",
|
|
1248
|
+
progress ? `→ ${progress}` : "→ done",
|
|
1249
|
+
);
|
|
1250
|
+
return theme.fg("warning", "…");
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1220
1253
|
// Subagents render as an ordinary unboxed tool block: a `│` heading with the
|
|
1221
1254
|
// plan kind/count/scope, then the numbered chain steps or parallel tasks with
|
|
1222
1255
|
// agent identities (emoji, profile badge, name badge) in accent. Single calls
|
|
@@ -1256,17 +1289,7 @@ function renderSubagentPlan(
|
|
|
1256
1289
|
const marker = collapsedAnchor(theme, color, undefined);
|
|
1257
1290
|
const budget = Math.max(1, width - visibleWidth(marker));
|
|
1258
1291
|
const progress = subagentProgressText(row);
|
|
1259
|
-
const outcome = failed
|
|
1260
|
-
? collapsedOutcome(row, budget, theme)
|
|
1261
|
-
: isLiveRow(row)
|
|
1262
|
-
? theme.fg("warning", progress ? `→ ${progress}` : "…")
|
|
1263
|
-
: row.result
|
|
1264
|
-
? fgCollapsed(
|
|
1265
|
-
theme,
|
|
1266
|
-
"toolOutput",
|
|
1267
|
-
progress ? `→ ${progress}` : "→ done",
|
|
1268
|
-
)
|
|
1269
|
-
: theme.fg("warning", "…");
|
|
1292
|
+
const outcome = subagentPlanOutcome(row, failed, progress, budget, theme);
|
|
1270
1293
|
const headline = (label: string) =>
|
|
1271
1294
|
marker +
|
|
1272
1295
|
(outcome
|
package/src/question-block.ts
CHANGED
|
@@ -79,35 +79,43 @@ function isQuestionToolName(name: string | undefined): boolean {
|
|
|
79
79
|
// carrying the question text, and each entry's answer arrives as `answer`
|
|
80
80
|
// (option label or typed text) or `selected` (multi-select labels). Any
|
|
81
81
|
// deviation fails the shape check so an unrelated tool is never reshaped.
|
|
82
|
+
function parseAnswerEntry(item: unknown): AnswerEntry | undefined {
|
|
83
|
+
if (!isRecord(item) || typeof item.question !== "string") return undefined;
|
|
84
|
+
|
|
85
|
+
const answer = item.answer;
|
|
86
|
+
if (answer !== undefined && answer !== null && typeof answer !== "string") {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const selected = item.selected;
|
|
91
|
+
if (
|
|
92
|
+
selected !== undefined &&
|
|
93
|
+
(!Array.isArray(selected) ||
|
|
94
|
+
!selected.every((label) => typeof label === "string"))
|
|
95
|
+
) {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
question: item.question,
|
|
101
|
+
questionIndex:
|
|
102
|
+
typeof item.questionIndex === "number" ? item.questionIndex : undefined,
|
|
103
|
+
kind: typeof item.kind === "string" ? item.kind : undefined,
|
|
104
|
+
answer,
|
|
105
|
+
selected: selected as string[] | undefined,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
82
109
|
function parseAnswerEntries(details: unknown): AnswerEntry[] | undefined {
|
|
83
110
|
if (!isRecord(details)) return undefined;
|
|
84
111
|
const raw = details.answers;
|
|
85
112
|
if (!Array.isArray(raw)) return undefined;
|
|
113
|
+
|
|
86
114
|
const entries: AnswerEntry[] = [];
|
|
87
115
|
for (const item of raw) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return undefined;
|
|
92
|
-
}
|
|
93
|
-
const selected = item.selected;
|
|
94
|
-
if (
|
|
95
|
-
selected !== undefined &&
|
|
96
|
-
!(
|
|
97
|
-
Array.isArray(selected) &&
|
|
98
|
-
selected.every((label) => typeof label === "string")
|
|
99
|
-
)
|
|
100
|
-
) {
|
|
101
|
-
return undefined;
|
|
102
|
-
}
|
|
103
|
-
entries.push({
|
|
104
|
-
question: item.question,
|
|
105
|
-
questionIndex:
|
|
106
|
-
typeof item.questionIndex === "number" ? item.questionIndex : undefined,
|
|
107
|
-
kind: typeof item.kind === "string" ? item.kind : undefined,
|
|
108
|
-
answer,
|
|
109
|
-
selected: selected as string[] | undefined,
|
|
110
|
-
});
|
|
116
|
+
const entry = parseAnswerEntry(item);
|
|
117
|
+
if (!entry) return undefined;
|
|
118
|
+
entries.push(entry);
|
|
111
119
|
}
|
|
112
120
|
return entries;
|
|
113
121
|
}
|