@phi-code-admin/phi-code 0.76.0 → 0.76.1
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/phi/browser.ts +56 -5
- package/package.json +2 -2
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
* user keeps the legacy `web_search` / `fetch_url` only).
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
+
import { createRequire } from "node:module";
|
|
26
|
+
import { existsSync } from "node:fs";
|
|
27
|
+
import { dirname, join } from "node:path";
|
|
28
|
+
import { pathToFileURL } from "node:url";
|
|
25
29
|
import { Type } from "@sinclair/typebox";
|
|
26
30
|
import type { ExtensionAPI } from "phi-code";
|
|
27
31
|
|
|
@@ -32,17 +36,64 @@ import type { ExtensionAPI } from "phi-code";
|
|
|
32
36
|
type BrowserApi = typeof import("@phi-code-admin/browser");
|
|
33
37
|
|
|
34
38
|
let cachedApi: BrowserApi | undefined;
|
|
35
|
-
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Resolve `@phi-code-admin/browser` from the host phi-code installation
|
|
42
|
+
* (the binary that loaded us, via `process.argv[1]`), not from this file's
|
|
43
|
+
* location. The extension is typically copied by phi-code's postinstall
|
|
44
|
+
* into `~/.phi/agent/extensions/browser.ts`, which has no `node_modules`
|
|
45
|
+
* of its own — a plain `import("@phi-code-admin/browser")` would resolve
|
|
46
|
+
* relative to that copy and fail. Walking the resolution from
|
|
47
|
+
* `process.argv[1]` (the `phi` CLI entry, which DOES sit next to its
|
|
48
|
+
* bundled `node_modules`) finds the package every time.
|
|
49
|
+
*/
|
|
50
|
+
function browserPackageFromPhi(): string | undefined {
|
|
51
|
+
const cliPath = process.argv[1];
|
|
52
|
+
if (!cliPath) return undefined;
|
|
53
|
+
try {
|
|
54
|
+
const req = createRequire(pathToFileURL(cliPath));
|
|
55
|
+
return req.resolve("@phi-code-admin/browser");
|
|
56
|
+
} catch {
|
|
57
|
+
// Fall through — we'll try walking up from cliPath manually.
|
|
58
|
+
}
|
|
59
|
+
let dir = dirname(cliPath);
|
|
60
|
+
for (let depth = 0; depth < 8; depth++) {
|
|
61
|
+
const candidate = join(dir, "node_modules", "@phi-code-admin", "browser", "dist", "index.js");
|
|
62
|
+
if (existsSync(candidate)) return candidate;
|
|
63
|
+
const parent = dirname(dir);
|
|
64
|
+
if (parent === dir) break;
|
|
65
|
+
dir = parent;
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
36
69
|
|
|
37
70
|
async function getBrowserApi(): Promise<BrowserApi> {
|
|
38
71
|
if (cachedApi) return cachedApi;
|
|
39
|
-
|
|
72
|
+
|
|
73
|
+
// 1. Try the standard dynamic import first. This works when the extension
|
|
74
|
+
// lives next to a `node_modules/@phi-code-admin/browser` (dev / monorepo
|
|
75
|
+
// layouts and any setup where the user has run a fresh `npm install` in
|
|
76
|
+
// the extension's directory).
|
|
40
77
|
try {
|
|
41
78
|
cachedApi = (await import("@phi-code-admin/browser")) as BrowserApi;
|
|
42
79
|
return cachedApi;
|
|
43
|
-
} catch (
|
|
44
|
-
|
|
45
|
-
|
|
80
|
+
} catch (firstErr) {
|
|
81
|
+
// 2. Fall back to resolving through the phi CLI binary, which always
|
|
82
|
+
// sits next to its bundled deps even when the extension was copied
|
|
83
|
+
// elsewhere by the postinstall script.
|
|
84
|
+
const resolved = browserPackageFromPhi();
|
|
85
|
+
if (resolved) {
|
|
86
|
+
try {
|
|
87
|
+
cachedApi = (await import(pathToFileURL(resolved).href)) as BrowserApi;
|
|
88
|
+
return cachedApi;
|
|
89
|
+
} catch (secondErr) {
|
|
90
|
+
// Re-throw the second error: it's the more informative one.
|
|
91
|
+
throw secondErr instanceof Error ? secondErr : new Error(String(secondErr));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// 3. No path worked. Throw the original error WITHOUT caching it, so
|
|
95
|
+
// the user can fix their install and the next tool call retries.
|
|
96
|
+
throw firstErr instanceof Error ? firstErr : new Error(String(firstErr));
|
|
46
97
|
}
|
|
47
98
|
}
|
|
48
99
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phi-code-admin/phi-code",
|
|
3
|
-
"version": "0.76.
|
|
3
|
+
"version": "0.76.1",
|
|
4
4
|
"description": "Coding agent CLI with persistent memory, sub-agents, intelligent routing, and orchestration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"piConfig": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@mariozechner/jiti": "^2.6.5",
|
|
50
|
-
"@phi-code-admin/browser": "^1.0.
|
|
50
|
+
"@phi-code-admin/browser": "^1.0.1",
|
|
51
51
|
"@silvia-odwyer/photon-node": "^0.3.4",
|
|
52
52
|
"chalk": "^5.5.0",
|
|
53
53
|
"cli-highlight": "^2.1.11",
|