@phren/cli 0.1.34 → 0.1.36
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/capabilities/web-ui.js +1 -1
- package/dist/cli/hooks.js +7 -3
- package/dist/cli/session-background.js +5 -6
- package/dist/cli/session-tool-hook.js +2 -0
- package/dist/cli-registry.js +11 -0
- package/dist/data/access.js +26 -1
- package/dist/finding/impact.js +4 -0
- package/dist/generated/memory-ui-graph.browser.js +5688 -294
- package/dist/hooks.d.ts +9 -0
- package/dist/hooks.js +17 -1
- package/dist/index.js +36 -32
- package/dist/init/config.js +2 -2
- package/dist/init/init-configure.js +13 -0
- package/dist/link/doctor.js +14 -1
- package/dist/link/skills.js +1 -1
- package/dist/logger.js +19 -0
- package/dist/memory-ui-graph.runtime.js +5688 -294
- package/dist/phren-paths.d.ts +6 -0
- package/dist/phren-paths.js +17 -0
- package/dist/shared/index.d.ts +14 -0
- package/dist/shared/index.js +73 -0
- package/dist/ui/data.d.ts +5 -0
- package/dist/ui/data.js +46 -7
- package/dist/ui/graph-chrome.d.ts +1 -0
- package/dist/ui/graph-chrome.js +163 -0
- package/dist/ui/graph.js +1 -1
- package/dist/ui/page.js +3 -0
- package/dist/ui/scripts.js +126 -19
- package/dist/ui/server.js +34 -2
- package/package.json +3 -4
|
@@ -29,7 +29,7 @@ export const webUiManifest = {
|
|
|
29
29
|
"search.history": { implemented: false, reason: "No search history in web UI" },
|
|
30
30
|
// Graph
|
|
31
31
|
"graph.read": { implemented: true, handler: "memory-ui-server.ts:/api/graph" },
|
|
32
|
-
"graph.visualize": { implemented: true, handler: "memory-ui-graph-app.ts:graph tab (
|
|
32
|
+
"graph.visualize": { implemented: true, handler: "memory-ui-graph-app.ts:graph tab (GraphRAG-style store>project>finding cages, Three.js / 3d-force-graph, CSS2D labels)" },
|
|
33
33
|
"graph.link_findings": { implemented: false, reason: "No link findings action in web UI" },
|
|
34
34
|
// Config
|
|
35
35
|
"config.get": { implemented: true, handler: "memory-ui-server.ts:/api/settings (read)" },
|
package/dist/cli/hooks.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// cli-hooks-globs.ts — project glob matching
|
|
7
7
|
import { debugLog, sessionMarker, sessionsDir, getPhrenPath, } from "../shared.js";
|
|
8
8
|
import { mergeConfig, } from "../shared/governance.js";
|
|
9
|
-
import {
|
|
9
|
+
import { loadIndexForHook, detectProject, } from "../shared/index.js";
|
|
10
10
|
import { isProjectHookEnabled } from "../project-config.js";
|
|
11
11
|
import { checkConsolidationNeeded, } from "../shared/content.js";
|
|
12
12
|
import { buildRobustFtsQuery, extractKeywordEntries, isFeatureEnabled, clampInt, errorMessage, } from "../utils.js";
|
|
@@ -118,9 +118,10 @@ export async function handleHookPrompt() {
|
|
|
118
118
|
.map(([topic]) => topic);
|
|
119
119
|
}
|
|
120
120
|
const tIndex0 = Date.now();
|
|
121
|
-
|
|
121
|
+
// Never block the prompt on a rebuild: serve the current/stale snapshot and
|
|
122
|
+
// refresh in a detached process (see loadIndexForHook).
|
|
123
|
+
const db = await loadIndexForHook(getPhrenPath(), profile);
|
|
122
124
|
stage.indexMs = Date.now() - tIndex0;
|
|
123
|
-
const gitCtx = getGitContext(cwd);
|
|
124
125
|
const intent = detectTaskIntent(prompt);
|
|
125
126
|
const detectedProject = cwd ? detectProject(getPhrenPath(), cwd, profile) : null;
|
|
126
127
|
if (detectedProject)
|
|
@@ -129,6 +130,9 @@ export async function handleHookPrompt() {
|
|
|
129
130
|
appendAuditLog(getPhrenPath(), "hook_prompt", `status=project_disabled project=${detectedProject}`);
|
|
130
131
|
process.exit(0);
|
|
131
132
|
}
|
|
133
|
+
// Resolve git context AFTER the enabled check — it spawns 3 git processes and is
|
|
134
|
+
// wasted work when the project has hooks disabled.
|
|
135
|
+
const gitCtx = getGitContext(cwd);
|
|
132
136
|
const resolvedConfig = mergeConfig(getPhrenPath(), detectedProject ?? undefined);
|
|
133
137
|
const safeQuery = buildRobustFtsQuery(keywords, detectedProject, getPhrenPath());
|
|
134
138
|
if (!safeQuery)
|
|
@@ -107,9 +107,10 @@ export function scheduleBackgroundMaintenance(phrenPathLocal, project) {
|
|
|
107
107
|
}
|
|
108
108
|
if (project)
|
|
109
109
|
spawnArgs.push(project);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
// Keep this log under .runtime/ (gitignored), matching background-sync.log.
|
|
111
|
+
// Writing it under .config/ makes it a tracked file that diverges per machine
|
|
112
|
+
// and breaks the Stop-hook pull-rebase.
|
|
113
|
+
const logPath = runtimeFile(phrenPathLocal, "background-maintenance.log");
|
|
113
114
|
const logFd = fs.openSync(logPath, "a");
|
|
114
115
|
fs.writeSync(logFd, `[${new Date().toISOString()}] spawn ${process.execPath} ${spawnArgs.join(" ")}\n`);
|
|
115
116
|
const child = spawnDetachedChild(spawnArgs, { phrenPath: phrenPathLocal, logFd });
|
|
@@ -158,9 +159,7 @@ export function scheduleBackgroundMaintenance(phrenPathLocal, project) {
|
|
|
158
159
|
catch (err) {
|
|
159
160
|
const errMsg = errorMessage(err);
|
|
160
161
|
try {
|
|
161
|
-
|
|
162
|
-
fs.mkdirSync(logDir, { recursive: true });
|
|
163
|
-
fs.appendFileSync(path.join(logDir, "background-maintenance.log"), `[${new Date().toISOString()}] spawn failed: ${errMsg}\n`);
|
|
162
|
+
fs.appendFileSync(runtimeFile(phrenPathLocal, "background-maintenance.log"), `[${new Date().toISOString()}] spawn failed: ${errMsg}\n`);
|
|
164
163
|
}
|
|
165
164
|
catch (err) {
|
|
166
165
|
logger.debug("hooks-session", `backgroundMaintenance logSpawnFailure: ${errorMessage(err)}`);
|
|
@@ -6,6 +6,7 @@ import * as fs from "fs";
|
|
|
6
6
|
import * as path from "path";
|
|
7
7
|
import { buildHookContext, debugLog, appendAuditLog, runtimeFile, sessionMarker, getPhrenPath, getWorkflowPolicy, appendReviewQueue, getProactivityLevelForFindings, FINDING_SENSITIVITY_CONFIG, isProjectHookEnabled, errorMessage, detectProject, } from "./hooks-context.js";
|
|
8
8
|
import { logger } from "../logger.js";
|
|
9
|
+
import { rotateJsonlIfLarge } from "../phren-paths.js";
|
|
9
10
|
import { buildIndex, queryRows, } from "../shared/index.js";
|
|
10
11
|
import { filterTaskByPriority } from "../shared/retrieval.js";
|
|
11
12
|
// ── PostToolUse hook ─────────────────────────────────────────────────────────
|
|
@@ -122,6 +123,7 @@ export async function handleHookTool() {
|
|
|
122
123
|
try {
|
|
123
124
|
const logFile = runtimeFile(ctx.phrenPath, "tool-log.jsonl");
|
|
124
125
|
fs.mkdirSync(path.dirname(logFile), { recursive: true });
|
|
126
|
+
rotateJsonlIfLarge(logFile);
|
|
125
127
|
fs.appendFileSync(logFile, JSON.stringify(entry) + "\n");
|
|
126
128
|
}
|
|
127
129
|
catch (err) {
|
package/dist/cli-registry.js
CHANGED
|
@@ -573,6 +573,17 @@ export const REGISTRY = [
|
|
|
573
573
|
await handleBackgroundMaintenance(args[0]);
|
|
574
574
|
},
|
|
575
575
|
},
|
|
576
|
+
{
|
|
577
|
+
name: "background-reindex",
|
|
578
|
+
topic: "core",
|
|
579
|
+
usage: "phren background-reindex",
|
|
580
|
+
summary: "Internal: rebuild the FTS index off the hook path",
|
|
581
|
+
hidden: true,
|
|
582
|
+
run: async (_args, ctx) => {
|
|
583
|
+
const { buildIndex } = await import("./shared/index.js");
|
|
584
|
+
await buildIndex(ctx.phrenPath(), ctx.profile());
|
|
585
|
+
},
|
|
586
|
+
},
|
|
576
587
|
{
|
|
577
588
|
name: "debug-injection",
|
|
578
589
|
topic: "core",
|
package/dist/data/access.js
CHANGED
|
@@ -58,6 +58,20 @@ function collectFindingBulletLines(lines) {
|
|
|
58
58
|
}
|
|
59
59
|
return bulletLines;
|
|
60
60
|
}
|
|
61
|
+
/** Bullet content with metadata comments removed — what the user actually sees. */
|
|
62
|
+
function bulletContentKey(line) {
|
|
63
|
+
return line.replace(/<!--.*?-->/g, " ").replace(/\s+/g, " ").trim();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Multiple matches are only truly ambiguous when their CONTENT differs. When a
|
|
67
|
+
* store carries literal duplicate bullets (same text, same tag), acting on the
|
|
68
|
+
* first occurrence is what the caller means — refusing made duplicate findings
|
|
69
|
+
* uneditable/undeletable from every host UI.
|
|
70
|
+
*/
|
|
71
|
+
function resolveDuplicateMatches(matches) {
|
|
72
|
+
const first = bulletContentKey(matches[0].line);
|
|
73
|
+
return matches.every(({ line }) => bulletContentKey(line) === first) ? matches[0] : null;
|
|
74
|
+
}
|
|
61
75
|
function findMatchingFindingBullet(bulletLines, needle, match) {
|
|
62
76
|
const fidNeedle = needle.replace(/^fid:/, "");
|
|
63
77
|
const fidMatch = /^[a-z0-9]{8}$/.test(fidNeedle)
|
|
@@ -70,11 +84,17 @@ function findMatchingFindingBullet(bulletLines, needle, match) {
|
|
|
70
84
|
if (exactMatches.length === 1)
|
|
71
85
|
return { kind: "found", idx: exactMatches[0].i };
|
|
72
86
|
if (exactMatches.length > 1) {
|
|
87
|
+
const dup = resolveDuplicateMatches(exactMatches);
|
|
88
|
+
if (dup)
|
|
89
|
+
return { kind: "found", idx: dup.i };
|
|
73
90
|
return { kind: "ambiguous", error: `"${match}" is ambiguous (${exactMatches.length} exact matches). Use a more specific phrase.` };
|
|
74
91
|
}
|
|
75
92
|
if (partialMatches.length === 1)
|
|
76
93
|
return { kind: "found", idx: partialMatches[0].i };
|
|
77
94
|
if (partialMatches.length > 1) {
|
|
95
|
+
const dup = resolveDuplicateMatches(partialMatches);
|
|
96
|
+
if (dup)
|
|
97
|
+
return { kind: "found", idx: dup.i };
|
|
78
98
|
return { kind: "ambiguous", error: `"${match}" is ambiguous (${partialMatches.length} partial matches). Use a more specific phrase.` };
|
|
79
99
|
}
|
|
80
100
|
return { kind: "not_found" };
|
|
@@ -399,7 +419,12 @@ export function editFinding(phrenPath, project, oldText, newText) {
|
|
|
399
419
|
const existing = lines[idx];
|
|
400
420
|
const metaMatch = existing.match(/(<!--.*?-->)/g);
|
|
401
421
|
const metaSuffix = metaMatch ? " " + metaMatch.join(" ") : "";
|
|
402
|
-
|
|
422
|
+
// Preserve the bullet's [tag] prefix: host UIs display (and send back)
|
|
423
|
+
// tag-stripped text, and losing the tag silently demoted the finding to
|
|
424
|
+
// untagged. Keep the old tag unless the new text supplies its own.
|
|
425
|
+
const existingTag = existing.match(/^-\s*(\[[a-z][a-z0-9_-]*\])\s/)?.[1];
|
|
426
|
+
const tagPrefix = existingTag && !/^\[[a-z][a-z0-9_-]*\]/.test(newTextTrimmed) ? `${existingTag} ` : "";
|
|
427
|
+
lines[idx] = `- ${tagPrefix}${newTextTrimmed}${metaSuffix}`;
|
|
403
428
|
const normalized = lines.join("\n").replace(/\n{3,}/g, "\n\n").trimEnd() + "\n";
|
|
404
429
|
const tmp = findingsPath + ".tmp." + process.pid;
|
|
405
430
|
fs.writeFileSync(tmp, normalized);
|
package/dist/finding/impact.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as crypto from "crypto";
|
|
2
2
|
import * as fs from "fs";
|
|
3
3
|
import { impactLogFile } from "../shared.js";
|
|
4
|
+
import { rotateJsonlIfLarge } from "../phren-paths.js";
|
|
4
5
|
import { withFileLock } from "../shared/governance.js";
|
|
5
6
|
import { normalizeFindingText } from "../content/metadata.js";
|
|
6
7
|
let highImpactCache = null;
|
|
@@ -86,6 +87,9 @@ function appendImpact(phrenPath, entries) {
|
|
|
86
87
|
return;
|
|
87
88
|
const file = impactLogFile(phrenPath);
|
|
88
89
|
withFileLock(file, () => {
|
|
90
|
+
// getHighImpactFindings re-parses this whole file on the hook hot path, so cap
|
|
91
|
+
// it — otherwise it grows unbounded (seen at 2MB) and every prompt re-parses it.
|
|
92
|
+
rotateJsonlIfLarge(file);
|
|
89
93
|
const lines = entries.map((entry) => JSON.stringify(entry));
|
|
90
94
|
fs.appendFileSync(file, lines.join("\n") + "\n");
|
|
91
95
|
});
|