@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
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic 2D force layout for the terminal graph view.
|
|
3
|
+
*
|
|
4
|
+
* The web viewer leans on 3d-force-graph; in the terminal we want something
|
|
5
|
+
* dependency-free, fast enough for a few hundred nodes, and — above all —
|
|
6
|
+
* deterministic, so the same store draws the same map every time the view
|
|
7
|
+
* opens. All jitter is derived from node ids via `seeded()`; nothing here
|
|
8
|
+
* calls Math.random.
|
|
9
|
+
*
|
|
10
|
+
* The store's topology is a star (project → findings/tasks/fragments/refs),
|
|
11
|
+
* so the simulation adds a gentle pull toward each node's home project. That
|
|
12
|
+
* keeps clusters readable instead of letting repulsion smear everything into
|
|
13
|
+
* one ring.
|
|
14
|
+
*/
|
|
15
|
+
import { seeded } from "../../graph-core/model.js";
|
|
16
|
+
/** Ideal edge length in world units. Everything else is scaled off this. */
|
|
17
|
+
export const IDEAL_DISTANCE = 12;
|
|
18
|
+
/** Spring strength by edge flavour: spokes hold the clusters, enrichment edges just nudge. */
|
|
19
|
+
const LINK_STRENGTH = {
|
|
20
|
+
star: 1,
|
|
21
|
+
fragment: 0.25,
|
|
22
|
+
supersedes: 0.6,
|
|
23
|
+
contradicts: 0.4,
|
|
24
|
+
};
|
|
25
|
+
/** Project ids in stable order plus, for every node, the project(s) it hangs off. */
|
|
26
|
+
function homes(nodes, links) {
|
|
27
|
+
const byId = new Map(nodes.map((node) => [node.id, node]));
|
|
28
|
+
const projects = nodes.filter((node) => node.kind === "project").sort((a, b) => a.id.localeCompare(b.id));
|
|
29
|
+
const projectByName = new Map(projects.map((node) => [node.project ?? node.id, node.id]));
|
|
30
|
+
const homeOf = new Map();
|
|
31
|
+
for (const node of nodes) {
|
|
32
|
+
if (node.kind === "project") {
|
|
33
|
+
homeOf.set(node.id, [node.id]);
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const own = node.project ? projectByName.get(node.project) : undefined;
|
|
37
|
+
homeOf.set(node.id, own ? [own] : []);
|
|
38
|
+
}
|
|
39
|
+
for (const link of links) {
|
|
40
|
+
if (link.kind && link.kind !== "star")
|
|
41
|
+
continue;
|
|
42
|
+
const a = byId.get(link.source);
|
|
43
|
+
const b = byId.get(link.target);
|
|
44
|
+
if (!a || !b)
|
|
45
|
+
continue;
|
|
46
|
+
if (a.kind === "project" && b.kind !== "project")
|
|
47
|
+
pushUnique(homeOf.get(b.id), a.id);
|
|
48
|
+
else if (b.kind === "project" && a.kind !== "project")
|
|
49
|
+
pushUnique(homeOf.get(a.id), b.id);
|
|
50
|
+
}
|
|
51
|
+
return { projects, homeOf };
|
|
52
|
+
}
|
|
53
|
+
function pushUnique(list, value) {
|
|
54
|
+
if (!list.includes(value))
|
|
55
|
+
list.push(value);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Starting positions: projects on a ring, leaves in a jittered blob around
|
|
59
|
+
* their home project, multi-home fragments at the centroid of their homes,
|
|
60
|
+
* orphans on an outer ring.
|
|
61
|
+
*/
|
|
62
|
+
export function seedPositions(nodes, links) {
|
|
63
|
+
const positions = new Map();
|
|
64
|
+
const { projects, homeOf } = homes(nodes, links);
|
|
65
|
+
const ring = IDEAL_DISTANCE * Math.max(2.5, Math.sqrt(projects.length) * 2.2);
|
|
66
|
+
projects.forEach((project, i) => {
|
|
67
|
+
const angle = (i / Math.max(1, projects.length)) * Math.PI * 2 - Math.PI / 2;
|
|
68
|
+
positions.set(project.id, { x: Math.cos(angle) * ring, y: Math.sin(angle) * ring });
|
|
69
|
+
});
|
|
70
|
+
if (projects.length === 1)
|
|
71
|
+
positions.set(projects[0].id, { x: 0, y: 0 });
|
|
72
|
+
const outer = ring + IDEAL_DISTANCE * 3;
|
|
73
|
+
for (const node of nodes) {
|
|
74
|
+
if (node.kind === "project")
|
|
75
|
+
continue;
|
|
76
|
+
const home = (homeOf.get(node.id) ?? []).map((id) => positions.get(id)).filter((p) => Boolean(p));
|
|
77
|
+
const angle = seeded(node.id, "angle") * Math.PI * 2;
|
|
78
|
+
if (home.length === 0) {
|
|
79
|
+
positions.set(node.id, { x: Math.cos(angle) * outer, y: Math.sin(angle) * outer });
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const cx = home.reduce((sum, p) => sum + p.x, 0) / home.length;
|
|
83
|
+
const cy = home.reduce((sum, p) => sum + p.y, 0) / home.length;
|
|
84
|
+
const radius = home.length > 1 ? IDEAL_DISTANCE * 0.4 : IDEAL_DISTANCE * (0.6 + seeded(node.id, "radius") * 1.2);
|
|
85
|
+
positions.set(node.id, { x: cx + Math.cos(angle) * radius, y: cy + Math.sin(angle) * radius });
|
|
86
|
+
}
|
|
87
|
+
return positions;
|
|
88
|
+
}
|
|
89
|
+
export class ForceSim {
|
|
90
|
+
positions;
|
|
91
|
+
ids;
|
|
92
|
+
index;
|
|
93
|
+
mass;
|
|
94
|
+
anchors;
|
|
95
|
+
isProject;
|
|
96
|
+
links;
|
|
97
|
+
temperature;
|
|
98
|
+
startTemperature;
|
|
99
|
+
constructor(nodes, links, seed) {
|
|
100
|
+
this.ids = nodes.map((node) => node.id);
|
|
101
|
+
this.index = new Map(this.ids.map((id, i) => [id, i]));
|
|
102
|
+
this.mass = nodes.map((node) => (node.kind === "project" ? 4 : 1) * Math.max(0.6, node.size / 12));
|
|
103
|
+
this.isProject = nodes.map((node) => node.kind === "project");
|
|
104
|
+
const { homeOf } = homes(nodes, links);
|
|
105
|
+
this.anchors = nodes.map((node) => (homeOf.get(node.id) ?? []).map((id) => this.index.get(id)).filter((i) => i !== undefined));
|
|
106
|
+
this.links = [];
|
|
107
|
+
for (const link of links) {
|
|
108
|
+
const a = this.index.get(link.source);
|
|
109
|
+
const b = this.index.get(link.target);
|
|
110
|
+
if (a === undefined || b === undefined || a === b)
|
|
111
|
+
continue;
|
|
112
|
+
this.links.push({ a, b, strength: LINK_STRENGTH[link.kind ?? "star"] });
|
|
113
|
+
}
|
|
114
|
+
const seeded = seedPositions(nodes, links);
|
|
115
|
+
this.positions = new Map();
|
|
116
|
+
for (const id of this.ids)
|
|
117
|
+
this.positions.set(id, { ...(seed?.get(id) ?? seeded.get(id)) });
|
|
118
|
+
this.startTemperature = IDEAL_DISTANCE * Math.max(1, Math.sqrt(nodes.length) / 4);
|
|
119
|
+
this.temperature = this.startTemperature;
|
|
120
|
+
}
|
|
121
|
+
/** 1 at the start, 0 when settled; mirrors d3's `alpha` for hosts that animate. */
|
|
122
|
+
get alpha() {
|
|
123
|
+
return this.startTemperature > 0 ? this.temperature / this.startTemperature : 0;
|
|
124
|
+
}
|
|
125
|
+
get settled() {
|
|
126
|
+
return this.temperature < 0.15;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Reuse a previous layout's positions for nodes that survived a data
|
|
130
|
+
* refresh, and reheat only mildly so the map shifts instead of scrambling.
|
|
131
|
+
*/
|
|
132
|
+
warmStart(previous) {
|
|
133
|
+
let reused = 0;
|
|
134
|
+
for (const id of this.ids) {
|
|
135
|
+
const prev = previous.get(id);
|
|
136
|
+
if (!prev)
|
|
137
|
+
continue;
|
|
138
|
+
this.positions.set(id, { ...prev });
|
|
139
|
+
reused++;
|
|
140
|
+
}
|
|
141
|
+
if (reused > 0)
|
|
142
|
+
this.temperature = Math.max(0.15, this.startTemperature * (reused === this.ids.length ? 0.15 : 0.4));
|
|
143
|
+
}
|
|
144
|
+
/** Reheat to the initial temperature (e.g. the `r` relayout key). */
|
|
145
|
+
reheat() {
|
|
146
|
+
this.temperature = this.startTemperature;
|
|
147
|
+
}
|
|
148
|
+
tick(count = 1) {
|
|
149
|
+
for (let n = 0; n < count; n++) {
|
|
150
|
+
if (this.settled)
|
|
151
|
+
return;
|
|
152
|
+
this.step();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/** Run until settled or the tick budget is spent. */
|
|
156
|
+
settle(maxTicks = 400) {
|
|
157
|
+
for (let n = 0; n < maxTicks && !this.settled; n++)
|
|
158
|
+
this.step();
|
|
159
|
+
}
|
|
160
|
+
step() {
|
|
161
|
+
const count = this.ids.length;
|
|
162
|
+
if (count === 0) {
|
|
163
|
+
this.temperature = 0;
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const xs = new Float64Array(count);
|
|
167
|
+
const ys = new Float64Array(count);
|
|
168
|
+
const dx = new Float64Array(count);
|
|
169
|
+
const dy = new Float64Array(count);
|
|
170
|
+
for (let i = 0; i < count; i++) {
|
|
171
|
+
const p = this.positions.get(this.ids[i]);
|
|
172
|
+
xs[i] = p.x;
|
|
173
|
+
ys[i] = p.y;
|
|
174
|
+
}
|
|
175
|
+
const k = IDEAL_DISTANCE;
|
|
176
|
+
const k2 = k * k;
|
|
177
|
+
// Repulsion: k² / d, weighted by mass so projects carve out room.
|
|
178
|
+
for (let i = 0; i < count; i++) {
|
|
179
|
+
for (let j = i + 1; j < count; j++) {
|
|
180
|
+
let ddx = xs[i] - xs[j];
|
|
181
|
+
let ddy = ys[i] - ys[j];
|
|
182
|
+
let dist2 = ddx * ddx + ddy * ddy;
|
|
183
|
+
if (dist2 < 0.01) {
|
|
184
|
+
// Coincident nodes: split them deterministically by index.
|
|
185
|
+
ddx = ((i * 7919 + j * 104729) % 17) / 17 - 0.5;
|
|
186
|
+
ddy = ((i * 15485863 + j * 32452843) % 13) / 13 - 0.5;
|
|
187
|
+
dist2 = ddx * ddx + ddy * ddy || 0.01;
|
|
188
|
+
}
|
|
189
|
+
const dist = Math.sqrt(dist2);
|
|
190
|
+
const cutoff = k * (this.isProject[i] || this.isProject[j] ? 14 : 6);
|
|
191
|
+
if (dist > cutoff)
|
|
192
|
+
continue;
|
|
193
|
+
const force = (k2 / dist) * Math.sqrt(this.mass[i] * this.mass[j]);
|
|
194
|
+
const fx = (ddx / dist) * force;
|
|
195
|
+
const fy = (ddy / dist) * force;
|
|
196
|
+
dx[i] += fx;
|
|
197
|
+
dy[i] += fy;
|
|
198
|
+
dx[j] -= fx;
|
|
199
|
+
dy[j] -= fy;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
// Attraction along links: d² / k, scaled by the edge flavour.
|
|
203
|
+
for (const link of this.links) {
|
|
204
|
+
const ddx = xs[link.a] - xs[link.b];
|
|
205
|
+
const ddy = ys[link.a] - ys[link.b];
|
|
206
|
+
const dist = Math.sqrt(ddx * ddx + ddy * ddy) || 0.01;
|
|
207
|
+
const force = ((dist * dist) / k) * link.strength;
|
|
208
|
+
const fx = (ddx / dist) * force;
|
|
209
|
+
const fy = (ddy / dist) * force;
|
|
210
|
+
dx[link.a] -= fx;
|
|
211
|
+
dy[link.a] -= fy;
|
|
212
|
+
dx[link.b] += fx;
|
|
213
|
+
dy[link.b] += fy;
|
|
214
|
+
}
|
|
215
|
+
// Cluster pull toward the home project(s); projects drift gently to the origin.
|
|
216
|
+
for (let i = 0; i < count; i++) {
|
|
217
|
+
if (this.isProject[i]) {
|
|
218
|
+
dx[i] -= xs[i] * 0.02;
|
|
219
|
+
dy[i] -= ys[i] * 0.02;
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
const anchors = this.anchors[i];
|
|
223
|
+
if (!anchors.length)
|
|
224
|
+
continue;
|
|
225
|
+
let ax = 0;
|
|
226
|
+
let ay = 0;
|
|
227
|
+
for (const a of anchors) {
|
|
228
|
+
ax += xs[a];
|
|
229
|
+
ay += ys[a];
|
|
230
|
+
}
|
|
231
|
+
ax /= anchors.length;
|
|
232
|
+
ay /= anchors.length;
|
|
233
|
+
dx[i] += (ax - xs[i]) * 0.08;
|
|
234
|
+
dy[i] += (ay - ys[i]) * 0.08;
|
|
235
|
+
}
|
|
236
|
+
// Apply, capped by the current temperature.
|
|
237
|
+
const cap = this.temperature;
|
|
238
|
+
for (let i = 0; i < count; i++) {
|
|
239
|
+
const len = Math.sqrt(dx[i] * dx[i] + dy[i] * dy[i]);
|
|
240
|
+
if (len === 0)
|
|
241
|
+
continue;
|
|
242
|
+
const scale = Math.min(len, cap) / len;
|
|
243
|
+
const p = this.positions.get(this.ids[i]);
|
|
244
|
+
p.x = xs[i] + dx[i] * scale;
|
|
245
|
+
p.y = ys[i] + dy[i] * scale;
|
|
246
|
+
}
|
|
247
|
+
this.temperature *= 0.94;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/** Axis-aligned bounds of a position set; null when empty. */
|
|
251
|
+
export function bounds(positions) {
|
|
252
|
+
let minX = Infinity;
|
|
253
|
+
let minY = Infinity;
|
|
254
|
+
let maxX = -Infinity;
|
|
255
|
+
let maxY = -Infinity;
|
|
256
|
+
for (const p of positions) {
|
|
257
|
+
if (p.x < minX)
|
|
258
|
+
minX = p.x;
|
|
259
|
+
if (p.y < minY)
|
|
260
|
+
minY = p.y;
|
|
261
|
+
if (p.x > maxX)
|
|
262
|
+
maxX = p.x;
|
|
263
|
+
if (p.y > maxY)
|
|
264
|
+
maxY = p.y;
|
|
265
|
+
}
|
|
266
|
+
return Number.isFinite(minX) ? { minX, minY, maxX, maxY } : null;
|
|
267
|
+
}
|
package/dist/shell/input.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { ShellState } from "../data/access.js";
|
|
6
6
|
import { type DoctorResultLike, type ShellDeps, type ShellView } from "./types.js";
|
|
7
|
+
import type { GraphController } from "./graph/controller.js";
|
|
7
8
|
/** Interface for the shell methods that executePalette needs */
|
|
8
9
|
interface PaletteHost {
|
|
9
10
|
phrenPath: string;
|
|
@@ -39,6 +40,8 @@ export interface NavigationHost extends PaletteHost {
|
|
|
39
40
|
prevHealthView: ShellView | undefined;
|
|
40
41
|
filter: string | undefined;
|
|
41
42
|
setFilter(value: string): void;
|
|
43
|
+
/** The knowledge-graph view's controller (created on first use). */
|
|
44
|
+
graph(): GraphController;
|
|
42
45
|
}
|
|
43
46
|
export declare function executePalette(host: PaletteHost, input: string): Promise<void>;
|
|
44
47
|
export declare function completeInput(line: string, phrenPath: string, profile: string, state: ShellState): string[];
|
package/dist/shell/input.js
CHANGED
|
@@ -64,6 +64,11 @@ export async function executePalette(host, input) {
|
|
|
64
64
|
host.setMessage(` ${TAB_ICONS.Health} Health`);
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
|
+
if (command === "graph" || command === "map") {
|
|
68
|
+
host.setView("Graph");
|
|
69
|
+
host.setMessage(` ${TAB_ICONS.Graph} Graph`);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
67
72
|
if (command === "open") {
|
|
68
73
|
const project = parts[1];
|
|
69
74
|
if (!project) {
|
|
@@ -463,7 +468,7 @@ export async function executePalette(host, input) {
|
|
|
463
468
|
}
|
|
464
469
|
function suggestCommand(input) {
|
|
465
470
|
const known = [
|
|
466
|
-
"help", "projects", "tasks", "task", "findings", "review queue", "machines", "health",
|
|
471
|
+
"help", "projects", "tasks", "task", "findings", "review queue", "machines", "health", "graph",
|
|
467
472
|
"open", "search", "add", "complete", "move", "reprioritize", "pin", "unpin", "context",
|
|
468
473
|
"work next", "tidy", "find add", "find remove", "machine map", "profile add-project", "profile remove-project",
|
|
469
474
|
"run fix", "relink", "rerun hooks", "update", "govern", "consolidate",
|
|
@@ -482,7 +487,7 @@ function suggestCommand(input) {
|
|
|
482
487
|
}
|
|
483
488
|
export function completeInput(line, phrenPath, profile, state) {
|
|
484
489
|
const commands = [
|
|
485
|
-
":projects", ":tasks", ":task", ":findings", ":review queue", ":machines", ":health",
|
|
490
|
+
":projects", ":tasks", ":task", ":findings", ":review queue", ":machines", ":health", ":graph",
|
|
486
491
|
":open", ":search", ":add", ":complete", ":move", ":reprioritize", ":pin",
|
|
487
492
|
":unpin", ":context", ":work next", ":tidy", ":find add", ":find remove",
|
|
488
493
|
":machine map",
|
|
@@ -580,6 +585,9 @@ export function getListItems(phrenPath, profile, state, healthLineCount) {
|
|
|
580
585
|
}
|
|
581
586
|
case "Health":
|
|
582
587
|
return Array.from({ length: Math.max(1, healthLineCount) }, (_, i) => ({ id: String(i) }));
|
|
588
|
+
case "Graph":
|
|
589
|
+
// The graph manages its own selection; the list cursor has nothing to walk.
|
|
590
|
+
return [];
|
|
583
591
|
default:
|
|
584
592
|
return [];
|
|
585
593
|
}
|
|
@@ -799,6 +807,11 @@ export function applyViewShortcut(host, key) {
|
|
|
799
807
|
host.setMessage(` ${TAB_ICONS.Health} Health ${style.dim("(esc to return)")}`);
|
|
800
808
|
return true;
|
|
801
809
|
}
|
|
810
|
+
if (key === "g") {
|
|
811
|
+
host.setView("Graph");
|
|
812
|
+
host.setMessage(` ${TAB_ICONS.Graph} Graph ${style.dim("↑↓←→ walk · / search · esc back")}`);
|
|
813
|
+
return true;
|
|
814
|
+
}
|
|
802
815
|
return false;
|
|
803
816
|
}
|
|
804
817
|
// ── Navigate-mode key handler ─────────────────────────────────────────────────
|
|
@@ -806,6 +819,13 @@ export async function handleNavigateKey(host, rawKey) {
|
|
|
806
819
|
// Terminals in application-cursor mode send SS3 (ESC O A) instead of CSI
|
|
807
820
|
// (ESC [ A) for the arrow keys; normalise so both spellings navigate.
|
|
808
821
|
const key = /^\x1bO[A-D]$/.test(rawKey) ? `\x1b[${rawKey[2]}` : rawKey;
|
|
822
|
+
// The graph view owns arrows, Enter, /, Esc-layering and its own letters;
|
|
823
|
+
// anything it declines (q, :, ?, view shortcuts, a final Esc) falls through.
|
|
824
|
+
if (host.state.view === "Graph") {
|
|
825
|
+
const handled = host.graph().handleKey(key, host);
|
|
826
|
+
if (handled !== undefined)
|
|
827
|
+
return handled;
|
|
828
|
+
}
|
|
809
829
|
if (key === "\x1b[A") {
|
|
810
830
|
host.moveCursor(-1);
|
|
811
831
|
showCursorPosition(host);
|
|
@@ -917,7 +937,7 @@ export async function handleNavigateKey(host, rawKey) {
|
|
|
917
937
|
}
|
|
918
938
|
// ── Tab switching ─────────────────────────────────────────────────────────────
|
|
919
939
|
function nextTab(host) {
|
|
920
|
-
if (host.state.view === "Projects" || host.state.view === "Health")
|
|
940
|
+
if (host.state.view === "Projects" || host.state.view === "Health" || host.state.view === "Graph")
|
|
921
941
|
return;
|
|
922
942
|
const idx = SUB_VIEWS.indexOf(host.state.view);
|
|
923
943
|
const next = SUB_VIEWS[(idx + 1) % SUB_VIEWS.length];
|
|
@@ -927,7 +947,7 @@ function nextTab(host) {
|
|
|
927
947
|
}
|
|
928
948
|
}
|
|
929
949
|
function prevTab(host) {
|
|
930
|
-
if (host.state.view === "Projects" || host.state.view === "Health")
|
|
950
|
+
if (host.state.view === "Projects" || host.state.view === "Health" || host.state.view === "Graph")
|
|
931
951
|
return;
|
|
932
952
|
const idx = SUB_VIEWS.indexOf(host.state.view);
|
|
933
953
|
const prev = SUB_VIEWS[(idx - 1 + SUB_VIEWS.length) % SUB_VIEWS.length];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The phren splash: mascot + wordmark text effect, shared by every terminal
|
|
3
|
+
* host (the interactive shell, phren-agent, anything embedding phren).
|
|
4
|
+
*
|
|
5
|
+
* The shell drives it from its own intro policy (once per version, always,
|
|
6
|
+
* off); other hosts call `playSplash` directly. Everything is injectable so
|
|
7
|
+
* the sequence can be tested without a terminal or real time.
|
|
8
|
+
*/
|
|
9
|
+
export type KeypressWaiter = () => Promise<void>;
|
|
10
|
+
export interface SplashOptions {
|
|
11
|
+
version: string;
|
|
12
|
+
/** Replaces "local memory for working agents" beside the wordmark. */
|
|
13
|
+
tagline?: string;
|
|
14
|
+
/** Dimmed line under the splash ("Press any key to enter"). */
|
|
15
|
+
hint?: string;
|
|
16
|
+
/** Play the decrypt reveal; otherwise open on the finished wordmark. */
|
|
17
|
+
reveal?: boolean;
|
|
18
|
+
/** Hold with the shimmer for this long after the reveal. */
|
|
19
|
+
dwellMs?: number;
|
|
20
|
+
/** Hold until this resolves instead of a fixed dwell. */
|
|
21
|
+
waitForKeypress?: KeypressWaiter;
|
|
22
|
+
/** Wrap in the alternate screen — for hosts that are not already fullscreen. */
|
|
23
|
+
fullscreen?: boolean;
|
|
24
|
+
/** Injection points for tests. */
|
|
25
|
+
paint?: (frame: string) => void;
|
|
26
|
+
sleep?: (ms: number) => Promise<void>;
|
|
27
|
+
isTTY?: boolean;
|
|
28
|
+
screen?: {
|
|
29
|
+
enter: () => void;
|
|
30
|
+
exit: () => void;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Play the splash and return when it is dismissed. Does nothing when stdout
|
|
35
|
+
* is not a terminal.
|
|
36
|
+
*/
|
|
37
|
+
export declare function playSplash(opts: SplashOptions): Promise<void>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The phren splash: mascot + wordmark text effect, shared by every terminal
|
|
3
|
+
* host (the interactive shell, phren-agent, anything embedding phren).
|
|
4
|
+
*
|
|
5
|
+
* The shell drives it from its own intro policy (once per version, always,
|
|
6
|
+
* off); other hosts call `playSplash` directly. Everything is injectable so
|
|
7
|
+
* the sequence can be tested without a terminal or real time.
|
|
8
|
+
*/
|
|
9
|
+
import { createPhrenAnimator } from "../phren-art.js";
|
|
10
|
+
import { LOGO_REVEAL_FRAMES, LOGO_REVEAL_FRAME_MS, LOGO_SHIMMER_FRAME_MS, logoRevealFrame, logoShimmerFrame, } from "./logo-fx.js";
|
|
11
|
+
import { composeStartupFrame, enterFullscreen, exitFullscreen, fitFrame, paintFrame, shellStartupFrames, style, } from "./render.js";
|
|
12
|
+
const NARROW_STAGE_MS = 160;
|
|
13
|
+
function realSleep(ms) {
|
|
14
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Play the splash and return when it is dismissed. Does nothing when stdout
|
|
18
|
+
* is not a terminal.
|
|
19
|
+
*/
|
|
20
|
+
export async function playSplash(opts) {
|
|
21
|
+
const isTTY = opts.isTTY ?? Boolean(process.stdout.isTTY);
|
|
22
|
+
if (!isTTY)
|
|
23
|
+
return;
|
|
24
|
+
const paint = opts.paint ?? paintFrame;
|
|
25
|
+
const sleep = opts.sleep ?? realSleep;
|
|
26
|
+
const screen = opts.screen ?? { enter: enterFullscreen, exit: exitFullscreen };
|
|
27
|
+
const hint = opts.hint ? style.dim(opts.hint) : undefined;
|
|
28
|
+
const dwellMs = opts.dwellMs ?? 0;
|
|
29
|
+
if (opts.fullscreen)
|
|
30
|
+
screen.enter();
|
|
31
|
+
const animator = createPhrenAnimator({ facing: "right" });
|
|
32
|
+
animator.start();
|
|
33
|
+
let shimmerTick = 0;
|
|
34
|
+
const frame = (logo, withHint = true) => {
|
|
35
|
+
paint(fitFrame(composeStartupFrame(animator.getFrame(), opts.version, withHint ? hint : undefined, logo ?? logoShimmerFrame(shimmerTick++), opts.tagline)));
|
|
36
|
+
};
|
|
37
|
+
try {
|
|
38
|
+
if (opts.reveal) {
|
|
39
|
+
// Terminals too narrow for the wordmark get the staged text reveal instead.
|
|
40
|
+
const stages = shellStartupFrames(opts.version, opts.tagline);
|
|
41
|
+
if (stages.length > 1) {
|
|
42
|
+
for (const stage of stages.slice(0, -1)) {
|
|
43
|
+
paint(stage);
|
|
44
|
+
await sleep(NARROW_STAGE_MS);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
for (let i = 0; i < LOGO_REVEAL_FRAMES; i++) {
|
|
49
|
+
frame(logoRevealFrame(i / (LOGO_REVEAL_FRAMES - 1)), false);
|
|
50
|
+
await sleep(LOGO_REVEAL_FRAME_MS);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (opts.waitForKeypress) {
|
|
55
|
+
const interval = setInterval(() => frame(), LOGO_SHIMMER_FRAME_MS);
|
|
56
|
+
frame();
|
|
57
|
+
try {
|
|
58
|
+
await opts.waitForKeypress();
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
clearInterval(interval);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else if (dwellMs > 0) {
|
|
65
|
+
const start = Date.now();
|
|
66
|
+
let elapsed = 0;
|
|
67
|
+
do {
|
|
68
|
+
frame();
|
|
69
|
+
await sleep(LOGO_SHIMMER_FRAME_MS);
|
|
70
|
+
elapsed = opts.sleep ? elapsed + LOGO_SHIMMER_FRAME_MS : Date.now() - start;
|
|
71
|
+
} while (elapsed < dwellMs);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
frame();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
animator.stop();
|
|
79
|
+
if (opts.fullscreen)
|
|
80
|
+
screen.exit();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text effects for the phren wordmark on the shell splash.
|
|
3
|
+
*
|
|
4
|
+
* Inspired by TerminalTextEffects: the block-letter logo is revealed with a
|
|
5
|
+
* "decrypt" scramble that settles cell by cell into the real glyphs, and the
|
|
6
|
+
* finished wordmark carries a slow light-beam shimmer while the splash holds.
|
|
7
|
+
*
|
|
8
|
+
* Two rules keep the letters intact:
|
|
9
|
+
* - scramble glyphs come only from the same box-drawing / block family the
|
|
10
|
+
* logo already uses, so every cell stays one column wide;
|
|
11
|
+
* - every frame is a pure function of (progress, cell) with hash-based
|
|
12
|
+
* jitter, so the reveal is deterministic and the final frame equals the
|
|
13
|
+
* plain gradient logo exactly.
|
|
14
|
+
*
|
|
15
|
+
* This module is imported by render.ts and must not import from it.
|
|
16
|
+
*/
|
|
17
|
+
export declare const PHREN_LOGO: string[];
|
|
18
|
+
export declare const PHREN_GRADIENT: string[];
|
|
19
|
+
/** Frames in the reveal and the delay between them. ~1s total. */
|
|
20
|
+
export declare const LOGO_REVEAL_FRAMES = 22;
|
|
21
|
+
export declare const LOGO_REVEAL_FRAME_MS = 45;
|
|
22
|
+
export declare const LOGO_SHIMMER_FRAME_MS = 110;
|
|
23
|
+
/** The finished wordmark: identical colours to `gradient(line)` in render.ts. */
|
|
24
|
+
export declare function logoPlain(): string[];
|
|
25
|
+
/**
|
|
26
|
+
* Decrypt reveal at `progress` in [0, 1]. Cells settle left to right with
|
|
27
|
+
* per-cell jitter; a settling cell flashes white for a moment; unsettled
|
|
28
|
+
* cells churn through scramble glyphs. At progress >= 1 this is `logoPlain()`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function logoRevealFrame(progress: number): string[];
|
|
31
|
+
/**
|
|
32
|
+
* A soft beam of light sweeping across the finished wordmark. `tick` is any
|
|
33
|
+
* increasing integer; the sweep loops with a pause between passes.
|
|
34
|
+
*/
|
|
35
|
+
export declare function logoShimmerFrame(tick: number): string[];
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text effects for the phren wordmark on the shell splash.
|
|
3
|
+
*
|
|
4
|
+
* Inspired by TerminalTextEffects: the block-letter logo is revealed with a
|
|
5
|
+
* "decrypt" scramble that settles cell by cell into the real glyphs, and the
|
|
6
|
+
* finished wordmark carries a slow light-beam shimmer while the splash holds.
|
|
7
|
+
*
|
|
8
|
+
* Two rules keep the letters intact:
|
|
9
|
+
* - scramble glyphs come only from the same box-drawing / block family the
|
|
10
|
+
* logo already uses, so every cell stays one column wide;
|
|
11
|
+
* - every frame is a pure function of (progress, cell) with hash-based
|
|
12
|
+
* jitter, so the reveal is deterministic and the final frame equals the
|
|
13
|
+
* plain gradient logo exactly.
|
|
14
|
+
*
|
|
15
|
+
* This module is imported by render.ts and must not import from it.
|
|
16
|
+
*/
|
|
17
|
+
const RESET = "\x1b[0m";
|
|
18
|
+
// Block-letter logo for the splash.
|
|
19
|
+
export const PHREN_LOGO = [
|
|
20
|
+
"██████╗ ██╗ ██╗██████╗ ███████╗███╗ ██╗",
|
|
21
|
+
"██╔══██╗██║ ██║██╔══██╗██╔════╝████╗ ██║",
|
|
22
|
+
"██████╔╝███████║██████╔╝█████╗ ██╔██╗ ██║",
|
|
23
|
+
"██╔═══╝ ██╔══██║██╔══██╗██╔══╝ ██║╚██╗██║",
|
|
24
|
+
"██║ ██║ ██║██║ ██║███████╗██║ ╚████║",
|
|
25
|
+
"╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═══╝",
|
|
26
|
+
];
|
|
27
|
+
// Neural gradient palette: purple → blue → cyan (256-color ANSI)
|
|
28
|
+
export const PHREN_GRADIENT = [
|
|
29
|
+
"\x1b[38;5;93m", // vivid purple
|
|
30
|
+
"\x1b[38;5;99m", // purple-blue
|
|
31
|
+
"\x1b[38;5;105m", // blue-purple
|
|
32
|
+
"\x1b[38;5;111m", // sky blue
|
|
33
|
+
"\x1b[38;5;75m", // dodger blue
|
|
34
|
+
"\x1b[38;5;81m", // cyan-blue
|
|
35
|
+
"\x1b[38;5;87m", // bright cyan
|
|
36
|
+
];
|
|
37
|
+
/** Glyphs the scramble may show: the logo's own alphabet plus shade blocks. All one cell wide. */
|
|
38
|
+
const SCRAMBLE_POOL = [..."░▒▓█▀▄╗╔╝╚║═╬╪╫┼"];
|
|
39
|
+
/** Dim greys the unsettled cells cycle through. */
|
|
40
|
+
const SCRAMBLE_COLORS = ["\x1b[38;5;238m", "\x1b[38;5;240m", "\x1b[38;5;243m", "\x1b[38;5;245m"];
|
|
41
|
+
const FLASH = "\x1b[38;5;231m";
|
|
42
|
+
const SHIMMER = ["\x1b[38;5;123m", "\x1b[38;5;159m", "\x1b[38;5;195m", "\x1b[38;5;159m", "\x1b[38;5;123m"];
|
|
43
|
+
/** Frames in the reveal and the delay between them. ~1s total. */
|
|
44
|
+
export const LOGO_REVEAL_FRAMES = 22;
|
|
45
|
+
export const LOGO_REVEAL_FRAME_MS = 45;
|
|
46
|
+
export const LOGO_SHIMMER_FRAME_MS = 110;
|
|
47
|
+
function hash(a, b, c) {
|
|
48
|
+
let h = 2166136261;
|
|
49
|
+
for (const v of [a, b, c]) {
|
|
50
|
+
h ^= v + 0x9e3779b9;
|
|
51
|
+
h = Math.imul(h, 16777619);
|
|
52
|
+
}
|
|
53
|
+
return (h >>> 0) / 4294967296;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Split a logo line into cells with the same colour assignment `gradient()`
|
|
57
|
+
* in render.ts uses (bucket by position among non-space characters).
|
|
58
|
+
*/
|
|
59
|
+
function cells(line) {
|
|
60
|
+
const chars = [...line];
|
|
61
|
+
const nonSpace = chars.filter((ch) => !/\s/.test(ch)).length;
|
|
62
|
+
let vi = 0;
|
|
63
|
+
return chars.map((ch) => {
|
|
64
|
+
if (/\s/.test(ch))
|
|
65
|
+
return { ch, colorIdx: -1, along: 0 };
|
|
66
|
+
const colorIdx = Math.min(Math.floor((vi * PHREN_GRADIENT.length) / nonSpace), PHREN_GRADIENT.length - 1);
|
|
67
|
+
const along = nonSpace > 1 ? vi / (nonSpace - 1) : 0;
|
|
68
|
+
vi++;
|
|
69
|
+
return { ch, colorIdx, along };
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
const LOGO_CELLS = PHREN_LOGO.map(cells);
|
|
73
|
+
function paint(row, color) {
|
|
74
|
+
let out = "";
|
|
75
|
+
let current = "";
|
|
76
|
+
row.forEach((cell, col) => {
|
|
77
|
+
if (cell.colorIdx < 0) {
|
|
78
|
+
out += cell.ch;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const { ch, sgr } = color(cell, col);
|
|
82
|
+
if (sgr !== current) {
|
|
83
|
+
out += sgr;
|
|
84
|
+
current = sgr;
|
|
85
|
+
}
|
|
86
|
+
out += ch;
|
|
87
|
+
});
|
|
88
|
+
return out + RESET;
|
|
89
|
+
}
|
|
90
|
+
/** The finished wordmark: identical colours to `gradient(line)` in render.ts. */
|
|
91
|
+
export function logoPlain() {
|
|
92
|
+
return LOGO_CELLS.map((row) => paint(row, (cell) => ({ ch: cell.ch, sgr: PHREN_GRADIENT[cell.colorIdx] })));
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Decrypt reveal at `progress` in [0, 1]. Cells settle left to right with
|
|
96
|
+
* per-cell jitter; a settling cell flashes white for a moment; unsettled
|
|
97
|
+
* cells churn through scramble glyphs. At progress >= 1 this is `logoPlain()`.
|
|
98
|
+
*/
|
|
99
|
+
export function logoRevealFrame(progress) {
|
|
100
|
+
const p = Math.max(0, Math.min(1, progress));
|
|
101
|
+
const tick = Math.floor(p * 40);
|
|
102
|
+
return LOGO_CELLS.map((row, r) => paint(row, (cell, c) => {
|
|
103
|
+
const settleAt = cell.along * 0.72 + hash(r, c, 1) * 0.24;
|
|
104
|
+
if (p >= 1 || p >= settleAt + 0.07)
|
|
105
|
+
return { ch: cell.ch, sgr: PHREN_GRADIENT[cell.colorIdx] };
|
|
106
|
+
if (p >= settleAt)
|
|
107
|
+
return { ch: cell.ch, sgr: FLASH };
|
|
108
|
+
const glyph = SCRAMBLE_POOL[Math.floor(hash(r, c, tick) * SCRAMBLE_POOL.length)];
|
|
109
|
+
const shade = SCRAMBLE_COLORS[Math.floor(hash(c, r, tick + 7) * SCRAMBLE_COLORS.length)];
|
|
110
|
+
return { ch: glyph, sgr: shade };
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* A soft beam of light sweeping across the finished wordmark. `tick` is any
|
|
115
|
+
* increasing integer; the sweep loops with a pause between passes.
|
|
116
|
+
*/
|
|
117
|
+
export function logoShimmerFrame(tick) {
|
|
118
|
+
const width = Math.max(...PHREN_LOGO.map((line) => [...line].length));
|
|
119
|
+
const period = width + 26;
|
|
120
|
+
const x = ((tick * 2) % period) - 8;
|
|
121
|
+
return LOGO_CELLS.map((row, r) => paint(row, (cell, c) => {
|
|
122
|
+
// The beam leans like a slash: each row is offset one column.
|
|
123
|
+
const d = c + r - x;
|
|
124
|
+
if (d >= -2 && d <= 2)
|
|
125
|
+
return { ch: cell.ch, sgr: SHIMMER[d + 2] };
|
|
126
|
+
return { ch: cell.ch, sgr: PHREN_GRADIENT[cell.colorIdx] };
|
|
127
|
+
}));
|
|
128
|
+
}
|
package/dist/shell/render.d.ts
CHANGED
|
@@ -72,12 +72,12 @@ export declare function paintFrame(frame: string): void;
|
|
|
72
72
|
* scrolls every later cursor-home repaint lands on shifted rows, stacking the
|
|
73
73
|
* frames on top of each other.
|
|
74
74
|
*/
|
|
75
|
-
export declare function composeStartupFrame(artLines: string[], version: string, hint?: string): string[];
|
|
75
|
+
export declare function composeStartupFrame(artLines: string[], version: string, hint?: string, logo?: string[], tagline?: string): string[];
|
|
76
76
|
/**
|
|
77
77
|
* Clamp a frame to the terminal before painting: truncate each line to the
|
|
78
78
|
* render width, erase whatever the previous frame left to the right of it, and
|
|
79
79
|
* drop rows past the bottom so the frame can never scroll the screen.
|
|
80
80
|
*/
|
|
81
81
|
export declare function fitFrame(lines: string[]): string;
|
|
82
|
-
export declare function shellStartupFrames(version: string): string[];
|
|
82
|
+
export declare function shellStartupFrames(version: string, tagline?: string): string[];
|
|
83
83
|
export {};
|