pi-cc-extensions 0.8.72 → 0.9.0
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.en.md
CHANGED
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CompactThinkingConfig } from "../feature/compact-thinking.ts";
|
|
2
|
-
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
|
|
@@ -68,7 +68,8 @@ export type Config = {
|
|
|
68
68
|
};
|
|
69
69
|
|
|
70
70
|
const AGENT_DIR = process.env.PI_CODING_AGENT_DIR ?? join(homedir(), ".pi", "agent");
|
|
71
|
-
const CONFIG_PATH = join(AGENT_DIR, "
|
|
71
|
+
export const CONFIG_PATH = join(AGENT_DIR, "pi-cc-extensions.json");
|
|
72
|
+
const LEGACY_CONFIG_PATH = join(AGENT_DIR, "claude-code-style.json");
|
|
72
73
|
|
|
73
74
|
export const DIFF_VIEW_MODES: DiffViewMode[] = ["auto", "split", "unified"];
|
|
74
75
|
export const DIFF_INDICATOR_MODES: DiffIndicatorMode[] = ["bars", "classic", "none"];
|
|
@@ -288,10 +289,21 @@ export const config: Config = loadConfig();
|
|
|
288
289
|
|
|
289
290
|
function loadConfig(): Config {
|
|
290
291
|
try {
|
|
291
|
-
const
|
|
292
|
-
|
|
292
|
+
const fromLegacy = !existsSync(CONFIG_PATH) && existsSync(LEGACY_CONFIG_PATH);
|
|
293
|
+
const rawPath = existsSync(CONFIG_PATH) ? CONFIG_PATH : fromLegacy ? LEGACY_CONFIG_PATH : null;
|
|
294
|
+
const source = rawPath
|
|
295
|
+
? (JSON.parse(readFileSync(rawPath, "utf8")) as Record<string, unknown>)
|
|
293
296
|
: {};
|
|
294
|
-
|
|
297
|
+
const next = normalizeConfig(source);
|
|
298
|
+
if (fromLegacy) {
|
|
299
|
+
try {
|
|
300
|
+
writeFileSync(CONFIG_PATH, JSON.stringify(next, null, 2));
|
|
301
|
+
rmSync(LEGACY_CONFIG_PATH, { force: true });
|
|
302
|
+
} catch {
|
|
303
|
+
// 新路径写失败时仍使用已读到的旧配置,旧文件保留。
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return next;
|
|
295
307
|
} catch {
|
|
296
308
|
// Ignore bad config and fall back to defaults.
|
|
297
309
|
}
|
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
15
15
|
import { truncateToWidth } from "@earendil-works/pi-tui";
|
|
16
16
|
import { execFile } from "node:child_process";
|
|
17
|
+
import { existsSync } from "node:fs";
|
|
18
|
+
import { homedir } from "node:os";
|
|
19
|
+
import { join } from "node:path";
|
|
20
|
+
import { pathToFileURL } from "node:url";
|
|
17
21
|
import { config } from "../../config/config.ts";
|
|
18
22
|
import { stripAnsi } from "../../utils/ansi-text.ts";
|
|
19
23
|
|
|
@@ -95,14 +99,26 @@ export function pickFooterUsageText(
|
|
|
95
99
|
|
|
96
100
|
let piUsageMod: any | null | undefined;
|
|
97
101
|
|
|
102
|
+
function piUsageImportSpecs(): string[] {
|
|
103
|
+
const agentDir = process.env.PI_CODING_AGENT_DIR ?? join(homedir(), ".pi", "agent");
|
|
104
|
+
const dist = join(agentDir, "npm", "node_modules", "@narumitw", "pi-usage", "dist", "index.ts");
|
|
105
|
+
const specs: string[] = [];
|
|
106
|
+
if (existsSync(dist)) specs.push(pathToFileURL(dist).href);
|
|
107
|
+
specs.push("@narumitw/pi-usage");
|
|
108
|
+
return specs;
|
|
109
|
+
}
|
|
110
|
+
|
|
98
111
|
async function getPiUsage(): Promise<any | null> {
|
|
99
112
|
if (piUsageMod !== undefined) return piUsageMod;
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
113
|
+
for (const spec of piUsageImportSpecs()) {
|
|
114
|
+
try {
|
|
115
|
+
piUsageMod = await import(spec);
|
|
116
|
+
return piUsageMod;
|
|
117
|
+
} catch {
|
|
118
|
+
// 下一候选:本机 Pi npm 目录,或包名(与本包同 node_modules 时)
|
|
119
|
+
}
|
|
105
120
|
}
|
|
121
|
+
piUsageMod = null;
|
|
106
122
|
return piUsageMod;
|
|
107
123
|
}
|
|
108
124
|
|
|
@@ -11,11 +11,11 @@ export function toolViewportWidth(width: number): number {
|
|
|
11
11
|
return Math.max(1, Math.floor(width * TOOL_VIEWPORT_WIDTH_RATIO));
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
/**
|
|
14
|
+
/** 与默认工具结果相同的一级缩进包装。子组件只扣始终加上的 1 列;↳ 行多出的 2 列由 truncateToWidth 吃掉。 */
|
|
15
15
|
export function insetComponent(component: any): any {
|
|
16
16
|
return {
|
|
17
17
|
render: (width: number) =>
|
|
18
|
-
component.render(Math.max(1, width -
|
|
18
|
+
component.render(Math.max(1, width - 1)).map((line: string) => {
|
|
19
19
|
const nestedMarker = line.replace(/^((?:\x1b\[[0-?]*[ -/]*[@-~])*)↳/, "$1 ↳");
|
|
20
20
|
return truncateToWidth(` ${nestedMarker}`, Math.max(0, width), "");
|
|
21
21
|
}),
|