@phren/cli 0.1.30 → 0.1.32

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.
@@ -0,0 +1,498 @@
1
+ /**
2
+ * Shared config schema — the single source of truth every surface renders from.
3
+ *
4
+ * The CLI (`phren config`), the Web UI settings tab, and the VS Code settings
5
+ * webview all import these descriptors so their labels, help text, option lists,
6
+ * defaults, and ranges can never drift apart.
7
+ *
8
+ * Each field is a {@link ConfigFieldDescriptor}; fields are grouped into the
9
+ * eight {@link CONFIG_DOMAINS}. Nothing here renders UI — descriptors are pure
10
+ * data so every surface can present them in its own idiom.
11
+ */
12
+ import { DEFAULT_POLICY, DEFAULT_WORKFLOW_POLICY, DEFAULT_INDEX_POLICY, } from "../governance/policy.js";
13
+ // ── Reusable option lists ─────────────────────────────────────────────────────
14
+ const PROACTIVITY_OPTIONS = [
15
+ {
16
+ value: "high",
17
+ label: "High",
18
+ blurb: "The agent auto-captures eagerly without waiting for an explicit ask.",
19
+ recommended: true,
20
+ },
21
+ {
22
+ value: "medium",
23
+ label: "Medium",
24
+ blurb: "The agent only auto-captures when your message has an explicit signal (e.g. \"remember this\").",
25
+ },
26
+ {
27
+ value: "low",
28
+ label: "Low",
29
+ blurb: "The agent never auto-captures — you drive every save yourself.",
30
+ },
31
+ ];
32
+ // ── Domain definitions ────────────────────────────────────────────────────────
33
+ export const CONFIG_DOMAINS = [
34
+ {
35
+ id: "proactivity",
36
+ label: "Proactivity",
37
+ icon: "pulse",
38
+ summary: "How eagerly the agent acts on its own to capture memory.",
39
+ scope: "global+project",
40
+ fields: [
41
+ {
42
+ key: "proactivity.base",
43
+ domain: "proactivity",
44
+ label: "Base proactivity",
45
+ summary: "Master auto-capture level for both findings and tasks.",
46
+ help: "Sets the default eagerness for everything the agent captures without being asked. "
47
+ + "Findings and tasks each inherit this unless you override them below.",
48
+ control: "enum",
49
+ options: PROACTIVITY_OPTIONS,
50
+ default: "high",
51
+ scope: "global+project",
52
+ impact: "Higher = more memories saved automatically; lower = you stay fully in control.",
53
+ risk: "safe",
54
+ },
55
+ {
56
+ key: "proactivity.findings",
57
+ domain: "proactivity",
58
+ label: "Findings proactivity",
59
+ summary: "Auto-capture level for findings specifically.",
60
+ help: "Overrides the base level just for findings (insights, decisions, pitfalls). "
61
+ + "Leave unset to inherit the base level.",
62
+ control: "enum",
63
+ options: PROACTIVITY_OPTIONS,
64
+ default: "high",
65
+ scope: "global+project",
66
+ impact: "Controls how often the agent writes to FINDINGS.md on its own.",
67
+ risk: "safe",
68
+ },
69
+ {
70
+ key: "proactivity.tasks",
71
+ domain: "proactivity",
72
+ label: "Tasks proactivity",
73
+ summary: "Auto-capture level for tasks specifically.",
74
+ help: "Overrides the base level just for tasks. Leave unset to inherit the base level.",
75
+ control: "enum",
76
+ options: PROACTIVITY_OPTIONS,
77
+ default: "high",
78
+ scope: "global+project",
79
+ impact: "Controls how often the agent adds items to tasks.md on its own.",
80
+ risk: "safe",
81
+ },
82
+ ],
83
+ },
84
+ {
85
+ id: "taskMode",
86
+ label: "Task mode",
87
+ icon: "checklist",
88
+ summary: "How much authority the agent has over your task list.",
89
+ scope: "global+project",
90
+ fields: [
91
+ {
92
+ key: "taskMode",
93
+ domain: "taskMode",
94
+ label: "Task mode",
95
+ summary: "What the agent is allowed to do with tasks.",
96
+ help: "Governs whether the agent may create, complete, and reorder tasks for you, "
97
+ + "or whether task management stays entirely in your hands.",
98
+ control: "enum",
99
+ options: [
100
+ {
101
+ value: "auto",
102
+ label: "Auto",
103
+ blurb: "The agent freely creates, updates, and completes tasks as work progresses.",
104
+ recommended: true,
105
+ },
106
+ {
107
+ value: "suggest",
108
+ label: "Suggest",
109
+ blurb: "The agent proposes task changes but waits for you to confirm.",
110
+ },
111
+ {
112
+ value: "manual",
113
+ label: "Manual",
114
+ blurb: "Only you create and change tasks; the agent never touches them.",
115
+ },
116
+ {
117
+ value: "off",
118
+ label: "Off",
119
+ blurb: "Task tracking is disabled entirely.",
120
+ },
121
+ ],
122
+ default: DEFAULT_WORKFLOW_POLICY.taskMode,
123
+ scope: "global+project",
124
+ impact: "`off` hides the task system completely; `auto` lets the agent run it.",
125
+ risk: "caution",
126
+ },
127
+ ],
128
+ },
129
+ {
130
+ id: "findingSensitivity",
131
+ label: "Finding sensitivity",
132
+ icon: "lightbulb",
133
+ summary: "How selective the agent is about what counts as worth remembering.",
134
+ scope: "global+project",
135
+ fields: [
136
+ {
137
+ key: "findingSensitivity",
138
+ domain: "findingSensitivity",
139
+ label: "Finding sensitivity",
140
+ summary: "The bar for what the agent saves as a finding.",
141
+ help: "Sets both the per-session cap on auto-captured findings and the instruction the "
142
+ + "agent follows about what is worth keeping.",
143
+ control: "enum",
144
+ options: [
145
+ {
146
+ value: "minimal",
147
+ label: "Minimal",
148
+ blurb: "Only save findings when the user explicitly asks you to remember something.",
149
+ },
150
+ {
151
+ value: "conservative",
152
+ label: "Conservative",
153
+ blurb: "Save decisions and pitfalls only — skip patterns and observations.",
154
+ },
155
+ {
156
+ value: "balanced",
157
+ label: "Balanced",
158
+ blurb: "Save non-obvious patterns, decisions, pitfalls, and bugs worth remembering next session.",
159
+ recommended: true,
160
+ },
161
+ {
162
+ value: "aggressive",
163
+ label: "Aggressive",
164
+ blurb: "Save everything worth remembering — err on the side of capturing.",
165
+ },
166
+ ],
167
+ default: DEFAULT_WORKFLOW_POLICY.findingSensitivity,
168
+ scope: "global+project",
169
+ impact: "Higher = more findings per session (cap 0/3/10/20), larger context injection, more noise.",
170
+ risk: "safe",
171
+ },
172
+ ],
173
+ },
174
+ {
175
+ id: "retention",
176
+ label: "Retention",
177
+ icon: "archive",
178
+ summary: "How long memory lives and how its confidence decays over time.",
179
+ scope: "global+project",
180
+ fields: [
181
+ {
182
+ key: "retention.ttlDays",
183
+ domain: "retention",
184
+ label: "TTL (days)",
185
+ summary: "Age at which a memory becomes eligible for pruning review.",
186
+ help: "Findings older than this are considered for cleanup during consolidation. "
187
+ + "It does not delete anything by itself.",
188
+ control: "number",
189
+ range: { min: 7, max: 3650, step: 1 },
190
+ default: DEFAULT_POLICY.ttlDays,
191
+ scope: "global+project",
192
+ impact: "Lower = memory turns over faster; higher = old findings linger longer.",
193
+ risk: "safe",
194
+ },
195
+ {
196
+ key: "retention.retentionDays",
197
+ domain: "retention",
198
+ label: "Retention (days)",
199
+ summary: "Hard age cutoff — findings past this are pruned.",
200
+ help: "The maximum age a finding can reach before `phren maintain prune` removes it. "
201
+ + "Shrinking this can permanently drop old memory.",
202
+ control: "number",
203
+ range: { min: 30, max: 3650, step: 1 },
204
+ default: DEFAULT_POLICY.retentionDays,
205
+ scope: "global+project",
206
+ impact: "Lowering this deletes findings older than the new cutoff on the next prune.",
207
+ risk: "caution",
208
+ },
209
+ {
210
+ key: "retention.autoAcceptThreshold",
211
+ domain: "retention",
212
+ label: "Auto-accept threshold",
213
+ summary: "Confidence score above which a finding skips the review queue.",
214
+ help: "Findings scoring at or above this go straight in; lower-scoring ones land in the "
215
+ + "review queue for you to approve.",
216
+ control: "number",
217
+ range: { min: 0, max: 1, step: 0.05 },
218
+ default: DEFAULT_POLICY.autoAcceptThreshold,
219
+ scope: "global+project",
220
+ impact: "Higher = more findings routed to manual review; lower = more auto-accepted.",
221
+ risk: "safe",
222
+ },
223
+ {
224
+ key: "retention.minInjectConfidence",
225
+ domain: "retention",
226
+ label: "Min inject confidence",
227
+ summary: "Lowest confidence a finding may have to be injected into context.",
228
+ help: "Findings scoring below this are kept on disk but not surfaced into the agent's "
229
+ + "context automatically.",
230
+ control: "number",
231
+ range: { min: 0, max: 1, step: 0.05 },
232
+ default: DEFAULT_POLICY.minInjectConfidence,
233
+ scope: "global+project",
234
+ impact: "Higher = only strong memories get injected; lower = weaker ones surface too.",
235
+ risk: "safe",
236
+ },
237
+ {
238
+ key: "retention.decay.d30",
239
+ domain: "retention",
240
+ label: "Decay @ 30 days",
241
+ summary: "Confidence multiplier applied to a finding 30 days old.",
242
+ help: "Part of the decay curve — how much a 30-day-old finding's confidence is scaled.",
243
+ control: "number",
244
+ range: { min: 0, max: 1, step: 0.05 },
245
+ default: DEFAULT_POLICY.decay.d30,
246
+ scope: "global+project",
247
+ impact: "Lower values make recent memory fade faster.",
248
+ risk: "safe",
249
+ },
250
+ {
251
+ key: "retention.decay.d60",
252
+ domain: "retention",
253
+ label: "Decay @ 60 days",
254
+ summary: "Confidence multiplier applied to a finding 60 days old.",
255
+ help: "Part of the decay curve — how much a 60-day-old finding's confidence is scaled.",
256
+ control: "number",
257
+ range: { min: 0, max: 1, step: 0.05 },
258
+ default: DEFAULT_POLICY.decay.d60,
259
+ scope: "global+project",
260
+ impact: "Lower values make mid-age memory fade faster.",
261
+ risk: "safe",
262
+ },
263
+ {
264
+ key: "retention.decay.d90",
265
+ domain: "retention",
266
+ label: "Decay @ 90 days",
267
+ summary: "Confidence multiplier applied to a finding 90 days old.",
268
+ help: "Part of the decay curve — how much a 90-day-old finding's confidence is scaled.",
269
+ control: "number",
270
+ range: { min: 0, max: 1, step: 0.05 },
271
+ default: DEFAULT_POLICY.decay.d90,
272
+ scope: "global+project",
273
+ impact: "Lower values make older memory fade faster.",
274
+ risk: "safe",
275
+ },
276
+ {
277
+ key: "retention.decay.d120",
278
+ domain: "retention",
279
+ label: "Decay @ 120 days",
280
+ summary: "Confidence multiplier applied to a finding 120 days old.",
281
+ help: "Part of the decay curve — how much a 120-day-old finding's confidence is scaled.",
282
+ control: "number",
283
+ range: { min: 0, max: 1, step: 0.05 },
284
+ default: DEFAULT_POLICY.decay.d120,
285
+ scope: "global+project",
286
+ impact: "Lower values make stale memory fade faster.",
287
+ risk: "safe",
288
+ },
289
+ ],
290
+ },
291
+ {
292
+ id: "workflow",
293
+ label: "Workflow",
294
+ icon: "settings-gear",
295
+ summary: "Review gating and which memory sections are treated as risky.",
296
+ scope: "global+project",
297
+ fields: [
298
+ {
299
+ key: "workflow.lowConfidenceThreshold",
300
+ domain: "workflow",
301
+ label: "Low-confidence threshold",
302
+ summary: "Score below which a finding is flagged as low-confidence.",
303
+ help: "Findings scoring under this are treated as low-confidence and may be routed to the "
304
+ + "review queue rather than accepted silently.",
305
+ control: "number",
306
+ range: { min: 0, max: 1, step: 0.05 },
307
+ default: DEFAULT_WORKFLOW_POLICY.lowConfidenceThreshold,
308
+ scope: "global+project",
309
+ impact: "Higher = more findings flagged for review; lower = fewer flagged.",
310
+ risk: "safe",
311
+ },
312
+ {
313
+ key: "workflow.riskySections",
314
+ domain: "workflow",
315
+ label: "Risky sections",
316
+ summary: "Review-queue sections that require explicit attention.",
317
+ help: "Findings landing in these sections are surfaced for review instead of being "
318
+ + "treated as settled. Choose any of Review, Stale, Conflicts.",
319
+ control: "string-list",
320
+ options: [
321
+ { value: "Review", label: "Review", blurb: "Items explicitly queued for your review." },
322
+ { value: "Stale", label: "Stale", blurb: "Findings that have aged past their TTL." },
323
+ { value: "Conflicts", label: "Conflicts", blurb: "Findings that contradict another finding." },
324
+ ],
325
+ default: DEFAULT_WORKFLOW_POLICY.riskySections,
326
+ scope: "global+project",
327
+ impact: "More sections = more findings held back for explicit attention.",
328
+ risk: "safe",
329
+ },
330
+ ],
331
+ },
332
+ {
333
+ id: "index",
334
+ label: "Index",
335
+ icon: "search",
336
+ summary: "Which files the search indexer reads.",
337
+ scope: "global-only",
338
+ fields: [
339
+ {
340
+ key: "index.includeGlobs",
341
+ domain: "index",
342
+ label: "Include globs",
343
+ summary: "Glob patterns the indexer reads.",
344
+ help: "Files matching any of these globs are indexed for search. Removing a pattern hides "
345
+ + "those files from search until the next reindex.",
346
+ control: "string-list",
347
+ default: DEFAULT_INDEX_POLICY.includeGlobs,
348
+ scope: "global-only",
349
+ impact: "Narrowing this shrinks what search and context injection can find.",
350
+ risk: "caution",
351
+ },
352
+ {
353
+ key: "index.excludeGlobs",
354
+ domain: "index",
355
+ label: "Exclude globs",
356
+ summary: "Glob patterns the indexer skips.",
357
+ help: "Files matching any of these globs are never indexed, even if they match an include "
358
+ + "pattern. Excludes win over includes.",
359
+ control: "string-list",
360
+ default: DEFAULT_INDEX_POLICY.excludeGlobs,
361
+ scope: "global-only",
362
+ impact: "Adding a pattern removes those files from search on the next reindex.",
363
+ risk: "caution",
364
+ },
365
+ {
366
+ key: "index.includeHidden",
367
+ domain: "index",
368
+ label: "Index hidden files",
369
+ summary: "Whether dotfiles and dot-directories are indexed.",
370
+ help: "When on, files and folders beginning with `.` are eligible for indexing.",
371
+ control: "boolean",
372
+ default: DEFAULT_INDEX_POLICY.includeHidden,
373
+ scope: "global-only",
374
+ impact: "Turning this on can pull in `.config` and similar files.",
375
+ risk: "caution",
376
+ },
377
+ ],
378
+ },
379
+ {
380
+ id: "topic",
381
+ label: "Topics",
382
+ icon: "symbol-namespace",
383
+ summary: "Per-project topic classification for routing findings.",
384
+ scope: "project-only",
385
+ fields: [
386
+ {
387
+ key: "topic.domain",
388
+ domain: "topic",
389
+ label: "Project domain",
390
+ summary: "The high-level domain this project belongs to.",
391
+ help: "A coarse classification (e.g. backend, frontend, data) used to tune how findings "
392
+ + "are organised for this project.",
393
+ control: "string-list",
394
+ default: null,
395
+ scope: "project-only",
396
+ impact: "Affects how new findings are routed into topic files.",
397
+ risk: "safe",
398
+ },
399
+ {
400
+ key: "topic.topics",
401
+ domain: "topic",
402
+ label: "Topics",
403
+ summary: "Named topics findings are bucketed into for this project.",
404
+ help: "Each topic has a slug, a label, an optional description, and keywords used to "
405
+ + "match findings to it.",
406
+ control: "object",
407
+ default: [],
408
+ scope: "project-only",
409
+ impact: "Editing topics changes how this project's findings are grouped.",
410
+ risk: "safe",
411
+ },
412
+ ],
413
+ },
414
+ {
415
+ id: "access",
416
+ label: "Access control",
417
+ icon: "shield",
418
+ summary: "Role-based permissions over who can read and write memory.",
419
+ scope: "global+project",
420
+ fields: [
421
+ {
422
+ key: "access.admins",
423
+ domain: "access",
424
+ label: "Admins",
425
+ summary: "Actors allowed every action, including config changes.",
426
+ help: "Actor names (matched against PHREN_ACTOR) with full permissions. "
427
+ + "When all three role lists are empty, phren runs in open mode.",
428
+ control: "string-list",
429
+ default: [],
430
+ scope: "global+project",
431
+ impact: "Admins can change config and manage findings, tasks, and access itself.",
432
+ risk: "caution",
433
+ },
434
+ {
435
+ key: "access.contributors",
436
+ domain: "access",
437
+ label: "Contributors",
438
+ summary: "Actors allowed to add and edit findings and tasks.",
439
+ help: "Actor names with read-write access to findings and tasks but not config.",
440
+ control: "string-list",
441
+ default: [],
442
+ scope: "global+project",
443
+ impact: "Contributors can write memory but cannot change configuration.",
444
+ risk: "caution",
445
+ },
446
+ {
447
+ key: "access.readers",
448
+ domain: "access",
449
+ label: "Readers",
450
+ summary: "Actors allowed read-only access.",
451
+ help: "Actor names that may search and read but never mutate memory.",
452
+ control: "string-list",
453
+ default: [],
454
+ scope: "global+project",
455
+ impact: "Readers can search and view but cannot add or edit anything.",
456
+ risk: "caution",
457
+ },
458
+ ],
459
+ },
460
+ ];
461
+ // ── Lookups ───────────────────────────────────────────────────────────────────
462
+ const DOMAIN_BY_ID = new Map(CONFIG_DOMAINS.map((d) => [d.id, d]));
463
+ const FIELD_BY_KEY = new Map(CONFIG_DOMAINS.flatMap((d) => d.fields.map((f) => [f.key, f])));
464
+ /** Look up a domain descriptor by id. */
465
+ export function getConfigDomain(id) {
466
+ return DOMAIN_BY_ID.get(id);
467
+ }
468
+ /** Look up a field descriptor by its dotted key. */
469
+ export function getConfigField(key) {
470
+ return FIELD_BY_KEY.get(key);
471
+ }
472
+ /** Every field across every domain, in domain order. */
473
+ export function allConfigFields() {
474
+ return CONFIG_DOMAINS.flatMap((d) => d.fields);
475
+ }
476
+ /**
477
+ * Aliases mapping the historical hyphenated `phren config` subcommands to the
478
+ * canonical domain ids. Help text and routing are generated from this so the
479
+ * CLI surface can never drift from the schema.
480
+ */
481
+ export const CONFIG_DOMAIN_ALIASES = {
482
+ proactivity: "proactivity",
483
+ "task-mode": "taskMode",
484
+ taskmode: "taskMode",
485
+ "finding-sensitivity": "findingSensitivity",
486
+ findingsensitivity: "findingSensitivity",
487
+ policy: "retention",
488
+ retention: "retention",
489
+ workflow: "workflow",
490
+ index: "index",
491
+ topic: "topic",
492
+ topics: "topic",
493
+ access: "access",
494
+ };
495
+ /** Resolve a user-supplied domain/subcommand token to a canonical domain id. */
496
+ export function resolveConfigDomainAlias(token) {
497
+ return CONFIG_DOMAIN_ALIASES[token.trim().toLowerCase()];
498
+ }
@@ -70,6 +70,12 @@ export type RetentionPolicyPatch = Partial<Omit<RetentionPolicy, "decay">> & {
70
70
  decay?: Partial<RetentionPolicy["decay"]>;
71
71
  };
72
72
  export declare const GOVERNANCE_SCHEMA_VERSION = 1;
73
+ /** Default retention policy. Exported so {@link config/schema} can render one source of truth. */
74
+ export declare const DEFAULT_POLICY: RetentionPolicy;
75
+ /** Default workflow policy. Exported so {@link config/schema} can render one source of truth. */
76
+ export declare const DEFAULT_WORKFLOW_POLICY: WorkflowPolicy;
77
+ /** Default index policy. Exported so {@link config/schema} can render one source of truth. */
78
+ export declare const DEFAULT_INDEX_POLICY: IndexPolicy;
73
79
  type GovernanceSchema = "retention-policy" | "workflow-policy" | "index-policy";
74
80
  export declare function validateGovernanceJson(filePath: string, schema: GovernanceSchema): boolean;
75
81
  export interface ResolvedConfig {
@@ -23,7 +23,8 @@ export function buildSyncStatus(opts) {
23
23
  };
24
24
  }
25
25
  export const GOVERNANCE_SCHEMA_VERSION = 1;
26
- const DEFAULT_POLICY = {
26
+ /** Default retention policy. Exported so {@link config/schema} can render one source of truth. */
27
+ export const DEFAULT_POLICY = {
27
28
  schemaVersion: GOVERNANCE_SCHEMA_VERSION,
28
29
  ttlDays: 120,
29
30
  retentionDays: 365,
@@ -36,14 +37,16 @@ const DEFAULT_POLICY = {
36
37
  d120: 0.45,
37
38
  },
38
39
  };
39
- const DEFAULT_WORKFLOW_POLICY = {
40
+ /** Default workflow policy. Exported so {@link config/schema} can render one source of truth. */
41
+ export const DEFAULT_WORKFLOW_POLICY = {
40
42
  schemaVersion: GOVERNANCE_SCHEMA_VERSION,
41
43
  lowConfidenceThreshold: 0.7,
42
44
  riskySections: ["Stale", "Conflicts"],
43
45
  taskMode: "auto",
44
46
  findingSensitivity: "balanced",
45
47
  };
46
- const DEFAULT_INDEX_POLICY = {
48
+ /** Default index policy. Exported so {@link config/schema} can render one source of truth. */
49
+ export const DEFAULT_INDEX_POLICY = {
47
50
  schemaVersion: GOVERNANCE_SCHEMA_VERSION,
48
51
  includeGlobs: ["**/*.md", "**/skills/**/*.md", ".claude/skills/**/*.md"],
49
52
  excludeGlobs: ["**/.git/**", "**/node_modules/**", "**/dist/**", "**/build/**"],
@@ -9,6 +9,8 @@ import { FINDING_SENSITIVITY_CONFIG, buildProactivitySnapshot, checkProjectInPro
9
9
  import { readProjectConfig, updateProjectConfigOverrides, } from "../project-config.js";
10
10
  import { isValidProjectName, safeProjectPath } from "../utils.js";
11
11
  import { readProjectTopics, writeProjectTopics, } from "../project-topics.js";
12
+ import { buildConfigView } from "../config/resolve.js";
13
+ import { getConfigField, CONFIG_DOMAINS } from "../config/schema.js";
12
14
  // ── Helpers ─────────────────────────────────────────────────────────────────
13
15
  function proactivitySnapshot(phrenPath) {
14
16
  const snap = buildProactivitySnapshot(phrenPath);
@@ -63,6 +65,25 @@ function getTopicConfigData(phrenPath, project) {
63
65
  },
64
66
  };
65
67
  }
68
+ /**
69
+ * Resolved per-field provenance for the requested domain(s), keyed by dotted
70
+ * field key. Every field carries the uniform `{ value, source, inheritedValue,
71
+ * sourcePath }` shape so all surfaces render the same 3-level source chip.
72
+ */
73
+ function resolvedFields(phrenPath, domain, project) {
74
+ const view = buildConfigView(phrenPath, project);
75
+ if (domain === "all")
76
+ return view.fields;
77
+ return Object.fromEntries(Object.entries(view.fields).filter(([key]) => getConfigField(key)?.domain === domain));
78
+ }
79
+ /**
80
+ * The shared schema descriptors for the requested domain(s). Surfaces that can't
81
+ * import `@phren/cli` directly (e.g. the VS Code extension) render entirely from
82
+ * this, so they never re-hardcode labels, options, or defaults.
83
+ */
84
+ function configSchema(domain) {
85
+ return domain === "all" ? CONFIG_DOMAINS : CONFIG_DOMAINS.filter((d) => d.id === domain);
86
+ }
66
87
  // ── Handlers ─────────────────────────────────────────────────────────────────
67
88
  async function handleGetConfig(ctx, { domain, project }) {
68
89
  const { phrenPath } = ctx;
@@ -156,6 +177,8 @@ async function handleGetConfig(ctx, { domain, project }) {
156
177
  if (d === "all" || d === "index") {
157
178
  result.index = getIndexPolicy(phrenPath);
158
179
  }
180
+ result.fields = resolvedFields(phrenPath, d, project);
181
+ result.schema = configSchema(d);
159
182
  return mcpResponse({
160
183
  ok: true,
161
184
  message: `Config for ${d === "all" ? "all domains" : d} (project: ${project}).`,
@@ -185,6 +208,8 @@ async function handleGetConfig(ctx, { domain, project }) {
185
208
  if (d === "all" || d === "index") {
186
209
  result.index = getIndexPolicy(phrenPath);
187
210
  }
211
+ result.fields = resolvedFields(phrenPath, d);
212
+ result.schema = configSchema(d);
188
213
  return mcpResponse({
189
214
  ok: true,
190
215
  message: `Config for ${d === "all" ? "all domains" : d}.`,
@@ -130,6 +130,9 @@ async function handleAddFinding(ctx, params) {
130
130
  });
131
131
  }
132
132
  }
133
+ const normalizedScope = normalizeMemoryScope(scope ?? "shared");
134
+ if (!normalizedScope)
135
+ return mcpResponse({ ok: false, error: `Invalid scope: "${scope}". Use lowercase letters/numbers with '-' or '_' (max 64 chars), e.g. "researcher".` });
133
136
  if (Array.isArray(finding)) {
134
137
  const findings = finding;
135
138
  if (findings.length > 100)
@@ -183,9 +186,6 @@ async function handleAddFinding(ctx, params) {
183
186
  }
184
187
  if (finding.length > 5000)
185
188
  return mcpResponse({ ok: false, error: "Finding text exceeds 5000 character limit." });
186
- const normalizedScope = normalizeMemoryScope(scope ?? "shared");
187
- if (!normalizedScope)
188
- return mcpResponse({ ok: false, error: `Invalid scope: "${scope}". Use lowercase letters/numbers with '-' or '_' (max 64 chars), e.g. "researcher".` });
189
189
  return withWriteQueue(async () => {
190
190
  try {
191
191
  const taggedFinding = applyFindingTypePrefix(finding, findingType);
@@ -629,10 +629,7 @@ export function register(server, ctx) {
629
629
  " Optionally classify with findingType: decision, pitfall, pattern, tradeoff, architecture, or bug.",
630
630
  inputSchema: z.object({
631
631
  project: z.string().describe("Project name (must match a directory in your phren store)."),
632
- finding: z.union([
633
- z.string().describe("A single insight, written as a bullet point."),
634
- z.array(z.string()).describe("Multiple insights to record in one call."),
635
- ]).describe("The insight(s) to save. Pass a string for one finding, or an array for bulk."),
632
+ finding: z.preprocess((v) => (typeof v === "string" ? [v] : v), z.array(z.string()).min(1)).describe("The insight(s) to save. Always pass as an array of strings — use a single-element array for one finding."),
636
633
  citation: z.object({
637
634
  file: z.string().optional().describe("Source file path that supports this finding."),
638
635
  line: z.number().int().positive().optional().describe("1-based line number in file."),
@@ -717,10 +714,7 @@ export function register(server, ctx) {
717
714
  " Pass a single string or an array of strings.",
718
715
  inputSchema: z.object({
719
716
  project: z.string().describe("Project name."),
720
- finding: z.union([
721
- z.string().describe("Partial text to match against existing findings."),
722
- z.array(z.string()).describe("List of partial texts to match and remove."),
723
- ]).describe("Text(s) to match and remove. Pass a string for one, or an array for bulk."),
717
+ finding: z.preprocess((v) => (typeof v === "string" ? [v] : v), z.array(z.string()).min(1)).describe("Text(s) to match and remove. Always pass as an array of strings — use a single-element array for one."),
724
718
  }),
725
719
  }, (params) => handleRemoveFinding(ctx, params));
726
720
  server.registerTool("push_changes", {