@phren/cli 0.2.3 → 0.2.5

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.
@@ -1,4 +1,4 @@
1
- export declare function callLlm(prompt: string, signal?: AbortSignal, maxTokens?: number): Promise<string>;
1
+ export declare function callLlm(prompt: string, signal?: AbortSignal, maxTokens?: number, timeoutMs?: number): Promise<string>;
2
2
  /**
3
3
  * Strip all common finding metadata:
4
4
  * - HTML comments: <!-- ... -->
@@ -71,14 +71,25 @@ function isAbortError(error) {
71
71
  return error instanceof Error && error.name === "AbortError";
72
72
  }
73
73
  const LLM_TIMEOUT_MS = 10_000;
74
+ /**
75
+ * Per-call budget. Ten seconds suits a YES/NO dedup check against a hosted
76
+ * model; a paragraph from a local 8B model on a laptop CPU takes longer, so
77
+ * callers with real output to wait for pass their own, and PHREN_LLM_TIMEOUT_MS
78
+ * raises the floor for everything.
79
+ */
80
+ function llmTimeoutMs(requested) {
81
+ const fromEnv = Number.parseInt(process.env.PHREN_LLM_TIMEOUT_MS ?? "", 10);
82
+ const floor = Number.isFinite(fromEnv) && fromEnv > 0 ? fromEnv : LLM_TIMEOUT_MS;
83
+ return Math.max(floor, requested ?? 0);
84
+ }
74
85
  function parseOpenAiResponse(data) {
75
86
  const d = data;
76
87
  return d.choices?.[0]?.message?.content?.trim() ?? "";
77
88
  }
78
89
  /** POST to an LLM endpoint with a combined per-call timeout + parent abort relay. */
79
- async function fetchLlm(url, init, signal, parseResponse) {
90
+ async function fetchLlm(url, init, signal, parseResponse, timeoutMs = LLM_TIMEOUT_MS) {
80
91
  const controller = new AbortController();
81
- const timeoutId = setTimeout(() => controller.abort(), LLM_TIMEOUT_MS);
92
+ const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
82
93
  if (signal)
83
94
  signal.addEventListener("abort", () => controller.abort(), { once: true });
84
95
  let response;
@@ -94,7 +105,8 @@ async function fetchLlm(url, init, signal, parseResponse) {
94
105
  }
95
106
  // Default maxTokens is 10 — callers that only need YES/NO or CONFLICT/OK responses
96
107
  // need just 3-5 tokens. Callers expecting longer output pass an explicit override (e.g. 60).
97
- export async function callLlm(prompt, signal, maxTokens = 10) {
108
+ export async function callLlm(prompt, signal, maxTokens = 10, timeoutMs) {
109
+ const budget = llmTimeoutMs(timeoutMs);
98
110
  // Check abort before starting any work to avoid unnecessary API calls
99
111
  if (signal?.aborted)
100
112
  throw new DOMException("Aborted", "AbortError");
@@ -110,7 +122,7 @@ export async function callLlm(prompt, signal, maxTokens = 10) {
110
122
  method: "POST",
111
123
  headers: { "Content-Type": "application/json", ...(key ? { Authorization: `Bearer ${key}` } : {}) },
112
124
  body: JSON.stringify({ model: model || "gpt-4o-mini", messages: [{ role: "user", content: prompt }], max_tokens: maxTokens, temperature: 0 }),
113
- }, signal, parseOpenAiResponse);
125
+ }, signal, parseOpenAiResponse, budget);
114
126
  }
115
127
  else if (anthropicKey) {
116
128
  // Anthropic REST API fallback (no SDK required)
@@ -122,7 +134,7 @@ export async function callLlm(prompt, signal, maxTokens = 10) {
122
134
  const d = data;
123
135
  const block = d.content?.[0];
124
136
  return (block?.type === "text" ? block.text ?? "" : "").trim();
125
- });
137
+ }, budget);
126
138
  }
127
139
  else if (openaiKey) {
128
140
  // OpenAI REST API fallback
@@ -130,7 +142,7 @@ export async function callLlm(prompt, signal, maxTokens = 10) {
130
142
  method: "POST",
131
143
  headers: { "Content-Type": "application/json", Authorization: `Bearer ${openaiKey}` },
132
144
  body: JSON.stringify({ model: model || "gpt-4o-mini", messages: [{ role: "user", content: prompt }], max_tokens: maxTokens, temperature: 0 }),
133
- }, signal, parseOpenAiResponse);
145
+ }, signal, parseOpenAiResponse, budget);
134
146
  }
135
147
  else {
136
148
  // No LLM configured — return empty to signal "not duplicate" / "no conflict"
@@ -144,7 +144,8 @@ export async function proseNow(d, bullets, signal) {
144
144
  const newest = [...bullets].reverse().slice(0, 60).map((b) => `- [${b.tag}] ${b.text}`).join("\n");
145
145
  const prompt = `These are archived engineering findings for the topic "${d.slug}" of one software project, newest first. Write one paragraph of 4 to 6 plain sentences stating what is currently known: the standing decisions, the pitfalls that still apply, and the patterns in use. Be concrete, name the components involved, no preamble, no bullet points.\n\n${newest}`;
146
146
  try {
147
- const text = (await callLlm(prompt, signal, 320)).trim();
147
+ // A paragraph from a local model can take a minute on a laptop; the default ten-second budget is for YES/NO checks.
148
+ const text = (await callLlm(prompt, signal, 320, 120_000)).trim();
148
149
  return text.length > 40 ? text : "";
149
150
  }
150
151
  catch (err) {
@@ -231,7 +232,7 @@ export async function summarizeTopicFile(filePath, slug, opts = {}) {
231
232
  }
232
233
  let now = "";
233
234
  if (opts.llm)
234
- now = await proseNow(digest, bullets, AbortSignal.timeout(25_000));
235
+ now = await proseNow(digest, bullets, AbortSignal.timeout(150_000));
235
236
  if (!now)
236
237
  now = structuralNow(digest);
237
238
  const next = upsertBlock(content, NOW_START, NOW_END, block(NOW_START, NOW_END, "## Now", now, stamp, fingerprint), "top");
@@ -102,6 +102,13 @@ export declare class GraphController {
102
102
  readonly mascot: GraphMascot;
103
103
  /** Space opens the selected node's full text in a bubble on the canvas. */
104
104
  reader: boolean;
105
+ private knowsCache;
106
+ /**
107
+ * The "What phren knows" paragraph for a project, written by
108
+ * `phren maintain summarize`; null until it has run. Read once per project
109
+ * per data load, so the pane can show it on every frame.
110
+ */
111
+ knowsFor(project: string): string | null;
105
112
  /**
106
113
  * v: the same graph as a sphere. Selection, search, watch mode and the
107
114
  * neighbour numbers all keep working; the camera orbits instead of panning.
@@ -18,6 +18,7 @@ import { GraphWatch } from "./watch.js";
18
18
  import { GraphAgents } from "./agents.js";
19
19
  import { GraphMascot } from "./mascot.js";
20
20
  import { LIVE_BUBBLE_MS } from "./bubble.js";
21
+ import { readKnowsBlock } from "../../content/summarize.js";
21
22
  import { DEFAULT_ORBIT, PITCH_LIMIT, buildOrbitLayout, parseMouse, projectOrbit, yawDelta, yawToFace } from "./orbit.js";
22
23
  /** Left alone in orbit for this long, the sphere starts turning on its own. */
23
24
  const IDLE_SPIN_MS = 6000;
@@ -103,6 +104,25 @@ export class GraphController {
103
104
  mascot = new GraphMascot();
104
105
  /** Space opens the selected node's full text in a bubble on the canvas. */
105
106
  reader = false;
107
+ knowsCache = new Map();
108
+ /**
109
+ * The "What phren knows" paragraph for a project, written by
110
+ * `phren maintain summarize`; null until it has run. Read once per project
111
+ * per data load, so the pane can show it on every frame.
112
+ */
113
+ knowsFor(project) {
114
+ if (!this.knowsCache.has(project)) {
115
+ let text = null;
116
+ try {
117
+ text = readKnowsBlock(this.phrenPath, project)?.text.replace(/^## What phren knows\s*/m, "").trim() ?? null;
118
+ }
119
+ catch {
120
+ text = null;
121
+ }
122
+ this.knowsCache.set(project, text);
123
+ }
124
+ return this.knowsCache.get(project) ?? null;
125
+ }
106
126
  /**
107
127
  * v: the same graph as a sphere. Selection, search, watch mode and the
108
128
  * neighbour numbers all keep working; the camera orbits instead of panning.
@@ -334,6 +354,7 @@ export class GraphController {
334
354
  if (warm && this.lastPositions.size)
335
355
  this.sim.warmStart(this.lastPositions);
336
356
  this.mascot.reset();
357
+ this.knowsCache.clear();
337
358
  // Settle before anyone sees it. Animating the relaxation instead — ticking
338
359
  // a few steps, framing the half-settled positions, then letting the rest
339
360
  // play out under a fixed camera — read as the whole cluster bouncing for a
@@ -356,7 +356,8 @@ function planBubbles(controller, cols, rows, selected) {
356
356
  const at = controller.projectNode(selected.id);
357
357
  if (!at)
358
358
  return [];
359
- const text = selected.fullLabel || selected.label;
359
+ const knows = selected.kind === "project" && selected.project ? controller.knowsFor(selected.project) : null;
360
+ const text = knows ? knows.replace(/\*\*/g, "").replace(/^- /gm, "• ") : (selected.fullLabel || selected.label);
360
361
  const anchor = toCell(at);
361
362
  const maxInner = Math.min(64, cols - BUBBLE_CHROME_COLS - 2);
362
363
  const maxRows = rows - BUBBLE_CHROME_ROWS - 1;
@@ -496,6 +497,23 @@ function renderPane(controller, selected, width, height) {
496
497
  if (selected.kind === "project") {
497
498
  row("findings", String(selected.findingCount ?? 0));
498
499
  row("tasks", String(selected.taskCount ?? 0));
500
+ const knows = selected.project ? controller.knowsFor(selected.project) : null;
501
+ if (knows) {
502
+ push();
503
+ push(style.dim("what phren knows"));
504
+ const bullets = knows.split("\n").filter((l) => l.startsWith("- ")).map((l) => l.slice(2).replace(/\*\*/g, ""));
505
+ const budget = Math.max(3, Math.floor(height * 0.28));
506
+ let used = 0;
507
+ for (const b of bullets) {
508
+ const lines = wrapText(b, inner - 2, 3);
509
+ if (used + lines.length > budget)
510
+ break;
511
+ lines.forEach((l, i) => push(`${i === 0 ? "· " : " "}${l}`));
512
+ used += lines.length;
513
+ }
514
+ if (bullets.length > 1)
515
+ push(`${style.boldCyan("␣")} ${style.dim("read all of it")}`);
516
+ }
499
517
  if (selected.store && selected.store !== "primary")
500
518
  row("store", selected.store);
501
519
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phren/cli",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Knowledge layer for AI agents — CLI, MCP server, and data layer",
5
5
  "type": "module",
6
6
  "bin": {