@henryqw/pi-footer 5.1.2 → 5.1.3
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/extensions/open.ts +24 -3
- package/package.json +1 -1
package/extensions/open.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { statSync } from "node:fs";
|
|
1
2
|
import { pathToFileURL } from "node:url";
|
|
2
3
|
import { type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
4
|
import { type ConfigLoad, registerConfigReporting } from "@henryqw/pi-config-store";
|
|
@@ -10,11 +11,31 @@ export function loadOpenInConfig(agentDir?: string): ConfigLoad<OpenInConfig> {
|
|
|
10
11
|
return createOpenInConfigStore(agentDir).loadSync();
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
// The footer renders often; reload only when the config file identity changes.
|
|
15
|
+
let cachedCommand: { path: string; key: string | undefined; command: string | undefined } | undefined;
|
|
16
|
+
|
|
17
|
+
function configuredCommand(): string | undefined {
|
|
18
|
+
const store = createOpenInConfigStore();
|
|
19
|
+
let key: string | undefined;
|
|
20
|
+
try {
|
|
21
|
+
const { size, mtimeMs, ctimeMs } = statSync(store.path);
|
|
22
|
+
key = `${size}:${mtimeMs}:${ctimeMs}`;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
// Other stat failures bypass the cache.
|
|
25
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") key = "missing";
|
|
26
|
+
}
|
|
27
|
+
if (key === undefined || cachedCommand?.path !== store.path || cachedCommand.key !== key) {
|
|
28
|
+
const loaded = store.loadSync();
|
|
29
|
+
cachedCommand = { path: store.path, key, command: loaded.status === "disabled" ? undefined : loaded.value.command };
|
|
30
|
+
}
|
|
31
|
+
return cachedCommand.command;
|
|
32
|
+
}
|
|
33
|
+
|
|
13
34
|
/** Runs on every footer render, so it never notifies; the footer and open extensions report issues at session start. */
|
|
14
35
|
export function configuredOpenUri(path: string): string | undefined {
|
|
15
|
-
const
|
|
16
|
-
if (
|
|
17
|
-
const [executable, ...args] =
|
|
36
|
+
const command = configuredCommand();
|
|
37
|
+
if (command === undefined) return undefined;
|
|
38
|
+
const [executable, ...args] = command.split(/\s+/);
|
|
18
39
|
if (executable !== "code") return undefined;
|
|
19
40
|
const query = args.includes("-n") || args.includes("--new-window") ? "?windowId=_blank" : "";
|
|
20
41
|
if (path.startsWith("\\\\")) {
|