@phren/cli 0.1.31 → 0.1.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/capabilities/cli.js +2 -2
  2. package/dist/cli/config-access.d.ts +1 -0
  3. package/dist/cli/config-access.js +59 -0
  4. package/dist/cli/config-llm.d.ts +1 -0
  5. package/dist/cli/config-llm.js +60 -0
  6. package/dist/cli/config-policy.d.ts +11 -0
  7. package/dist/cli/config-policy.js +328 -0
  8. package/dist/cli/config-proactivity.d.ts +15 -0
  9. package/dist/cli/config-proactivity.js +129 -0
  10. package/dist/cli/config-shared.d.ts +6 -0
  11. package/dist/cli/config-shared.js +23 -0
  12. package/dist/cli/config-synonyms.d.ts +1 -0
  13. package/dist/cli/config-synonyms.js +60 -0
  14. package/dist/cli/config.d.ts +6 -24
  15. package/dist/cli/config.js +13 -670
  16. package/dist/finding-graph-id.d.ts +15 -0
  17. package/dist/finding-graph-id.js +58 -0
  18. package/dist/generated/memory-ui-graph.browser.js +15 -15
  19. package/dist/governance/activity.d.ts +36 -0
  20. package/dist/governance/activity.js +83 -0
  21. package/dist/governance/rbac.d.ts +17 -0
  22. package/dist/governance/rbac.js +37 -1
  23. package/dist/memory-ui-graph.runtime.js +15 -15
  24. package/dist/phren-paths.d.ts +6 -0
  25. package/dist/phren-paths.js +8 -0
  26. package/dist/shared/governance.d.ts +1 -0
  27. package/dist/shared/governance.js +1 -0
  28. package/dist/shared.d.ts +1 -1
  29. package/dist/shared.js +1 -1
  30. package/dist/tools/config.js +39 -2
  31. package/dist/tools/finding.js +5 -11
  32. package/dist/tools/search.js +28 -1
  33. package/dist/tools/tasks.js +3 -12
  34. package/dist/ui/data.d.ts +2 -0
  35. package/dist/ui/data.js +8 -3
  36. package/dist/ui/graph.js +2 -0
  37. package/dist/ui/page.js +45 -2
  38. package/dist/ui/scripts.d.ts +13 -0
  39. package/dist/ui/scripts.js +229 -2
  40. package/dist/ui/server.js +165 -1
  41. package/dist/ui/styles.d.ts +1 -0
  42. package/dist/ui/styles.js +38 -0
  43. package/package.json +1 -1
  44. package/dist/cli-hooks-prompt.d.ts +0 -18
  45. package/dist/cli-hooks-prompt.js +0 -359
  46. package/dist/cli-hooks-session-handlers.d.ts +0 -3
  47. package/dist/cli-hooks-session-handlers.js +0 -356
  48. package/dist/cli-hooks-stop.d.ts +0 -11
  49. package/dist/cli-hooks-stop.js +0 -584
  50. package/dist/init-bootstrap.d.ts +0 -5
  51. package/dist/init-bootstrap.js +0 -21
  52. package/dist/init-detect.d.ts +0 -8
  53. package/dist/init-detect.js +0 -38
  54. package/dist/init-env.d.ts +0 -6
  55. package/dist/init-env.js +0 -114
  56. package/dist/init-fresh.d.ts +0 -10
  57. package/dist/init-fresh.js +0 -234
  58. package/dist/init-hooks.d.ts +0 -5
  59. package/dist/init-hooks.js +0 -26
  60. package/dist/init-mcp.d.ts +0 -8
  61. package/dist/init-mcp.js +0 -65
  62. package/dist/init-modes.d.ts +0 -4
  63. package/dist/init-modes.js +0 -135
  64. package/dist/init-npm.d.ts +0 -10
  65. package/dist/init-npm.js +0 -37
  66. package/dist/init-project-local.d.ts +0 -2
  67. package/dist/init-project-local.js +0 -99
  68. package/dist/init-semantic.d.ts +0 -4
  69. package/dist/init-semantic.js +0 -48
  70. package/dist/init-types.d.ts +0 -59
  71. package/dist/init-types.js +0 -1
  72. package/dist/init-update.d.ts +0 -10
  73. package/dist/init-update.js +0 -96
@@ -1,54 +1,21 @@
1
1
  import { getPhrenPath, readRootManifest } from "../shared.js";
2
- import { installPreferencesFile } from "../phren-paths.js";
3
- import { getIndexPolicy, updateIndexPolicy, getRetentionPolicy, updateRetentionPolicy, getWorkflowPolicy, updateWorkflowPolicy, mergeConfig, VALID_TASK_MODES, VALID_FINDING_SENSITIVITY, } from "../shared/governance.js";
4
- import { listMachines as listMachinesStore, listProfiles as listProfilesStore, listProfiles } from "../data/access.js";
2
+ import { listMachines as listMachinesStore, listProfiles as listProfilesStore } from "../data/access.js";
5
3
  import { setTelemetryEnabled, getTelemetrySummary, resetTelemetry } from "../telemetry.js";
6
- import { governanceInstallPreferencesFile, readInstallPreferences, readGovernanceInstallPreferences, writeInstallPreferences, writeGovernanceInstallPreferences, } from "../init/preferences.js";
7
- import { PROACTIVITY_LEVELS, getProactivityLevel, getProactivityLevelForTask, getProactivityLevelForFindings, } from "../proactivity.js";
8
- import { PROJECT_OWNERSHIP_MODES, getProjectOwnershipDefault, parseProjectOwnershipMode, updateProjectConfigOverrides, readProjectConfig, writeProjectConfig, } from "../project-config.js";
9
- import * as fs from "fs";
10
4
  import * as path from "path";
11
5
  import { buildConfigView } from "../config/resolve.js";
12
6
  import { CONFIG_DOMAINS } from "../config/schema.js";
13
- import { isValidProjectName, learnedSynonymsPath, learnSynonym, loadLearnedSynonyms, removeLearnedSynonym, } from "../utils.js";
14
- // ── Shared helpers ────────────────────────────────────────────────────────────
15
- function parseProjectArg(args) {
16
- const project = args.find((a) => a.startsWith("--project="))?.slice("--project=".length)
17
- ?? (args.indexOf("--project") !== -1 ? args[args.indexOf("--project") + 1] : undefined);
18
- const rest = args.filter((a, i) => a !== "--project" && !a.startsWith("--project=") && args[i - 1] !== "--project");
19
- return { project, rest };
20
- }
21
- export function checkProjectInProfile(phrenPath, project) {
22
- const profiles = listProfiles(phrenPath);
23
- if (profiles.ok) {
24
- const registered = profiles.data.some((entry) => entry.projects.includes(project));
25
- if (!registered) {
26
- return `Warning: Project '${project}' not found in active profile. Run 'phren add /path/to/${project}' first.\n Config was written to ${phrenPath}/${project}/phren.project.yaml but won't be used until the project is registered.`;
27
- }
28
- }
29
- return null;
30
- }
31
- function warnIfUnregistered(phrenPath, project) {
32
- const warning = checkProjectInProfile(phrenPath, project);
33
- if (warning)
34
- console.error(warning);
35
- }
36
- export function buildProactivitySnapshot(phrenPath) {
37
- const prefs = readGovernanceInstallPreferences(phrenPath);
38
- return {
39
- path: governanceInstallPreferencesFile(phrenPath),
40
- configured: {
41
- proactivity: prefs.proactivity ?? null,
42
- proactivityFindings: prefs.proactivityFindings ?? null,
43
- proactivityTask: prefs.proactivityTask ?? null,
44
- },
45
- effective: {
46
- proactivity: getProactivityLevel(phrenPath),
47
- proactivityFindings: getProactivityLevelForFindings(phrenPath),
48
- proactivityTask: getProactivityLevelForTask(phrenPath),
49
- },
50
- };
51
- }
7
+ import { isValidProjectName } from "../utils.js";
8
+ import { parseProjectArg, checkProjectInProfile } from "./config-shared.js";
9
+ import { handleConfigProactivity, handleConfigProjectOwnership } from "./config-proactivity.js";
10
+ import { handleIndexPolicy, handleRetentionPolicy, handleWorkflowPolicy, handleConfigTaskMode, handleConfigFindingSensitivity, } from "./config-policy.js";
11
+ import { handleConfigLlm } from "./config-llm.js";
12
+ import { handleConfigAccess } from "./config-access.js";
13
+ import { handleConfigSynonyms } from "./config-synonyms.js";
14
+ // Re-export the public surface so external importers (cli-registry.ts, tools/config.ts,
15
+ // tests) keep resolving the same names from "./cli/config.js" after the split.
16
+ export { checkProjectInProfile, handleIndexPolicy, handleRetentionPolicy, handleWorkflowPolicy, handleConfigAccess };
17
+ export { buildProactivitySnapshot } from "./config-proactivity.js";
18
+ export { FINDING_SENSITIVITY_CONFIG } from "./config-policy.js";
52
19
  // ── Config show ───────────────────────────────────────────────────────────────
53
20
  function formatConfigValue(value) {
54
21
  if (value === undefined || value === null)
@@ -200,630 +167,6 @@ Subcommands:
200
167
  }
201
168
  }
202
169
  }
203
- function normalizeProactivityLevel(raw) {
204
- if (!raw)
205
- return undefined;
206
- const normalized = raw.trim().toLowerCase();
207
- return PROACTIVITY_LEVELS.includes(normalized)
208
- ? normalized
209
- : undefined;
210
- }
211
- function printProactivityUsage(subcommand) {
212
- console.error(`Usage: phren config ${subcommand} [high|medium|low]`);
213
- }
214
- function printSynonymsUsage() {
215
- console.error("Usage: phren config synonyms list <project>");
216
- console.error(" phren config synonyms add <project> <term> <syn1,syn2,...>");
217
- console.error(" phren config synonyms remove <project> <term> [syn1,syn2,...]");
218
- }
219
- function parseSynonymItems(raw) {
220
- if (!raw)
221
- return [];
222
- return raw
223
- .split(",")
224
- .map((item) => item.trim())
225
- .filter(Boolean);
226
- }
227
- function handleConfigSynonyms(args) {
228
- const phrenPath = getPhrenPath();
229
- let action = args[0] || "list";
230
- let project = args[1];
231
- if (action !== "list" && action !== "add" && action !== "remove" && isValidProjectName(action)) {
232
- project = action;
233
- action = "list";
234
- }
235
- if (!project || !isValidProjectName(project)) {
236
- printSynonymsUsage();
237
- process.exit(1);
238
- }
239
- if (action === "list") {
240
- console.log(JSON.stringify({
241
- project,
242
- path: learnedSynonymsPath(phrenPath, project),
243
- synonyms: loadLearnedSynonyms(project, phrenPath),
244
- }, null, 2));
245
- return;
246
- }
247
- if (action === "add") {
248
- const term = args[2];
249
- const synonyms = parseSynonymItems(args[3]);
250
- if (!term || synonyms.length === 0) {
251
- printSynonymsUsage();
252
- process.exit(1);
253
- }
254
- const updated = learnSynonym(phrenPath, project, term, synonyms);
255
- console.log(JSON.stringify({ project, term, synonyms: updated[term.toLowerCase()] ?? [], updated }, null, 2));
256
- return;
257
- }
258
- if (action === "remove") {
259
- const term = args[2];
260
- if (!term) {
261
- printSynonymsUsage();
262
- process.exit(1);
263
- }
264
- const updated = removeLearnedSynonym(phrenPath, project, term, parseSynonymItems(args[3]));
265
- console.log(JSON.stringify({ project, term: term.toLowerCase(), updated }, null, 2));
266
- return;
267
- }
268
- printSynonymsUsage();
269
- process.exit(1);
270
- }
271
- function handleConfigProactivity(subcommand, args) {
272
- const phrenPath = getPhrenPath();
273
- const { project: projectArg, rest: filteredArgs } = parseProjectArg(args);
274
- const value = filteredArgs[0];
275
- if (value === undefined) {
276
- if (projectArg) {
277
- if (!isValidProjectName(projectArg)) {
278
- console.error(`Invalid project name: "${projectArg}"`);
279
- process.exit(1);
280
- }
281
- const resolved = mergeConfig(phrenPath, projectArg);
282
- console.log(JSON.stringify({
283
- _project: projectArg,
284
- base: resolved.proactivity.base ?? null,
285
- findings: resolved.proactivity.findings ?? null,
286
- tasks: resolved.proactivity.tasks ?? null,
287
- }, null, 2));
288
- return;
289
- }
290
- console.log(JSON.stringify(buildProactivitySnapshot(phrenPath), null, 2));
291
- return;
292
- }
293
- if (filteredArgs.length !== 1) {
294
- printProactivityUsage(subcommand);
295
- process.exit(1);
296
- }
297
- const level = normalizeProactivityLevel(value);
298
- if (!level) {
299
- printProactivityUsage(subcommand);
300
- process.exit(1);
301
- }
302
- if (projectArg) {
303
- if (!isValidProjectName(projectArg)) {
304
- console.error(`Invalid project name: "${projectArg}"`);
305
- process.exit(1);
306
- }
307
- warnIfUnregistered(phrenPath, projectArg);
308
- const key = subcommand === "proactivity" ? "proactivity"
309
- : subcommand === "proactivity.findings" ? "proactivityFindings"
310
- : "proactivityTask";
311
- updateProjectConfigOverrides(phrenPath, projectArg, (current) => ({ ...current, [key]: level }));
312
- const resolved = mergeConfig(phrenPath, projectArg);
313
- console.log(JSON.stringify({
314
- _project: projectArg,
315
- base: resolved.proactivity.base ?? null,
316
- findings: resolved.proactivity.findings ?? null,
317
- tasks: resolved.proactivity.tasks ?? null,
318
- }, null, 2));
319
- return;
320
- }
321
- switch (subcommand) {
322
- case "proactivity":
323
- writeGovernanceInstallPreferences(phrenPath, { proactivity: level });
324
- break;
325
- case "proactivity.findings":
326
- writeGovernanceInstallPreferences(phrenPath, { proactivityFindings: level });
327
- break;
328
- case "proactivity.tasks":
329
- writeGovernanceInstallPreferences(phrenPath, { proactivityTask: level });
330
- break;
331
- }
332
- console.log(JSON.stringify(buildProactivitySnapshot(phrenPath), null, 2));
333
- }
334
- function projectOwnershipConfigSnapshot(phrenPath) {
335
- const prefs = readInstallPreferences(phrenPath);
336
- return {
337
- path: installPreferencesFile(phrenPath),
338
- configured: {
339
- projectOwnershipDefault: prefs.projectOwnershipDefault ?? null,
340
- },
341
- effective: {
342
- projectOwnershipDefault: getProjectOwnershipDefault(phrenPath),
343
- },
344
- };
345
- }
346
- function handleConfigProjectOwnership(args) {
347
- const phrenPath = getPhrenPath();
348
- const value = args[0];
349
- if (value === undefined) {
350
- console.log(JSON.stringify(projectOwnershipConfigSnapshot(phrenPath), null, 2));
351
- return;
352
- }
353
- if (args.length !== 1) {
354
- console.error(`Usage: phren config project-ownership [${PROJECT_OWNERSHIP_MODES.join("|")}]`);
355
- process.exit(1);
356
- }
357
- const ownership = parseProjectOwnershipMode(value);
358
- if (!ownership) {
359
- console.error(`Usage: phren config project-ownership [${PROJECT_OWNERSHIP_MODES.join("|")}]`);
360
- process.exit(1);
361
- }
362
- writeInstallPreferences(phrenPath, { projectOwnershipDefault: ownership });
363
- console.log(JSON.stringify(projectOwnershipConfigSnapshot(phrenPath), null, 2));
364
- }
365
- // ── Finding sensitivity config ────────────────────────────────────────────────
366
- export const FINDING_SENSITIVITY_CONFIG = {
367
- minimal: {
368
- sessionCap: 0,
369
- proactivityFindings: "low",
370
- agentInstruction: "Only save findings when the user explicitly asks you to remember something.",
371
- },
372
- conservative: {
373
- sessionCap: 3,
374
- proactivityFindings: "medium",
375
- agentInstruction: "Save decisions and pitfalls only — skip patterns and observations.",
376
- },
377
- balanced: {
378
- sessionCap: 10,
379
- proactivityFindings: "high",
380
- agentInstruction: "Save non-obvious patterns, decisions, pitfalls, and bugs worth remembering next session.",
381
- },
382
- aggressive: {
383
- sessionCap: 20,
384
- proactivityFindings: "high",
385
- agentInstruction: "Save everything worth remembering — err on the side of capturing.",
386
- },
387
- };
388
- function handleWorkflowField(args, opts) {
389
- const phrenPath = getPhrenPath();
390
- const { project: projectArg, rest: filteredArgs } = parseProjectArg(args);
391
- const action = filteredArgs[0];
392
- if (!action || action === "get") {
393
- if (projectArg) {
394
- if (!isValidProjectName(projectArg)) {
395
- console.error(`Invalid project name: "${projectArg}"`);
396
- process.exit(1);
397
- }
398
- const resolved = mergeConfig(phrenPath, projectArg);
399
- const value = opts.getProjectValue(resolved);
400
- console.log(JSON.stringify(opts.formatProjectOutput(projectArg, value), null, 2));
401
- return;
402
- }
403
- console.log(JSON.stringify(opts.getSnapshot(phrenPath), null, 2));
404
- return;
405
- }
406
- const applyValue = (value) => {
407
- if (projectArg) {
408
- if (!isValidProjectName(projectArg)) {
409
- console.error(`Invalid project name: "${projectArg}"`);
410
- process.exit(1);
411
- }
412
- warnIfUnregistered(phrenPath, projectArg);
413
- updateProjectConfigOverrides(phrenPath, projectArg, (current) => ({ ...current, [opts.projectOverrideKey]: value }));
414
- const resolved = mergeConfig(phrenPath, projectArg);
415
- const eff = opts.getProjectValue(resolved);
416
- console.log(JSON.stringify(opts.formatProjectOutput(projectArg, eff), null, 2));
417
- return;
418
- }
419
- const result = updateWorkflowPolicy(phrenPath, { [opts.workflowPatchKey]: value });
420
- if (!result.ok) {
421
- console.error(result.error);
422
- if (result.code === "PERMISSION_DENIED")
423
- process.exit(1);
424
- return;
425
- }
426
- console.log(JSON.stringify(opts.getSnapshot(phrenPath), null, 2));
427
- };
428
- if (action === "set") {
429
- const value = opts.normalize(filteredArgs[1]);
430
- if (!value) {
431
- console.error(`Usage: phren config ${opts.fieldName} set [${opts.validValues.join("|")}]`);
432
- process.exit(1);
433
- }
434
- return applyValue(value);
435
- }
436
- const value = opts.normalize(action);
437
- if (value)
438
- return applyValue(value);
439
- console.error(`Usage: phren config ${opts.fieldName} [--project <name>] [get|set <value>|<value>] — values: ${opts.validValues.join("|")}`);
440
- process.exit(1);
441
- }
442
- function normalizeFromList(raw, validValues) {
443
- if (!raw)
444
- return null;
445
- const lower = raw.trim().toLowerCase();
446
- return validValues.includes(lower) ? lower : null;
447
- }
448
- function handleConfigTaskMode(args) {
449
- handleWorkflowField(args, {
450
- fieldName: "task-mode",
451
- validValues: VALID_TASK_MODES,
452
- normalize: (raw) => normalizeFromList(raw, VALID_TASK_MODES),
453
- getSnapshot: (phrenPath) => ({ taskMode: getWorkflowPolicy(phrenPath).taskMode }),
454
- getProjectValue: (resolved) => resolved.taskMode,
455
- formatProjectOutput: (proj, value) => ({ _project: proj, taskMode: value }),
456
- workflowPatchKey: "taskMode",
457
- projectOverrideKey: "taskMode",
458
- });
459
- }
460
- function handleConfigFindingSensitivity(args) {
461
- handleWorkflowField(args, {
462
- fieldName: "finding-sensitivity",
463
- validValues: VALID_FINDING_SENSITIVITY,
464
- normalize: (raw) => normalizeFromList(raw, VALID_FINDING_SENSITIVITY),
465
- getSnapshot: (phrenPath) => {
466
- const policy = getWorkflowPolicy(phrenPath);
467
- const level = policy.findingSensitivity;
468
- return { level, ...FINDING_SENSITIVITY_CONFIG[level] };
469
- },
470
- getProjectValue: (resolved) => resolved.findingSensitivity,
471
- formatProjectOutput: (proj, value) => ({ _project: proj, level: value, ...FINDING_SENSITIVITY_CONFIG[value] }),
472
- workflowPatchKey: "findingSensitivity",
473
- projectOverrideKey: "findingSensitivity",
474
- });
475
- }
476
- // ── LLM config ───────────────────────────────────────────────────────────────
477
- const EXPENSIVE_MODEL_RE = /opus|sonnet|gpt-4(?!o-mini)/i;
478
- const DEFAULT_LLM_MODEL = "gpt-4o-mini / claude-haiku-4-5-20251001";
479
- function printSemanticCostNotice(model) {
480
- const effectiveModel = model || process.env.PHREN_LLM_MODEL || DEFAULT_LLM_MODEL;
481
- console.log(` Note: Each semantic check is ~80 input + ~5 output tokens (one call per 'maybe' pair, cached 24h).`);
482
- console.log(` Current model: ${effectiveModel}`);
483
- if (model && EXPENSIVE_MODEL_RE.test(model)) {
484
- console.log(` Warning: This model is 20x more expensive than Haiku for yes/no checks.`);
485
- console.log(` Consider: PHREN_LLM_MODEL=claude-haiku-4-5-20251001`);
486
- }
487
- }
488
- function llmConfigSnapshot() {
489
- return {
490
- model: process.env.PHREN_LLM_MODEL || null,
491
- endpoint: process.env.PHREN_LLM_ENDPOINT || null,
492
- keySet: Boolean(process.env.PHREN_LLM_KEY || process.env.ANTHROPIC_API_KEY || process.env.OPENAI_API_KEY),
493
- note: `Set via environment variables. Each semantic check: ~80 input + ~5 output tokens. Default model: ${DEFAULT_LLM_MODEL}.`,
494
- };
495
- }
496
- function handleConfigLlm(args) {
497
- const action = args[0];
498
- if (!action || action === "get") {
499
- const snapshot = llmConfigSnapshot();
500
- console.log(JSON.stringify(snapshot, null, 2));
501
- const model = process.env.PHREN_LLM_MODEL;
502
- if (model && EXPENSIVE_MODEL_RE.test(model)) {
503
- process.stderr.write(`\nWarning: PHREN_LLM_MODEL=${model} is expensive for yes/no semantic checks.\n`);
504
- process.stderr.write(`Consider: PHREN_LLM_MODEL=claude-haiku-4-5-20251001\n`);
505
- }
506
- return;
507
- }
508
- if (action === "set") {
509
- const key = args[1];
510
- const value = args[2];
511
- if (!key || !value) {
512
- console.error("Usage: phren config llm set model <name>");
513
- console.error(" phren config llm set endpoint <url>");
514
- console.error(" phren config llm set key <api-key>");
515
- process.exit(1);
516
- }
517
- const envMap = {
518
- model: "PHREN_LLM_MODEL",
519
- endpoint: "PHREN_LLM_ENDPOINT",
520
- key: "PHREN_LLM_KEY",
521
- };
522
- const envVar = envMap[key];
523
- if (!envVar) {
524
- console.error(`Unknown setting "${key}". Valid: model, endpoint, key`);
525
- process.exit(1);
526
- }
527
- console.log(`Set ${envVar}=${value} in your shell or ~/.phren/.env`);
528
- if (key === "model") {
529
- printSemanticCostNotice(value);
530
- }
531
- return;
532
- }
533
- console.error("Usage: phren config llm [get|set model <name>|set endpoint <url>|set key <api-key>]");
534
- process.exit(1);
535
- }
536
- // ── Index policy ─────────────────────────────────────────────────────────────
537
- export async function handleIndexPolicy(args) {
538
- if (!args.length || args[0] === "get") {
539
- console.log(JSON.stringify(getIndexPolicy(getPhrenPath()), null, 2));
540
- return;
541
- }
542
- if (args[0] === "set") {
543
- const patch = {};
544
- for (const arg of args.slice(1)) {
545
- if (!arg.startsWith("--"))
546
- continue;
547
- const [k, v] = arg.slice(2).split("=");
548
- if (!k || v === undefined)
549
- continue;
550
- if (k === "include") {
551
- patch.includeGlobs = v.split(",").map((s) => s.trim()).filter(Boolean);
552
- }
553
- else if (k === "exclude") {
554
- patch.excludeGlobs = v.split(",").map((s) => s.trim()).filter(Boolean);
555
- }
556
- else if (k === "includeHidden") {
557
- patch.includeHidden = /^(1|true|yes|on)$/i.test(v);
558
- }
559
- }
560
- const result = updateIndexPolicy(getPhrenPath(), patch);
561
- if (!result.ok) {
562
- console.error(result.error);
563
- if (result.code === "PERMISSION_DENIED")
564
- process.exit(1);
565
- return;
566
- }
567
- console.log(JSON.stringify(result.data, null, 2));
568
- return;
569
- }
570
- console.error("Usage: phren index-policy [get|set --include=**/*.md,**/skills/**/*.md,.claude/skills/**/*.md --exclude=**/node_modules/**,**/.git/** --includeHidden=false]");
571
- process.exit(1);
572
- }
573
- // ── Memory policy ────────────────────────────────────────────────────────────
574
- export async function handleRetentionPolicy(args) {
575
- const phrenPath = getPhrenPath();
576
- const { project: projectArg, rest: filteredArgs } = parseProjectArg(args);
577
- if (!filteredArgs.length || filteredArgs[0] === "get") {
578
- if (projectArg) {
579
- if (!isValidProjectName(projectArg)) {
580
- console.error(`Invalid project name: "${projectArg}"`);
581
- process.exit(1);
582
- }
583
- const resolved = mergeConfig(phrenPath, projectArg);
584
- console.log(JSON.stringify({ _project: projectArg, ...resolved.retentionPolicy }, null, 2));
585
- return;
586
- }
587
- console.log(JSON.stringify(getRetentionPolicy(phrenPath), null, 2));
588
- const conflictOn = process.env.PHREN_FEATURE_SEMANTIC_CONFLICT === "1";
589
- process.stderr.write(`\nDedup: free Jaccard similarity scan on every add_finding (no API key needed).\n`);
590
- process.stderr.write(` Near-matches (30–55% overlap) are returned in the response for the agent to decide.\n`);
591
- if (conflictOn) {
592
- process.stderr.write(`\nConflict detection (PHREN_FEATURE_SEMANTIC_CONFLICT=1): active.\n`);
593
- process.stderr.write(` Uses an LLM for batch conflict checks. See: phren config llm\n`);
594
- }
595
- else {
596
- process.stderr.write(`\nConflict detection: disabled (set PHREN_FEATURE_SEMANTIC_CONFLICT=1 to enable for batch ops).\n`);
597
- process.stderr.write(` LLM needed only for batch operations (phren maintain consolidate/extract).\n`);
598
- }
599
- return;
600
- }
601
- if (filteredArgs[0] === "set") {
602
- if (projectArg) {
603
- if (!isValidProjectName(projectArg)) {
604
- console.error(`Invalid project name: "${projectArg}"`);
605
- process.exit(1);
606
- }
607
- warnIfUnregistered(phrenPath, projectArg);
608
- updateProjectConfigOverrides(phrenPath, projectArg, (current) => {
609
- const existingRetention = current.retentionPolicy ?? {};
610
- const retentionPatch = { ...existingRetention };
611
- for (const arg of filteredArgs.slice(1)) {
612
- if (!arg.startsWith("--"))
613
- continue;
614
- const [k, v] = arg.slice(2).split("=");
615
- if (!k || v === undefined)
616
- continue;
617
- const num = Number(v);
618
- const value = Number.isNaN(num) ? v : num;
619
- if (k.startsWith("decay.")) {
620
- retentionPatch.decay = { ...(retentionPatch.decay ?? {}) };
621
- retentionPatch.decay[k.slice("decay.".length)] = value;
622
- }
623
- else {
624
- retentionPatch[k] = value;
625
- }
626
- }
627
- return { ...current, retentionPolicy: retentionPatch };
628
- });
629
- const resolved = mergeConfig(phrenPath, projectArg);
630
- console.log(JSON.stringify({ _project: projectArg, ...resolved.retentionPolicy }, null, 2));
631
- return;
632
- }
633
- const patch = {};
634
- for (const arg of filteredArgs.slice(1)) {
635
- if (!arg.startsWith("--"))
636
- continue;
637
- const [k, v] = arg.slice(2).split("=");
638
- if (!k || v === undefined)
639
- continue;
640
- const num = Number(v);
641
- const value = Number.isNaN(num) ? v : num;
642
- if (k.startsWith("decay.")) {
643
- patch.decay = patch.decay || {};
644
- patch.decay[k.slice("decay.".length)] = value;
645
- }
646
- else {
647
- patch[k] = value;
648
- }
649
- }
650
- const result = updateRetentionPolicy(phrenPath, patch);
651
- if (!result.ok) {
652
- console.error(result.error);
653
- if (result.code === "PERMISSION_DENIED")
654
- process.exit(1);
655
- return;
656
- }
657
- console.log(JSON.stringify(result.data, null, 2));
658
- return;
659
- }
660
- console.error("Usage: phren config policy [--project <name>] [get|set --ttlDays=120 --retentionDays=365 --autoAcceptThreshold=0.75 --minInjectConfidence=0.35 --decay.d30=1 --decay.d60=0.85 --decay.d90=0.65 --decay.d120=0.45]");
661
- process.exit(1);
662
- }
663
- // ── Memory workflow ──────────────────────────────────────────────────────────
664
- export async function handleWorkflowPolicy(args) {
665
- const phrenPath = getPhrenPath();
666
- const { project: projectArg, rest: filteredArgs } = parseProjectArg(args);
667
- if (!filteredArgs.length || filteredArgs[0] === "get") {
668
- if (projectArg) {
669
- if (!isValidProjectName(projectArg)) {
670
- console.error(`Invalid project name: "${projectArg}"`);
671
- process.exit(1);
672
- }
673
- const resolved = mergeConfig(phrenPath, projectArg);
674
- console.log(JSON.stringify({ _project: projectArg, ...resolved.workflowPolicy }, null, 2));
675
- return;
676
- }
677
- console.log(JSON.stringify(getWorkflowPolicy(phrenPath), null, 2));
678
- return;
679
- }
680
- if (filteredArgs[0] === "set") {
681
- if (projectArg) {
682
- if (!isValidProjectName(projectArg)) {
683
- console.error(`Invalid project name: "${projectArg}"`);
684
- process.exit(1);
685
- }
686
- warnIfUnregistered(phrenPath, projectArg);
687
- updateProjectConfigOverrides(phrenPath, projectArg, (current) => {
688
- const nextConfig = { ...current };
689
- const existingWorkflow = current.workflowPolicy ?? {};
690
- const workflowPatch = { ...existingWorkflow };
691
- for (const arg of filteredArgs.slice(1)) {
692
- if (!arg.startsWith("--"))
693
- continue;
694
- const [k, v] = arg.slice(2).split("=");
695
- if (!k || v === undefined)
696
- continue;
697
- if (k === "riskySections") {
698
- workflowPatch.riskySections = v.split(",").map((s) => s.trim()).filter(Boolean);
699
- }
700
- else if (k === "taskMode") {
701
- nextConfig.taskMode = v;
702
- }
703
- else if (k === "findingSensitivity") {
704
- nextConfig.findingSensitivity = v;
705
- }
706
- else {
707
- const num = Number(v);
708
- workflowPatch[k] = Number.isNaN(num) ? v : num;
709
- }
710
- }
711
- if (Object.keys(workflowPatch).length > 0 || existingWorkflow !== current.workflowPolicy) {
712
- nextConfig.workflowPolicy = workflowPatch;
713
- }
714
- return nextConfig;
715
- });
716
- const resolved = mergeConfig(phrenPath, projectArg);
717
- console.log(JSON.stringify({ _project: projectArg, ...resolved.workflowPolicy }, null, 2));
718
- return;
719
- }
720
- const patch = {};
721
- for (const arg of filteredArgs.slice(1)) {
722
- if (!arg.startsWith("--"))
723
- continue;
724
- const [k, v] = arg.slice(2).split("=");
725
- if (!k || v === undefined)
726
- continue;
727
- if (k === "riskySections") {
728
- patch.riskySections = v.split(",").map((s) => s.trim()).filter(Boolean);
729
- }
730
- else {
731
- const num = Number(v);
732
- patch[k] = Number.isNaN(num) ? v : num;
733
- }
734
- }
735
- const result = updateWorkflowPolicy(phrenPath, patch);
736
- if (!result.ok) {
737
- console.log(result.error);
738
- if (result.code === "PERMISSION_DENIED")
739
- process.exit(1);
740
- return;
741
- }
742
- console.log(JSON.stringify(result.data, null, 2));
743
- return;
744
- }
745
- console.error("Usage: phren config workflow [--project <name>] [get|set --lowConfidenceThreshold=0.7 --riskySections=Stale,Conflicts --taskMode=manual]");
746
- process.exit(1);
747
- }
748
- // ── Access control ───────────────────────────────────────────────────────────
749
- const ACCESS_ROLES = ["admins", "contributors", "readers"];
750
- function globalAccessFile(phrenPath) {
751
- return path.join(phrenPath, ".config", "access-control.json");
752
- }
753
- function readGlobalAccess(phrenPath) {
754
- const file = globalAccessFile(phrenPath);
755
- if (!fs.existsSync(file))
756
- return {};
757
- try {
758
- const parsed = JSON.parse(fs.readFileSync(file, "utf8"));
759
- return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
760
- }
761
- catch {
762
- return {};
763
- }
764
- }
765
- function parseRoleList(raw) {
766
- return raw.split(",").map((s) => s.trim()).filter(Boolean);
767
- }
768
- function printAccessSnapshot(phrenPath, projectArg) {
769
- const view = buildConfigView(phrenPath, projectArg);
770
- console.log(JSON.stringify({
771
- _project: projectArg ?? null,
772
- _note: "Effective lists are the union of global and per-project roles. All lists empty everywhere = open mode.",
773
- admins: view.fields["access.admins"].value,
774
- contributors: view.fields["access.contributors"].value,
775
- readers: view.fields["access.readers"].value,
776
- }, null, 2));
777
- }
778
- export function handleConfigAccess(args) {
779
- const phrenPath = getPhrenPath();
780
- const { project: projectArg, rest } = parseProjectArg(args);
781
- const action = rest[0];
782
- if (projectArg && !isValidProjectName(projectArg)) {
783
- console.error(`Invalid project name: "${projectArg}"`);
784
- process.exit(1);
785
- }
786
- if (!action || action === "get") {
787
- printAccessSnapshot(phrenPath, projectArg);
788
- return;
789
- }
790
- if (action === "set") {
791
- const patch = {};
792
- let touched = false;
793
- for (const arg of rest.slice(1)) {
794
- if (!arg.startsWith("--"))
795
- continue;
796
- const [k, v] = arg.slice(2).split("=");
797
- if (!k || v === undefined)
798
- continue;
799
- if (ACCESS_ROLES.includes(k)) {
800
- patch[k] = parseRoleList(v);
801
- touched = true;
802
- }
803
- }
804
- if (!touched) {
805
- console.error("Usage: phren config access [--project <name>] set --admins=a,b --contributors=c --readers=d");
806
- process.exit(1);
807
- }
808
- if (projectArg) {
809
- warnIfUnregistered(phrenPath, projectArg);
810
- const current = readProjectConfig(phrenPath, projectArg);
811
- writeProjectConfig(phrenPath, projectArg, {
812
- access: { ...(current.access ?? {}), ...patch },
813
- });
814
- }
815
- else {
816
- const next = { ...readGlobalAccess(phrenPath), ...patch };
817
- const file = globalAccessFile(phrenPath);
818
- fs.mkdirSync(path.dirname(file), { recursive: true });
819
- fs.writeFileSync(file, JSON.stringify(next, null, 2) + "\n");
820
- }
821
- printAccessSnapshot(phrenPath, projectArg);
822
- return;
823
- }
824
- console.error("Usage: phren config access [--project <name>] [get|set --admins=a,b --contributors=c --readers=d]");
825
- process.exit(1);
826
- }
827
170
  // ── Machines and profiles ────────────────────────────────────────────────────
828
171
  function handleConfigMachines() {
829
172
  const manifest = readRootManifest(getPhrenPath());