feat(read): compact resource read rendering
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { join } from "node:path";
|
||||
import { Text, type TUI } from "@mariozechner/pi-tui";
|
||||
import stripAnsi from "strip-ansi";
|
||||
import { Type } from "typebox";
|
||||
import { beforeAll, describe, expect, test } from "vitest";
|
||||
import { getReadmePath } from "../src/config.js";
|
||||
import type { ToolDefinition } from "../src/core/extensions/types.js";
|
||||
import { type BashOperations, createBashToolDefinition } from "../src/core/tools/bash.js";
|
||||
import { createReadTool, createReadToolDefinition } from "../src/core/tools/read.js";
|
||||
@@ -145,7 +147,7 @@ describe("ToolExecutionComponent parity", () => {
|
||||
const component = new ToolExecutionComponent(
|
||||
"read",
|
||||
"tool-4b",
|
||||
{ path: "README.md" },
|
||||
{ path: "notes.txt" },
|
||||
{},
|
||||
overrideDefinition,
|
||||
createFakeTui(),
|
||||
@@ -313,7 +315,7 @@ describe("ToolExecutionComponent parity", () => {
|
||||
const component = new ToolExecutionComponent(
|
||||
"read",
|
||||
"tool-8",
|
||||
{ path: "README.md" },
|
||||
{ path: "notes.txt" },
|
||||
{},
|
||||
createReadToolDefinition(process.cwd()),
|
||||
createFakeTui(),
|
||||
@@ -328,4 +330,58 @@ describe("ToolExecutionComponent parity", () => {
|
||||
expect(rendered).toContain("two");
|
||||
expect(rendered).not.toContain("two\n\n");
|
||||
});
|
||||
|
||||
for (const scenario of [
|
||||
{
|
||||
title: "SKILL.md",
|
||||
path: join(process.cwd(), "attio", "SKILL.md"),
|
||||
content: "---\nname: attio\ndescription: CRM helper\n---\n\n# Hidden skill instructions",
|
||||
compact: "[skill] attio",
|
||||
hidden: "Hidden skill instructions",
|
||||
absent: "read skill attio",
|
||||
},
|
||||
{
|
||||
title: "AGENTS.md",
|
||||
path: join(process.cwd(), "AGENTS.md"),
|
||||
content: "Hidden resource instructions",
|
||||
compact: "read resource AGENTS.md",
|
||||
hidden: "Hidden resource instructions",
|
||||
absent: undefined,
|
||||
},
|
||||
{
|
||||
title: "Pi documentation",
|
||||
path: getReadmePath(),
|
||||
content: "Hidden docs content",
|
||||
compact: "read docs README.md",
|
||||
hidden: "Hidden docs content",
|
||||
absent: undefined,
|
||||
},
|
||||
] as const) {
|
||||
test(`renders ${scenario.title} read results compactly until expanded`, () => {
|
||||
const component = new ToolExecutionComponent(
|
||||
"read",
|
||||
`tool-compact-${scenario.title}`,
|
||||
{ path: scenario.path },
|
||||
{},
|
||||
createReadToolDefinition(process.cwd()),
|
||||
createFakeTui(),
|
||||
process.cwd(),
|
||||
);
|
||||
component.updateResult(
|
||||
{ content: [{ type: "text", text: scenario.content }], details: undefined, isError: false },
|
||||
false,
|
||||
);
|
||||
|
||||
const collapsed = stripAnsi(component.render(120).join("\n"));
|
||||
expect(collapsed).toContain(scenario.compact);
|
||||
expect(collapsed).not.toContain(scenario.hidden);
|
||||
if (scenario.absent) {
|
||||
expect(collapsed).not.toContain(scenario.absent);
|
||||
}
|
||||
|
||||
component.setExpanded(true);
|
||||
const expanded = stripAnsi(component.render(120).join("\n"));
|
||||
expect(expanded).toContain(scenario.hidden);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user