@phren/cli 0.2.4 → 0.2.6
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/content/dedup.d.ts
CHANGED
|
@@ -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: <!-- ... -->
|
package/dist/content/dedup.js
CHANGED
|
@@ -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(),
|
|
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"
|
|
@@ -17,6 +17,7 @@ import * as fs from "fs";
|
|
|
17
17
|
import * as path from "path";
|
|
18
18
|
import { createHash } from "crypto";
|
|
19
19
|
import { callLlm } from "./dedup.js";
|
|
20
|
+
import { bootstrapPhrenDotEnv } from "../phren-dotenv.js";
|
|
20
21
|
import { readProjectTopics, topicReferencePath } from "../project-topics.js";
|
|
21
22
|
import { storeAwareProjectPath } from "../store-routing.js";
|
|
22
23
|
import { atomicWriteText, debugLog } from "../phren-paths.js";
|
|
@@ -144,7 +145,8 @@ export async function proseNow(d, bullets, signal) {
|
|
|
144
145
|
const newest = [...bullets].reverse().slice(0, 60).map((b) => `- [${b.tag}] ${b.text}`).join("\n");
|
|
145
146
|
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
147
|
try {
|
|
147
|
-
|
|
148
|
+
// A paragraph from a local model can take a minute on a laptop; the default ten-second budget is for YES/NO checks.
|
|
149
|
+
const text = (await callLlm(prompt, signal, 320, 120_000)).trim();
|
|
148
150
|
return text.length > 40 ? text : "";
|
|
149
151
|
}
|
|
150
152
|
catch (err) {
|
|
@@ -231,7 +233,7 @@ export async function summarizeTopicFile(filePath, slug, opts = {}) {
|
|
|
231
233
|
}
|
|
232
234
|
let now = "";
|
|
233
235
|
if (opts.llm)
|
|
234
|
-
now = await proseNow(digest, bullets, AbortSignal.timeout(
|
|
236
|
+
now = await proseNow(digest, bullets, AbortSignal.timeout(150_000));
|
|
235
237
|
if (!now)
|
|
236
238
|
now = structuralNow(digest);
|
|
237
239
|
const next = upsertBlock(content, NOW_START, NOW_END, block(NOW_START, NOW_END, "## Now", now, stamp, fingerprint), "top");
|
|
@@ -267,6 +269,10 @@ function countOpenTasks(tasksPath) {
|
|
|
267
269
|
}
|
|
268
270
|
/** Summarize every topic file of a project and refresh the "What phren knows" block in summary.md. */
|
|
269
271
|
export async function summarizeProject(phrenPath, project, opts = {}) {
|
|
272
|
+
// The store's .env carries the LLM endpoint and model; a CLI path that has
|
|
273
|
+
// not touched a feature flag yet has not loaded it.
|
|
274
|
+
if (opts.llm)
|
|
275
|
+
bootstrapPhrenDotEnv(phrenPath);
|
|
270
276
|
const topics = readProjectTopics(phrenPath, project).topics;
|
|
271
277
|
const results = [];
|
|
272
278
|
const seen = new Set();
|