@trim21/personal-pi-extensions 0.0.277 → 0.0.280
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
CHANGED
package/src/claude-code/files.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { fileURLToPath } from "node:url";
|
|
|
7
7
|
import type { ImageContent, TextContent } from "@earendil-works/pi-ai";
|
|
8
8
|
import {
|
|
9
9
|
type ExtensionAPI,
|
|
10
|
+
type ExtensionContext,
|
|
10
11
|
generateDiffString,
|
|
11
12
|
generateUnifiedPatch,
|
|
12
13
|
withFileMutationQueue,
|
|
@@ -16,6 +17,8 @@ import { Type } from "typebox";
|
|
|
16
17
|
import { guardWriteAccess } from "../lib/write-guard.js";
|
|
17
18
|
import {
|
|
18
19
|
type ClaudeCodeState,
|
|
20
|
+
createClaudeCodeState,
|
|
21
|
+
deserializeReads,
|
|
19
22
|
didYouMean,
|
|
20
23
|
type FileSnapshot,
|
|
21
24
|
requireAbsolutePath,
|
|
@@ -528,3 +531,53 @@ export function registerFileTools(pi: ExtensionAPI, state: ClaudeCodeState): voi
|
|
|
528
531
|
},
|
|
529
532
|
});
|
|
530
533
|
}
|
|
534
|
+
|
|
535
|
+
/** 会更新 reads state 并随 details 持久化快照的工具名。 */
|
|
536
|
+
const FILE_TOOL_NAMES = new Set(["Read", "Edit", "Write"]);
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* 从当前分支的历史工具结果重建已读记账。先清空再重放,保证 state 只反映
|
|
540
|
+
* 当前分支:rewind / fork / resume 后,被抛弃分支上的 Read 不再残留。
|
|
541
|
+
*/
|
|
542
|
+
function restoreFileReads(
|
|
543
|
+
state: ClaudeCodeState,
|
|
544
|
+
sessionManager: ExtensionContext["sessionManager"],
|
|
545
|
+
): void {
|
|
546
|
+
state.reads.clear();
|
|
547
|
+
for (const entry of sessionManager.getBranch()) {
|
|
548
|
+
if (entry.type !== "message" || entry.message.role !== "toolResult") continue;
|
|
549
|
+
if (!FILE_TOOL_NAMES.has(entry.message.toolName)) continue;
|
|
550
|
+
const details = entry.message.details as { reads?: unknown } | undefined;
|
|
551
|
+
if (!details?.reads) continue;
|
|
552
|
+
for (const [filePath, snapshot] of deserializeReads(details.reads)) {
|
|
553
|
+
state.reads.set(filePath, snapshot);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* 独立扩展入口:files.ts 可单独经 `-e claude-code/files.ts` 加载(spawn-agent
|
|
560
|
+
* 子代理把 Read/Edit/Write 工具名映射到本文件),无需经 index.ts。reads
|
|
561
|
+
* state 归本文件所有:扩展实例内创建,并随 session 事件从历史分支恢复,
|
|
562
|
+
* 与主进程 index.ts 聚合加载时的行为一致。
|
|
563
|
+
*/
|
|
564
|
+
export default function claudeCodeFileTools(pi: ExtensionAPI): void {
|
|
565
|
+
const state = createClaudeCodeState();
|
|
566
|
+
|
|
567
|
+
// 扩展实例在进程启动 / /reload / /new / /resume / /fork 时重建,内存里的
|
|
568
|
+
// 已读记账随之丢失。这里从当前分支的历史工具结果里恢复:digest 是当时的值,
|
|
569
|
+
// 若文件在此期间被外部修改,Edit/Write 时的指纹对比仍会要求重新 Read,
|
|
570
|
+
// 防呆语义不因重建而弱化。
|
|
571
|
+
pi.on("session_start", (_event, ctx) => {
|
|
572
|
+
restoreFileReads(state, ctx.sessionManager);
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
// rewind / 树内跳转走 navigateTree → branch(),只发 session_tree 不发
|
|
576
|
+
// session_start,扩展实例也不重建。这里同样重放当前分支,丢弃被抛弃分支
|
|
577
|
+
// 的记账,避免 state 与当前分支脱节。
|
|
578
|
+
pi.on("session_tree", (_event, ctx) => {
|
|
579
|
+
restoreFileReads(state, ctx.sessionManager);
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
registerFileTools(pi, state);
|
|
583
|
+
}
|
package/src/claude-code/glob.ts
CHANGED
|
@@ -154,3 +154,8 @@ export function registerGlobTool(pi: ExtensionAPI): void {
|
|
|
154
154
|
},
|
|
155
155
|
});
|
|
156
156
|
}
|
|
157
|
+
|
|
158
|
+
// 独立扩展入口:spawn-agent 子代理声明 `Glob` 工具时按本文件 `-e` 加载,
|
|
159
|
+
// 无需经 index.ts / search.ts 聚合。registerGlobTool 本身就是 (pi) => void,
|
|
160
|
+
// 可直接作为扩展 factory。
|
|
161
|
+
export default registerGlobTool;
|
package/src/claude-code/grep.ts
CHANGED
|
@@ -342,3 +342,8 @@ export function registerGrepTool(pi: ExtensionAPI): void {
|
|
|
342
342
|
},
|
|
343
343
|
});
|
|
344
344
|
}
|
|
345
|
+
|
|
346
|
+
// 独立扩展入口:spawn-agent 子代理声明 `Grep` 工具时按本文件 `-e` 加载,
|
|
347
|
+
// 无需经 index.ts / search.ts 聚合。registerGrepTool 本身就是 (pi) => void,
|
|
348
|
+
// 可直接作为扩展 factory。
|
|
349
|
+
export default registerGrepTool;
|
package/src/claude-code/index.ts
CHANGED
|
@@ -1,53 +1,19 @@
|
|
|
1
|
-
import type { ExtensionAPI
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import { registerFileTools } from "./files.js";
|
|
3
|
+
import claudeCodeFileTools from "./files.js";
|
|
5
4
|
import { registerSearchTools } from "./search.js";
|
|
6
5
|
import { registerSessionTools } from "./session-tools.js";
|
|
7
6
|
import { registerShellTools } from "./shell.js";
|
|
8
7
|
|
|
9
|
-
/** 会更新 reads state 并随 details 持久化快照的工具名。 */
|
|
10
|
-
const FILE_TOOL_NAMES = new Set(["Read", "Edit", "Write"]);
|
|
11
|
-
|
|
12
8
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
9
|
+
* Claude Code 风格工具集入口:聚合 files / search / shell / session 四组工具。
|
|
10
|
+
*
|
|
11
|
+
* reads state 的创建与 session 恢复归 files.ts 所有(见其 default export),
|
|
12
|
+
* 本文件不再持有 state;spawn-agent 子代理按工具名直接 `-e` 加载各模块文件
|
|
13
|
+
* (files.ts / grep.ts / glob.ts 均为独立扩展入口)。
|
|
15
14
|
*/
|
|
16
|
-
function restoreReads(
|
|
17
|
-
state: ClaudeCodeState,
|
|
18
|
-
sessionManager: ExtensionContext["sessionManager"],
|
|
19
|
-
): void {
|
|
20
|
-
state.reads.clear();
|
|
21
|
-
for (const entry of sessionManager.getBranch()) {
|
|
22
|
-
if (entry.type !== "message" || entry.message.role !== "toolResult") continue;
|
|
23
|
-
if (!FILE_TOOL_NAMES.has(entry.message.toolName)) continue;
|
|
24
|
-
const details = entry.message.details as { reads?: unknown } | undefined;
|
|
25
|
-
if (!details?.reads) continue;
|
|
26
|
-
for (const [filePath, snapshot] of deserializeReads(details.reads)) {
|
|
27
|
-
state.reads.set(filePath, snapshot);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
15
|
export default function claudeCodeTools(pi: ExtensionAPI): void {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// 扩展实例在进程启动 / /reload / /new / /resume / /fork 时重建,内存里的
|
|
36
|
-
// 已读记账随之丢失。这里从当前分支的历史工具结果里恢复:digest 是当时的值,
|
|
37
|
-
// 若文件在此期间被外部修改,Edit/Write 时的指纹对比仍会要求重新 Read,
|
|
38
|
-
// 防呆语义不因重建而弱化。
|
|
39
|
-
pi.on("session_start", (_event, ctx) => {
|
|
40
|
-
restoreReads(state, ctx.sessionManager);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// rewind / 树内跳转走 navigateTree → branch(),只发 session_tree 不发
|
|
44
|
-
// session_start,扩展实例也不重建。这里同样重放当前分支,丢弃被抛弃分支
|
|
45
|
-
// 的记账,避免 state 与当前分支脱节。
|
|
46
|
-
pi.on("session_tree", (_event, ctx) => {
|
|
47
|
-
restoreReads(state, ctx.sessionManager);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
registerFileTools(pi, state);
|
|
16
|
+
claudeCodeFileTools(pi);
|
|
51
17
|
registerSearchTools(pi);
|
|
52
18
|
registerShellTools(pi);
|
|
53
19
|
registerSessionTools(pi);
|