@trim21/personal-pi-extensions 0.0.384 → 0.0.386
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 +1 -1
- package/src/aft/tools.ts +2 -14
- package/src/bwrap/runtime.ts +4 -2
- package/src/claude-code/glob.ts +7 -3
- package/src/lib/path.ts +14 -1
package/package.json
CHANGED
package/src/aft/tools.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { readFileSync } from "node:fs";
|
|
9
9
|
import { stat } from "node:fs/promises";
|
|
10
10
|
import { homedir } from "node:os";
|
|
11
|
-
import { basename, isAbsolute, join,
|
|
11
|
+
import { basename, isAbsolute, join, resolve } from "node:path";
|
|
12
12
|
import { fileURLToPath } from "node:url";
|
|
13
13
|
|
|
14
14
|
import {
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
24
24
|
import { Type } from "typebox";
|
|
25
25
|
|
|
26
|
+
import { formatDisplayPath } from "../lib/path.js";
|
|
26
27
|
import { type ToolPendant } from "../lib/pendant.js";
|
|
27
28
|
import { callAftTool, SEMANTIC_INDEX_WAIT_TIMEOUT_MS } from "./bridge.js";
|
|
28
29
|
|
|
@@ -50,19 +51,6 @@ export function resolvePathArg(cwd: string, input: string): string {
|
|
|
50
51
|
return isAbsolute(input) ? input : resolve(cwd, input);
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
/** 人类可读的显示路径:cwd 内用 `./…`,home 内用 `~/…`,否则原样绝对路径。 */
|
|
54
|
-
export function formatDisplayPath(cwd: string, filePath: string): string {
|
|
55
|
-
const relToCwd = relative(cwd, filePath);
|
|
56
|
-
if (relToCwd !== "" && !relToCwd.startsWith("..") && !isAbsolute(relToCwd)) {
|
|
57
|
-
return `./${relToCwd}`;
|
|
58
|
-
}
|
|
59
|
-
const relToHome = relative(homedir(), filePath);
|
|
60
|
-
if (relToHome !== "" && !relToHome.startsWith("..") && !isAbsolute(relToHome)) {
|
|
61
|
-
return `~/${relToHome}`;
|
|
62
|
-
}
|
|
63
|
-
return filePath;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
54
|
/** subtitle 中路径的最大显示长度,超过时退化为仅文件名。 */
|
|
67
55
|
export const MAX_SUBTITLE_PATH_LENGTH = 20;
|
|
68
56
|
|
package/src/bwrap/runtime.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
import { type TObject, Type } from "typebox";
|
|
17
17
|
|
|
18
18
|
import { type CommandSpec, parseCommand } from "../lib/cli.js";
|
|
19
|
+
import { formatDisplayPath } from "../lib/path.js";
|
|
19
20
|
import {
|
|
20
21
|
type CheckboxAction,
|
|
21
22
|
type SelectAction,
|
|
@@ -533,9 +534,10 @@ export class BwrapRuntime {
|
|
|
533
534
|
);
|
|
534
535
|
}
|
|
535
536
|
lines.push(fenceCodeBlock(command));
|
|
536
|
-
// 执行目录与工作区不同时,提示实际执行目录(execCwd
|
|
537
|
+
// 执行目录与工作区不同时,提示实际执行目录(execCwd 是解析后的绝对路径,
|
|
538
|
+
// 显示用 pretty path 风格:home 内 `~/…`,否则绝对路径)
|
|
537
539
|
if (execCwd !== ctx.cwd) {
|
|
538
|
-
lines.push(`Workdir: ${escapeHtml(execCwd)}`);
|
|
540
|
+
lines.push(`Workdir: ${escapeHtml(formatDisplayPath(ctx.cwd, execCwd))}`);
|
|
539
541
|
}
|
|
540
542
|
const description = lines.join("\n");
|
|
541
543
|
|
package/src/claude-code/glob.ts
CHANGED
|
@@ -88,9 +88,13 @@ export async function globFiles(
|
|
|
88
88
|
stdout = result.stdout;
|
|
89
89
|
} catch (error) {
|
|
90
90
|
if (signal?.aborted) throwIfAborted(signal);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
91
|
+
// rg exit code 1 = 搜索完成但无匹配,对齐 Claude Code 的 ripGrep(正常空结果)
|
|
92
|
+
const code = (error as { code?: unknown }).code;
|
|
93
|
+
if (code === 1) return { files: [], truncated: false };
|
|
94
|
+
const detail =
|
|
95
|
+
(error as { stderr?: string }).stderr?.trim() ||
|
|
96
|
+
(error instanceof Error ? error.message : String(error));
|
|
97
|
+
throw new Error(`ripgrep failed: ${detail}`, { cause: error });
|
|
94
98
|
}
|
|
95
99
|
// rg 输出相对 searchDir 的路径,转成绝对路径
|
|
96
100
|
const lines = stdout ? stdout.replace(/\n$/, "").split("\n") : [];
|
package/src/lib/path.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { stat } from "node:fs/promises";
|
|
6
6
|
import { homedir } from "node:os";
|
|
7
|
-
import { isAbsolute, join, resolve } from "node:path";
|
|
7
|
+
import { isAbsolute, join, relative, resolve } from "node:path";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Expand a leading `~` to the user's home directory.
|
|
@@ -46,3 +46,16 @@ export async function resolveWorkdir(workdir: string, baseDir: string): Promise<
|
|
|
46
46
|
}
|
|
47
47
|
return target;
|
|
48
48
|
}
|
|
49
|
+
|
|
50
|
+
/** 人类可读的显示路径:cwd 内用 `./…`,home 内用 `~/…`,否则原样绝对路径。 */
|
|
51
|
+
export function formatDisplayPath(cwd: string, filePath: string): string {
|
|
52
|
+
const relToCwd = relative(cwd, filePath);
|
|
53
|
+
if (relToCwd !== "" && !relToCwd.startsWith("..") && !isAbsolute(relToCwd)) {
|
|
54
|
+
return `./${relToCwd}`;
|
|
55
|
+
}
|
|
56
|
+
const relToHome = relative(homedir(), filePath);
|
|
57
|
+
if (relToHome !== "" && !relToHome.startsWith("..") && !isAbsolute(relToHome)) {
|
|
58
|
+
return `~/${relToHome}`;
|
|
59
|
+
}
|
|
60
|
+
return filePath;
|
|
61
|
+
}
|