@phren/cli 0.2.4 → 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");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phren/cli",
3
- "version": "0.2.4",
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": {