@phren/cli 0.1.39 → 0.1.40
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/cli/session-background.js +4 -0
- package/dist/cli/session-stop.js +16 -0
- package/dist/cli-handlers.d.ts +2 -0
- package/dist/cli-handlers.js +40 -0
- package/dist/cli-registry.js +15 -1
- package/dist/hooks.d.ts +6 -0
- package/dist/hooks.js +6 -3
- package/dist/init/init-configure.d.ts +7 -2
- package/dist/init/init-configure.js +36 -10
- package/dist/init/init-preset.d.ts +3 -0
- package/dist/init/init-preset.js +122 -0
- package/dist/init/init-uninstall.js +9 -0
- package/dist/init/init-walkthrough.d.ts +2 -0
- package/dist/init/init-walkthrough.js +42 -17
- package/dist/init/init.d.ts +5 -0
- package/dist/init/init.js +62 -14
- package/dist/init/management-preset.d.ts +42 -0
- package/dist/init/management-preset.js +122 -0
- package/dist/init/preferences.d.ts +17 -0
- package/dist/init/preferences.js +3 -0
- package/dist/init/self-wiring.d.ts +5 -0
- package/dist/init/self-wiring.js +52 -0
- package/dist/init/setup.d.ts +5 -1
- package/dist/init/setup.js +19 -7
- package/dist/init/teardown.d.ts +15 -0
- package/dist/init/teardown.js +241 -0
- package/dist/link/doctor.js +41 -14
- package/dist/link/link.js +49 -26
- package/dist/status.js +13 -1
- package/package.json +1 -1
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Teardown helpers: remove phren-owned symlinks, wrappers, and repo mirrors.
|
|
3
|
+
*
|
|
4
|
+
* Shared by `phren uninstall` and `phren preset` downgrades. Everything here
|
|
5
|
+
* only ever removes artifacts phren itself created — symlinks that resolve into
|
|
6
|
+
* the store, wrappers carrying the phren marker, and `.git/info/exclude` lines
|
|
7
|
+
* under the phren-managed marker. User-owned files are never touched.
|
|
8
|
+
*/
|
|
9
|
+
import * as fs from "fs";
|
|
10
|
+
import * as path from "path";
|
|
11
|
+
import { homeDir, homePath, getProjectDirs } from "../phren-paths.js";
|
|
12
|
+
import { debugLog } from "../shared.js";
|
|
13
|
+
import { errorMessage } from "../utils.js";
|
|
14
|
+
import { log } from "./shared.js";
|
|
15
|
+
import { FINDINGS_FILENAME } from "../data/access.js";
|
|
16
|
+
import { getProjectOwnershipMode, readProjectConfig } from "../project-config.js";
|
|
17
|
+
import { findProjectDir } from "../project-locator.js";
|
|
18
|
+
function agentSkillDirs() {
|
|
19
|
+
const home = homeDir();
|
|
20
|
+
return [
|
|
21
|
+
homePath(".claude", "skills"),
|
|
22
|
+
path.join(home, ".cursor", "skills"),
|
|
23
|
+
path.join(home, ".copilot", "skills"),
|
|
24
|
+
path.join(home, ".codex", "skills"),
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
/** Remove the phren-owned ~/.claude/CLAUDE.md and copilot-instructions.md symlinks. */
|
|
28
|
+
export function removePhrenHomeSymlinks() {
|
|
29
|
+
const removed = [];
|
|
30
|
+
for (const link of [homePath(".claude", "CLAUDE.md"), homePath(".github", "copilot-instructions.md")]) {
|
|
31
|
+
try {
|
|
32
|
+
if (fs.lstatSync(link).isSymbolicLink()) {
|
|
33
|
+
fs.unlinkSync(link);
|
|
34
|
+
log(` Removed symlink: ${link}`);
|
|
35
|
+
removed.push(link);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
// Missing or a regular file (user-owned) — leave it alone.
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return removed;
|
|
43
|
+
}
|
|
44
|
+
/** Remove ~/.local/bin/{copilot,cursor,codex,phren} wrappers that carry the phren marker. */
|
|
45
|
+
export function removePhrenWrappers() {
|
|
46
|
+
const removed = [];
|
|
47
|
+
const localBinDir = path.join(homeDir(), ".local", "bin");
|
|
48
|
+
for (const tool of ["copilot", "cursor", "codex", "phren"]) {
|
|
49
|
+
const wrapperPath = path.join(localBinDir, tool);
|
|
50
|
+
try {
|
|
51
|
+
if (fs.existsSync(wrapperPath)) {
|
|
52
|
+
const content = fs.readFileSync(wrapperPath, "utf8");
|
|
53
|
+
if (content.includes("PHREN_PATH") && content.includes("phren")) {
|
|
54
|
+
fs.unlinkSync(wrapperPath);
|
|
55
|
+
log(` Removed ${tool} wrapper (${wrapperPath})`);
|
|
56
|
+
removed.push(wrapperPath);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
debugLog(`removePhrenWrappers: cleanup failed for ${wrapperPath}: ${errorMessage(err)}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return removed;
|
|
65
|
+
}
|
|
66
|
+
/** Remove skill symlinks in agent skill dirs that resolve into the phren store, plus manifests. */
|
|
67
|
+
export function sweepAgentSkillSymlinks(phrenPath) {
|
|
68
|
+
const resolvedPhren = path.resolve(phrenPath);
|
|
69
|
+
for (const dir of agentSkillDirs()) {
|
|
70
|
+
if (!fs.existsSync(dir))
|
|
71
|
+
continue;
|
|
72
|
+
let entries;
|
|
73
|
+
try {
|
|
74
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
debugLog(`sweepAgentSkillSymlinks: readdirSync failed for ${dir}: ${errorMessage(err)}`);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
for (const entry of entries) {
|
|
81
|
+
if (!entry.isSymbolicLink())
|
|
82
|
+
continue;
|
|
83
|
+
const fullPath = path.join(dir, entry.name);
|
|
84
|
+
try {
|
|
85
|
+
const target = fs.realpathSync(fullPath);
|
|
86
|
+
if (target.startsWith(resolvedPhren + path.sep) || target === resolvedPhren) {
|
|
87
|
+
fs.unlinkSync(fullPath);
|
|
88
|
+
log(` Removed skill symlink: ${fullPath}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
// Broken symlink — only remove it if it clearly pointed into the store.
|
|
93
|
+
try {
|
|
94
|
+
const raw = fs.readlinkSync(fullPath);
|
|
95
|
+
const resolved = path.resolve(dir, raw);
|
|
96
|
+
if (resolved.startsWith(resolvedPhren + path.sep) || resolved === resolvedPhren) {
|
|
97
|
+
fs.unlinkSync(fullPath);
|
|
98
|
+
log(` Removed broken skill symlink: ${fullPath}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (err2) {
|
|
102
|
+
debugLog(`sweepAgentSkillSymlinks: could not inspect ${fullPath}: ${errorMessage(err2)}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const parentDir = path.dirname(dir);
|
|
107
|
+
for (const manifestFile of ["skill-manifest.json", "skill-commands.json"]) {
|
|
108
|
+
const manifestPath = path.join(parentDir, manifestFile);
|
|
109
|
+
try {
|
|
110
|
+
if (fs.existsSync(manifestPath)) {
|
|
111
|
+
fs.unlinkSync(manifestPath);
|
|
112
|
+
log(` Removed ${manifestFile} (${manifestPath})`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
debugLog(`sweepAgentSkillSymlinks: could not remove ${manifestPath}: ${errorMessage(err)}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** Remove the given exclude entries (and the phren-managed marker) from a repo's .git/info/exclude. */
|
|
122
|
+
export function removeGitExcludes(projectDir, entries) {
|
|
123
|
+
const excludePath = path.join(projectDir, ".git", "info", "exclude");
|
|
124
|
+
if (!fs.existsSync(excludePath))
|
|
125
|
+
return;
|
|
126
|
+
try {
|
|
127
|
+
const removeSet = new Set(entries);
|
|
128
|
+
const lines = fs.readFileSync(excludePath, "utf8").split("\n");
|
|
129
|
+
const kept = lines.filter((line) => {
|
|
130
|
+
const trimmed = line.trim();
|
|
131
|
+
if (trimmed === "# phren-managed")
|
|
132
|
+
return false;
|
|
133
|
+
return !removeSet.has(trimmed);
|
|
134
|
+
});
|
|
135
|
+
// Collapse any trailing blank lines we may have introduced.
|
|
136
|
+
while (kept.length > 1 && kept[kept.length - 1].trim() === "" && kept[kept.length - 2].trim() === "") {
|
|
137
|
+
kept.pop();
|
|
138
|
+
}
|
|
139
|
+
const next = kept.join("\n");
|
|
140
|
+
if (next !== lines.join("\n")) {
|
|
141
|
+
fs.writeFileSync(excludePath, next.endsWith("\n") || next === "" ? next : next + "\n");
|
|
142
|
+
log(` Cleaned phren entries from ${excludePath}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
debugLog(`removeGitExcludes: failed for ${projectDir}: ${errorMessage(err)}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Remove per-project repo mirror symlinks (CLAUDE.md, REFERENCE.md, findings,
|
|
151
|
+
* AGENTS.md, CLAUDE-*.md, .github/copilot-instructions.md, .claude/skills/*) that
|
|
152
|
+
* phren created in phren-managed repos, and strip the matching exclude lines.
|
|
153
|
+
* Only removes symlinks that resolve back into the phren store.
|
|
154
|
+
*/
|
|
155
|
+
export function sweepProjectMirrors(phrenPath) {
|
|
156
|
+
const resolvedPhren = path.resolve(phrenPath);
|
|
157
|
+
const resolvesIntoStore = (p) => {
|
|
158
|
+
try {
|
|
159
|
+
const target = fs.realpathSync(p);
|
|
160
|
+
return target.startsWith(resolvedPhren + path.sep) || target === resolvedPhren;
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
// Broken symlink — check its raw (unresolved) target.
|
|
164
|
+
try {
|
|
165
|
+
const raw = fs.readlinkSync(p);
|
|
166
|
+
const resolved = path.resolve(path.dirname(p), raw);
|
|
167
|
+
return resolved.startsWith(resolvedPhren + path.sep) || resolved === resolvedPhren;
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
for (const projectDir of getProjectDirs(phrenPath)) {
|
|
175
|
+
const project = path.basename(projectDir);
|
|
176
|
+
if (project === "global")
|
|
177
|
+
continue;
|
|
178
|
+
let ownership;
|
|
179
|
+
try {
|
|
180
|
+
const config = readProjectConfig(phrenPath, project);
|
|
181
|
+
ownership = getProjectOwnershipMode(phrenPath, project, config);
|
|
182
|
+
}
|
|
183
|
+
catch (err) {
|
|
184
|
+
debugLog(`sweepProjectMirrors: config read failed for ${project}: ${errorMessage(err)}`);
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (ownership !== "phren-managed")
|
|
188
|
+
continue;
|
|
189
|
+
const repo = findProjectDir(project);
|
|
190
|
+
if (!repo || !fs.existsSync(repo))
|
|
191
|
+
continue;
|
|
192
|
+
const removedEntries = [];
|
|
193
|
+
const removeMirror = (relPath) => {
|
|
194
|
+
const full = path.join(repo, relPath);
|
|
195
|
+
let stat;
|
|
196
|
+
try {
|
|
197
|
+
stat = fs.lstatSync(full);
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (!stat.isSymbolicLink())
|
|
203
|
+
return;
|
|
204
|
+
if (!resolvesIntoStore(full))
|
|
205
|
+
return;
|
|
206
|
+
try {
|
|
207
|
+
fs.unlinkSync(full);
|
|
208
|
+
log(` Removed repo mirror: ${full}`);
|
|
209
|
+
removedEntries.push(relPath);
|
|
210
|
+
}
|
|
211
|
+
catch (err) {
|
|
212
|
+
debugLog(`sweepProjectMirrors: could not remove ${full}: ${errorMessage(err)}`);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
// Fixed mirror files.
|
|
216
|
+
for (const f of ["CLAUDE.md", "REFERENCE.md", FINDINGS_FILENAME, "AGENTS.md", path.join(".github", "copilot-instructions.md")]) {
|
|
217
|
+
removeMirror(f);
|
|
218
|
+
}
|
|
219
|
+
// CLAUDE-*.md split files.
|
|
220
|
+
try {
|
|
221
|
+
for (const f of fs.readdirSync(repo)) {
|
|
222
|
+
if (/^CLAUDE-.+\.md$/.test(f))
|
|
223
|
+
removeMirror(f);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
catch { /* repo unreadable — skip */ }
|
|
227
|
+
// Project skill symlinks under .claude/skills.
|
|
228
|
+
const skillsDir = path.join(repo, ".claude", "skills");
|
|
229
|
+
if (fs.existsSync(skillsDir)) {
|
|
230
|
+
try {
|
|
231
|
+
for (const entry of fs.readdirSync(skillsDir, { withFileTypes: true })) {
|
|
232
|
+
if (entry.isSymbolicLink())
|
|
233
|
+
removeMirror(path.join(".claude", "skills", entry.name));
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
catch { /* skills dir unreadable — skip */ }
|
|
237
|
+
}
|
|
238
|
+
if (removedEntries.length > 0)
|
|
239
|
+
removeGitExcludes(repo, removedEntries);
|
|
240
|
+
}
|
|
241
|
+
}
|
package/dist/link/doctor.js
CHANGED
|
@@ -18,6 +18,7 @@ import { inspectTaskHygiene } from "../task/hygiene.js";
|
|
|
18
18
|
import { resolveTaskFilePath, TASK_FILE_ALIASES } from "../data/tasks.js";
|
|
19
19
|
import { FINDINGS_FILENAME } from "../data/access.js";
|
|
20
20
|
import { repairPreexistingInstall } from "../init/setup.js";
|
|
21
|
+
import { getManagementPreset, resolveManagementCapabilities } from "../init/management-preset.js";
|
|
21
22
|
import { getMachineName, lookupProfile, findProfileFile, getProfileProjects, findProjectDir, } from "./link.js";
|
|
22
23
|
import { claudeProjectKey } from "./context.js";
|
|
23
24
|
import { getProjectOwnershipMode, readProjectConfig } from "../project-config.js";
|
|
@@ -188,6 +189,8 @@ export async function runDoctor(phrenPath, fix = false, checkData = false) {
|
|
|
188
189
|
detail: nodeVersion || "node not found in PATH",
|
|
189
190
|
});
|
|
190
191
|
const prefs = readInstallPreferences(phrenPath);
|
|
192
|
+
const managementPreset = getManagementPreset(phrenPath);
|
|
193
|
+
const caps = resolveManagementCapabilities(phrenPath);
|
|
191
194
|
const gitRemote = gitRemoteStatus(phrenPath, prefs.syncIntent);
|
|
192
195
|
checks.push({
|
|
193
196
|
name: "git-remote",
|
|
@@ -290,28 +293,52 @@ export async function runDoctor(phrenPath, fix = false, checkData = false) {
|
|
|
290
293
|
ok: fs.existsSync(memoryFile),
|
|
291
294
|
detail: fs.existsSync(memoryFile) ? memoryFile : "missing generated MEMORY.md",
|
|
292
295
|
});
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
296
|
+
// Under presets that don't symlink into ~/.claude, the "missing" links are
|
|
297
|
+
// expected — report them as ok with a preset note instead of failures.
|
|
298
|
+
if (caps.linkGlobalClaudeMd) {
|
|
299
|
+
const globalClaudeSrc = path.join(phrenPath, "global", "CLAUDE.md");
|
|
300
|
+
const globalClaudeDest = homePath(".claude", "CLAUDE.md");
|
|
301
|
+
let globalLinkOk = false;
|
|
302
|
+
try {
|
|
303
|
+
globalLinkOk = fs.existsSync(globalClaudeDest) && fs.realpathSync(globalClaudeDest) === fs.realpathSync(globalClaudeSrc);
|
|
304
|
+
}
|
|
305
|
+
catch (err) {
|
|
306
|
+
debugLog(`doctor: global CLAUDE.md symlink check failed: ${errorMessage(err)}`);
|
|
307
|
+
globalLinkOk = false;
|
|
308
|
+
}
|
|
309
|
+
checks.push({
|
|
310
|
+
name: "global-link",
|
|
311
|
+
ok: globalLinkOk,
|
|
312
|
+
detail: globalLinkOk ? "global CLAUDE.md symlink ok" : "global CLAUDE.md link drifted/missing",
|
|
313
|
+
});
|
|
298
314
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
315
|
+
else {
|
|
316
|
+
checks.push({
|
|
317
|
+
name: "global-link",
|
|
318
|
+
ok: true,
|
|
319
|
+
detail: `not managed under ${managementPreset} preset (phren does not write ~/.claude/CLAUDE.md)`,
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
if (caps.installSkillLinks) {
|
|
323
|
+
pushSkillMirrorChecks(checks, "global", buildSkillManifest(phrenPath, profile || "", "global", homePath(".claude", "skills")), homePath(".claude", "skills"));
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
checks.push({ name: "skills-mirror:global", ok: true, detail: `skills not mirrored under ${managementPreset} preset` });
|
|
302
327
|
}
|
|
303
|
-
checks.push({
|
|
304
|
-
name: "global-link",
|
|
305
|
-
ok: globalLinkOk,
|
|
306
|
-
detail: globalLinkOk ? "global CLAUDE.md symlink ok" : "global CLAUDE.md link drifted/missing",
|
|
307
|
-
});
|
|
308
|
-
pushSkillMirrorChecks(checks, "global", buildSkillManifest(phrenPath, profile || "", "global", homePath(".claude", "skills")), homePath(".claude", "skills"));
|
|
309
328
|
for (const project of projects) {
|
|
310
329
|
if (project === "global")
|
|
311
330
|
continue;
|
|
312
331
|
const config = readProjectConfig(phrenPath, project);
|
|
313
332
|
const ownership = getProjectOwnershipMode(phrenPath, project, config);
|
|
314
333
|
const target = findProjectDir(project);
|
|
334
|
+
if (!caps.repoMirroring) {
|
|
335
|
+
checks.push({
|
|
336
|
+
name: `ownership:${project}`,
|
|
337
|
+
ok: true,
|
|
338
|
+
detail: `repo mirrors disabled (${managementPreset} preset)`,
|
|
339
|
+
});
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
315
342
|
if (ownership !== "phren-managed") {
|
|
316
343
|
checks.push({
|
|
317
344
|
name: `ownership:${project}`,
|
package/dist/link/link.js
CHANGED
|
@@ -15,6 +15,7 @@ import { STORES_FILENAME } from "../store-registry.js";
|
|
|
15
15
|
import { log } from "../init/shared.js";
|
|
16
16
|
import { listMachines as listMachinesShared, listProfiles as listProfilesShared, setMachineProfile, } from "../profile-store.js";
|
|
17
17
|
import { writeSkillMd, isManagedSymlink } from "./skills.js";
|
|
18
|
+
import { resolveManagementCapabilities } from "../init/management-preset.js";
|
|
18
19
|
import { syncScopeSkillsToDir } from "../skill/files.js";
|
|
19
20
|
import { renderSkillInstructionsSection } from "../skill/registry.js";
|
|
20
21
|
import { findProjectDir } from "../project-locator.js";
|
|
@@ -271,39 +272,60 @@ function writeManagedAgentsFile(src, dest, content, managedRoot) {
|
|
|
271
272
|
return true;
|
|
272
273
|
}
|
|
273
274
|
// ── Linking operations ──────────────────────────────────────────────────────
|
|
274
|
-
function linkGlobal(phrenPath, tools) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
const copilotSkillsDir = homePath(".copilot", "skills");
|
|
280
|
-
log(" global skills -> ~/.copilot/skills/");
|
|
281
|
-
try {
|
|
282
|
-
syncScopeSkillsToDir(phrenPath, "global", copilotSkillsDir);
|
|
283
|
-
}
|
|
284
|
-
catch (err) {
|
|
285
|
-
logger.debug("link", `linkGlobal copilotSkills: ${errorMessage(err)}`);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
const globalClaude = path.join(phrenPath, "global", "CLAUDE.md");
|
|
289
|
-
if (fs.existsSync(globalClaude)) {
|
|
290
|
-
symlinkFile(globalClaude, homePath(".claude", "CLAUDE.md"), phrenPath);
|
|
275
|
+
function linkGlobal(phrenPath, tools, caps) {
|
|
276
|
+
if (caps.installSkillLinks) {
|
|
277
|
+
log(" global skills -> ~/.claude/skills/");
|
|
278
|
+
const skillsDir = homePath(".claude", "skills");
|
|
279
|
+
syncScopeSkillsToDir(phrenPath, "global", skillsDir);
|
|
291
280
|
if (tools.has("copilot")) {
|
|
281
|
+
const copilotSkillsDir = homePath(".copilot", "skills");
|
|
282
|
+
log(" global skills -> ~/.copilot/skills/");
|
|
292
283
|
try {
|
|
293
|
-
|
|
294
|
-
fs.mkdirSync(copilotInstrDir, { recursive: true });
|
|
295
|
-
symlinkFile(globalClaude, path.join(copilotInstrDir, "copilot-instructions.md"), phrenPath);
|
|
284
|
+
syncScopeSkillsToDir(phrenPath, "global", copilotSkillsDir);
|
|
296
285
|
}
|
|
297
286
|
catch (err) {
|
|
298
|
-
logger.debug("link", `linkGlobal
|
|
287
|
+
logger.debug("link", `linkGlobal copilotSkills: ${errorMessage(err)}`);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (caps.linkGlobalClaudeMd) {
|
|
292
|
+
const globalClaude = path.join(phrenPath, "global", "CLAUDE.md");
|
|
293
|
+
if (fs.existsSync(globalClaude)) {
|
|
294
|
+
symlinkFile(globalClaude, homePath(".claude", "CLAUDE.md"), phrenPath);
|
|
295
|
+
if (tools.has("copilot")) {
|
|
296
|
+
try {
|
|
297
|
+
const copilotInstrDir = homePath(".github");
|
|
298
|
+
fs.mkdirSync(copilotInstrDir, { recursive: true });
|
|
299
|
+
symlinkFile(globalClaude, path.join(copilotInstrDir, "copilot-instructions.md"), phrenPath);
|
|
300
|
+
}
|
|
301
|
+
catch (err) {
|
|
302
|
+
logger.debug("link", `linkGlobal copilotInstructions: ${errorMessage(err)}`);
|
|
303
|
+
}
|
|
299
304
|
}
|
|
300
305
|
}
|
|
301
306
|
}
|
|
307
|
+
if (!caps.installSkillLinks && !caps.linkGlobalClaudeMd) {
|
|
308
|
+
log(" global symlinks skipped (management preset does not write into ~/.claude)");
|
|
309
|
+
}
|
|
302
310
|
}
|
|
303
|
-
function linkProject(phrenPath, project, tools) {
|
|
311
|
+
function linkProject(phrenPath, project, tools, caps) {
|
|
304
312
|
const config = readProjectConfig(phrenPath, project);
|
|
305
313
|
const ownership = getProjectOwnershipMode(phrenPath, project, config);
|
|
306
314
|
const target = findProjectDir(project);
|
|
315
|
+
// Presets that opt out of repo mirroring still register per-project MCP
|
|
316
|
+
// servers, but never write into the repo itself.
|
|
317
|
+
if (!caps.repoMirroring) {
|
|
318
|
+
if (target) {
|
|
319
|
+
log(` ${project} -> ${target} (repo mirrors disabled by preset)`);
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
log(` ${project} (repo mirrors disabled by preset)`);
|
|
323
|
+
}
|
|
324
|
+
if (isRecord(config.mcpServers)) {
|
|
325
|
+
linkProjectMcpServers(project, config.mcpServers);
|
|
326
|
+
}
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
307
329
|
if (!target && ownership === "phren-managed") {
|
|
308
330
|
log(` skip ${project} (not found on disk)`);
|
|
309
331
|
if (isRecord(config.mcpServers)) {
|
|
@@ -496,12 +518,13 @@ export async function runLink(phrenPath, opts = {}) {
|
|
|
496
518
|
const detectedTools = opts.allTools
|
|
497
519
|
? new Set(["copilot", "cursor", "codex"])
|
|
498
520
|
: detectInstalledTools();
|
|
521
|
+
const caps = resolveManagementCapabilities(phrenPath);
|
|
499
522
|
// Step 5: Symlink
|
|
500
523
|
log("Linking...");
|
|
501
|
-
linkGlobal(phrenPath, detectedTools);
|
|
524
|
+
linkGlobal(phrenPath, detectedTools, caps);
|
|
502
525
|
for (const p of projects) {
|
|
503
526
|
if (p !== "global")
|
|
504
|
-
linkProject(phrenPath, p, detectedTools);
|
|
527
|
+
linkProject(phrenPath, p, detectedTools, caps);
|
|
505
528
|
}
|
|
506
529
|
// Remove stale phren__<project>__* MCP entries for removed projects
|
|
507
530
|
pruneStaleProjectMcpServers(projects.filter(p => p !== "global"));
|
|
@@ -514,10 +537,10 @@ export async function runLink(phrenPath, opts = {}) {
|
|
|
514
537
|
log(` MCP mode: ${mcpEnabled ? "ON (recommended)" : "OFF (hooks-only fallback)"}`);
|
|
515
538
|
log(` Hooks mode: ${hooksEnabled ? "ON (active)" : "OFF (disabled)"}`);
|
|
516
539
|
maybeOfferStarterTemplateUpdate(phrenPath);
|
|
517
|
-
const mcpStatusForContext = configureMcpTargets(phrenPath, { mcpEnabled, hooksEnabled });
|
|
540
|
+
const mcpStatusForContext = configureMcpTargets(phrenPath, { mcpEnabled, hooksEnabled, caps });
|
|
518
541
|
// Register hooks for Copilot CLI, Cursor, Codex
|
|
519
542
|
if (hooksEnabled) {
|
|
520
|
-
const hookedTools = configureAllHooks(phrenPath, { tools: detectedTools });
|
|
543
|
+
const hookedTools = configureAllHooks(phrenPath, { tools: detectedTools, installWrappers: caps.installWrappers });
|
|
521
544
|
if (hookedTools.length)
|
|
522
545
|
log(` Hooks registered: ${hookedTools.join(", ")}`);
|
|
523
546
|
}
|
package/dist/status.js
CHANGED
|
@@ -5,6 +5,7 @@ import { findPhrenPath, getProjectDirs, EXEC_TIMEOUT_QUICK_MS, debugLog, isRecor
|
|
|
5
5
|
import { buildIndex, detectProject, findFtsCacheForPath, listIndexedDocumentPaths, queryRows } from "./shared/index.js";
|
|
6
6
|
import { mergeConfig, getWorkflowPolicy } from "./shared/governance.js";
|
|
7
7
|
import { getMcpEnabledPreference, getHooksEnabledPreference } from "./init/init.js";
|
|
8
|
+
import { getManagementPreset, resolveManagementCapabilities } from "./init/management-preset.js";
|
|
8
9
|
import { getTelemetrySummary } from "./telemetry.js";
|
|
9
10
|
import { runGit as runGitShared, errorMessage } from "./utils.js";
|
|
10
11
|
import { logger } from "./logger.js";
|
|
@@ -107,11 +108,22 @@ export async function runStatus() {
|
|
|
107
108
|
if (profile) {
|
|
108
109
|
console.log(` ${DIM}profile${RESET} ${profile}`);
|
|
109
110
|
}
|
|
110
|
-
// MCP + hooks status
|
|
111
|
+
// Management preset + MCP + hooks status
|
|
112
|
+
const preset = getManagementPreset(phrenPath);
|
|
113
|
+
const caps = resolveManagementCapabilities(phrenPath);
|
|
111
114
|
const mcpEnabled = getMcpEnabledPreference(phrenPath);
|
|
112
115
|
const hooksEnabled = getHooksEnabledPreference(phrenPath);
|
|
116
|
+
console.log(` ${DIM}preset${RESET} ${preset}`);
|
|
113
117
|
console.log(` ${DIM}mcp${RESET} ${mcpEnabled ? `${GREEN}on${RESET}` : `${YELLOW}off${RESET}`}`);
|
|
114
118
|
console.log(` ${DIM}hooks${RESET} ${hooksEnabled ? `${GREEN}on${RESET}` : `${YELLOW}off${RESET}`}`);
|
|
119
|
+
// What phren touches on this machine under the current preset.
|
|
120
|
+
const touches = [
|
|
121
|
+
caps.linkGlobalClaudeMd ? "~/.claude/CLAUDE.md" : null,
|
|
122
|
+
caps.installSkillLinks ? "~/.claude/skills" : null,
|
|
123
|
+
caps.installWrappers ? "~/.local/bin wrappers" : null,
|
|
124
|
+
caps.repoMirroring ? "repo mirrors" : null,
|
|
125
|
+
].filter(Boolean);
|
|
126
|
+
console.log(` ${DIM}touches${RESET} ${touches.length ? touches.join(", ") : `${DIM}store only${RESET}`}`);
|
|
115
127
|
// Hook health: check ~/.claude/settings.json
|
|
116
128
|
let hooksInstalled = false;
|
|
117
129
|
let mcpConfigured = false;
|