@phren/cli 0.3.1 → 0.3.3

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.
@@ -1,8 +1,14 @@
1
1
  /**
2
2
  * Resolves the content conflicts a store merge can settle without a person:
3
- * tasks.md per task id against the merge base, generated blocks from the
4
- * incoming side, and the record-oriented files that already union-merge.
5
- * Everything else stays conflicted so the caller aborts and names it.
3
+ * tasks.md per task id against the merge base, generated summaries from the
4
+ * incoming side, and the append-only record files (findings, notes, journal,
5
+ * review queue, topic archives) as a union of both sides. Everything else
6
+ * stays conflicted so the caller aborts and names it.
7
+ *
8
+ * Any file left unresolved aborts the whole merge, and every later auto-save
9
+ * then commits locally and fails to push, so a store drifts further from its
10
+ * remote each session. Every file phren itself writes during normal use needs
11
+ * a strategy here.
6
12
  */
7
13
  import { execFileSync, spawnSync } from "child_process";
8
14
  import * as crypto from "crypto";
@@ -29,6 +35,10 @@ export function conflictStrategy(relFile) {
29
35
  return "topic";
30
36
  if (name === "summary.md")
31
37
  return "summary";
38
+ if (name === "review.md")
39
+ return "union";
40
+ if (/(^|\/)(notes|journal)\/[^/]+\.md$/i.test(file))
41
+ return "union";
32
42
  return null;
33
43
  }
34
44
  function git(cwd, args) {
@@ -71,15 +81,38 @@ function mergeText(base, ours, theirs) {
71
81
  fs.rmSync(dir, { recursive: true, force: true });
72
82
  }
73
83
  }
84
+ /**
85
+ * A line-level three-way merge that keeps both sides of a conflicting hunk,
86
+ * local lines first (`git merge-file --union`). For append-only records two
87
+ * machines adding entries at the same spot is not a real conflict.
88
+ */
89
+ function unionText(base, ours, theirs) {
90
+ const clean = mergeText(base, ours, theirs);
91
+ if (clean !== null)
92
+ return clean;
93
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "phren-merge-"));
94
+ try {
95
+ const [o, b, t] = ["ours", "base", "theirs"].map((name) => path.join(dir, name));
96
+ fs.writeFileSync(o, ours);
97
+ fs.writeFileSync(b, base);
98
+ fs.writeFileSync(t, theirs);
99
+ const result = spawnSync("git", ["merge-file", "--union", "-p", o, b, t], { encoding: "utf8", env: nonInteractiveGitEnv(), timeout: EXEC_TIMEOUT_MS });
100
+ return result.status === 0 ? result.stdout : null;
101
+ }
102
+ finally {
103
+ fs.rmSync(dir, { recursive: true, force: true });
104
+ }
105
+ }
74
106
  /**
75
107
  * Generated blocks regenerate, so the incoming block wins; the rest of the
76
- * file must still merge line by line.
108
+ * file merges with `merge`: a union of both sides by default (a topic
109
+ * archive's bullets).
77
110
  */
78
- function mergeWithGeneratedBlock(base, ours, theirs, start, end, where) {
111
+ function mergeWithGeneratedBlock(base, ours, theirs, start, end, where, merge = unionText) {
79
112
  const b = splitBlock(base, start, end);
80
113
  const o = splitBlock(ours, start, end);
81
114
  const t = splitBlock(theirs, start, end);
82
- const rest = mergeText(b.rest, o.rest, t.rest);
115
+ const rest = merge(b.rest, o.rest, t.rest);
83
116
  if (rest === null)
84
117
  return null;
85
118
  const block = t.block ?? o.block;
@@ -94,7 +127,11 @@ function resolveContent(strategy, base, ours, theirs) {
94
127
  // Archived tasks only accumulate: keep both sides, the incoming version of any duplicate.
95
128
  case "archive": return mergeTask(theirs, ours);
96
129
  case "topic": return mergeWithGeneratedBlock(base, ours, theirs, NOW_START, NOW_END, "top");
97
- case "summary": return mergeWithGeneratedBlock(base, ours, theirs, KNOWS_START, KNOWS_END, "bottom");
130
+ // Summaries are regenerated from the store: when the hand-written part
131
+ // doesn't merge cleanly, take the incoming file whole and let the next
132
+ // summarize pass fold in anything only this machine had.
133
+ case "summary": return mergeWithGeneratedBlock(base, ours, theirs, KNOWS_START, KNOWS_END, "bottom", mergeText) ?? theirs;
134
+ case "union": return unionText(base, ours, theirs);
98
135
  }
99
136
  }
100
137
  /** Resolves what it can in the store's in-progress merge and stages it. */
@@ -698,7 +698,7 @@ async function handleGetFindings(ctx, { project, limit, include_superseded, incl
698
698
  if (entry.scope)
699
699
  metadata.push(`scope=${entry.scope}`);
700
700
  if (entry.symbol)
701
- metadata.push(`symbol=${entry.symbol}`);
701
+ metadata.push(`name=${entry.symbol}`);
702
702
  if (entry.supersedes)
703
703
  metadata.push(`supersedes="${entry.supersedes.slice(0, 30)}"`);
704
704
  if (entry.supersededBy)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phren/cli",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Knowledge layer for AI agents - CLI, MCP server, and data layer",
5
5
  "type": "module",
6
6
  "bin": {