@zhushanwen/pi-session-reader 0.13.0 → 0.13.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 +4 -4
- package/src/__tests__/index.test.ts +17 -1
- package/src/tui/tool-render.ts +3 -28
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhushanwen/pi-session-reader",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"taiji": {
|
|
@@ -16,16 +16,16 @@
|
|
|
16
16
|
"pi-package"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@zhushanwen/extension-protocol": "0.
|
|
19
|
+
"@zhushanwen/extension-protocol": "0.24.0",
|
|
20
20
|
"@zhushanwen/pi-ext-guards": "0.5.0",
|
|
21
21
|
"@zhushanwen/pi-extension-logger": "0.6.2",
|
|
22
22
|
"@zhushanwen/session-core": "0.12.0",
|
|
23
|
-
"@zhushanwen/zcode-session-source": "0.2.
|
|
23
|
+
"@zhushanwen/zcode-session-source": "0.2.8"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@vitest/coverage-v8": "^4.1.9",
|
|
27
27
|
"vitest": "^4.1.8",
|
|
28
|
-
"@zhushanwen/subagent-core": "1.
|
|
28
|
+
"@zhushanwen/subagent-core": "2.1.0"
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
31
31
|
"index.ts",
|
|
@@ -2,7 +2,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
|
2
2
|
import { mkdtemp, mkdir, writeFile, rm } from 'node:fs/promises'
|
|
3
3
|
import { tmpdir } from 'node:os'
|
|
4
4
|
import { join } from 'node:path'
|
|
5
|
-
import type { ExtensionAPI } from '@earendil-works/pi-coding-agent'
|
|
5
|
+
import type { ExtensionAPI, Theme } from '@earendil-works/pi-coding-agent'
|
|
6
6
|
import { Check } from 'typebox/value'
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -107,6 +107,22 @@ describe('sessionReaderExtension - execute 契约', () => {
|
|
|
107
107
|
toolDef.execute('tc-1', { action: 'find' }, undefined, undefined, undefined),
|
|
108
108
|
).rejects.toThrow(/👉/)
|
|
109
109
|
})
|
|
110
|
+
|
|
111
|
+
it('renderResult 接线(C-ext-05):注册定义携带函数成员 + 折叠态输出 details.summary 一行', () => {
|
|
112
|
+
const toolDef = fake.registerTool.mock.calls[0][0] as {
|
|
113
|
+
renderResult: (result: unknown, options: { expanded: boolean }, theme: Theme) => { render: (width: number) => string[] }
|
|
114
|
+
}
|
|
115
|
+
expect(typeof toolDef.renderResult).toBe('function')
|
|
116
|
+
const renderTheme = { fg: (_token: string, text: string) => text } as unknown as Theme
|
|
117
|
+
const result = {
|
|
118
|
+
content: [{ type: 'text', text: 'session outline…' }],
|
|
119
|
+
details: { summary: 'Read 12 turns from session abc' },
|
|
120
|
+
}
|
|
121
|
+
// Text.render 按宽度 pad,trim 后断言(折叠态 = details.summary 一行)
|
|
122
|
+
const lines = toolDef.renderResult(result, { expanded: false }, renderTheme).render(400)
|
|
123
|
+
expect(lines.length).toBe(1)
|
|
124
|
+
expect(lines[0].trim()).toBe('Read 12 turns from session abc')
|
|
125
|
+
})
|
|
110
126
|
})
|
|
111
127
|
|
|
112
128
|
describe('sessionReaderExtension - execute 信号包采集(U3:ctx 全形态降级)', () => {
|
package/src/tui/tool-render.ts
CHANGED
|
@@ -7,32 +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 {
|
|
11
|
-
|
|
12
|
-
/** content[0] 的 text 纯文本(content 缺失或非 text 类型时兜底空串)。 */
|
|
13
|
-
function contentText(result: unknown): string {
|
|
14
|
-
const content = fieldValue(result, 'content')
|
|
15
|
-
if (!Array.isArray(content)) return ''
|
|
16
|
-
return firstContentText({ content })
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** unknown 值按字段名安全取值(index-signature 收窄,替代全可选结构断言)。 */
|
|
20
|
-
function fieldValue(v: unknown, key: string): unknown {
|
|
21
|
-
if (typeof v !== 'object' || v === null) return undefined
|
|
22
|
-
return (v as Record<string, unknown>)[key]
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** 从 details 安全读取 summary(容错非对象形态与旧版本 entry)。 */
|
|
26
|
-
function readDetailsSummary(result: unknown): string | undefined {
|
|
27
|
-
const summary = fieldValue(fieldValue(result, 'details'), 'summary')
|
|
28
|
-
return typeof summary === 'string' && summary !== '' ? summary : undefined
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** 折叠态回退:content 文本首行(多行 outline/detail 输出只取首行,保持一行摘要形态)。 */
|
|
32
|
-
function firstLine(text: string): string {
|
|
33
|
-
const idx = text.indexOf('\n')
|
|
34
|
-
return idx === -1 ? text : text.slice(0, idx)
|
|
35
|
-
}
|
|
10
|
+
import { firstLine, readDetailsSummary, resultContentText } from '@zhushanwen/extension-protocol'
|
|
36
11
|
|
|
37
12
|
/**
|
|
38
13
|
* 折叠态(expanded=false)= details.summary 一行(dim);展开态 = content 纯文本。
|
|
@@ -42,7 +17,7 @@ export function renderSessionReadResult(
|
|
|
42
17
|
options: { expanded: boolean },
|
|
43
18
|
theme: Theme,
|
|
44
19
|
): Text {
|
|
45
|
-
if (options.expanded) return new Text(
|
|
46
|
-
const summary = readDetailsSummary(result) ?? firstLine(
|
|
20
|
+
if (options.expanded) return new Text(resultContentText(result), 0, 0)
|
|
21
|
+
const summary = readDetailsSummary(result) ?? firstLine(resultContentText(result))
|
|
47
22
|
return new Text(theme.fg('dim', summary), 0, 0)
|
|
48
23
|
}
|