@phren/cli 0.1.41 → 0.1.42
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/actions.js +1 -13
- package/dist/cli/extract.js +3 -2
- package/dist/cli/namespaces-utils.js +1 -1
- package/dist/content/archive.js +3 -2
- package/dist/content/dedup.js +4 -3
- package/dist/content/learning.js +5 -4
- package/dist/content/secrets.js +4 -1
- package/dist/data/access.js +10 -9
- package/dist/data/tasks.js +46 -6
- package/dist/finding/lifecycle.js +3 -2
- package/dist/governance/policy.js +4 -3
- package/dist/project-config.js +3 -2
- package/dist/project-topics.js +13 -12
- package/dist/shared/data-utils.js +13 -3
- package/dist/store-routing.d.ts +8 -0
- package/dist/store-routing.js +23 -1
- package/dist/tools/config.js +4 -3
- package/dist/tools/extract-facts.js +3 -2
- package/dist/tools/finding.js +6 -5
- package/dist/ui/server.js +2 -6
- package/dist/utils-fts.js +3 -2
- package/dist/utils-paths.d.ts +1 -0
- package/dist/utils-paths.js +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/package.json +1 -1
package/dist/cli/actions.js
CHANGED
|
@@ -15,19 +15,7 @@ import { runSearch, runFragmentSearch, parseFragmentSearchArgs, runRelatedDocs,
|
|
|
15
15
|
import { resolveRuntimeProfile } from "../runtime-profile.js";
|
|
16
16
|
import { getProjectConsolidationStatus, CONSOLIDATION_ENTRY_THRESHOLD } from "../content/validate.js";
|
|
17
17
|
import { listAllSessions } from "../tools/session.js";
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
const { getNonPrimaryStores } = require("../store-registry.js");
|
|
21
|
-
if (fs.existsSync(path.join(phrenPath, project)))
|
|
22
|
-
return phrenPath;
|
|
23
|
-
for (const store of getNonPrimaryStores(phrenPath)) {
|
|
24
|
-
if (fs.existsSync(path.join(store.path, project)))
|
|
25
|
-
return store.path;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
catch { /* fall through */ }
|
|
29
|
-
return phrenPath;
|
|
30
|
-
}
|
|
18
|
+
import { resolveProjectStorePath } from "./namespaces-utils.js";
|
|
31
19
|
async function runAndPrint(fn) {
|
|
32
20
|
const result = await fn();
|
|
33
21
|
if (result.lines.length > 0)
|
package/dist/cli/extract.js
CHANGED
|
@@ -2,7 +2,8 @@ import { debugLog, appendAuditLog, atomicWriteText, EXEC_TIMEOUT_MS, getPhrenPat
|
|
|
2
2
|
import { appendReviewQueue, getRetentionPolicy, recordFeedback, flushEntryScores, entryScoreKey, } from "../shared/governance.js";
|
|
3
3
|
import { detectProject } from "../shared/index.js";
|
|
4
4
|
import { commandExists } from "../hooks.js";
|
|
5
|
-
import { runGit as runGitShared, isFeatureEnabled, clampInt, errorMessage, isValidProjectName, resolveExecCommand
|
|
5
|
+
import { runGit as runGitShared, isFeatureEnabled, clampInt, errorMessage, isValidProjectName, resolveExecCommand } from "../utils.js";
|
|
6
|
+
import { storeAwareProjectPath } from "../store-routing.js";
|
|
6
7
|
import { appendFindingJournal, compactFindingJournals } from "../finding/journal.js";
|
|
7
8
|
import { findingQualityReason } from "../content/quality.js";
|
|
8
9
|
import { FINDINGS_FILENAME } from "../data/access.js";
|
|
@@ -310,7 +311,7 @@ function addMarkersFromJournal(file, into) {
|
|
|
310
311
|
*/
|
|
311
312
|
function readProcessedMemory(phrenPath, project) {
|
|
312
313
|
const memory = { commits: new Set(), subjects: new Set() };
|
|
313
|
-
const projectDir =
|
|
314
|
+
const projectDir = storeAwareProjectPath(phrenPath, project);
|
|
314
315
|
if (!projectDir)
|
|
315
316
|
return memory;
|
|
316
317
|
addMarkersFromFile(path.join(projectDir, "review.md"), memory);
|
|
@@ -3,9 +3,9 @@ import * as path from "path";
|
|
|
3
3
|
import { execFileSync } from "child_process";
|
|
4
4
|
import { errorMessage } from "../utils.js";
|
|
5
5
|
import { logger } from "../logger.js";
|
|
6
|
+
import { getNonPrimaryStores } from "../store-registry.js";
|
|
6
7
|
export function resolveProjectStorePath(phrenPath, project) {
|
|
7
8
|
try {
|
|
8
|
-
const { getNonPrimaryStores } = require("../store-registry.js");
|
|
9
9
|
if (fs.existsSync(path.join(phrenPath, project)))
|
|
10
10
|
return phrenPath;
|
|
11
11
|
for (const store of getNonPrimaryStores(phrenPath)) {
|
package/dist/content/archive.js
CHANGED
|
@@ -2,7 +2,8 @@ import * as fs from "fs";
|
|
|
2
2
|
import * as path from "path";
|
|
3
3
|
import * as crypto from "crypto";
|
|
4
4
|
import { debugLog, runtimeFile, phrenOk, phrenErr, PhrenError, appendAuditLog, tryUnlink } from "../shared.js";
|
|
5
|
-
import { isValidProjectName,
|
|
5
|
+
import { isValidProjectName, errorMessage } from "../utils.js";
|
|
6
|
+
import { storeAwareProjectPath } from "../store-routing.js";
|
|
6
7
|
import { withFileLock } from "../shared/governance.js";
|
|
7
8
|
import { walkDirectory } from "../shared/data-utils.js";
|
|
8
9
|
import { appendArchivedEntriesToTopicDoc, classifyTopicForText, readProjectTopics, topicReferencePath } from "../project-topics.js";
|
|
@@ -114,7 +115,7 @@ function isAlreadyArchived(archivedSet, bullet) {
|
|
|
114
115
|
export function autoArchiveToReference(phrenPath, project, keepCount) {
|
|
115
116
|
if (!isValidProjectName(project))
|
|
116
117
|
return phrenErr(`Invalid project name: "${project}".`, PhrenError.INVALID_PROJECT_NAME);
|
|
117
|
-
const resolvedDir =
|
|
118
|
+
const resolvedDir = storeAwareProjectPath(phrenPath, project);
|
|
118
119
|
if (!resolvedDir || !fs.existsSync(resolvedDir))
|
|
119
120
|
return phrenErr(`Project "${project}" not found in phren.`, PhrenError.PROJECT_NOT_FOUND);
|
|
120
121
|
const learningsPath = path.join(resolvedDir, FINDINGS_FILENAME);
|
package/dist/content/dedup.js
CHANGED
|
@@ -2,7 +2,8 @@ import * as fs from "fs";
|
|
|
2
2
|
import * as path from "path";
|
|
3
3
|
import * as crypto from "crypto";
|
|
4
4
|
import { debugLog, runtimeFile, KNOWN_OBSERVATION_TAGS } from "../shared.js";
|
|
5
|
-
import { isFeatureEnabled,
|
|
5
|
+
import { isFeatureEnabled, errorMessage } from "../utils.js";
|
|
6
|
+
import { storeAwareProjectPath } from "../store-routing.js";
|
|
6
7
|
import { UNIVERSAL_TECH_TERMS_RE, EXTRA_FRAGMENT_PATTERNS } from "../phren-core.js";
|
|
7
8
|
import { isInactiveFindingLine } from "../finding/lifecycle.js";
|
|
8
9
|
import { logger } from "../logger.js";
|
|
@@ -443,7 +444,7 @@ export function resolveCoref(text, context) {
|
|
|
443
444
|
export async function checkSemanticDedup(phrenPath, project, newLearning, signal) {
|
|
444
445
|
if (!isFeatureEnabled("PHREN_FEATURE_SEMANTIC_DEDUP", false))
|
|
445
446
|
return false;
|
|
446
|
-
const resolvedDir =
|
|
447
|
+
const resolvedDir = storeAwareProjectPath(phrenPath, project);
|
|
447
448
|
if (!resolvedDir)
|
|
448
449
|
return false;
|
|
449
450
|
const findingsPath = path.join(resolvedDir, FINDINGS_FILENAME);
|
|
@@ -495,7 +496,7 @@ const CONFLICT_CHECK_TOTAL_TIMEOUT_MS = 30_000;
|
|
|
495
496
|
export async function checkSemanticConflicts(phrenPath, project, newFinding, signal) {
|
|
496
497
|
if (!isFeatureEnabled("PHREN_FEATURE_SEMANTIC_CONFLICT", false))
|
|
497
498
|
return { annotations: [], checked: false };
|
|
498
|
-
const resolvedDir =
|
|
499
|
+
const resolvedDir = storeAwareProjectPath(phrenPath, project);
|
|
499
500
|
if (!resolvedDir)
|
|
500
501
|
return { annotations: [], checked: false };
|
|
501
502
|
const newEntities = extractProseEntities(newFinding);
|
package/dist/content/learning.js
CHANGED
|
@@ -4,7 +4,8 @@ import * as crypto from "crypto";
|
|
|
4
4
|
import { debugLog, appendAuditLog, phrenOk, phrenErr, PhrenError } from "../shared.js";
|
|
5
5
|
import { normalizeMemoryScope } from "../shared.js";
|
|
6
6
|
import { withFileLock } from "../shared/governance.js";
|
|
7
|
-
import { isValidProjectName
|
|
7
|
+
import { isValidProjectName } from "../utils.js";
|
|
8
|
+
import { storeAwareProjectPath } from "../store-routing.js";
|
|
8
9
|
import { buildCitationComment, buildScopeComment, buildSourceComment, getHeadCommit, getRepoRoot, inferCitationLocation, } from "./citation.js";
|
|
9
10
|
import { isDuplicateFinding, scanForSecrets, normalizeObservationTags, resolveCoref } from "./dedup.js";
|
|
10
11
|
import { validateFindingsFormat, validateFinding } from "./validate.js";
|
|
@@ -199,7 +200,7 @@ function insertFindingIntoContent(content, today, bullet, citationComment) {
|
|
|
199
200
|
export function upsertCanonical(phrenPath, project, memory) {
|
|
200
201
|
if (!isValidProjectName(project))
|
|
201
202
|
return phrenErr(`Invalid project name: "${project}".`, PhrenError.INVALID_PROJECT_NAME);
|
|
202
|
-
const resolvedDir =
|
|
203
|
+
const resolvedDir = storeAwareProjectPath(phrenPath, project);
|
|
203
204
|
if (!resolvedDir || !fs.existsSync(resolvedDir))
|
|
204
205
|
return phrenErr(`Project "${project}" not found in phren.`, PhrenError.PROJECT_NOT_FOUND);
|
|
205
206
|
const canonicalPath = path.join(resolvedDir, "truths.md");
|
|
@@ -232,7 +233,7 @@ export function addFindingToFile(phrenPath, project, learning, citationInput, op
|
|
|
232
233
|
return phrenErr(findingError, PhrenError.EMPTY_INPUT);
|
|
233
234
|
if (!isValidProjectName(project))
|
|
234
235
|
return phrenErr(`Invalid project name: "${project}".`, PhrenError.INVALID_PROJECT_NAME);
|
|
235
|
-
const resolvedDir =
|
|
236
|
+
const resolvedDir = storeAwareProjectPath(phrenPath, project);
|
|
236
237
|
if (!resolvedDir)
|
|
237
238
|
return phrenErr(`Invalid project name: "${project}".`, PhrenError.INVALID_PROJECT_NAME);
|
|
238
239
|
const learningsPath = path.join(resolvedDir, FINDINGS_FILENAME);
|
|
@@ -384,7 +385,7 @@ export function addFindingToFile(phrenPath, project, learning, citationInput, op
|
|
|
384
385
|
export function addFindingsToFile(phrenPath, project, learnings, opts) {
|
|
385
386
|
if (!isValidProjectName(project))
|
|
386
387
|
return phrenErr(`Invalid project name: "${project}".`, PhrenError.INVALID_PROJECT_NAME);
|
|
387
|
-
const resolvedDir =
|
|
388
|
+
const resolvedDir = storeAwareProjectPath(phrenPath, project);
|
|
388
389
|
if (!resolvedDir)
|
|
389
390
|
return phrenErr(`Invalid project name: "${project}".`, PhrenError.INVALID_PROJECT_NAME);
|
|
390
391
|
const learningsPath = path.join(resolvedDir, FINDINGS_FILENAME);
|
package/dist/content/secrets.js
CHANGED
|
@@ -101,7 +101,10 @@ export function scanForSecrets(text) {
|
|
|
101
101
|
return 'Slack webhook URL';
|
|
102
102
|
// Long base64-encoded secret-like blob (requires base64 chars including +/= and must not be
|
|
103
103
|
// a plain hex digest like a git commit SHA — 40-char lowercase hex is explicitly exempt).
|
|
104
|
-
|
|
104
|
+
// Also requires a digit: 40 random base64 chars lack one ~0.1% of the time, while
|
|
105
|
+
// slash-joined camelCase identifier chains ("addFooToBar/addFoosToBar/upsertBaz") never
|
|
106
|
+
// have one — that prose shape was being rejected as a credential.
|
|
107
|
+
if (!/^[0-9a-f]{40}$/.test(text) && /(?=[A-Za-z0-9+/]*[+/])(?=[A-Za-z+/]*[0-9])[A-Za-z0-9+/]{40,}={0,2}/.test(text.replace(/[0-9a-f]{40}/g, "")))
|
|
105
108
|
return 'long base64 secret';
|
|
106
109
|
// Connection string with credentials
|
|
107
110
|
if (/(mongodb|postgres|mysql|redis):\/\/[^@\s]+:[^@\s]+@/i.test(text))
|
package/dist/data/access.js
CHANGED
|
@@ -7,7 +7,7 @@ import * as yaml from "js-yaml";
|
|
|
7
7
|
import { appendAuditLog, phrenErr, PhrenError, phrenOk, forwardErr, getProjectDirs, isRecord, } from "../shared.js";
|
|
8
8
|
import { normalizeQueueEntryText, } from "../shared/governance.js";
|
|
9
9
|
import { addFindingToFile, } from "../shared/content.js";
|
|
10
|
-
import { isValidProjectName,
|
|
10
|
+
import { isValidProjectName, QUEUE_FILENAME, safeProjectPath } from "../utils.js";
|
|
11
11
|
import { parseCitationComment, parseScopeComment, parseSourceComment, } from "../content/citation.js";
|
|
12
12
|
import { parseFindingLifecycle, } from "../finding/lifecycle.js";
|
|
13
13
|
import { METADATA_REGEX, isCitationLine, isArchiveStart, isArchiveEnd, parseFindingId, parseAllContradictions, stripComments, normalizeFindingText, } from "../content/metadata.js";
|
|
@@ -303,7 +303,7 @@ export function removeFinding(phrenPath, project, match) {
|
|
|
303
303
|
if (!ensured.ok)
|
|
304
304
|
return forwardErr(ensured);
|
|
305
305
|
const findingsPath = path.resolve(path.join(ensured.data, FINDINGS_FILENAME));
|
|
306
|
-
if (!findingsPath.startsWith(
|
|
306
|
+
if (!findingsPath.startsWith(path.resolve(ensured.data) + path.sep)) {
|
|
307
307
|
return phrenErr(`${FINDINGS_FILENAME} path escapes phren store`, PhrenError.VALIDATION_ERROR);
|
|
308
308
|
}
|
|
309
309
|
const filePath = findingsPath;
|
|
@@ -340,7 +340,7 @@ export function removeFindings(phrenPath, project, matches) {
|
|
|
340
340
|
if (!ensured.ok)
|
|
341
341
|
return forwardErr(ensured);
|
|
342
342
|
const findingsPath = path.resolve(path.join(ensured.data, FINDINGS_FILENAME));
|
|
343
|
-
if (!findingsPath.startsWith(
|
|
343
|
+
if (!findingsPath.startsWith(path.resolve(ensured.data) + path.sep)) {
|
|
344
344
|
return phrenErr(`${FINDINGS_FILENAME} path escapes phren store`, PhrenError.VALIDATION_ERROR);
|
|
345
345
|
}
|
|
346
346
|
if (!fs.existsSync(findingsPath))
|
|
@@ -394,7 +394,7 @@ export function editFinding(phrenPath, project, oldText, newText) {
|
|
|
394
394
|
if (!newTextTrimmed)
|
|
395
395
|
return phrenErr("New finding text cannot be empty.", PhrenError.EMPTY_INPUT);
|
|
396
396
|
const findingsPath = path.resolve(path.join(ensured.data, FINDINGS_FILENAME));
|
|
397
|
-
if (!findingsPath.startsWith(
|
|
397
|
+
if (!findingsPath.startsWith(path.resolve(ensured.data) + path.sep)) {
|
|
398
398
|
return phrenErr(`${FINDINGS_FILENAME} path escapes phren store`, PhrenError.VALIDATION_ERROR);
|
|
399
399
|
}
|
|
400
400
|
if (!fs.existsSync(findingsPath))
|
|
@@ -432,8 +432,9 @@ export function editFinding(phrenPath, project, oldText, newText) {
|
|
|
432
432
|
return phrenOk(`Updated finding in ${project}`);
|
|
433
433
|
});
|
|
434
434
|
}
|
|
435
|
-
//
|
|
436
|
-
|
|
435
|
+
// Queue paths derive from the store-resolved project dir (ensureProject),
|
|
436
|
+
// so secondary-store projects hit their own store's review.md.
|
|
437
|
+
const queuePath = (projectDir) => path.join(projectDir, QUEUE_FILENAME);
|
|
437
438
|
function parseQueueLine(line) {
|
|
438
439
|
const parsed = line.match(/^- \[(\d{4}-\d{2}-\d{2})\]\s*(.+)$/);
|
|
439
440
|
const rawText = parsed ? parsed[2] : line.replace(/^-\s+/, "").trim();
|
|
@@ -457,7 +458,7 @@ export function readReviewQueue(phrenPath, project) {
|
|
|
457
458
|
const ensured = ensureProject(phrenPath, project);
|
|
458
459
|
if (!ensured.ok)
|
|
459
460
|
return forwardErr(ensured);
|
|
460
|
-
const file = queuePath(
|
|
461
|
+
const file = queuePath(ensured.data);
|
|
461
462
|
if (!fs.existsSync(file))
|
|
462
463
|
return phrenOk([]);
|
|
463
464
|
const lines = fs.readFileSync(file, "utf8").split("\n");
|
|
@@ -506,7 +507,7 @@ function withQueueLineOp(phrenPath, project, lineText, op) {
|
|
|
506
507
|
const ensured = ensureProject(phrenPath, project);
|
|
507
508
|
if (!ensured.ok)
|
|
508
509
|
return forwardErr(ensured);
|
|
509
|
-
const file = queuePath(
|
|
510
|
+
const file = queuePath(ensured.data);
|
|
510
511
|
if (!fs.existsSync(file))
|
|
511
512
|
return phrenErr(`No review queue found for "${project}".`, PhrenError.FILE_NOT_FOUND);
|
|
512
513
|
return withSafeLock(file, () => {
|
|
@@ -535,7 +536,7 @@ function locateQueueLine(phrenPath, project, lineText) {
|
|
|
535
536
|
const ensured = ensureProject(phrenPath, project);
|
|
536
537
|
if (!ensured.ok)
|
|
537
538
|
return forwardErr(ensured);
|
|
538
|
-
const file = queuePath(
|
|
539
|
+
const file = queuePath(ensured.data);
|
|
539
540
|
if (!fs.existsSync(file))
|
|
540
541
|
return phrenErr(`No review queue found for "${project}".`, PhrenError.FILE_NOT_FOUND);
|
|
541
542
|
const lines = fs.readFileSync(file, "utf8").split("\n");
|
package/dist/data/tasks.js
CHANGED
|
@@ -3,9 +3,9 @@ import * as path from "path";
|
|
|
3
3
|
import { randomBytes, randomUUID } from "crypto";
|
|
4
4
|
import { phrenErr, PhrenError, phrenOk, forwardErr, getProjectDirs, } from "../shared.js";
|
|
5
5
|
import { validateTaskFormat } from "../shared/content.js";
|
|
6
|
-
import { safeProjectPath } from "../utils.js";
|
|
7
6
|
import { withSafeLock, ensureProject } from "../shared/data-utils.js";
|
|
8
7
|
import { getNonPrimaryStores, getStoreProjectDirs } from "../store-registry.js";
|
|
8
|
+
import { storeAwareProjectPath } from "../store-routing.js";
|
|
9
9
|
const ACTIVE_HEADINGS = new Set(["active", "in progress", "in-progress", "current", "wip"]);
|
|
10
10
|
const QUEUE_HEADINGS = new Set(["queue", "queued", "task", "todo", "upcoming", "next"]);
|
|
11
11
|
const DONE_HEADINGS = new Set(["done", "completed", "finished", "archived"]);
|
|
@@ -166,10 +166,9 @@ export function applyGravity(items) {
|
|
|
166
166
|
});
|
|
167
167
|
}
|
|
168
168
|
export function canonicalTaskFilePath(phrenPath, project) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return path.join(resolved, TASKS_FILENAME);
|
|
169
|
+
// Store-aware: locks and writes must target the owning store's file, not a
|
|
170
|
+
// phantom primary-store path.
|
|
171
|
+
return storeAwareProjectPath(phrenPath, project, TASKS_FILENAME);
|
|
173
172
|
}
|
|
174
173
|
export function isTaskFileName(filename) {
|
|
175
174
|
return filename.toLowerCase() === TASKS_FILENAME;
|
|
@@ -480,6 +479,9 @@ export function completeTasks(phrenPath, project, matches) {
|
|
|
480
479
|
const bPath = canonicalTaskFilePath(phrenPath, project);
|
|
481
480
|
if (!bPath)
|
|
482
481
|
return phrenErr(`Project name "${project}" is not valid.`, PhrenError.INVALID_PROJECT_NAME);
|
|
482
|
+
const preCheck = ensureProject(phrenPath, project);
|
|
483
|
+
if (!preCheck.ok)
|
|
484
|
+
return forwardErr(preCheck);
|
|
483
485
|
return withSafeLock(bPath, () => {
|
|
484
486
|
const parsed = readTasks(phrenPath, project);
|
|
485
487
|
if (!parsed.ok)
|
|
@@ -506,6 +508,9 @@ export function completeTask(phrenPath, project, match) {
|
|
|
506
508
|
const bPath = canonicalTaskFilePath(phrenPath, project);
|
|
507
509
|
if (!bPath)
|
|
508
510
|
return phrenErr(`Project name "${project}" is not valid.`, PhrenError.INVALID_PROJECT_NAME);
|
|
511
|
+
const preCheck = ensureProject(phrenPath, project);
|
|
512
|
+
if (!preCheck.ok)
|
|
513
|
+
return forwardErr(preCheck);
|
|
509
514
|
return withSafeLock(bPath, () => {
|
|
510
515
|
const parsed = readTasks(phrenPath, project);
|
|
511
516
|
if (!parsed.ok)
|
|
@@ -527,6 +532,9 @@ export function removeTask(phrenPath, project, match) {
|
|
|
527
532
|
const bPath = canonicalTaskFilePath(phrenPath, project);
|
|
528
533
|
if (!bPath)
|
|
529
534
|
return phrenErr(`Project name "${project}" is not valid.`, PhrenError.INVALID_PROJECT_NAME);
|
|
535
|
+
const preCheck = ensureProject(phrenPath, project);
|
|
536
|
+
if (!preCheck.ok)
|
|
537
|
+
return forwardErr(preCheck);
|
|
530
538
|
return withSafeLock(bPath, () => {
|
|
531
539
|
const parsed = readTasks(phrenPath, project);
|
|
532
540
|
if (!parsed.ok)
|
|
@@ -545,6 +553,9 @@ export function removeTasks(phrenPath, project, matches) {
|
|
|
545
553
|
const bPath = canonicalTaskFilePath(phrenPath, project);
|
|
546
554
|
if (!bPath)
|
|
547
555
|
return phrenErr(`Project name "${project}" is not valid.`, PhrenError.INVALID_PROJECT_NAME);
|
|
556
|
+
const preCheck = ensureProject(phrenPath, project);
|
|
557
|
+
if (!preCheck.ok)
|
|
558
|
+
return forwardErr(preCheck);
|
|
548
559
|
return withSafeLock(bPath, () => {
|
|
549
560
|
const parsed = readTasks(phrenPath, project);
|
|
550
561
|
if (!parsed.ok)
|
|
@@ -568,6 +579,9 @@ export function updateTask(phrenPath, project, match, updates) {
|
|
|
568
579
|
const bPath = canonicalTaskFilePath(phrenPath, project);
|
|
569
580
|
if (!bPath)
|
|
570
581
|
return phrenErr(`Project name "${project}" is not valid.`, PhrenError.INVALID_PROJECT_NAME);
|
|
582
|
+
const preCheck = ensureProject(phrenPath, project);
|
|
583
|
+
if (!preCheck.ok)
|
|
584
|
+
return forwardErr(preCheck);
|
|
571
585
|
return withSafeLock(bPath, () => {
|
|
572
586
|
const parsed = readTasks(phrenPath, project);
|
|
573
587
|
if (!parsed.ok)
|
|
@@ -648,6 +662,9 @@ export function pinTask(phrenPath, project, match) {
|
|
|
648
662
|
const bPath = canonicalTaskFilePath(phrenPath, project);
|
|
649
663
|
if (!bPath)
|
|
650
664
|
return phrenErr(`Project name "${project}" is not valid.`, PhrenError.INVALID_PROJECT_NAME);
|
|
665
|
+
const preCheck = ensureProject(phrenPath, project);
|
|
666
|
+
if (!preCheck.ok)
|
|
667
|
+
return forwardErr(preCheck);
|
|
651
668
|
return withSafeLock(bPath, () => {
|
|
652
669
|
const parsed = readTasks(phrenPath, project);
|
|
653
670
|
if (!parsed.ok)
|
|
@@ -673,6 +690,9 @@ export function unpinTask(phrenPath, project, match) {
|
|
|
673
690
|
const bPath = canonicalTaskFilePath(phrenPath, project);
|
|
674
691
|
if (!bPath)
|
|
675
692
|
return phrenErr(`Project name "${project}" is not valid.`, PhrenError.INVALID_PROJECT_NAME);
|
|
693
|
+
const preCheck = ensureProject(phrenPath, project);
|
|
694
|
+
if (!preCheck.ok)
|
|
695
|
+
return forwardErr(preCheck);
|
|
676
696
|
return withSafeLock(bPath, () => {
|
|
677
697
|
const parsed = readTasks(phrenPath, project);
|
|
678
698
|
if (!parsed.ok)
|
|
@@ -695,6 +715,9 @@ export function reorderTask(phrenPath, project, match, targetRank) {
|
|
|
695
715
|
const bPath = canonicalTaskFilePath(phrenPath, project);
|
|
696
716
|
if (!bPath)
|
|
697
717
|
return phrenErr(`Project name "${project}" is not valid.`, PhrenError.INVALID_PROJECT_NAME);
|
|
718
|
+
const preCheck = ensureProject(phrenPath, project);
|
|
719
|
+
if (!preCheck.ok)
|
|
720
|
+
return forwardErr(preCheck);
|
|
698
721
|
return withSafeLock(bPath, () => {
|
|
699
722
|
const parsed = readTasks(phrenPath, project);
|
|
700
723
|
if (!parsed.ok)
|
|
@@ -732,6 +755,9 @@ export function appendChildFinding(phrenPath, project, match, findingId) {
|
|
|
732
755
|
const bPath = canonicalTaskFilePath(phrenPath, project);
|
|
733
756
|
if (!bPath)
|
|
734
757
|
return phrenErr(`Project name "${project}" is not valid.`, PhrenError.INVALID_PROJECT_NAME);
|
|
758
|
+
const preCheck = ensureProject(phrenPath, project);
|
|
759
|
+
if (!preCheck.ok)
|
|
760
|
+
return forwardErr(preCheck);
|
|
735
761
|
return withSafeLock(bPath, () => {
|
|
736
762
|
const parsed = readTasks(phrenPath, project);
|
|
737
763
|
if (!parsed.ok)
|
|
@@ -752,6 +778,9 @@ export function promoteTask(phrenPath, project, match, moveToActive) {
|
|
|
752
778
|
const bPath = canonicalTaskFilePath(phrenPath, project);
|
|
753
779
|
if (!bPath)
|
|
754
780
|
return phrenErr(`Project name "${project}" is not valid.`, PhrenError.INVALID_PROJECT_NAME);
|
|
781
|
+
const preCheck = ensureProject(phrenPath, project);
|
|
782
|
+
if (!preCheck.ok)
|
|
783
|
+
return forwardErr(preCheck);
|
|
755
784
|
return withSafeLock(bPath, () => {
|
|
756
785
|
const parsed = readTasks(phrenPath, project);
|
|
757
786
|
if (!parsed.ok)
|
|
@@ -777,6 +806,9 @@ export function workNextTask(phrenPath, project) {
|
|
|
777
806
|
const bPath = canonicalTaskFilePath(phrenPath, project);
|
|
778
807
|
if (!bPath)
|
|
779
808
|
return phrenErr(`Project name "${project}" is not valid.`, PhrenError.INVALID_PROJECT_NAME);
|
|
809
|
+
const preCheck = ensureProject(phrenPath, project);
|
|
810
|
+
if (!preCheck.ok)
|
|
811
|
+
return forwardErr(preCheck);
|
|
780
812
|
return withSafeLock(bPath, () => {
|
|
781
813
|
const parsed = readTasks(phrenPath, project);
|
|
782
814
|
if (!parsed.ok)
|
|
@@ -802,6 +834,9 @@ export function tidyDoneTasks(phrenPath, project, keep = 30, dryRun) {
|
|
|
802
834
|
const bPath = canonicalTaskFilePath(phrenPath, project);
|
|
803
835
|
if (!bPath)
|
|
804
836
|
return phrenErr(`Project name "${project}" is not valid.`, PhrenError.INVALID_PROJECT_NAME);
|
|
837
|
+
const preCheck = ensureProject(phrenPath, project);
|
|
838
|
+
if (!preCheck.ok)
|
|
839
|
+
return forwardErr(preCheck);
|
|
805
840
|
return withSafeLock(bPath, () => {
|
|
806
841
|
const parsed = readTasks(phrenPath, project);
|
|
807
842
|
if (!parsed.ok)
|
|
@@ -815,7 +850,9 @@ export function tidyDoneTasks(phrenPath, project, keep = 30, dryRun) {
|
|
|
815
850
|
return phrenOk(`[dry-run] Would archive ${archived.length} done item(s) for ${project}, keeping ${safeKeep}.`);
|
|
816
851
|
}
|
|
817
852
|
parsed.data.items.Done = parsed.data.items.Done.slice(0, safeKeep);
|
|
818
|
-
|
|
853
|
+
// Archive into the store that owns the tasks file (bPath = <store>/<project>/tasks.md),
|
|
854
|
+
// so secondary-store task history never lands in the primary store's .config.
|
|
855
|
+
const archiveFile = taskArchivePath(path.dirname(path.dirname(bPath)), project);
|
|
819
856
|
fs.mkdirSync(path.dirname(archiveFile), { recursive: true });
|
|
820
857
|
const stamp = new Date().toISOString();
|
|
821
858
|
const lines = archived.map((item) => `- [x] ${item.line}${item.context ? `\n Context: ${item.context}` : ""}`);
|
|
@@ -835,6 +872,9 @@ export function linkTaskIssue(phrenPath, project, match, link) {
|
|
|
835
872
|
const bPath = canonicalTaskFilePath(phrenPath, project);
|
|
836
873
|
if (!bPath)
|
|
837
874
|
return phrenErr(`Project name "${project}" is not valid.`, PhrenError.INVALID_PROJECT_NAME);
|
|
875
|
+
const preCheck = ensureProject(phrenPath, project);
|
|
876
|
+
if (!preCheck.ok)
|
|
877
|
+
return forwardErr(preCheck);
|
|
838
878
|
return withSafeLock(bPath, () => {
|
|
839
879
|
const parsed = readTasks(phrenPath, project);
|
|
840
880
|
if (!parsed.ok)
|
|
@@ -4,7 +4,8 @@ import { PhrenError, phrenErr, phrenOk } from "../phren-core.js";
|
|
|
4
4
|
// Phren lifecycle comment prefix. No backward compat.
|
|
5
5
|
const LIFECYCLE_PREFIX = "phren";
|
|
6
6
|
import { withFileLock } from "../shared/governance.js";
|
|
7
|
-
import { isValidProjectName
|
|
7
|
+
import { isValidProjectName } from "../utils.js";
|
|
8
|
+
import { storeAwareProjectPath } from "../store-routing.js";
|
|
8
9
|
import { isArchiveEnd, isArchiveStart, parseCreatedDate as parseCreatedDateMeta, parseStatusField, parseStatus, parseSupersession, parseContradiction, parseFindingId as parseFindingIdMeta, stripLifecycleMetadata, stripRelationMetadata, normalizeFindingText, } from "../content/metadata.js";
|
|
9
10
|
import { FINDINGS_FILENAME } from "../data/access.js";
|
|
10
11
|
/**
|
|
@@ -206,7 +207,7 @@ function matchFinding(lines, match) {
|
|
|
206
207
|
function findingsPathForProject(phrenPath, project) {
|
|
207
208
|
if (!isValidProjectName(project))
|
|
208
209
|
return phrenErr(`Invalid project name: "${project}"`, PhrenError.INVALID_PROJECT_NAME);
|
|
209
|
-
const projectDir =
|
|
210
|
+
const projectDir = storeAwareProjectPath(phrenPath, project);
|
|
210
211
|
if (!projectDir)
|
|
211
212
|
return phrenErr(`Invalid project name: "${project}"`, PhrenError.INVALID_PROJECT_NAME);
|
|
212
213
|
if (!fs.existsSync(projectDir))
|
|
@@ -3,7 +3,8 @@ import * as fs from "fs";
|
|
|
3
3
|
import * as path from "path";
|
|
4
4
|
import { appendAuditLog, debugLog, getProjectDirs, isRecord, runtimeDir, runtimeHealthFile, withDefaults, phrenErr, PhrenError, phrenOk, resolveFindingsPath } from "../shared.js";
|
|
5
5
|
import { withFileLock, isFiniteNumber, hasValidSchemaVersion } from "../shared/governance.js";
|
|
6
|
-
import { errorMessage, isValidProjectName
|
|
6
|
+
import { errorMessage, isValidProjectName } from "../utils.js";
|
|
7
|
+
import { storeAwareProjectPath } from "../store-routing.js";
|
|
7
8
|
import { readProjectConfig } from "../project-config.js";
|
|
8
9
|
import { getActiveProfileDefaults } from "../profile-store.js";
|
|
9
10
|
import { runCustomHooks } from "../hooks.js";
|
|
@@ -666,7 +667,7 @@ function queueDedupKey(line) {
|
|
|
666
667
|
export function appendReviewQueue(phrenPath, project, section, entries) {
|
|
667
668
|
if (!isValidProjectName(project))
|
|
668
669
|
return phrenErr(`Invalid project name: "${project}".`, PhrenError.INVALID_PROJECT_NAME);
|
|
669
|
-
const resolvedDir =
|
|
670
|
+
const resolvedDir = storeAwareProjectPath(phrenPath, project);
|
|
670
671
|
if (!resolvedDir || !fs.existsSync(resolvedDir))
|
|
671
672
|
return phrenErr(`Project "${project}" not found in phren.`, PhrenError.PROJECT_NOT_FOUND);
|
|
672
673
|
const queuePath = path.join(resolvedDir, "review.md");
|
|
@@ -815,7 +816,7 @@ export function pruneDeadMemories(phrenPath, project, dryRun) {
|
|
|
815
816
|
return phrenErr(`Invalid project name: "${project}".`, PhrenError.INVALID_PROJECT_NAME);
|
|
816
817
|
const dirs = project
|
|
817
818
|
? (() => {
|
|
818
|
-
const resolvedProject =
|
|
819
|
+
const resolvedProject = storeAwareProjectPath(phrenPath, project);
|
|
819
820
|
return resolvedProject ? [resolvedProject] : [];
|
|
820
821
|
})()
|
|
821
822
|
: getProjectDirs(phrenPath).filter((dir) => path.basename(dir) !== "global");
|
package/dist/project-config.js
CHANGED
|
@@ -4,7 +4,8 @@ import * as path from "path";
|
|
|
4
4
|
import * as yaml from "js-yaml";
|
|
5
5
|
import { readInstallPreferences } from "./init/preferences.js";
|
|
6
6
|
import { debugLog } from "./shared.js";
|
|
7
|
-
import { errorMessage
|
|
7
|
+
import { errorMessage } from "./utils.js";
|
|
8
|
+
import { storeAwareProjectPath } from "./store-routing.js";
|
|
8
9
|
import { withFileLock } from "./shared/governance.js";
|
|
9
10
|
export const PROJECT_OWNERSHIP_MODES = ["phren-managed", "detached", "repo-managed"];
|
|
10
11
|
export const PROJECT_HOOK_EVENTS = ["UserPromptSubmit", "Stop", "SessionStart", "PostToolUse"];
|
|
@@ -25,7 +26,7 @@ export function projectConfigPath(phrenPath, project) {
|
|
|
25
26
|
return path.join(phrenPath, project, "phren.project.yaml");
|
|
26
27
|
}
|
|
27
28
|
function resolveProjectConfigPath(phrenPath, project) {
|
|
28
|
-
return
|
|
29
|
+
return storeAwareProjectPath(phrenPath, project, "phren.project.yaml");
|
|
29
30
|
}
|
|
30
31
|
function writeProjectConfigFile(configPath, next) {
|
|
31
32
|
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
package/dist/project-topics.js
CHANGED
|
@@ -3,7 +3,8 @@ import * as fs from "fs";
|
|
|
3
3
|
import * as path from "path";
|
|
4
4
|
import { debugLog } from "./shared.js";
|
|
5
5
|
import { withFileLock } from "./shared/governance.js";
|
|
6
|
-
import { STOP_WORDS, errorMessage, extractKeywords, isValidProjectName
|
|
6
|
+
import { STOP_WORDS, errorMessage, extractKeywords, isValidProjectName } from "./utils.js";
|
|
7
|
+
import { storeAwareProjectPath } from "./store-routing.js";
|
|
7
8
|
import { walkDirectory } from "./shared/data-utils.js";
|
|
8
9
|
import { FINDINGS_FILENAME } from "./data/access.js";
|
|
9
10
|
const TOPIC_CONFIG_FILENAME = "topic-config.json";
|
|
@@ -381,16 +382,16 @@ function ensureGeneralTopic(topics) {
|
|
|
381
382
|
return [...topics, { ...GENERAL_TOPIC, keywords: [...GENERAL_TOPIC.keywords] }];
|
|
382
383
|
}
|
|
383
384
|
function topicConfigPath(phrenPath, project) {
|
|
384
|
-
return
|
|
385
|
+
return storeAwareProjectPath(phrenPath, project, TOPIC_CONFIG_FILENAME);
|
|
385
386
|
}
|
|
386
387
|
function projectDirPath(phrenPath, project) {
|
|
387
|
-
return
|
|
388
|
+
return storeAwareProjectPath(phrenPath, project);
|
|
388
389
|
}
|
|
389
390
|
function topicReferenceRelativePath(slug) {
|
|
390
391
|
return path.posix.join("reference", "topics", `${slug}.md`);
|
|
391
392
|
}
|
|
392
393
|
export function topicReferencePath(phrenPath, project, slug) {
|
|
393
|
-
return
|
|
394
|
+
return storeAwareProjectPath(phrenPath, project, "reference", "topics", `${normalizeTopicSlug(slug)}.md`);
|
|
394
395
|
}
|
|
395
396
|
function readJsonFile(filePath) {
|
|
396
397
|
try {
|
|
@@ -412,14 +413,14 @@ function countByTerm(terms) {
|
|
|
412
413
|
function readTopicInputContent(phrenPath, project) {
|
|
413
414
|
const parts = [];
|
|
414
415
|
for (const file of ["CLAUDE.md", FINDINGS_FILENAME]) {
|
|
415
|
-
const filePath =
|
|
416
|
+
const filePath = storeAwareProjectPath(phrenPath, project, file);
|
|
416
417
|
if (!filePath || !fs.existsSync(filePath))
|
|
417
418
|
continue;
|
|
418
419
|
const content = fs.readFileSync(filePath, "utf8").trim();
|
|
419
420
|
if (content)
|
|
420
421
|
parts.push(content);
|
|
421
422
|
}
|
|
422
|
-
const referenceDir =
|
|
423
|
+
const referenceDir = storeAwareProjectPath(phrenPath, project, "reference");
|
|
423
424
|
if (referenceDir && fs.existsSync(referenceDir)) {
|
|
424
425
|
for (const filePath of readReferenceMarkdownFiles(referenceDir)) {
|
|
425
426
|
try {
|
|
@@ -834,7 +835,7 @@ export function listProjectReferenceDocs(phrenPath, project, topics) {
|
|
|
834
835
|
if (!projectDir)
|
|
835
836
|
return { topicDocs: [], otherDocs: [] };
|
|
836
837
|
const topicDocs = listProjectTopicDocs(phrenPath, project, topics);
|
|
837
|
-
const referenceDir =
|
|
838
|
+
const referenceDir = storeAwareProjectPath(phrenPath, project, "reference");
|
|
838
839
|
if (!referenceDir || !fs.existsSync(referenceDir))
|
|
839
840
|
return { topicDocs, otherDocs: [] };
|
|
840
841
|
const otherDocs = [];
|
|
@@ -857,7 +858,7 @@ export function listProjectReferenceDocs(phrenPath, project, topics) {
|
|
|
857
858
|
}
|
|
858
859
|
function listLegacyTopicDocs(phrenPath, project) {
|
|
859
860
|
const projectDir = projectDirPath(phrenPath, project);
|
|
860
|
-
const referenceDir =
|
|
861
|
+
const referenceDir = storeAwareProjectPath(phrenPath, project, "reference");
|
|
861
862
|
if (!projectDir || !referenceDir || !fs.existsSync(referenceDir))
|
|
862
863
|
return [];
|
|
863
864
|
const files = fs.readdirSync(referenceDir, { withFileTypes: true })
|
|
@@ -898,7 +899,7 @@ function tokenizeSuggestionTerms(text) {
|
|
|
898
899
|
function collectSuggestionCorpus(phrenPath, project) {
|
|
899
900
|
const parts = [];
|
|
900
901
|
for (const file of ["CLAUDE.md", "summary.md", FINDINGS_FILENAME]) {
|
|
901
|
-
const filePath =
|
|
902
|
+
const filePath = storeAwareProjectPath(phrenPath, project, file);
|
|
902
903
|
if (!filePath || !fs.existsSync(filePath))
|
|
903
904
|
continue;
|
|
904
905
|
const content = fs.readFileSync(filePath, "utf8");
|
|
@@ -1030,10 +1031,10 @@ function resolveReferenceContentPath(phrenPath, project, file) {
|
|
|
1030
1031
|
return null;
|
|
1031
1032
|
if (!file.endsWith(".md"))
|
|
1032
1033
|
return null;
|
|
1033
|
-
const filePath =
|
|
1034
|
+
const filePath = storeAwareProjectPath(phrenPath, project, file);
|
|
1034
1035
|
if (!filePath)
|
|
1035
1036
|
return null;
|
|
1036
|
-
const referenceRoot =
|
|
1037
|
+
const referenceRoot = storeAwareProjectPath(phrenPath, project, "reference");
|
|
1037
1038
|
if (!referenceRoot)
|
|
1038
1039
|
return null;
|
|
1039
1040
|
const normalizedRoot = referenceRoot + path.sep;
|
|
@@ -1051,7 +1052,7 @@ export function readReferenceContent(phrenPath, project, file) {
|
|
|
1051
1052
|
}
|
|
1052
1053
|
export function reclassifyLegacyTopicDocs(phrenPath, project) {
|
|
1053
1054
|
const { topics } = readProjectTopics(phrenPath, project);
|
|
1054
|
-
const referenceDir =
|
|
1055
|
+
const referenceDir = storeAwareProjectPath(phrenPath, project, "reference");
|
|
1055
1056
|
if (!referenceDir || !fs.existsSync(referenceDir))
|
|
1056
1057
|
return { movedFiles: 0, movedEntries: 0, skipped: [] };
|
|
1057
1058
|
const skipped = [];
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
2
|
import * as path from "path";
|
|
3
|
-
import { phrenErr, PhrenError, phrenOk, } from "../shared.js";
|
|
3
|
+
import { phrenErr, PhrenError, phrenOk, parsePhrenErrorCode, } from "../shared.js";
|
|
4
4
|
import { withFileLock as withFileLockRaw } from "./governance.js";
|
|
5
5
|
import { isValidProjectName, safeProjectPath, errorMessage } from "../utils.js";
|
|
6
|
+
import { resolveProject } from "../store-routing.js";
|
|
6
7
|
export function withSafeLock(filePath, fn) {
|
|
7
8
|
try {
|
|
8
9
|
return withFileLockRaw(filePath, fn);
|
|
@@ -46,8 +47,17 @@ export function ensureProject(phrenPath, project) {
|
|
|
46
47
|
const dir = safeProjectPath(phrenPath, project);
|
|
47
48
|
if (!dir)
|
|
48
49
|
return phrenErr(`Project name "${project}" is not valid. Use lowercase letters, numbers, and hyphens (e.g. "my-project").`, PhrenError.INVALID_PROJECT_NAME);
|
|
49
|
-
if (
|
|
50
|
+
if (fs.existsSync(dir))
|
|
51
|
+
return phrenOk(dir);
|
|
52
|
+
// Not in the primary store — the project may live in a registered secondary store.
|
|
53
|
+
try {
|
|
54
|
+
return phrenOk(resolveProject(phrenPath, project).projectDir);
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
const msg = errorMessage(err);
|
|
58
|
+
if (parsePhrenErrorCode(msg) === PhrenError.VALIDATION_ERROR) {
|
|
59
|
+
return phrenErr(msg.replace(/^[A-Z_]+:\s*/, ""), PhrenError.VALIDATION_ERROR);
|
|
60
|
+
}
|
|
50
61
|
return phrenErr(`No project "${project}" found. Add it with 'cd ~/your-project && phren add'.`, PhrenError.PROJECT_NOT_FOUND);
|
|
51
62
|
}
|
|
52
|
-
return phrenOk(dir);
|
|
53
63
|
}
|
package/dist/store-routing.d.ts
CHANGED
|
@@ -35,3 +35,11 @@ export declare function listAllProjects(phrenPath: string, profile?: string): Ar
|
|
|
35
35
|
projectName: string;
|
|
36
36
|
projectDir: string;
|
|
37
37
|
}>;
|
|
38
|
+
/**
|
|
39
|
+
* Store-aware variant of safeProjectPath for callers holding the primary store
|
|
40
|
+
* root: when the project directory does not exist in `phrenPath`, resolve the
|
|
41
|
+
* owning store from the registry and build the path under it instead. Falls
|
|
42
|
+
* back to the (nonexistent) primary-store path when the project is in no store
|
|
43
|
+
* or is ambiguous, so callers' existing not-found handling fires unchanged.
|
|
44
|
+
*/
|
|
45
|
+
export declare function storeAwareProjectPath(phrenPath: string, project: string, ...segments: string[]): string | null;
|
package/dist/store-routing.js
CHANGED
|
@@ -2,7 +2,7 @@ import * as fs from "fs";
|
|
|
2
2
|
import * as path from "path";
|
|
3
3
|
import { getProjectDirs } from "./phren-paths.js";
|
|
4
4
|
import { PhrenError } from "./phren-core.js";
|
|
5
|
-
import { isValidProjectName } from "./utils.js";
|
|
5
|
+
import { isValidProjectName, safeProjectPath } from "./utils.js";
|
|
6
6
|
import { resolveAllStores } from "./store-registry.js";
|
|
7
7
|
// ── Parsing ──────────────────────────────────────────────────────────────────
|
|
8
8
|
/**
|
|
@@ -93,6 +93,28 @@ export function listAllProjects(phrenPath, profile) {
|
|
|
93
93
|
}
|
|
94
94
|
return results;
|
|
95
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Store-aware variant of safeProjectPath for callers holding the primary store
|
|
98
|
+
* root: when the project directory does not exist in `phrenPath`, resolve the
|
|
99
|
+
* owning store from the registry and build the path under it instead. Falls
|
|
100
|
+
* back to the (nonexistent) primary-store path when the project is in no store
|
|
101
|
+
* or is ambiguous, so callers' existing not-found handling fires unchanged.
|
|
102
|
+
*/
|
|
103
|
+
export function storeAwareProjectPath(phrenPath, project, ...segments) {
|
|
104
|
+
let root = phrenPath;
|
|
105
|
+
const primaryDir = safeProjectPath(phrenPath, project);
|
|
106
|
+
if (!primaryDir)
|
|
107
|
+
return null;
|
|
108
|
+
if (!fs.existsSync(primaryDir)) {
|
|
109
|
+
try {
|
|
110
|
+
root = resolveProject(phrenPath, project).store.path;
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
// keep the primary root
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return safeProjectPath(root, project, ...segments);
|
|
117
|
+
}
|
|
96
118
|
// ── Internal helpers ─────────────────────────────────────────────────────────
|
|
97
119
|
const STORE_NAME_PATTERN = /^[a-z][a-z0-9_-]{0,63}$/;
|
|
98
120
|
function isValidStoreName(name) {
|
package/dist/tools/config.js
CHANGED
|
@@ -7,7 +7,8 @@ import { PROACTIVITY_LEVELS, } from "../proactivity.js";
|
|
|
7
7
|
import { writeGovernanceInstallPreferences, } from "../init/preferences.js";
|
|
8
8
|
import { FINDING_SENSITIVITY_CONFIG, buildProactivitySnapshot, checkProjectInProfile } from "../cli/config.js";
|
|
9
9
|
import { readProjectConfig, updateProjectConfigOverrides, } from "../project-config.js";
|
|
10
|
-
import { errorMessage, isValidProjectName
|
|
10
|
+
import { errorMessage, isValidProjectName } from "../utils.js";
|
|
11
|
+
import { storeAwareProjectPath } from "../store-routing.js";
|
|
11
12
|
import { ACCESS_ROLE_KEYS, ACL_LOCKOUT_HINT, permissionDeniedError, setAccessRoles } from "../governance/rbac.js";
|
|
12
13
|
import { readProjectTopics, writeProjectTopics, } from "../project-topics.js";
|
|
13
14
|
import { buildConfigView } from "../config/resolve.js";
|
|
@@ -41,7 +42,7 @@ function hasOwnOverride(overrides, key) {
|
|
|
41
42
|
const projectParam = z.string().optional().describe("Project name. When provided, writes to that project's phren.project.yaml instead of global .config/.");
|
|
42
43
|
// ── Topic helpers (shared by get_config topic domain and set_config topic domain) ──
|
|
43
44
|
function getTopicConfigData(phrenPath, project) {
|
|
44
|
-
const projectDir =
|
|
45
|
+
const projectDir = storeAwareProjectPath(phrenPath, project);
|
|
45
46
|
if (!projectDir || !fs.existsSync(projectDir)) {
|
|
46
47
|
return { ok: false, error: `Project "${project}" not found in phren.` };
|
|
47
48
|
}
|
|
@@ -533,7 +534,7 @@ async function handleSetConfig(ctx, { domain, settings, project }) {
|
|
|
533
534
|
catch (err) {
|
|
534
535
|
return mcpResponse({ ok: false, error: errorMessage(err) });
|
|
535
536
|
}
|
|
536
|
-
const projectDir =
|
|
537
|
+
const projectDir = storeAwareProjectPath(topicPhrenPath, topicProject);
|
|
537
538
|
if (!projectDir || !fs.existsSync(projectDir)) {
|
|
538
539
|
return mcpResponse({ ok: false, error: `Project "${topicProject}" not found in phren.` });
|
|
539
540
|
}
|
|
@@ -7,14 +7,15 @@
|
|
|
7
7
|
import * as fs from "fs";
|
|
8
8
|
import * as path from "path";
|
|
9
9
|
import { debugLog } from "../shared.js";
|
|
10
|
-
import {
|
|
10
|
+
import { isFeatureEnabled, errorMessage } from "../utils.js";
|
|
11
|
+
import { storeAwareProjectPath } from "../store-routing.js";
|
|
11
12
|
import { callLlm } from "../content/dedup.js";
|
|
12
13
|
import { withFileLock } from "../shared/governance.js";
|
|
13
14
|
import { logger } from "../logger.js";
|
|
14
15
|
const FACT_EXTRACT_FLAG = "PHREN_FEATURE_FACT_EXTRACT";
|
|
15
16
|
const MAX_FACTS = 50;
|
|
16
17
|
function preferencesPath(phrenPath, project) {
|
|
17
|
-
const dir =
|
|
18
|
+
const dir = storeAwareProjectPath(phrenPath, project);
|
|
18
19
|
return dir ? path.join(dir, "preferences.json") : null;
|
|
19
20
|
}
|
|
20
21
|
export function readExtractedFacts(phrenPath, project) {
|
package/dist/tools/finding.js
CHANGED
|
@@ -3,7 +3,8 @@ import { z } from "zod";
|
|
|
3
3
|
import * as fs from "fs";
|
|
4
4
|
import * as path from "path";
|
|
5
5
|
import { logger } from "../logger.js";
|
|
6
|
-
import { isValidProjectName,
|
|
6
|
+
import { isValidProjectName, errorMessage } from "../utils.js";
|
|
7
|
+
import { storeAwareProjectPath } from "../store-routing.js";
|
|
7
8
|
import { removeFinding as removeFindingCore, removeFindings as removeFindingsCore, applyFindingTypePrefix, } from "../core/finding.js";
|
|
8
9
|
import { debugLog, EXEC_TIMEOUT_MS, FINDING_TYPES, normalizeMemoryScope, } from "../shared.js";
|
|
9
10
|
import { getCurrentActor, getMachineName } from "../machine-identity.js";
|
|
@@ -101,7 +102,7 @@ function withLifecycleMutation(phrenPath, project, writeQueue, updateIndex, hand
|
|
|
101
102
|
const result = handler();
|
|
102
103
|
if (!result.ok)
|
|
103
104
|
return mcpResponse({ ok: false, error: result.error });
|
|
104
|
-
const resolvedFindingsDir =
|
|
105
|
+
const resolvedFindingsDir = storeAwareProjectPath(phrenPath, project);
|
|
105
106
|
if (resolvedFindingsDir)
|
|
106
107
|
updateIndex(path.join(resolvedFindingsDir, FINDINGS_FILENAME));
|
|
107
108
|
const mapped = mapResponse(result.data);
|
|
@@ -445,7 +446,7 @@ async function handleEditFinding(ctx, { project: projectInput, old_text, new_tex
|
|
|
445
446
|
const result = editFindingCore(phrenPath, project, old_text, new_text);
|
|
446
447
|
if (!result.ok)
|
|
447
448
|
return mcpResponse({ ok: false, error: result.error });
|
|
448
|
-
const resolvedFindingsDir =
|
|
449
|
+
const resolvedFindingsDir = storeAwareProjectPath(phrenPath, project);
|
|
449
450
|
if (resolvedFindingsDir)
|
|
450
451
|
updateFileInIndex(path.join(resolvedFindingsDir, FINDINGS_FILENAME));
|
|
451
452
|
return mcpResponse({
|
|
@@ -477,7 +478,7 @@ async function handleRemoveFinding(ctx, { project: projectInput, finding }) {
|
|
|
477
478
|
const result = removeFindingsCore(phrenPath, project, finding);
|
|
478
479
|
if (!result.ok)
|
|
479
480
|
return mcpResponse({ ok: false, error: result.message });
|
|
480
|
-
const resolvedFindingsDir =
|
|
481
|
+
const resolvedFindingsDir = storeAwareProjectPath(phrenPath, project);
|
|
481
482
|
if (resolvedFindingsDir)
|
|
482
483
|
updateFileInIndex(path.join(resolvedFindingsDir, FINDINGS_FILENAME));
|
|
483
484
|
return mcpResponse({ ok: true, message: result.message, data: result.data });
|
|
@@ -487,7 +488,7 @@ async function handleRemoveFinding(ctx, { project: projectInput, finding }) {
|
|
|
487
488
|
const result = removeFindingCore(phrenPath, project, finding);
|
|
488
489
|
if (!result.ok)
|
|
489
490
|
return mcpResponse({ ok: false, error: result.message });
|
|
490
|
-
const resolvedFindingsDir =
|
|
491
|
+
const resolvedFindingsDir = storeAwareProjectPath(phrenPath, project);
|
|
491
492
|
if (resolvedFindingsDir)
|
|
492
493
|
updateFileInIndex(path.join(resolvedFindingsDir, FINDINGS_FILENAME));
|
|
493
494
|
return mcpResponse({ ok: true, message: result.message, data: result.data });
|
package/dist/ui/server.js
CHANGED
|
@@ -15,7 +15,8 @@ import { buildGraph, collectProjectsForUI, collectSkillsForUI, getHooksData, isA
|
|
|
15
15
|
import { lookupEventsLogFile } from "../shared.js";
|
|
16
16
|
import { CONSOLIDATION_ENTRY_THRESHOLD } from "../content/validate.js";
|
|
17
17
|
import { ensureTopicReferenceDoc, getProjectTopicsResponse, listProjectReferenceDocs, pinProjectTopicSuggestion, readReferenceContent, reclassifyLegacyTopicDocs, unpinProjectTopicSuggestion, writeProjectTopics, } from "../project-topics.js";
|
|
18
|
-
import { getWorkflowPolicy, updateWorkflowPolicy, mergeConfig, getRetentionPolicy, getProjectConfigOverrides, getIndexPolicy, updateIndexPolicy, VALID_TASK_MODES } from "../governance/policy.js";
|
|
18
|
+
import { getWorkflowPolicy, updateWorkflowPolicy, updateRetentionPolicy, mergeConfig, getRetentionPolicy, getProjectConfigOverrides, getIndexPolicy, updateIndexPolicy, VALID_TASK_MODES } from "../governance/policy.js";
|
|
19
|
+
import { listProfiles, setMachineProfile, getDefaultMachineAlias } from "../profile-store.js";
|
|
19
20
|
import { setAccessRoles, ACCESS_ROLE_KEYS, permissionDeniedError } from "../governance/rbac.js";
|
|
20
21
|
import { readProjectConfig, updateProjectConfigOverrides } from "../project-config.js";
|
|
21
22
|
import { buildConfigView } from "../config/resolve.js";
|
|
@@ -1009,7 +1010,6 @@ function handlePostSettingsMcpEnabled(req, res, url, ctx) {
|
|
|
1009
1010
|
}
|
|
1010
1011
|
function handleGetProfiles(res, ctx) {
|
|
1011
1012
|
try {
|
|
1012
|
-
const { listProfiles } = require("../profile-store.js");
|
|
1013
1013
|
const profileResult = listProfiles(ctx.phrenPath);
|
|
1014
1014
|
if (!profileResult.ok) {
|
|
1015
1015
|
return jsonOk(res, { ok: false, error: profileResult.error, profiles: [] });
|
|
@@ -1027,7 +1027,6 @@ function handlePostProfile(req, res, url, ctx) {
|
|
|
1027
1027
|
if (!profileName)
|
|
1028
1028
|
return jsonErr(res, "Profile name required", 400);
|
|
1029
1029
|
try {
|
|
1030
|
-
const { setMachineProfile, getDefaultMachineAlias } = require("../profile-store.js");
|
|
1031
1030
|
const machineAlias = getDefaultMachineAlias();
|
|
1032
1031
|
const result = setMachineProfile(ctx.phrenPath, machineAlias, profileName);
|
|
1033
1032
|
if (!result.ok)
|
|
@@ -1082,7 +1081,6 @@ function handlePostSettingsProjectOverrides(req, res, url, ctx) {
|
|
|
1082
1081
|
if (globalUpdate) {
|
|
1083
1082
|
try {
|
|
1084
1083
|
if (NUMERIC_RETENTION_FIELDS.includes(field)) {
|
|
1085
|
-
const { updateRetentionPolicy } = require("../governance/policy.js");
|
|
1086
1084
|
let updateData = {};
|
|
1087
1085
|
if (!clearField) {
|
|
1088
1086
|
const num = parseFloat(value);
|
|
@@ -1096,7 +1094,6 @@ function handlePostSettingsProjectOverrides(req, res, url, ctx) {
|
|
|
1096
1094
|
return jsonOk(res, { ok: true, retentionPolicy: result.data });
|
|
1097
1095
|
}
|
|
1098
1096
|
else if (field.startsWith("decay.")) {
|
|
1099
|
-
const { updateRetentionPolicy } = require("../governance/policy.js");
|
|
1100
1097
|
const point = field.slice("decay.".length);
|
|
1101
1098
|
let updateData = {};
|
|
1102
1099
|
if (!clearField) {
|
|
@@ -1118,7 +1115,6 @@ function handlePostSettingsProjectOverrides(req, res, url, ctx) {
|
|
|
1118
1115
|
return jsonOk(res, { ok: true, workflowPolicy: result.data });
|
|
1119
1116
|
}
|
|
1120
1117
|
else if (NUMERIC_WORKFLOW_FIELDS.includes(field)) {
|
|
1121
|
-
const { updateWorkflowPolicy } = require("../governance/policy.js");
|
|
1122
1118
|
let updateData = {};
|
|
1123
1119
|
if (!clearField) {
|
|
1124
1120
|
const num = parseFloat(value);
|
package/dist/utils-fts.js
CHANGED
|
@@ -3,7 +3,8 @@ import * as path from "path";
|
|
|
3
3
|
import * as yaml from "js-yaml";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
5
|
import { findPhrenPath } from "./phren-paths.js";
|
|
6
|
-
import { isValidProjectName
|
|
6
|
+
import { isValidProjectName } from "./utils-paths.js";
|
|
7
|
+
import { storeAwareProjectPath } from "./store-routing.js";
|
|
7
8
|
// Lazy import of logDebug to break circular dependency:
|
|
8
9
|
// utils.ts -> phren-paths.ts -> logger.ts -> phren-paths.ts -> utils.ts
|
|
9
10
|
let _logDebug;
|
|
@@ -184,7 +185,7 @@ function parseLearnedSynonymsJson(filePath) {
|
|
|
184
185
|
export function learnedSynonymsPath(phrenPath, project) {
|
|
185
186
|
if (!isValidProjectName(project))
|
|
186
187
|
return null;
|
|
187
|
-
return
|
|
188
|
+
return storeAwareProjectPath(phrenPath, project, LEARNED_SYNONYMS_FILE);
|
|
188
189
|
}
|
|
189
190
|
export function loadLearnedSynonyms(project, phrenPath) {
|
|
190
191
|
if (!project || !isValidProjectName(project))
|
package/dist/utils-paths.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export declare function isValidProjectName(name: string): boolean;
|
|
2
2
|
export declare function safeProjectPath(base: string, ...segments: string[]): string | null;
|
|
3
|
+
export declare const QUEUE_FILENAME = "review.md";
|
|
3
4
|
export declare function queueFilePath(phrenPath: string, project: string): string;
|
package/dist/utils-paths.js
CHANGED
|
@@ -48,7 +48,7 @@ export function safeProjectPath(base, ...segments) {
|
|
|
48
48
|
}
|
|
49
49
|
return resolved;
|
|
50
50
|
}
|
|
51
|
-
const QUEUE_FILENAME = "review.md";
|
|
51
|
+
export const QUEUE_FILENAME = "review.md";
|
|
52
52
|
export function queueFilePath(phrenPath, project) {
|
|
53
53
|
if (!isValidProjectName(project)) {
|
|
54
54
|
throw new Error(`Invalid project name: ${project}`);
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { runGitOrThrow, runGit, normalizeExecCommand, resolveExecCommand, errorMessage, isFeatureEnabled, clampInt, getOptionValue, getPositionalArgs, } from "./utils-helpers.js";
|
|
2
|
-
export { isValidProjectName, safeProjectPath, queueFilePath, } from "./utils-paths.js";
|
|
2
|
+
export { isValidProjectName, safeProjectPath, queueFilePath, QUEUE_FILENAME, } from "./utils-paths.js";
|
|
3
3
|
export { STOP_WORDS, extractKeywordEntries, extractKeywords, learnedSynonymsPath, loadLearnedSynonyms, loadSynonymMap, learnSynonym, removeLearnedSynonym, sanitizeFts5Query, buildRobustFtsQuery, buildRelaxedFtsQuery, buildFtsQueryVariants, } from "./utils-fts.js";
|
package/dist/utils.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
// helpers, argv parsing, exec helpers), utils-paths.ts (path validation),
|
|
3
3
|
// utils-fts.ts (FTS5 query building, synonym/keyword extraction).
|
|
4
4
|
export { runGitOrThrow, runGit, normalizeExecCommand, resolveExecCommand, errorMessage, isFeatureEnabled, clampInt, getOptionValue, getPositionalArgs, } from "./utils-helpers.js";
|
|
5
|
-
export { isValidProjectName, safeProjectPath, queueFilePath, } from "./utils-paths.js";
|
|
5
|
+
export { isValidProjectName, safeProjectPath, queueFilePath, QUEUE_FILENAME, } from "./utils-paths.js";
|
|
6
6
|
export { STOP_WORDS, extractKeywordEntries, extractKeywords, learnedSynonymsPath, loadLearnedSynonyms, loadSynonymMap, learnSynonym, removeLearnedSynonym, sanitizeFts5Query, buildRobustFtsQuery, buildRelaxedFtsQuery, buildFtsQueryVariants, } from "./utils-fts.js";
|