@phren/cli 0.1.51 → 0.1.52
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/dist/hooks.d.ts +1 -0
- package/dist/hooks.js +1 -1
- package/dist/init/config.d.ts +26 -0
- package/dist/init/config.js +30 -14
- package/package.json +1 -1
package/dist/hooks.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export declare function extractHookScriptPath(command: string): string | null;
|
|
|
34
34
|
* upgrade that breaks all four lifecycle hooks reports one path, not four.
|
|
35
35
|
*/
|
|
36
36
|
export declare function findStaleHookEntrypoints(commands: readonly string[]): string[];
|
|
37
|
+
export declare function phrenPackageSpec(): string;
|
|
37
38
|
/** Shell-escape a value by wrapping in single quotes with proper escaping of embedded single quotes. */
|
|
38
39
|
export declare function shellEscape(s: string): string;
|
|
39
40
|
export interface LifecycleCommands {
|
package/dist/hooks.js
CHANGED
|
@@ -172,7 +172,7 @@ export function findStaleHookEntrypoints(commands) {
|
|
|
172
172
|
}
|
|
173
173
|
return [...stale];
|
|
174
174
|
}
|
|
175
|
-
function phrenPackageSpec() {
|
|
175
|
+
export function phrenPackageSpec() {
|
|
176
176
|
return PACKAGE_SPEC;
|
|
177
177
|
}
|
|
178
178
|
/** Shell-escape a value by wrapping in single quotes with proper escaping of embedded single quotes. */
|
package/dist/init/config.d.ts
CHANGED
|
@@ -17,6 +17,32 @@ type JsonObject = Record<string, unknown> & {
|
|
|
17
17
|
servers?: Record<string, unknown>;
|
|
18
18
|
};
|
|
19
19
|
export declare function patchJsonFile(filePath: string, patch: (data: JsonObject) => void): void;
|
|
20
|
+
/**
|
|
21
|
+
* True when the running copy of phren lives in npm's npx cache. That cache is
|
|
22
|
+
* npm's to evict, so a path into it is not something to write into anyone's
|
|
23
|
+
* settings: it works until the day it silently does not.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isEphemeralInstall(entryScript: string): boolean;
|
|
26
|
+
export interface McpServerConfig {
|
|
27
|
+
command: string;
|
|
28
|
+
args: string[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* How Claude (and the other MCP hosts) should start the phren server.
|
|
32
|
+
*
|
|
33
|
+
* A real install points straight at its own `dist/index.js`. An `npx` install
|
|
34
|
+
* does not: the file it would name sits in the npx cache, and the day npm
|
|
35
|
+
* evicts it the MCP server stops starting with no error anyone sees — which
|
|
36
|
+
* is exactly how `npx @phren/cli init` ends up "not working" a week later.
|
|
37
|
+
* That case goes through the CLI wrapper init writes to `~/.local/bin`, which
|
|
38
|
+
* knows how to find or fetch phren. Windows has no shell wrapper to lean on,
|
|
39
|
+
* so it falls back to `npx.cmd` with the real package name.
|
|
40
|
+
*/
|
|
41
|
+
export declare function buildMcpServerConfig(phrenPath: string, opts?: {
|
|
42
|
+
entryScript?: string;
|
|
43
|
+
platform?: NodeJS.Platform;
|
|
44
|
+
wrapperPath?: string;
|
|
45
|
+
}): McpServerConfig;
|
|
20
46
|
export declare function removeTomlMcpServer(filePath: string): boolean;
|
|
21
47
|
export declare function removeMcpServerAtPath(filePath: string): boolean;
|
|
22
48
|
export declare function isPhrenCommand(command: string): boolean;
|
package/dist/init/config.js
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import * as fs from "fs";
|
|
6
6
|
import * as path from "path";
|
|
7
|
-
import { buildLifecycleCommands, commandExists } from "../hooks.js";
|
|
7
|
+
import { buildLifecycleCommands, commandExists, phrenPackageSpec } from "../hooks.js";
|
|
8
8
|
import { isRecord, hookConfigPath, homePath, readRootManifest, atomicWriteText, } from "../shared.js";
|
|
9
9
|
import { isFeatureEnabled, errorMessage } from "../utils.js";
|
|
10
10
|
import { probeVsCodeConfig, resolveCodexMcpConfig, resolveCopilotMcpConfig, resolveCursorMcpConfig, } from "../provider-adapters.js";
|
|
11
11
|
import { getMcpEnabledPreference, getHooksEnabledPreference, readInstallPreferences, updateInstallPreferences } from "./preferences.js";
|
|
12
|
-
import { resolveEntryScript, log
|
|
12
|
+
import { resolveEntryScript, log } from "./shared.js";
|
|
13
13
|
import { readCustomHooks } from "../hooks.js";
|
|
14
14
|
function getObjectProp(value, key) {
|
|
15
15
|
const candidate = value[key];
|
|
@@ -34,21 +34,37 @@ export function patchJsonFile(filePath, patch) {
|
|
|
34
34
|
patch(data);
|
|
35
35
|
atomicWriteText(filePath, JSON.stringify(data, null, 2) + "\n");
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
/**
|
|
38
|
+
* True when the running copy of phren lives in npm's npx cache. That cache is
|
|
39
|
+
* npm's to evict, so a path into it is not something to write into anyone's
|
|
40
|
+
* settings: it works until the day it silently does not.
|
|
41
|
+
*/
|
|
42
|
+
export function isEphemeralInstall(entryScript) {
|
|
43
|
+
return /[\\/]_npx[\\/]/.test(entryScript);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* How Claude (and the other MCP hosts) should start the phren server.
|
|
47
|
+
*
|
|
48
|
+
* A real install points straight at its own `dist/index.js`. An `npx` install
|
|
49
|
+
* does not: the file it would name sits in the npx cache, and the day npm
|
|
50
|
+
* evicts it the MCP server stops starting with no error anyone sees — which
|
|
51
|
+
* is exactly how `npx @phren/cli init` ends up "not working" a week later.
|
|
52
|
+
* That case goes through the CLI wrapper init writes to `~/.local/bin`, which
|
|
53
|
+
* knows how to find or fetch phren. Windows has no shell wrapper to lean on,
|
|
54
|
+
* so it falls back to `npx.cmd` with the real package name.
|
|
55
|
+
*/
|
|
56
|
+
export function buildMcpServerConfig(phrenPath, opts = {}) {
|
|
57
|
+
const entryScript = opts.entryScript ?? resolveEntryScript();
|
|
58
|
+
const platform = opts.platform ?? process.platform;
|
|
59
|
+
if (entryScript && !isEphemeralInstall(entryScript) && fs.existsSync(entryScript)) {
|
|
60
|
+
return { command: "node", args: [entryScript, phrenPath] };
|
|
61
|
+
}
|
|
62
|
+
if (platform !== "win32") {
|
|
63
|
+
return { command: opts.wrapperPath ?? homePath(".local", "bin", "phren"), args: [phrenPath] };
|
|
44
64
|
}
|
|
45
65
|
// MCP clients spawn servers with { shell: false } on Windows, so the bare
|
|
46
66
|
// `npx` name can't resolve the `npx.cmd` shim and the server fails to start.
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
command: process.platform === "win32" ? "npx.cmd" : "npx",
|
|
50
|
-
args: ["-y", `phren@${VERSION}`, phrenPath],
|
|
51
|
-
};
|
|
67
|
+
return { command: "npx.cmd", args: ["-y", phrenPackageSpec(), phrenPath] };
|
|
52
68
|
}
|
|
53
69
|
function upsertMcpServer(data, mcpEnabled, preferredRoot, phrenPath) {
|
|
54
70
|
const knownRoots = ["mcpServers", "servers"];
|