@phren/cli 0.3.11 → 0.3.13

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 (182) hide show
  1. package/dist/bridge/account-usage.d.ts +124 -0
  2. package/dist/bridge/account-usage.js +258 -0
  3. package/dist/bridge/agent-hook-stores.d.ts +3 -0
  4. package/dist/bridge/agent-hook-stores.js +5 -0
  5. package/dist/bridge/agent-hooks.d.ts +162 -5
  6. package/dist/bridge/agent-hooks.js +682 -49
  7. package/dist/bridge/approval-summary.d.ts +16 -0
  8. package/dist/bridge/approval-summary.js +133 -0
  9. package/dist/bridge/authority-command.d.ts +20 -0
  10. package/dist/bridge/authority-command.js +120 -0
  11. package/dist/bridge/authority.d.ts +223 -0
  12. package/dist/bridge/authority.js +231 -0
  13. package/dist/bridge/claude-account-setup.d.ts +14 -0
  14. package/dist/bridge/claude-account-setup.js +69 -0
  15. package/dist/bridge/claude-accounts.d.ts +49 -0
  16. package/dist/bridge/claude-accounts.js +195 -0
  17. package/dist/bridge/code-routes.js +2 -2
  18. package/dist/bridge/codex-app-server.d.ts +144 -0
  19. package/dist/bridge/codex-app-server.js +319 -0
  20. package/dist/bridge/codex-auth-refresh.d.ts +33 -0
  21. package/dist/bridge/codex-auth-refresh.js +71 -0
  22. package/dist/bridge/codex-hook-trust.d.ts +27 -0
  23. package/dist/bridge/codex-hook-trust.js +237 -0
  24. package/dist/bridge/codex-question-reply.d.ts +16 -0
  25. package/dist/bridge/codex-question-reply.js +57 -0
  26. package/dist/bridge/codex-review-mode.d.ts +10 -0
  27. package/dist/bridge/codex-review-mode.js +74 -0
  28. package/dist/bridge/codex-servers.d.ts +217 -0
  29. package/dist/bridge/codex-servers.js +636 -0
  30. package/dist/bridge/command.js +97 -4
  31. package/dist/bridge/computer-identity.d.ts +75 -0
  32. package/dist/bridge/computer-identity.js +166 -0
  33. package/dist/bridge/conductor-group.d.ts +91 -8
  34. package/dist/bridge/conductor-group.js +105 -9
  35. package/dist/bridge/conductor-role.d.ts +94 -0
  36. package/dist/bridge/conductor-role.js +176 -0
  37. package/dist/bridge/conductor-sets.d.ts +20 -0
  38. package/dist/bridge/conductor-sets.js +59 -0
  39. package/dist/bridge/dispatch-command.d.ts +3 -0
  40. package/dist/bridge/dispatch-command.js +82 -12
  41. package/dist/bridge/dispatch-returns.d.ts +128 -19
  42. package/dist/bridge/dispatch-returns.js +371 -54
  43. package/dist/bridge/dispatch.d.ts +128 -3
  44. package/dist/bridge/dispatch.js +303 -42
  45. package/dist/bridge/fanouts.d.ts +7 -1
  46. package/dist/bridge/fanouts.js +39 -4
  47. package/dist/bridge/folder-trust.d.ts +56 -0
  48. package/dist/bridge/folder-trust.js +195 -0
  49. package/dist/bridge/grants.d.ts +22 -1
  50. package/dist/bridge/grants.js +57 -9
  51. package/dist/bridge/hand-off-queue.d.ts +74 -0
  52. package/dist/bridge/hand-off-queue.js +235 -0
  53. package/dist/bridge/hand-off.d.ts +30 -10
  54. package/dist/bridge/hand-off.js +79 -46
  55. package/dist/bridge/harness-status.d.ts +11 -0
  56. package/dist/bridge/harness-status.js +32 -0
  57. package/dist/bridge/harnesses.d.ts +39 -0
  58. package/dist/bridge/harnesses.js +65 -0
  59. package/dist/bridge/health.d.ts +2 -0
  60. package/dist/bridge/health.js +1 -1
  61. package/dist/bridge/herdr.d.ts +11 -2
  62. package/dist/bridge/herdr.js +98 -23
  63. package/dist/bridge/hook-fast.d.ts +4 -0
  64. package/dist/bridge/hook-fast.js +68 -0
  65. package/dist/bridge/install.d.ts +16 -1
  66. package/dist/bridge/install.js +102 -21
  67. package/dist/bridge/launch-brief.d.ts +96 -0
  68. package/dist/bridge/launch-brief.js +164 -0
  69. package/dist/bridge/model-switch.d.ts +3 -0
  70. package/dist/bridge/model-switch.js +17 -1
  71. package/dist/bridge/models.d.ts +8 -4
  72. package/dist/bridge/models.js +24 -8
  73. package/dist/bridge/mux-wire.d.ts +9 -0
  74. package/dist/bridge/mux-wire.js +19 -0
  75. package/dist/bridge/opencode-pane-server.d.ts +113 -0
  76. package/dist/bridge/opencode-pane-server.js +332 -0
  77. package/dist/bridge/opencode-panes.d.ts +111 -0
  78. package/dist/bridge/opencode-panes.js +295 -0
  79. package/dist/bridge/pane-accounts.d.ts +8 -0
  80. package/dist/bridge/pane-accounts.js +46 -0
  81. package/dist/bridge/pane-status.d.ts +12 -0
  82. package/dist/bridge/pane-status.js +50 -1
  83. package/dist/bridge/prompt-startup.d.ts +5 -0
  84. package/dist/bridge/prompt-startup.js +24 -0
  85. package/dist/bridge/protocol.d.ts +5 -0
  86. package/dist/bridge/protocol.js +4 -0
  87. package/dist/bridge/push.d.ts +11 -4
  88. package/dist/bridge/push.js +27 -4
  89. package/dist/bridge/questions.d.ts +37 -2
  90. package/dist/bridge/questions.js +158 -15
  91. package/dist/bridge/resources.d.ts +9 -3
  92. package/dist/bridge/resources.js +24 -8
  93. package/dist/bridge/schedule-format.d.ts +2 -0
  94. package/dist/bridge/schedule-format.js +3 -0
  95. package/dist/bridge/schedule-launch.d.ts +2 -1
  96. package/dist/bridge/schedule-launch.js +27 -53
  97. package/dist/bridge/schedule-watch.d.ts +24 -1
  98. package/dist/bridge/schedule-watch.js +89 -2
  99. package/dist/bridge/server-launch.d.ts +22 -5
  100. package/dist/bridge/server-launch.js +238 -32
  101. package/dist/bridge/server-overview.d.ts +10 -3
  102. package/dist/bridge/server-overview.js +32 -15
  103. package/dist/bridge/server-pane-routes.d.ts +3 -0
  104. package/dist/bridge/server-pane-routes.js +150 -18
  105. package/dist/bridge/server-routes.d.ts +11 -0
  106. package/dist/bridge/server-routes.js +214 -36
  107. package/dist/bridge/server-stream.d.ts +2 -0
  108. package/dist/bridge/server-stream.js +22 -8
  109. package/dist/bridge/server.d.ts +6 -1
  110. package/dist/bridge/server.js +58 -13
  111. package/dist/bridge/session-activity.d.ts +93 -0
  112. package/dist/bridge/session-activity.js +139 -0
  113. package/dist/bridge/session-rename.d.ts +48 -0
  114. package/dist/bridge/session-rename.js +190 -0
  115. package/dist/bridge/session-servers.js +2 -2
  116. package/dist/bridge/settings-switch.d.ts +60 -0
  117. package/dist/bridge/settings-switch.js +287 -0
  118. package/dist/bridge/speech-voice.d.ts +55 -0
  119. package/dist/bridge/speech-voice.js +132 -0
  120. package/dist/bridge/speech.d.ts +70 -11
  121. package/dist/bridge/speech.js +169 -41
  122. package/dist/bridge/stalls.d.ts +22 -0
  123. package/dist/bridge/stalls.js +57 -0
  124. package/dist/bridge/sudo.d.ts +209 -0
  125. package/dist/bridge/sudo.js +501 -0
  126. package/dist/bridge/terminal-herdr.js +9 -3
  127. package/dist/bridge/terminal-tmux.d.ts +15 -3
  128. package/dist/bridge/terminal-tmux.js +103 -13
  129. package/dist/bridge/terminal.d.ts +27 -4
  130. package/dist/bridge/terminal.js +8 -1
  131. package/dist/bridge/transcript-claude.d.ts +4 -0
  132. package/dist/bridge/transcript-claude.js +186 -16
  133. package/dist/bridge/transcript-codex.d.ts +0 -2
  134. package/dist/bridge/transcript-codex.js +29 -4
  135. package/dist/bridge/transcript-preview.d.ts +1 -0
  136. package/dist/bridge/transcript-preview.js +24 -4
  137. package/dist/bridge/transcripts.d.ts +15 -2
  138. package/dist/bridge/transcripts.js +47 -16
  139. package/dist/bridge/turn-records.d.ts +85 -0
  140. package/dist/bridge/turn-records.js +143 -0
  141. package/dist/bridge/uploads.d.ts +3 -0
  142. package/dist/bridge/uploads.js +14 -0
  143. package/dist/bridge/usage.d.ts +56 -10
  144. package/dist/bridge/usage.js +190 -45
  145. package/dist/bridge-hook.mjs +27975 -20636
  146. package/dist/cli/claude-unmanaged.d.ts +12 -0
  147. package/dist/cli/claude-unmanaged.js +105 -0
  148. package/dist/cli/schedules.js +2 -1
  149. package/dist/cli/session-start.js +10 -1
  150. package/dist/cli/session-stop.js +9 -1
  151. package/dist/cli-registry.js +31 -6
  152. package/dist/data/task-receipts.d.ts +19 -0
  153. package/dist/data/task-receipts.js +68 -0
  154. package/dist/data/tasks.js +4 -1
  155. package/dist/generated/memory-ui-graph.browser.js +63 -63
  156. package/dist/graph-core/model.js +24 -3
  157. package/dist/graph-core/types.d.ts +4 -1
  158. package/dist/graph-core/types.js +1 -0
  159. package/dist/init/init-preset.js +7 -3
  160. package/dist/init/init-uninstall.js +2 -11
  161. package/dist/init/teardown.d.ts +3 -0
  162. package/dist/init/teardown.js +47 -0
  163. package/dist/link/context.js +21 -9
  164. package/dist/mcp/plugin-mode.js +1 -1
  165. package/dist/memory-ui-graph.runtime.js +63 -63
  166. package/dist/modules/code-package.d.ts +1 -0
  167. package/dist/modules/code-package.js +36 -7
  168. package/dist/modules/registry.js +17 -16
  169. package/dist/profile-store.d.ts +6 -0
  170. package/dist/profile-store.js +25 -1
  171. package/dist/shell/graph/glyphs.js +4 -0
  172. package/dist/shell/graph/graph-view.js +2 -0
  173. package/dist/status.js +7 -1
  174. package/dist/sync/task-claim.js +3 -2
  175. package/dist/task/lifecycle.js +25 -4
  176. package/dist/test-global-setup.js +5 -0
  177. package/dist/tools/dispatch.js +52 -4
  178. package/dist/tools/tasks.js +10 -1
  179. package/package.json +1 -1
  180. package/plugins/opencode/phren-transcript.js +87 -4
  181. package/starter/global/AGENTS.md +4 -0
  182. package/starter/global/skills/conductor/SKILL.md +51 -4
@@ -35,6 +35,10 @@ export function deriveKind(node) {
35
35
  return "entity";
36
36
  if (node.group === "reference")
37
37
  return "reference";
38
+ if (node.group === "topic")
39
+ return "topic";
40
+ if (node.group === "note")
41
+ return "note";
38
42
  if (node.group.startsWith("task-"))
39
43
  return "task";
40
44
  if (node.group.startsWith("topic:"))
@@ -102,6 +106,10 @@ export function baseColorForNode(node, storeColor) {
102
106
  return KIND_COLORS.entity;
103
107
  if (kind === "reference")
104
108
  return KIND_COLORS.reference;
109
+ if (kind === "topic")
110
+ return topicColor(node.topicSlug);
111
+ if (kind === "note")
112
+ return KIND_COLORS.note;
105
113
  return KIND_COLORS.other;
106
114
  }
107
115
  export function sizeForNode(node, scores) {
@@ -119,6 +127,10 @@ export function sizeForNode(node, scores) {
119
127
  return clamp(8 + (node.section === "Active" ? 2 : 0) + (node.priority === "high" ? 1 : 0), 8, 15);
120
128
  if (kind === "reference")
121
129
  return clamp(7 + Math.sqrt(refCount + 1) * 1.2, 7, 12);
130
+ if (kind === "topic")
131
+ return clamp(10 + Math.sqrt(refCount + 1) * 2.2, 11, 24);
132
+ if (kind === "note")
133
+ return 9;
122
134
  return 9;
123
135
  }
124
136
  export function nodeRadius(node) {
@@ -148,7 +160,7 @@ export function normalizeNode(node, scores, storeColor) {
148
160
  health: inferHealth(score),
149
161
  baseColor: baseColorForNode(node, storeColor),
150
162
  size: sizeForNode(node, scores),
151
- forceLabel: kind === "project" || (kind === "entity" && (node.refCount || 0) >= 12),
163
+ forceLabel: kind === "project" || (kind === "entity" && (node.refCount || 0) >= 12) || (kind === "topic" && (node.refCount || 0) >= 8),
152
164
  };
153
165
  }
154
166
  /** Undirected adjacency over every node/link, ignoring links to unknown ids. */
@@ -165,7 +177,7 @@ export function buildFullAdjacency(nodes, links) {
165
177
  return adjacency;
166
178
  }
167
179
  export function connectionCounts(model, nodeId) {
168
- const counts = { total: 0, projects: 0, findings: 0, tasks: 0, entities: 0, references: 0 };
180
+ const counts = { total: 0, projects: 0, findings: 0, tasks: 0, entities: 0, references: 0, topics: 0, notes: 0 };
169
181
  const adjacency = model.fullAdjacency.get(nodeId);
170
182
  if (!adjacency)
171
183
  return counts;
@@ -184,6 +196,10 @@ export function connectionCounts(model, nodeId) {
184
196
  counts.entities++;
185
197
  else if (neighbor.kind === "reference")
186
198
  counts.references++;
199
+ else if (neighbor.kind === "topic")
200
+ counts.topics++;
201
+ else if (neighbor.kind === "note")
202
+ counts.notes++;
187
203
  });
188
204
  return counts;
189
205
  }
@@ -272,6 +288,10 @@ export function nodeRank(node, filters, scores) {
272
288
  rank += node.section === "Active" ? 540 : 470;
273
289
  if (node.kind === "reference")
274
290
  rank += 180 + (node.refCount || 0) * 3;
291
+ if (node.kind === "topic")
292
+ rank += 700 + (node.refCount || 0) * 4;
293
+ if (node.kind === "note")
294
+ rank += 440;
275
295
  if (node.priority === "high")
276
296
  rank += 60;
277
297
  if (node.health === "healthy")
@@ -459,7 +479,8 @@ export function rankedProjectIds(nodes, project) {
459
479
  return left > right ? -1 : 1;
460
480
  });
461
481
  const tasks = nodes.filter((node) => node.project === project && deriveKind(node) === "task");
462
- return [...findings, ...tasks].map((node) => node.id);
482
+ const notes = nodes.filter((node) => node.project === project && deriveKind(node) === "note");
483
+ return [...findings, ...tasks, ...notes].map((node) => node.id);
463
484
  }
464
485
  /**
465
486
  * Previous/next id in a ranked list, wrapping at both ends. The list is the
@@ -62,7 +62,7 @@ export type GraphPayload = {
62
62
  scores?: Record<string, ScoreEntry>;
63
63
  topics?: RawTopic[];
64
64
  };
65
- export type NodeKind = "project" | "finding" | "task" | "entity" | "reference" | "other";
65
+ export type NodeKind = "project" | "finding" | "task" | "entity" | "reference" | "topic" | "note" | "other";
66
66
  export type NodeHealth = "healthy" | "decaying" | "stale";
67
67
  export type RuntimeNode = RawNode & {
68
68
  kind: NodeKind;
@@ -86,6 +86,8 @@ export type NodeDetail = RuntimeNode & {
86
86
  tasks: number;
87
87
  entities: number;
88
88
  references: number;
89
+ topics: number;
90
+ notes: number;
89
91
  };
90
92
  score?: ScoreEntry;
91
93
  /** Values supplied by the project pane's inline editor on save. */
@@ -104,6 +106,7 @@ export declare const KIND_COLORS: {
104
106
  project: string;
105
107
  entity: string;
106
108
  reference: string;
109
+ note: string;
107
110
  "task-active": string;
108
111
  "task-queue": string;
109
112
  "task-done": string;
@@ -34,6 +34,7 @@ export const KIND_COLORS = {
34
34
  project: "#f5b342",
35
35
  entity: "#38e1ff",
36
36
  reference: "#42e099",
37
+ note: "#c9a67a",
37
38
  "task-active": "#3ae374",
38
39
  "task-queue": "#48b2ff",
39
40
  "task-done": "#5c6b8a",
@@ -12,7 +12,7 @@ import { configureMcpTargets, configureHooksIfEnabled } from "./init-configure.j
12
12
  import { repairPreexistingInstall } from "./setup.js";
13
13
  import { getMcpEnabledPreference, getHooksEnabledPreference, setHooksEnabledPreference, setManagementPresetPreference, } from "./preferences.js";
14
14
  import { MANAGEMENT_PRESETS, getManagementPreset, parseManagementPreset, presetSummaryLines, resolveManagementCapabilities, } from "./management-preset.js";
15
- import { removePhrenHomeSymlinks, removePhrenWrappers, sweepAgentSkillSymlinks, sweepProjectMirrors } from "./teardown.js";
15
+ import { removeGeneratedHomeFiles, removePhrenHomeSymlinks, removePhrenWrappers, sweepAgentSkillSymlinks, sweepProjectMirrors } from "./teardown.js";
16
16
  import { printSelfWiringSnippet } from "./self-wiring.js";
17
17
  import { DEFAULT_PHREN_PATH, log, confirmPrompt } from "./shared.js";
18
18
  function printCapabilityTable(caps) {
@@ -57,7 +57,8 @@ export async function runPreset(arg, opts = {}) {
57
57
  const teardownNeeded = (prevCaps.linkGlobalClaudeMd && !caps.linkGlobalClaudeMd) ||
58
58
  (prevCaps.installSkillLinks && !caps.installSkillLinks) ||
59
59
  (prevCaps.installWrappers && !caps.installWrappers) ||
60
- (prevCaps.repoMirroring && !caps.repoMirroring);
60
+ (prevCaps.repoMirroring && !caps.repoMirroring) ||
61
+ (prevCaps.selfHeal && !caps.selfHeal);
61
62
  if (teardownNeeded && !opts.yes) {
62
63
  const ok = await confirmPrompt(`Switching ${previous} → ${preset} will remove phren-owned symlinks/wrappers from your machine and repos. Continue?`);
63
64
  if (!ok) {
@@ -94,10 +95,13 @@ export async function runPreset(arg, opts = {}) {
94
95
  removePhrenWrappers();
95
96
  if (prevCaps.repoMirroring && !caps.repoMirroring)
96
97
  sweepProjectMirrors(phrenPath);
98
+ if (prevCaps.selfHeal && !caps.selfHeal)
99
+ removeGeneratedHomeFiles();
97
100
  // Setup of artifacts the new preset adds but the previous one lacked.
98
101
  const setupNeeded = (!prevCaps.linkGlobalClaudeMd && caps.linkGlobalClaudeMd) ||
99
102
  (!prevCaps.installSkillLinks && caps.installSkillLinks) ||
100
- (!prevCaps.repoMirroring && caps.repoMirroring);
103
+ (!prevCaps.repoMirroring && caps.repoMirroring) ||
104
+ (!prevCaps.selfHeal && caps.selfHeal);
101
105
  if (setupNeeded) {
102
106
  try {
103
107
  repairPreexistingInstall(phrenPath, { caps, preset });
@@ -10,7 +10,7 @@ import { FINDINGS_FILENAME } from "../data/access.js";
10
10
  import { codexJsonCandidates, copilotMcpCandidates, cursorMcpCandidates, vscodeMcpCandidates, } from "../provider-adapters.js";
11
11
  import { removeMcpServerAtPath, removeTomlMcpServer, isPhrenCommand, patchJsonFile, } from "./config.js";
12
12
  import { DEFAULT_PHREN_PATH, log } from "./shared.js";
13
- import { sweepProjectMirrors } from "./teardown.js";
13
+ import { removeGeneratedHomeFiles, sweepProjectMirrors } from "./teardown.js";
14
14
  const PHREN_NPM_PACKAGE_NAME = "@phren/cli";
15
15
  function getNpmCommand() {
16
16
  return process.platform === "win32" ? "npm.cmd" : "npm";
@@ -429,16 +429,7 @@ export async function runUninstall(opts = {}) {
429
429
  catch (err) {
430
430
  debugLog(`uninstall: cleanup failed for ${machineFile}: ${errorMessage(err)}`);
431
431
  }
432
- const contextFile = homePath(".phren-context.md");
433
- try {
434
- if (fs.existsSync(contextFile)) {
435
- fs.unlinkSync(contextFile);
436
- log(` Removed machine context file (${contextFile})`);
437
- }
438
- }
439
- catch (err) {
440
- debugLog(`uninstall: cleanup failed for ${contextFile}: ${errorMessage(err)}`);
441
- }
432
+ removeGeneratedHomeFiles();
442
433
  // Remove global AGENTS.md symlink (created by linkGlobal -> ~/.claude/CLAUDE.md)
443
434
  const globalClaudeLink = homePath(".claude", "CLAUDE.md");
444
435
  try {
@@ -1,3 +1,6 @@
1
+ export declare function generatedRootMemoryPath(): string;
2
+ /** Remove only complete managed blocks; surrounding notes and unmarked files survive. */
3
+ export declare function removeGeneratedHomeFiles(): string[];
1
4
  /** Remove the phren-owned ~/.claude/CLAUDE.md and copilot-instructions.md symlinks. */
2
5
  export declare function removePhrenHomeSymlinks(): string[];
3
6
  /** Remove ~/.local/bin/{copilot,cursor,codex,phren} wrappers that carry the phren marker. */
@@ -24,6 +24,53 @@ function agentSkillDirs() {
24
24
  path.join(home, ".codex", "skills"),
25
25
  ];
26
26
  }
27
+ export function generatedRootMemoryPath() {
28
+ const home = homeDir();
29
+ const key = home.replace(/[/\\:]/g, "-").replace(/^-/, "");
30
+ return path.join(home, ".claude", "projects", key, "memory", "MEMORY.md");
31
+ }
32
+ /** Remove only complete managed blocks; surrounding notes and unmarked files survive. */
33
+ export function removeGeneratedHomeFiles() {
34
+ const changed = [];
35
+ const targets = [
36
+ { file: homePath(".phren-context.md"), start: "<!-- phren-managed -->", end: "<!-- phren-managed -->" },
37
+ { file: generatedRootMemoryPath(), start: "<!-- phren:projects:start -->", end: "<!-- phren:projects:end -->" },
38
+ ];
39
+ for (const { file, start, end } of targets) {
40
+ try {
41
+ // A symlink may point at a user's unrelated file, even if it has a marker.
42
+ if (!fs.existsSync(file) || !fs.lstatSync(file).isFile())
43
+ continue;
44
+ const content = fs.readFileSync(file, "utf8");
45
+ const first = content.indexOf(start);
46
+ const last = content.indexOf(end, first + start.length);
47
+ if (first < 0 || last < 0)
48
+ continue;
49
+ let remaining = content.slice(0, first) + content.slice(last + end.length);
50
+ // This exact introduction is generated alongside the root projects block.
51
+ // Custom introductions and any notes following the block remain intact.
52
+ const generatedIntros = [
53
+ "# Root Memory\n\n## Machine Context\nRead `~/.phren-context.md` for profile, active projects, and sync metadata.\n\n",
54
+ "# Root Memory\n\n## Machine Context\nRead `~/.phren-context.md` for profile, active projects, last sync date.\n\n## Cross-Project Notes\n- Read a project's AGENTS.md before making changes.\n- Per-project memory files (MEMORY-{name}.md) have commands, versions, findings.\n\n",
55
+ ];
56
+ if (file === generatedRootMemoryPath()) {
57
+ const introduction = generatedIntros.find((intro) => remaining.startsWith(intro));
58
+ if (introduction)
59
+ remaining = remaining.slice(introduction.length);
60
+ }
61
+ if (remaining.trim())
62
+ fs.writeFileSync(file, remaining);
63
+ else
64
+ fs.unlinkSync(file);
65
+ changed.push(file);
66
+ log(` Removed phren-managed content: ${file}`);
67
+ }
68
+ catch (err) {
69
+ debugLog(`removeGeneratedHomeFiles: cleanup failed for ${file}: ${errorMessage(err)}`);
70
+ }
71
+ }
72
+ return changed;
73
+ }
27
74
  /** Remove the phren-owned ~/.claude/CLAUDE.md and copilot-instructions.md symlinks. */
28
75
  export function removePhrenHomeSymlinks() {
29
76
  const removed = [];
@@ -192,13 +192,9 @@ export function rebuildMemory(phrenPath, projects) {
192
192
  if (!hasSummaries)
193
193
  return;
194
194
  fs.mkdirSync(memoryDir, { recursive: true });
195
- let header = "";
196
- if (fs.existsSync(memoryFile)) {
197
- const existing = fs.readFileSync(memoryFile, "utf8");
198
- const idx = existing.indexOf("<!-- phren:projects:start -->");
199
- if (idx !== -1)
200
- header = existing.slice(0, idx);
201
- }
195
+ const existing = fs.existsSync(memoryFile) ? fs.readFileSync(memoryFile, "utf8") : "";
196
+ const projectsStart = "<!-- phren:projects:start -->";
197
+ const projectsEnd = "<!-- phren:projects:end -->";
202
198
  let managed = "<!-- phren:projects:start -->\n<!-- Auto-generated by phren link. Do not edit below this line. -->\n\n## Active Projects\n\n| Project | What | Memory |\n|---------|------|--------|\n";
203
199
  for (const project of projects) {
204
200
  if (project === "global")
@@ -213,8 +209,24 @@ export function rebuildMemory(phrenPath, projects) {
213
209
  }
214
210
  managed += "\n<!-- phren:projects:end -->";
215
211
  const freshHeader = "# Root Memory\n\n## Machine Context\nRead `~/.phren-context.md` for profile, active projects, last sync date.\n\n## Cross-Project Notes\n- Read a project's AGENTS.md before making changes.\n- Per-project memory files (MEMORY-{name}.md) have commands, versions, findings.\n\n";
216
- fs.writeFileSync(memoryFile, (header || freshHeader) + managed + "\n");
217
- log(` rebuilt ${memoryFile} (pointer format)`);
212
+ const start = existing.indexOf(projectsStart);
213
+ const end = existing.indexOf(projectsEnd);
214
+ let updated = existing;
215
+ if (start === -1 && end === -1) {
216
+ // A preset downgrade removes our block but leaves the owner's notes.
217
+ // An unmarked file is user content, not an empty generated header.
218
+ const header = existing || freshHeader;
219
+ const separator = header.endsWith("\n\n") ? "" : header.endsWith("\n") ? "\n" : "\n\n";
220
+ updated = header + separator + managed + "\n";
221
+ }
222
+ else if (start !== -1 && end > start) {
223
+ updated = existing.slice(0, start) + managed + existing.slice(end + projectsEnd.length);
224
+ }
225
+ // Incomplete or reversed markers cannot establish ownership: leave them alone.
226
+ if (updated !== existing) {
227
+ fs.writeFileSync(memoryFile, updated);
228
+ log(` rebuilt ${memoryFile} (pointer format)`);
229
+ }
218
230
  const SUMMARY_START = "<!-- phren:summary:start -->";
219
231
  const SUMMARY_END = "<!-- phren:summary:end -->";
220
232
  for (const project of projects) {
@@ -49,7 +49,7 @@ export function setupMessage() {
49
49
  "",
50
50
  "Setup runs `phren init --yes`, which:",
51
51
  "- creates the store at ~/.phren (a local git repo; nothing leaves the machine unless you add a remote)",
52
- "- registers phren's MCP server and memory hooks in ~/.claude/settings.json (the plugin's own copies then stand down)",
52
+ "- wires Claude Code's memory hooks and MCP server (the plugin yields wherever init's wiring loads)",
53
53
  "- wires any other agents it detects (Codex, Copilot CLI, Cursor, VS Code)",
54
54
  "",
55
55
  "Ask the user before running it. Afterwards, Claude Code needs a restart to load the memory tools.",