@phren/cli 0.3.44 → 0.3.46
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-hook-asks.d.ts +34 -0
- package/dist/bridge/agent-hook-asks.js +72 -0
- package/dist/bridge/agent-hook-callback.d.ts +22 -0
- package/dist/bridge/agent-hook-callback.js +114 -0
- package/dist/bridge/agent-hooks.d.ts +7 -74
- package/dist/bridge/agent-hooks.js +22 -186
- package/dist/bridge/claude-question-dialog.d.ts +6 -0
- package/dist/bridge/claude-question-dialog.js +29 -7
- package/dist/bridge/codex-app-server.d.ts +5 -0
- package/dist/bridge/codex-app-server.js +15 -0
- package/dist/bridge/codex-auth-refresh.js +7 -0
- package/dist/bridge/dispatch-command.js +7 -1
- package/dist/bridge/file-write.js +3 -1
- package/dist/bridge/git-host-auth.d.ts +6 -0
- package/dist/bridge/git-host-auth.js +45 -0
- package/dist/bridge/git-publish.d.ts +1 -1
- package/dist/bridge/git-publish.js +75 -8
- package/dist/bridge/git-review.js +23 -2
- package/dist/bridge/git.d.ts +5 -1
- package/dist/bridge/git.js +103 -8
- package/dist/bridge/health.d.ts +1 -0
- package/dist/bridge/health.js +8 -5
- package/dist/bridge/lookup-cache.d.ts +17 -0
- package/dist/bridge/lookup-cache.js +70 -0
- package/dist/bridge/memory-store.js +40 -14
- package/dist/bridge/pair.js +4 -0
- package/dist/bridge/peers.js +36 -0
- package/dist/bridge/projects.d.ts +14 -0
- package/dist/bridge/projects.js +48 -1
- package/dist/bridge/prompt-deliveries.d.ts +38 -3
- package/dist/bridge/prompt-deliveries.js +196 -36
- package/dist/bridge/schedule-format.d.ts +4 -0
- package/dist/bridge/schedule-format.js +34 -0
- package/dist/bridge/schedule-problems.js +4 -0
- package/dist/bridge/scoped-gateway.d.ts +1 -0
- package/dist/bridge/scoped-gateway.js +10 -1
- package/dist/bridge/server-launch.js +6 -2
- package/dist/bridge/server-routes.js +5 -1
- package/dist/bridge/session-activity.d.ts +10 -0
- package/dist/bridge/session-activity.js +25 -0
- package/dist/bridge/session-servers.js +3 -0
- package/dist/bridge/{codex-thread-origin.d.ts → thread-origin.d.ts} +8 -0
- package/dist/bridge/{codex-thread-origin.js → thread-origin.js} +24 -6
- package/dist/bridge/usage.d.ts +4 -0
- package/dist/bridge/usage.js +22 -8
- package/dist/bridge-hook.mjs +1149 -469
- package/dist/cli/namespaces-tasks.js +19 -5
- package/dist/cli/ops.d.ts +1 -1
- package/dist/cli/ops.js +2 -2
- package/dist/cli/schedules.js +16 -9
- package/dist/content/summarize.js +46 -6
- package/dist/content/validate.d.ts +3 -1
- package/dist/content/validate.js +33 -4
- package/dist/data/access.d.ts +8 -1
- package/dist/data/access.js +27 -9
- package/dist/data/notes.d.ts +2 -0
- package/dist/data/notes.js +2 -1
- package/dist/entrypoint.js +2 -1
- package/dist/generated/memory-ui-graph.browser.js +1 -1
- package/dist/governance/locks.js +17 -1
- package/dist/governance/policy.js +37 -23
- package/dist/link/link.js +6 -1
- package/dist/memory-ui-graph.runtime.js +1 -1
- package/dist/sync/conflict-resolve.d.ts +1 -1
- package/dist/sync/conflict-resolve.js +91 -8
- package/dist/task/lifecycle.js +2 -1
- package/package.json +1 -1
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as path from "node:path";
|
|
3
|
-
import { getPhrenPath } from "../shared.js";
|
|
3
|
+
import { findProjectNameCaseInsensitive, getPhrenPath } from "../shared.js";
|
|
4
|
+
import { resolveRuntimeProfile } from "../runtime-profile.js";
|
|
4
5
|
import { enableTaskFormat, taskFormatStatus, taskFormatMigrationHint, taskFormatCurrentWriters } from "../data/task-format.js";
|
|
5
6
|
import { resolveAllStores } from "../store-registry.js";
|
|
6
7
|
import { addTask, completeTask, updateTask, reorderTask, pinTask, removeTask, workNextTask, tidyDoneTasks, linkTaskIssue, promoteTask, resolveTaskItem } from "../data/tasks.js";
|
|
7
8
|
import { buildTaskIssueBody, createGithubIssueForTask, parseGithubIssueUrl, resolveProjectGithubRepo } from "../task/github.js";
|
|
8
9
|
function printTaskUsage() {
|
|
9
10
|
console.log("Usage:");
|
|
10
|
-
console.log(' phren task list [profile] [--responsibility=human|agent] [--readiness=ready|waiting-on-human|waiting-on-task]');
|
|
11
|
+
console.log(' phren task list [profile|project] [--responsibility=human|agent] [--readiness=ready|waiting-on-human|waiting-on-task]');
|
|
11
12
|
console.log(' phren task format [--json | enable --all-writers-compatible]');
|
|
12
13
|
console.log(' phren task add <project> "<text>"');
|
|
13
14
|
console.log(' phren task complete <project> "<text>"');
|
|
@@ -46,7 +47,7 @@ export async function handleTaskNamespace(args) {
|
|
|
46
47
|
}
|
|
47
48
|
if (subcommand === "list") {
|
|
48
49
|
// Delegate to the cross-project task view (same as `phren tasks`)
|
|
49
|
-
return handleTaskListArgs(args.slice(1),
|
|
50
|
+
return handleTaskListArgs(args.slice(1), resolveRuntimeProfile(getPhrenPath()));
|
|
50
51
|
}
|
|
51
52
|
if (subcommand === "format") {
|
|
52
53
|
const store = taskFormatStore(getPhrenPath());
|
|
@@ -454,6 +455,19 @@ export async function handleTaskListArgs(args, defaultProfile) {
|
|
|
454
455
|
throw new Error("Invalid task responsibility/readiness filter; use --responsibility=human|agent or --readiness=ready|waiting-on-human|waiting-on-task.");
|
|
455
456
|
const profiles = args.filter(a => !a.startsWith("--"));
|
|
456
457
|
if (profiles.length > 1)
|
|
457
|
-
throw new Error("Pass at most one task profile.");
|
|
458
|
-
|
|
458
|
+
throw new Error("Pass at most one task profile or project.");
|
|
459
|
+
// `phren task list phren` names a project as often as a profile: a name that is a
|
|
460
|
+
// project of the active profile lists just that project instead of an empty profile.
|
|
461
|
+
const { readTasksAcrossProjects } = await import("../data/access.js");
|
|
462
|
+
const project = profiles[0] && readTasksAcrossProjects(getPhrenPath(), defaultProfile).some(doc => doc.project.toLowerCase() === profiles[0].toLowerCase()) ? profiles[0] : undefined;
|
|
463
|
+
if (profiles[0] && !project) {
|
|
464
|
+
const { listProfiles } = await import("../profile-store.js");
|
|
465
|
+
const known = listProfiles(getPhrenPath());
|
|
466
|
+
const isProfile = known.ok && known.data.some(p => p.name === profiles[0]);
|
|
467
|
+
if (!isProfile && !findProjectNameCaseInsensitive(getPhrenPath(), profiles[0])) {
|
|
468
|
+
console.error(`"${profiles[0]}" is neither a profile nor a project.`);
|
|
469
|
+
process.exit(1);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
return handleTaskView(project ? defaultProfile : profiles[0] || defaultProfile, filter.data, project);
|
|
459
473
|
}
|
package/dist/cli/ops.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type TaskFilter } from "../data/task-contract.js";
|
|
2
|
-
export declare function handleTaskView(profile: string, filter?: TaskFilter): void;
|
|
2
|
+
export declare function handleTaskView(profile: string, filter?: TaskFilter, project?: string): void;
|
|
3
3
|
export declare function handleSessionsView(args: string[]): Promise<void>;
|
|
4
4
|
export declare function handleQuickstart(): Promise<void>;
|
|
5
5
|
export declare function handleDebugInjection(args: string[], profile: string): Promise<void>;
|
package/dist/cli/ops.js
CHANGED
|
@@ -9,8 +9,8 @@ import { applyGravity } from "../data/tasks.js";
|
|
|
9
9
|
import { buildIndex, queryRows } from "../shared/index.js";
|
|
10
10
|
import { resolveSubprocessArgs } from "./hooks.js";
|
|
11
11
|
import { listAllSessions, getSessionArtifacts } from "../tools/session.js";
|
|
12
|
-
export function handleTaskView(profile, filter = {}) {
|
|
13
|
-
const docs = readTasksAcrossProjects(getPhrenPath(), profile);
|
|
12
|
+
export function handleTaskView(profile, filter = {}, project) {
|
|
13
|
+
const docs = readTasksAcrossProjects(getPhrenPath(), profile).filter(doc => !project || doc.project.toLowerCase() === project.toLowerCase());
|
|
14
14
|
if (!docs.length) {
|
|
15
15
|
console.log("No tasks found.");
|
|
16
16
|
return;
|
package/dist/cli/schedules.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import { request } from "node:http";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { SCHEDULE_EVERY, SCHEDULE_HARNESSES, SCHEDULE_SESSIONS, WEEKDAYS, computerMatches, canonicalComputer, newScheduleId, parseSchedule, readScheduleDocument, writeScheduleDocument, } from "../bridge/schedules.js";
|
|
4
|
+
import { SCHEDULE_EVERY, SCHEDULE_HARNESSES, SCHEDULE_SESSIONS, WEEKDAYS, computerMatches, canonicalComputer, newScheduleId, parseSchedule, readScheduleDocument, withScheduleLock, writeScheduleDocument, } from "../bridge/schedules.js";
|
|
5
5
|
import { object, socketPath } from "../bridge/protocol.js";
|
|
6
6
|
import { listMachines } from "../profile-store.js";
|
|
7
7
|
import { getProjectDirs } from "../shared.js";
|
|
@@ -101,19 +101,26 @@ async function add(store, args) {
|
|
|
101
101
|
const problems = await scheduleProblems(validated, path.basename(directory), { store, owned: ownsHere(validated) });
|
|
102
102
|
if (problems.length)
|
|
103
103
|
throw new Error(`This schedule could not run: ${problems.join(" ")}`);
|
|
104
|
-
|
|
104
|
+
// Append to the file as it is now, under the lock every schedules.yaml writer takes.
|
|
105
|
+
await withScheduleLock(directory, async () => {
|
|
106
|
+
const current = await readScheduleDocument(directory);
|
|
107
|
+
await writeScheduleDocument(directory, [...current.schedules, validated], current.document);
|
|
108
|
+
});
|
|
105
109
|
console.log(`Added schedule ${validated.id} to ${path.basename(directory)}.`);
|
|
106
110
|
}
|
|
107
111
|
async function mutate(store, action, projectName, id) {
|
|
108
112
|
if (!projectName || !id)
|
|
109
113
|
throw new Error(`Usage: phren schedule ${action} <project> <id>`);
|
|
110
|
-
const directory = projectDirectory(store, projectName)
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
const directory = projectDirectory(store, projectName);
|
|
115
|
+
await withScheduleLock(directory, async () => {
|
|
116
|
+
const file = await readScheduleDocument(directory);
|
|
117
|
+
const existing = file.schedules.find(schedule => schedule.id === id);
|
|
118
|
+
if (!existing)
|
|
119
|
+
throw new Error(`Schedule "${id}" was not found in ${path.basename(directory)}.`);
|
|
120
|
+
const schedules = action === "remove" ? file.schedules.filter(schedule => schedule.id !== id)
|
|
121
|
+
: file.schedules.map(schedule => schedule.id === id ? { ...schedule, enabled: action === "enable", updatedAt: new Date().toISOString() } : schedule);
|
|
122
|
+
await writeScheduleDocument(directory, schedules, file.document);
|
|
123
|
+
});
|
|
117
124
|
console.log(`${action === "remove" ? "Removed" : action === "enable" ? "Enabled" : "Disabled"} schedule ${id}.`);
|
|
118
125
|
}
|
|
119
126
|
async function hookPost(route, data) {
|
|
@@ -23,6 +23,7 @@ import { readProjectTopics, topicReferencePath } from "../project-topics.js";
|
|
|
23
23
|
import { storeAwareProjectPath } from "../store-routing.js";
|
|
24
24
|
import { atomicWriteText, debugLog } from "../phren-paths.js";
|
|
25
25
|
import { errorMessage } from "../utils.js";
|
|
26
|
+
import { withFileLock } from "../governance/locks.js";
|
|
26
27
|
export const NOW_START = "<!-- phren:now:start -->";
|
|
27
28
|
export const NOW_END = "<!-- phren:now:end -->";
|
|
28
29
|
export const KNOWS_START = "<!-- phren:knows:start -->";
|
|
@@ -289,13 +290,47 @@ export function splitTopicFile(filePath, maxBullets = TOPIC_SPLIT_AT) {
|
|
|
289
290
|
return null;
|
|
290
291
|
const olderPath = filePath.replace(/\.md$/, ".older.md");
|
|
291
292
|
const title = head.find((l) => l.startsWith("# ")) ?? "# archive";
|
|
292
|
-
|
|
293
|
-
|
|
293
|
+
// The older file has writers of its own (a review rejection removes bullets
|
|
294
|
+
// from it): read and rewrite it under its lock, always taken after the topic's.
|
|
295
|
+
withFileLock(olderPath, () => {
|
|
296
|
+
const prior = fs.existsSync(olderPath) ? fs.readFileSync(olderPath, "utf8").trimEnd() + "\n\n" : `${title} (older archive)\n\nSections moved here from ${path.basename(filePath)} once it passed ${maxBullets} bullets. Still indexed; still searchable.\n\n`;
|
|
297
|
+
atomicWriteText(olderPath, prior + moved.map((sec) => sec.join("\n").trimEnd()).join("\n\n") + "\n");
|
|
298
|
+
});
|
|
294
299
|
atomicWriteText(filePath, [...head, ...keep.flat()].join("\n").trimEnd() + "\n");
|
|
295
300
|
return olderPath;
|
|
296
301
|
}
|
|
302
|
+
/** Attempts at writing a topic block before giving up because the file keeps changing underneath. */
|
|
303
|
+
const TOPIC_WRITE_ATTEMPTS = 3;
|
|
304
|
+
/**
|
|
305
|
+
* Writes `next` only if the topic still reads `expected`, under the same file
|
|
306
|
+
* lock the archive pass appends with. False when it changed meanwhile.
|
|
307
|
+
*/
|
|
308
|
+
function writeIfUnchanged(filePath, expected, next) {
|
|
309
|
+
return withFileLock(filePath, () => {
|
|
310
|
+
if (fs.readFileSync(filePath, "utf8") !== expected)
|
|
311
|
+
return false;
|
|
312
|
+
if (next !== expected)
|
|
313
|
+
atomicWriteText(filePath, next);
|
|
314
|
+
return true;
|
|
315
|
+
});
|
|
316
|
+
}
|
|
297
317
|
export async function summarizeTopicFile(filePath, slug, opts = {}) {
|
|
298
|
-
const split = splitTopicFile(filePath);
|
|
318
|
+
const split = withFileLock(filePath, () => splitTopicFile(filePath));
|
|
319
|
+
// The model can take minutes; findings archived into this topic meanwhile
|
|
320
|
+
// must not be overwritten by the snapshot it was given, so every write
|
|
321
|
+
// re-reads under the lock and starts over when the file moved.
|
|
322
|
+
for (let attempt = 1;; attempt++) {
|
|
323
|
+
const result = await summarizeTopicOnce(filePath, slug, opts, split);
|
|
324
|
+
if (result)
|
|
325
|
+
return result;
|
|
326
|
+
if (attempt >= TOPIC_WRITE_ATTEMPTS) {
|
|
327
|
+
debugLog(`summarize: ${slug} kept changing while it was summarized; left as it was`);
|
|
328
|
+
const current = fs.readFileSync(filePath, "utf8");
|
|
329
|
+
return { slug, file: filePath, bullets: parseTopicBullets(current).length, updated: false, split: split ?? undefined, now: blockBody(current, NOW_START, NOW_END) ?? "" };
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
async function summarizeTopicOnce(filePath, slug, opts, split) {
|
|
299
334
|
const content = fs.readFileSync(filePath, "utf8");
|
|
300
335
|
const stamp = (opts.now ?? (() => new Date()))().toISOString();
|
|
301
336
|
const prev = blockMeta(content, NOW_START);
|
|
@@ -309,7 +344,8 @@ export async function summarizeTopicFile(filePath, slug, opts = {}) {
|
|
|
309
344
|
const e = content.indexOf(NOW_END);
|
|
310
345
|
if (s !== -1 && e !== -1 && e > s) {
|
|
311
346
|
const stripped = `${content.slice(0, s)}${content.slice(e + NOW_END.length)}`.replace(/\n{3,}/g, "\n\n");
|
|
312
|
-
|
|
347
|
+
if (!writeIfUnchanged(filePath, content, stripped))
|
|
348
|
+
return null;
|
|
313
349
|
return { slug, file: filePath, bullets: 0, updated: true, now: "" };
|
|
314
350
|
}
|
|
315
351
|
return { slug, file: filePath, bullets: 0, updated: false, now: "" };
|
|
@@ -325,8 +361,8 @@ export async function summarizeTopicFile(filePath, slug, opts = {}) {
|
|
|
325
361
|
if (!now)
|
|
326
362
|
now = structuralNow(digest);
|
|
327
363
|
const next = upsertBlock(content, NOW_START, NOW_END, block(NOW_START, NOW_END, "## Now", now, stamp, fingerprint), "top");
|
|
328
|
-
if (
|
|
329
|
-
|
|
364
|
+
if (!writeIfUnchanged(filePath, content, next))
|
|
365
|
+
return null;
|
|
330
366
|
return { slug, file: filePath, bullets: bullets.length, updated: next !== content, split: split ?? undefined, now };
|
|
331
367
|
}
|
|
332
368
|
export function countActiveFindingsIn(findingsPath) {
|
|
@@ -487,6 +523,10 @@ export function setTopicSummary(filePath, text, now = () => new Date()) {
|
|
|
487
523
|
const paragraph = text.replace(/\s+/g, " ").trim();
|
|
488
524
|
if (paragraph.length < 40)
|
|
489
525
|
return { ok: false, error: "A summary needs at least a couple of sentences." };
|
|
526
|
+
// Read and write under the topic's lock, or a finding archived in between is lost.
|
|
527
|
+
return withFileLock(filePath, () => writeTopicSummary(filePath, paragraph, now));
|
|
528
|
+
}
|
|
529
|
+
function writeTopicSummary(filePath, paragraph, now) {
|
|
490
530
|
const content = fs.readFileSync(filePath, "utf8");
|
|
491
531
|
const bullets = parseTopicBullets(content);
|
|
492
532
|
if (!bullets.length)
|
|
@@ -55,6 +55,8 @@ export declare class FindingsMergeLossError extends Error {
|
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* Merge two FINDINGS.md versions: union entries per date, newest date first.
|
|
58
|
+
* Given the merge base, a finding one side removed and the other left
|
|
59
|
+
* untouched stays removed instead of coming back from the union.
|
|
58
60
|
*
|
|
59
61
|
* Deduplicates by bullet text, keeping the continuation lines of whichever copy
|
|
60
62
|
* wins (ours takes priority). Preamble and trailing regions are unioned from
|
|
@@ -67,7 +69,7 @@ export declare class FindingsMergeLossError extends Error {
|
|
|
67
69
|
* `FindingsMergeLossError` rather than committing the loss. Callers leave the
|
|
68
70
|
* conflict for the user.
|
|
69
71
|
*/
|
|
70
|
-
export declare function mergeFindings(ours: string, theirs: string): string;
|
|
72
|
+
export declare function mergeFindings(ours: string, theirs: string, base?: string): string;
|
|
71
73
|
/**
|
|
72
74
|
* Merge two tasks.md versions: union items per section, deduplicated by stable ID when
|
|
73
75
|
* present or by normalised bullet text otherwise. Context/continuation lines are preserved.
|
package/dist/content/validate.js
CHANGED
|
@@ -329,6 +329,8 @@ export class FindingsMergeLossError extends Error {
|
|
|
329
329
|
}
|
|
330
330
|
/**
|
|
331
331
|
* Merge two FINDINGS.md versions: union entries per date, newest date first.
|
|
332
|
+
* Given the merge base, a finding one side removed and the other left
|
|
333
|
+
* untouched stays removed instead of coming back from the union.
|
|
332
334
|
*
|
|
333
335
|
* Deduplicates by bullet text, keeping the continuation lines of whichever copy
|
|
334
336
|
* wins (ours takes priority). Preamble and trailing regions are unioned from
|
|
@@ -341,22 +343,47 @@ export class FindingsMergeLossError extends Error {
|
|
|
341
343
|
* `FindingsMergeLossError` rather than committing the loss. Callers leave the
|
|
342
344
|
* conflict for the user.
|
|
343
345
|
*/
|
|
344
|
-
export function mergeFindings(ours, theirs) {
|
|
345
|
-
const
|
|
346
|
+
export function mergeFindings(ours, theirs, base) {
|
|
347
|
+
const removed = base === undefined ? new Map() : removedFindings(base, ours, theirs);
|
|
348
|
+
const { text, dedupedContinuations } = buildMergedFindings(ours, theirs, removed);
|
|
349
|
+
const removedLines = new Set([...removed.values()].flatMap((block) => block.split("\n").map((line) => line.trim())));
|
|
346
350
|
const present = new Set(text.split("\n").map((line) => line.trim()));
|
|
347
351
|
const lost = [...significantLines(ours), ...significantLines(theirs)]
|
|
348
352
|
.filter((line) => !present.has(line))
|
|
349
353
|
// A block that lost a dedup race takes its own continuation lines with it —
|
|
350
354
|
// that is the intended rule (the finding is present, ours' provenance wins),
|
|
351
355
|
// not the content loss this guard exists to catch.
|
|
352
|
-
.filter((line) => !dedupedContinuations.has(line))
|
|
356
|
+
.filter((line) => !dedupedContinuations.has(line))
|
|
357
|
+
// A finding one side removed and the other left as it was is meant to go.
|
|
358
|
+
.filter((line) => !removedLines.has(line));
|
|
353
359
|
if (lost.length > 0) {
|
|
354
360
|
throw new FindingsMergeLossError(`Refusing to auto-merge ${FINDINGS_FILENAME}: ${lost.length} line(s) would be dropped, ` +
|
|
355
361
|
`starting with "${lost[0].slice(0, 80)}". Resolve this conflict by hand.`);
|
|
356
362
|
}
|
|
357
363
|
return text;
|
|
358
364
|
}
|
|
359
|
-
|
|
365
|
+
/**
|
|
366
|
+
* Findings the merge base had that one side removed (archived, deleted or
|
|
367
|
+
* rewrote) while the other left them exactly as they were, keyed by bullet
|
|
368
|
+
* text. A union of both sides would bring them back.
|
|
369
|
+
*/
|
|
370
|
+
function removedFindings(base, ours, theirs) {
|
|
371
|
+
const blocks = (content) => {
|
|
372
|
+
const byKey = new Map();
|
|
373
|
+
for (const list of parseFindings(content).dates.values())
|
|
374
|
+
for (const block of list)
|
|
375
|
+
byKey.set(findingBulletText(block), block);
|
|
376
|
+
return byKey;
|
|
377
|
+
};
|
|
378
|
+
const [b, o, t] = [blocks(base), blocks(ours), blocks(theirs)];
|
|
379
|
+
const removed = new Map();
|
|
380
|
+
for (const [key, block] of b) {
|
|
381
|
+
if ((!o.has(key) && t.get(key) === block) || (!t.has(key) && o.get(key) === block))
|
|
382
|
+
removed.set(key, block);
|
|
383
|
+
}
|
|
384
|
+
return removed;
|
|
385
|
+
}
|
|
386
|
+
function buildMergedFindings(ours, theirs, removed = new Map()) {
|
|
360
387
|
const ourSide = parseFindings(ours);
|
|
361
388
|
const theirSide = parseFindings(theirs);
|
|
362
389
|
const allDates = [...new Set([...ourSide.dates.keys(), ...theirSide.dates.keys()])].sort().reverse();
|
|
@@ -372,6 +399,8 @@ function buildMergedFindings(ours, theirs) {
|
|
|
372
399
|
const merged = [];
|
|
373
400
|
for (const block of [...(ourSide.dates.get(date) ?? []), ...(theirSide.dates.get(date) ?? [])]) {
|
|
374
401
|
const key = findingBulletText(block);
|
|
402
|
+
if (removed.has(key))
|
|
403
|
+
continue;
|
|
375
404
|
if (seen.has(key)) {
|
|
376
405
|
for (const line of block.split("\n").slice(1)) {
|
|
377
406
|
const trimmed = line.trim();
|
package/dist/data/access.d.ts
CHANGED
|
@@ -72,7 +72,14 @@ export declare function readFindings(phrenPath: string, project: string, opts?:
|
|
|
72
72
|
export declare function parseFindingsContent(content: string, opts?: ReadFindingsOptions): FindingItem[];
|
|
73
73
|
export declare function readFindingHistory(phrenPath: string, project: string, findingId?: string): PhrenResult<FindingHistoryEntry[]>;
|
|
74
74
|
export declare function addFinding(phrenPath: string, project: string, learning: string): PhrenResult<AddFindingResult>;
|
|
75
|
-
|
|
75
|
+
/**
|
|
76
|
+
* `exactOnly` accepts only a fid or the whole normalized text (a type tag aside): a caller that
|
|
77
|
+
* holds a finding's full text (review-queue reject) must never delete a
|
|
78
|
+
* different finding that merely contains it.
|
|
79
|
+
*/
|
|
80
|
+
export declare function removeFinding(phrenPath: string, project: string, match: string, opts?: {
|
|
81
|
+
exactOnly?: boolean;
|
|
82
|
+
}): PhrenResult<string>;
|
|
76
83
|
export declare function removeFindings(phrenPath: string, project: string, matches: string[]): PhrenResult<{
|
|
77
84
|
removed: string[];
|
|
78
85
|
errors: string[];
|
package/dist/data/access.js
CHANGED
|
@@ -74,7 +74,8 @@ function resolveDuplicateMatches(matches) {
|
|
|
74
74
|
const first = bulletContentKey(matches[0].line);
|
|
75
75
|
return matches.every(({ line }) => bulletContentKey(line) === first) ? matches[0] : null;
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
const withoutTypeTag = (text) => text.replace(/^\[[a-z-]+\]\s*/i, "");
|
|
78
|
+
function findMatchingFindingBullet(bulletLines, needle, match, exactOnly = false) {
|
|
78
79
|
const fidNeedle = needle.replace(/^fid:/, "");
|
|
79
80
|
const fidMatch = /^[a-z0-9]{8}$/.test(fidNeedle)
|
|
80
81
|
? bulletLines.filter(({ line }) => new RegExp(`<!--\\s*fid:${fidNeedle}\\s*-->`).test(line))
|
|
@@ -91,6 +92,17 @@ function findMatchingFindingBullet(bulletLines, needle, match) {
|
|
|
91
92
|
return { kind: "found", idx: dup.i };
|
|
92
93
|
return { kind: "ambiguous", error: `"${match}" is ambiguous (${exactMatches.length} exact matches). Use a more specific phrase.` };
|
|
93
94
|
}
|
|
95
|
+
if (exactOnly) {
|
|
96
|
+
// The whole text, allowing only a type tag one side lacks ("[pattern] ").
|
|
97
|
+
const bare = withoutTypeTag(needle);
|
|
98
|
+
const tagged = bulletLines.filter(({ line }) => withoutTypeTag(normalizeFindingText(line)) === bare);
|
|
99
|
+
if (tagged.length === 0)
|
|
100
|
+
return { kind: "not_found" };
|
|
101
|
+
const dup = tagged.length === 1 ? tagged[0] : resolveDuplicateMatches(tagged);
|
|
102
|
+
if (dup)
|
|
103
|
+
return { kind: "found", idx: dup.i };
|
|
104
|
+
return { kind: "ambiguous", error: `"${match}" is ambiguous (${tagged.length} matches). Use a more specific phrase.` };
|
|
105
|
+
}
|
|
94
106
|
if (partialMatches.length === 1)
|
|
95
107
|
return { kind: "found", idx: partialMatches[0].i };
|
|
96
108
|
if (partialMatches.length > 1) {
|
|
@@ -308,7 +320,12 @@ export function addFinding(phrenPath, project, learning) {
|
|
|
308
320
|
// addFindingToFile handles its own file lock; no double-wrap
|
|
309
321
|
return addFindingToFile(phrenPath, project, learning);
|
|
310
322
|
}
|
|
311
|
-
|
|
323
|
+
/**
|
|
324
|
+
* `exactOnly` accepts only a fid or the whole normalized text (a type tag aside): a caller that
|
|
325
|
+
* holds a finding's full text (review-queue reject) must never delete a
|
|
326
|
+
* different finding that merely contains it.
|
|
327
|
+
*/
|
|
328
|
+
export function removeFinding(phrenPath, project, match, opts = {}) {
|
|
312
329
|
const ensured = ensureProject(phrenPath, project);
|
|
313
330
|
if (!ensured.ok)
|
|
314
331
|
return forwardErr(ensured);
|
|
@@ -323,12 +340,12 @@ export function removeFinding(phrenPath, project, match) {
|
|
|
323
340
|
const lines = fs.readFileSync(filePath, "utf8").split("\n");
|
|
324
341
|
const needle = normalizeFindingText(match);
|
|
325
342
|
const bulletLines = collectFindingBulletLines(lines);
|
|
326
|
-
const activeMatch = findMatchingFindingBullet(bulletLines.filter(({ archived }) => !archived), needle, match);
|
|
343
|
+
const activeMatch = findMatchingFindingBullet(bulletLines.filter(({ archived }) => !archived), needle, match, opts.exactOnly);
|
|
327
344
|
if (activeMatch.kind === "ambiguous") {
|
|
328
345
|
return phrenErr(activeMatch.error, PhrenError.AMBIGUOUS_MATCH);
|
|
329
346
|
}
|
|
330
347
|
if (activeMatch.kind === "not_found") {
|
|
331
|
-
const archivedMatch = findMatchingFindingBullet(bulletLines.filter(({ archived }) => archived), needle, match);
|
|
348
|
+
const archivedMatch = findMatchingFindingBullet(bulletLines.filter(({ archived }) => archived), needle, match, opts.exactOnly);
|
|
332
349
|
if (archivedMatch.kind === "ambiguous" || archivedMatch.kind === "found") {
|
|
333
350
|
return phrenErr(`Finding "${match}" is archived and read-only. Restore or re-add it before mutating history.`, PhrenError.VALIDATION_ERROR);
|
|
334
351
|
}
|
|
@@ -586,7 +603,7 @@ function existsAsLiveFinding(phrenPath, project, text) {
|
|
|
586
603
|
* the review queue lines that point at them. Those queue items are the reason
|
|
587
604
|
* approve and reject used to be no-ops, so both verbs have to look here.
|
|
588
605
|
*/
|
|
589
|
-
function findArchivedReferenceMatches(phrenPath, project, text) {
|
|
606
|
+
function findArchivedReferenceMatches(phrenPath, project, text, exactOnly = false) {
|
|
590
607
|
const referenceDir = safeProjectPath(phrenPath, project, "reference");
|
|
591
608
|
if (!referenceDir || !fs.existsSync(referenceDir))
|
|
592
609
|
return [];
|
|
@@ -610,13 +627,13 @@ function findArchivedReferenceMatches(phrenPath, project, text) {
|
|
|
610
627
|
idx: i,
|
|
611
628
|
line: lines[i],
|
|
612
629
|
};
|
|
613
|
-
if (normalized === needle)
|
|
630
|
+
if (normalized === needle || (exactOnly && withoutTypeTag(normalized) === withoutTypeTag(needle)))
|
|
614
631
|
exact.push(hit);
|
|
615
632
|
else if (normalized.includes(needle))
|
|
616
633
|
partial.push(hit);
|
|
617
634
|
}
|
|
618
635
|
}
|
|
619
|
-
return exact.length > 0 ? exact : partial;
|
|
636
|
+
return exact.length > 0 || exactOnly ? exact : partial;
|
|
620
637
|
}
|
|
621
638
|
/** Bullet content of archived matches, ignoring metadata — used to detect true ambiguity. */
|
|
622
639
|
function archivedMatchesAreIdentical(matches) {
|
|
@@ -737,7 +754,8 @@ export function rejectQueueItemDetailed(phrenPath, project, lineText) {
|
|
|
737
754
|
};
|
|
738
755
|
if (!text)
|
|
739
756
|
return finish("discarded", `Rejected queue item from ${project} (empty entry)`);
|
|
740
|
-
|
|
757
|
+
// Only this exact finding: a partial match would delete an unrelated one.
|
|
758
|
+
const removed = removeFinding(phrenPath, project, text, { exactOnly: true });
|
|
741
759
|
if (removed.ok) {
|
|
742
760
|
return finish("removed", `Rejected and removed finding from ${FINDINGS_FILENAME} in ${project}`);
|
|
743
761
|
}
|
|
@@ -747,7 +765,7 @@ export function rejectQueueItemDetailed(phrenPath, project, lineText) {
|
|
|
747
765
|
if (removed.code !== PhrenError.NOT_FOUND && removed.code !== PhrenError.FILE_NOT_FOUND) {
|
|
748
766
|
return forwardErr(removed);
|
|
749
767
|
}
|
|
750
|
-
const matches = findArchivedReferenceMatches(phrenPath, project, text);
|
|
768
|
+
const matches = findArchivedReferenceMatches(phrenPath, project, text, true);
|
|
751
769
|
if (matches.length === 0) {
|
|
752
770
|
return finish("discarded", `Rejected and discarded queue item from ${project} (candidate was never added to ${FINDINGS_FILENAME}; nothing to remove)`);
|
|
753
771
|
}
|
package/dist/data/notes.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ export interface AddNoteOptions {
|
|
|
19
19
|
date?: string;
|
|
20
20
|
now?: Date;
|
|
21
21
|
}
|
|
22
|
+
/** A note's heading as this module writes it: `## HH:MM[:SS] <!-- nid:xxxxxxxx -->`, optionally promoted. */
|
|
23
|
+
export declare const NOTE_HEADING_RE: RegExp;
|
|
22
24
|
export declare function noteFilePath(phrenPath: string, project: string, date: string): PhrenResult<string>;
|
|
23
25
|
export declare function listNotes(phrenPath: string, project: string, options?: ListNotesOptions): PhrenResult<NoteItem[]>;
|
|
24
26
|
export declare function getNote(phrenPath: string, project: string, selector: string): PhrenResult<NoteItem>;
|
package/dist/data/notes.js
CHANGED
|
@@ -7,7 +7,8 @@ import { atomicWriteText } from "../phren-paths.js";
|
|
|
7
7
|
import { ensureProject, withSafeLock } from "../shared/data-utils.js";
|
|
8
8
|
export const NOTES_DIRNAME = "notes";
|
|
9
9
|
export const MAX_NOTE_LENGTH = 10_000;
|
|
10
|
-
|
|
10
|
+
/** A note's heading as this module writes it: `## HH:MM[:SS] <!-- nid:xxxxxxxx -->`, optionally promoted. */
|
|
11
|
+
export const NOTE_HEADING_RE = /^##\s+(\d{2}:\d{2}(?::\d{2})?)\s+<!--\s*nid:([a-f0-9]{8})\s*-->(?:\s+<!--\s*promoted\s*-->)?\s*$/i;
|
|
11
12
|
function isValidDate(value) {
|
|
12
13
|
if (!/^\d{4}-\d{2}-\d{2}$/.test(value))
|
|
13
14
|
return false;
|
package/dist/entrypoint.js
CHANGED
|
@@ -170,8 +170,9 @@ export async function runTopLevelCommand(argv, opts = {}) {
|
|
|
170
170
|
snapshot = activateModules(store, undefined, true);
|
|
171
171
|
}
|
|
172
172
|
const unavailable = disabledCommand([cmd.name, ...argv.slice(1)].join(" "), snapshot);
|
|
173
|
+
// Without a store every module reads as disabled; "run init" is the fix, not "enable the module".
|
|
173
174
|
if (unavailable) {
|
|
174
|
-
console.error(unavailable);
|
|
175
|
+
console.error(findPhrenPath() ? unavailable : "phren is not set up yet. Run: phren init");
|
|
175
176
|
return finish(1);
|
|
176
177
|
}
|
|
177
178
|
}
|
|
@@ -6328,4 +6328,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
6328
6328
|
${r.map(p=>`<option value="${rt(p)}"${B.filterStore===p?" selected":""}>${rt(p)}</option>`).join("")}
|
|
6329
6329
|
</select>`:"",'<div class="phren-hud-heading">Type</div>',`<div class="phren-hud-grid">${o}</div>`,a?'<div class="phren-hud-heading">Topics</div>':"",a?`<div class="phren-hud-grid">${a}</div>`:"",'<div class="phren-hud-heading">Health</div>',`<div class="phren-hud-grid">${l}</div>`,'<div class="phren-hud-heading">Node limit</div>',`<input type="number" class="phren-hud-limit" data-limit-input min="50" max="50000" value="${B.nodeLimit}" />`,"</div>","</div>",`<span class="phren-hud-counter" data-filter-counter>${B.visibleNodes.length} / ${B.rawNodes.length}</span>`,'<div class="phren-hud-results" data-search-results hidden>','<div class="phren-hud-results-head">','<span class="phren-hud-results-title" data-match-title>MATCHES</span>','<span class="phren-hud-results-nav">','<button type="button" data-match-prev aria-label="Previous match">\u25B2</button>','<span class="phren-hud-results-count" data-match-count>\u2013 / 0</span>','<button type="button" data-match-next aria-label="Next match">\u25BC</button>',"</span>","</div>",'<div class="phren-hud-results-list" data-match-list></div>',"</div>","</div>"].join(""),e&&(e.style.display="none",e.innerHTML=""),t&&(t.style.display="none",t.innerHTML="");let c=n.querySelector("[data-search-filter]");c?.addEventListener("input",()=>{B.searchQuery=c.value,uA(),B.currentMatchIndex=-1,no(),Qd(),Gp()}),c?.addEventListener("keydown",p=>{p.key==="Enter"?(lT(p.shiftKey?-1:1),p.preventDefault(),p.stopPropagation()):p.key==="Escape"&&(c.value="",B.searchQuery="",uA(),B.currentMatchIndex=-1,no(),Qd(),Gp(),c.blur(),p.stopPropagation())}),n.querySelector("[data-match-list]")?.addEventListener("click",p=>{let g=p.target?.closest("[data-match-index]");if(!g)return;let x=Number.parseInt(g.getAttribute("data-match-index")||"",10);Number.isFinite(x)&&nX(x)}),n.querySelector("[data-match-prev]")?.addEventListener("click",()=>lT(-1)),n.querySelector("[data-match-next]")?.addEventListener("click",()=>lT(1)),n.querySelectorAll("[data-filter-type-check]").forEach(p=>{p.addEventListener("change",()=>{let g=p.getAttribute("data-filter-type-check");B.filterTypes[g]=p.checked,is({resetCamera:!0,emitSelection:!!B.selectedNodeId}),Jw()})}),n.querySelectorAll("[data-filter-topic-check]").forEach(p=>{p.addEventListener("change",()=>{let g=p.getAttribute("data-filter-topic-check")||"";B.filterTopics[g]=p.checked,is({resetCamera:!0,emitSelection:!!B.selectedNodeId}),Jw()})}),n.querySelectorAll('input[name="graph-health-filter"]').forEach(p=>{p.addEventListener("change",()=>{p.checked&&(B.filterHealth=p.value,is({resetCamera:!1,emitSelection:!!B.selectedNodeId}))})});let h=n.querySelector("[data-project-filter]");h?.addEventListener("change",()=>{B.filterProject=h.value||"all",is({resetCamera:!0,emitSelection:!!B.selectedNodeId})});let d=n.querySelector("[data-store-filter]");d?.addEventListener("change",()=>{B.filterStore=d.value||"all",is({resetCamera:!0,emitSelection:!!B.selectedNodeId})});let f=n.querySelector("[data-limit-input]");f?.addEventListener("change",()=>{let p=Number.parseInt(f.value,10);Number.isFinite(p)&&(B.nodeLimit=qt(p,50,5e4),f.value=String(B.nodeLimit),is({resetCamera:!1,emitSelection:!!B.selectedNodeId}))});let A=n.querySelector("[data-filter-toggle]"),m=n.querySelector("[data-filter-panel]");if(A&&m){A.addEventListener("click",g=>{g.stopPropagation(),m.style.display=m.style.display==="block"?"none":"block"}),m.addEventListener("click",g=>g.stopPropagation());let p=()=>{m.style.display="none"};document.addEventListener("click",p),B.cleanupFns.push(()=>document.removeEventListener("click",p))}Gp()}function Qd(){let n=document.getElementById("graph-filter");if(!n)return;let e=n.querySelector("[data-filter-counter]");if(!e)return;let t=B.searchQuery.trim();if(t&&B.currentMatchIndex>=0&&B.searchResults.length){e.textContent=`${B.currentMatchIndex+1} / ${B.searchResults.length}`;return}let i=t?B.searchMatchIds.size:B.visibleNodes.length;e.textContent=`${i} / ${B.rawNodes.length}`}function cT(){return typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}function nU(n){let e=B.searchResults[n];e&&(B.currentMatchIndex=n,tr(e.id),cT()||Sd(e.id),Gp(),Qd())}function lT(n){let e=B.searchResults.length;if(!e)return;let t=B.currentMatchIndex,i=t<0?n>0?0:e-1:(t+n+e)%e;nU(i)}function nX(n){let e=B.searchResults.length;e&&nU(qt(n,0,e-1))}function iU(n){let e=B.searchResults.length;if(!e)B.currentMatchIndex=-1;else if(B.currentMatchIndex>=0){let t=n?B.searchResults.findIndex(i=>i.id===n):-1;B.currentMatchIndex=t>=0?t:Math.min(B.currentMatchIndex,e-1)}Gp(),Qd()}function Gp(){let n=document.getElementById("graph-filter");if(!n)return;let e=n.querySelector("[data-search-results]");if(!e)return;let t=B.searchResults,i=t.length;if(i===0){e.classList.remove("visible"),e.setAttribute("hidden","");return}let r=B.currentMatchIndex,s=e.querySelector("[data-match-title]"),o=e.querySelector("[data-match-count]"),a=e.querySelector("[data-match-list]");if(s&&(s.textContent=`MATCHES (${i})`),o&&(o.textContent=`${r>=0?r+1:"\u2013"} / ${i}`),a){let u=0;if(i>200){let f=r>=0?r:0;u=qt(f-Math.floor(200/2),0,i-200)}let h=Math.min(i,u+200),d=[];u>0&&d.push(`<div class="phren-hud-result-more">\u2026${u} above</div>`);for(let f=u;f<h;f++){let A=t[f],m=`${rt(A.kind)}\xB7${rt(A.project||"\u2014")}`;d.push(`<button type="button" class="phren-hud-result-row${f===r?" active":""}" data-match-index="${f}"><span class="phren-hud-result-label">${rt(A.label)}</span><span class="phren-hud-result-chip">${m}</span></button>`)}h<i&&d.push(`<div class="phren-hud-result-more">+${i-h} more\u2026</div>`),a.innerHTML=d.join("")}e.removeAttribute("hidden"),cT()?e.classList.add("visible"):requestAnimationFrame(()=>requestAnimationFrame(()=>e.classList.add("visible"))),a?.querySelector(".phren-hud-result-row.active")?.scrollIntoView({block:"nearest",behavior:cT()?"auto":"smooth"})}var Xl=null,rs=null;function rU(){B.container&&(eU(),(!Xl||!Xl.isConnected)&&(Xl=document.createElement("div"),Xl.className="phren-hud-stats",Xl.setAttribute("aria-hidden","true"),B.container.appendChild(Xl)),(!rs||!rs.isConnected)&&(rs=document.createElement("div"),rs.className="phren-hud-legend",B.container.appendChild(rs)),iX(),uT(),Gw(),Vi({data:!0}))}function iX(){if(!rs)return;let n=[{key:"project",label:"Projects",color:Pn.project},{key:"finding",label:"Findings",color:hl.general},{key:"task",label:"Tasks",color:Pn["task-active"]},{key:"entity",label:"Fragments",color:Pn.entity},{key:"reference",label:"Refs",color:Pn.reference},{key:"topic",label:"Topics",color:hl.general},{key:"note",label:"Notes",color:Pn.note}];rs.innerHTML=n.map(e=>`<span class="phren-legend-chip${B.filterTypes[e.key]?"":" off"}" data-legend-kind="${e.key}">
|
|
6330
6330
|
<span class="phren-hud-dot" style="background:${e.color}"></span>${rt(e.label)}
|
|
6331
|
-
</span>`).join(""),rs.querySelectorAll("[data-legend-kind]").forEach(e=>{e.addEventListener("click",()=>{let t=e.getAttribute("data-legend-kind");B.filterTypes[t]=!B.filterTypes[t],$2(),is({resetCamera:!0,emitSelection:!!B.selectedNodeId}),Jw()})}),rs.querySelectorAll("[data-legend-topic]").forEach(e=>{e.addEventListener("click",()=>{let t=e.getAttribute("data-legend-topic")||"";B.filterTopics[t]=B.filterTopics[t]===!1,$2(),is({resetCamera:!0,emitSelection:!!B.selectedNodeId}),Jw()})})}function $2(){let n=document.getElementById("graph-filter");n&&(n.querySelectorAll("[data-filter-type-check]").forEach(e=>{let t=e.getAttribute("data-filter-type-check");e.checked=B.filterTypes[t]}),n.querySelectorAll("[data-filter-topic-check]").forEach(e=>{let t=e.getAttribute("data-filter-topic-check")||"";e.checked=B.filterTopics[t]!==!1}))}function Jw(){rs&&(rs.querySelectorAll("[data-legend-kind]").forEach(n=>{let e=n.getAttribute("data-legend-kind");n.classList.toggle("off",!B.filterTypes[e])}),rs.querySelectorAll("[data-legend-topic]").forEach(n=>{let e=n.getAttribute("data-legend-topic")||"";n.classList.toggle("off",B.filterTopics[e]===!1)}))}function uT(){if(!Xl)return;let n=B.visibleNodes.reduce((e,t)=>e+(t.kind==="project"?1:0),0);Xl.textContent=`${B.visibleNodes.length} NODES \xB7 ${B.visibleLinks.length} LINKS \xB7 ${n} PROJECTS`}var rX={primary:"#6076a6"},sU=["#9a6bd0","#4d9a8f","#c98a4a","#5a8fd0","#cf6b9a"];function oU(n,e){return rX[n]||sU[e%sU.length]}function aU(n){let e=new Map,t=new Map,i=d=>{if(d.raw.kind!=="entity")return{store:d.raw.store||"primary",project:d.raw.project||d.raw.id};let f=B.fullAdjacency.get(d.id);if(f){let A=null;for(let m of f){let p=B.nodeById.get(m);if(p?.kind!=="project")continue;let g={store:p.store||"primary",project:p.project||p.id};if(A||(A=g),B.visibleIds.has(m))return g}if(A)return A}return{store:"primary",project:d.raw.connectedProjects?.[0]||"shared"}};for(let d of n){let{store:f,project:A}=i(d);e.has(f)||e.set(f,new Map);let m=e.get(f);m.has(A)||m.set(A,[]),d.raw.kind==="project"?t.set(`${f} ${A}`,d):m.get(A).push(d)}let r=[],s=[...e.keys()].sort((d,f)=>d==="primary"?-1:f==="primary"?1:d.localeCompare(f)),o=d=>{let f=e.get(d).size;return f<=1?0:40+Math.sqrt(f)*24},a=84,l=new Map,c=o(s[0]);l.set(s[0],new D(0,0,0));let u=c,h=-c;s.slice(1).forEach((d,f)=>{let A=o(d),m=f%2===0,p=m?u+a+A:h-a-A;m?u=p+A:h=p-A,l.set(d,new D(p,(bn(d,"sy")-.5)*44,(bn(d,"sz")-.5)*70))}),s.forEach((d,f)=>{let A=e.get(d),m=l.get(d),p=[...A.keys()].sort(),g=p.length,x=o(d),w=new D(1/0,1/0,1/0),C=new D(-1/0,-1/0,-1/0),y=Math.PI*(3-Math.sqrt(5));p.forEach((b,E)=>{let v=A.get(b),S=g<=1?0:E/(g-1),_=g<=1?0:(S*2-1)*.85,P=Math.sqrt(Math.max(0,1-_*_)),N=E*y+bn(b,"pa")*.5,Q=x*(.55+bn(b,"pr")*.6),I=new D(m.x+Math.cos(N)*P*Q,m.y+_*Q*.9,m.z+Math.sin(N)*P*Q),R=Math.max(1,v.length),U=10+Math.sqrt(R)*3.2,G=new D(1/0,1/0,1/0),$=new D(-1/0,-1/0,-1/0),J=(ie,pe=1)=>{let ot=(bn(ie.id,"x")+bn(ie.id,"x2")+bn(ie.id,"x3")-1.5)/1.5,nt=(bn(ie.id,"y")+bn(ie.id,"y2")+bn(ie.id,"y3")-1.5)/1.5,$e=(bn(ie.id,"z")+bn(ie.id,"z2")+bn(ie.id,"z3")-1.5)/1.5,ee=I.x+ot*U*pe,ue=I.y+nt*U*.85*pe,Pe=I.z+$e*U*pe;ie.x=ie.fx=ee,ie.y=ie.fy=ue,ie.z=ie.fz=Pe,G.min(new D(ee,ue,Pe)),$.max(new D(ee,ue,Pe))};v.forEach(ie=>J(ie));let te=t.get(`${d} ${b}`);te&&(te.x=te.fx=I.x,te.y=te.fy=I.y,te.z=te.fz=I.z,G.min(I),$.max(I)),Number.isFinite(G.x)||(G.copy(I).subScalar(5),$.copy(I).addScalar(5)),G.subScalar(4),$.addScalar(4),w.min(G),C.max($);let V=te?.raw.baseColor||oU(d,f);r.push({id:`project:${d}:${b}`,kind:"project",min:G.clone(),max:$.clone(),color:V,label:b,count:v.length})}),Number.isFinite(w.x)&&(w.subScalar(12),C.addScalar(12),r.push({id:`store:${d}`,kind:"store",min:w.clone(),max:C.clone(),color:oU(d,f),label:d,count:[...A.values()].reduce((b,E)=>b+E.length,0)}))});for(let d of n)d.__group?.position.set(d.x??0,d.y??0,d.z??0);return r}var Od=null,lU=null,ma=null,hT=null,cU=null,Ww=null,kp=null;function sX(){let n=document.createElement("div");n.className="graph-cinematic",n.setAttribute("aria-hidden","true"),n.style.cssText="position:absolute;inset:0;pointer-events:none;z-index:4;overflow:hidden;";let e=document.createElement("div");return e.className="graph-vignette",e.style.cssText="position:absolute;inset:0;background:radial-gradient(ellipse at 50% 50%, transparent 55%, rgba(0,0,0,0.55) 100%);",n.appendChild(e),cU=n,n}function oX(n){try{let e=n.getContext(),t=e.getExtension("WEBGL_debug_renderer_info"),i=[t?e.getParameter(t.UNMASKED_RENDERER_WEBGL):"",e.getParameter(e.RENDERER),e.getParameter(e.VERSION)];return/swiftshader/i.test(i.join(" "))}catch{return!1}}function aX(n){let e=B.fgNodeById.get(n.id);if(e)e.raw=n;else{e={id:n.id,raw:n};let t=600;e.x=(bn(n.id,"x")-.5)*t,e.y=(bn(n.id,"y")-.5)*t,e.z=(bn(n.id,"z")-.5)*t,B.fgNodeById.set(n.id,e)}return e}function lX(){let n=B.visibleNodes.map(aX),e=new Set(n.map(r=>r.id)),t=B.visibleLinks.filter(r=>e.has(r.source)&&e.has(r.target)).map(r=>({source:r.source,target:r.target})),i=aU(n);B.fg.graphData({nodes:n,links:t}),X2(),B.fg.scene&&(kp=B.fg.scene(),O_(kp,i,Ud())),no()}function is(n={}){let e=c_();B.visibleNodes=e.nodes,B.visibleLinks=e.links,B.visibleIds=new Set(e.nodes.map(i=>i.id)),u_();let t=B.currentMatchIndex>=0?B.searchResults[B.currentMatchIndex]?.id??null:null;if(uA(),B.fg&&lX(),Qd(),iU(t),uT(),Gw(),Vi({data:!0}),B.selectedNodeId&&!B.visibleAdjacency.has(B.selectedNodeId)?(B.selectedNodeId=null,sT()):n.emitSelection&&B.selectedNodeId&&setTimeout(()=>Ld(B.selectedNodeId),0),n.resetCamera&&B.fg){let i=B.fg,r=B.lastInteractionAt;setTimeout(()=>{B.fg===i&&!B.selectedNodeId&&!B.focusedProjectId&&B.lastInteractionAt===r&&Wl(600)},180)}}function uU(){if(!B.container||B.fg)return;B.theme=xm(),B.container.style.position="relative",M_(),B.fxOff=B.container.getAttribute("data-fx")==="off",Ww=S_();let n=new p2(B.container,{controlType:"orbit",extraRenderers:[Ww]}).backgroundColor(Sv).showNavInfo(!1).nodeId("id").nodeThreeObject(m=>K_(m)).nodeThreeObjectExtend(!1).linkColor(m=>x2(m)).linkWidth(()=>w2()).linkCurvature(.2).linkOpacity(1).linkDirectionalParticles(m=>C2(m)).linkDirectionalParticleSpeed(.006).linkDirectionalParticleWidth(1.2).linkDirectionalParticleColor(()=>aA).enableNodeDrag(!1).warmupTicks(0).cooldownTicks(0).d3AlphaDecay(1).onNodeHover(m=>W2(m)).onNodeClick((m,p)=>jw(p,m)).onLinkClick((m,p)=>jw(p,null)).onNodeRightClick((m,p)=>q2(m,p)).onNodeDragEnd(m=>{m.fx=m.x,m.fy=m.y,m.fz=m.z}).onBackgroundClick(m=>jw(m,null));B.fg=n;let e=n.renderer();e.toneMapping=Mc,e.toneMappingExposure=1.05;let t=oX(e),i=t?.5:Math.min(window.devicePixelRatio||1,1.5);e.setPixelRatio(i),n.postProcessingComposer().setPixelRatio(i),n.controls().autoRotate=!1,n.controls().autoRotateSpeed=.22;let r=n.controls(),s=()=>{aT(),j2()};r.addEventListener("start",s),r.addEventListener("end",rT),B.cleanupFns.push(()=>{r.removeEventListener("start",s),r.removeEventListener("end",rT)});let o=()=>aT();B.container.addEventListener("pointerdown",o),B.container.addEventListener("wheel",o,{passive:!0}),B.cleanupFns.push(()=>{B.container?.removeEventListener("pointerdown",o),B.container?.removeEventListener("wheel",o)});let a=n.d3Force("charge");if(a&&a.strength(0),n.d3Force("link",null),n.d3Force("center",null),!B.fxOff&&!t){let m=Ud();hT=new Md(new se(Math.max(1,m.w/2),Math.max(1,m.h/2)),.55,.5,.2),n.postProcessingComposer().addPass(hT)}n.scene().fog=new $d(Sv,6e-4),W_(n.scene()),n.cameraPosition({x:260,y:190,z:520},{x:0,y:0,z:0},0),ma=new Ti(new Jn({map:Gm(),color:new ge(aA),transparent:!0,opacity:0,blending:nn,depthWrite:!1,depthTest:!1,fog:!1})),ma.visible=!1,ma.renderOrder=998,n.scene().add(ma);let l=sX();B.container.appendChild(l),B.cleanupFns.push(()=>l.remove());let c=m=>{let p=B.container.getBoundingClientRect();B.lastMouse={x:m.clientX-p.left,y:m.clientY-p.top}};B.container.addEventListener("mousemove",c),B.cleanupFns.push(()=>B.container?.removeEventListener("mousemove",c));let u=m=>{let p=m.target,g=p?.tagName;if(!(g==="INPUT"||g==="TEXTAREA"||g==="SELECT"||p?.isContentEditable)){if(m.key==="Escape"){if(!B.selectedNodeId&&!B.focusedProjectId)return;ns();return}if((m.key==="ArrowLeft"||m.key==="ArrowRight")&&!m.altKey&&!m.ctrlKey&&!m.metaKey){let x=m.key==="ArrowRight"?1:-1;if(B.selectedNodeId){let w=wm(B.selectedNodeId,x);w&&tr(w),m.preventDefault();return}G2(x),m.preventDefault()}}};document.addEventListener("keydown",u),B.cleanupFns.push(()=>document.removeEventListener("keydown",u));let h=()=>{let m=Ud();B.fg?.width(m.w).height(m.h),Ww?.setSize(m.w,m.h),k_(m.w,m.h),Nd()};typeof ResizeObserver=="function"?(B.resizeObserver=new ResizeObserver(h),B.resizeObserver.observe(B.container)):(window.addEventListener("resize",h),B.cleanupFns.push(()=>window.removeEventListener("resize",h))),h(),n.onEngineStop(()=>{B.firstSettle&&(B.firstSettle=!1,Kw())});let d=new MutationObserver(()=>{xm()!==B.theme&&(B.theme=xm())});d.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),B.themeObserver=d;let f=0,A=m=>{if(B.ambientRafId=requestAnimationFrame(A),document.hidden){f=m;return}let p=f>0?Math.min(.05,(m-f)/1e3):.016;f=m;let g=m*.001;Od&&(Od.rotation.y+=p*.008),q_(p,g),Qv(p),Z2(m),ma&&(ma.visible=!1),E2(p)};B.ambientRafId=requestAnimationFrame(A)}function hU(){J2(),Od&&(Od.geometry.dispose(),Od.material.dispose(),Od=null),lU?.children.forEach(n=>{n.material.dispose()}),lU=null,ma&&(ma.material.dispose(),ma=null),X_(),kp&&(Yv(kp),kp=null),hT=null,cU=null,Ww=null}function cX(n){if(B.container=document.getElementById("graph-canvas"),!B.container){console.error("[phrenGraph] #graph-canvas not found");return}B.payload=n||{},B.rawNodes=(n.nodes||[]).map(a_),B.rawLinks=(n.links||[]).slice(),B.topics=(n.topics&&n.topics.length?n.topics:Array.from(new Map(B.rawNodes.filter(t=>t.kind==="finding"&&t.topicSlug).map(t=>[t.topicSlug,{slug:t.topicSlug,label:t.topicLabel||t.topicSlug}])).values())).sort((t,i)=>t.label.localeCompare(i.label)),l_(),B.nodeById=new Map,B.rawNodes.forEach(t=>B.nodeById.set(t.id,t)),Ov(),B.fgNodeById.forEach(dT),B.fgNodeById.clear(),_v(),tU(),uU(),rU();let e=!!B.fg&&B.introPlayed;B.firstSettle=!e,is({resetCamera:!e,emitSelection:!!B.selectedNodeId}),y2(),e||setTimeout(()=>{B.firstSettle&&(B.firstSettle=!1,Kw())},2600)}function dT(n){n.__dot&&n.__dot.material.dispose(),n.__core&&n.__core.material.dispose(),n.__shell&&n.__shell.material.dispose(),n.__wire&&n.__wire.material.dispose(),n.__ring&&n.__ring.material.dispose(),n.__halo&&n.__halo.material.dispose(),n.__labelObj&&__(n.id),n.__labelObj?.removeFromParent(),n.__labelEl&&n.__labelEl.remove(),n.__group=void 0,n.__dot=void 0,n.__core=void 0,n.__shell=void 0,n.__wire=void 0,n.__ring=void 0,n.__halo=void 0,n.__labelObj=void 0,n.__labelEl=void 0}function uX(n,e){let t=B.nodeById.get(n);if(!t)return!1;typeof e.section=="string"&&(t.section=e.section),typeof e.priority=="string"&&(t.priority=e.priority),typeof e.topicSlug=="string"&&(t.topicSlug=e.topicSlug),typeof e.topicLabel=="string"&&(t.topicLabel=e.topicLabel),typeof e.text=="string"&&(t.fullLabel=e.text,e.label||(t.label=e.text.slice(0,40)+(e.text.length>40?"\u2026":""))),typeof e.fullLabel=="string"&&(t.fullLabel=e.fullLabel),typeof e.label=="string"&&(t.label=e.label),t.baseColor=e.color||o_(t),t.searchText=gm(t);let i=B.hostNodes.find(s=>s.id===n);i&&Object.assign(i,{section:t.section,priority:t.priority,topicSlug:t.topicSlug,topicLabel:t.topicLabel,label:t.label,fullLabel:t.fullLabel,baseColor:t.baseColor});let r=B.fgNodeById.get(n);return r&&(j_(r),Lv(r)),Mm(),Vi({data:!0}),!0}function hX(n,e){let t=B.fgNodeById.get(n);if(!B.nodeById.has(n)&&!t)return!1;let i=B.selectedNodeId===n,r=typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches,s=e?.animate!==!1&&!r&&!!t?.__group,o=()=>{let x=B.nodeById.get(n);if(x&&(x.kind==="finding"||x.kind==="task")&&x.project){let w=B.rawNodes.find(C=>C.kind==="project"&&(C.project||C.id)===x.project);if(w){x.kind==="finding"&&typeof w.findingCount=="number"&&w.findingCount>0&&w.findingCount--,x.kind==="task"&&typeof w.taskCount=="number"&&w.taskCount>0&&w.taskCount--;let C=B.fgNodeById.get(w.id);C&&Lv(C)}}B.rawNodes=B.rawNodes.filter(w=>w.id!==n),B.rawLinks=B.rawLinks.filter(w=>w.source!==n&&w.target!==n),B.nodeById.delete(n),B.selectedNodeId===n&&(B.selectedNodeId=null),B.hoveredNodeId===n&&(B.hoveredNodeId=null),B.focusedProjectId===n&&(B.focusedProjectId=null),t&&(dT(t),B.fgNodeById.delete(n)),xe.currentNodeId===n&&(xe.currentNodeId=null),xe.targetNodeId===n&&(xe.targetNodeId=null),_v(),is({resetCamera:!1,emitSelection:!1}),i&&a()},a=()=>{B.selectionClearCallbacks.forEach(x=>x())};if(!s||!t?.__group||!B.fg?.scene)return o(),!0;let l=B.fg.scene(),c=new D(t.x||0,t.y||0,t.z||0),u=t.__dot?.material,h=u?.map??null,d=u?u.color.clone():new ge("#ffffff"),f=t.__dot?t.__dot.scale.x:3;o();let A=new Ti(new Jn({map:h,color:d,transparent:!0,opacity:1,depthWrite:!1,blending:nn,toneMapped:!1}));A.position.copy(c),A.scale.setScalar(f),l.add(A);let m=280,p=performance.now(),g=x=>{let w=Math.min(1,(x-p)/m),C=(1-w)*(1-w)*(1-w);A.scale.setScalar(Math.max(.01,f*C)),A.material.opacity=C,w<1?requestAnimationFrame(g):(l.remove(A),A.material.dispose())};return requestAnimationFrame(g),!0}function dX(){if(YS(),b2(),B.ambientRafId&&cancelAnimationFrame(B.ambientRafId),B.ambientRafId=0,B.themeObserver?.disconnect(),B.themeObserver=null,B.resizeObserver?.disconnect(),B.resizeObserver=null,B.cleanupFns.forEach(n=>n()),B.cleanupFns=[],Ov(),B.fgNodeById.forEach(dT),B.fgNodeById.clear(),hU(),B.fg)try{B.fg._destructor?.()}catch{}B.fg=null,B.container=null,B.introPlayed=!1}Sh.graphZoom=function(e){K2(e)};Sh.graphReset=function(){ns(),Wl(500)};Sh.graphResetLayout=function(){B.fg&&(B.fgNodeById.forEach(e=>{e.fx=void 0,e.fy=void 0,e.fz=void 0}),B.firstSettle=!0,B.fg.d3ReheatSimulation())};Sh.graphClearSelection=function(){ns()};Sh.phrenGraph={__renderer:"three",mount:cX,onNodeSelect(n){B.nodeSelectCallbacks.push(n)},onSelectionClear(n){B.selectionClearCallbacks.push(n)},onRightClick(n){B.rightClickCallbacks.push(n)},onItemAction(n){B.itemActionCallbacks.push(n)},clearSelection:ns,selectNode:tr,focusNode:tr,peekNode(n){B.fgNodeById.has(n)&&(B.firstSettle=!1,B.introPlayed=!0,Ow(n))},walkTo:B2,getNodeAt:oT,screenPosFor:Yw,setSelectionViewport:V2,getNodeDetail:vr,stepDossier:wm,dossierPosition:f_,getData(){return{nodes:B.hostNodes.slice(),links:B.visibleLinks.slice(),topics:B.topics.slice(),total:B.rawNodes.length}},removeNode:hX,updateNode:uX,destroy:dX,benchLabels:n=>P_(n)};})();
|
|
6331
|
+
</span>`).join(""),rs.querySelectorAll("[data-legend-kind]").forEach(e=>{e.addEventListener("click",()=>{let t=e.getAttribute("data-legend-kind");B.filterTypes[t]=!B.filterTypes[t],$2(),is({resetCamera:!0,emitSelection:!!B.selectedNodeId}),Jw()})}),rs.querySelectorAll("[data-legend-topic]").forEach(e=>{e.addEventListener("click",()=>{let t=e.getAttribute("data-legend-topic")||"";B.filterTopics[t]=B.filterTopics[t]===!1,$2(),is({resetCamera:!0,emitSelection:!!B.selectedNodeId}),Jw()})})}function $2(){let n=document.getElementById("graph-filter");n&&(n.querySelectorAll("[data-filter-type-check]").forEach(e=>{let t=e.getAttribute("data-filter-type-check");e.checked=B.filterTypes[t]}),n.querySelectorAll("[data-filter-topic-check]").forEach(e=>{let t=e.getAttribute("data-filter-topic-check")||"";e.checked=B.filterTopics[t]!==!1}))}function Jw(){rs&&(rs.querySelectorAll("[data-legend-kind]").forEach(n=>{let e=n.getAttribute("data-legend-kind");n.classList.toggle("off",!B.filterTypes[e])}),rs.querySelectorAll("[data-legend-topic]").forEach(n=>{let e=n.getAttribute("data-legend-topic")||"";n.classList.toggle("off",B.filterTopics[e]===!1)}))}function uT(){if(!Xl)return;let n=B.visibleNodes.reduce((e,t)=>e+(t.kind==="project"?1:0),0);Xl.textContent=`${B.visibleNodes.length} NODES \xB7 ${B.visibleLinks.length} LINKS \xB7 ${n} PROJECTS`}var rX={primary:"#6076a6"},sU=["#9a6bd0","#4d9a8f","#c98a4a","#5a8fd0","#cf6b9a"];function oU(n,e){return rX[n]||sU[e%sU.length]}function aU(n){if(n.length===0)return[];let e=new Map,t=new Map,i=d=>{if(d.raw.kind!=="entity")return{store:d.raw.store||"primary",project:d.raw.project||d.raw.id};let f=B.fullAdjacency.get(d.id);if(f){let A=null;for(let m of f){let p=B.nodeById.get(m);if(p?.kind!=="project")continue;let g={store:p.store||"primary",project:p.project||p.id};if(A||(A=g),B.visibleIds.has(m))return g}if(A)return A}return{store:"primary",project:d.raw.connectedProjects?.[0]||"shared"}};for(let d of n){let{store:f,project:A}=i(d);e.has(f)||e.set(f,new Map);let m=e.get(f);m.has(A)||m.set(A,[]),d.raw.kind==="project"?t.set(`${f} ${A}`,d):m.get(A).push(d)}let r=[],s=[...e.keys()].sort((d,f)=>d==="primary"?-1:f==="primary"?1:d.localeCompare(f)),o=d=>{let f=e.get(d).size;return f<=1?0:40+Math.sqrt(f)*24},a=84,l=new Map,c=o(s[0]);l.set(s[0],new D(0,0,0));let u=c,h=-c;s.slice(1).forEach((d,f)=>{let A=o(d),m=f%2===0,p=m?u+a+A:h-a-A;m?u=p+A:h=p-A,l.set(d,new D(p,(bn(d,"sy")-.5)*44,(bn(d,"sz")-.5)*70))}),s.forEach((d,f)=>{let A=e.get(d),m=l.get(d),p=[...A.keys()].sort(),g=p.length,x=o(d),w=new D(1/0,1/0,1/0),C=new D(-1/0,-1/0,-1/0),y=Math.PI*(3-Math.sqrt(5));p.forEach((b,E)=>{let v=A.get(b),S=g<=1?0:E/(g-1),_=g<=1?0:(S*2-1)*.85,P=Math.sqrt(Math.max(0,1-_*_)),N=E*y+bn(b,"pa")*.5,Q=x*(.55+bn(b,"pr")*.6),I=new D(m.x+Math.cos(N)*P*Q,m.y+_*Q*.9,m.z+Math.sin(N)*P*Q),R=Math.max(1,v.length),U=10+Math.sqrt(R)*3.2,G=new D(1/0,1/0,1/0),$=new D(-1/0,-1/0,-1/0),J=(ie,pe=1)=>{let ot=(bn(ie.id,"x")+bn(ie.id,"x2")+bn(ie.id,"x3")-1.5)/1.5,nt=(bn(ie.id,"y")+bn(ie.id,"y2")+bn(ie.id,"y3")-1.5)/1.5,$e=(bn(ie.id,"z")+bn(ie.id,"z2")+bn(ie.id,"z3")-1.5)/1.5,ee=I.x+ot*U*pe,ue=I.y+nt*U*.85*pe,Pe=I.z+$e*U*pe;ie.x=ie.fx=ee,ie.y=ie.fy=ue,ie.z=ie.fz=Pe,G.min(new D(ee,ue,Pe)),$.max(new D(ee,ue,Pe))};v.forEach(ie=>J(ie));let te=t.get(`${d} ${b}`);te&&(te.x=te.fx=I.x,te.y=te.fy=I.y,te.z=te.fz=I.z,G.min(I),$.max(I)),Number.isFinite(G.x)||(G.copy(I).subScalar(5),$.copy(I).addScalar(5)),G.subScalar(4),$.addScalar(4),w.min(G),C.max($);let V=te?.raw.baseColor||oU(d,f);r.push({id:`project:${d}:${b}`,kind:"project",min:G.clone(),max:$.clone(),color:V,label:b,count:v.length})}),Number.isFinite(w.x)&&(w.subScalar(12),C.addScalar(12),r.push({id:`store:${d}`,kind:"store",min:w.clone(),max:C.clone(),color:oU(d,f),label:d,count:[...A.values()].reduce((b,E)=>b+E.length,0)}))});for(let d of n)d.__group?.position.set(d.x??0,d.y??0,d.z??0);return r}var Od=null,lU=null,ma=null,hT=null,cU=null,Ww=null,kp=null;function sX(){let n=document.createElement("div");n.className="graph-cinematic",n.setAttribute("aria-hidden","true"),n.style.cssText="position:absolute;inset:0;pointer-events:none;z-index:4;overflow:hidden;";let e=document.createElement("div");return e.className="graph-vignette",e.style.cssText="position:absolute;inset:0;background:radial-gradient(ellipse at 50% 50%, transparent 55%, rgba(0,0,0,0.55) 100%);",n.appendChild(e),cU=n,n}function oX(n){try{let e=n.getContext(),t=e.getExtension("WEBGL_debug_renderer_info"),i=[t?e.getParameter(t.UNMASKED_RENDERER_WEBGL):"",e.getParameter(e.RENDERER),e.getParameter(e.VERSION)];return/swiftshader/i.test(i.join(" "))}catch{return!1}}function aX(n){let e=B.fgNodeById.get(n.id);if(e)e.raw=n;else{e={id:n.id,raw:n};let t=600;e.x=(bn(n.id,"x")-.5)*t,e.y=(bn(n.id,"y")-.5)*t,e.z=(bn(n.id,"z")-.5)*t,B.fgNodeById.set(n.id,e)}return e}function lX(){let n=B.visibleNodes.map(aX),e=new Set(n.map(r=>r.id)),t=B.visibleLinks.filter(r=>e.has(r.source)&&e.has(r.target)).map(r=>({source:r.source,target:r.target})),i=aU(n);B.fg.graphData({nodes:n,links:t}),X2(),B.fg.scene&&(kp=B.fg.scene(),O_(kp,i,Ud())),no()}function is(n={}){let e=c_();B.visibleNodes=e.nodes,B.visibleLinks=e.links,B.visibleIds=new Set(e.nodes.map(i=>i.id)),u_();let t=B.currentMatchIndex>=0?B.searchResults[B.currentMatchIndex]?.id??null:null;if(uA(),B.fg&&lX(),Qd(),iU(t),uT(),Gw(),Vi({data:!0}),B.selectedNodeId&&!B.visibleAdjacency.has(B.selectedNodeId)?(B.selectedNodeId=null,sT()):n.emitSelection&&B.selectedNodeId&&setTimeout(()=>Ld(B.selectedNodeId),0),n.resetCamera&&B.fg){let i=B.fg,r=B.lastInteractionAt;setTimeout(()=>{B.fg===i&&!B.selectedNodeId&&!B.focusedProjectId&&B.lastInteractionAt===r&&Wl(600)},180)}}function uU(){if(!B.container||B.fg)return;B.theme=xm(),B.container.style.position="relative",M_(),B.fxOff=B.container.getAttribute("data-fx")==="off",Ww=S_();let n=new p2(B.container,{controlType:"orbit",extraRenderers:[Ww]}).backgroundColor(Sv).showNavInfo(!1).nodeId("id").nodeThreeObject(m=>K_(m)).nodeThreeObjectExtend(!1).linkColor(m=>x2(m)).linkWidth(()=>w2()).linkCurvature(.2).linkOpacity(1).linkDirectionalParticles(m=>C2(m)).linkDirectionalParticleSpeed(.006).linkDirectionalParticleWidth(1.2).linkDirectionalParticleColor(()=>aA).enableNodeDrag(!1).warmupTicks(0).cooldownTicks(0).d3AlphaDecay(1).onNodeHover(m=>W2(m)).onNodeClick((m,p)=>jw(p,m)).onLinkClick((m,p)=>jw(p,null)).onNodeRightClick((m,p)=>q2(m,p)).onNodeDragEnd(m=>{m.fx=m.x,m.fy=m.y,m.fz=m.z}).onBackgroundClick(m=>jw(m,null));B.fg=n;let e=n.renderer();e.toneMapping=Mc,e.toneMappingExposure=1.05;let t=oX(e),i=t?.5:Math.min(window.devicePixelRatio||1,1.5);e.setPixelRatio(i),n.postProcessingComposer().setPixelRatio(i),n.controls().autoRotate=!1,n.controls().autoRotateSpeed=.22;let r=n.controls(),s=()=>{aT(),j2()};r.addEventListener("start",s),r.addEventListener("end",rT),B.cleanupFns.push(()=>{r.removeEventListener("start",s),r.removeEventListener("end",rT)});let o=()=>aT();B.container.addEventListener("pointerdown",o),B.container.addEventListener("wheel",o,{passive:!0}),B.cleanupFns.push(()=>{B.container?.removeEventListener("pointerdown",o),B.container?.removeEventListener("wheel",o)});let a=n.d3Force("charge");if(a&&a.strength(0),n.d3Force("link",null),n.d3Force("center",null),!B.fxOff&&!t){let m=Ud();hT=new Md(new se(Math.max(1,m.w/2),Math.max(1,m.h/2)),.55,.5,.2),n.postProcessingComposer().addPass(hT)}n.scene().fog=new $d(Sv,6e-4),W_(n.scene()),n.cameraPosition({x:260,y:190,z:520},{x:0,y:0,z:0},0),ma=new Ti(new Jn({map:Gm(),color:new ge(aA),transparent:!0,opacity:0,blending:nn,depthWrite:!1,depthTest:!1,fog:!1})),ma.visible=!1,ma.renderOrder=998,n.scene().add(ma);let l=sX();B.container.appendChild(l),B.cleanupFns.push(()=>l.remove());let c=m=>{let p=B.container.getBoundingClientRect();B.lastMouse={x:m.clientX-p.left,y:m.clientY-p.top}};B.container.addEventListener("mousemove",c),B.cleanupFns.push(()=>B.container?.removeEventListener("mousemove",c));let u=m=>{let p=m.target,g=p?.tagName;if(!(g==="INPUT"||g==="TEXTAREA"||g==="SELECT"||p?.isContentEditable)){if(m.key==="Escape"){if(!B.selectedNodeId&&!B.focusedProjectId)return;ns();return}if((m.key==="ArrowLeft"||m.key==="ArrowRight")&&!m.altKey&&!m.ctrlKey&&!m.metaKey){let x=m.key==="ArrowRight"?1:-1;if(B.selectedNodeId){let w=wm(B.selectedNodeId,x);w&&tr(w),m.preventDefault();return}G2(x),m.preventDefault()}}};document.addEventListener("keydown",u),B.cleanupFns.push(()=>document.removeEventListener("keydown",u));let h=()=>{let m=Ud();B.fg?.width(m.w).height(m.h),Ww?.setSize(m.w,m.h),k_(m.w,m.h),Nd()};typeof ResizeObserver=="function"?(B.resizeObserver=new ResizeObserver(h),B.resizeObserver.observe(B.container)):(window.addEventListener("resize",h),B.cleanupFns.push(()=>window.removeEventListener("resize",h))),h(),n.onEngineStop(()=>{B.firstSettle&&(B.firstSettle=!1,Kw())});let d=new MutationObserver(()=>{xm()!==B.theme&&(B.theme=xm())});d.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),B.themeObserver=d;let f=0,A=m=>{if(B.ambientRafId=requestAnimationFrame(A),document.hidden){f=m;return}let p=f>0?Math.min(.05,(m-f)/1e3):.016;f=m;let g=m*.001;Od&&(Od.rotation.y+=p*.008),q_(p,g),Qv(p),Z2(m),ma&&(ma.visible=!1),E2(p)};B.ambientRafId=requestAnimationFrame(A)}function hU(){J2(),Od&&(Od.geometry.dispose(),Od.material.dispose(),Od=null),lU?.children.forEach(n=>{n.material.dispose()}),lU=null,ma&&(ma.material.dispose(),ma=null),X_(),kp&&(Yv(kp),kp=null),hT=null,cU=null,Ww=null}function cX(n){if(B.container=document.getElementById("graph-canvas"),!B.container){console.error("[phrenGraph] #graph-canvas not found");return}B.payload=n||{},B.rawNodes=(n.nodes||[]).map(a_),B.rawLinks=(n.links||[]).slice(),B.topics=(n.topics&&n.topics.length?n.topics:Array.from(new Map(B.rawNodes.filter(t=>t.kind==="finding"&&t.topicSlug).map(t=>[t.topicSlug,{slug:t.topicSlug,label:t.topicLabel||t.topicSlug}])).values())).sort((t,i)=>t.label.localeCompare(i.label)),l_(),B.nodeById=new Map,B.rawNodes.forEach(t=>B.nodeById.set(t.id,t)),Ov(),B.fgNodeById.forEach(dT),B.fgNodeById.clear(),_v(),tU(),uU(),rU();let e=!!B.fg&&B.introPlayed;B.firstSettle=!e,is({resetCamera:!e,emitSelection:!!B.selectedNodeId}),y2(),e||setTimeout(()=>{B.firstSettle&&(B.firstSettle=!1,Kw())},2600)}function dT(n){n.__dot&&n.__dot.material.dispose(),n.__core&&n.__core.material.dispose(),n.__shell&&n.__shell.material.dispose(),n.__wire&&n.__wire.material.dispose(),n.__ring&&n.__ring.material.dispose(),n.__halo&&n.__halo.material.dispose(),n.__labelObj&&__(n.id),n.__labelObj?.removeFromParent(),n.__labelEl&&n.__labelEl.remove(),n.__group=void 0,n.__dot=void 0,n.__core=void 0,n.__shell=void 0,n.__wire=void 0,n.__ring=void 0,n.__halo=void 0,n.__labelObj=void 0,n.__labelEl=void 0}function uX(n,e){let t=B.nodeById.get(n);if(!t)return!1;typeof e.section=="string"&&(t.section=e.section),typeof e.priority=="string"&&(t.priority=e.priority),typeof e.topicSlug=="string"&&(t.topicSlug=e.topicSlug),typeof e.topicLabel=="string"&&(t.topicLabel=e.topicLabel),typeof e.text=="string"&&(t.fullLabel=e.text,e.label||(t.label=e.text.slice(0,40)+(e.text.length>40?"\u2026":""))),typeof e.fullLabel=="string"&&(t.fullLabel=e.fullLabel),typeof e.label=="string"&&(t.label=e.label),t.baseColor=e.color||o_(t),t.searchText=gm(t);let i=B.hostNodes.find(s=>s.id===n);i&&Object.assign(i,{section:t.section,priority:t.priority,topicSlug:t.topicSlug,topicLabel:t.topicLabel,label:t.label,fullLabel:t.fullLabel,baseColor:t.baseColor});let r=B.fgNodeById.get(n);return r&&(j_(r),Lv(r)),Mm(),Vi({data:!0}),!0}function hX(n,e){let t=B.fgNodeById.get(n);if(!B.nodeById.has(n)&&!t)return!1;let i=B.selectedNodeId===n,r=typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches,s=e?.animate!==!1&&!r&&!!t?.__group,o=()=>{let x=B.nodeById.get(n);if(x&&(x.kind==="finding"||x.kind==="task")&&x.project){let w=B.rawNodes.find(C=>C.kind==="project"&&(C.project||C.id)===x.project);if(w){x.kind==="finding"&&typeof w.findingCount=="number"&&w.findingCount>0&&w.findingCount--,x.kind==="task"&&typeof w.taskCount=="number"&&w.taskCount>0&&w.taskCount--;let C=B.fgNodeById.get(w.id);C&&Lv(C)}}B.rawNodes=B.rawNodes.filter(w=>w.id!==n),B.rawLinks=B.rawLinks.filter(w=>w.source!==n&&w.target!==n),B.nodeById.delete(n),B.selectedNodeId===n&&(B.selectedNodeId=null),B.hoveredNodeId===n&&(B.hoveredNodeId=null),B.focusedProjectId===n&&(B.focusedProjectId=null),t&&(dT(t),B.fgNodeById.delete(n)),xe.currentNodeId===n&&(xe.currentNodeId=null),xe.targetNodeId===n&&(xe.targetNodeId=null),_v(),is({resetCamera:!1,emitSelection:!1}),i&&a()},a=()=>{B.selectionClearCallbacks.forEach(x=>x())};if(!s||!t?.__group||!B.fg?.scene)return o(),!0;let l=B.fg.scene(),c=new D(t.x||0,t.y||0,t.z||0),u=t.__dot?.material,h=u?.map??null,d=u?u.color.clone():new ge("#ffffff"),f=t.__dot?t.__dot.scale.x:3;o();let A=new Ti(new Jn({map:h,color:d,transparent:!0,opacity:1,depthWrite:!1,blending:nn,toneMapped:!1}));A.position.copy(c),A.scale.setScalar(f),l.add(A);let m=280,p=performance.now(),g=x=>{let w=Math.min(1,(x-p)/m),C=(1-w)*(1-w)*(1-w);A.scale.setScalar(Math.max(.01,f*C)),A.material.opacity=C,w<1?requestAnimationFrame(g):(l.remove(A),A.material.dispose())};return requestAnimationFrame(g),!0}function dX(){if(YS(),b2(),B.ambientRafId&&cancelAnimationFrame(B.ambientRafId),B.ambientRafId=0,B.themeObserver?.disconnect(),B.themeObserver=null,B.resizeObserver?.disconnect(),B.resizeObserver=null,B.cleanupFns.forEach(n=>n()),B.cleanupFns=[],Ov(),B.fgNodeById.forEach(dT),B.fgNodeById.clear(),hU(),B.fg)try{B.fg._destructor?.()}catch{}B.fg=null,B.container=null,B.introPlayed=!1}Sh.graphZoom=function(e){K2(e)};Sh.graphReset=function(){ns(),Wl(500)};Sh.graphResetLayout=function(){B.fg&&(B.fgNodeById.forEach(e=>{e.fx=void 0,e.fy=void 0,e.fz=void 0}),B.firstSettle=!0,B.fg.d3ReheatSimulation())};Sh.graphClearSelection=function(){ns()};Sh.phrenGraph={__renderer:"three",mount:cX,onNodeSelect(n){B.nodeSelectCallbacks.push(n)},onSelectionClear(n){B.selectionClearCallbacks.push(n)},onRightClick(n){B.rightClickCallbacks.push(n)},onItemAction(n){B.itemActionCallbacks.push(n)},clearSelection:ns,selectNode:tr,focusNode:tr,peekNode(n){B.fgNodeById.has(n)&&(B.firstSettle=!1,B.introPlayed=!0,Ow(n))},walkTo:B2,getNodeAt:oT,screenPosFor:Yw,setSelectionViewport:V2,getNodeDetail:vr,stepDossier:wm,dossierPosition:f_,getData(){return{nodes:B.hostNodes.slice(),links:B.visibleLinks.slice(),topics:B.topics.slice(),total:B.rawNodes.length}},removeNode:hX,updateNode:uX,destroy:dX,benchLabels:n=>P_(n)};})();
|
package/dist/governance/locks.js
CHANGED
|
@@ -101,7 +101,23 @@ export function tryFileLock(filePath) {
|
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
103
|
catch (err) {
|
|
104
|
-
|
|
104
|
+
const code = err.code;
|
|
105
|
+
// Windows refuses to create a lock another process is deleting (still
|
|
106
|
+
// open somewhere) with EPERM, EACCES or EBUSY: it is held, not broken.
|
|
107
|
+
// With no lock file there at all, the error is a real permission problem.
|
|
108
|
+
if (process.platform === "win32" && (code === "EPERM" || code === "EACCES" || code === "EBUSY")) {
|
|
109
|
+
let present = true;
|
|
110
|
+
try {
|
|
111
|
+
fs.statSync(lockPath);
|
|
112
|
+
}
|
|
113
|
+
catch (statErr) {
|
|
114
|
+
present = statErr.code !== "ENOENT";
|
|
115
|
+
}
|
|
116
|
+
if (present)
|
|
117
|
+
return null;
|
|
118
|
+
throw err;
|
|
119
|
+
}
|
|
120
|
+
if (code !== "EEXIST")
|
|
105
121
|
throw err;
|
|
106
122
|
try {
|
|
107
123
|
const contents = fs.readFileSync(lockPath, "utf8");
|