@zhushanwen/pi-rename-session 0.14.0 → 0.14.1
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 +2 -2
- package/src/__tests__/index.test.ts +17 -1
- package/src/render.ts +3 -22
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhushanwen/pi-rename-session",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"taiji": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"pi-package"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@zhushanwen/extension-protocol": "0.
|
|
38
|
+
"@zhushanwen/extension-protocol": "0.24.0",
|
|
39
39
|
"@zhushanwen/pi-ext-guards": "0.5.0",
|
|
40
40
|
"@zhushanwen/pi-extension-logger": "0.6.2",
|
|
41
41
|
"@zhushanwen/pi-llm-shared": "0.12.0"
|
|
@@ -11,7 +11,7 @@ vi.mock("@zhushanwen/pi-extension-logger", () => ({
|
|
|
11
11
|
}));
|
|
12
12
|
|
|
13
13
|
import type { Api, Model, Usage } from "@earendil-works/pi-ai";
|
|
14
|
-
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
14
|
+
import type { ExtensionAPI, ExtensionContext, Theme } from "@earendil-works/pi-coding-agent";
|
|
15
15
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
16
16
|
|
|
17
17
|
// mock llm-shared:只 override resolveModel + callLLM(callRenameLLM 的依赖),
|
|
@@ -780,6 +780,7 @@ describe("usage 记录接线(appendUsageEntry 回调注入)", () => {
|
|
|
780
780
|
interface RegisteredRenameTool {
|
|
781
781
|
name: string;
|
|
782
782
|
parameters: object;
|
|
783
|
+
renderResult: (result: unknown, options: { expanded: boolean }, theme: Theme) => { render: (width: number) => string[] };
|
|
783
784
|
execute: (
|
|
784
785
|
toolCallId: string,
|
|
785
786
|
params: { title: string },
|
|
@@ -819,6 +820,21 @@ describe("rename_session 工具注册与 execute 检查(D3)", () => {
|
|
|
819
820
|
expect(tool.parameters).toHaveProperty("properties.title");
|
|
820
821
|
});
|
|
821
822
|
|
|
823
|
+
it("TC-T1b: renderResult 接线(C-ext-05):注册定义携带函数成员 + 折叠态输出 details.summary 一行", () => {
|
|
824
|
+
setupWithMode(AGENT_TOOL_CONFIG);
|
|
825
|
+
const tool = setup.registeredTool as RegisteredRenameTool;
|
|
826
|
+
expect(typeof tool.renderResult).toBe("function");
|
|
827
|
+
const renderTheme = { fg: (_token: string, text: string) => text } as unknown as Theme;
|
|
828
|
+
const result = {
|
|
829
|
+
content: [{ type: "text", text: "已命名:new-title" }],
|
|
830
|
+
details: { summary: 'Renamed session to "new-title"' },
|
|
831
|
+
};
|
|
832
|
+
// Text.render 按宽度 pad,trim 后断言(折叠态 = details.summary 一行)
|
|
833
|
+
const lines = tool.renderResult(result, { expanded: false }, renderTheme).render(400);
|
|
834
|
+
expect(lines.length).toBe(1);
|
|
835
|
+
expect(lines[0].trim()).toBe('Renamed session to "new-title"');
|
|
836
|
+
});
|
|
837
|
+
|
|
822
838
|
it("TC-T2: load 时 mode=first-prompt → 工具不注册(三值互斥,工具范围 load 求值)", () => {
|
|
823
839
|
setupWithMode(FIRST_PROMPT_CONFIG);
|
|
824
840
|
expect(setup.registerToolMock).not.toHaveBeenCalled();
|
package/src/render.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
9
9
|
import { Text } from "@earendil-works/pi-tui";
|
|
10
|
-
import {
|
|
10
|
+
import { readDetailsSummary, resultContentText } from "@zhushanwen/extension-protocol";
|
|
11
11
|
|
|
12
12
|
/** rename_session 工具 result 的 details 形状(summary 由 buildRenameSessionSummary 产出)。 */
|
|
13
13
|
export interface RenameSessionDetails { // oe-exempt:20261017:framework:details 数据形状窄 view(单实现消费,非抽象接口)
|
|
@@ -19,25 +19,6 @@ export function buildRenameSessionSummary(params: { title: string }): string {
|
|
|
19
19
|
return `Renamed session to "${params.title}"`;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
/** unknown 值按字段名安全取值(index-signature 收窄,替代全可选结构断言)。 */
|
|
23
|
-
function fieldValue(v: unknown, key: string): unknown {
|
|
24
|
-
if (typeof v !== "object" || v === null) return undefined;
|
|
25
|
-
return (v as Record<string, unknown>)[key];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** 从 tool result 的 details 安全读取 summary(容错历史 entry 与非对象形态)。 */
|
|
29
|
-
function readDetailsSummary(result: unknown): string | undefined {
|
|
30
|
-
const summary = fieldValue(fieldValue(result, "details"), "summary");
|
|
31
|
-
return typeof summary === "string" && summary !== "" ? summary : undefined;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** content[0] 的 text 纯文本(content 缺失或非 text 类型时兜底空串)。 */
|
|
35
|
-
function contentText(result: unknown): string {
|
|
36
|
-
const content = fieldValue(result, "content");
|
|
37
|
-
if (!Array.isArray(content)) return "";
|
|
38
|
-
return firstContentText({ content });
|
|
39
|
-
}
|
|
40
|
-
|
|
41
22
|
/**
|
|
42
23
|
* TUI renderResult:折叠态(expanded=false)= details.summary 一行(dim);展开态 =
|
|
43
24
|
* content 纯文本。summary 缺失(旧版本持久化 entry)时折叠态回退 content 文本。
|
|
@@ -48,7 +29,7 @@ export function renderRenameSessionResult(
|
|
|
48
29
|
theme: Theme,
|
|
49
30
|
): Text {
|
|
50
31
|
const summary = readDetailsSummary(result);
|
|
51
|
-
const collapsed = summary ?? (
|
|
52
|
-
const text = options.expanded ?
|
|
32
|
+
const collapsed = summary ?? (resultContentText(result) || "Renamed");
|
|
33
|
+
const text = options.expanded ? resultContentText(result) : collapsed;
|
|
53
34
|
return new Text(theme.fg("dim", text), 0, 0);
|
|
54
35
|
}
|