@in-the-loop-labs/pair-review 4.1.1 → 5.0.1

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 (71) hide show
  1. package/README.md +81 -13
  2. package/package.json +6 -2
  3. package/plugin/.claude-plugin/plugin.json +1 -1
  4. package/plugin-code-critic/.claude-plugin/plugin.json +1 -1
  5. package/plugin-pair-loop/.claude-plugin/plugin.json +1 -1
  6. package/plugin-pair-loop/skills/loop/SKILL.md +17 -8
  7. package/public/css/ai-summary-modal.css +1 -1
  8. package/public/css/analysis-config.css +33 -49
  9. package/public/css/council-card.css +118 -0
  10. package/public/css/council-dropdown.css +164 -0
  11. package/public/css/pr.css +668 -393
  12. package/public/css/repo-settings.css +15 -305
  13. package/public/css/settings.css +1141 -0
  14. package/public/css/snippet-manager.css +233 -0
  15. package/public/index.html +40 -59
  16. package/public/js/components/AIPanel.js +82 -16
  17. package/public/js/components/ChatPanel.js +401 -5
  18. package/public/js/components/CouncilCard.js +202 -0
  19. package/public/js/components/CouncilDropdown.js +292 -0
  20. package/public/js/components/DiffOptionsDropdown.js +177 -4
  21. package/public/js/components/SnippetManager.js +463 -0
  22. package/public/js/index.js +7 -30
  23. package/public/js/local.js +20 -2
  24. package/public/js/modules/comment-manager.js +8 -1
  25. package/public/js/modules/comment-minimizer.js +249 -190
  26. package/public/js/modules/diff-renderer.js +16 -4
  27. package/public/js/modules/external-comment-manager.js +414 -48
  28. package/public/js/modules/file-comment-manager.js +28 -21
  29. package/public/js/modules/hunk-summary-renderer.js +155 -29
  30. package/public/js/modules/pierre-bridge.js +2513 -0
  31. package/public/js/modules/pierre-context.js +345 -0
  32. package/public/js/modules/suggestion-manager.js +176 -20
  33. package/public/js/modules/tour-renderer.js +400 -184
  34. package/public/js/pr.js +1614 -158
  35. package/public/js/repo-settings.js +60 -284
  36. package/public/js/settings.js +1086 -0
  37. package/public/js/theme-bootstrap.js +40 -0
  38. package/public/js/theme.js +247 -0
  39. package/public/js/utils/provider-model.js +3 -3
  40. package/public/js/utils/suggestion-ui.js +157 -8
  41. package/public/local.html +20 -31
  42. package/public/pr.html +14 -23
  43. package/public/repo-settings.html +24 -14
  44. package/public/settings.html +138 -0
  45. package/public/setup.html +8 -13
  46. package/src/chat/api-reference.js +9 -5
  47. package/src/chat/prompt-builder.js +8 -1
  48. package/src/config.js +15 -6
  49. package/src/database.js +307 -14
  50. package/src/external/github-adapter.js +39 -5
  51. package/src/headless/delegate.js +682 -0
  52. package/src/local-review.js +10 -10
  53. package/src/local-scope.js +9 -0
  54. package/src/main.js +276 -157
  55. package/src/mcp-stdio.js +24 -1
  56. package/src/review-config.js +93 -25
  57. package/src/routes/chat.js +2 -2
  58. package/src/routes/config.js +12 -10
  59. package/src/routes/external-comments.js +5 -1
  60. package/src/routes/local.js +2 -4
  61. package/src/routes/mcp.js +18 -13
  62. package/src/routes/reviews.js +223 -4
  63. package/src/routes/settings.js +252 -0
  64. package/src/routes/setup.js +80 -1
  65. package/src/routes/shared.js +31 -29
  66. package/src/routes/snippets.js +154 -0
  67. package/src/routes/stack-analysis.js +17 -14
  68. package/src/server.js +86 -18
  69. package/src/settings/global-settings-service.js +472 -0
  70. package/src/settings/registry.js +624 -0
  71. package/src/utils/db-identity.js +44 -0
@@ -0,0 +1,624 @@
1
+ // Copyright 2026 Tim Perkins (tjwp) | SPDX-License-Identifier: Apache-2.0
2
+ /**
3
+ * Global Settings Registry
4
+ *
5
+ * Single catalog of every global (non-repo) setting the /settings page can
6
+ * surface. It drives three things that must never drift apart:
7
+ * 1. Validation of in-app override writes (type, enum membership, bounds).
8
+ * 2. Source attribution (which config layer / env var / DB an effective
9
+ * value came from) — via each entry's dot-path `key` and optional
10
+ * `envVar`.
11
+ * 3. The settings UI (label, description, group, control type).
12
+ *
13
+ * Each entry:
14
+ * {
15
+ * key: dot-path into the merged config object (e.g. 'summaries.enabled')
16
+ * label: human label for the UI
17
+ * description: one-line help text
18
+ * group: general | ai | summaries | tours | chat | advanced | readonly
19
+ * type: boolean | string | integer | enum | object
20
+ * values: [...] (enum only) — allowed values
21
+ * default: built-in default; MUST match DEFAULT_CONFIG / the inline
22
+ * default used by the value's consumer
23
+ * editable: whether the value can be set in-app (false => read-only row)
24
+ * restartRequired: true when the value is captured at startup, so an in-app
25
+ * change is stored but only takes effect on next launch
26
+ * envVar: env var that overrides this value (for source attribution)
27
+ * sensitive: mask the value in API/UI (return "configured" only)
28
+ * badge: optional 'new' | 'beta' pill for the UI (null default)
29
+ * }
30
+ *
31
+ * SECTIONS is the ordered catalog of UI groups. Each entry's `id` matches a
32
+ * registry entry's `group`; titles/descriptions are the single source of truth
33
+ * the settings page renders (lifted out of public/js/settings.js so the two can
34
+ * never drift). A section may carry a `badge` ('new' | 'beta' | null).
35
+ *
36
+ * Defaults are verified against src/config.js DEFAULT_CONFIG and the inline
37
+ * defaults in src/routes/config.js. Enum value sets are verified against the
38
+ * actual consumer code (comment-formatter PRESETS, SplitButton actions,
39
+ * ChatPanel spinner, theme toggle).
40
+ */
41
+
42
+ const REGISTRY = [
43
+ // ---- General -----------------------------------------------------------
44
+ {
45
+ key: 'comment_format',
46
+ label: 'Comment format',
47
+ description: 'Template preset used when adopting an AI suggestion into a review comment.',
48
+ group: 'general',
49
+ type: 'enum',
50
+ values: ['legacy', 'minimal', 'plain', 'emoji-only', 'maximal'],
51
+ default: 'legacy',
52
+ editable: true,
53
+ restartRequired: false
54
+ },
55
+ {
56
+ key: 'comment_button_action',
57
+ label: 'Default review button action',
58
+ description: 'Primary action of the split submit button (Submit vs. Preview).',
59
+ group: 'general',
60
+ type: 'enum',
61
+ values: ['submit', 'preview'],
62
+ default: 'submit',
63
+ editable: true,
64
+ restartRequired: false
65
+ },
66
+ {
67
+ key: 'enable_graphite',
68
+ label: 'Show Graphite links',
69
+ description: 'Show Graphite links alongside GitHub links in the PR header.',
70
+ group: 'general',
71
+ type: 'boolean',
72
+ default: false,
73
+ editable: true,
74
+ restartRequired: false
75
+ },
76
+ {
77
+ key: 'external_comments',
78
+ label: 'GitHub comment sync',
79
+ description: 'Enable syncing GitHub PR review comments into the External segment. Mounts extra routes at startup.',
80
+ group: 'general',
81
+ type: 'boolean',
82
+ default: false,
83
+ editable: true,
84
+ restartRequired: true
85
+ },
86
+ {
87
+ key: 'assisted_by_url',
88
+ label: 'Assisted-by URL',
89
+ description: 'URL for the "Review assisted by" footer link.',
90
+ group: 'general',
91
+ type: 'string',
92
+ default: 'https://github.com/in-the-loop-labs/pair-review',
93
+ editable: true,
94
+ restartRequired: false
95
+ },
96
+
97
+ // ---- AI defaults -------------------------------------------------------
98
+ {
99
+ // The "Default for Analysis" control: a single selection that is EITHER the
100
+ // Default Provider/Model pair (below) OR a saved Review Council. Its allowed
101
+ // values are the councils stored in the DB — a dynamic enum the registry's
102
+ // static `values: [...]` model can't express — so the settings page
103
+ // special-cases this key (COUNCIL_KEYS) into the shared rich council
104
+ // dropdown (CouncilDropdown), whose empty/base option is "Default Provider /
105
+ // Model". Empty string = use the provider/model pair (no council). See
106
+ // src/review-config.js for the resolver tier this feeds.
107
+ key: 'default_council_id',
108
+ label: 'Default for Analysis',
109
+ description: "The default analysis: your Default Provider/Model pair (below) or a saved Review Council. Explicit per-run picks and a repository's own default still take precedence. Single-model tasks — hunk summaries, tours, MCP start_analysis — always use the provider/model, never a council.",
110
+ group: 'ai',
111
+ type: 'string',
112
+ default: '',
113
+ editable: true,
114
+ restartRequired: false
115
+ },
116
+ {
117
+ key: 'default_provider',
118
+ label: 'Default provider',
119
+ description: "AI provider for the Default Provider/Model analysis (used when 'Default for Analysis' is not a council) and for single-model tasks like summaries.",
120
+ group: 'ai',
121
+ type: 'string',
122
+ default: 'claude',
123
+ editable: true,
124
+ restartRequired: false
125
+ },
126
+ {
127
+ key: 'default_model',
128
+ label: 'Default model',
129
+ description: "Model within the default provider for the Default Provider/Model analysis and single-model tasks.",
130
+ group: 'ai',
131
+ type: 'string',
132
+ default: 'opus',
133
+ editable: true,
134
+ restartRequired: false
135
+ },
136
+
137
+ // ---- Summaries ---------------------------------------------------------
138
+ {
139
+ key: 'summaries.enabled',
140
+ label: 'Enable summaries',
141
+ description: 'Make the hunk-summaries feature available (toolbar button + per-file toggles).',
142
+ group: 'summaries',
143
+ type: 'boolean',
144
+ default: false,
145
+ editable: true,
146
+ restartRequired: false
147
+ },
148
+ {
149
+ key: 'summaries.auto_generate',
150
+ label: 'Auto-generate summaries',
151
+ description: 'Kick off summary generation automatically on review load.',
152
+ group: 'summaries',
153
+ type: 'boolean',
154
+ default: true,
155
+ editable: true,
156
+ restartRequired: false
157
+ },
158
+ {
159
+ key: 'summaries.provider',
160
+ label: 'Summaries provider',
161
+ description: 'Provider for hunk-summary tasks. Empty falls back to the default provider.',
162
+ group: 'summaries',
163
+ type: 'string',
164
+ default: '',
165
+ editable: true,
166
+ restartRequired: false
167
+ },
168
+ {
169
+ key: 'summaries.model',
170
+ label: 'Summaries model',
171
+ description: "Model for hunk-summary tasks. Empty uses the provider's fast tier, then the default model.",
172
+ group: 'summaries',
173
+ type: 'string',
174
+ default: '',
175
+ editable: true,
176
+ restartRequired: false
177
+ },
178
+ {
179
+ key: 'summaries.max_files',
180
+ label: 'Summaries file cap',
181
+ description: 'Skip summary generation for reviews touching more than this many files.',
182
+ group: 'summaries',
183
+ type: 'integer',
184
+ default: 50,
185
+ editable: true,
186
+ restartRequired: false
187
+ },
188
+ {
189
+ key: 'summaries.max_lines_added',
190
+ label: 'Summaries added-line cap',
191
+ description: 'Skip summary generation when the diff adds more than this many lines.',
192
+ group: 'summaries',
193
+ type: 'integer',
194
+ default: 3000,
195
+ editable: true,
196
+ restartRequired: false
197
+ },
198
+
199
+ // ---- Tours -------------------------------------------------------------
200
+ {
201
+ key: 'tours.enabled',
202
+ label: 'Enable tours',
203
+ description: 'Make the guided-tour feature available (toolbar button visible).',
204
+ group: 'tours',
205
+ type: 'boolean',
206
+ default: false,
207
+ editable: true,
208
+ restartRequired: false
209
+ },
210
+ {
211
+ key: 'tours.auto_generate',
212
+ label: 'Auto-generate tours',
213
+ description: 'Kick off tour generation automatically on review load.',
214
+ group: 'tours',
215
+ type: 'boolean',
216
+ default: true,
217
+ editable: true,
218
+ restartRequired: false
219
+ },
220
+ {
221
+ key: 'tours.provider',
222
+ label: 'Tours provider',
223
+ description: 'Provider for tour generation. Empty falls back to the summaries provider, then the default provider.',
224
+ group: 'tours',
225
+ type: 'string',
226
+ default: '',
227
+ editable: true,
228
+ restartRequired: false
229
+ },
230
+ {
231
+ key: 'tours.model',
232
+ label: 'Tours model',
233
+ description: 'Model for tour generation. Empty falls back to summaries model resolution.',
234
+ group: 'tours',
235
+ type: 'string',
236
+ default: '',
237
+ editable: true,
238
+ restartRequired: false
239
+ },
240
+
241
+ // ---- Chat --------------------------------------------------------------
242
+ {
243
+ key: 'enable_chat',
244
+ label: 'Enable chat',
245
+ description: 'Enable the chat panel feature.',
246
+ group: 'chat',
247
+ type: 'boolean',
248
+ default: true,
249
+ editable: true,
250
+ restartRequired: false
251
+ },
252
+ {
253
+ key: 'chat_provider',
254
+ label: 'Chat provider',
255
+ description: "Chat provider ('pi', 'copilot-acp', 'opencode-acp', 'cursor-acp', 'codex').",
256
+ group: 'chat',
257
+ type: 'string',
258
+ default: 'pi',
259
+ editable: true,
260
+ restartRequired: false
261
+ },
262
+ {
263
+ key: 'chat.enable_shortcuts',
264
+ label: 'Chat action shortcuts',
265
+ description: 'Show action shortcut buttons in the chat panel.',
266
+ group: 'chat',
267
+ type: 'boolean',
268
+ default: true,
269
+ editable: true,
270
+ restartRequired: false
271
+ },
272
+ {
273
+ key: 'chat.enter_to_send',
274
+ label: 'Enter to send',
275
+ description: 'Pressing Enter sends the chat message (instead of inserting a newline).',
276
+ group: 'chat',
277
+ type: 'boolean',
278
+ default: true,
279
+ editable: true,
280
+ restartRequired: false
281
+ },
282
+ {
283
+ key: 'chat_spinner',
284
+ label: 'Chat spinner style',
285
+ description: 'Animation shown while the chat agent is working.',
286
+ group: 'chat',
287
+ type: 'enum',
288
+ values: ['dots', 'loop'],
289
+ default: 'dots',
290
+ editable: true,
291
+ restartRequired: false
292
+ },
293
+
294
+ // ---- Advanced (restart required) --------------------------------------
295
+ {
296
+ key: 'worktree_retention_days',
297
+ label: 'Worktree retention (days)',
298
+ description: 'Delete stale PR worktrees older than this many days.',
299
+ group: 'advanced',
300
+ type: 'integer',
301
+ default: 7,
302
+ editable: true,
303
+ restartRequired: true
304
+ },
305
+ {
306
+ key: 'review_retention_days',
307
+ label: 'Review retention (days)',
308
+ description: 'Delete stale reviews older than this many days.',
309
+ group: 'advanced',
310
+ type: 'integer',
311
+ default: 21,
312
+ editable: true,
313
+ restartRequired: true
314
+ },
315
+ {
316
+ key: 'dev_mode',
317
+ label: 'Dev mode',
318
+ description: 'Disable static file caching for development.',
319
+ group: 'advanced',
320
+ type: 'boolean',
321
+ default: false,
322
+ editable: true,
323
+ restartRequired: true
324
+ },
325
+ {
326
+ key: 'debug_stream',
327
+ label: 'Debug provider streaming',
328
+ description: 'Log AI provider streaming events (equivalent to --debug-stream).',
329
+ group: 'advanced',
330
+ type: 'boolean',
331
+ default: false,
332
+ editable: true,
333
+ restartRequired: true
334
+ },
335
+ {
336
+ key: 'yolo',
337
+ label: 'YOLO mode',
338
+ description: 'Skip fine-grained AI provider permission setup (equivalent to --yolo).',
339
+ group: 'advanced',
340
+ type: 'boolean',
341
+ default: false,
342
+ editable: true,
343
+ restartRequired: true,
344
+ envVar: 'PAIR_REVIEW_YOLO'
345
+ },
346
+
347
+ // ---- Read-only (bootstrap / sensitive / complex) ----------------------
348
+ {
349
+ key: 'skip_update_notifier',
350
+ label: 'Skip update notifier',
351
+ description: 'Suppress the "update available" notification on exit. Read from config files at startup by the CLI wrapper (bin/pair-review.js) BEFORE the database opens, so an in-app override can never take effect — set it in a config file.',
352
+ group: 'readonly',
353
+ type: 'boolean',
354
+ default: false,
355
+ editable: false,
356
+ restartRequired: true
357
+ },
358
+ {
359
+ key: 'port',
360
+ label: 'Port',
361
+ description: 'Server port. Bootstrap value; edit via config file or PORT env var.',
362
+ group: 'readonly',
363
+ type: 'integer',
364
+ default: 7247,
365
+ editable: false,
366
+ restartRequired: true,
367
+ envVar: 'PORT'
368
+ },
369
+ {
370
+ key: 'single_port',
371
+ label: 'Single-port mode',
372
+ description: 'Reuse a single server on the configured port; new invocations delegate to it.',
373
+ group: 'readonly',
374
+ type: 'boolean',
375
+ default: true,
376
+ editable: false,
377
+ restartRequired: true,
378
+ envVar: 'PAIR_REVIEW_SINGLE_PORT'
379
+ },
380
+ {
381
+ key: 'db_name',
382
+ label: 'Database filename',
383
+ description: 'Custom database filename. Selects the DB that would hold these overrides, so it cannot be set in-app.',
384
+ group: 'readonly',
385
+ type: 'string',
386
+ default: '',
387
+ editable: false,
388
+ restartRequired: true,
389
+ envVar: 'PAIR_REVIEW_DB_NAME'
390
+ },
391
+ {
392
+ key: 'github_token',
393
+ label: 'GitHub token',
394
+ description: 'GitHub Personal Access Token. Never editable in-app; set via config file or GITHUB_TOKEN.',
395
+ group: 'readonly',
396
+ type: 'string',
397
+ default: '',
398
+ editable: false,
399
+ restartRequired: true,
400
+ sensitive: true,
401
+ envVar: 'GITHUB_TOKEN'
402
+ },
403
+ {
404
+ key: 'github_token_command',
405
+ label: 'GitHub token command',
406
+ description: 'Shell command whose stdout is used as the GitHub token.',
407
+ group: 'readonly',
408
+ type: 'string',
409
+ default: 'gh auth token',
410
+ editable: false,
411
+ restartRequired: true
412
+ },
413
+ {
414
+ key: 'providers',
415
+ label: 'AI providers',
416
+ description: 'Custom AI analysis provider configurations from config files.',
417
+ group: 'readonly',
418
+ type: 'object',
419
+ default: {},
420
+ editable: false,
421
+ restartRequired: true
422
+ },
423
+ {
424
+ key: 'chat_providers',
425
+ label: 'Chat providers',
426
+ description: 'Custom chat provider configurations from config files.',
427
+ group: 'readonly',
428
+ type: 'object',
429
+ default: {},
430
+ editable: false,
431
+ restartRequired: true
432
+ },
433
+ {
434
+ key: 'repos',
435
+ label: 'Repositories',
436
+ description: 'Per-repository configurations from config files.',
437
+ group: 'readonly',
438
+ type: 'object',
439
+ default: {},
440
+ editable: false,
441
+ restartRequired: true
442
+ },
443
+ {
444
+ key: 'hooks',
445
+ label: 'Hooks',
446
+ description: 'Hook commands per event from config files.',
447
+ group: 'readonly',
448
+ type: 'object',
449
+ default: {},
450
+ editable: false,
451
+ restartRequired: true
452
+ }
453
+ ];
454
+
455
+ const REGISTRY_BY_KEY = new Map(REGISTRY.map((e) => [e.key, e]));
456
+
457
+ /** Allowed badge values for both sections and individual settings (null = none). */
458
+ const BADGE_VALUES = new Set(['new', 'beta']);
459
+
460
+ /**
461
+ * Ordered UI sections. `id` matches an entry's `group`. Titles/descriptions are
462
+ * lifted verbatim from the frontend so /api/settings can drive the section nav
463
+ * (order, titles, badges) instead of the page deriving them locally.
464
+ *
465
+ * A section may carry a `badge` ('new' | 'beta' | null) and an optional
466
+ * `hidden: true` flag. `hidden` is a build-time visibility default (distinct
467
+ * from the config-driven `settings_ui.hidden` preference): the API forwards it
468
+ * on the sections payload and the settings-page renderer omits hidden sections
469
+ * (and their nav entries). Summaries is hidden for now while the feature is
470
+ * being finished — flip the flag to bring the section back.
471
+ */
472
+ const SECTIONS = [
473
+ { id: 'general', title: 'General', description: 'Basic application preferences.', badge: null },
474
+ { id: 'ai', title: 'AI Defaults', description: 'The default for analysis — a provider/model pair or a Review Council — plus the provider/model used for single-model tasks.', badge: null },
475
+ { id: 'summaries', title: 'Summaries', description: 'Automatic PR summary generation.', badge: null, hidden: true },
476
+ { id: 'tours', title: 'Tours', description: 'Automatic code tour generation.', badge: 'new' },
477
+ { id: 'chat', title: 'Chat', description: 'The AI chat assistant.', badge: null },
478
+ { id: 'advanced', title: 'Advanced', description: 'These are captured at startup — changes take effect after you restart pair-review.', badge: null },
479
+ { id: 'readonly', title: 'From config files & environment', description: 'Read-only here. Set these via config files, CLI flags, or environment variables.', badge: null }
480
+ ];
481
+
482
+ const SECTION_IDS = new Set(SECTIONS.map((s) => s.id));
483
+
484
+ /** @returns {Array<Object>} The full registry catalog (shared reference — do not mutate). */
485
+ function getRegistry() {
486
+ return REGISTRY;
487
+ }
488
+
489
+ /** @returns {Array<Object>} The ordered section catalog (shared reference — do not mutate). */
490
+ function getSections() {
491
+ return SECTIONS;
492
+ }
493
+
494
+ /**
495
+ * @param {string} id - Section id
496
+ * @returns {boolean} Whether the id is a known section.
497
+ */
498
+ function isSectionId(id) {
499
+ return SECTION_IDS.has(id);
500
+ }
501
+
502
+ /**
503
+ * @param {string} key - Dot-path key
504
+ * @returns {Object|null} The registry entry, or null when the key is unknown.
505
+ */
506
+ function getEntry(key) {
507
+ return REGISTRY_BY_KEY.get(key) || null;
508
+ }
509
+
510
+ /**
511
+ * Read a dot-path value out of a plain object. Returns undefined when any
512
+ * segment is missing. Walks own-property presence via `hasPath` semantics
513
+ * only where needed; this getter tolerates absent intermediate objects.
514
+ * @param {Object} obj
515
+ * @param {string} dotPath
516
+ * @returns {*}
517
+ */
518
+ function getPath(obj, dotPath) {
519
+ if (!obj || typeof obj !== 'object') return undefined;
520
+ const parts = dotPath.split('.');
521
+ let cur = obj;
522
+ for (const part of parts) {
523
+ if (cur === null || typeof cur !== 'object' || !(part in cur)) return undefined;
524
+ cur = cur[part];
525
+ }
526
+ return cur;
527
+ }
528
+
529
+ /**
530
+ * Whether a dot-path is defined as an own property at every level of `obj`.
531
+ * Uses hasOwnProperty (NOT truthiness) so that a value of `false`, `0`, or
532
+ * `''` still counts as "defined" — essential for correct source attribution.
533
+ * @param {Object} obj
534
+ * @param {string} dotPath
535
+ * @returns {boolean}
536
+ */
537
+ function hasPath(obj, dotPath) {
538
+ if (!obj || typeof obj !== 'object') return false;
539
+ const parts = dotPath.split('.');
540
+ let cur = obj;
541
+ for (const part of parts) {
542
+ if (cur === null || typeof cur !== 'object' || !Object.prototype.hasOwnProperty.call(cur, part)) {
543
+ return false;
544
+ }
545
+ cur = cur[part];
546
+ }
547
+ return true;
548
+ }
549
+
550
+ /**
551
+ * Set a dot-path value on a plain object, creating intermediate plain objects
552
+ * as needed. Mutates `obj` in place.
553
+ * @param {Object} obj
554
+ * @param {string} dotPath
555
+ * @param {*} value
556
+ */
557
+ function setPath(obj, dotPath, value) {
558
+ const parts = dotPath.split('.');
559
+ let cur = obj;
560
+ for (let i = 0; i < parts.length - 1; i++) {
561
+ const part = parts[i];
562
+ if (cur[part] === null || typeof cur[part] !== 'object' || Array.isArray(cur[part])) {
563
+ cur[part] = {};
564
+ }
565
+ cur = cur[part];
566
+ }
567
+ cur[parts[parts.length - 1]] = value;
568
+ }
569
+
570
+ /**
571
+ * Validate a candidate value against a registry entry's type/enum/bounds.
572
+ * Does NOT check `editable` — callers decide whether a non-editable key may be
573
+ * written (the API rejects those before reaching here).
574
+ *
575
+ * @param {Object} entry - Registry entry
576
+ * @param {*} value - Candidate value
577
+ * @returns {{ valid: boolean, error?: string }}
578
+ */
579
+ function validateValue(entry, value) {
580
+ if (!entry) return { valid: false, error: 'Unknown setting' };
581
+ switch (entry.type) {
582
+ case 'boolean':
583
+ if (typeof value !== 'boolean') {
584
+ return { valid: false, error: `${entry.key} must be a boolean` };
585
+ }
586
+ return { valid: true };
587
+ case 'string':
588
+ if (typeof value !== 'string') {
589
+ return { valid: false, error: `${entry.key} must be a string` };
590
+ }
591
+ return { valid: true };
592
+ case 'integer':
593
+ if (!Number.isInteger(value) || value < 0) {
594
+ return { valid: false, error: `${entry.key} must be a non-negative integer` };
595
+ }
596
+ return { valid: true };
597
+ case 'enum':
598
+ if (!Array.isArray(entry.values) || !entry.values.includes(value)) {
599
+ return { valid: false, error: `${entry.key} must be one of: ${(entry.values || []).join(', ')}` };
600
+ }
601
+ return { valid: true };
602
+ case 'object':
603
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) {
604
+ return { valid: false, error: `${entry.key} must be an object` };
605
+ }
606
+ return { valid: true };
607
+ default:
608
+ return { valid: false, error: `Unsupported type for ${entry.key}` };
609
+ }
610
+ }
611
+
612
+ module.exports = {
613
+ getRegistry,
614
+ getSections,
615
+ isSectionId,
616
+ getEntry,
617
+ getPath,
618
+ hasPath,
619
+ setPath,
620
+ validateValue,
621
+ REGISTRY,
622
+ SECTIONS,
623
+ BADGE_VALUES
624
+ };
@@ -0,0 +1,44 @@
1
+ // Copyright 2026 Tim Perkins (tjwp) | SPDX-License-Identifier: Apache-2.0
2
+
3
+ /**
4
+ * Database identity helpers shared by the server (/health) and the headless
5
+ * CLI delegation handshake. Two processes may only delegate work to each
6
+ * other when they resolve the same SQLite database file; comparing digests
7
+ * of the resolved absolute path avoids exposing the raw filesystem path
8
+ * over HTTP.
9
+ */
10
+
11
+ const crypto = require('crypto');
12
+ const path = require('path');
13
+ const { getConfigDir, resolveDbName } = require('../config');
14
+
15
+ /**
16
+ * Resolves the absolute path of the SQLite database for the given config,
17
+ * using the same precedence as server startup (PAIR_REVIEW_DB_NAME env >
18
+ * config.db_name > 'database.db', inside the pair-review config dir).
19
+ *
20
+ * @param {Object} config - Configuration object from loadConfig()
21
+ * @returns {string} - Absolute database file path
22
+ */
23
+ function resolveDbPath(config) {
24
+ // getConfigDir() is already absolute and computeDbId() resolves the path
25
+ // again, so an outer path.resolve here is a no-op — join is enough.
26
+ return path.join(getConfigDir(), resolveDbName(config));
27
+ }
28
+
29
+ /**
30
+ * Computes a stable identity digest for a database path. Both sides of the
31
+ * delegation handshake must use this exact function so digests compare
32
+ * equal by construction.
33
+ *
34
+ * @param {string} dbPath - Database file path (absolute or relative)
35
+ * @returns {string} - Hex SHA-256 digest of the resolved absolute path
36
+ */
37
+ function computeDbId(dbPath) {
38
+ return crypto.createHash('sha256').update(path.resolve(dbPath)).digest('hex');
39
+ }
40
+
41
+ module.exports = {
42
+ resolveDbPath,
43
+ computeDbId,
44
+ };