@phren/cli 0.1.45 → 0.1.46
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/agents/providers/herdr.d.ts +18 -0
- package/dist/agents/providers/herdr.js +94 -0
- package/dist/agents/providers/spawner.d.ts +13 -0
- package/dist/agents/providers/spawner.js +63 -0
- package/dist/agents/registry.d.ts +28 -0
- package/dist/agents/registry.js +82 -0
- package/dist/agents/types.d.ts +51 -0
- package/dist/agents/types.js +42 -0
- package/dist/cli/search.js +29 -0
- package/dist/cli-registry.d.ts +1 -1
- package/dist/cli-registry.js +1 -0
- package/dist/content/learning.js +24 -1
- package/dist/generated/memory-ui-graph.browser.js +69 -69
- package/dist/graph-core/model.js +99 -9
- package/dist/memory-ui-graph.runtime.js +69 -69
- package/dist/phren-art.d.ts +7 -0
- package/dist/phren-art.js +6 -41
- package/dist/shared/lookup-tail.d.ts +35 -0
- package/dist/shared/lookup-tail.js +100 -0
- package/dist/shell/graph/agents.d.ts +48 -0
- package/dist/shell/graph/agents.js +152 -0
- package/dist/shell/graph/controller.d.ts +40 -2
- package/dist/shell/graph/controller.js +149 -12
- package/dist/shell/graph/graph-view.d.ts +7 -0
- package/dist/shell/graph/graph-view.js +227 -50
- package/dist/shell/graph/layout.d.ts +21 -2
- package/dist/shell/graph/layout.js +79 -11
- package/dist/shell/graph/watch.d.ts +71 -0
- package/dist/shell/graph/watch.js +153 -0
- package/dist/shell/input.js +3 -1
- package/dist/shell/render.js +3 -0
- package/dist/shell/shell.d.ts +2 -0
- package/dist/shell/shell.js +9 -4
- package/dist/shell/startup.d.ts +3 -0
- package/dist/shell/startup.js +8 -0
- package/dist/shell/view.js +61 -73
- package/dist/ui/server.js +6 -56
- package/package.json +1 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Watch mode for the terminal graph.
|
|
3
|
+
*
|
|
4
|
+
* Every memory phren lands on — an MCP `search_knowledge` hit, a memory a
|
|
5
|
+
* hook injected before a prompt, a finding just written — is appended to
|
|
6
|
+
* `.runtime/lookup-events.jsonl`. Watch mode tails that log so a graph open
|
|
7
|
+
* in one terminal lights up as an agent works in another: the node pulses,
|
|
8
|
+
* the camera flies to it, and the finding's full text lands in the pane.
|
|
9
|
+
*
|
|
10
|
+
* This module owns the event plumbing only. Drawing lives in graph-view.ts
|
|
11
|
+
* and camera/selection in controller.ts.
|
|
12
|
+
*/
|
|
13
|
+
import { type LookupEvent } from "../../governance/activity.js";
|
|
14
|
+
/** How long a touched node stays lit, in ms. */
|
|
15
|
+
export declare const HEAT_MS = 6000;
|
|
16
|
+
/** Events kept for the activity feed. */
|
|
17
|
+
export declare const ACTIVITY_LIMIT = 60;
|
|
18
|
+
export interface ActivityItem {
|
|
19
|
+
event: LookupEvent;
|
|
20
|
+
/** Wall-clock ms when this arrived; drives heat decay and the feed's age column. */
|
|
21
|
+
seenAt: number;
|
|
22
|
+
/** Graph node this event points at, when resolvable. */
|
|
23
|
+
nodeId?: string;
|
|
24
|
+
/** True for rows loaded as history rather than seen live. */
|
|
25
|
+
historical: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface GraphWatchOptions {
|
|
28
|
+
pollMs?: number;
|
|
29
|
+
/** Injected in tests so no real file or timer is needed. */
|
|
30
|
+
tail?: {
|
|
31
|
+
poll: () => LookupEvent[];
|
|
32
|
+
};
|
|
33
|
+
backfill?: (phrenPath: string, limit: number) => LookupEvent[];
|
|
34
|
+
now?: () => number;
|
|
35
|
+
}
|
|
36
|
+
export declare class GraphWatch {
|
|
37
|
+
readonly phrenPath: string;
|
|
38
|
+
/** Newest first. */
|
|
39
|
+
activity: ActivityItem[];
|
|
40
|
+
private heat;
|
|
41
|
+
private tail;
|
|
42
|
+
private timer;
|
|
43
|
+
private onEvents;
|
|
44
|
+
private readonly pollMs;
|
|
45
|
+
private readonly injectedTail?;
|
|
46
|
+
private readonly backfillFn;
|
|
47
|
+
private readonly now;
|
|
48
|
+
constructor(phrenPath: string, opts?: GraphWatchOptions);
|
|
49
|
+
get running(): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Begin tailing. Recent history is loaded into the feed immediately but is
|
|
52
|
+
* never treated as live: it does not pulse and never moves the camera.
|
|
53
|
+
*/
|
|
54
|
+
start(onEvents: (items: ActivityItem[]) => void): void;
|
|
55
|
+
stop(): void;
|
|
56
|
+
/** Drain the log. Returns the new items, newest last, and lights their nodes. */
|
|
57
|
+
poll(): ActivityItem[];
|
|
58
|
+
/** 1 right after a node was touched, easing to 0 over HEAT_MS. */
|
|
59
|
+
heatOf(nodeId: string): number;
|
|
60
|
+
/** True while any node is still lit, so the host keeps animating. */
|
|
61
|
+
get hot(): boolean;
|
|
62
|
+
clearActivity(): void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The graph node an event points at. Findings carry a precomputed `nodeId`
|
|
66
|
+
* (the same id `buildGraph` assigns); everything else falls back to the
|
|
67
|
+
* project node, whose id is the project name.
|
|
68
|
+
*/
|
|
69
|
+
export declare function targetNodeId(event: LookupEvent): string | undefined;
|
|
70
|
+
/** "just now", "4s", "2m" — the feed's age column. */
|
|
71
|
+
export declare function formatAge(ms: number): string;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Watch mode for the terminal graph.
|
|
3
|
+
*
|
|
4
|
+
* Every memory phren lands on — an MCP `search_knowledge` hit, a memory a
|
|
5
|
+
* hook injected before a prompt, a finding just written — is appended to
|
|
6
|
+
* `.runtime/lookup-events.jsonl`. Watch mode tails that log so a graph open
|
|
7
|
+
* in one terminal lights up as an agent works in another: the node pulses,
|
|
8
|
+
* the camera flies to it, and the finding's full text lands in the pane.
|
|
9
|
+
*
|
|
10
|
+
* This module owns the event plumbing only. Drawing lives in graph-view.ts
|
|
11
|
+
* and camera/selection in controller.ts.
|
|
12
|
+
*/
|
|
13
|
+
import { lookupEventsLogFile } from "../../shared.js";
|
|
14
|
+
import { readRecentLookups } from "../../governance/activity.js";
|
|
15
|
+
import { LookupTail } from "../../shared/lookup-tail.js";
|
|
16
|
+
/** How long a touched node stays lit, in ms. */
|
|
17
|
+
export const HEAT_MS = 6000;
|
|
18
|
+
/** Events kept for the activity feed. */
|
|
19
|
+
export const ACTIVITY_LIMIT = 60;
|
|
20
|
+
const DEFAULT_POLL_MS = 700;
|
|
21
|
+
/** Backfilled rows shown when watch mode starts, so the feed is never empty. */
|
|
22
|
+
const BACKFILL = 12;
|
|
23
|
+
export class GraphWatch {
|
|
24
|
+
phrenPath;
|
|
25
|
+
/** Newest first. */
|
|
26
|
+
activity = [];
|
|
27
|
+
heat = new Map();
|
|
28
|
+
tail = null;
|
|
29
|
+
timer = null;
|
|
30
|
+
onEvents = null;
|
|
31
|
+
pollMs;
|
|
32
|
+
injectedTail;
|
|
33
|
+
backfillFn;
|
|
34
|
+
now;
|
|
35
|
+
constructor(phrenPath, opts = {}) {
|
|
36
|
+
this.phrenPath = phrenPath;
|
|
37
|
+
this.pollMs = opts.pollMs ?? DEFAULT_POLL_MS;
|
|
38
|
+
this.injectedTail = opts.tail;
|
|
39
|
+
this.backfillFn = opts.backfill ?? readRecentLookups;
|
|
40
|
+
this.now = opts.now ?? (() => Date.now());
|
|
41
|
+
}
|
|
42
|
+
get running() {
|
|
43
|
+
return this.tail !== null;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Begin tailing. Recent history is loaded into the feed immediately but is
|
|
47
|
+
* never treated as live: it does not pulse and never moves the camera.
|
|
48
|
+
*/
|
|
49
|
+
start(onEvents) {
|
|
50
|
+
if (this.tail)
|
|
51
|
+
return;
|
|
52
|
+
this.onEvents = onEvents;
|
|
53
|
+
this.tail = this.injectedTail ?? new LookupTail(lookupEventsLogFile(this.phrenPath));
|
|
54
|
+
if (!this.activity.length) {
|
|
55
|
+
try {
|
|
56
|
+
const seenAt = this.now();
|
|
57
|
+
this.activity = this.backfillFn(this.phrenPath, BACKFILL).map((event) => ({
|
|
58
|
+
event,
|
|
59
|
+
seenAt,
|
|
60
|
+
nodeId: targetNodeId(event),
|
|
61
|
+
historical: true,
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
this.activity = [];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (!this.injectedTail) {
|
|
69
|
+
this.timer = setInterval(() => this.poll(), this.pollMs);
|
|
70
|
+
this.timer.unref?.();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
stop() {
|
|
74
|
+
if (this.timer) {
|
|
75
|
+
clearInterval(this.timer);
|
|
76
|
+
this.timer = null;
|
|
77
|
+
}
|
|
78
|
+
this.tail = null;
|
|
79
|
+
this.onEvents = null;
|
|
80
|
+
this.heat.clear();
|
|
81
|
+
}
|
|
82
|
+
/** Drain the log. Returns the new items, newest last, and lights their nodes. */
|
|
83
|
+
poll() {
|
|
84
|
+
if (!this.tail)
|
|
85
|
+
return [];
|
|
86
|
+
let events;
|
|
87
|
+
try {
|
|
88
|
+
events = this.tail.poll();
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
if (!events.length)
|
|
94
|
+
return [];
|
|
95
|
+
const seenAt = this.now();
|
|
96
|
+
const items = events.map((event) => ({ event, seenAt, nodeId: targetNodeId(event), historical: false }));
|
|
97
|
+
for (const item of items) {
|
|
98
|
+
if (item.nodeId)
|
|
99
|
+
this.heat.set(item.nodeId, seenAt);
|
|
100
|
+
}
|
|
101
|
+
this.activity = [...items].reverse().concat(this.activity).slice(0, ACTIVITY_LIMIT);
|
|
102
|
+
this.onEvents?.(items);
|
|
103
|
+
return items;
|
|
104
|
+
}
|
|
105
|
+
/** 1 right after a node was touched, easing to 0 over HEAT_MS. */
|
|
106
|
+
heatOf(nodeId) {
|
|
107
|
+
const at = this.heat.get(nodeId);
|
|
108
|
+
if (at === undefined)
|
|
109
|
+
return 0;
|
|
110
|
+
const age = this.now() - at;
|
|
111
|
+
if (age >= HEAT_MS) {
|
|
112
|
+
this.heat.delete(nodeId);
|
|
113
|
+
return 0;
|
|
114
|
+
}
|
|
115
|
+
return 1 - age / HEAT_MS;
|
|
116
|
+
}
|
|
117
|
+
/** True while any node is still lit, so the host keeps animating. */
|
|
118
|
+
get hot() {
|
|
119
|
+
if (!this.heat.size)
|
|
120
|
+
return false;
|
|
121
|
+
const now = this.now();
|
|
122
|
+
for (const at of this.heat.values()) {
|
|
123
|
+
if (now - at < HEAT_MS)
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
this.heat.clear();
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
clearActivity() {
|
|
130
|
+
this.activity = [];
|
|
131
|
+
this.heat.clear();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* The graph node an event points at. Findings carry a precomputed `nodeId`
|
|
136
|
+
* (the same id `buildGraph` assigns); everything else falls back to the
|
|
137
|
+
* project node, whose id is the project name.
|
|
138
|
+
*/
|
|
139
|
+
export function targetNodeId(event) {
|
|
140
|
+
if (event.nodeId)
|
|
141
|
+
return event.nodeId;
|
|
142
|
+
return event.project || undefined;
|
|
143
|
+
}
|
|
144
|
+
/** "just now", "4s", "2m" — the feed's age column. */
|
|
145
|
+
export function formatAge(ms) {
|
|
146
|
+
if (ms < 1500)
|
|
147
|
+
return "now";
|
|
148
|
+
if (ms < 60_000)
|
|
149
|
+
return `${Math.round(ms / 1000)}s`;
|
|
150
|
+
if (ms < 3_600_000)
|
|
151
|
+
return `${Math.round(ms / 60_000)}m`;
|
|
152
|
+
return `${Math.round(ms / 3_600_000)}h`;
|
|
153
|
+
}
|
package/dist/shell/input.js
CHANGED
|
@@ -807,9 +807,11 @@ export function applyViewShortcut(host, key) {
|
|
|
807
807
|
host.setMessage(` ${TAB_ICONS.Health} Health ${style.dim("(esc to return)")}`);
|
|
808
808
|
return true;
|
|
809
809
|
}
|
|
810
|
+
// No message: the bottom bar already says this, and in the Graph view a
|
|
811
|
+
// spare row is worth more than a reminder.
|
|
810
812
|
if (key === "g") {
|
|
811
813
|
host.setView("Graph");
|
|
812
|
-
host.setMessage(
|
|
814
|
+
host.setMessage("");
|
|
813
815
|
return true;
|
|
814
816
|
}
|
|
815
817
|
return false;
|
package/dist/shell/render.js
CHANGED
|
@@ -250,6 +250,9 @@ export function shellHelpText() {
|
|
|
250
250
|
` ${style.bold("Tasks")} ${k("a")} ${d("add task")} ${k("d")} ${d("toggle active/queue")} ${k("↵")} ${d("mark complete")}`,
|
|
251
251
|
` ${style.bold("Findings")} ${k("a")} ${d("tell phren")} ${k("d")} ${d("delete selected")}`,
|
|
252
252
|
` ${style.bold("Review Queue")} ${k("↵")} ${d("inspect selected item")} ${d("(read-only)")}`,
|
|
253
|
+
` ${style.bold("Graph")} ${k("↑↓←→")} ${d("walk")} ${k("1-9")} ${d("neighbour")} ${k("↵")} ${d("select / focus")} ${k("w")} ${d("watch")}`,
|
|
254
|
+
` ${" ".repeat(13)}${k("/")} ${d("search")} ${k("n N")} ${d("next / prev hit")} ${k("f")} ${d("filter")} ${k("[ ]")} ${d("project")}`,
|
|
255
|
+
` ${" ".repeat(13)}${k("+ -")} ${d("zoom")} ${k("0")} ${d("fit")} ${k("r")} ${d("re-lay out")} ${k("⇧↑↓←→")} ${d("pan")} ${k("o")} ${d("3D viewer")}`,
|
|
253
256
|
` ${style.bold("Skills")} ${k("t")} ${d("toggle enabled")} ${k("d")} ${d("remove")}`,
|
|
254
257
|
"",
|
|
255
258
|
hdr("Palette commands (:cmd)"),
|
package/dist/shell/shell.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export declare class PhrenShell {
|
|
|
26
26
|
private _subsectionsCache;
|
|
27
27
|
private _graph?;
|
|
28
28
|
private repaintHandler;
|
|
29
|
+
/** `--live` / `--no-live`; undefined leaves watch mode at its default. */
|
|
30
|
+
private graphLive?;
|
|
29
31
|
get mode(): "navigate" | "input";
|
|
30
32
|
get inputBuffer(): string;
|
|
31
33
|
get filter(): string | undefined;
|
package/dist/shell/shell.js
CHANGED
|
@@ -42,6 +42,8 @@ export class PhrenShell {
|
|
|
42
42
|
_subsectionsCache = null;
|
|
43
43
|
_graph;
|
|
44
44
|
repaintHandler = null;
|
|
45
|
+
/** `--live` / `--no-live`; undefined leaves watch mode at its default. */
|
|
46
|
+
graphLive;
|
|
45
47
|
get mode() { return this.navMode; }
|
|
46
48
|
get inputBuffer() { return this.inputBuf; }
|
|
47
49
|
get filter() { return this.state.filter; }
|
|
@@ -59,12 +61,15 @@ export class PhrenShell {
|
|
|
59
61
|
// last session happened to leave behind; without one we always land home.
|
|
60
62
|
if (startup.project)
|
|
61
63
|
this.state.project = startup.project;
|
|
64
|
+
this.graphLive = startup.live;
|
|
62
65
|
this.state.view = startup.view ?? "Projects";
|
|
63
66
|
this.message = startup.notice
|
|
64
67
|
? ` ${style.yellow("⚠")} ${startup.notice}`
|
|
65
|
-
: this.state.
|
|
66
|
-
?
|
|
67
|
-
:
|
|
68
|
+
: this.state.view === "Graph"
|
|
69
|
+
? ""
|
|
70
|
+
: this.state.project
|
|
71
|
+
? ` Dashboard ready — active context ${style.boldCyan(this.state.project)}`
|
|
72
|
+
: ` Dashboard ready — choose a project with ${style.boldCyan("↵")} or stay global`;
|
|
68
73
|
}
|
|
69
74
|
close() { this._graph?.dispose(); saveShellState(this.phrenPath, this.state); }
|
|
70
75
|
setMessage(msg) { this.message = msg; }
|
|
@@ -79,7 +84,7 @@ export class PhrenShell {
|
|
|
79
84
|
}
|
|
80
85
|
graph() {
|
|
81
86
|
if (!this._graph) {
|
|
82
|
-
this._graph = new GraphController(this.phrenPath, this.profile);
|
|
87
|
+
this._graph = new GraphController(this.phrenPath, this.profile, { watchEnabled: this.graphLive });
|
|
83
88
|
this._graph.setRepaintHook(this.repaintHandler);
|
|
84
89
|
}
|
|
85
90
|
return this._graph;
|
package/dist/shell/startup.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ import type { ShellView } from "./types.js";
|
|
|
9
9
|
export interface ShellStartup {
|
|
10
10
|
view?: ShellView;
|
|
11
11
|
project?: string;
|
|
12
|
+
/** Graph watch mode. Undefined leaves the default (on). */
|
|
13
|
+
live?: boolean;
|
|
12
14
|
/** Shown on the shell's message line — fullscreen mode eats anything printed before launch. */
|
|
13
15
|
notice?: string;
|
|
14
16
|
}
|
|
@@ -16,6 +18,7 @@ export interface ShellStartupArgs {
|
|
|
16
18
|
view?: string;
|
|
17
19
|
project?: string;
|
|
18
20
|
here?: boolean;
|
|
21
|
+
live?: boolean;
|
|
19
22
|
unknown?: string;
|
|
20
23
|
}
|
|
21
24
|
export declare function normalizeShellView(raw: string | undefined): ShellView | undefined;
|
package/dist/shell/startup.js
CHANGED
|
@@ -62,6 +62,12 @@ export function parseShellArgs(args) {
|
|
|
62
62
|
case "--here":
|
|
63
63
|
parsed.here = true;
|
|
64
64
|
break;
|
|
65
|
+
case "--live":
|
|
66
|
+
parsed.live = true;
|
|
67
|
+
break;
|
|
68
|
+
case "--no-live":
|
|
69
|
+
parsed.live = false;
|
|
70
|
+
break;
|
|
65
71
|
default:
|
|
66
72
|
if (flag.startsWith("-") && parsed.unknown === undefined)
|
|
67
73
|
parsed.unknown = flag;
|
|
@@ -77,6 +83,8 @@ export function parseShellArgs(args) {
|
|
|
77
83
|
export function resolveShellStartup(parsed, opts) {
|
|
78
84
|
const warnings = [];
|
|
79
85
|
const startup = {};
|
|
86
|
+
if (parsed.live !== undefined)
|
|
87
|
+
startup.live = parsed.live;
|
|
80
88
|
if (parsed.unknown)
|
|
81
89
|
warnings.push(`Unknown flag ${parsed.unknown} — ignored.`);
|
|
82
90
|
if (parsed.view) {
|
package/dist/shell/view.js
CHANGED
|
@@ -6,7 +6,7 @@ import * as fs from "fs";
|
|
|
6
6
|
import * as path from "path";
|
|
7
7
|
import { canonicalTaskFilePath, listProjectCards, readTasks, readFindings, readReviewQueue, readRuntimeHealth, resolveTaskFilePath, } from "../data/access.js";
|
|
8
8
|
import { getNonPrimaryStores } from "../store-registry.js";
|
|
9
|
-
import { style, badge, separator, stripAnsi, truncateLine, renderWidth, wrapSegments, lineViewport, shellHelpText, gradient, } from "./render.js";
|
|
9
|
+
import { style, badge, separator, stripAnsi, truncateLine, displayWidth, renderWidth, wrapSegments, lineViewport, shellHelpText, gradient, } from "./render.js";
|
|
10
10
|
import { formatSelectableLine, viewportWithStatus, } from "./view-list.js";
|
|
11
11
|
import { SUB_VIEWS, TAB_ICONS, } from "./types.js";
|
|
12
12
|
import { tasksByFilter, queueByFilter, } from "./palette.js";
|
|
@@ -16,7 +16,7 @@ import { isProjectHookEnabled, readProjectConfig } from "../project-config.js";
|
|
|
16
16
|
import { getScopedSkills } from "../skill/registry.js";
|
|
17
17
|
import { errorMessage } from "../utils.js";
|
|
18
18
|
import { logger } from "../logger.js";
|
|
19
|
-
import { renderGraphView } from "./graph/graph-view.js";
|
|
19
|
+
import { renderGraphView, graphSummary } from "./graph/graph-view.js";
|
|
20
20
|
/** Resolve which store (primary or team) contains a project */
|
|
21
21
|
function resolveProjectStorePath(phrenPath, project) {
|
|
22
22
|
if (fs.existsSync(path.join(phrenPath, project)))
|
|
@@ -31,38 +31,35 @@ function resolveProjectStorePath(phrenPath, project) {
|
|
|
31
31
|
return phrenPath;
|
|
32
32
|
}
|
|
33
33
|
// ── Tab bar ────────────────────────────────────────────────────────────────
|
|
34
|
-
|
|
34
|
+
/**
|
|
35
|
+
* The whole top of the frame in as few rows as possible: brand, current view,
|
|
36
|
+
* project and filter on one line, then a rule. On a 24-row terminal the old
|
|
37
|
+
* three-row header cost more than a tenth of the screen.
|
|
38
|
+
*/
|
|
39
|
+
function renderTopBar(state, summary = "") {
|
|
35
40
|
const cols = renderWidth();
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
});
|
|
59
|
-
const segments = projectTag ? [projectTag, ...tabs] : tabs;
|
|
60
|
-
const tabLine = wrapSegments(segments, cols, {
|
|
61
|
-
indent: " ",
|
|
62
|
-
maxLines: 2,
|
|
63
|
-
separator: style.dim("│"),
|
|
64
|
-
});
|
|
65
|
-
return `${tabLine}\n${separator(cols)}`;
|
|
41
|
+
const brand = gradient("◆ phren");
|
|
42
|
+
const dot = style.dim("·");
|
|
43
|
+
const project = state.project ? `${dot} ${style.cyan(state.project)}` : "";
|
|
44
|
+
const filter = state.filter ? `${dot} ${style.yellow("/" + state.filter)}` : "";
|
|
45
|
+
const isSub = SUB_VIEWS.includes(state.view);
|
|
46
|
+
if (!isSub) {
|
|
47
|
+
const label = style.boldMagenta(`${TAB_ICONS[state.view] ?? "◆"} ${state.view}`);
|
|
48
|
+
const line = [" " + brand, label, project, filter, summary ? `${dot} ${summary}` : ""].filter(Boolean).join(" ");
|
|
49
|
+
return `${truncateLine(line, cols)}\n${separator(cols)}`;
|
|
50
|
+
}
|
|
51
|
+
// Sub-views carry a tab strip. Try full labels, then icons for the inactive
|
|
52
|
+
// tabs, before giving up and taking a second row.
|
|
53
|
+
const head = ` ${brand}${project ? ` ${project}` : ""}${filter ? ` ${filter}` : ""}`;
|
|
54
|
+
const full = SUB_VIEWS.map((v) => (v === state.view ? style.boldMagenta(`${TAB_ICONS[v]} ${v}`) : style.dim(`${TAB_ICONS[v]} ${v}`)));
|
|
55
|
+
const terse = SUB_VIEWS.map((v) => (v === state.view ? style.boldMagenta(`${TAB_ICONS[v]} ${v}`) : style.dim(TAB_ICONS[v] ?? "")));
|
|
56
|
+
for (const tabs of [full, terse]) {
|
|
57
|
+
const merged = `${head} ${style.dim("│")} ${tabs.join(style.dim(" │ "))}`;
|
|
58
|
+
if (displayWidth(merged) <= cols)
|
|
59
|
+
return `${merged}\n${separator(cols)}`;
|
|
60
|
+
}
|
|
61
|
+
const tabLine = wrapSegments(full, cols, { indent: " ", maxLines: 2, separator: style.dim("│") });
|
|
62
|
+
return `${head}\n${tabLine}\n${separator(cols)}`;
|
|
66
63
|
}
|
|
67
64
|
// ── Bottom bar ─────────────────────────────────────────────────────────────
|
|
68
65
|
function renderBottomBar(state, navMode, inputCtx, inputBuf) {
|
|
@@ -83,42 +80,38 @@ function renderBottomBar(state, navMode, inputCtx, inputBuf) {
|
|
|
83
80
|
const label = labels[inputCtx] || inputCtx;
|
|
84
81
|
return `${sep}\n ${style.boldCyan(label + " ›")} ${inputBuf}${style.cyan("█")}`;
|
|
85
82
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
"
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
83
|
+
// Only what you reach for constantly. Everything else is one `?` away, so
|
|
84
|
+
// the bar never costs more than a single row.
|
|
85
|
+
const essentials = {
|
|
86
|
+
Projects: [`${k("↑↓")} ${d("move")}`, `${k("↵")} ${d("open")}`],
|
|
87
|
+
Tasks: [`${k("↑↓")} ${d("move")}`, `${k("a")} ${d("add")}`, `${k("↵")} ${d("done")}`],
|
|
88
|
+
Findings: [`${k("↑↓")} ${d("move")}`, `${k("a")} ${d("add")}`],
|
|
89
|
+
"Review Queue": [`${k("↑↓")} ${d("move")}`, `${k("↵")} ${d("inspect")}`],
|
|
90
|
+
Skills: [`${k("↑↓")} ${d("move")}`, `${k("t")} ${d("toggle")}`],
|
|
91
|
+
Hooks: [`${k("↑↓")} ${d("move")}`, `${k("a")} ${d("enable")}`],
|
|
92
|
+
Health: [`${k("↑↓")} ${d("scroll")}`],
|
|
93
|
+
Graph: [`${k("↑↓←→")} ${d("walk")}`, `${k("↵")} ${d("select")}`, `${k("w")} ${d("watch")}`, `${k("a")} ${d("agents")}`],
|
|
95
94
|
};
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const hints = [...nav, ...extra, ...tail];
|
|
109
|
-
return `${sep}\n${wrapSegments(hints, cols, {
|
|
110
|
-
indent: " ",
|
|
111
|
-
maxLines: 3,
|
|
112
|
-
separator: dot,
|
|
113
|
-
})}`;
|
|
95
|
+
const search = state.view === "Graph" ? `${k("/")} ${d("search")}` : `${k("/")} ${d("filter")}`;
|
|
96
|
+
// `? keys` and `q quit` are the two you cannot afford to lose, so a narrow
|
|
97
|
+
// terminal drops view hints off the end instead of truncating those away.
|
|
98
|
+
const always = [`${k("?")} ${d("keys")}`, `${k("q")} ${d("quit")}`];
|
|
99
|
+
const optional = [...(essentials[state.view] ?? []), search];
|
|
100
|
+
let line = "";
|
|
101
|
+
for (let take = optional.length; take >= 0; take--) {
|
|
102
|
+
line = wrapSegments([...optional.slice(0, take), ...always], cols, { indent: " ", maxLines: 1, separator: dot });
|
|
103
|
+
if (!stripAnsi(line).trimEnd().endsWith("…"))
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
return `${sep}\n${line}`;
|
|
114
107
|
}
|
|
115
108
|
// ── Content height ─────────────────────────────────────────────────────────
|
|
116
109
|
function countRenderedLines(block) {
|
|
117
110
|
return block.split("\n").length;
|
|
118
111
|
}
|
|
119
|
-
function contentHeight(
|
|
112
|
+
function contentHeight(topBar, bottomBar, hasMessage) {
|
|
120
113
|
const rows = process.stdout.rows || 24;
|
|
121
|
-
const reserved =
|
|
114
|
+
const reserved = countRenderedLines(topBar) + countRenderedLines(bottomBar) + (hasMessage ? 1 : 0);
|
|
122
115
|
return Math.max(4, rows - reserved);
|
|
123
116
|
}
|
|
124
117
|
function collectProjectDashboardEntries(ctx) {
|
|
@@ -672,17 +665,13 @@ function renderHealthView(phrenPath, doctor, cursor, height, currentScroll, setS
|
|
|
672
665
|
}
|
|
673
666
|
// ── Main render ────────────────────────────────────────────────────────────
|
|
674
667
|
export async function renderShell(ctx, navMode, inputCtx, inputBuf, showHelp, message, doctorSnapshot, subsectionsCache, setHealthLineCount, setSubsectionsCache) {
|
|
675
|
-
const
|
|
676
|
-
|
|
677
|
-
: "";
|
|
678
|
-
const filterLabel = ctx.state.filter
|
|
679
|
-
? ` ${style.dim("·")} ${style.yellow("/" + ctx.state.filter)}`
|
|
680
|
-
: "";
|
|
681
|
-
const header = ` ${gradient("◆ phren")}${projectLabel}${filterLabel}`;
|
|
682
|
-
const tabBar = renderTabBar(ctx.state);
|
|
668
|
+
const graphSummaryLine = ctx.state.view === "Graph" && ctx.graph ? graphSummary(ctx.graph()) : "";
|
|
669
|
+
const topBar = renderTopBar(ctx.state, graphSummaryLine);
|
|
683
670
|
const bottomBar = renderBottomBar(ctx.state, navMode, inputCtx, inputBuf);
|
|
684
671
|
const cursor = ctx.currentCursor();
|
|
685
|
-
|
|
672
|
+
// An empty message line used to hold a row open on every frame.
|
|
673
|
+
const hasMessage = Boolean(stripAnsi(message).trim());
|
|
674
|
+
const height = contentHeight(topBar, bottomBar, hasMessage);
|
|
686
675
|
let contentLines;
|
|
687
676
|
if (showHelp) {
|
|
688
677
|
contentLines = shellHelpText().split("\n");
|
|
@@ -737,9 +726,8 @@ export async function renderShell(ctx, navMode, inputCtx, inputBuf, showHelp, me
|
|
|
737
726
|
const displayed = contentLines.slice(0, height);
|
|
738
727
|
while (displayed.length < height)
|
|
739
728
|
displayed.push("");
|
|
740
|
-
const msgLine = ` ${style.dimItalic(stripAnsi(message).trimStart() ? message : "")}`;
|
|
741
729
|
const cols = renderWidth();
|
|
742
|
-
const parts = [
|
|
730
|
+
const parts = [topBar, ...displayed, ...(hasMessage ? [` ${style.dimItalic(message.trimStart())}`] : []), bottomBar];
|
|
743
731
|
return parts.map(line => {
|
|
744
732
|
if (line.includes("\n")) {
|
|
745
733
|
return line.split("\n").map(sub => truncateLine(sub, cols) + "\x1b[K").join("\n");
|
package/dist/ui/server.js
CHANGED
|
@@ -13,6 +13,7 @@ import { isValidProjectName, errorMessage, safeProjectPath } from "../utils.js";
|
|
|
13
13
|
import { readInstallPreferences, writeInstallPreferences, writeGovernanceInstallPreferences } from "../init/preferences.js";
|
|
14
14
|
import { buildGraph, collectProjectsForUI, collectSkillsForUI, getHooksData, isAllowedHookConfigPath, isAllowedSkillPath, readSyncSnapshot, recentAccepted, recentLookups, recentUsage, } from "./data.js";
|
|
15
15
|
import { lookupEventsLogFile } from "../shared.js";
|
|
16
|
+
import { LookupTail } from "../shared/lookup-tail.js";
|
|
16
17
|
import { CONSOLIDATION_ENTRY_THRESHOLD } from "../content/validate.js";
|
|
17
18
|
import { ensureTopicReferenceDoc, getProjectTopicsResponse, listProjectReferenceDocs, pinProjectTopicSuggestion, readReferenceContent, reclassifyLegacyTopicDocs, unpinProjectTopicSuggestion, writeProjectTopics, } from "../project-topics.js";
|
|
18
19
|
import { getWorkflowPolicy, updateWorkflowPolicy, updateRetentionPolicy, mergeConfig, getRetentionPolicy, getProjectConfigOverrides, getIndexPolicy, updateIndexPolicy, VALID_TASK_MODES } from "../governance/policy.js";
|
|
@@ -398,63 +399,12 @@ function handleLookupStream(req, res, ctx) {
|
|
|
398
399
|
"X-Accel-Buffering": "no",
|
|
399
400
|
});
|
|
400
401
|
res.write("retry: 3000\n\n");
|
|
401
|
-
|
|
402
|
-
//
|
|
403
|
-
|
|
404
|
-
let offset = 0;
|
|
405
|
-
try {
|
|
406
|
-
offset = fs.existsSync(logPath) ? fs.statSync(logPath).size : 0;
|
|
407
|
-
}
|
|
408
|
-
catch {
|
|
409
|
-
offset = 0;
|
|
410
|
-
}
|
|
411
|
-
let carry = "";
|
|
402
|
+
// Only stream events appended after the client connects; the initial
|
|
403
|
+
// snapshot comes from /api/lookups.
|
|
404
|
+
const tail = new LookupTail(lookupEventsLogFile(ctx.phrenPath));
|
|
412
405
|
const flushNew = () => {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
if (!fs.existsSync(logPath))
|
|
416
|
-
return;
|
|
417
|
-
size = fs.statSync(logPath).size;
|
|
418
|
-
}
|
|
419
|
-
catch {
|
|
420
|
-
return;
|
|
421
|
-
}
|
|
422
|
-
if (size < offset) {
|
|
423
|
-
offset = 0;
|
|
424
|
-
carry = "";
|
|
425
|
-
} // file rotated/truncated
|
|
426
|
-
if (size <= offset)
|
|
427
|
-
return;
|
|
428
|
-
let chunk = "";
|
|
429
|
-
try {
|
|
430
|
-
const fd = fs.openSync(logPath, "r");
|
|
431
|
-
try {
|
|
432
|
-
const buf = Buffer.alloc(size - offset);
|
|
433
|
-
fs.readSync(fd, buf, 0, buf.length, offset);
|
|
434
|
-
chunk = buf.toString("utf8");
|
|
435
|
-
}
|
|
436
|
-
finally {
|
|
437
|
-
fs.closeSync(fd);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
catch {
|
|
441
|
-
return;
|
|
442
|
-
}
|
|
443
|
-
offset = size;
|
|
444
|
-
const lines = (carry + chunk).split("\n");
|
|
445
|
-
carry = lines.pop() ?? "";
|
|
446
|
-
for (const line of lines) {
|
|
447
|
-
const trimmed = line.trim();
|
|
448
|
-
if (!trimmed)
|
|
449
|
-
continue;
|
|
450
|
-
try {
|
|
451
|
-
JSON.parse(trimmed); // validate before forwarding
|
|
452
|
-
res.write(`data: ${trimmed}\n\n`);
|
|
453
|
-
}
|
|
454
|
-
catch {
|
|
455
|
-
// skip malformed lines
|
|
456
|
-
}
|
|
457
|
-
}
|
|
406
|
+
for (const line of tail.pollLines())
|
|
407
|
+
res.write(`data: ${line}\n\n`);
|
|
458
408
|
};
|
|
459
409
|
const pollTimer = setInterval(flushNew, 1000);
|
|
460
410
|
const heartbeat = setInterval(() => {
|