@phren/cli 0.2.16 → 0.3.0
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/bridge/agent-hooks.d.ts +2 -0
- package/dist/bridge/agent-hooks.js +4 -0
- package/dist/bridge/code-note.d.ts +2 -1
- package/dist/bridge/code-note.js +13 -4
- package/dist/bridge/code-routes.d.ts +32 -14
- package/dist/bridge/code-routes.js +131 -8
- package/dist/bridge/dispatch-returns.d.ts +2 -0
- package/dist/bridge/dispatch-returns.js +12 -8
- package/dist/bridge/dispatch.d.ts +4 -1
- package/dist/bridge/dispatch.js +30 -5
- package/dist/bridge/install.d.ts +0 -4
- package/dist/bridge/install.js +3 -3
- package/dist/bridge/protocol.js +20 -1
- package/dist/bridge/schedule-watch.d.ts +2 -0
- package/dist/bridge/schedule-watch.js +16 -3
- package/dist/bridge/server-pane-routes.d.ts +7 -0
- package/dist/bridge/server-pane-routes.js +90 -11
- package/dist/bridge/server-routes.d.ts +2 -0
- package/dist/bridge/server-routes.js +44 -26
- package/dist/bridge/transcript-preview.d.ts +2 -0
- package/dist/bridge/transcript-preview.js +15 -0
- package/dist/bridge-hook.mjs +8842 -3209
- package/dist/cli/config-policy.js +25 -0
- package/dist/cli/extract.d.ts +0 -8
- package/dist/cli/extract.js +1 -1
- package/dist/cli-registry.js +7 -7
- package/dist/content/validate.d.ts +14 -3
- package/dist/content/validate.js +174 -114
- package/dist/data/access.d.ts +9 -0
- package/dist/data/access.js +18 -0
- package/dist/generated/memory-ui-graph.browser.js +520 -410
- package/dist/governance/policy.js +4 -3
- package/dist/hooks.d.ts +0 -15
- package/dist/hooks.js +1 -1
- package/dist/init/init-uninstall.js +13 -3
- package/dist/init/setup.js +19 -5
- package/dist/init/store-gitignore.d.ts +0 -5
- package/dist/init/store-gitignore.js +0 -8
- package/dist/link/context-imports.d.ts +15 -0
- package/dist/link/context-imports.js +101 -0
- package/dist/link/doctor.js +28 -4
- package/dist/mcp/profile.d.ts +0 -4
- package/dist/mcp/profile.js +0 -13
- package/dist/memory-ui-graph.runtime.js +520 -410
- package/dist/modules/code-package.js +10 -2
- package/dist/modules/registry.js +1 -1
- package/dist/profile-store.js +39 -3
- package/dist/project-topics.d.ts +1 -0
- package/dist/project-topics.js +9 -6
- package/dist/shared/retrieval.d.ts +0 -2
- package/dist/shared/retrieval.js +1 -1
- package/dist/tools/code.js +29 -21
- package/dist/tools/config.js +3 -0
- package/dist/tools/dispatch.js +1 -1
- package/dist/tools/finding.d.ts +11 -0
- package/dist/tools/finding.js +154 -99
- package/dist/ui/server.js +18 -1
- package/dist/update.js +21 -10
- package/package.json +7 -7
- package/starter/global/skills/conductor/SKILL.md +1 -1
|
@@ -3,6 +3,27 @@ import { getIndexPolicy, updateIndexPolicy, getRetentionPolicy, updateRetentionP
|
|
|
3
3
|
import { updateProjectConfigOverrides } from "../project-config.js";
|
|
4
4
|
import { isValidProjectName } from "../utils.js";
|
|
5
5
|
import { parseProjectArg, warnIfUnregistered } from "./config-shared.js";
|
|
6
|
+
/**
|
|
7
|
+
* Exit 1 unless every `set` token is a `--key=value` pair. The parsers below skip
|
|
8
|
+
* anything else, so `set ttlDays 90` or `set --ttlDays 90` used to write an
|
|
9
|
+
* unchanged config and print it as if the change had applied.
|
|
10
|
+
*/
|
|
11
|
+
function requireFlagPairs(setArgs, usage) {
|
|
12
|
+
const isPair = (arg) => {
|
|
13
|
+
if (!arg.startsWith("--"))
|
|
14
|
+
return false;
|
|
15
|
+
const [k, v] = arg.slice(2).split("=");
|
|
16
|
+
return Boolean(k) && v !== undefined;
|
|
17
|
+
};
|
|
18
|
+
const bad = setArgs.filter((arg) => !isPair(arg));
|
|
19
|
+
if (setArgs.length > 0 && bad.length === 0)
|
|
20
|
+
return;
|
|
21
|
+
console.error("No settings changed: every value must be given as --key=value.");
|
|
22
|
+
if (bad.length > 0)
|
|
23
|
+
console.error(` Not understood: ${bad.join(" ")}`);
|
|
24
|
+
console.error(` Usage: ${usage}`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
6
27
|
// ── Finding sensitivity config ────────────────────────────────────────────────
|
|
7
28
|
export const FINDING_SENSITIVITY_CONFIG = {
|
|
8
29
|
minimal: {
|
|
@@ -185,6 +206,7 @@ export async function handleRetentionPolicy(args) {
|
|
|
185
206
|
console.error(`Invalid project name: "${projectArg}"`);
|
|
186
207
|
process.exit(1);
|
|
187
208
|
}
|
|
209
|
+
requireFlagPairs(filteredArgs.slice(1), "phren config policy set --project <name> --ttlDays=90 --retentionDays=365");
|
|
188
210
|
warnIfUnregistered(phrenPath, projectArg);
|
|
189
211
|
updateProjectConfigOverrides(phrenPath, projectArg, (current) => {
|
|
190
212
|
const existingRetention = current.retentionPolicy ?? {};
|
|
@@ -211,6 +233,7 @@ export async function handleRetentionPolicy(args) {
|
|
|
211
233
|
console.log(JSON.stringify({ _project: projectArg, ...resolved.retentionPolicy }, null, 2));
|
|
212
234
|
return;
|
|
213
235
|
}
|
|
236
|
+
requireFlagPairs(filteredArgs.slice(1), "phren config policy set --ttlDays=90 --retentionDays=365");
|
|
214
237
|
const patch = {};
|
|
215
238
|
for (const arg of filteredArgs.slice(1)) {
|
|
216
239
|
if (!arg.startsWith("--"))
|
|
@@ -264,6 +287,7 @@ export async function handleWorkflowPolicy(args) {
|
|
|
264
287
|
console.error(`Invalid project name: "${projectArg}"`);
|
|
265
288
|
process.exit(1);
|
|
266
289
|
}
|
|
290
|
+
requireFlagPairs(filteredArgs.slice(1), "phren config workflow set --project <name> --lowConfidenceThreshold=0.7");
|
|
267
291
|
warnIfUnregistered(phrenPath, projectArg);
|
|
268
292
|
updateProjectConfigOverrides(phrenPath, projectArg, (current) => {
|
|
269
293
|
const nextConfig = { ...current };
|
|
@@ -298,6 +322,7 @@ export async function handleWorkflowPolicy(args) {
|
|
|
298
322
|
console.log(JSON.stringify({ _project: projectArg, ...resolved.workflowPolicy }, null, 2));
|
|
299
323
|
return;
|
|
300
324
|
}
|
|
325
|
+
requireFlagPairs(filteredArgs.slice(1), "phren config workflow set --lowConfidenceThreshold=0.7 --riskySections=Stale,Conflicts");
|
|
301
326
|
const patch = {};
|
|
302
327
|
for (const arg of filteredArgs.slice(1)) {
|
|
303
328
|
if (!arg.startsWith("--"))
|
package/dist/cli/extract.d.ts
CHANGED
|
@@ -18,14 +18,6 @@ export declare function scoreFindingCandidate(subject: string, body: string): {
|
|
|
18
18
|
score: number;
|
|
19
19
|
text: string;
|
|
20
20
|
} | null;
|
|
21
|
-
/**
|
|
22
|
-
* Dedup key for the human-readable part of a candidate.
|
|
23
|
-
*
|
|
24
|
-
* Hash dedup alone is necessary but not sufficient: rebased history re-scrapes an identical
|
|
25
|
-
* commit message under a new hash (observed pairs 0a918619/c55f38fa and 6b9a2ab9/9479d2ad),
|
|
26
|
-
* so the same finding still arrives twice.
|
|
27
|
-
*/
|
|
28
|
-
export declare function extractSubjectKey(text: string): string;
|
|
29
21
|
/**
|
|
30
22
|
* Render the provenance a queued candidate needs to stay promotable.
|
|
31
23
|
*
|
package/dist/cli/extract.js
CHANGED
|
@@ -231,7 +231,7 @@ function shortHash(hash) {
|
|
|
231
231
|
* commit message under a new hash (observed pairs 0a918619/c55f38fa and 6b9a2ab9/9479d2ad),
|
|
232
232
|
* so the same finding still arrives twice.
|
|
233
233
|
*/
|
|
234
|
-
|
|
234
|
+
function extractSubjectKey(text) {
|
|
235
235
|
return text
|
|
236
236
|
.replace(/<!--[\s\S]*?-->/g, " ")
|
|
237
237
|
.replace(new RegExp(SOURCE_COMMIT_MARKER.source, "gi"), " ")
|
package/dist/cli-registry.js
CHANGED
|
@@ -294,15 +294,15 @@ export const REGISTRY = [
|
|
|
294
294
|
name: "code",
|
|
295
295
|
topic: "core",
|
|
296
296
|
usage: "phren code <index|status|search|outline|refs|def|usage> [project]",
|
|
297
|
-
summary: "Index
|
|
297
|
+
summary: "Index a project's code and look up its functions, types and where they are used",
|
|
298
298
|
subcommands: [
|
|
299
299
|
{ name: "index", usage: "phren code index <project> [--full] [--repo <path>]", summary: "Build or refresh the code index" },
|
|
300
|
-
{ name: "status", usage: "phren code status <project> [--top <n>]", summary: "Show index counts, languages and
|
|
301
|
-
{ name: "search", usage: "phren code search <project> <query> [--kind k] [--limit n]", summary: "
|
|
302
|
-
{ name: "outline", usage: "phren code outline <project> <path>", summary: "A file's
|
|
303
|
-
{ name: "refs", usage: "phren code refs <project> <
|
|
304
|
-
{ name: "def", usage: "phren code def <project> <
|
|
305
|
-
{ name: "usage", usage: "phren code usage <project> [--top n]", summary: "
|
|
300
|
+
{ name: "status", usage: "phren code status <project> [--top <n>]", summary: "Show index counts, languages and the most used functions and types" },
|
|
301
|
+
{ name: "search", usage: "phren code search <project> <query> [--kind k] [--limit n]", summary: "Find functions, types and variables by name" },
|
|
302
|
+
{ name: "outline", usage: "phren code outline <project> <path>", summary: "A file's functions, types and variables in source order, nested" },
|
|
303
|
+
{ name: "refs", usage: "phren code refs <project> <name>", summary: "Where a function, type or variable is used, grouped by file" },
|
|
304
|
+
{ name: "def", usage: "phren code def <project> <name>", summary: "Where it is defined: doc, snippet and last change" },
|
|
305
|
+
{ name: "usage", usage: "phren code usage <project> [--top n]", summary: "Most and least used functions and types" },
|
|
306
306
|
],
|
|
307
307
|
run: async (args, ctx) => (await (await import("./modules/code-package.js")).requireCodePackage(ctx.phrenPath())).runCodeCommand(args, ctx),
|
|
308
308
|
},
|
|
@@ -50,11 +50,22 @@ export declare function extractConflictVersions(content: string): {
|
|
|
50
50
|
ours: string;
|
|
51
51
|
theirs: string;
|
|
52
52
|
} | null;
|
|
53
|
+
/** Raised when a merge would drop content; the caller must leave the conflict alone. */
|
|
54
|
+
export declare class FindingsMergeLossError extends Error {
|
|
55
|
+
}
|
|
53
56
|
/**
|
|
54
57
|
* Merge two FINDINGS.md versions: union entries per date, newest date first.
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
+
*
|
|
59
|
+
* Deduplicates by bullet text, keeping the continuation lines of whichever copy
|
|
60
|
+
* wins (ours takes priority). Preamble and trailing regions are unioned from
|
|
61
|
+
* **both** sides — taking them from `ours` alone silently deleted theirs'
|
|
62
|
+
* archive blocks and non-date sections.
|
|
63
|
+
*
|
|
64
|
+
* Runs unattended (push_changes, session-stop conflict recovery) and its result
|
|
65
|
+
* is committed and pushed, so it verifies itself: every content line of either
|
|
66
|
+
* input must appear in the output, and a merge that cannot manage that throws
|
|
67
|
+
* `FindingsMergeLossError` rather than committing the loss. Callers leave the
|
|
68
|
+
* conflict for the user.
|
|
58
69
|
*/
|
|
59
70
|
export declare function mergeFindings(ours: string, theirs: string): string;
|
|
60
71
|
/**
|
package/dist/content/validate.js
CHANGED
|
@@ -182,157 +182,217 @@ export function extractConflictVersions(content) {
|
|
|
182
182
|
}
|
|
183
183
|
return { ours: oursLines.join("\n"), theirs: theirsLines.join("\n") };
|
|
184
184
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
185
|
+
/** Does this line open a region that is not a live date section? */
|
|
186
|
+
function opensTrailingRegion(line) {
|
|
187
|
+
const trimmed = line.trim();
|
|
188
|
+
if (trimmed.startsWith("<details"))
|
|
189
|
+
return true;
|
|
190
|
+
if (trimmed.startsWith("<!-- phren:archive:start"))
|
|
191
|
+
return true;
|
|
192
|
+
if (line.startsWith("## ") && !/^\d{4}-\d{2}-\d{2}$/.test(line.slice(3).trim()))
|
|
193
|
+
return true;
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Parse FINDINGS.md into title / preamble / date sections / trailing.
|
|
198
|
+
*
|
|
199
|
+
* Two rules matter for not losing content:
|
|
200
|
+
*
|
|
201
|
+
* 1. A finding block is its bullet plus **every** following line up to the next
|
|
202
|
+
* bullet, heading, or blank line — not only `<!--` comments. Hand-written
|
|
203
|
+
* indented detail lines (" - rationale: …") used to end the block, which
|
|
204
|
+
* dropped them *and* the citation comment that followed them.
|
|
205
|
+
* 2. Once an archive wrapper (`<details>`, `<!-- phren:archive:start -->`) or a
|
|
206
|
+
* non-date `## ` section starts, everything after it is trailing content that
|
|
207
|
+
* is carried through verbatim. Parsing archived bullets as live date entries
|
|
208
|
+
* is how a merge promoted archived findings back into the active section.
|
|
209
|
+
*/
|
|
210
|
+
function parseFindings(content) {
|
|
211
|
+
const lines = content.split("\n");
|
|
212
|
+
const title = lines[0] ?? "# Findings";
|
|
213
|
+
const preamble = [];
|
|
214
|
+
const dates = new Map();
|
|
215
|
+
const trailing = [];
|
|
191
216
|
let currentDate = "";
|
|
192
217
|
let currentBlock = [];
|
|
193
|
-
|
|
194
|
-
|
|
218
|
+
let phase = "preamble";
|
|
219
|
+
const flush = () => {
|
|
220
|
+
if (currentBlock.length > 0 && currentDate) {
|
|
221
|
+
dates.get(currentDate).push(currentBlock.join("\n").replace(/\s+$/, ""));
|
|
222
|
+
}
|
|
223
|
+
currentBlock = [];
|
|
224
|
+
};
|
|
225
|
+
for (let i = 1; i < lines.length; i++) {
|
|
195
226
|
const line = lines[i];
|
|
196
|
-
if (
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
entries.get(currentDate).push(currentBlock.join("\n"));
|
|
200
|
-
currentBlock = [];
|
|
201
|
-
}
|
|
202
|
-
const heading = line.slice(3).trim();
|
|
203
|
-
if (/^\d{4}-\d{2}-\d{2}$/.test(heading)) {
|
|
204
|
-
currentDate = heading;
|
|
205
|
-
if (!entries.has(currentDate))
|
|
206
|
-
entries.set(currentDate, []);
|
|
207
|
-
}
|
|
227
|
+
if (phase === "trailing") {
|
|
228
|
+
trailing.push(line);
|
|
229
|
+
continue;
|
|
208
230
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
231
|
+
if (opensTrailingRegion(line)) {
|
|
232
|
+
flush();
|
|
233
|
+
phase = "trailing";
|
|
234
|
+
trailing.push(line);
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
if (line.startsWith("## ") && /^\d{4}-\d{2}-\d{2}$/.test(line.slice(3).trim())) {
|
|
238
|
+
flush();
|
|
239
|
+
phase = "dates";
|
|
240
|
+
currentDate = line.slice(3).trim();
|
|
241
|
+
if (!dates.has(currentDate))
|
|
242
|
+
dates.set(currentDate, []);
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
if (phase === "preamble") {
|
|
246
|
+
preamble.push(line);
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
if (line.startsWith("- ")) {
|
|
250
|
+
flush();
|
|
214
251
|
currentBlock = [line];
|
|
252
|
+
continue;
|
|
215
253
|
}
|
|
216
|
-
|
|
217
|
-
//
|
|
254
|
+
if (line.trim() !== "") {
|
|
255
|
+
// Either a continuation of the current finding (an indented sub-bullet, a
|
|
256
|
+
// metadata comment, a wrapped sentence) or, with no bullet open, a stray
|
|
257
|
+
// run of content — a fenced block, a stray paragraph. Both are kept as
|
|
258
|
+
// part of a block so the writer can put them back; dropping "lines the
|
|
259
|
+
// parser did not recognise" is what made this merge lossy.
|
|
218
260
|
currentBlock.push(line);
|
|
261
|
+
continue;
|
|
219
262
|
}
|
|
220
|
-
|
|
221
|
-
// Non-comment, non-bullet line: flush any pending block
|
|
222
|
-
if (currentBlock.length > 0 && currentDate) {
|
|
223
|
-
entries.get(currentDate).push(currentBlock.join("\n"));
|
|
224
|
-
currentBlock = [];
|
|
225
|
-
}
|
|
226
|
-
}
|
|
263
|
+
flush();
|
|
227
264
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
265
|
+
flush();
|
|
266
|
+
while (preamble.length > 0 && preamble[preamble.length - 1].trim() === "")
|
|
267
|
+
preamble.pop();
|
|
268
|
+
while (trailing.length > 0 && trailing[trailing.length - 1].trim() === "")
|
|
269
|
+
trailing.pop();
|
|
270
|
+
return { title, preamble, dates, trailing };
|
|
233
271
|
}
|
|
234
272
|
// Extract the bullet text from a finding block (first line) for dedup purposes
|
|
235
273
|
function findingBulletText(block) {
|
|
236
274
|
// Strip stable finding ID so two entries with different fids but same text are considered duplicates during merge.
|
|
237
275
|
return block.split("\n")[0].replace(METADATA_REGEX.findingId, "").replace(/\s+/g, " ").trim();
|
|
238
276
|
}
|
|
239
|
-
/**
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
break;
|
|
251
|
-
preamble.push(line);
|
|
277
|
+
/** Union two line lists, keeping order and dropping lines already present. */
|
|
278
|
+
function unionLines(ourLines, theirLines) {
|
|
279
|
+
const present = new Set(ourLines.map((line) => line.trim()).filter(Boolean));
|
|
280
|
+
const out = [...ourLines];
|
|
281
|
+
for (const line of theirLines) {
|
|
282
|
+
const key = line.trim();
|
|
283
|
+
if (key && present.has(key))
|
|
284
|
+
continue;
|
|
285
|
+
if (key)
|
|
286
|
+
present.add(key);
|
|
287
|
+
out.push(line);
|
|
252
288
|
}
|
|
253
|
-
|
|
254
|
-
|
|
289
|
+
while (out.length > 0 && out[out.length - 1].trim() === "")
|
|
290
|
+
out.pop();
|
|
291
|
+
return out;
|
|
255
292
|
}
|
|
256
293
|
/**
|
|
257
|
-
*
|
|
258
|
-
*
|
|
294
|
+
* Union trailing regions (archive `<details>` blocks, non-date sections).
|
|
295
|
+
*
|
|
296
|
+
* Segment-wise rather than line-wise: filtering individual lines could strip a
|
|
297
|
+
* bullet out of theirs' `<details>` block and leave a stray `</details>`. When
|
|
298
|
+
* one side's content lines are a subset of the other's, the subset is dropped —
|
|
299
|
+
* that covers the common "theirs is ours plus one archived finding" case. When
|
|
300
|
+
* they genuinely differ, both are emitted: a duplicated archive block is
|
|
301
|
+
* recoverable, a deleted one is not.
|
|
259
302
|
*/
|
|
260
|
-
function
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
303
|
+
function unionTrailing(ourTrailing, theirTrailing) {
|
|
304
|
+
if (ourTrailing.length === 0)
|
|
305
|
+
return [...theirTrailing];
|
|
306
|
+
if (theirTrailing.length === 0)
|
|
307
|
+
return [...ourTrailing];
|
|
308
|
+
const ourKeys = new Set(ourTrailing.map((line) => line.trim()).filter(Boolean));
|
|
309
|
+
const theirContent = theirTrailing.map((line) => line.trim()).filter(Boolean);
|
|
310
|
+
if (theirContent.every((line) => ourKeys.has(line)))
|
|
311
|
+
return [...ourTrailing];
|
|
312
|
+
const theirKeys = new Set(theirContent);
|
|
313
|
+
const ourContent = ourTrailing.map((line) => line.trim()).filter(Boolean);
|
|
314
|
+
if (ourContent.every((line) => theirKeys.has(line)))
|
|
315
|
+
return [...theirTrailing];
|
|
316
|
+
return [...ourTrailing, "", ...theirTrailing];
|
|
317
|
+
}
|
|
318
|
+
/** Content lines a merge must round-trip: no blanks, no title, no date headings. */
|
|
319
|
+
function significantLines(content) {
|
|
320
|
+
return content
|
|
321
|
+
.split("\n")
|
|
322
|
+
.slice(1)
|
|
323
|
+
.map((line) => line.trim())
|
|
324
|
+
.filter((line) => line !== "")
|
|
325
|
+
.filter((line) => !(line.startsWith("## ") && /^\d{4}-\d{2}-\d{2}$/.test(line.slice(3).trim())));
|
|
326
|
+
}
|
|
327
|
+
/** Raised when a merge would drop content; the caller must leave the conflict alone. */
|
|
328
|
+
export class FindingsMergeLossError extends Error {
|
|
282
329
|
}
|
|
283
330
|
/**
|
|
284
331
|
* Merge two FINDINGS.md versions: union entries per date, newest date first.
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
332
|
+
*
|
|
333
|
+
* Deduplicates by bullet text, keeping the continuation lines of whichever copy
|
|
334
|
+
* wins (ours takes priority). Preamble and trailing regions are unioned from
|
|
335
|
+
* **both** sides — taking them from `ours` alone silently deleted theirs'
|
|
336
|
+
* archive blocks and non-date sections.
|
|
337
|
+
*
|
|
338
|
+
* Runs unattended (push_changes, session-stop conflict recovery) and its result
|
|
339
|
+
* is committed and pushed, so it verifies itself: every content line of either
|
|
340
|
+
* input must appear in the output, and a merge that cannot manage that throws
|
|
341
|
+
* `FindingsMergeLossError` rather than committing the loss. Callers leave the
|
|
342
|
+
* conflict for the user.
|
|
288
343
|
*/
|
|
289
344
|
export function mergeFindings(ours, theirs) {
|
|
290
|
-
const
|
|
291
|
-
const
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
345
|
+
const { text, dedupedContinuations } = buildMergedFindings(ours, theirs);
|
|
346
|
+
const present = new Set(text.split("\n").map((line) => line.trim()));
|
|
347
|
+
const lost = [...significantLines(ours), ...significantLines(theirs)]
|
|
348
|
+
.filter((line) => !present.has(line))
|
|
349
|
+
// A block that lost a dedup race takes its own continuation lines with it —
|
|
350
|
+
// that is the intended rule (the finding is present, ours' provenance wins),
|
|
351
|
+
// not the content loss this guard exists to catch.
|
|
352
|
+
.filter((line) => !dedupedContinuations.has(line));
|
|
353
|
+
if (lost.length > 0) {
|
|
354
|
+
throw new FindingsMergeLossError(`Refusing to auto-merge ${FINDINGS_FILENAME}: ${lost.length} line(s) would be dropped, ` +
|
|
355
|
+
`starting with "${lost[0].slice(0, 80)}". Resolve this conflict by hand.`);
|
|
301
356
|
}
|
|
302
|
-
|
|
357
|
+
return text;
|
|
358
|
+
}
|
|
359
|
+
function buildMergedFindings(ours, theirs) {
|
|
360
|
+
const ourSide = parseFindings(ours);
|
|
361
|
+
const theirSide = parseFindings(theirs);
|
|
362
|
+
const allDates = [...new Set([...ourSide.dates.keys(), ...theirSide.dates.keys()])].sort().reverse();
|
|
363
|
+
const lines = [ourSide.title || theirSide.title || "# Findings"];
|
|
364
|
+
const dedupedContinuations = new Set();
|
|
365
|
+
const preamble = unionLines(ourSide.preamble, theirSide.preamble);
|
|
366
|
+
if (preamble.length > 0)
|
|
367
|
+
lines.push(...preamble, "");
|
|
368
|
+
else
|
|
303
369
|
lines.push("");
|
|
304
|
-
}
|
|
305
370
|
for (const date of allDates) {
|
|
306
|
-
const ourItems = ourEntries.get(date) ?? [];
|
|
307
|
-
const theirItems = theirEntries.get(date) ?? [];
|
|
308
|
-
// Dedup by bullet text, ours wins on conflict
|
|
309
371
|
const seen = new Set();
|
|
310
372
|
const merged = [];
|
|
311
|
-
for (const block of
|
|
373
|
+
for (const block of [...(ourSide.dates.get(date) ?? []), ...(theirSide.dates.get(date) ?? [])]) {
|
|
312
374
|
const key = findingBulletText(block);
|
|
313
|
-
if (
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
if (!seen.has(key)) {
|
|
321
|
-
seen.add(key);
|
|
322
|
-
merged.push(block);
|
|
375
|
+
if (seen.has(key)) {
|
|
376
|
+
for (const line of block.split("\n").slice(1)) {
|
|
377
|
+
const trimmed = line.trim();
|
|
378
|
+
if (trimmed)
|
|
379
|
+
dedupedContinuations.add(trimmed);
|
|
380
|
+
}
|
|
381
|
+
continue;
|
|
323
382
|
}
|
|
383
|
+
seen.add(key);
|
|
384
|
+
merged.push(block);
|
|
324
385
|
}
|
|
325
386
|
if (merged.length > 0) {
|
|
326
387
|
lines.push(`## ${date}`, "");
|
|
327
|
-
for (const block of merged)
|
|
388
|
+
for (const block of merged)
|
|
328
389
|
lines.push(block, "");
|
|
329
|
-
}
|
|
330
390
|
}
|
|
331
391
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
return lines.join("\n");
|
|
392
|
+
const trailing = unionTrailing(ourSide.trailing, theirSide.trailing);
|
|
393
|
+
if (trailing.length > 0)
|
|
394
|
+
lines.push(...trailing, "");
|
|
395
|
+
return { text: lines.join("\n"), dedupedContinuations };
|
|
336
396
|
}
|
|
337
397
|
/**
|
|
338
398
|
* Pattern for the stable bid comment embedded in task lines. The comment carries
|
package/dist/data/access.d.ts
CHANGED
|
@@ -137,6 +137,15 @@ export declare function approveQueueItem(phrenPath: string, project: string, lin
|
|
|
137
137
|
export declare function rejectQueueItemDetailed(phrenPath: string, project: string, lineText: string): PhrenResult<QueueRejectResult>;
|
|
138
138
|
/** Remove a queue item from review.md AND the corresponding finding wherever it lives. */
|
|
139
139
|
export declare function rejectQueueItem(phrenPath: string, project: string, lineText: string): PhrenResult<string>;
|
|
140
|
+
/**
|
|
141
|
+
* Drop a queue line and nothing else.
|
|
142
|
+
*
|
|
143
|
+
* Unlike `rejectQueueItem`, this never touches FINDINGS.md or `reference/topics/`.
|
|
144
|
+
* It is the verb for "stop asking me about this", not "this is wrong" — which is
|
|
145
|
+
* what automated expiry needs: a governance-queued finding that already lives in
|
|
146
|
+
* FINDINGS.md must survive its queue line timing out.
|
|
147
|
+
*/
|
|
148
|
+
export declare function dequeueQueueItem(phrenPath: string, project: string, lineText: string): PhrenResult<string>;
|
|
140
149
|
/** Edit a queue item's text in review.md and the corresponding finding in FINDINGS.md. */
|
|
141
150
|
export declare function editQueueItem(phrenPath: string, project: string, lineText: string, newText: string): PhrenResult<string>;
|
|
142
151
|
export declare function readReviewQueueAcrossProjects(phrenPath: string, profile?: string): PhrenResult<ProjectQueueItem[]>;
|
package/dist/data/access.js
CHANGED
|
@@ -782,6 +782,24 @@ export function rejectQueueItem(phrenPath, project, lineText) {
|
|
|
782
782
|
const result = rejectQueueItemDetailed(phrenPath, project, lineText);
|
|
783
783
|
return result.ok ? phrenOk(result.data.message) : result;
|
|
784
784
|
}
|
|
785
|
+
/**
|
|
786
|
+
* Drop a queue line and nothing else.
|
|
787
|
+
*
|
|
788
|
+
* Unlike `rejectQueueItem`, this never touches FINDINGS.md or `reference/topics/`.
|
|
789
|
+
* It is the verb for "stop asking me about this", not "this is wrong" — which is
|
|
790
|
+
* what automated expiry needs: a governance-queued finding that already lives in
|
|
791
|
+
* FINDINGS.md must survive its queue line timing out.
|
|
792
|
+
*/
|
|
793
|
+
export function dequeueQueueItem(phrenPath, project, lineText) {
|
|
794
|
+
const located = locateQueueLine(phrenPath, project, lineText);
|
|
795
|
+
if (!located.ok)
|
|
796
|
+
return forwardErr(located);
|
|
797
|
+
const dequeued = dequeueLine(phrenPath, project, lineText);
|
|
798
|
+
if (!dequeued.ok)
|
|
799
|
+
return forwardErr(dequeued);
|
|
800
|
+
appendAuditLog(phrenPath, "review_dequeue", `project=${project}`);
|
|
801
|
+
return phrenOk(`Removed queue item from ${project} (content left untouched)`);
|
|
802
|
+
}
|
|
785
803
|
/** Edit a queue item's text in review.md and the corresponding finding in FINDINGS.md. */
|
|
786
804
|
export function editQueueItem(phrenPath, project, lineText, newText) {
|
|
787
805
|
const trimmed = newText.replace(/[\r\n]+/g, " ").trim();
|