@phren/cli 0.1.44 → 0.1.45

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.
Files changed (74) hide show
  1. package/dist/cli/actions.d.ts +1 -1
  2. package/dist/cli/actions.js +7 -2
  3. package/dist/cli/config-proactivity.d.ts +6 -6
  4. package/dist/cli/hooks.d.ts +1 -1
  5. package/dist/cli/hooks.js +14 -3
  6. package/dist/cli/session-stop.d.ts +1 -1
  7. package/dist/cli/session-tool-hook.d.ts +1 -1
  8. package/dist/cli-registry.js +1 -1
  9. package/dist/data/access.js +2 -1
  10. package/dist/generated/memory-ui-graph.browser.js +481 -318
  11. package/dist/governance/locks.js +6 -0
  12. package/dist/graph-core/index.d.ts +2 -0
  13. package/dist/graph-core/index.js +2 -0
  14. package/dist/graph-core/model.d.ts +84 -0
  15. package/dist/graph-core/model.js +355 -0
  16. package/dist/graph-core/types.d.ts +110 -0
  17. package/dist/graph-core/types.js +43 -0
  18. package/dist/index.js +4 -1
  19. package/dist/init/init-uninstall.d.ts +1 -0
  20. package/dist/init/init-uninstall.js +1 -1
  21. package/dist/init/setup.js +11 -4
  22. package/dist/link/context.js +2 -1
  23. package/dist/link/link.js +3 -2
  24. package/dist/link/skills.js +2 -1
  25. package/dist/memory-ui-graph.runtime.js +481 -318
  26. package/dist/phren-core.d.ts +16 -0
  27. package/dist/phren-core.js +21 -0
  28. package/dist/phren-paths.js +8 -4
  29. package/dist/profile-store.js +3 -2
  30. package/dist/project-config.js +2 -1
  31. package/dist/shared/index.js +1 -1
  32. package/dist/shared/retrieval.d.ts +28 -0
  33. package/dist/shared/retrieval.js +45 -0
  34. package/dist/shell/entry.d.ts +3 -3
  35. package/dist/shell/entry.js +19 -44
  36. package/dist/shell/graph/canvas.d.ts +64 -0
  37. package/dist/shell/graph/canvas.js +256 -0
  38. package/dist/shell/graph/controller.d.ts +164 -0
  39. package/dist/shell/graph/controller.js +645 -0
  40. package/dist/shell/graph/glyphs.d.ts +12 -0
  41. package/dist/shell/graph/glyphs.js +31 -0
  42. package/dist/shell/graph/graph-view.d.ts +12 -0
  43. package/dist/shell/graph/graph-view.js +408 -0
  44. package/dist/shell/graph/layout.d.ts +68 -0
  45. package/dist/shell/graph/layout.js +267 -0
  46. package/dist/shell/input.d.ts +3 -0
  47. package/dist/shell/input.js +24 -4
  48. package/dist/shell/intro.d.ts +37 -0
  49. package/dist/shell/intro.js +82 -0
  50. package/dist/shell/logo-fx.d.ts +35 -0
  51. package/dist/shell/logo-fx.js +128 -0
  52. package/dist/shell/render.d.ts +2 -2
  53. package/dist/shell/render.js +12 -28
  54. package/dist/shell/shell.d.ts +13 -1
  55. package/dist/shell/shell.js +45 -7
  56. package/dist/shell/startup.d.ts +37 -0
  57. package/dist/shell/startup.js +105 -0
  58. package/dist/shell/state-store.d.ts +1 -1
  59. package/dist/shell/state-store.js +1 -1
  60. package/dist/shell/types.js +1 -0
  61. package/dist/shell/view.d.ts +3 -0
  62. package/dist/shell/view.js +24 -3
  63. package/dist/store-registry.js +3 -3
  64. package/dist/test-global-setup.d.ts +1 -0
  65. package/dist/test-global-setup.js +22 -0
  66. package/dist/tool-registry.js +1 -0
  67. package/dist/ui/data.d.ts +15 -7
  68. package/dist/ui/data.js +102 -3
  69. package/dist/utils-fts.js +2 -1
  70. package/dist/utils-helpers.d.ts +1 -0
  71. package/dist/utils-helpers.js +6 -0
  72. package/dist/utils.d.ts +1 -1
  73. package/dist/utils.js +1 -1
  74. package/package.json +11 -7
package/dist/ui/data.js CHANGED
@@ -10,13 +10,32 @@ import { hookConfigPaths, hookConfigRoots } from "../provider-adapters.js";
10
10
  import { readProjectConfig, isProjectHookEnabled, PROJECT_HOOK_EVENTS } from "../project-config.js";
11
11
  import { getAllSkills } from "../skill/registry.js";
12
12
  import { resolveTaskFilePath, readTasks, TASKS_FILENAME } from "../data/tasks.js";
13
- import { FINDINGS_FILENAME } from "../data/access.js";
13
+ import { FINDINGS_FILENAME, readFindings } from "../data/access.js";
14
14
  import { buildIndex, queryDocBySourceKey, queryRows } from "../shared/index.js";
15
15
  import { readProjectTopics, classifyTopicForText } from "../project-topics.js";
16
16
  import { entryScoreKey } from "../governance/scores.js";
17
17
  import { findingStableId } from "../finding-graph-id.js";
18
18
  import { readRecentLookups } from "../governance/activity.js";
19
19
  import { logger } from "../logger.js";
20
+ /** `[tag] text` → `text`, lower-cased, for matching lifecycle snippets against node labels. */
21
+ function lifecycleKey(text) {
22
+ return text.replace(/^\[[a-z_-]+\]\s+/i, "").trim().toLowerCase();
23
+ }
24
+ /**
25
+ * Resolve a 60-char lifecycle snippet to a finding node of the same project.
26
+ * Either side may be the prefix of the other: the snippet is truncated, and
27
+ * the node label may itself be shorter than 60 chars.
28
+ */
29
+ function resolveLifecycleRef(snippet, candidates) {
30
+ const key = lifecycleKey(snippet);
31
+ if (!key)
32
+ return undefined;
33
+ for (const candidate of candidates) {
34
+ if (candidate.key.startsWith(key) || key.startsWith(candidate.key))
35
+ return candidate.nodeId;
36
+ }
37
+ return undefined;
38
+ }
20
39
  function extractGithubUrl(content) {
21
40
  const match = content.match(/https?:\/\/github\.com\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+/);
22
41
  return match ? match[0] : undefined;
@@ -160,7 +179,7 @@ export function getHooksData(phrenPath, profile) {
160
179
  }
161
180
  return { globalEnabled, tools, customHooks: readCustomHooks(phrenPath), projectOverrides };
162
181
  }
163
- export async function buildGraph(phrenPath, profile, focusProject, existingDb) {
182
+ export async function buildGraph(phrenPath, profile, focusProject, existingDb, opts = {}) {
164
183
  // Collect projects from primary store and all readable non-primary stores
165
184
  const storeProjects = [];
166
185
  const primaryProjects = getProjectDirs(phrenPath, profile)
@@ -205,6 +224,15 @@ export async function buildGraph(phrenPath, profile, focusProject, existingDb) {
205
224
  usedFindingIds.set(id, seen + 1);
206
225
  return seen === 0 ? id : `${id}-${seen + 1}`;
207
226
  };
227
+ // Finding text → node id per project, for resolving lifecycle snippets.
228
+ const findingKeysByProject = new Map();
229
+ const rememberFinding = (project, text, nodeId) => {
230
+ if (!opts.includeLifecycleEdges)
231
+ return;
232
+ const list = findingKeysByProject.get(project) ?? [];
233
+ list.push({ key: lifecycleKey(text), nodeId });
234
+ findingKeysByProject.set(project, list);
235
+ };
208
236
  for (const { storePath, project } of storeProjects) {
209
237
  // Load dynamic topics for this project
210
238
  const { topics: projectTopics } = readProjectTopics(storePath, project);
@@ -318,6 +346,7 @@ export async function buildGraph(phrenPath, profile, focusProject, existingDb) {
318
346
  date: currentDate,
319
347
  });
320
348
  links.push({ source: project, target: nodeId });
349
+ rememberFinding(project, text, nodeId);
321
350
  for (const other of exactProjectMentions(text, projectSet, project)) {
322
351
  links.push({ source: project, target: other });
323
352
  }
@@ -354,6 +383,7 @@ export async function buildGraph(phrenPath, profile, focusProject, existingDb) {
354
383
  date: currentDate,
355
384
  });
356
385
  links.push({ source: project, target: nodeId });
386
+ rememberFinding(project, text, nodeId);
357
387
  for (const other of exactProjectMentions(text, projectSet, project)) {
358
388
  links.push({ source: project, target: other });
359
389
  }
@@ -390,12 +420,43 @@ export async function buildGraph(phrenPath, profile, focusProject, existingDb) {
390
420
  date: currentDate,
391
421
  });
392
422
  links.push({ source: project, target: nodeId });
423
+ rememberFinding(project, text, nodeId);
393
424
  }
394
425
  const projectNode = projectNodeByName.get(project);
395
426
  if (projectNode) {
396
427
  projectNode.findingCount = (projectNode.findingCount || 0) + taggedCount + untaggedAdded;
397
428
  }
398
429
  }
430
+ // ── Lifecycle edges (opt-in) ─────────────────────────────────────────
431
+ if (opts.includeLifecycleEdges) {
432
+ for (const { storePath, project } of storeProjects) {
433
+ const candidates = findingKeysByProject.get(project);
434
+ if (!candidates?.length)
435
+ continue;
436
+ const result = readFindings(storePath, project);
437
+ if (!result.ok)
438
+ continue;
439
+ for (const item of result.data) {
440
+ if (!item.supersedes && !item.supersededBy && !item.contradicts?.length)
441
+ continue;
442
+ const self = resolveLifecycleRef(item.text, candidates);
443
+ if (!self)
444
+ continue;
445
+ const edge = (snippet, kind, newerFirst) => {
446
+ const other = resolveLifecycleRef(snippet, candidates);
447
+ if (!other || other === self)
448
+ return;
449
+ links.push(newerFirst ? { source: self, target: other, kind } : { source: other, target: self, kind });
450
+ };
451
+ if (item.supersedes)
452
+ edge(item.supersedes, "supersedes", true);
453
+ if (item.supersededBy)
454
+ edge(item.supersededBy, "supersedes", false);
455
+ for (const snippet of item.contradicts ?? [])
456
+ edge(snippet, "contradicts", true);
457
+ }
458
+ }
459
+ }
399
460
  // ── Tasks ──────────────────────────────────────────────────────────
400
461
  try {
401
462
  for (const { storePath, project } of storeProjects) {
@@ -479,6 +540,7 @@ export async function buildGraph(phrenPath, profile, focusProject, existingDb) {
479
540
  refsByEntity.set(entityId, refs);
480
541
  }
481
542
  }
543
+ const entityNodeIds = new Map();
482
544
  if (rows) {
483
545
  for (const row of rows) {
484
546
  const entityId = typeof row[0] === "number" ? row[0] : -1;
@@ -517,7 +579,44 @@ export async function buildGraph(phrenPath, profile, focusProject, existingDb) {
517
579
  for (const proj of linkedProjects) {
518
580
  links.push({ source: nodeId, target: proj });
519
581
  }
582
+ entityNodeIds.set(entityId, nodeId);
583
+ }
584
+ }
585
+ // ── Fragment co-occurrence edges (opt-in) ──────────────────────────
586
+ // Two fragments mentioned by the same document are related; the more
587
+ // documents they share, the stronger the tie. Derived from refsByEntity,
588
+ // so no extra SQL.
589
+ if (opts.includeFragmentEdges && entityNodeIds.size > 1) {
590
+ const MAX_ENTITIES_PER_DOC = 40;
591
+ const MAX_FRAGMENT_EDGES = 400;
592
+ const entitiesByDoc = new Map();
593
+ for (const [entityId, nodeId] of entityNodeIds) {
594
+ for (const ref of refsByEntity.get(entityId) ?? []) {
595
+ const list = entitiesByDoc.get(ref.doc) ?? [];
596
+ if (list.length < MAX_ENTITIES_PER_DOC && !list.includes(nodeId))
597
+ list.push(nodeId);
598
+ entitiesByDoc.set(ref.doc, list);
599
+ }
600
+ }
601
+ const pairCounts = new Map();
602
+ for (const members of entitiesByDoc.values()) {
603
+ const sorted = members.slice().sort();
604
+ for (let i = 0; i < sorted.length; i++) {
605
+ for (let j = i + 1; j < sorted.length; j++) {
606
+ const key = `${sorted[i]}||${sorted[j]}`;
607
+ const entry = pairCounts.get(key) ?? { a: sorted[i], b: sorted[j], count: 0 };
608
+ entry.count++;
609
+ pairCounts.set(key, entry);
610
+ }
611
+ }
520
612
  }
613
+ const ranked = Array.from(pairCounts.values()).sort((x, y) => y.count - x.count || x.a.localeCompare(y.a) || x.b.localeCompare(y.b));
614
+ // Prefer pairs that co-occur in several docs; on a small store fall back
615
+ // to single co-mentions so the fragment layer still has structure.
616
+ const strong = ranked.filter((pair) => pair.count >= 2);
617
+ const chosen = (strong.length >= 20 ? strong : ranked).slice(0, MAX_FRAGMENT_EDGES);
618
+ for (const pair of chosen)
619
+ links.push({ source: pair.a, target: pair.b, kind: "fragment" });
521
620
  }
522
621
  }
523
622
  catch {
@@ -582,7 +681,7 @@ export async function buildGraph(phrenPath, profile, focusProject, existingDb) {
582
681
  }
583
682
  const seen = new Set();
584
683
  const dedupedLinks = links.filter((link) => {
585
- const key = [link.source, link.target].sort().join("||");
684
+ const key = `${[link.source, link.target].sort().join("||")}::${link.kind ?? ""}`;
586
685
  if (seen.has(key))
587
686
  return false;
588
687
  seen.add(key);
package/dist/utils-fts.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as fs from "fs";
2
2
  import * as path from "path";
3
3
  import * as yaml from "js-yaml";
4
+ import { loadYamlDocument } from "./phren-core.js";
4
5
  import { fileURLToPath } from "url";
5
6
  import { findPhrenPath } from "./phren-paths.js";
6
7
  import { isValidProjectName } from "./utils-paths.js";
@@ -122,7 +123,7 @@ function parseSynonymsYaml(filePath) {
122
123
  if (!fs.existsSync(filePath))
123
124
  return {};
124
125
  try {
125
- const parsed = yaml.load(fs.readFileSync(filePath, "utf8"), { schema: yaml.CORE_SCHEMA });
126
+ const parsed = loadYamlDocument(fs.readFileSync(filePath, "utf8"), (text) => yaml.load(text, { schema: yaml.CORE_SCHEMA }));
126
127
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
127
128
  return {};
128
129
  const loaded = {};
@@ -9,6 +9,7 @@ export declare function resolveExecCommand(cmd: string): ResolvedExecCommand;
9
9
  export declare function errorMessage(err: unknown): string;
10
10
  export declare function isFeatureEnabled(envName: string, defaultValue?: boolean): boolean;
11
11
  export declare function clampInt(raw: string | undefined, fallback: number, min: number, max: number): number;
12
+ export declare function clampFloat(raw: string | undefined, fallback: number, min: number, max: number): number;
12
13
  export declare function getOptionValue(args: string[], name: string): string | undefined;
13
14
  export declare function getPositionalArgs(args: string[], optionNamesWithValues: string[]): string[];
14
15
  export {};
@@ -78,6 +78,12 @@ export function clampInt(raw, fallback, min, max) {
78
78
  return fallback;
79
79
  return Math.min(max, Math.max(min, parsed));
80
80
  }
81
+ export function clampFloat(raw, fallback, min, max) {
82
+ const parsed = Number.parseFloat(raw || "");
83
+ if (Number.isNaN(parsed))
84
+ return fallback;
85
+ return Math.min(max, Math.max(min, parsed));
86
+ }
81
87
  // ── Argv parsing helpers ────────────────────────────────────────────────────
82
88
  export function getOptionValue(args, name) {
83
89
  const exactIdx = args.indexOf(name);
package/dist/utils.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { runGitOrThrow, runGit, normalizeExecCommand, resolveExecCommand, errorMessage, isFeatureEnabled, clampInt, getOptionValue, getPositionalArgs, } from "./utils-helpers.js";
1
+ export { runGitOrThrow, runGit, normalizeExecCommand, resolveExecCommand, errorMessage, isFeatureEnabled, clampInt, clampFloat, getOptionValue, getPositionalArgs, } from "./utils-helpers.js";
2
2
  export { isValidProjectName, safeProjectPath, queueFilePath, QUEUE_FILENAME, } from "./utils-paths.js";
3
3
  export { STOP_WORDS, extractKeywordEntries, extractKeywords, learnedSynonymsPath, loadLearnedSynonyms, loadSynonymMap, learnSynonym, removeLearnedSynonym, sanitizeFts5Query, buildRobustFtsQuery, buildRelaxedFtsQuery, buildFtsQueryVariants, } from "./utils-fts.js";
package/dist/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // Barrel re-export. Implementations split across utils-helpers.ts (general
2
2
  // helpers, argv parsing, exec helpers), utils-paths.ts (path validation),
3
3
  // utils-fts.ts (FTS5 query building, synonym/keyword extraction).
4
- export { runGitOrThrow, runGit, normalizeExecCommand, resolveExecCommand, errorMessage, isFeatureEnabled, clampInt, getOptionValue, getPositionalArgs, } from "./utils-helpers.js";
4
+ export { runGitOrThrow, runGit, normalizeExecCommand, resolveExecCommand, errorMessage, isFeatureEnabled, clampInt, clampFloat, getOptionValue, getPositionalArgs, } from "./utils-helpers.js";
5
5
  export { isValidProjectName, safeProjectPath, queueFilePath, QUEUE_FILENAME, } from "./utils-paths.js";
6
6
  export { STOP_WORDS, extractKeywordEntries, extractKeywords, learnedSynonymsPath, loadLearnedSynonyms, loadSynonymMap, learnSynonym, removeLearnedSynonym, sanitizeFts5Query, buildRobustFtsQuery, buildRelaxedFtsQuery, buildFtsQueryVariants, } from "./utils-fts.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@phren/cli",
3
- "version": "0.1.44",
4
- "description": "Knowledge layer for AI agents \u2014 CLI, MCP server, and data layer",
3
+ "version": "0.1.45",
4
+ "description": "Knowledge layer for AI agents — CLI, MCP server, and data layer",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "phren": "dist/index.js"
@@ -85,6 +85,10 @@
85
85
  "types": "./dist/shell/render-api.d.ts",
86
86
  "default": "./dist/shell/render-api.js"
87
87
  },
88
+ "./shell/intro": {
89
+ "types": "./dist/shell/intro.d.ts",
90
+ "default": "./dist/shell/intro.js"
91
+ },
88
92
  "./phren-art": {
89
93
  "types": "./dist/phren-art.d.ts",
90
94
  "default": "./dist/phren-art.js"
@@ -104,11 +108,11 @@
104
108
  "preuninstall": "node scripts/preuninstall.mjs"
105
109
  },
106
110
  "dependencies": {
107
- "@modelcontextprotocol/sdk": "^1.29.0",
108
- "chalk": "^5.6.2",
111
+ "@modelcontextprotocol/sdk": "^1.30.0",
112
+ "chalk": "^6.0.0",
109
113
  "glob": "^13.0.6",
110
- "inquirer": "^14.0.2",
111
- "js-yaml": "^4.2.0",
114
+ "inquirer": "^14.1.0",
115
+ "js-yaml": "^5.3.0",
112
116
  "sql.js-fts5": "^1.4.0",
113
117
  "zod": "^4.4.3"
114
118
  },
@@ -131,7 +135,7 @@
131
135
  },
132
136
  "devDependencies": {
133
137
  "3d-force-graph": "^1.80.0",
134
- "three": "^0.184.0"
138
+ "three": "^0.185.1"
135
139
  },
136
140
  "publishConfig": {
137
141
  "access": "public"