@phren/cli 0.2.6 → 0.2.7
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/summarize.d.ts +11 -1
- package/dist/content/summarize.js +49 -3
- package/package.json +1 -1
|
@@ -41,7 +41,17 @@ export declare function mostMentioned(bullets: ArchivedBullet[], limit?: number)
|
|
|
41
41
|
export declare function digestTopic(slug: string, file: string, bullets: ArchivedBullet[]): TopicDigest;
|
|
42
42
|
/** The paragraph that can always be written, no model required. */
|
|
43
43
|
export declare function structuralNow(d: TopicDigest): string;
|
|
44
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Identifiers a paragraph names that none of the bullets do. A small local
|
|
46
|
+
* model asked to summarise engineering notes will happily invent the stack
|
|
47
|
+
* ("built on argparse" for a TypeScript project); a summary that adds facts
|
|
48
|
+
* is worse than no summary, so any invented identifier fails the paragraph.
|
|
49
|
+
*/
|
|
50
|
+
export declare function inventedIdentifiers(prose: string, bullets: ArchivedBullet[]): string[];
|
|
51
|
+
/**
|
|
52
|
+
* A prose paragraph over the newest bullets, when a model is configured; ""
|
|
53
|
+
* otherwise, and "" when the paragraph names things the bullets do not.
|
|
54
|
+
*/
|
|
45
55
|
export declare function proseNow(d: TopicDigest, bullets: ArchivedBullet[], signal?: AbortSignal): Promise<string>;
|
|
46
56
|
/** Fingerprint of everything in a topic file except its own Now block. */
|
|
47
57
|
export declare function contentFingerprint(content: string, start: string, end: string): string;
|
|
@@ -140,14 +140,48 @@ export function structuralNow(d) {
|
|
|
140
140
|
parts.push(`Newest: ${d.headlines.map((h, i) => `(${i + 1}) ${h}`).join(" ")}`);
|
|
141
141
|
return parts.join(" ");
|
|
142
142
|
}
|
|
143
|
-
/**
|
|
143
|
+
/**
|
|
144
|
+
* Identifiers a paragraph names that none of the bullets do. A small local
|
|
145
|
+
* model asked to summarise engineering notes will happily invent the stack
|
|
146
|
+
* ("built on argparse" for a TypeScript project); a summary that adds facts
|
|
147
|
+
* is worse than no summary, so any invented identifier fails the paragraph.
|
|
148
|
+
*/
|
|
149
|
+
export function inventedIdentifiers(prose, bullets) {
|
|
150
|
+
const source = bullets.map((b) => b.text).join("\n").toLowerCase();
|
|
151
|
+
const out = [];
|
|
152
|
+
for (const m of prose.matchAll(/`([^`]{2,60})`|\b([A-Z][a-z]+[A-Z][A-Za-z0-9]+)\b|\b([a-z][a-z0-9]*(?:[_.-][a-z0-9]+)+)\b/g)) {
|
|
153
|
+
const term = (m[1] ?? m[2] ?? m[3] ?? "").trim();
|
|
154
|
+
if (!term || term.length < 3)
|
|
155
|
+
continue;
|
|
156
|
+
if (!source.includes(term.toLowerCase()))
|
|
157
|
+
out.push(term);
|
|
158
|
+
}
|
|
159
|
+
return [...new Set(out)];
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* A prose paragraph over the newest bullets, when a model is configured; ""
|
|
163
|
+
* otherwise, and "" when the paragraph names things the bullets do not.
|
|
164
|
+
*/
|
|
144
165
|
export async function proseNow(d, bullets, signal) {
|
|
145
166
|
const newest = [...bullets].reverse().slice(0, 60).map((b) => `- [${b.tag}] ${b.text}`).join("\n");
|
|
146
|
-
const prompt =
|
|
167
|
+
const prompt = [
|
|
168
|
+
`Below are archived engineering findings for the topic "${d.slug}" of one software project, newest first.`,
|
|
169
|
+
"Write one paragraph of 4 to 6 plain sentences saying what is currently known: standing decisions, pitfalls that still apply, patterns in use.",
|
|
170
|
+
"Rules: use only facts stated in the findings. Do not name any language, framework, library, file, or component unless a finding names it, and spell such names exactly as the findings do. If the findings do not support a sentence, leave it out. No preamble, no bullet points, no headings.",
|
|
171
|
+
"",
|
|
172
|
+
newest,
|
|
173
|
+
].join("\n");
|
|
147
174
|
try {
|
|
148
175
|
// A paragraph from a local model can take a minute on a laptop; the default ten-second budget is for YES/NO checks.
|
|
149
176
|
const text = (await callLlm(prompt, signal, 320, 120_000)).trim();
|
|
150
|
-
|
|
177
|
+
if (text.length <= 40)
|
|
178
|
+
return "";
|
|
179
|
+
const invented = inventedIdentifiers(text, bullets);
|
|
180
|
+
if (invented.length) {
|
|
181
|
+
debugLog(`summarize: rejected model paragraph for ${d.slug}, names not in the findings: ${invented.slice(0, 5).join(", ")}`);
|
|
182
|
+
return "";
|
|
183
|
+
}
|
|
184
|
+
return text;
|
|
151
185
|
}
|
|
152
186
|
catch (err) {
|
|
153
187
|
debugLog(`summarize: llm failed: ${errorMessage(err)}`);
|
|
@@ -225,6 +259,18 @@ export async function summarizeTopicFile(filePath, slug, opts = {}) {
|
|
|
225
259
|
const fingerprint = contentFingerprint(content, NOW_START, NOW_END);
|
|
226
260
|
const bullets = parseTopicBullets(content);
|
|
227
261
|
const digest = digestTopic(slug, filePath, bullets);
|
|
262
|
+
if (!bullets.length) {
|
|
263
|
+
// A hand-written reference doc that happens to live under reference/topics
|
|
264
|
+
// is not an archive. It gets no block, and loses one it was given before.
|
|
265
|
+
const s = content.indexOf(NOW_START.replace("-->", ""));
|
|
266
|
+
const e = content.indexOf(NOW_END);
|
|
267
|
+
if (s !== -1 && e !== -1 && e > s) {
|
|
268
|
+
const stripped = `${content.slice(0, s)}${content.slice(e + NOW_END.length)}`.replace(/\n{3,}/g, "\n\n");
|
|
269
|
+
atomicWriteText(filePath, stripped);
|
|
270
|
+
return { slug, file: filePath, bullets: 0, updated: true, now: "" };
|
|
271
|
+
}
|
|
272
|
+
return { slug, file: filePath, bullets: 0, updated: false, now: "" };
|
|
273
|
+
}
|
|
228
274
|
// The block carries a fingerprint of the rest of the file; unchanged bullets
|
|
229
275
|
// mean an unchanged summary, whatever the clock says.
|
|
230
276
|
if (!opts.force && prev?.hash === fingerprint && !split) {
|