@phren/cli 0.1.51 → 0.1.53
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/cli/hooks.js +31 -1
- 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/cli/hooks.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// cli-hooks-output.ts — hook output formatting
|
|
6
6
|
// cli-hooks-globs.ts — project glob matching
|
|
7
7
|
import { debugLog, sessionMarker, sessionsDir, getPhrenPath, } from "../shared.js";
|
|
8
|
-
import { mergeConfig, } from "../shared/governance.js";
|
|
8
|
+
import { mergeConfig, recordLookupEvents } from "../shared/governance.js";
|
|
9
9
|
import { loadIndexForHook, detectProject, } from "../shared/index.js";
|
|
10
10
|
import { isProjectHookEnabled } from "../project-config.js";
|
|
11
11
|
import { checkConsolidationNeeded, } from "../shared/content.js";
|
|
@@ -37,6 +37,7 @@ import { getGitContext, trackSessionMetrics, } from "./hooks-session.js";
|
|
|
37
37
|
import { approximateTokens, SNIPPET_OVERHEAD_TOKENS } from "../shared/retrieval.js";
|
|
38
38
|
import { resolveRuntimeProfile } from "../runtime-profile.js";
|
|
39
39
|
import { handleTaskPromptLifecycle } from "../task/lifecycle.js";
|
|
40
|
+
import { bestFindingNodeId } from "../finding-graph-id.js";
|
|
40
41
|
// Auto-learn from prompts was removed — it learned conversational noise ("bro", "idk", typos)
|
|
41
42
|
// as synonyms for high-frequency terms. Manual `phren config synonyms add` still works.
|
|
42
43
|
// Future: finding-based co-occurrence mining (phren maintain command, not live hook).
|
|
@@ -227,6 +228,35 @@ export async function handleHookPrompt() {
|
|
|
227
228
|
budgetUsedTokens = runningTokens;
|
|
228
229
|
debugLog(`injection-budget: trimmed ${selected.length} -> ${kept.length} snippets to fit ${maxInjectTokens} token budget`);
|
|
229
230
|
}
|
|
231
|
+
// Live activity: what a prompt pulled in is a recall as much as a search
|
|
232
|
+
// hit is, and it is by far the most common kind. Recording it here is what
|
|
233
|
+
// lets the terminal graph's watch mode, and anything else tailing the log,
|
|
234
|
+
// light up while an agent works. Best-effort: logging must never break
|
|
235
|
+
// the hook.
|
|
236
|
+
try {
|
|
237
|
+
const at = new Date().toISOString();
|
|
238
|
+
// The prompt, not the expanded keyword string: the feed shows this to a
|
|
239
|
+
// person, and "retry retry backoff backoff jitter" is not what they asked.
|
|
240
|
+
const asked = prompt.replace(/\s+/g, " ").trim().slice(0, 160);
|
|
241
|
+
recordLookupEvents(getPhrenPath(), budgetSelected.map((s) => {
|
|
242
|
+
const nodeId = s.doc.type === "findings" ? bestFindingNodeId(s.doc.project, s.doc.content, keywords) : null;
|
|
243
|
+
return {
|
|
244
|
+
at,
|
|
245
|
+
query: asked,
|
|
246
|
+
project: s.doc.project,
|
|
247
|
+
filename: s.doc.filename,
|
|
248
|
+
type: s.doc.type,
|
|
249
|
+
path: s.doc.path,
|
|
250
|
+
snippet: s.snippet,
|
|
251
|
+
source: "hook",
|
|
252
|
+
...(nodeId ? { nodeId } : {}),
|
|
253
|
+
...(sessionId ? { session: sessionId } : {}),
|
|
254
|
+
};
|
|
255
|
+
}));
|
|
256
|
+
}
|
|
257
|
+
catch (err) {
|
|
258
|
+
debugLog(`hook-prompt lookup-events: ${errorMessage(err)}`);
|
|
259
|
+
}
|
|
230
260
|
const parts = buildHookOutput(budgetSelected, budgetUsedTokens, intent, gitCtx, detectedProject, stage, safeTokenBudget, getPhrenPath(), sessionId);
|
|
231
261
|
const taskLevel = resolvedConfig.proactivity.tasks
|
|
232
262
|
?? resolvedConfig.proactivity.base
|
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"];
|