@phren/cli 0.1.20 → 0.1.21
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/generated/memory-ui-graph.browser.js +2 -2
- package/dist/hooks.d.ts +15 -4
- package/dist/hooks.js +61 -31
- package/dist/link/doctor.js +19 -1
- package/dist/memory-ui-graph.runtime.js +2 -2
- package/dist/phren-paths.d.ts +1 -0
- package/dist/phren-paths.js +23 -2
- package/dist/project-migrate.d.ts +25 -0
- package/dist/project-migrate.js +126 -0
- package/dist/shared.d.ts +1 -1
- package/dist/shared.js +1 -1
- package/package.json +1 -1
package/dist/hooks.d.ts
CHANGED
|
@@ -23,10 +23,21 @@ export interface BuildLifecycleOptions {
|
|
|
23
23
|
export declare function buildLifecycleCommands(phrenPath: string, options?: BuildLifecycleOptions): LifecycleCommands;
|
|
24
24
|
export declare function buildSharedLifecycleCommands(): LifecycleCommands;
|
|
25
25
|
/**
|
|
26
|
-
* Windows-only: append
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
26
|
+
* Windows-only: append `~/.local/bin` to the user's persistent PATH if it
|
|
27
|
+
* isn't already there. On Linux/macOS `~/.local/bin` is on PATH by default
|
|
28
|
+
* (XDG / `.profile`); on Windows nothing adds it, so the `phren.cmd` wrapper
|
|
29
|
+
* is invisible to cmd/PowerShell/Git Bash until we fix PATH.
|
|
30
|
+
*
|
|
31
|
+
* Reads/writes the User PATH directly from the registry under
|
|
32
|
+
* `HKCU\Environment` so we (a) keep the original value kind — `REG_EXPAND_SZ`
|
|
33
|
+
* vs `REG_SZ` — intact, and (b) preserve any `%VAR%` references the user has
|
|
34
|
+
* in their PATH. Going through `[Environment]::GetEnvironmentVariable` /
|
|
35
|
+
* `SetEnvironmentVariable` would silently expand `%VAR%` on read and write
|
|
36
|
+
* the result back as `REG_SZ`, baking expansions in permanently and
|
|
37
|
+
* downgrading the registry type — corrupting unrelated PATH entries.
|
|
38
|
+
*
|
|
39
|
+
* After writing, broadcasts `WM_SETTINGCHANGE` so newly-launched processes
|
|
40
|
+
* pick up the change without waiting for a logoff.
|
|
30
41
|
*
|
|
31
42
|
* Returns:
|
|
32
43
|
* "added" — PATH was updated (user must open a new terminal).
|
package/dist/hooks.js
CHANGED
|
@@ -286,10 +286,21 @@ exit $status
|
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
288
|
/**
|
|
289
|
-
* Windows-only: append
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
289
|
+
* Windows-only: append `~/.local/bin` to the user's persistent PATH if it
|
|
290
|
+
* isn't already there. On Linux/macOS `~/.local/bin` is on PATH by default
|
|
291
|
+
* (XDG / `.profile`); on Windows nothing adds it, so the `phren.cmd` wrapper
|
|
292
|
+
* is invisible to cmd/PowerShell/Git Bash until we fix PATH.
|
|
293
|
+
*
|
|
294
|
+
* Reads/writes the User PATH directly from the registry under
|
|
295
|
+
* `HKCU\Environment` so we (a) keep the original value kind — `REG_EXPAND_SZ`
|
|
296
|
+
* vs `REG_SZ` — intact, and (b) preserve any `%VAR%` references the user has
|
|
297
|
+
* in their PATH. Going through `[Environment]::GetEnvironmentVariable` /
|
|
298
|
+
* `SetEnvironmentVariable` would silently expand `%VAR%` on read and write
|
|
299
|
+
* the result back as `REG_SZ`, baking expansions in permanently and
|
|
300
|
+
* downgrading the registry type — corrupting unrelated PATH entries.
|
|
301
|
+
*
|
|
302
|
+
* After writing, broadcasts `WM_SETTINGCHANGE` so newly-launched processes
|
|
303
|
+
* pick up the change without waiting for a logoff.
|
|
293
304
|
*
|
|
294
305
|
* Returns:
|
|
295
306
|
* "added" — PATH was updated (user must open a new terminal).
|
|
@@ -301,42 +312,61 @@ export function ensureLocalBinOnWindowsPath() {
|
|
|
301
312
|
if (process.platform !== "win32")
|
|
302
313
|
return "skipped";
|
|
303
314
|
const target = homePath(".local", "bin");
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
315
|
+
const escapedTarget = target.replace(/'/g, "''");
|
|
316
|
+
const script = `
|
|
317
|
+
$ErrorActionPreference = 'Stop'
|
|
318
|
+
try {
|
|
319
|
+
$key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('Environment', $true)
|
|
320
|
+
if ($null -eq $key) { Write-Output 'FAILED'; exit 1 }
|
|
321
|
+
if (@($key.GetValueNames()) -contains 'Path') {
|
|
322
|
+
$rawPath = $key.GetValue('Path', '', [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames)
|
|
323
|
+
$kind = $key.GetValueKind('Path')
|
|
324
|
+
} else {
|
|
325
|
+
$rawPath = ''
|
|
326
|
+
$kind = [Microsoft.Win32.RegistryValueKind]::ExpandString
|
|
327
|
+
}
|
|
328
|
+
$target = '${escapedTarget}'
|
|
329
|
+
$targetNorm = ([Environment]::ExpandEnvironmentVariables($target)).TrimEnd('\\').ToLowerInvariant()
|
|
330
|
+
$present = $false
|
|
331
|
+
if ($rawPath) {
|
|
332
|
+
foreach ($entry in ($rawPath -split ';')) {
|
|
333
|
+
if (-not $entry) { continue }
|
|
334
|
+
$expanded = ([Environment]::ExpandEnvironmentVariables($entry)).TrimEnd('\\').ToLowerInvariant()
|
|
335
|
+
if ($expanded -eq $targetNorm) { $present = $true; break }
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
if ($present) { $key.Close(); Write-Output 'ALREADY'; exit 0 }
|
|
339
|
+
$newRaw = if ($rawPath) { $rawPath.TrimEnd(';') + ';' + $target } else { $target }
|
|
340
|
+
$key.SetValue('Path', $newRaw, $kind)
|
|
341
|
+
$key.Close()
|
|
342
|
+
Add-Type -Namespace PhrenInit -Name PathBroadcast -MemberDefinition '[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError=true, CharSet=System.Runtime.InteropServices.CharSet.Auto)] public static extern System.IntPtr SendMessageTimeout(System.IntPtr hWnd, uint Msg, System.UIntPtr wParam, string lParam, uint fuFlags, uint uTimeout, out System.UIntPtr lpdwResult);' | Out-Null
|
|
343
|
+
$r = [System.UIntPtr]::Zero
|
|
344
|
+
[void][PhrenInit.PathBroadcast]::SendMessageTimeout([System.IntPtr]0xFFFF, 0x1A, [System.UIntPtr]::Zero, 'Environment', 2, 5000, [ref]$r)
|
|
345
|
+
Write-Output 'ADDED'
|
|
346
|
+
} catch {
|
|
347
|
+
Write-Output ('FAILED: ' + $_.Exception.Message)
|
|
348
|
+
exit 1
|
|
349
|
+
}
|
|
350
|
+
`;
|
|
351
|
+
let out = "";
|
|
311
352
|
try {
|
|
312
|
-
|
|
353
|
+
out = execFileSync("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", script], {
|
|
313
354
|
encoding: "utf8",
|
|
314
|
-
stdio: ["ignore", "pipe", "
|
|
355
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
315
356
|
timeout: EXEC_TIMEOUT_QUICK_MS,
|
|
316
357
|
}).trim();
|
|
317
358
|
}
|
|
318
359
|
catch (err) {
|
|
319
|
-
debugLog(`ensureLocalBinOnWindowsPath:
|
|
360
|
+
debugLog(`ensureLocalBinOnWindowsPath: ${errorMessage(err)}`);
|
|
320
361
|
return "failed";
|
|
321
362
|
}
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
if (alreadyPersisted)
|
|
325
|
-
return alreadyOnSessionPath ? "already" : "already";
|
|
326
|
-
const newUserPath = userEntries.length > 0 ? `${userPath};${target}` : target;
|
|
327
|
-
const escaped = newUserPath.replace(/'/g, "''");
|
|
328
|
-
const writeScript = `[Environment]::SetEnvironmentVariable('Path','${escaped}','User')`;
|
|
329
|
-
try {
|
|
330
|
-
execFileSync("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", writeScript], {
|
|
331
|
-
stdio: ["ignore", "ignore", "pipe"],
|
|
332
|
-
timeout: EXEC_TIMEOUT_QUICK_MS,
|
|
333
|
-
});
|
|
363
|
+
const lastLine = out.split(/\r?\n/).pop()?.trim() ?? "";
|
|
364
|
+
if (lastLine === "ADDED")
|
|
334
365
|
return "added";
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
}
|
|
366
|
+
if (lastLine === "ALREADY")
|
|
367
|
+
return "already";
|
|
368
|
+
debugLog(`ensureLocalBinOnWindowsPath: unexpected output: ${out}`);
|
|
369
|
+
return "failed";
|
|
340
370
|
}
|
|
341
371
|
/**
|
|
342
372
|
* Install a lightweight `phren` CLI wrapper at ~/.local/bin/phren so the bare
|
package/dist/link/doctor.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
2
|
import * as path from "path";
|
|
3
3
|
import { execFileSync } from "child_process";
|
|
4
|
-
import { debugLog, EXEC_TIMEOUT_QUICK_MS, getProjectDirs, isRecord, homeDir, homePath, hookConfigPath, runtimeHealthFile, } from "../shared.js";
|
|
4
|
+
import { debugLog, EXEC_TIMEOUT_QUICK_MS, getProjectDirs, isRecord, homeDir, homePath, hookConfigPath, listInvalidProjectDirs, runtimeHealthFile, } from "../shared.js";
|
|
5
|
+
import { migrateInvalidProjectNames, formatMigrationSummary } from "../project-migrate.js";
|
|
5
6
|
import { commandVersion, versionAtLeast, nearestWritableTarget } from "../init/shared.js";
|
|
6
7
|
import { validateGovernanceJson } from "../shared/governance.js";
|
|
7
8
|
import { errorMessage } from "../utils.js";
|
|
@@ -173,6 +174,14 @@ export async function runDoctor(phrenPath, fix = false, checkData = false) {
|
|
|
173
174
|
ok: projects.length > 0,
|
|
174
175
|
detail: projects.length ? `${projects.length} projects in profile` : "no projects listed",
|
|
175
176
|
});
|
|
177
|
+
const invalidProjectDirs = listInvalidProjectDirs(phrenPath);
|
|
178
|
+
checks.push({
|
|
179
|
+
name: "project-names-valid",
|
|
180
|
+
ok: invalidProjectDirs.length === 0,
|
|
181
|
+
detail: invalidProjectDirs.length === 0
|
|
182
|
+
? "all project directories use valid names"
|
|
183
|
+
: `${invalidProjectDirs.length} invalid project dir(s): ${invalidProjectDirs.join(", ")}. These are ignored by the UI and indexer. Run \`phren doctor --fix\` to rename to lowercase.`,
|
|
184
|
+
});
|
|
176
185
|
// Filesystem speed check
|
|
177
186
|
const fsBenchFile = path.join(phrenPath, ".fs-bench-tmp");
|
|
178
187
|
let fsMs = 0;
|
|
@@ -475,6 +484,15 @@ export async function runDoctor(phrenPath, fix = false, checkData = false) {
|
|
|
475
484
|
details.push("baseline repair complete");
|
|
476
485
|
checks.push({ name: "baseline-repair", ok: true, detail: details.join("; ") });
|
|
477
486
|
}
|
|
487
|
+
if (fix && invalidProjectDirs.length > 0) {
|
|
488
|
+
const migration = migrateInvalidProjectNames(phrenPath);
|
|
489
|
+
const unresolved = migration.outcomes.filter((o) => o.action !== "renamed");
|
|
490
|
+
checks.push({
|
|
491
|
+
name: "project-names-migrate",
|
|
492
|
+
ok: unresolved.length === 0,
|
|
493
|
+
detail: formatMigrationSummary(migration),
|
|
494
|
+
});
|
|
495
|
+
}
|
|
478
496
|
if (fix && profile && profileFile) {
|
|
479
497
|
await runLink(phrenPath, { machine, profile });
|
|
480
498
|
checks.push({ name: "self-heal", ok: true, detail: "relinked hooks, symlinks, context, memory pointers" });
|