@phren/cli 0.2.2 → 0.2.4
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.
|
@@ -43,10 +43,15 @@ export declare function digestTopic(slug: string, file: string, bullets: Archive
|
|
|
43
43
|
export declare function structuralNow(d: TopicDigest): string;
|
|
44
44
|
/** A prose paragraph over the newest bullets, when a model is configured; "" otherwise. */
|
|
45
45
|
export declare function proseNow(d: TopicDigest, bullets: ArchivedBullet[], signal?: AbortSignal): Promise<string>;
|
|
46
|
+
/** Fingerprint of everything in a topic file except its own Now block. */
|
|
47
|
+
export declare function contentFingerprint(content: string, start: string, end: string): string;
|
|
46
48
|
/** Insert or replace a marked block. Topic files: before the first section; summary: at the end. */
|
|
47
49
|
export declare function upsertBlock(content: string, start: string, end: string, rendered: string, where: "top" | "bottom"): string;
|
|
48
|
-
/** The stamp inside an existing block, so unchanged files are not rewritten. */
|
|
49
|
-
export declare function
|
|
50
|
+
/** The stamp and fingerprint inside an existing block, so unchanged files are not rewritten. */
|
|
51
|
+
export declare function blockMeta(content: string, start: string): {
|
|
52
|
+
at: string;
|
|
53
|
+
hash: string | null;
|
|
54
|
+
} | null;
|
|
50
55
|
export interface SummarizeOptions {
|
|
51
56
|
/** Ask a configured model for prose; falls back to structural when none answers. */
|
|
52
57
|
llm?: boolean;
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import * as fs from "fs";
|
|
17
17
|
import * as path from "path";
|
|
18
|
+
import { createHash } from "crypto";
|
|
18
19
|
import { callLlm } from "./dedup.js";
|
|
19
20
|
import { readProjectTopics, topicReferencePath } from "../project-topics.js";
|
|
20
21
|
import { storeAwareProjectPath } from "../store-routing.js";
|
|
@@ -151,8 +152,15 @@ export async function proseNow(d, bullets, signal) {
|
|
|
151
152
|
return "";
|
|
152
153
|
}
|
|
153
154
|
}
|
|
154
|
-
function block(start, end, heading, body, stamp) {
|
|
155
|
-
return `${start.replace("-->", `at=${stamp} -->`)}\n${heading}\n\n${body}\n${end}`;
|
|
155
|
+
function block(start, end, heading, body, stamp, hash = "") {
|
|
156
|
+
return `${start.replace("-->", `at=${stamp}${hash ? ` hash=${hash}` : ""} -->`)}\n${heading}\n\n${body}\n${end}`;
|
|
157
|
+
}
|
|
158
|
+
/** Fingerprint of everything in a topic file except its own Now block. */
|
|
159
|
+
export function contentFingerprint(content, start, end) {
|
|
160
|
+
const s = content.indexOf(start.replace("-->", ""));
|
|
161
|
+
const e = content.indexOf(end);
|
|
162
|
+
const rest = s !== -1 && e !== -1 && e > s ? content.slice(0, s) + content.slice(e + end.length) : content;
|
|
163
|
+
return createHash("sha1").update(rest.replace(/\s+/g, " ").trim()).digest("hex").slice(0, 12);
|
|
156
164
|
}
|
|
157
165
|
/** Insert or replace a marked block. Topic files: before the first section; summary: at the end. */
|
|
158
166
|
export function upsertBlock(content, start, end, rendered, where) {
|
|
@@ -170,10 +178,10 @@ export function upsertBlock(content, start, end, rendered, where) {
|
|
|
170
178
|
}
|
|
171
179
|
return `${content.trimEnd()}\n\n${rendered}\n`;
|
|
172
180
|
}
|
|
173
|
-
/** The stamp inside an existing block, so unchanged files are not rewritten. */
|
|
174
|
-
export function
|
|
175
|
-
const m = new RegExp(`${start.replace("-->", "").replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}at=([^ ]+) -->`).exec(content);
|
|
176
|
-
return m ? m[1] : null;
|
|
181
|
+
/** The stamp and fingerprint inside an existing block, so unchanged files are not rewritten. */
|
|
182
|
+
export function blockMeta(content, start) {
|
|
183
|
+
const m = new RegExp(`${start.replace("-->", "").replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}at=([^ ]+)(?: hash=([0-9a-f]+))? -->`).exec(content);
|
|
184
|
+
return m ? { at: m[1], hash: m[2] ?? null } : null;
|
|
177
185
|
}
|
|
178
186
|
/**
|
|
179
187
|
* Move whole "## Archived <date>" sections, oldest first, into <topic>.older.md
|
|
@@ -210,13 +218,14 @@ export function splitTopicFile(filePath, maxBullets = TOPIC_SPLIT_AT) {
|
|
|
210
218
|
export async function summarizeTopicFile(filePath, slug, opts = {}) {
|
|
211
219
|
const split = splitTopicFile(filePath);
|
|
212
220
|
const content = fs.readFileSync(filePath, "utf8");
|
|
213
|
-
const stat = fs.statSync(filePath);
|
|
214
221
|
const stamp = (opts.now ?? (() => new Date()))().toISOString();
|
|
215
|
-
const prev =
|
|
222
|
+
const prev = blockMeta(content, NOW_START);
|
|
223
|
+
const fingerprint = contentFingerprint(content, NOW_START, NOW_END);
|
|
216
224
|
const bullets = parseTopicBullets(content);
|
|
217
225
|
const digest = digestTopic(slug, filePath, bullets);
|
|
218
|
-
// The block
|
|
219
|
-
|
|
226
|
+
// The block carries a fingerprint of the rest of the file; unchanged bullets
|
|
227
|
+
// mean an unchanged summary, whatever the clock says.
|
|
228
|
+
if (!opts.force && prev?.hash === fingerprint && !split) {
|
|
220
229
|
const existing = content.slice(content.indexOf(NOW_START.replace("-->", "")), content.indexOf(NOW_END));
|
|
221
230
|
return { slug, file: filePath, bullets: bullets.length, updated: false, now: existing.split("\n").slice(2).join("\n").trim() };
|
|
222
231
|
}
|
|
@@ -225,7 +234,7 @@ export async function summarizeTopicFile(filePath, slug, opts = {}) {
|
|
|
225
234
|
now = await proseNow(digest, bullets, AbortSignal.timeout(25_000));
|
|
226
235
|
if (!now)
|
|
227
236
|
now = structuralNow(digest);
|
|
228
|
-
const next = upsertBlock(content, NOW_START, NOW_END, block(NOW_START, NOW_END, "## Now", now, stamp), "top");
|
|
237
|
+
const next = upsertBlock(content, NOW_START, NOW_END, block(NOW_START, NOW_END, "## Now", now, stamp, fingerprint), "top");
|
|
229
238
|
if (next !== content)
|
|
230
239
|
atomicWriteText(filePath, next);
|
|
231
240
|
return { slug, file: filePath, bullets: bullets.length, updated: next !== content, split: split ?? undefined, now };
|
|
@@ -298,7 +307,7 @@ export async function summarizeProject(phrenPath, project, opts = {}) {
|
|
|
298
307
|
const rendered = block(KNOWS_START, KNOWS_END, "## What phren knows", lines.join("\n"), stamp);
|
|
299
308
|
const existing = fs.existsSync(summaryPath) ? fs.readFileSync(summaryPath, "utf8") : `# ${project}\n`;
|
|
300
309
|
const next = upsertBlock(existing, KNOWS_START, KNOWS_END, rendered, "bottom");
|
|
301
|
-
const stripStamp = (s) => s.replace(/ at=[^ ]+ -->/g, " -->");
|
|
310
|
+
const stripStamp = (s) => s.replace(/ at=[^ ]+( hash=[0-9a-f]+)? -->/g, " -->");
|
|
302
311
|
const changed = stripStamp(next) !== stripStamp(existing);
|
|
303
312
|
if (changed)
|
|
304
313
|
atomicWriteText(summaryPath, next);
|
|
@@ -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
|
|
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
|
}
|