@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,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agents running in a Herdr workspace.
|
|
3
|
+
*
|
|
4
|
+
* `herdr agent list` prints one JSON envelope describing every agent pane —
|
|
5
|
+
* which agent, what it is doing, which directory, and whether it is focused —
|
|
6
|
+
* and answers in a few milliseconds, so it is cheap enough to poll.
|
|
7
|
+
*
|
|
8
|
+
* Nothing Herdr-specific may leak past this file: the rest of phren only ever
|
|
9
|
+
* sees `AgentRecord`.
|
|
10
|
+
*/
|
|
11
|
+
import type { AgentProvider, AgentRecord } from "../types.js";
|
|
12
|
+
/** Injected so tests never shell out. */
|
|
13
|
+
export type CommandExistsFn = (cmd: string) => boolean;
|
|
14
|
+
export type RunJsonFn = (argv: string[], timeoutMs: number) => unknown | null;
|
|
15
|
+
export declare function runHerdrJson(argv: string[], timeoutMs: number): unknown | null;
|
|
16
|
+
/** Pull the agent array out of Herdr's envelope, tolerating shape drift. */
|
|
17
|
+
export declare function parseHerdrAgents(payload: unknown): AgentRecord[];
|
|
18
|
+
export declare function createHerdrProvider(commandExists: CommandExistsFn, runJson?: RunJsonFn): AgentProvider;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agents running in a Herdr workspace.
|
|
3
|
+
*
|
|
4
|
+
* `herdr agent list` prints one JSON envelope describing every agent pane —
|
|
5
|
+
* which agent, what it is doing, which directory, and whether it is focused —
|
|
6
|
+
* and answers in a few milliseconds, so it is cheap enough to poll.
|
|
7
|
+
*
|
|
8
|
+
* Nothing Herdr-specific may leak past this file: the rest of phren only ever
|
|
9
|
+
* sees `AgentRecord`.
|
|
10
|
+
*/
|
|
11
|
+
import { execFileSync } from "child_process";
|
|
12
|
+
import { clampInt, resolveExecCommand } from "../../utils-helpers.js";
|
|
13
|
+
import { debugLog } from "../../shared.js";
|
|
14
|
+
import { errorMessage } from "../../utils.js";
|
|
15
|
+
/** Herdr's vocabulary for what an agent is doing, mapped onto phren's. */
|
|
16
|
+
function toStatus(raw) {
|
|
17
|
+
switch (String(raw ?? "").toLowerCase()) {
|
|
18
|
+
case "working":
|
|
19
|
+
case "running":
|
|
20
|
+
case "busy":
|
|
21
|
+
return "working";
|
|
22
|
+
case "done":
|
|
23
|
+
case "complete":
|
|
24
|
+
case "completed":
|
|
25
|
+
return "done";
|
|
26
|
+
case "error":
|
|
27
|
+
case "failed":
|
|
28
|
+
return "error";
|
|
29
|
+
default:
|
|
30
|
+
return "idle";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function runHerdrJson(argv, timeoutMs) {
|
|
34
|
+
try {
|
|
35
|
+
const exec = resolveExecCommand("herdr");
|
|
36
|
+
const out = execFileSync(exec.command, argv, {
|
|
37
|
+
encoding: "utf8",
|
|
38
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
39
|
+
shell: exec.shell,
|
|
40
|
+
timeout: timeoutMs,
|
|
41
|
+
maxBuffer: 2 * 1024 * 1024,
|
|
42
|
+
}).trim();
|
|
43
|
+
if (!out)
|
|
44
|
+
return null;
|
|
45
|
+
return JSON.parse(out);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
debugLog(`herdr provider: ${errorMessage(err)}`);
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** Pull the agent array out of Herdr's envelope, tolerating shape drift. */
|
|
53
|
+
export function parseHerdrAgents(payload) {
|
|
54
|
+
if (typeof payload !== "object" || payload === null)
|
|
55
|
+
return [];
|
|
56
|
+
const result = payload.result;
|
|
57
|
+
const agents = typeof result === "object" && result !== null ? result.agents : undefined;
|
|
58
|
+
if (!Array.isArray(agents))
|
|
59
|
+
return [];
|
|
60
|
+
const out = [];
|
|
61
|
+
for (const entry of agents) {
|
|
62
|
+
if (typeof entry !== "object" || entry === null)
|
|
63
|
+
continue;
|
|
64
|
+
const a = entry;
|
|
65
|
+
const cwd = typeof a.foreground_cwd === "string" && a.foreground_cwd ? a.foreground_cwd : a.cwd;
|
|
66
|
+
const paneId = a.pane_id;
|
|
67
|
+
if (typeof cwd !== "string" || !cwd || typeof paneId !== "string" || !paneId)
|
|
68
|
+
continue;
|
|
69
|
+
const title = typeof a.terminal_title_stripped === "string" && a.terminal_title_stripped
|
|
70
|
+
? a.terminal_title_stripped
|
|
71
|
+
: typeof a.terminal_title === "string" ? a.terminal_title : paneId;
|
|
72
|
+
out.push({
|
|
73
|
+
id: paneId,
|
|
74
|
+
label: title,
|
|
75
|
+
cwd,
|
|
76
|
+
status: toStatus(a.agent_status),
|
|
77
|
+
kind: typeof a.agent === "string" ? a.agent : undefined,
|
|
78
|
+
focused: a.focused === true,
|
|
79
|
+
focus: ["herdr", "agent", "focus", paneId],
|
|
80
|
+
provider: "herdr",
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
export function createHerdrProvider(commandExists, runJson = runHerdrJson) {
|
|
86
|
+
return {
|
|
87
|
+
name: "herdr",
|
|
88
|
+
available: () => commandExists("herdr"),
|
|
89
|
+
list() {
|
|
90
|
+
const timeoutMs = clampInt(process.env.PHREN_HERDR_TIMEOUT_MS, 3000, 250, 30000);
|
|
91
|
+
return parseHerdrAgents(runJson(["agent", "list"], timeoutMs));
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agents spawned by phren-agent's own multi-agent mode.
|
|
3
|
+
*
|
|
4
|
+
* The spawner runs in a different process from the shell, so it publishes each
|
|
5
|
+
* agent as a small JSON file under `.runtime/agents/` and removes it on exit.
|
|
6
|
+
* That makes phren's own agents visible in the graph on the same footing as
|
|
7
|
+
* any other host's, and gives the provider contract a second real
|
|
8
|
+
* implementation rather than a speculative one.
|
|
9
|
+
*/
|
|
10
|
+
import { type AgentProvider } from "../types.js";
|
|
11
|
+
/** Where a spawner publishes its live agents. */
|
|
12
|
+
export declare function agentsRuntimeDir(phrenPath: string): string;
|
|
13
|
+
export declare function createSpawnerProvider(phrenPath: string, now?: () => number): AgentProvider;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agents spawned by phren-agent's own multi-agent mode.
|
|
3
|
+
*
|
|
4
|
+
* The spawner runs in a different process from the shell, so it publishes each
|
|
5
|
+
* agent as a small JSON file under `.runtime/agents/` and removes it on exit.
|
|
6
|
+
* That makes phren's own agents visible in the graph on the same footing as
|
|
7
|
+
* any other host's, and gives the provider contract a second real
|
|
8
|
+
* implementation rather than a speculative one.
|
|
9
|
+
*/
|
|
10
|
+
import * as fs from "fs";
|
|
11
|
+
import * as path from "path";
|
|
12
|
+
import { runtimeFile } from "../../shared.js";
|
|
13
|
+
import { debugLog } from "../../shared.js";
|
|
14
|
+
import { errorMessage } from "../../utils.js";
|
|
15
|
+
import { isAgentRecord } from "../types.js";
|
|
16
|
+
/** Where a spawner publishes its live agents. */
|
|
17
|
+
export function agentsRuntimeDir(phrenPath) {
|
|
18
|
+
return runtimeFile(phrenPath, "agents");
|
|
19
|
+
}
|
|
20
|
+
/** Records older than this are treated as leaked by a process that died badly. */
|
|
21
|
+
const STALE_MS = 5 * 60_000;
|
|
22
|
+
export function createSpawnerProvider(phrenPath, now = Date.now) {
|
|
23
|
+
const dir = agentsRuntimeDir(phrenPath);
|
|
24
|
+
return {
|
|
25
|
+
name: "phren-agent",
|
|
26
|
+
available: () => {
|
|
27
|
+
try {
|
|
28
|
+
return fs.existsSync(dir);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
list() {
|
|
35
|
+
let entries;
|
|
36
|
+
try {
|
|
37
|
+
entries = fs.readdirSync(dir).filter((name) => name.endsWith(".json"));
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
const out = [];
|
|
43
|
+
for (const entry of entries) {
|
|
44
|
+
const file = path.join(dir, entry);
|
|
45
|
+
try {
|
|
46
|
+
const stat = fs.statSync(file);
|
|
47
|
+
if (now() - stat.mtimeMs > STALE_MS)
|
|
48
|
+
continue;
|
|
49
|
+
const parsed = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
50
|
+
const records = Array.isArray(parsed) ? parsed : [parsed];
|
|
51
|
+
for (const record of records) {
|
|
52
|
+
if (isAgentRecord(record))
|
|
53
|
+
out.push({ ...record, provider: "phren-agent" });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
debugLog(`spawner provider: ${entry}: ${errorMessage(err)}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collect the agents running on this machine and join them onto the graph.
|
|
3
|
+
*
|
|
4
|
+
* This module stays free of heavy imports on purpose: the graph view calls it
|
|
5
|
+
* on a timer, and `cli-registry.ts` treats cold start as a constraint. The
|
|
6
|
+
* project lookup is injected rather than imported, which keeps the FTS index
|
|
7
|
+
* out of this path and makes the join testable without a store.
|
|
8
|
+
*/
|
|
9
|
+
import type { AgentProvider, AgentRecord, JoinedAgent } from "./types.js";
|
|
10
|
+
/** Off by default, like every other optional feature here. */
|
|
11
|
+
export declare function agentsEnabled(): boolean;
|
|
12
|
+
/** Resolves a working directory to a phren project, or null. */
|
|
13
|
+
export type ProjectResolver = (cwd: string) => string | null;
|
|
14
|
+
/**
|
|
15
|
+
* Ask every available provider, in order. A provider that throws or hangs is
|
|
16
|
+
* skipped rather than allowed to break a repaint; duplicates by id keep the
|
|
17
|
+
* first answer, so an earlier provider wins.
|
|
18
|
+
*/
|
|
19
|
+
export declare function collectAgents(providers: AgentProvider[]): AgentRecord[];
|
|
20
|
+
/**
|
|
21
|
+
* Attach each agent to the phren project its directory belongs to. The
|
|
22
|
+
* resolver is the same one the hooks use, so a git worktree lands on the
|
|
23
|
+
* repository it came from. Agents outside any project keep a null project and
|
|
24
|
+
* still appear in the list.
|
|
25
|
+
*/
|
|
26
|
+
export declare function joinAgents(records: AgentRecord[], resolve: ProjectResolver): JoinedAgent[];
|
|
27
|
+
/** Sort for display: what you are looking at first, then busy, then the rest. */
|
|
28
|
+
export declare function sortAgents(agents: JoinedAgent[]): JoinedAgent[];
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collect the agents running on this machine and join them onto the graph.
|
|
3
|
+
*
|
|
4
|
+
* This module stays free of heavy imports on purpose: the graph view calls it
|
|
5
|
+
* on a timer, and `cli-registry.ts` treats cold start as a constraint. The
|
|
6
|
+
* project lookup is injected rather than imported, which keeps the FTS index
|
|
7
|
+
* out of this path and makes the join testable without a store.
|
|
8
|
+
*/
|
|
9
|
+
import { isFeatureEnabled } from "../utils-helpers.js";
|
|
10
|
+
import { debugLog } from "../shared.js";
|
|
11
|
+
import { errorMessage } from "../utils.js";
|
|
12
|
+
/** Off by default, like every other optional feature here. */
|
|
13
|
+
export function agentsEnabled() {
|
|
14
|
+
return isFeatureEnabled("PHREN_FEATURE_AGENTS", false);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Ask every available provider, in order. A provider that throws or hangs is
|
|
18
|
+
* skipped rather than allowed to break a repaint; duplicates by id keep the
|
|
19
|
+
* first answer, so an earlier provider wins.
|
|
20
|
+
*/
|
|
21
|
+
export function collectAgents(providers) {
|
|
22
|
+
const seen = new Set();
|
|
23
|
+
const out = [];
|
|
24
|
+
for (const provider of providers) {
|
|
25
|
+
let records = [];
|
|
26
|
+
try {
|
|
27
|
+
if (!provider.available())
|
|
28
|
+
continue;
|
|
29
|
+
records = provider.list();
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
debugLog(`agent provider ${provider.name}: ${errorMessage(err)}`);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
for (const record of records) {
|
|
36
|
+
const key = `${record.provider ?? provider.name}:${record.id}`;
|
|
37
|
+
if (seen.has(key))
|
|
38
|
+
continue;
|
|
39
|
+
seen.add(key);
|
|
40
|
+
out.push({ provider: provider.name, ...record });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Attach each agent to the phren project its directory belongs to. The
|
|
47
|
+
* resolver is the same one the hooks use, so a git worktree lands on the
|
|
48
|
+
* repository it came from. Agents outside any project keep a null project and
|
|
49
|
+
* still appear in the list.
|
|
50
|
+
*/
|
|
51
|
+
export function joinAgents(records, resolve) {
|
|
52
|
+
const cache = new Map();
|
|
53
|
+
return records.map((record) => {
|
|
54
|
+
let project = cache.get(record.cwd);
|
|
55
|
+
if (project === undefined) {
|
|
56
|
+
try {
|
|
57
|
+
project = resolve(record.cwd);
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
debugLog(`agent join ${record.cwd}: ${errorMessage(err)}`);
|
|
61
|
+
project = null;
|
|
62
|
+
}
|
|
63
|
+
cache.set(record.cwd, project);
|
|
64
|
+
}
|
|
65
|
+
return { ...record, project };
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/** Sort for display: what you are looking at first, then busy, then the rest. */
|
|
69
|
+
export function sortAgents(agents) {
|
|
70
|
+
const rank = (a) => {
|
|
71
|
+
if (a.focused)
|
|
72
|
+
return 0;
|
|
73
|
+
if (a.status === "working")
|
|
74
|
+
return 1;
|
|
75
|
+
if (a.status === "error")
|
|
76
|
+
return 2;
|
|
77
|
+
if (a.status === "idle")
|
|
78
|
+
return 3;
|
|
79
|
+
return 4;
|
|
80
|
+
};
|
|
81
|
+
return agents.slice().sort((a, b) => rank(a) - rank(b) || a.label.localeCompare(b.label));
|
|
82
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What phren knows about a coding agent running on this machine.
|
|
3
|
+
*
|
|
4
|
+
* phren does not spawn or supervise these; it discovers them from whatever is
|
|
5
|
+
* already managing them — a Herdr workspace, phren-agent's own multi-agent
|
|
6
|
+
* spawner, a tmux session — and joins them onto the knowledge graph by the
|
|
7
|
+
* directory they are working in.
|
|
8
|
+
*
|
|
9
|
+
* The contract is deliberately small and host-agnostic. Anything that can
|
|
10
|
+
* print this shape is a provider, which is why a tmux or Zellij user needs a
|
|
11
|
+
* few lines of shell rather than a change to phren.
|
|
12
|
+
*/
|
|
13
|
+
export type AgentStatus = "working" | "idle" | "done" | "error";
|
|
14
|
+
export interface AgentRecord {
|
|
15
|
+
/** Stable for as long as the agent lives; used to address it. */
|
|
16
|
+
id: string;
|
|
17
|
+
/** Human label, e.g. the pane's title. */
|
|
18
|
+
label: string;
|
|
19
|
+
/** Working directory, which is how the agent joins a phren project. */
|
|
20
|
+
cwd: string;
|
|
21
|
+
status: AgentStatus;
|
|
22
|
+
/** Which agent this is ("claude", "codex", …), when the host knows. */
|
|
23
|
+
kind?: string;
|
|
24
|
+
/** Whether the host considers this the agent the user is looking at. */
|
|
25
|
+
focused?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Command that brings this agent to the front, as argv. phren never needs to
|
|
28
|
+
* know what focusing means for a given host — the provider says how.
|
|
29
|
+
*/
|
|
30
|
+
focus?: string[];
|
|
31
|
+
/** Which provider produced this record, for the pane and for debugging. */
|
|
32
|
+
provider?: string;
|
|
33
|
+
}
|
|
34
|
+
/** An agent record joined to the phren project its directory belongs to. */
|
|
35
|
+
export interface JoinedAgent extends AgentRecord {
|
|
36
|
+
/** Resolved phren project, or null when the directory is not a phren project. */
|
|
37
|
+
project: string | null;
|
|
38
|
+
}
|
|
39
|
+
export interface AgentProvider {
|
|
40
|
+
name: string;
|
|
41
|
+
/** Cheap probe. Must not throw and must not block on network or a lock. */
|
|
42
|
+
available(): boolean;
|
|
43
|
+
/** Never throws: a provider that cannot answer returns nothing. */
|
|
44
|
+
list(): AgentRecord[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Structural guard for records that arrive from outside phren. These drive a
|
|
48
|
+
* command invocation, so a malformed entry is dropped rather than trusted —
|
|
49
|
+
* the same posture governance takes with its on-disk JSON.
|
|
50
|
+
*/
|
|
51
|
+
export declare function isAgentRecord(value: unknown): value is AgentRecord;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What phren knows about a coding agent running on this machine.
|
|
3
|
+
*
|
|
4
|
+
* phren does not spawn or supervise these; it discovers them from whatever is
|
|
5
|
+
* already managing them — a Herdr workspace, phren-agent's own multi-agent
|
|
6
|
+
* spawner, a tmux session — and joins them onto the knowledge graph by the
|
|
7
|
+
* directory they are working in.
|
|
8
|
+
*
|
|
9
|
+
* The contract is deliberately small and host-agnostic. Anything that can
|
|
10
|
+
* print this shape is a provider, which is why a tmux or Zellij user needs a
|
|
11
|
+
* few lines of shell rather than a change to phren.
|
|
12
|
+
*/
|
|
13
|
+
const STATUSES = new Set(["working", "idle", "done", "error"]);
|
|
14
|
+
/**
|
|
15
|
+
* Structural guard for records that arrive from outside phren. These drive a
|
|
16
|
+
* command invocation, so a malformed entry is dropped rather than trusted —
|
|
17
|
+
* the same posture governance takes with its on-disk JSON.
|
|
18
|
+
*/
|
|
19
|
+
export function isAgentRecord(value) {
|
|
20
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
21
|
+
return false;
|
|
22
|
+
const rec = value;
|
|
23
|
+
if (typeof rec.id !== "string" || !rec.id)
|
|
24
|
+
return false;
|
|
25
|
+
if (typeof rec.label !== "string")
|
|
26
|
+
return false;
|
|
27
|
+
if (typeof rec.cwd !== "string" || !rec.cwd)
|
|
28
|
+
return false;
|
|
29
|
+
if (typeof rec.status !== "string" || !STATUSES.has(rec.status))
|
|
30
|
+
return false;
|
|
31
|
+
if (rec.kind !== undefined && typeof rec.kind !== "string")
|
|
32
|
+
return false;
|
|
33
|
+
if (rec.focused !== undefined && typeof rec.focused !== "boolean")
|
|
34
|
+
return false;
|
|
35
|
+
if (rec.focus !== undefined) {
|
|
36
|
+
if (!Array.isArray(rec.focus) || rec.focus.length === 0)
|
|
37
|
+
return false;
|
|
38
|
+
if (!rec.focus.every((part) => typeof part === "string" && part.length > 0))
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
}
|
package/dist/cli/search.js
CHANGED
|
@@ -5,6 +5,8 @@ import { buildIndex, extractSnippet, queryDocRows, queryRows, queryFragmentLinks
|
|
|
5
5
|
import { buildFtsQueryVariants, errorMessage, isValidProjectName } from "../utils.js";
|
|
6
6
|
import { logger } from "../logger.js";
|
|
7
7
|
import { keywordFallbackSearch } from "../core/search.js";
|
|
8
|
+
import { recordLookupEvents } from "../shared/governance.js";
|
|
9
|
+
import { bestFindingNodeId } from "../finding-graph-id.js";
|
|
8
10
|
const MAX_HISTORY = 20;
|
|
9
11
|
const SEARCH_TYPE_ALIASES = {
|
|
10
12
|
skills: "skill",
|
|
@@ -267,11 +269,38 @@ export async function runSearch(opts, phrenPath, profile) {
|
|
|
267
269
|
lines.push(`Type filter: ${opts.type}`);
|
|
268
270
|
lines.push("");
|
|
269
271
|
}
|
|
272
|
+
const hits = [];
|
|
270
273
|
for (const row of rows) {
|
|
271
274
|
const snippet = extractSnippet(row.content, opts.query, 7);
|
|
272
275
|
lines.push(`[${row.project}/${row.filename}] (${row.type})`);
|
|
273
276
|
lines.push(snippet);
|
|
274
277
|
lines.push("");
|
|
278
|
+
hits.push({ project: row.project, filename: row.filename, type: row.type, snippet, path: row.path, content: row.content });
|
|
279
|
+
}
|
|
280
|
+
// Live activity: the CLI records the same lookup events the MCP search
|
|
281
|
+
// does, so `phren search` in one terminal lights up a graph watching in
|
|
282
|
+
// another. Best-effort — logging must never fail a search.
|
|
283
|
+
if (opts.query) {
|
|
284
|
+
try {
|
|
285
|
+
const at = new Date().toISOString();
|
|
286
|
+
recordLookupEvents(phrenPath, hits.map((hit) => {
|
|
287
|
+
const nodeId = hit.type === "findings" ? bestFindingNodeId(hit.project, hit.content, opts.query ?? "") : null;
|
|
288
|
+
return {
|
|
289
|
+
at,
|
|
290
|
+
query: opts.query ?? "",
|
|
291
|
+
project: hit.project,
|
|
292
|
+
filename: hit.filename,
|
|
293
|
+
type: hit.type,
|
|
294
|
+
path: hit.path,
|
|
295
|
+
snippet: hit.snippet,
|
|
296
|
+
source: "search",
|
|
297
|
+
...(nodeId ? { nodeId } : {}),
|
|
298
|
+
};
|
|
299
|
+
}));
|
|
300
|
+
}
|
|
301
|
+
catch (err) {
|
|
302
|
+
logger.debug("search", `cli search lookup-events: ${errorMessage(err)}`);
|
|
303
|
+
}
|
|
275
304
|
}
|
|
276
305
|
return { lines, exitCode: 0 };
|
|
277
306
|
}
|
package/dist/cli-registry.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export interface Command {
|
|
|
35
35
|
hidden?: boolean;
|
|
36
36
|
run: RunFn;
|
|
37
37
|
}
|
|
38
|
-
export declare const ENV_HELP = "Environment variables:\n PHREN_PATH Override phren directory (default: ~/.phren)\n PHREN_PROFILE Active profile name\n PHREN_DEBUG Enable debug logging (set to 1)\n\n Embeddings:\n PHREN_OLLAMA_URL Ollama base URL (default: http://localhost:11434, 'off' to disable)\n PHREN_EMBEDDING_API_URL OpenAI-compatible /embeddings endpoint\n PHREN_EMBEDDING_API_KEY API key for embedding endpoint\n PHREN_EMBEDDING_MODEL Embedding model (default: nomic-embed-text)\n\n Context injection:\n PHREN_CONTEXT_TOKEN_BUDGET Max tokens injected per prompt (default: 550)\n PHREN_MAX_INJECT_TOKENS Hard cap on total injected tokens (default: 2000)\n PHREN_HOOK_TIMEOUT_MS Hook subprocess timeout in ms (default: 14000)\n\n Feature flags:\n PHREN_FEATURE_TOOL_HOOK=0 Skip the PostToolUse subprocess (perf)\n PHREN_FEATURE_AUTO_EXTRACT=0 Disable auto memory extraction\n PHREN_FEATURE_AUTO_CAPTURE=1 Extract insights from conversations\n PHREN_FEATURE_SEMANTIC_DEDUP=1 LLM-based dedup on add_finding\n PHREN_FEATURE_HYBRID_SEARCH=0 Disable TF-IDF cosine fallback\n\n Run 'phren help all' to see everything.\n";
|
|
38
|
+
export declare const ENV_HELP = "Environment variables:\n PHREN_PATH Override phren directory (default: ~/.phren)\n PHREN_PROFILE Active profile name\n PHREN_DEBUG Enable debug logging (set to 1)\n\n Embeddings:\n PHREN_OLLAMA_URL Ollama base URL (default: http://localhost:11434, 'off' to disable)\n PHREN_EMBEDDING_API_URL OpenAI-compatible /embeddings endpoint\n PHREN_EMBEDDING_API_KEY API key for embedding endpoint\n PHREN_EMBEDDING_MODEL Embedding model (default: nomic-embed-text)\n\n Context injection:\n PHREN_CONTEXT_TOKEN_BUDGET Max tokens injected per prompt (default: 550)\n PHREN_MAX_INJECT_TOKENS Hard cap on total injected tokens (default: 2000)\n PHREN_HOOK_TIMEOUT_MS Hook subprocess timeout in ms (default: 14000)\n\n Feature flags:\n PHREN_FEATURE_AGENTS=1 Show running coding agents on the graph\n PHREN_FEATURE_TOOL_HOOK=0 Skip the PostToolUse subprocess (perf)\n PHREN_FEATURE_AUTO_EXTRACT=0 Disable auto memory extraction\n PHREN_FEATURE_AUTO_CAPTURE=1 Extract insights from conversations\n PHREN_FEATURE_SEMANTIC_DEDUP=1 LLM-based dedup on add_finding\n PHREN_FEATURE_HYBRID_SEARCH=0 Disable TF-IDF cosine fallback\n\n Run 'phren help all' to see everything.\n";
|
|
39
39
|
export declare const DOC_TOPICS: Record<string, string>;
|
|
40
40
|
export declare const REGISTRY: Command[];
|
|
41
41
|
export declare function lookupCommand(name: string): Command | undefined;
|
package/dist/cli-registry.js
CHANGED
|
@@ -43,6 +43,7 @@ export const ENV_HELP = `Environment variables:
|
|
|
43
43
|
PHREN_HOOK_TIMEOUT_MS Hook subprocess timeout in ms (default: 14000)
|
|
44
44
|
|
|
45
45
|
Feature flags:
|
|
46
|
+
PHREN_FEATURE_AGENTS=1 Show running coding agents on the graph
|
|
46
47
|
PHREN_FEATURE_TOOL_HOOK=0 Skip the PostToolUse subprocess (perf)
|
|
47
48
|
PHREN_FEATURE_AUTO_EXTRACT=0 Disable auto memory extraction
|
|
48
49
|
PHREN_FEATURE_AUTO_CAPTURE=1 Extract insights from conversations
|
package/dist/content/learning.js
CHANGED
|
@@ -3,7 +3,8 @@ import * as path from "path";
|
|
|
3
3
|
import * as crypto from "crypto";
|
|
4
4
|
import { debugLog, appendAuditLog, phrenOk, phrenErr, PhrenError } from "../shared.js";
|
|
5
5
|
import { normalizeMemoryScope } from "../shared.js";
|
|
6
|
-
import { withFileLock } from "../shared/governance.js";
|
|
6
|
+
import { withFileLock, recordLookupEvents } from "../shared/governance.js";
|
|
7
|
+
import { findingNodeIdForLine } from "../finding-graph-id.js";
|
|
7
8
|
import { isValidProjectName } from "../utils.js";
|
|
8
9
|
import { storeAwareProjectPath } from "../store-routing.js";
|
|
9
10
|
import { buildCitationComment, buildScopeComment, buildSourceComment, getHeadCommit, getRepoRoot, inferCitationLocation, } from "./citation.js";
|
|
@@ -365,6 +366,28 @@ export function addFindingToFile(phrenPath, project, learning, citationInput, op
|
|
|
365
366
|
if (typeof result.data === "string")
|
|
366
367
|
return phrenOk({ message: result.data, status: "skipped" });
|
|
367
368
|
appendAuditLog(phrenPath, "add_finding", `project=${project}${result.data.created ? " created=true" : ""} citation_commit=${result.data.citation.commit ?? "none"} citation_file=${result.data.citation.file ?? "none"}`);
|
|
369
|
+
// Live activity: a write lights up the same graph node a lookup would, so a
|
|
370
|
+
// watching shell shows findings being saved as well as read. Best-effort.
|
|
371
|
+
try {
|
|
372
|
+
const bullet = result.data.bullet;
|
|
373
|
+
if (bullet) {
|
|
374
|
+
// Derive the node id the same way buildGraph does, so a watching graph
|
|
375
|
+
// lights the node that was just written rather than a phantom id.
|
|
376
|
+
const nodeId = findingNodeIdForLine(project, bullet.startsWith("-") ? bullet : `- ${bullet}`);
|
|
377
|
+
recordLookupEvents(phrenPath, [{
|
|
378
|
+
query: "",
|
|
379
|
+
project,
|
|
380
|
+
filename: FINDINGS_FILENAME,
|
|
381
|
+
type: "findings",
|
|
382
|
+
snippet: bullet.replace(/^-\s+/, "").replace(/\s*<!--.*?-->/g, "").trim(),
|
|
383
|
+
source: "write",
|
|
384
|
+
...(nodeId ? { nodeId } : {}),
|
|
385
|
+
}]);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
catch (err) {
|
|
389
|
+
debugLog(`addFindingToFile lookup-event: ${String(err)}`);
|
|
390
|
+
}
|
|
368
391
|
const cap = Number.parseInt((process.env.PHREN_FINDINGS_CAP) || "", 10) || DEFAULT_FINDINGS_CAP;
|
|
369
392
|
const activeCount = countActiveFindings(result.data.content);
|
|
370
393
|
if (activeCount > cap) {
|