@phren/cli 0.1.42 → 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/capabilities/cli.js +1 -1
- package/dist/capabilities/mcp.js +1 -1
- package/dist/capabilities/vscode.js +3 -3
- package/dist/capabilities/web-ui.js +29 -29
- 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-output.js +15 -6
- package/dist/cli/hooks.d.ts +1 -1
- package/dist/cli/hooks.js +16 -5
- 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/governance/scores.d.ts +9 -1
- package/dist/governance/scores.js +12 -1
- 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 +13 -3
- 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.d.ts +2 -0
- package/dist/profile-store.js +16 -19
- package/dist/project-config.js +2 -1
- package/dist/shared/fragment-graph.js +7 -2
- package/dist/shared/index.js +1 -1
- package/dist/shared/retrieval.d.ts +38 -0
- package/dist/shared/retrieval.js +62 -4
- package/dist/shell/entry.d.ts +10 -2
- package/dist/shell/entry.js +128 -97
- 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 +4 -1
- package/dist/shell/input.js +28 -5
- package/dist/shell/intro.d.ts +37 -0
- package/dist/shell/intro.js +82 -0
- package/dist/shell/keys.d.ts +36 -0
- package/dist/shell/keys.js +107 -0
- package/dist/shell/logo-fx.d.ts +35 -0
- package/dist/shell/logo-fx.js +128 -0
- package/dist/shell/render.d.ts +34 -1
- package/dist/shell/render.js +220 -66
- package/dist/shell/shell.d.ts +13 -1
- package/dist/shell/shell.js +61 -10
- 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 +26 -4
- package/dist/store-registry.d.ts +13 -0
- package/dist/store-registry.js +109 -37
- 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/tools/memory.js +12 -5
- package/dist/tools/ops.js +1 -1
- 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 +38 -7
- package/starter/global/skills/phren-consolidate/SKILL.md +152 -0
- package/starter/global/skills/phren-discover/SKILL.md +175 -0
- package/starter/global/skills/phren-init/SKILL.md +216 -0
- package/starter/global/skills/phren-profiles/SKILL.md +121 -0
- package/starter/global/skills/phren-sync/SKILL.md +261 -0
- package/dist/init-uninstall.d.ts +0 -3
- package/dist/init-uninstall.js +0 -514
- package/dist/init-walkthrough.d.ts +0 -55
- package/dist/init-walkthrough.js +0 -524
|
@@ -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[];
|
|
@@ -53,5 +56,5 @@ export declare function getListItems(phrenPath: string, profile: string, state:
|
|
|
53
56
|
* Returns true if the key was handled.
|
|
54
57
|
*/
|
|
55
58
|
export declare function applyViewShortcut(host: NavigationHost, key: string): boolean;
|
|
56
|
-
export declare function handleNavigateKey(host: NavigationHost,
|
|
59
|
+
export declare function handleNavigateKey(host: NavigationHost, rawKey: string): Promise<boolean>;
|
|
57
60
|
export {};
|
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,10 +807,25 @@ 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 ─────────────────────────────────────────────────
|
|
805
|
-
export async function handleNavigateKey(host,
|
|
818
|
+
export async function handleNavigateKey(host, rawKey) {
|
|
819
|
+
// Terminals in application-cursor mode send SS3 (ESC O A) instead of CSI
|
|
820
|
+
// (ESC [ A) for the arrow keys; normalise so both spellings navigate.
|
|
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
|
+
}
|
|
806
829
|
if (key === "\x1b[A") {
|
|
807
830
|
host.moveCursor(-1);
|
|
808
831
|
showCursorPosition(host);
|
|
@@ -914,7 +937,7 @@ export async function handleNavigateKey(host, key) {
|
|
|
914
937
|
}
|
|
915
938
|
// ── Tab switching ─────────────────────────────────────────────────────────────
|
|
916
939
|
function nextTab(host) {
|
|
917
|
-
if (host.state.view === "Projects" || host.state.view === "Health")
|
|
940
|
+
if (host.state.view === "Projects" || host.state.view === "Health" || host.state.view === "Graph")
|
|
918
941
|
return;
|
|
919
942
|
const idx = SUB_VIEWS.indexOf(host.state.view);
|
|
920
943
|
const next = SUB_VIEWS[(idx + 1) % SUB_VIEWS.length];
|
|
@@ -924,7 +947,7 @@ function nextTab(host) {
|
|
|
924
947
|
}
|
|
925
948
|
}
|
|
926
949
|
function prevTab(host) {
|
|
927
|
-
if (host.state.view === "Projects" || host.state.view === "Health")
|
|
950
|
+
if (host.state.view === "Projects" || host.state.view === "Health" || host.state.view === "Graph")
|
|
928
951
|
return;
|
|
929
952
|
const idx = SUB_VIEWS.indexOf(host.state.view);
|
|
930
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,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raw-mode stdin decoder.
|
|
3
|
+
*
|
|
4
|
+
* Node hands us whatever bytes happened to arrive in one read, not one keypress.
|
|
5
|
+
* Key autorepeat, fast typing, mouse-wheel-as-arrows, and paste all coalesce
|
|
6
|
+
* several keys into a single "data" chunk (e.g. "\x1b[B\x1b[B\x1b[B" or "ub"),
|
|
7
|
+
* and any handler that compares the whole chunk against a single key drops
|
|
8
|
+
* everything but an exact match. This splits a chunk back into discrete keys.
|
|
9
|
+
*
|
|
10
|
+
* A chunk can also end mid-sequence, so trailing partial escapes are buffered
|
|
11
|
+
* and prepended to the next chunk. A lone ESC is indistinguishable from the
|
|
12
|
+
* start of a split sequence, so the caller flushes on a short timer (see
|
|
13
|
+
* ESC_FLUSH_MS) to keep the Escape key responsive.
|
|
14
|
+
*/
|
|
15
|
+
/** How long to wait for the rest of an escape sequence before treating ESC as the Escape key. */
|
|
16
|
+
export declare const ESC_FLUSH_MS = 30;
|
|
17
|
+
/**
|
|
18
|
+
* Split `buf` into discrete keys.
|
|
19
|
+
*
|
|
20
|
+
* Returns the decoded keys plus any trailing bytes that form an incomplete
|
|
21
|
+
* escape sequence; the caller must prepend `pending` to the next chunk.
|
|
22
|
+
*/
|
|
23
|
+
export declare function decodeKeys(buf: string): {
|
|
24
|
+
keys: string[];
|
|
25
|
+
pending: string;
|
|
26
|
+
};
|
|
27
|
+
/** Stateful wrapper that carries incomplete sequences across chunk boundaries. */
|
|
28
|
+
export declare class KeyDecoder {
|
|
29
|
+
private pending;
|
|
30
|
+
/** Decode a stdin chunk into discrete keys. */
|
|
31
|
+
push(chunk: string): string[];
|
|
32
|
+
/** True when a partial sequence is buffered and a flush timer should be armed. */
|
|
33
|
+
hasPending(): boolean;
|
|
34
|
+
/** Emit buffered bytes as literal keys — call when no continuation arrived in time. */
|
|
35
|
+
flush(): string[];
|
|
36
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raw-mode stdin decoder.
|
|
3
|
+
*
|
|
4
|
+
* Node hands us whatever bytes happened to arrive in one read, not one keypress.
|
|
5
|
+
* Key autorepeat, fast typing, mouse-wheel-as-arrows, and paste all coalesce
|
|
6
|
+
* several keys into a single "data" chunk (e.g. "\x1b[B\x1b[B\x1b[B" or "ub"),
|
|
7
|
+
* and any handler that compares the whole chunk against a single key drops
|
|
8
|
+
* everything but an exact match. This splits a chunk back into discrete keys.
|
|
9
|
+
*
|
|
10
|
+
* A chunk can also end mid-sequence, so trailing partial escapes are buffered
|
|
11
|
+
* and prepended to the next chunk. A lone ESC is indistinguishable from the
|
|
12
|
+
* start of a split sequence, so the caller flushes on a short timer (see
|
|
13
|
+
* ESC_FLUSH_MS) to keep the Escape key responsive.
|
|
14
|
+
*/
|
|
15
|
+
/** How long to wait for the rest of an escape sequence before treating ESC as the Escape key. */
|
|
16
|
+
export const ESC_FLUSH_MS = 30;
|
|
17
|
+
const ESC = "\x1b";
|
|
18
|
+
// One code point plus any trailing combining marks / variation selectors, so a
|
|
19
|
+
// surrogate pair or accented character is never split down the middle.
|
|
20
|
+
const GRAPHEME = /^(?:\P{M}\p{M}*)/u;
|
|
21
|
+
function nextChar(buf, i) {
|
|
22
|
+
const m = GRAPHEME.exec(buf.slice(i));
|
|
23
|
+
return m ? m[0] : buf[i];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Split `buf` into discrete keys.
|
|
27
|
+
*
|
|
28
|
+
* Returns the decoded keys plus any trailing bytes that form an incomplete
|
|
29
|
+
* escape sequence; the caller must prepend `pending` to the next chunk.
|
|
30
|
+
*/
|
|
31
|
+
export function decodeKeys(buf) {
|
|
32
|
+
const keys = [];
|
|
33
|
+
let i = 0;
|
|
34
|
+
while (i < buf.length) {
|
|
35
|
+
const ch = buf[i];
|
|
36
|
+
if (ch !== ESC) {
|
|
37
|
+
const char = nextChar(buf, i);
|
|
38
|
+
keys.push(char);
|
|
39
|
+
i += char.length;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
// ESC is the last byte we have — could be the Escape key or a split sequence.
|
|
43
|
+
if (i + 1 >= buf.length)
|
|
44
|
+
return { keys, pending: buf.slice(i) };
|
|
45
|
+
const next = buf[i + 1];
|
|
46
|
+
// ESC ESC — the first is a complete Escape keypress.
|
|
47
|
+
if (next === ESC) {
|
|
48
|
+
keys.push(ESC);
|
|
49
|
+
i += 1;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
// CSI: ESC [ params intermediates final
|
|
53
|
+
if (next === "[") {
|
|
54
|
+
let j = i + 2;
|
|
55
|
+
while (j < buf.length && buf[j] >= "\x30" && buf[j] <= "\x3f")
|
|
56
|
+
j++;
|
|
57
|
+
while (j < buf.length && buf[j] >= "\x20" && buf[j] <= "\x2f")
|
|
58
|
+
j++;
|
|
59
|
+
if (j >= buf.length)
|
|
60
|
+
return { keys, pending: buf.slice(i) };
|
|
61
|
+
if (buf[j] >= "\x40" && buf[j] <= "\x7e") {
|
|
62
|
+
keys.push(buf.slice(i, j + 1));
|
|
63
|
+
i = j + 1;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
// Malformed — drop the ESC [ introducer and resync on the next byte.
|
|
67
|
+
i += 2;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
// SS3: ESC O <final> — arrows in application cursor mode, F1-F4.
|
|
71
|
+
if (next === "O") {
|
|
72
|
+
if (i + 2 >= buf.length)
|
|
73
|
+
return { keys, pending: buf.slice(i) };
|
|
74
|
+
keys.push(buf.slice(i, i + 3));
|
|
75
|
+
i += 3;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
// ESC followed by a printable character. The shell binds no Alt combos, so
|
|
79
|
+
// emitting them separately recovers both keys (Esc-then-shortcut is common)
|
|
80
|
+
// instead of dropping an unrecognised two-character token.
|
|
81
|
+
keys.push(ESC);
|
|
82
|
+
i += 1;
|
|
83
|
+
}
|
|
84
|
+
return { keys, pending: "" };
|
|
85
|
+
}
|
|
86
|
+
/** Stateful wrapper that carries incomplete sequences across chunk boundaries. */
|
|
87
|
+
export class KeyDecoder {
|
|
88
|
+
pending = "";
|
|
89
|
+
/** Decode a stdin chunk into discrete keys. */
|
|
90
|
+
push(chunk) {
|
|
91
|
+
const { keys, pending } = decodeKeys(this.pending + chunk);
|
|
92
|
+
this.pending = pending;
|
|
93
|
+
return keys;
|
|
94
|
+
}
|
|
95
|
+
/** True when a partial sequence is buffered and a flush timer should be armed. */
|
|
96
|
+
hasPending() { return this.pending.length > 0; }
|
|
97
|
+
/** Emit buffered bytes as literal keys — call when no continuation arrived in time. */
|
|
98
|
+
flush() {
|
|
99
|
+
if (!this.pending)
|
|
100
|
+
return [];
|
|
101
|
+
const buffered = this.pending;
|
|
102
|
+
this.pending = "";
|
|
103
|
+
// A lone ESC is the Escape key; anything longer is a sequence the terminal
|
|
104
|
+
// truncated, so surface it whole and let the handler ignore it.
|
|
105
|
+
return buffered === ESC ? [ESC] : [buffered];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -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[];
|