@phren/cli 0.2.5 → 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.
@@ -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
- /** A prose paragraph over the newest bullets, when a model is configured; "" otherwise. */
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;
@@ -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";
@@ -139,14 +140,48 @@ export function structuralNow(d) {
139
140
  parts.push(`Newest: ${d.headlines.map((h, i) => `(${i + 1}) ${h}`).join(" ")}`);
140
141
  return parts.join(" ");
141
142
  }
142
- /** A prose paragraph over the newest bullets, when a model is configured; "" otherwise. */
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
+ */
143
165
  export async function proseNow(d, bullets, signal) {
144
166
  const newest = [...bullets].reverse().slice(0, 60).map((b) => `- [${b.tag}] ${b.text}`).join("\n");
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}`;
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");
146
174
  try {
147
175
  // A paragraph from a local model can take a minute on a laptop; the default ten-second budget is for YES/NO checks.
148
176
  const text = (await callLlm(prompt, signal, 320, 120_000)).trim();
149
- return text.length > 40 ? text : "";
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;
150
185
  }
151
186
  catch (err) {
152
187
  debugLog(`summarize: llm failed: ${errorMessage(err)}`);
@@ -224,6 +259,18 @@ export async function summarizeTopicFile(filePath, slug, opts = {}) {
224
259
  const fingerprint = contentFingerprint(content, NOW_START, NOW_END);
225
260
  const bullets = parseTopicBullets(content);
226
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
+ }
227
274
  // The block carries a fingerprint of the rest of the file; unchanged bullets
228
275
  // mean an unchanged summary, whatever the clock says.
229
276
  if (!opts.force && prev?.hash === fingerprint && !split) {
@@ -268,6 +315,10 @@ function countOpenTasks(tasksPath) {
268
315
  }
269
316
  /** Summarize every topic file of a project and refresh the "What phren knows" block in summary.md. */
270
317
  export async function summarizeProject(phrenPath, project, opts = {}) {
318
+ // The store's .env carries the LLM endpoint and model; a CLI path that has
319
+ // not touched a feature flag yet has not loaded it.
320
+ if (opts.llm)
321
+ bootstrapPhrenDotEnv(phrenPath);
271
322
  const topics = readProjectTopics(phrenPath, project).topics;
272
323
  const results = [];
273
324
  const seen = new Set();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phren/cli",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Knowledge layer for AI agents — CLI, MCP server, and data layer",
5
5
  "type": "module",
6
6
  "bin": {