@phren/cli 0.1.44 → 0.1.45
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/actions.d.ts +1 -1
- package/dist/cli/actions.js +7 -2
- package/dist/cli/config-proactivity.d.ts +6 -6
- package/dist/cli/hooks.d.ts +1 -1
- package/dist/cli/hooks.js +14 -3
- package/dist/cli/session-stop.d.ts +1 -1
- package/dist/cli/session-tool-hook.d.ts +1 -1
- package/dist/cli-registry.js +1 -1
- package/dist/data/access.js +2 -1
- package/dist/generated/memory-ui-graph.browser.js +481 -318
- package/dist/governance/locks.js +6 -0
- package/dist/graph-core/index.d.ts +2 -0
- package/dist/graph-core/index.js +2 -0
- package/dist/graph-core/model.d.ts +84 -0
- package/dist/graph-core/model.js +355 -0
- package/dist/graph-core/types.d.ts +110 -0
- package/dist/graph-core/types.js +43 -0
- package/dist/index.js +4 -1
- package/dist/init/init-uninstall.d.ts +1 -0
- package/dist/init/init-uninstall.js +1 -1
- package/dist/init/setup.js +11 -4
- package/dist/link/context.js +2 -1
- package/dist/link/link.js +3 -2
- package/dist/link/skills.js +2 -1
- package/dist/memory-ui-graph.runtime.js +481 -318
- package/dist/phren-core.d.ts +16 -0
- package/dist/phren-core.js +21 -0
- package/dist/phren-paths.js +8 -4
- package/dist/profile-store.js +3 -2
- package/dist/project-config.js +2 -1
- package/dist/shared/index.js +1 -1
- package/dist/shared/retrieval.d.ts +28 -0
- package/dist/shared/retrieval.js +45 -0
- package/dist/shell/entry.d.ts +3 -3
- package/dist/shell/entry.js +19 -44
- package/dist/shell/graph/canvas.d.ts +64 -0
- package/dist/shell/graph/canvas.js +256 -0
- package/dist/shell/graph/controller.d.ts +164 -0
- package/dist/shell/graph/controller.js +645 -0
- package/dist/shell/graph/glyphs.d.ts +12 -0
- package/dist/shell/graph/glyphs.js +31 -0
- package/dist/shell/graph/graph-view.d.ts +12 -0
- package/dist/shell/graph/graph-view.js +408 -0
- package/dist/shell/graph/layout.d.ts +68 -0
- package/dist/shell/graph/layout.js +267 -0
- package/dist/shell/input.d.ts +3 -0
- package/dist/shell/input.js +24 -4
- package/dist/shell/intro.d.ts +37 -0
- package/dist/shell/intro.js +82 -0
- package/dist/shell/logo-fx.d.ts +35 -0
- package/dist/shell/logo-fx.js +128 -0
- package/dist/shell/render.d.ts +2 -2
- package/dist/shell/render.js +12 -28
- package/dist/shell/shell.d.ts +13 -1
- package/dist/shell/shell.js +45 -7
- package/dist/shell/startup.d.ts +37 -0
- package/dist/shell/startup.js +105 -0
- package/dist/shell/state-store.d.ts +1 -1
- package/dist/shell/state-store.js +1 -1
- package/dist/shell/types.js +1 -0
- package/dist/shell/view.d.ts +3 -0
- package/dist/shell/view.js +24 -3
- package/dist/store-registry.js +3 -3
- package/dist/test-global-setup.d.ts +1 -0
- package/dist/test-global-setup.js +22 -0
- package/dist/tool-registry.js +1 -0
- package/dist/ui/data.d.ts +15 -7
- package/dist/ui/data.js +102 -3
- package/dist/utils-fts.js +2 -1
- package/dist/utils-helpers.d.ts +1 -0
- package/dist/utils-helpers.js +6 -0
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/package.json +11 -7
package/dist/governance/locks.js
CHANGED
|
@@ -50,7 +50,13 @@ function acquireFileLock(lockPath) {
|
|
|
50
50
|
fs.unlinkSync(lockPath);
|
|
51
51
|
}
|
|
52
52
|
catch { /* already gone */ }
|
|
53
|
+
continue;
|
|
53
54
|
}
|
|
55
|
+
// Owner is alive and legitimately holding a long lock: back off
|
|
56
|
+
// like every other retry path, or this loop spins at 100% CPU
|
|
57
|
+
// and `maxWait` never fires.
|
|
58
|
+
sleep(pollInterval);
|
|
59
|
+
waited += pollInterval;
|
|
54
60
|
continue;
|
|
55
61
|
}
|
|
56
62
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure graph model logic shared by the browser 3D viewer and the terminal
|
|
3
|
+
* graph view. Every function here takes its context explicitly (no module
|
|
4
|
+
* singletons), so hosts can hold whatever state shape suits them.
|
|
5
|
+
*
|
|
6
|
+
* Must stay free of DOM, node builtins, and imports outside `src/graph-core/`.
|
|
7
|
+
*/
|
|
8
|
+
import type { NodeDetail, NodeHealth, NodeKind, RawLink, RawNode, RuntimeNode, ScoreEntry } from "./types.js";
|
|
9
|
+
export type ScoreMap = Record<string, ScoreEntry>;
|
|
10
|
+
/** Structural filters a host applies before layout. Search does not remove nodes. */
|
|
11
|
+
export interface GraphFilters {
|
|
12
|
+
filterTypes: Partial<Record<NodeKind, boolean>>;
|
|
13
|
+
filterTopics: Record<string, boolean>;
|
|
14
|
+
/** "all", a single health value, or "aging" (= decaying + stale). */
|
|
15
|
+
filterHealth: string;
|
|
16
|
+
filterProject: string;
|
|
17
|
+
filterStore: string;
|
|
18
|
+
searchQuery: string;
|
|
19
|
+
nodeLimit: number;
|
|
20
|
+
}
|
|
21
|
+
/** The normalized graph a host keeps between renders. */
|
|
22
|
+
export interface GraphModel {
|
|
23
|
+
rawNodes: RuntimeNode[];
|
|
24
|
+
rawLinks: RawLink[];
|
|
25
|
+
nodeById: Map<string, RuntimeNode>;
|
|
26
|
+
fullAdjacency: Map<string, Set<string>>;
|
|
27
|
+
visibleAdjacency: Map<string, Set<string>>;
|
|
28
|
+
scores: ScoreMap;
|
|
29
|
+
}
|
|
30
|
+
export type StoreColorFn = (storeName?: string) => string | null;
|
|
31
|
+
/** Hands out a distinct palette colour per non-primary store, first come first served. */
|
|
32
|
+
export declare class StoreColorAssigner {
|
|
33
|
+
private readonly assigned;
|
|
34
|
+
color(storeName?: string): string | null;
|
|
35
|
+
}
|
|
36
|
+
export declare function clamp(value: number, min: number, max: number): number;
|
|
37
|
+
export declare function hashString(value: string): number;
|
|
38
|
+
/** Deterministic pseudo-random in [0, 1) derived from a value + salt. */
|
|
39
|
+
export declare function seeded(value: string, salt: string): number;
|
|
40
|
+
export declare function deriveKind(node: RawNode): NodeKind;
|
|
41
|
+
export declare function topicColor(slug?: string): string;
|
|
42
|
+
export declare function scoreForNode(node: RawNode, scores: ScoreMap): ScoreEntry | undefined;
|
|
43
|
+
export declare function inferHealth(score?: ScoreEntry, now?: number): NodeHealth;
|
|
44
|
+
export declare function qualityScore(node: RawNode, scores: ScoreMap): number | null;
|
|
45
|
+
export declare function baseColorForNode(node: RawNode, storeColor: StoreColorFn): string;
|
|
46
|
+
export declare function sizeForNode(node: RawNode, scores: ScoreMap): number;
|
|
47
|
+
export declare function nodeRadius(node: RuntimeNode): number;
|
|
48
|
+
export declare function searchTextForNode(node: RawNode): string;
|
|
49
|
+
export declare function normalizeNode(node: RawNode, scores: ScoreMap, storeColor: StoreColorFn): RuntimeNode;
|
|
50
|
+
/** Undirected adjacency over every node/link, ignoring links to unknown ids. */
|
|
51
|
+
export declare function buildFullAdjacency(nodes: RuntimeNode[], links: RawLink[]): Map<string, Set<string>>;
|
|
52
|
+
export declare function connectionCounts(model: Pick<GraphModel, "fullAdjacency" | "nodeById">, nodeId: string): NodeDetail["connections"];
|
|
53
|
+
/** Check if a node is in a project's direct network (1-hop neighbors). */
|
|
54
|
+
export declare function isInProjectNetwork(visibleAdjacency: Map<string, Set<string>>, nodeId: string, projectId: string): boolean;
|
|
55
|
+
export declare function nodeDetail(model: Pick<GraphModel, "fullAdjacency" | "nodeById" | "scores">, nodeId: string): NodeDetail | null;
|
|
56
|
+
/**
|
|
57
|
+
* Structural filters only. The search query deliberately does NOT remove
|
|
58
|
+
* nodes — search dims non-matches instead, so the graph keeps its shape
|
|
59
|
+
* while matches light up.
|
|
60
|
+
*/
|
|
61
|
+
export declare function nodeMatchesFilters(node: RuntimeNode, filters: GraphFilters): boolean;
|
|
62
|
+
export declare function nodeRank(node: RuntimeNode, filters: GraphFilters, scores: ScoreMap): number;
|
|
63
|
+
export interface VisibleData {
|
|
64
|
+
nodes: RuntimeNode[];
|
|
65
|
+
links: RawLink[];
|
|
66
|
+
/** Adjacency restricted to the visible node set (pre-prune, like the browser's `visibleAdjacency`). */
|
|
67
|
+
visibleAdjacency: Map<string, Set<string>>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Apply structural filters + the node cap. Projects and the selected node are
|
|
71
|
+
* always kept when the cap trims the list.
|
|
72
|
+
*/
|
|
73
|
+
export declare function buildVisibleData(model: Pick<GraphModel, "rawNodes" | "rawLinks" | "scores">, filters: GraphFilters, selectedId: string | null): VisibleData;
|
|
74
|
+
/** Score a match the way Enter-to-fly ranks: label prefix > substring > deep text. */
|
|
75
|
+
export declare function matchRank(node: RuntimeNode, query: string, filters: GraphFilters, scores: ScoreMap): number;
|
|
76
|
+
export interface SearchMatches {
|
|
77
|
+
matchIds: Set<string>;
|
|
78
|
+
/** Matches ordered best→worst. */
|
|
79
|
+
results: RuntimeNode[];
|
|
80
|
+
}
|
|
81
|
+
/** Recompute the set of visible nodes matching a search query. */
|
|
82
|
+
export declare function recomputeSearchMatches(visibleNodes: RuntimeNode[], query: string, filters: GraphFilters, scores: ScoreMap): SearchMatches;
|
|
83
|
+
/** The best search hit for Enter-to-fly: first of the ranked results. */
|
|
84
|
+
export declare function bestSearchMatch(results: RuntimeNode[]): RuntimeNode | null;
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { KIND_COLORS, STORE_COLORS, TOPIC_COLORS } from "./types.js";
|
|
2
|
+
/** Hands out a distinct palette colour per non-primary store, first come first served. */
|
|
3
|
+
export class StoreColorAssigner {
|
|
4
|
+
assigned = new Map();
|
|
5
|
+
color(storeName) {
|
|
6
|
+
if (!storeName || storeName === "primary")
|
|
7
|
+
return null;
|
|
8
|
+
const existing = this.assigned.get(storeName);
|
|
9
|
+
if (existing)
|
|
10
|
+
return existing;
|
|
11
|
+
const idx = (this.assigned.size + 1) % STORE_COLORS.length;
|
|
12
|
+
this.assigned.set(storeName, STORE_COLORS[idx]);
|
|
13
|
+
return STORE_COLORS[idx];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function clamp(value, min, max) {
|
|
17
|
+
return Math.min(max, Math.max(min, value));
|
|
18
|
+
}
|
|
19
|
+
export function hashString(value) {
|
|
20
|
+
let hash = 2166136261;
|
|
21
|
+
for (let i = 0; i < value.length; i++) {
|
|
22
|
+
hash ^= value.charCodeAt(i);
|
|
23
|
+
hash = Math.imul(hash, 16777619);
|
|
24
|
+
}
|
|
25
|
+
return hash >>> 0;
|
|
26
|
+
}
|
|
27
|
+
/** Deterministic pseudo-random in [0, 1) derived from a value + salt. */
|
|
28
|
+
export function seeded(value, salt) {
|
|
29
|
+
return (hashString(`${salt}:${value}`) % 10000) / 10000;
|
|
30
|
+
}
|
|
31
|
+
export function deriveKind(node) {
|
|
32
|
+
if (node.group === "project")
|
|
33
|
+
return "project";
|
|
34
|
+
if (node.group === "entity")
|
|
35
|
+
return "entity";
|
|
36
|
+
if (node.group === "reference")
|
|
37
|
+
return "reference";
|
|
38
|
+
if (node.group.startsWith("task-"))
|
|
39
|
+
return "task";
|
|
40
|
+
if (node.group.startsWith("topic:"))
|
|
41
|
+
return "finding";
|
|
42
|
+
return "other";
|
|
43
|
+
}
|
|
44
|
+
export function topicColor(slug) {
|
|
45
|
+
if (!slug)
|
|
46
|
+
return KIND_COLORS.other;
|
|
47
|
+
return TOPIC_COLORS[slug] || TOPIC_COLORS.general;
|
|
48
|
+
}
|
|
49
|
+
export function scoreForNode(node, scores) {
|
|
50
|
+
if (node.scoreKey && scores[node.scoreKey])
|
|
51
|
+
return scores[node.scoreKey];
|
|
52
|
+
if (node.scoreKeys) {
|
|
53
|
+
for (const key of node.scoreKeys) {
|
|
54
|
+
if (scores[key])
|
|
55
|
+
return scores[key];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (node.refDocs) {
|
|
59
|
+
for (const ref of node.refDocs) {
|
|
60
|
+
if (ref.scoreKey && scores[ref.scoreKey])
|
|
61
|
+
return scores[ref.scoreKey];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
export function inferHealth(score, now = Date.now()) {
|
|
67
|
+
if (!score || !score.lastUsedAt)
|
|
68
|
+
return "healthy";
|
|
69
|
+
const ageMs = now - new Date(score.lastUsedAt).getTime();
|
|
70
|
+
const ageDays = Number.isFinite(ageMs) ? ageMs / 86400000 : 0;
|
|
71
|
+
const penalties = (score.repromptPenalty || 0) + (score.regressionPenalty || 0) * 2;
|
|
72
|
+
if (ageDays > 150 || penalties >= 4)
|
|
73
|
+
return "stale";
|
|
74
|
+
if (ageDays > 60 || penalties >= 2)
|
|
75
|
+
return "decaying";
|
|
76
|
+
return "healthy";
|
|
77
|
+
}
|
|
78
|
+
export function qualityScore(node, scores) {
|
|
79
|
+
const score = scoreForNode(node, scores);
|
|
80
|
+
if (!score)
|
|
81
|
+
return null;
|
|
82
|
+
const helpful = score.helpful || 0;
|
|
83
|
+
const impressions = score.impressions || 0;
|
|
84
|
+
const penalties = (score.repromptPenalty || 0) + (score.regressionPenalty || 0) * 2;
|
|
85
|
+
const raw = 0.55 + helpful * 0.1 + Math.min(0.2, impressions * 0.02) - penalties * 0.08;
|
|
86
|
+
return clamp(raw, 0.1, 1);
|
|
87
|
+
}
|
|
88
|
+
export function baseColorForNode(node, storeColor) {
|
|
89
|
+
const kind = deriveKind(node);
|
|
90
|
+
if (kind === "finding")
|
|
91
|
+
return topicColor(node.topicSlug || node.group.slice(6));
|
|
92
|
+
if (kind === "task") {
|
|
93
|
+
if (node.section === "Done" || node.group === "task-done")
|
|
94
|
+
return KIND_COLORS["task-done"];
|
|
95
|
+
if (node.section === "Active" || node.group === "task-active")
|
|
96
|
+
return KIND_COLORS["task-active"];
|
|
97
|
+
return KIND_COLORS["task-queue"];
|
|
98
|
+
}
|
|
99
|
+
if (kind === "project")
|
|
100
|
+
return storeColor(node.store) || KIND_COLORS.project;
|
|
101
|
+
if (kind === "entity")
|
|
102
|
+
return KIND_COLORS.entity;
|
|
103
|
+
if (kind === "reference")
|
|
104
|
+
return KIND_COLORS.reference;
|
|
105
|
+
return KIND_COLORS.other;
|
|
106
|
+
}
|
|
107
|
+
export function sizeForNode(node, scores) {
|
|
108
|
+
const kind = deriveKind(node);
|
|
109
|
+
const refCount = Math.max(0, node.refCount || 0);
|
|
110
|
+
const score = scoreForNode(node, scores);
|
|
111
|
+
const helpful = Math.max(0, score?.helpful || 0);
|
|
112
|
+
if (kind === "project")
|
|
113
|
+
return clamp(20 + Math.sqrt(refCount + 4) * 4, 24, 38);
|
|
114
|
+
if (kind === "entity")
|
|
115
|
+
return clamp(8 + Math.sqrt(refCount + 1) * 2.3, 10, 22);
|
|
116
|
+
if (kind === "finding")
|
|
117
|
+
return clamp(7.5 + Math.sqrt(helpful + 1) * 1.8 + (node.tagged ? 1.4 : 0), 9, 18);
|
|
118
|
+
if (kind === "task")
|
|
119
|
+
return clamp(8 + (node.section === "Active" ? 2 : 0) + (node.priority === "high" ? 1 : 0), 8, 15);
|
|
120
|
+
if (kind === "reference")
|
|
121
|
+
return clamp(7 + Math.sqrt(refCount + 1) * 1.2, 7, 12);
|
|
122
|
+
return 9;
|
|
123
|
+
}
|
|
124
|
+
export function nodeRadius(node) {
|
|
125
|
+
return clamp(node.size * 0.5, 4, 18);
|
|
126
|
+
}
|
|
127
|
+
export function searchTextForNode(node) {
|
|
128
|
+
return [
|
|
129
|
+
node.label,
|
|
130
|
+
node.fullLabel,
|
|
131
|
+
node.project,
|
|
132
|
+
node.entityType,
|
|
133
|
+
node.section,
|
|
134
|
+
node.priority,
|
|
135
|
+
node.topicSlug,
|
|
136
|
+
node.topicLabel,
|
|
137
|
+
...(node.connectedProjects || []),
|
|
138
|
+
...(node.refDocs || []).map((ref) => ref.doc),
|
|
139
|
+
].join(" ").toLowerCase();
|
|
140
|
+
}
|
|
141
|
+
export function normalizeNode(node, scores, storeColor) {
|
|
142
|
+
const score = scoreForNode(node, scores);
|
|
143
|
+
const kind = deriveKind(node);
|
|
144
|
+
return {
|
|
145
|
+
...node,
|
|
146
|
+
kind,
|
|
147
|
+
searchText: searchTextForNode(node),
|
|
148
|
+
health: inferHealth(score),
|
|
149
|
+
baseColor: baseColorForNode(node, storeColor),
|
|
150
|
+
size: sizeForNode(node, scores),
|
|
151
|
+
forceLabel: kind === "project" || (kind === "entity" && (node.refCount || 0) >= 12),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/** Undirected adjacency over every node/link, ignoring links to unknown ids. */
|
|
155
|
+
export function buildFullAdjacency(nodes, links) {
|
|
156
|
+
const adjacency = new Map();
|
|
157
|
+
for (const node of nodes)
|
|
158
|
+
adjacency.set(node.id, new Set());
|
|
159
|
+
for (const link of links) {
|
|
160
|
+
if (!adjacency.has(link.source) || !adjacency.has(link.target))
|
|
161
|
+
continue;
|
|
162
|
+
adjacency.get(link.source).add(link.target);
|
|
163
|
+
adjacency.get(link.target).add(link.source);
|
|
164
|
+
}
|
|
165
|
+
return adjacency;
|
|
166
|
+
}
|
|
167
|
+
export function connectionCounts(model, nodeId) {
|
|
168
|
+
const counts = { total: 0, projects: 0, findings: 0, tasks: 0, entities: 0, references: 0 };
|
|
169
|
+
const adjacency = model.fullAdjacency.get(nodeId);
|
|
170
|
+
if (!adjacency)
|
|
171
|
+
return counts;
|
|
172
|
+
counts.total = adjacency.size;
|
|
173
|
+
adjacency.forEach((neighborId) => {
|
|
174
|
+
const neighbor = model.nodeById.get(neighborId);
|
|
175
|
+
if (!neighbor)
|
|
176
|
+
return;
|
|
177
|
+
if (neighbor.kind === "project")
|
|
178
|
+
counts.projects++;
|
|
179
|
+
else if (neighbor.kind === "finding")
|
|
180
|
+
counts.findings++;
|
|
181
|
+
else if (neighbor.kind === "task")
|
|
182
|
+
counts.tasks++;
|
|
183
|
+
else if (neighbor.kind === "entity")
|
|
184
|
+
counts.entities++;
|
|
185
|
+
else if (neighbor.kind === "reference")
|
|
186
|
+
counts.references++;
|
|
187
|
+
});
|
|
188
|
+
return counts;
|
|
189
|
+
}
|
|
190
|
+
/** Check if a node is in a project's direct network (1-hop neighbors). */
|
|
191
|
+
export function isInProjectNetwork(visibleAdjacency, nodeId, projectId) {
|
|
192
|
+
if (nodeId === projectId)
|
|
193
|
+
return true;
|
|
194
|
+
const neighbors = visibleAdjacency.get(projectId);
|
|
195
|
+
if (neighbors?.has(nodeId))
|
|
196
|
+
return true;
|
|
197
|
+
const nodeNeighbors = visibleAdjacency.get(nodeId);
|
|
198
|
+
if (nodeNeighbors) {
|
|
199
|
+
for (const nn of nodeNeighbors) {
|
|
200
|
+
if (neighbors?.has(nn))
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
export function nodeDetail(model, nodeId) {
|
|
207
|
+
const node = model.nodeById.get(nodeId);
|
|
208
|
+
if (!node)
|
|
209
|
+
return null;
|
|
210
|
+
return {
|
|
211
|
+
...node,
|
|
212
|
+
displayLabel: node.label,
|
|
213
|
+
tooltipLabel: node.fullLabel || node.label,
|
|
214
|
+
text: node.fullLabel || node.label,
|
|
215
|
+
docs: (node.refDocs || []).map((ref) => ref.doc),
|
|
216
|
+
projectName: node.project || "",
|
|
217
|
+
qualityScore: qualityScore(node, model.scores),
|
|
218
|
+
connections: connectionCounts(model, nodeId),
|
|
219
|
+
score: scoreForNode(node, model.scores),
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Structural filters only. The search query deliberately does NOT remove
|
|
224
|
+
* nodes — search dims non-matches instead, so the graph keeps its shape
|
|
225
|
+
* while matches light up.
|
|
226
|
+
*/
|
|
227
|
+
export function nodeMatchesFilters(node, filters) {
|
|
228
|
+
if (!filters.filterTypes[node.kind])
|
|
229
|
+
return false;
|
|
230
|
+
if (node.kind === "finding" && node.topicSlug && filters.filterTopics[node.topicSlug] === false)
|
|
231
|
+
return false;
|
|
232
|
+
if (filters.filterHealth === "aging") {
|
|
233
|
+
if (node.health === "healthy")
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
else if (filters.filterHealth !== "all" && node.health !== filters.filterHealth) {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
if (filters.filterStore !== "all" && node.store && node.store !== filters.filterStore)
|
|
240
|
+
return false;
|
|
241
|
+
if (filters.filterProject !== "all") {
|
|
242
|
+
const project = filters.filterProject;
|
|
243
|
+
const connectedProjects = new Set();
|
|
244
|
+
if (node.project)
|
|
245
|
+
connectedProjects.add(node.project);
|
|
246
|
+
(node.connectedProjects || []).forEach((name) => connectedProjects.add(name));
|
|
247
|
+
(node.refDocs || []).forEach((ref) => {
|
|
248
|
+
if (ref.project)
|
|
249
|
+
connectedProjects.add(ref.project);
|
|
250
|
+
else if (ref.doc.includes("/"))
|
|
251
|
+
connectedProjects.add(ref.doc.slice(0, ref.doc.indexOf("/")));
|
|
252
|
+
});
|
|
253
|
+
if (node.kind === "project") {
|
|
254
|
+
if ((node.project || "") !== project)
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
else if (!connectedProjects.has(project)) {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return true;
|
|
262
|
+
}
|
|
263
|
+
export function nodeRank(node, filters, scores) {
|
|
264
|
+
let rank = 0;
|
|
265
|
+
if (node.kind === "project")
|
|
266
|
+
rank += 2000;
|
|
267
|
+
if (node.kind === "entity")
|
|
268
|
+
rank += 800 + (node.refCount || 0) * 8;
|
|
269
|
+
if (node.kind === "finding")
|
|
270
|
+
rank += 600 + (scoreForNode(node, scores)?.helpful || 0) * 14 + (node.tagged ? 45 : 0);
|
|
271
|
+
if (node.kind === "task")
|
|
272
|
+
rank += node.section === "Active" ? 540 : 470;
|
|
273
|
+
if (node.kind === "reference")
|
|
274
|
+
rank += 180 + (node.refCount || 0) * 3;
|
|
275
|
+
if (node.priority === "high")
|
|
276
|
+
rank += 60;
|
|
277
|
+
if (node.health === "healthy")
|
|
278
|
+
rank += 24;
|
|
279
|
+
if (node.health === "decaying")
|
|
280
|
+
rank -= 12;
|
|
281
|
+
if (node.health === "stale")
|
|
282
|
+
rank -= 25;
|
|
283
|
+
if (filters.filterProject !== "all" && node.project === filters.filterProject)
|
|
284
|
+
rank += 80;
|
|
285
|
+
if (filters.filterStore !== "all" && node.store === filters.filterStore)
|
|
286
|
+
rank += 40;
|
|
287
|
+
if (filters.searchQuery && node.searchText.includes(filters.searchQuery.toLowerCase()))
|
|
288
|
+
rank += 120;
|
|
289
|
+
return rank;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Apply structural filters + the node cap. Projects and the selected node are
|
|
293
|
+
* always kept when the cap trims the list.
|
|
294
|
+
*/
|
|
295
|
+
export function buildVisibleData(model, filters, selectedId) {
|
|
296
|
+
const filteredNodes = model.rawNodes.filter((node) => nodeMatchesFilters(node, filters));
|
|
297
|
+
let limitedNodes = filteredNodes.slice();
|
|
298
|
+
if (limitedNodes.length > filters.nodeLimit) {
|
|
299
|
+
const sorted = limitedNodes.slice().sort((a, b) => nodeRank(b, filters, model.scores) - nodeRank(a, filters, model.scores));
|
|
300
|
+
const keepIds = new Set();
|
|
301
|
+
for (const node of sorted) {
|
|
302
|
+
if (keepIds.size >= filters.nodeLimit)
|
|
303
|
+
break;
|
|
304
|
+
keepIds.add(node.id);
|
|
305
|
+
}
|
|
306
|
+
model.rawNodes.forEach((node) => {
|
|
307
|
+
if (node.kind === "project")
|
|
308
|
+
keepIds.add(node.id);
|
|
309
|
+
});
|
|
310
|
+
if (selectedId)
|
|
311
|
+
keepIds.add(selectedId);
|
|
312
|
+
limitedNodes = filteredNodes.filter((node) => keepIds.has(node.id));
|
|
313
|
+
}
|
|
314
|
+
const visibleIds = new Set(limitedNodes.map((node) => node.id));
|
|
315
|
+
const visibleLinks = model.rawLinks.filter((link) => visibleIds.has(link.source) && visibleIds.has(link.target));
|
|
316
|
+
const visibleAdjacency = new Map();
|
|
317
|
+
limitedNodes.forEach((node) => visibleAdjacency.set(node.id, new Set()));
|
|
318
|
+
visibleLinks.forEach((link) => {
|
|
319
|
+
visibleAdjacency.get(link.source).add(link.target);
|
|
320
|
+
visibleAdjacency.get(link.target).add(link.source);
|
|
321
|
+
});
|
|
322
|
+
const connectedIds = new Set();
|
|
323
|
+
visibleLinks.forEach((link) => {
|
|
324
|
+
connectedIds.add(link.source);
|
|
325
|
+
connectedIds.add(link.target);
|
|
326
|
+
});
|
|
327
|
+
const prunedNodes = limitedNodes.filter((node) => node.kind !== "project" || connectedIds.has(node.id) || (node.project || "") === filters.filterProject || filters.filterTypes.project);
|
|
328
|
+
return { nodes: prunedNodes, links: visibleLinks, visibleAdjacency };
|
|
329
|
+
}
|
|
330
|
+
/** Score a match the way Enter-to-fly ranks: label prefix > substring > deep text. */
|
|
331
|
+
export function matchRank(node, query, filters, scores) {
|
|
332
|
+
const label = node.label.toLowerCase();
|
|
333
|
+
const score = label.startsWith(query) ? 3 : label.includes(query) ? 2 : 1;
|
|
334
|
+
return score * 100000 + nodeRank(node, filters, scores);
|
|
335
|
+
}
|
|
336
|
+
/** Recompute the set of visible nodes matching a search query. */
|
|
337
|
+
export function recomputeSearchMatches(visibleNodes, query, filters, scores) {
|
|
338
|
+
const matchIds = new Set();
|
|
339
|
+
const needle = query.trim().toLowerCase();
|
|
340
|
+
if (!needle)
|
|
341
|
+
return { matchIds, results: [] };
|
|
342
|
+
const matched = [];
|
|
343
|
+
for (const node of visibleNodes) {
|
|
344
|
+
if (node.searchText.includes(needle)) {
|
|
345
|
+
matchIds.add(node.id);
|
|
346
|
+
matched.push(node);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
matched.sort((a, b) => matchRank(b, needle, filters, scores) - matchRank(a, needle, filters, scores));
|
|
350
|
+
return { matchIds, results: matched };
|
|
351
|
+
}
|
|
352
|
+
/** The best search hit for Enter-to-fly: first of the ranked results. */
|
|
353
|
+
export function bestSearchMatch(results) {
|
|
354
|
+
return results.length ? results[0] : null;
|
|
355
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared graph payload contract.
|
|
3
|
+
*
|
|
4
|
+
* This module is consumed by three hosts: the browser 3D viewer (bundled by
|
|
5
|
+
* esbuild from `browser/`), the VS Code webview (via the same bundle), and the
|
|
6
|
+
* terminal graph view in `phren shell` (compiled by tsc). It must therefore
|
|
7
|
+
* stay free of DOM, node builtins, and any import outside `src/graph-core/`.
|
|
8
|
+
*/
|
|
9
|
+
export type ScoreEntry = {
|
|
10
|
+
impressions?: number;
|
|
11
|
+
helpful?: number;
|
|
12
|
+
repromptPenalty?: number;
|
|
13
|
+
regressionPenalty?: number;
|
|
14
|
+
lastUsedAt?: string;
|
|
15
|
+
};
|
|
16
|
+
export type RawNode = {
|
|
17
|
+
id: string;
|
|
18
|
+
label: string;
|
|
19
|
+
fullLabel?: string;
|
|
20
|
+
group: string;
|
|
21
|
+
refCount?: number;
|
|
22
|
+
project?: string;
|
|
23
|
+
store?: string;
|
|
24
|
+
tagged?: boolean;
|
|
25
|
+
scoreKey?: string;
|
|
26
|
+
scoreKeys?: string[];
|
|
27
|
+
priority?: string;
|
|
28
|
+
section?: string;
|
|
29
|
+
entityType?: string;
|
|
30
|
+
date?: string;
|
|
31
|
+
refDocs?: Array<{
|
|
32
|
+
doc: string;
|
|
33
|
+
project?: string;
|
|
34
|
+
scoreKey?: string;
|
|
35
|
+
}>;
|
|
36
|
+
connectedProjects?: string[];
|
|
37
|
+
topicSlug?: string;
|
|
38
|
+
topicLabel?: string;
|
|
39
|
+
findingCount?: number;
|
|
40
|
+
taskCount?: number;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Edge flavour. Absent (or "star") is the default project→leaf spoke the web
|
|
44
|
+
* viewer has always drawn; the typed kinds are opt-in enrichments emitted by
|
|
45
|
+
* `buildGraph` for hosts that want real traversal structure.
|
|
46
|
+
*/
|
|
47
|
+
export type RawLinkKind = "star" | "fragment" | "supersedes" | "contradicts";
|
|
48
|
+
export type RawLink = {
|
|
49
|
+
source: string;
|
|
50
|
+
target: string;
|
|
51
|
+
kind?: RawLinkKind;
|
|
52
|
+
};
|
|
53
|
+
export type RawTopic = {
|
|
54
|
+
slug: string;
|
|
55
|
+
label: string;
|
|
56
|
+
};
|
|
57
|
+
export type GraphPayload = {
|
|
58
|
+
nodes?: RawNode[];
|
|
59
|
+
links?: RawLink[];
|
|
60
|
+
scores?: Record<string, ScoreEntry>;
|
|
61
|
+
topics?: RawTopic[];
|
|
62
|
+
};
|
|
63
|
+
export type NodeKind = "project" | "finding" | "task" | "entity" | "reference" | "other";
|
|
64
|
+
export type NodeHealth = "healthy" | "decaying" | "stale";
|
|
65
|
+
export type RuntimeNode = RawNode & {
|
|
66
|
+
kind: NodeKind;
|
|
67
|
+
searchText: string;
|
|
68
|
+
health: NodeHealth;
|
|
69
|
+
baseColor: string;
|
|
70
|
+
size: number;
|
|
71
|
+
forceLabel: boolean;
|
|
72
|
+
};
|
|
73
|
+
export type NodeDetail = RuntimeNode & {
|
|
74
|
+
displayLabel: string;
|
|
75
|
+
tooltipLabel: string;
|
|
76
|
+
text: string;
|
|
77
|
+
docs: string[];
|
|
78
|
+
projectName: string;
|
|
79
|
+
qualityScore: number | null;
|
|
80
|
+
connections: {
|
|
81
|
+
total: number;
|
|
82
|
+
projects: number;
|
|
83
|
+
findings: number;
|
|
84
|
+
tasks: number;
|
|
85
|
+
entities: number;
|
|
86
|
+
references: number;
|
|
87
|
+
};
|
|
88
|
+
score?: ScoreEntry;
|
|
89
|
+
/** Values supplied by the project pane's inline editor on save. */
|
|
90
|
+
editedText?: string;
|
|
91
|
+
editedSection?: string;
|
|
92
|
+
editedPriority?: string;
|
|
93
|
+
};
|
|
94
|
+
/** The void. Every layer sits on this near-black indigo. */
|
|
95
|
+
export declare const BG_COLOR = "#05060f";
|
|
96
|
+
/** Amber used for selection / focused links — the single warm accent. */
|
|
97
|
+
export declare const ACCENT_AMBER = "#ffd166";
|
|
98
|
+
/** Cyan used for live pulses, HUD borders and hover accents. */
|
|
99
|
+
export declare const ACCENT_CYAN = "#67e8f9";
|
|
100
|
+
export declare const TOPIC_COLORS: Record<string, string>;
|
|
101
|
+
export declare const KIND_COLORS: {
|
|
102
|
+
project: string;
|
|
103
|
+
entity: string;
|
|
104
|
+
reference: string;
|
|
105
|
+
"task-active": string;
|
|
106
|
+
"task-queue": string;
|
|
107
|
+
"task-done": string;
|
|
108
|
+
other: string;
|
|
109
|
+
};
|
|
110
|
+
export declare const STORE_COLORS: string[];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared graph payload contract.
|
|
3
|
+
*
|
|
4
|
+
* This module is consumed by three hosts: the browser 3D viewer (bundled by
|
|
5
|
+
* esbuild from `browser/`), the VS Code webview (via the same bundle), and the
|
|
6
|
+
* terminal graph view in `phren shell` (compiled by tsc). It must therefore
|
|
7
|
+
* stay free of DOM, node builtins, and any import outside `src/graph-core/`.
|
|
8
|
+
*/
|
|
9
|
+
// ── Holographic-archive palette ─────────────────────────────────────────
|
|
10
|
+
/** The void. Every layer sits on this near-black indigo. */
|
|
11
|
+
export const BG_COLOR = "#05060f";
|
|
12
|
+
/** Amber used for selection / focused links — the single warm accent. */
|
|
13
|
+
export const ACCENT_AMBER = "#ffd166";
|
|
14
|
+
/** Cyan used for live pulses, HUD borders and hover accents. */
|
|
15
|
+
export const ACCENT_CYAN = "#67e8f9";
|
|
16
|
+
export const TOPIC_COLORS = {
|
|
17
|
+
architecture: "#46c8ff",
|
|
18
|
+
debugging: "#ff5470",
|
|
19
|
+
security: "#ff7847",
|
|
20
|
+
performance: "#ffb648",
|
|
21
|
+
testing: "#3ce8a4",
|
|
22
|
+
devops: "#2ee6c8",
|
|
23
|
+
tooling: "#6d8dff",
|
|
24
|
+
api: "#4f7dff",
|
|
25
|
+
database: "#38b6ff",
|
|
26
|
+
frontend: "#b48bff",
|
|
27
|
+
auth: "#ff9346",
|
|
28
|
+
data: "#2ed3e8",
|
|
29
|
+
mobile: "#43e0a8",
|
|
30
|
+
ai_ml: "#9d7bff",
|
|
31
|
+
general: "#7f8db3",
|
|
32
|
+
};
|
|
33
|
+
export const KIND_COLORS = {
|
|
34
|
+
project: "#f5b342",
|
|
35
|
+
entity: "#38e1ff",
|
|
36
|
+
reference: "#42e099",
|
|
37
|
+
"task-active": "#3ae374",
|
|
38
|
+
"task-queue": "#48b2ff",
|
|
39
|
+
"task-done": "#5c6b8a",
|
|
40
|
+
other: "#7f8db3",
|
|
41
|
+
};
|
|
42
|
+
// Distinct colors per store — up to 6 stores, then cycles
|
|
43
|
+
export const STORE_COLORS = ["#f5b342", "#9d7bff", "#2ed3e8", "#ff5470", "#43e0a8", "#f472b6"];
|
package/dist/index.js
CHANGED
|
@@ -102,8 +102,11 @@ async function main() {
|
|
|
102
102
|
indexReady = false;
|
|
103
103
|
db = await buildIndex(phrenPath, profile);
|
|
104
104
|
indexReady = true;
|
|
105
|
+
// buildIndex() hands back its cached handle inside the debounce
|
|
106
|
+
// window, so oldDb can be the very database we just installed.
|
|
105
107
|
try {
|
|
106
|
-
oldDb
|
|
108
|
+
if (oldDb && oldDb !== db)
|
|
109
|
+
oldDb.close();
|
|
107
110
|
}
|
|
108
111
|
catch (err) {
|
|
109
112
|
logger.warn("rebuildIndex", `dbClose: ${errorMessage(err)}`);
|
|
@@ -37,7 +37,7 @@ function runSyncCommand(command, args) {
|
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
function shouldUninstallCurrentGlobalPackage() {
|
|
40
|
+
export function shouldUninstallCurrentGlobalPackage() {
|
|
41
41
|
// `npm uninstall -g` resolves against the machine's real npm prefix, which
|
|
42
42
|
// no amount of PHREN_PATH/HOME redirection sandboxes. A test that spawns
|
|
43
43
|
// `phren uninstall` against temp directories would therefore delete the
|