pi-cc-extensions 0.7.5 → 0.7.6
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/README.md +3 -3
- package/extensions/context.ts +12 -4
- package/extensions/{session-reference/index.ts → session-reference.ts} +1 -1
- package/package.json +2 -2
- package/extensions/README.md +0 -3
- package/extensions/session-reference/README.md +0 -28
- /package/extensions/{session-reference/core.ts → session-reference-core.ts} +0 -0
package/README.md
CHANGED
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
- Pi 默认输入栏
|
|
55
55
|
- Edit / Write 的 Diff 预览
|
|
56
56
|
- 工具结果的折叠与展开
|
|
57
|
-
-
|
|
57
|
+
- 类 claude code 滚动到底部 button
|
|
58
58
|
|
|
59
59
|
常用命令:
|
|
60
60
|
|
|
@@ -79,13 +79,13 @@
|
|
|
79
79
|
|
|
80
80
|
### 历史 Session 引用
|
|
81
81
|
|
|
82
|
-
`extensions/session-reference
|
|
82
|
+
`extensions/session-reference.ts` 将历史 Session 接入 `@` 补全:
|
|
83
83
|
|
|
84
84
|
1. 在提示词中输入 `@`。
|
|
85
85
|
2. 从 `[Session] ...` 或 `[SubAgent] ...` 补全项中选择要引用的上下文。
|
|
86
86
|
3. 提交时以 `@session:<session-id>` 引用其当前有效上下文。
|
|
87
87
|
|
|
88
|
-
Session 模糊查询默认显示 3 个候选,并与文件候选按 1:2 交错排列;路径型查询优先显示文件。若已加载 `pi-subagents`,也可直接引用现有 SubAgent。一次提示词可以引用多个 Session
|
|
88
|
+
Session 模糊查询默认显示 3 个候选,并与文件候选按 1:2 交错排列;路径型查询优先显示文件。若已加载 `pi-subagents`,也可直接引用现有 SubAgent。一次提示词可以引用多个 Session;扩展会自动去重,并限制注入规模以避免上下文无限膨胀。
|
|
89
89
|
|
|
90
90
|
### SubAgent `@` 补全
|
|
91
91
|
|
package/extensions/context.ts
CHANGED
|
@@ -46,7 +46,7 @@ export function createWrappedTextCache(content: string): {
|
|
|
46
46
|
|
|
47
47
|
export async function showTextPreview(ctx: Pick<ExtensionCommandContext, "ui">, title: string, rawContent: string): Promise<void> {
|
|
48
48
|
const content = normalizePreviewText(rawContent);
|
|
49
|
-
await ctx.ui.custom
|
|
49
|
+
await ctx.ui.custom((tui, theme, _keybindings, done) => {
|
|
50
50
|
let scrollOffset = 0;
|
|
51
51
|
let pageSize = 1;
|
|
52
52
|
let totalLines = 1;
|
|
@@ -63,7 +63,7 @@ export async function showTextPreview(ctx: Pick<ExtensionCommandContext, "ui">,
|
|
|
63
63
|
},
|
|
64
64
|
handleInput(data: string) {
|
|
65
65
|
if (matchesKey(data, Key.escape) || matchesKey(data, Key.ctrl("c"))) {
|
|
66
|
-
done();
|
|
66
|
+
done(undefined);
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
69
|
if (matchesKey(data, Key.up)) scrollTo(scrollOffset - 1);
|
|
@@ -161,6 +161,12 @@ const tokenEstimate = (value: unknown): number => {
|
|
|
161
161
|
return Math.max(0, Math.ceil(text.length / 4));
|
|
162
162
|
};
|
|
163
163
|
|
|
164
|
+
type ToolPreviewInfo = {
|
|
165
|
+
name: string;
|
|
166
|
+
description?: string;
|
|
167
|
+
promptGuidelines?: string[];
|
|
168
|
+
};
|
|
169
|
+
|
|
164
170
|
export function scaleParts(parts: ContextPart[], target: number): ContextPart[] {
|
|
165
171
|
const estimated = parts.reduce((sum, part) => sum + part.tokens, 0);
|
|
166
172
|
if (estimated === 0 || target <= 0) return parts;
|
|
@@ -233,7 +239,9 @@ export default function contextUsageExtension(pi: ExtensionAPI) {
|
|
|
233
239
|
}
|
|
234
240
|
|
|
235
241
|
const options = ctx.getSystemPromptOptions();
|
|
236
|
-
const toolByName = new Map
|
|
242
|
+
const toolByName = new Map<string, ToolPreviewInfo>(
|
|
243
|
+
(pi.getAllTools() as ToolPreviewInfo[]).map((tool) => [tool.name, tool] as const),
|
|
244
|
+
);
|
|
237
245
|
const toolContent = (options.selectedTools ?? []).map((name) => {
|
|
238
246
|
const tool = toolByName.get(name);
|
|
239
247
|
const lines = [`## ${name}`];
|
|
@@ -273,7 +281,7 @@ export default function contextUsageExtension(pi: ExtensionAPI) {
|
|
|
273
281
|
let selectedPreviewIndex = 0;
|
|
274
282
|
|
|
275
283
|
while (true) {
|
|
276
|
-
const action = await ctx.ui.custom
|
|
284
|
+
const action = await ctx.ui.custom((tui, theme, _keybindings, done) => {
|
|
277
285
|
let previewHitboxes: Array<{ key: PreviewKey; row: number; startCol: number; endCol: number }> = [];
|
|
278
286
|
|
|
279
287
|
const padLine = (text: string, width: number): string => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-cc-extensions",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.6",
|
|
4
4
|
"description": "Personal extensions for the Pi coding agent",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"extensions": [
|
|
17
17
|
"./extensions/claude-code-style.ts",
|
|
18
18
|
"./extensions/context.ts",
|
|
19
|
-
"./extensions/session-reference
|
|
19
|
+
"./extensions/session-reference.ts",
|
|
20
20
|
"./extensions/agent-autocomplete.ts"
|
|
21
21
|
]
|
|
22
22
|
},
|
package/extensions/README.md
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# Session Reference
|
|
2
|
-
|
|
3
|
-
在 pi 编辑器中输入 `@`,从统一补全列表选择 `[Session] ...`,即可把历史 Session 绑定为:
|
|
4
|
-
|
|
5
|
-
```text
|
|
6
|
-
@session:<session-id>
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
提交 prompt 时,扩展读取该 Session 当前有效分支(遵循分支与 compaction),以自定义上下文消息注入当前 Session。历史内容被标记为不可信背景上下文,不会切换或合并 Session。
|
|
10
|
-
|
|
11
|
-
## 行为
|
|
12
|
-
|
|
13
|
-
- 搜索全部 pi 历史 Session;当前 Workspace 的 Session 优先。
|
|
14
|
-
- Session 模糊查询默认最多显示 3 个候选。
|
|
15
|
-
- 与 pi 原有 `@` 文件补全并存:普通查询按 1:2 交错排列 Session 与文件,路径型查询优先显示文件。
|
|
16
|
-
- 若已加载 `pi-subagents`,`@` 补全会同时显示现有 SubAgent,并引用其当前有效上下文。
|
|
17
|
-
- 支持一个 prompt 引用多个 Session,并自动去重;单次最多注入前 5 个。
|
|
18
|
-
- 跳过历史 Session 中嵌套的 Session 引用,避免递归膨胀。
|
|
19
|
-
- 上下文限制:单条消息 8 KB、单 Session 24 KB、总计 48 KB;超限保留开头和结尾。
|
|
20
|
-
- 选择后仅插入引用标记;真正读取和注入发生在提交 prompt 时。
|
|
21
|
-
|
|
22
|
-
项目扩展可通过 `/reload` 热重载。
|
|
23
|
-
|
|
24
|
-
## 验证
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
node --test .pi/extensions/session-reference/core.test.ts
|
|
28
|
-
```
|
|
File without changes
|