@phren/cli 0.1.19 → 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/cli/session-stop.js +1 -1
- package/dist/cli-hooks-stop.js +2 -2
- 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/dist/tools/finding.js +2 -2
- package/package.json +1 -1
package/dist/phren-paths.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export declare function errorLog(tool: string, msg: string): void;
|
|
|
43
43
|
export declare function appendIndexEvent(phrenPath: string, event: Record<string, unknown>): void;
|
|
44
44
|
/** Resolve the canonical findings file for a project directory. */
|
|
45
45
|
export declare function resolveFindingsPath(projectDir: string): string | undefined;
|
|
46
|
+
export declare function listInvalidProjectDirs(phrenPath: string): string[];
|
|
46
47
|
export declare function normalizeProjectNameForCreate(name: string): string;
|
|
47
48
|
export declare function findProjectNameCaseInsensitive(phrenPath: string, name: string): string | null;
|
|
48
49
|
export declare function findArchivedProjectNameCaseInsensitive(phrenPath: string, name: string): string | null;
|
package/dist/phren-paths.js
CHANGED
|
@@ -322,6 +322,27 @@ function isProjectDirEntry(entry) {
|
|
|
322
322
|
&& !entry.name.endsWith(".archived")
|
|
323
323
|
&& !RESERVED_PROJECT_DIR_NAMES.has(entry.name);
|
|
324
324
|
}
|
|
325
|
+
// Like isProjectDirEntry, but also rejects names that would fail downstream
|
|
326
|
+
// validation (e.g. uppercase). These dirs exist on disk but can't be read by
|
|
327
|
+
// the UI or CLI read paths, so enumeration surfaces must skip them. Collision
|
|
328
|
+
// detection still uses isProjectDirEntry so we can *see* the stragglers.
|
|
329
|
+
function isIndexableProjectEntry(entry) {
|
|
330
|
+
return isProjectDirEntry(entry) && isValidProjectName(entry.name);
|
|
331
|
+
}
|
|
332
|
+
// Project directories whose names exist on disk but fail isValidProjectName.
|
|
333
|
+
// Used by `phren doctor` to surface silent half-working state.
|
|
334
|
+
export function listInvalidProjectDirs(phrenPath) {
|
|
335
|
+
try {
|
|
336
|
+
return fs.readdirSync(phrenPath, { withFileTypes: true })
|
|
337
|
+
.filter((entry) => isProjectDirEntry(entry) && !isValidProjectName(entry.name))
|
|
338
|
+
.map((entry) => entry.name);
|
|
339
|
+
}
|
|
340
|
+
catch (err) {
|
|
341
|
+
if ((process.env.PHREN_DEBUG))
|
|
342
|
+
stderrLog(`listInvalidProjectDirs: ${errorMessage(err)}`);
|
|
343
|
+
return [];
|
|
344
|
+
}
|
|
345
|
+
}
|
|
325
346
|
export function normalizeProjectNameForCreate(name) {
|
|
326
347
|
return name.trim().toLowerCase();
|
|
327
348
|
}
|
|
@@ -365,7 +386,7 @@ function getLocalProjectDirs(phrenPath, manifest) {
|
|
|
365
386
|
const projectPath = safeProjectPath(phrenPath, primaryProject);
|
|
366
387
|
if (!projectPath || !fs.existsSync(projectPath) || !fs.statSync(projectPath).isDirectory())
|
|
367
388
|
return [];
|
|
368
|
-
const visible = fs.readdirSync(phrenPath, { withFileTypes: true }).filter(
|
|
389
|
+
const visible = fs.readdirSync(phrenPath, { withFileTypes: true }).filter(isIndexableProjectEntry).map((entry) => entry.name);
|
|
369
390
|
if (visible.length !== 1 || visible[0] !== primaryProject)
|
|
370
391
|
return [];
|
|
371
392
|
return [projectPath];
|
|
@@ -417,7 +438,7 @@ export function getProjectDirs(phrenPath, profile) {
|
|
|
417
438
|
}
|
|
418
439
|
try {
|
|
419
440
|
return fs.readdirSync(phrenPath, { withFileTypes: true })
|
|
420
|
-
.filter(
|
|
441
|
+
.filter(isIndexableProjectEntry)
|
|
421
442
|
.map((entry) => path.join(phrenPath, entry.name));
|
|
422
443
|
}
|
|
423
444
|
catch (err) {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type MigrationOutcome = {
|
|
2
|
+
from: string;
|
|
3
|
+
to: string;
|
|
4
|
+
action: "renamed";
|
|
5
|
+
} | {
|
|
6
|
+
from: string;
|
|
7
|
+
to: string;
|
|
8
|
+
action: "skipped-collision";
|
|
9
|
+
reason: string;
|
|
10
|
+
} | {
|
|
11
|
+
from: string;
|
|
12
|
+
to: string;
|
|
13
|
+
action: "skipped-invalid-slug";
|
|
14
|
+
reason: string;
|
|
15
|
+
} | {
|
|
16
|
+
from: string;
|
|
17
|
+
to: string;
|
|
18
|
+
action: "error";
|
|
19
|
+
reason: string;
|
|
20
|
+
};
|
|
21
|
+
export interface MigrationResult {
|
|
22
|
+
outcomes: MigrationOutcome[];
|
|
23
|
+
}
|
|
24
|
+
export declare function migrateInvalidProjectNames(phrenPath: string): MigrationResult;
|
|
25
|
+
export declare function formatMigrationSummary(result: MigrationResult): string;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import { listInvalidProjectDirs, normalizeProjectNameForCreate } from "./phren-paths.js";
|
|
4
|
+
import { isValidProjectName, errorMessage } from "./utils.js";
|
|
5
|
+
import { listProfiles, addProjectToProfile, removeProjectFromProfile, } from "./profile-store.js";
|
|
6
|
+
import { logger } from "./logger.js";
|
|
7
|
+
// Rename on-disk project directories whose names fail `isValidProjectName`
|
|
8
|
+
// (typically uppercase) to their lowercase form, and update any profile YAML
|
|
9
|
+
// references. Skips entries where the target name would collide with an
|
|
10
|
+
// existing directory or where lowercasing alone doesn't yield a valid name.
|
|
11
|
+
export function migrateInvalidProjectNames(phrenPath) {
|
|
12
|
+
const invalid = listInvalidProjectDirs(phrenPath);
|
|
13
|
+
const outcomes = [];
|
|
14
|
+
for (const from of invalid) {
|
|
15
|
+
const to = normalizeProjectNameForCreate(from);
|
|
16
|
+
if (!isValidProjectName(to)) {
|
|
17
|
+
outcomes.push({
|
|
18
|
+
from,
|
|
19
|
+
to,
|
|
20
|
+
action: "skipped-invalid-slug",
|
|
21
|
+
reason: `lowercasing does not yield a valid name (got "${to}"); rename manually`,
|
|
22
|
+
});
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (to === from) {
|
|
26
|
+
outcomes.push({
|
|
27
|
+
from,
|
|
28
|
+
to,
|
|
29
|
+
action: "skipped-invalid-slug",
|
|
30
|
+
reason: "already lowercase but still fails validation; rename manually",
|
|
31
|
+
});
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const oldDir = path.join(phrenPath, from);
|
|
35
|
+
const newDir = path.join(phrenPath, to);
|
|
36
|
+
// Case-insensitive filesystems (macOS APFS/HFS+, default Windows) resolve
|
|
37
|
+
// both paths to the same inode. Treat that as "rename casing in place"
|
|
38
|
+
// rather than a collision.
|
|
39
|
+
let sameInode = false;
|
|
40
|
+
try {
|
|
41
|
+
if (fs.existsSync(newDir)) {
|
|
42
|
+
const oldStat = fs.statSync(oldDir);
|
|
43
|
+
const newStat = fs.statSync(newDir);
|
|
44
|
+
sameInode = oldStat.ino === newStat.ino && oldStat.dev === newStat.dev;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
logger.debug("project-migrate", `stat compare ${from}->${to}: ${errorMessage(err)}`);
|
|
49
|
+
}
|
|
50
|
+
if (fs.existsSync(newDir) && !sameInode) {
|
|
51
|
+
outcomes.push({
|
|
52
|
+
from,
|
|
53
|
+
to,
|
|
54
|
+
action: "skipped-collision",
|
|
55
|
+
reason: `target "${to}" already exists as a separate directory; merge manually`,
|
|
56
|
+
});
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
if (sameInode) {
|
|
61
|
+
// Two-step rename forces the case change on case-insensitive filesystems
|
|
62
|
+
// without letting an observer see a missing directory.
|
|
63
|
+
const tmp = path.join(phrenPath, `${from}.phren-case-tmp-${process.pid}`);
|
|
64
|
+
fs.renameSync(oldDir, tmp);
|
|
65
|
+
fs.renameSync(tmp, newDir);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
fs.renameSync(oldDir, newDir);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
outcomes.push({
|
|
73
|
+
from,
|
|
74
|
+
to,
|
|
75
|
+
action: "error",
|
|
76
|
+
reason: `rename failed: ${errorMessage(err)}`,
|
|
77
|
+
});
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
updateProfileReferences(phrenPath, from, to);
|
|
81
|
+
outcomes.push({ from, to, action: "renamed" });
|
|
82
|
+
}
|
|
83
|
+
return { outcomes };
|
|
84
|
+
}
|
|
85
|
+
function updateProfileReferences(phrenPath, oldName, newName) {
|
|
86
|
+
const profiles = listProfiles(phrenPath);
|
|
87
|
+
if (!profiles.ok) {
|
|
88
|
+
logger.debug("project-migrate", `updateProfileReferences listProfiles: ${profiles.error}`);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
for (const profile of profiles.data) {
|
|
92
|
+
if (!profile.projects.includes(oldName))
|
|
93
|
+
continue;
|
|
94
|
+
const removed = removeProjectFromProfile(phrenPath, profile.name, oldName);
|
|
95
|
+
if (!removed.ok) {
|
|
96
|
+
logger.debug("project-migrate", `remove ${oldName} from ${profile.name}: ${removed.error}`);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const added = addProjectToProfile(phrenPath, profile.name, newName);
|
|
100
|
+
if (!added.ok) {
|
|
101
|
+
logger.debug("project-migrate", `add ${newName} to ${profile.name}: ${added.error}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export function formatMigrationSummary(result) {
|
|
106
|
+
if (result.outcomes.length === 0)
|
|
107
|
+
return "no invalid project directories found";
|
|
108
|
+
const parts = [];
|
|
109
|
+
const renamed = result.outcomes.filter((o) => o.action === "renamed");
|
|
110
|
+
const collisions = result.outcomes.filter((o) => o.action === "skipped-collision");
|
|
111
|
+
const invalidSlugs = result.outcomes.filter((o) => o.action === "skipped-invalid-slug");
|
|
112
|
+
const errors = result.outcomes.filter((o) => o.action === "error");
|
|
113
|
+
if (renamed.length > 0) {
|
|
114
|
+
parts.push(`renamed ${renamed.length}: ${renamed.map((o) => `${o.from}->${o.to}`).join(", ")}`);
|
|
115
|
+
}
|
|
116
|
+
if (collisions.length > 0) {
|
|
117
|
+
parts.push(`${collisions.length} collision(s): ${collisions.map((o) => o.from).join(", ")}`);
|
|
118
|
+
}
|
|
119
|
+
if (invalidSlugs.length > 0) {
|
|
120
|
+
parts.push(`${invalidSlugs.length} unfixable: ${invalidSlugs.map((o) => o.from).join(", ")}`);
|
|
121
|
+
}
|
|
122
|
+
if (errors.length > 0) {
|
|
123
|
+
parts.push(`${errors.length} error(s): ${errors.map((o) => `${o.from} (${o.reason})`).join(", ")}`);
|
|
124
|
+
}
|
|
125
|
+
return parts.join("; ");
|
|
126
|
+
}
|
package/dist/shared.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type { HookToolName } from "./provider-adapters.js";
|
|
2
2
|
export { HOOK_TOOL_NAMES, hookConfigPath } from "./provider-adapters.js";
|
|
3
3
|
export { EXEC_TIMEOUT_MS, EXEC_TIMEOUT_QUICK_MS, PhrenError, type PhrenErrorCode, type PhrenResult, phrenOk, phrenErr, forwardErr, parsePhrenErrorCode, isRecord, withDefaults, FINDING_TYPES, type FindingType, FINDING_TAGS, type FindingTag, KNOWN_OBSERVATION_TAGS, DOC_TYPES, type DocType, capCache, RESERVED_PROJECT_DIR_NAMES, } from "./phren-core.js";
|
|
4
|
-
export { ROOT_MANIFEST_FILENAME, type InstallMode, type SyncMode, type PhrenRootManifest, type InstallContext, homeDir, homePath, expandHomePath, defaultPhrenPath, rootManifestPath, readRootManifest, writeRootManifest, resolveInstallContext, findNearestPhrenPath, isProjectLocalMode, runtimeDir, tryUnlink, sessionsDir, runtimeFile, installPreferencesFile, runtimeHealthFile, shellStateFile, sessionMetricsFile, memoryScoresFile, memoryUsageLogFile, sessionMarker, debugLog, appendIndexEvent, resolveFindingsPath, findPhrenPath, ensurePhrenPath, findPhrenPathWithArg, normalizeProjectNameForCreate, findProjectNameCaseInsensitive, findArchivedProjectNameCaseInsensitive, getProjectDirs, collectNativeMemoryFiles, computePhrenLiveStateToken, getPhrenPath, qualityMarkers, atomicWriteText, } from "./phren-paths.js";
|
|
4
|
+
export { ROOT_MANIFEST_FILENAME, type InstallMode, type SyncMode, type PhrenRootManifest, type InstallContext, homeDir, homePath, expandHomePath, defaultPhrenPath, rootManifestPath, readRootManifest, writeRootManifest, resolveInstallContext, findNearestPhrenPath, isProjectLocalMode, runtimeDir, tryUnlink, sessionsDir, runtimeFile, installPreferencesFile, runtimeHealthFile, shellStateFile, sessionMetricsFile, memoryScoresFile, memoryUsageLogFile, sessionMarker, debugLog, appendIndexEvent, resolveFindingsPath, findPhrenPath, ensurePhrenPath, findPhrenPathWithArg, normalizeProjectNameForCreate, findProjectNameCaseInsensitive, findArchivedProjectNameCaseInsensitive, getProjectDirs, listInvalidProjectDirs, collectNativeMemoryFiles, computePhrenLiveStateToken, getPhrenPath, qualityMarkers, atomicWriteText, } from "./phren-paths.js";
|
|
5
5
|
export { PROACTIVITY_LEVELS, type ProactivityLevel, getProactivityLevel, getProactivityLevelForFindings, getProactivityLevelForTask, hasExplicitFindingSignal, hasExplicitTaskSignal, hasExecutionIntent, hasDiscoveryIntent, shouldAutoCaptureFindingsForLevel, shouldAutoCaptureTaskForLevel, } from "./proactivity.js";
|
|
6
6
|
export declare function normalizeMemoryScope(scope?: string | null): string | undefined;
|
|
7
7
|
export declare function isMemoryScopeVisible(itemScope: string | undefined, activeScope?: string): boolean;
|
package/dist/shared.js
CHANGED
|
@@ -6,7 +6,7 @@ import { withFileLock } from "./governance/locks.js";
|
|
|
6
6
|
const MAX_LOG_LINES = 1000;
|
|
7
7
|
export { HOOK_TOOL_NAMES, hookConfigPath } from "./provider-adapters.js";
|
|
8
8
|
export { EXEC_TIMEOUT_MS, EXEC_TIMEOUT_QUICK_MS, PhrenError, phrenOk, phrenErr, forwardErr, parsePhrenErrorCode, isRecord, withDefaults, FINDING_TYPES, FINDING_TAGS, KNOWN_OBSERVATION_TAGS, DOC_TYPES, capCache, RESERVED_PROJECT_DIR_NAMES, } from "./phren-core.js";
|
|
9
|
-
export { ROOT_MANIFEST_FILENAME, homeDir, homePath, expandHomePath, defaultPhrenPath, rootManifestPath, readRootManifest, writeRootManifest, resolveInstallContext, findNearestPhrenPath, isProjectLocalMode, runtimeDir, tryUnlink, sessionsDir, runtimeFile, installPreferencesFile, runtimeHealthFile, shellStateFile, sessionMetricsFile, memoryScoresFile, memoryUsageLogFile, sessionMarker, debugLog, appendIndexEvent, resolveFindingsPath, findPhrenPath, ensurePhrenPath, findPhrenPathWithArg, normalizeProjectNameForCreate, findProjectNameCaseInsensitive, findArchivedProjectNameCaseInsensitive, getProjectDirs, collectNativeMemoryFiles, computePhrenLiveStateToken, getPhrenPath, qualityMarkers, atomicWriteText, } from "./phren-paths.js";
|
|
9
|
+
export { ROOT_MANIFEST_FILENAME, homeDir, homePath, expandHomePath, defaultPhrenPath, rootManifestPath, readRootManifest, writeRootManifest, resolveInstallContext, findNearestPhrenPath, isProjectLocalMode, runtimeDir, tryUnlink, sessionsDir, runtimeFile, installPreferencesFile, runtimeHealthFile, shellStateFile, sessionMetricsFile, memoryScoresFile, memoryUsageLogFile, sessionMarker, debugLog, appendIndexEvent, resolveFindingsPath, findPhrenPath, ensurePhrenPath, findPhrenPathWithArg, normalizeProjectNameForCreate, findProjectNameCaseInsensitive, findArchivedProjectNameCaseInsensitive, getProjectDirs, listInvalidProjectDirs, collectNativeMemoryFiles, computePhrenLiveStateToken, getPhrenPath, qualityMarkers, atomicWriteText, } from "./phren-paths.js";
|
|
10
10
|
export { PROACTIVITY_LEVELS, getProactivityLevel, getProactivityLevelForFindings, getProactivityLevelForTask, hasExplicitFindingSignal, hasExplicitTaskSignal, hasExecutionIntent, hasDiscoveryIntent, shouldAutoCaptureFindingsForLevel, shouldAutoCaptureTaskForLevel, } from "./proactivity.js";
|
|
11
11
|
const MEMORY_SCOPE_PATTERN = /^[a-z][a-z0-9_-]{0,63}$/;
|
|
12
12
|
export function normalizeMemoryScope(scope) {
|
package/dist/tools/finding.js
CHANGED
|
@@ -467,7 +467,7 @@ async function handlePushChanges(ctx, { message }) {
|
|
|
467
467
|
const commitMsg = message || `phren: save ${files.length} file(s) across ${projectNames.length} project(s)`;
|
|
468
468
|
runCustomHooks(phrenPath, "pre-save");
|
|
469
469
|
// Stage all files including untracked (new project dirs, first FINDINGS.md, etc.)
|
|
470
|
-
runGit(["add", "-A"]);
|
|
470
|
+
runGit(["add", "--sparse", "-A"]);
|
|
471
471
|
runGit(["commit", "-m", commitMsg]);
|
|
472
472
|
let hasRemote = false;
|
|
473
473
|
try {
|
|
@@ -570,7 +570,7 @@ async function handlePushChanges(ctx, { message }) {
|
|
|
570
570
|
continue;
|
|
571
571
|
}
|
|
572
572
|
// Only stage team-safe files: journal/, tasks.md, truths.md, FINDINGS.md, summary.md
|
|
573
|
-
runStoreGit(["add", "--", "*/journal/*", "*/tasks.md", "*/truths.md", "*/FINDINGS.md", "*/summary.md"]);
|
|
573
|
+
runStoreGit(["add", "--sparse", "--", "*/journal/*", "*/tasks.md", "*/truths.md", "*/FINDINGS.md", "*/FINDINGS.md.bak", "*/summary.md", "*/review.md", "*/CLAUDE.md", "*/topic-config.json", "*/phren.project.yaml", "*/reference/**", "*/skills/**"]);
|
|
574
574
|
const actor = process.env.PHREN_ACTOR || process.env.USER || "unknown";
|
|
575
575
|
runStoreGit(["commit", "-m", `phren: ${actor} team sync`]);
|
|
576
576
|
try {
|