thumbgate 1.39.1 → 1.40.2

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 (199) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/.well-known/llms.txt +2 -2
  3. package/.well-known/mcp/server-card.json +1 -1
  4. package/README.md +5 -4
  5. package/adapters/claude/.mcp.json +6 -2
  6. package/adapters/codex/config.toml +5 -0
  7. package/adapters/forge/forge.yaml +4 -4
  8. package/adapters/future-agi/.mcp.json +1 -1
  9. package/adapters/future-agi/config.toml +1 -1
  10. package/adapters/future-agi/opencode.json +1 -1
  11. package/adapters/herdr/herdr-plugin.toml +2 -2
  12. package/adapters/mcp/server-stdio.js +82 -7
  13. package/adapters/opencode/opencode.json +1 -1
  14. package/bin/cli.js +128 -15
  15. package/config/brand-standards.json +131 -0
  16. package/config/gates/default.json +18 -1
  17. package/config/github-about.json +1 -1
  18. package/config/mcp-allowlists.json +16 -3
  19. package/config/merge-quality-checks.json +1 -0
  20. package/config/post-deploy-marketing-pages.json +3 -3
  21. package/config/schemas/task-outcome-receipt.schema.json +9 -0
  22. package/openapi/openapi.yaml +7 -3
  23. package/package.json +98 -31
  24. package/public/about.html +2 -2
  25. package/public/admin.html +771 -0
  26. package/public/agent-manager.html +3 -3
  27. package/public/agents-cost-savings.html +1 -1
  28. package/public/ai-malpractice-prevention.html +12 -12
  29. package/public/architecture.html +0 -1
  30. package/public/assets/diagrams/decision.svg +3 -3
  31. package/public/blog/2026-10-05-why-3-days-of-triage-wont-save-ai-speed-code.html +1 -1
  32. package/public/blog/2026-10-09-your-code-got-a-third-author-governance.html +1 -1
  33. package/public/blog/git-at-agent-scale.html +2 -2
  34. package/public/blog/inside-your-boundary.html +1 -1
  35. package/public/blog/process-over-outcome-gates.html +1 -1
  36. package/public/case-studies.html +1 -2
  37. package/public/codex-enterprise.html +1 -1
  38. package/public/codex-plugin.html +1 -1
  39. package/public/dashboard.html +773 -481
  40. package/public/diagnostic.html +8 -3
  41. package/public/enterprise-governance.html +26 -174
  42. package/public/eval-scorecard.html +3 -4
  43. package/public/eval-scorecard.json +2 -2
  44. package/public/evaluations.html +0 -1
  45. package/public/founders.html +3 -3
  46. package/public/gaming-playbook.html +4 -4
  47. package/public/guide.html +3 -5
  48. package/public/index.html +181 -205
  49. package/public/install.html +12 -11
  50. package/public/js/buyer-intent.js +49 -8
  51. package/public/lessons.html +103 -46
  52. package/public/numbers.html +32 -33
  53. package/public/operator-framework.html +44 -72
  54. package/public/peter.html +3 -3
  55. package/public/platform-partners.html +1 -1
  56. package/public/pricing.html +61 -327
  57. package/public/pro.html +3 -1
  58. package/public/project-switcher.js +76 -0
  59. package/public/whitepaper.html +1 -2
  60. package/scripts/activation-quickstart.js +15 -3
  61. package/scripts/activation-tracker.js +280 -3
  62. package/scripts/agent-action-inventory.js +235 -143
  63. package/scripts/agent-operations-planner.js +1 -1
  64. package/scripts/agent-readiness.js +36 -6
  65. package/scripts/agentic-prompt-pipelines.js +901 -0
  66. package/scripts/analytics-report.js +363 -0
  67. package/scripts/analytics-window.js +7 -1
  68. package/scripts/async-job-runner.js +66 -11
  69. package/scripts/audit-trail.js +37 -24
  70. package/scripts/auto-context-packs.js +249 -0
  71. package/scripts/auto-promote-gates.js +37 -27
  72. package/scripts/backfill-lesson-scopes.js +122 -0
  73. package/scripts/billing-setup.js +137 -0
  74. package/scripts/billing.js +889 -132
  75. package/scripts/bot-detection.js +112 -0
  76. package/scripts/brand-standards-gate.js +571 -0
  77. package/scripts/chatgpt-ads-readiness-pack.js +1 -1
  78. package/scripts/check-update.js +236 -0
  79. package/scripts/cli-schema.js +1 -1
  80. package/scripts/commercial-offer.js +2 -2
  81. package/scripts/contextfs.js +9 -3
  82. package/scripts/conversion-rate-stats.js +442 -0
  83. package/scripts/cost-cli.js +147 -0
  84. package/scripts/creator-campaigns.js +239 -0
  85. package/scripts/cross-encoder-reranker.js +4 -0
  86. package/scripts/cuda-gate-batch.js +560 -0
  87. package/scripts/daemon-manager.js +108 -0
  88. package/scripts/dashboard-chat.js +11 -0
  89. package/scripts/dashboard.js +576 -169
  90. package/scripts/decision-journal.js +7 -4
  91. package/scripts/delegation-runtime.js +1036 -0
  92. package/scripts/dispatch-brief.js +159 -0
  93. package/scripts/distribution-surfaces.js +110 -0
  94. package/scripts/docker-sandbox-planner.js +3 -3
  95. package/scripts/egm-goldfish-packet.js +95 -0
  96. package/scripts/embeddinggemma-adapter.js +407 -0
  97. package/scripts/export-dpo-pairs.js +12 -7
  98. package/scripts/feedback-aggregate.js +4 -0
  99. package/scripts/feedback-attribution.js +6 -4
  100. package/scripts/feedback-history-distiller.js +18 -6
  101. package/scripts/feedback-loop.js +255 -89
  102. package/scripts/feedback-paths.js +8 -1
  103. package/scripts/feedback-sanitizer.js +5 -0
  104. package/scripts/feedback-scope.js +106 -0
  105. package/scripts/feedback-session.js +8 -2
  106. package/scripts/filesystem-search.js +13 -8
  107. package/scripts/financial-control-plane.js +707 -45
  108. package/scripts/funnel-analytics.js +35 -0
  109. package/scripts/gate-semantic-layer.js +292 -0
  110. package/scripts/gate-stats.js +8 -2
  111. package/scripts/gates-engine.js +694 -230
  112. package/scripts/generate-eval-scorecard.js +0 -1
  113. package/scripts/harness-tool-names.js +31 -5
  114. package/scripts/hybrid-feedback-context.js +5 -2
  115. package/scripts/implementation-notes.js +241 -0
  116. package/scripts/intent-router.js +518 -0
  117. package/scripts/intervention-policy.js +2 -1
  118. package/scripts/latency-budget.js +164 -0
  119. package/scripts/lesson-canonical.js +2 -2
  120. package/scripts/lesson-db.js +55 -14
  121. package/scripts/lesson-graph.js +2 -1
  122. package/scripts/lesson-retrieval.js +95 -9
  123. package/scripts/lesson-search.js +86 -22
  124. package/scripts/lesson-synthesis.js +21 -5
  125. package/scripts/mailer/index.js +17 -1
  126. package/scripts/mailer/resend-mailer.js +213 -179
  127. package/scripts/mcp-writeguard.js +158 -0
  128. package/scripts/migrate-project-scope.js +209 -0
  129. package/scripts/model-candidates.js +414 -0
  130. package/scripts/openrouter-armor-partnership-diode.js +2419 -0
  131. package/scripts/operational-dashboard.js +172 -0
  132. package/scripts/operational-integrity.js +436 -3
  133. package/scripts/operational-summary.js +190 -0
  134. package/scripts/operator-artifacts.js +622 -0
  135. package/scripts/optimize-context.js +17 -0
  136. package/scripts/override-audit.js +2 -0
  137. package/scripts/owner-admin.js +338 -0
  138. package/scripts/pr-manager.js +194 -1
  139. package/scripts/predictive-insights.js +449 -0
  140. package/scripts/profound-aeo-citation-engine.js +583 -0
  141. package/scripts/progressive-signoff.js +260 -0
  142. package/scripts/project-catalog.js +243 -0
  143. package/scripts/project-dashboard.js +61 -0
  144. package/scripts/project-evidence.js +172 -0
  145. package/scripts/project-identity.js +182 -0
  146. package/scripts/project-scope.js +381 -0
  147. package/scripts/prompt-guard.js +446 -52
  148. package/scripts/proof-report.js +232 -0
  149. package/scripts/provider-action-normalizer.js +14 -6
  150. package/scripts/pulse.js +80 -0
  151. package/scripts/rate-limiter.js +41 -0
  152. package/scripts/rrsi-doctor.js +2698 -0
  153. package/scripts/secret-redaction.js +171 -25
  154. package/scripts/secret-scanner.js +101 -42
  155. package/scripts/self-protection.js +2 -2
  156. package/scripts/seo-gsd.js +14 -14
  157. package/scripts/session-context-dedupe.js +66 -0
  158. package/scripts/session-report.js +120 -0
  159. package/scripts/settings-hierarchy.js +4 -2
  160. package/scripts/statusline-meta.js +34 -23
  161. package/scripts/subagent-profiles.js +79 -0
  162. package/scripts/task-outcomes.js +29 -2
  163. package/scripts/telemetry-analytics.js +238 -13
  164. package/scripts/third-author-cli.js +118 -0
  165. package/scripts/third-author-governance.js +437 -0
  166. package/scripts/thumbgate-dream.js +878 -0
  167. package/scripts/thumbgate-search.js +23 -9
  168. package/scripts/tool-kpi-tracker.js +5 -2
  169. package/scripts/tool-registry.js +42 -1
  170. package/scripts/triage-savings-calculator.js +1 -1
  171. package/scripts/vector-store.js +4 -1
  172. package/scripts/verified-lessons.js +270 -0
  173. package/scripts/verify-marketing-pages-deployed.js +2 -2
  174. package/scripts/workflow-sentinel.js +29 -10
  175. package/server.json +2 -2
  176. package/skills/thumbgate-daily-discoveries/SKILL.md +25 -41
  177. package/src/api/server.js +2371 -451
  178. package/src/feedback.js +21 -0
  179. package/src/hermes-sync-plane.js +2 -1
  180. package/src/index.js +2 -0
  181. package/src/lesson-search.js +9 -0
  182. package/src/mckinsey-top-company-ai-coding.js +493 -0
  183. package/src/mcp/server.js +3 -0
  184. package/src/mcp-writeguard.js +772 -11
  185. package/src/openshell-lovable-engine.js +1475 -0
  186. package/src/task-outcome.js +3 -0
  187. package/config/evals/agent-safety-eval.json +0 -447
  188. package/config/evals/retrieval-ranking-golden.json +0 -522
  189. package/config/progressive/01-wire-only.json +0 -11
  190. package/config/progressive/02-dashboard-empty-ok.json +0 -10
  191. package/config/progressive/03-one-lesson.json +0 -10
  192. package/config/progressive/04-warn-fires.json +0 -11
  193. package/config/progressive/05-strict-optional.json +0 -11
  194. package/config/progressive/README.md +0 -15
  195. package/public/assets/diagrams/agent-integration.png +0 -0
  196. package/public/assets/diagrams/thumbgate-architecture.png +0 -0
  197. package/scripts/install-thumbgate-daily-publish-launchd.sh +0 -83
  198. package/scripts/thumbgate-daily-discoveries-publish.js +0 -461
  199. package/scripts/thumbgate-daily-discoveries-publish.sh +0 -18
@@ -8,6 +8,7 @@
8
8
  */
9
9
 
10
10
  const crypto = require('node:crypto');
11
+ const { tenantDataScope, assertScopedDataPath } = require('./feedback-scope');
11
12
  const fs = require('fs');
12
13
  const path = require('path');
13
14
  const { loadOptionalModule } = require('./private-core-boundary');
@@ -47,6 +48,7 @@ const {
47
48
  } = require('./failure-diagnostics');
48
49
  const { getEffectiveSetting } = require('./evolution-state');
49
50
  const { ensureDir, readTextTail } = require('./fs-utils');
51
+ const { redactSecrets } = require('./secret-redaction');
50
52
  const {
51
53
  buildFeedbackPathsFromDir,
52
54
  getFeedbackPaths: resolveFeedbackPaths,
@@ -89,6 +91,7 @@ function isSelfHarnessOptimizerEnabled(env = process.env) {
89
91
  * - 2-second timeout via AbortSignal.timeout.
90
92
  */
91
93
  function emitAnonymousFeedbackPing(signal) {
94
+ if (tenantDataScope()) return;
92
95
  try {
93
96
  const env = process.env || {};
94
97
  if (
@@ -167,50 +170,28 @@ function isAuditTrailEntry(entry = {}) {
167
170
  }
168
171
 
169
172
  // Lesson DB — SQLite+FTS5 backing store (dual-write alongside JSONL)
170
- let _lessonDB = null;
171
- let _lessonDBPath = null;
172
-
173
- function resolveLessonDbPath() {
174
- if (process.env.LESSON_DB_PATH) return process.env.LESSON_DB_PATH;
175
- if (process.env.THUMBGATE_FEEDBACK_DIR || process.env.RAILWAY_VOLUME_MOUNT_PATH) {
176
- return path.join(getFeedbackPaths().FEEDBACK_DIR, 'lessons.sqlite');
177
- }
178
- return null;
179
- }
180
-
181
- function getLessonDB() {
182
- const desiredPath = resolveLessonDbPath();
183
- if (_lessonDB && _lessonDBPath === desiredPath) return _lessonDB;
184
-
185
- if (_lessonDB && _lessonDBPath !== desiredPath) {
186
- try {
187
- _lessonDB.close();
188
- } catch {
189
- // Non-critical; reopen on the new path below.
190
- }
191
- _lessonDB = null;
192
- _lessonDBPath = null;
193
- }
194
-
173
+ const lessonConnections = new Map();
174
+ function getLessonDB(options = {}) {
175
+ const scope = tenantDataScope();
176
+ const desiredPath = scope
177
+ ? assertScopedDataPath(path.join(getFeedbackPaths(options).FEEDBACK_DIR, 'lessons.sqlite'))
178
+ : path.resolve(options.feedbackDir ? path.join(options.feedbackDir, 'lessons.sqlite') : process.env.LESSON_DB_PATH || path.join(getFeedbackPaths(options).FEEDBACK_DIR, 'lessons.sqlite'));
179
+ // Tenant connections are request-owned and closed by their callers. Local
180
+ // explicit account roots retain the bounded per-path connection cache.
181
+ if (scope) {
182
+ try { return require('./lesson-db').initDB(desiredPath); } catch { return null; }
183
+ }
184
+ if (lessonConnections.has(desiredPath)) return lessonConnections.get(desiredPath);
195
185
  try {
196
- const { initDB } = require('./lesson-db');
197
- _lessonDB = desiredPath ? initDB(desiredPath) : initDB();
198
- _lessonDBPath = desiredPath;
199
- return _lessonDB;
200
- } catch (_err) {
201
- // Keep the DB path scoped to the active feedback root even when SQLite
202
- // cannot open (for example, native module ABI drift in local dev).
203
- if (desiredPath) {
204
- try {
205
- fs.mkdirSync(path.dirname(desiredPath), { recursive: true });
206
- fs.closeSync(fs.openSync(desiredPath, 'a'));
207
- _lessonDBPath = desiredPath;
208
- } catch {
209
- // Ignore file materialization failures and degrade gracefully below.
210
- }
186
+ const db = require('./lesson-db').initDB(desiredPath);
187
+ if (lessonConnections.size >= 32) {
188
+ const oldest = lessonConnections.keys().next().value;
189
+ lessonConnections.get(oldest).close();
190
+ lessonConnections.delete(oldest);
211
191
  }
212
- return null; // SQLite unavailable — degrade gracefully
213
- }
192
+ lessonConnections.set(desiredPath, db);
193
+ return db;
194
+ } catch { return null; }
214
195
  }
215
196
 
216
197
  // ML sequence tracking constants (ML-03)
@@ -270,7 +251,8 @@ function updateStatuslineWithLesson({ accepted, signal, memoryId, feedbackId, le
270
251
  fs.writeFileSync(cachePath, JSON.stringify(cache));
271
252
  try {
272
253
  const { refreshStatuslineCache } = require('./hook-thumbgate-cache-updater');
273
- refreshStatuslineCache(analyzeFeedback(), cachePath);
254
+ // Human-only: the status bar shows the owner's own thumbs, not agent captures.
255
+ refreshStatuslineCache(analyzeFeedback(undefined, { humanOnly: true }), cachePath);
274
256
  } catch {
275
257
  /* keep lesson refresh best-effort */
276
258
  }
@@ -338,9 +320,114 @@ function getMemoryFirewallModule() {
338
320
  }
339
321
 
340
322
 
323
+ const RECENT_THUMBS_CAP = 200;
324
+ const THUMB_EMAIL_RE = /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g;
325
+ const THUMB_PHONE_RE = /(?:\+\d{1,3}[\s.-]?)?(?:\(\d{3}\)|\b\d{3})[\s.-]\d{3}[\s.-]\d{4}\b/g;
326
+
327
+ function recentThumbsOutputPath() {
328
+ const scope = tenantDataScope();
329
+ if (scope) return assertScopedDataPath(path.join(scope.feedbackDir, 'RECENT-THUMBS.md'));
330
+ const override = process.env.THUMBGATE_RECENT_THUMBS_PATH;
331
+ if (override) return override;
332
+ if (process.env.THUMBGATE_RECENT_THUMBS_DISABLE === '1') return null;
333
+ if (process.env.NODE_TEST_CONTEXT) return null;
334
+ const home = process.env.HOME || process.env.USERPROFILE || '';
335
+ if (!home) return null;
336
+ return path.join(home, '.thumbgate', 'RECENT-THUMBS.md');
337
+ }
338
+
339
+ function scrubThumbSentence(text) {
340
+ let out = redactSecrets(String(text || ''));
341
+ if (typeof out !== 'string') out = String(text || '');
342
+ out = out.replace(THUMB_EMAIL_RE, '[REDACTED:email]');
343
+ out = out.replace(THUMB_PHONE_RE, '[REDACTED:phone]');
344
+ out = out.replace(/\s+/g, ' ').trim();
345
+ if (!out) return '';
346
+ const match = out.match(/^.*?[.!?](?:\s|$)/);
347
+ const sentence = (match ? match[0] : out).trim();
348
+ return /[.!?]$/.test(sentence) ? sentence : `${sentence}.`;
349
+ }
350
+
351
+ function formatThumbWhen(timestamp) {
352
+ const date = new Date(timestamp || 0);
353
+ if (Number.isNaN(date.getTime())) return 'time unknown';
354
+ const parts = new Intl.DateTimeFormat('en-US', {
355
+ timeZone: 'America/New_York',
356
+ year: 'numeric',
357
+ month: '2-digit',
358
+ day: '2-digit',
359
+ hour: 'numeric',
360
+ minute: '2-digit',
361
+ hour12: true,
362
+ }).formatToParts(date);
363
+ const get = (type) => parts.find((part) => part.type === type)?.value || '';
364
+ const hour = String(Number(get('hour')));
365
+ const period = get('dayPeriod').toUpperCase();
366
+ return `${get('year')}-${get('month')}-${get('day')} ${hour}:${get('minute')} ${period}`;
367
+ }
368
+
369
+ function thumbWord(signal) {
370
+ const normalized = normalizeSignal(signal);
371
+ if (normalized === 'negative') return 'down';
372
+ if (normalized === 'positive') return 'up';
373
+ return null;
374
+ }
375
+
376
+ function renderRecentThumbLine(record) {
377
+ if (!record || typeof record !== 'object') return null;
378
+ const word = thumbWord(record.signal);
379
+ if (!word) return null;
380
+ const wrong = scrubThumbSentence(record.whatWentWrong || record.context || record.whatWorked || '');
381
+ if (!wrong) return null;
382
+ const claim = scrubThumbSentence(record.whatToChange || '') || 'No corrected claim was recorded.';
383
+ return `- ${formatThumbWhen(record.timestamp)}, ${word}: ${wrong} Corrected claim: ${claim}`;
384
+ }
385
+
386
+ function renderRecentThumbs(records) {
387
+ const ranked = (Array.isArray(records) ? records : [])
388
+ .map((record, index) => ({ record, index, at: Date.parse(record && record.timestamp) || 0 }))
389
+ .sort((a, b) => (b.at - a.at) || (b.index - a.index));
390
+ const lines = [];
391
+ const seen = new Set();
392
+ for (const item of ranked) {
393
+ const line = renderRecentThumbLine(item.record);
394
+ if (!line) continue;
395
+ const id = item.record && item.record.id ? String(item.record.id) : '';
396
+ if ((id && seen.has(`id:${id}`)) || seen.has(line)) continue;
397
+ if (id) seen.add(`id:${id}`);
398
+ seen.add(line);
399
+ lines.push(line);
400
+ if (lines.length >= RECENT_THUMBS_CAP) break;
401
+ }
402
+ const header = '# Recent thumbs\n\nNewest first. One sentence each, with the claim it corrected.\n\n';
403
+ return `${header}${lines.join('\n') || '- No thumbs recorded.'}\n`;
404
+ }
405
+
406
+ function syncRecentThumbsFromLog(logPath) {
407
+ try {
408
+ const outPath = recentThumbsOutputPath();
409
+ if (!outPath || !logPath) return false;
410
+ const text = renderRecentThumbs(readJSONL(logPath));
411
+ ensureDir(path.dirname(outPath));
412
+ if (fs.existsSync(outPath) && fs.readFileSync(outPath, 'utf8') === text) return false;
413
+ fs.writeFileSync(outPath, text);
414
+ return true;
415
+ } catch {
416
+ return false;
417
+ }
418
+ }
419
+
341
420
  function appendJSONL(filePath, record) {
342
421
  ensureDir(path.dirname(filePath));
343
422
  fs.appendFileSync(filePath, `${JSON.stringify(record)}\n`);
423
+ try {
424
+ const expected = getFeedbackPaths().FEEDBACK_LOG_PATH;
425
+ if (path.resolve(String(filePath)) === path.resolve(expected)) {
426
+ syncRecentThumbsFromLog(filePath);
427
+ }
428
+ } catch {
429
+ /* a thumb export must not fail the capture that just landed */
430
+ }
344
431
  }
345
432
 
346
433
  function normalizeAnalysisShape(analysis = {}) {
@@ -409,7 +496,7 @@ function findDuplicateMemory(memoryLogPath, newRecord) {
409
496
 
410
497
  const existing = readJSONL(memoryLogPath, { maxLines: 0 });
411
498
  for (let i = existing.length - 1; i >= 0; i--) {
412
- if (existing[i].sourceFeedbackId === feedbackId) return existing[i];
499
+ if (existing[i].sourceFeedbackId === feedbackId && require('./project-identity').matchesProject(existing[i], require('./project-identity').projectForRecord(newRecord).projectKey)) return existing[i];
413
500
  }
414
501
  return null;
415
502
  }
@@ -426,8 +513,8 @@ function toStoredDiagnosis(diagnosis) {
426
513
  };
427
514
  }
428
515
 
429
- function appendRejectionLedger(feedbackEvent, reason) {
430
- const { REJECTION_LEDGER_PATH } = getFeedbackPaths();
516
+ function appendRejectionLedger(feedbackEvent, reason, options = {}) {
517
+ const { REJECTION_LEDGER_PATH } = getFeedbackPaths(options);
431
518
  appendJSONL(REJECTION_LEDGER_PATH, {
432
519
  id: feedbackEvent.id,
433
520
  signal: feedbackEvent.signal,
@@ -491,14 +578,15 @@ function listEnforcementMatrix() {
491
578
  };
492
579
  }
493
580
 
494
- function appendDiagnosticRecord(params = {}) {
495
- const { DIAGNOSTIC_LOG_PATH } = getFeedbackPaths();
581
+ function appendDiagnosticRecord(params = {}, options = {}) {
582
+ const { DIAGNOSTIC_LOG_PATH } = getFeedbackPaths(options);
496
583
  const storedDiagnosis = toStoredDiagnosis(params.diagnosis);
497
584
  if (!storedDiagnosis) {
498
585
  return null;
499
586
  }
500
587
 
501
588
  const record = {
589
+ ...require('./project-identity').projectForRecord(params),
502
590
  id: `diag_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
503
591
  source: params.source || 'system',
504
592
  step: params.step || storedDiagnosis.criticalFailureStep || null,
@@ -510,7 +598,7 @@ function appendDiagnosticRecord(params = {}) {
510
598
  appendJSONL(DIAGNOSTIC_LOG_PATH, record);
511
599
  try {
512
600
  const { trainAndPersistInterventionPolicy } = require('./intervention-policy');
513
- trainAndPersistInterventionPolicy(getFeedbackPaths().FEEDBACK_DIR);
601
+ trainAndPersistInterventionPolicy(getFeedbackPaths(options).FEEDBACK_DIR);
514
602
  } catch { /* non-critical */ }
515
603
  return record;
516
604
  }
@@ -542,7 +630,7 @@ function buildMemoryFirewallViolations(decision = {}) {
542
630
  }));
543
631
  }
544
632
 
545
- function maybeBlockMemoryIngress({ feedbackEvent, memoryRecord = null, summary, now }) {
633
+ function maybeBlockMemoryIngress({ feedbackEvent, memoryRecord = null, summary, now, options = {} }) {
546
634
  const memoryFirewall = getMemoryFirewallModule();
547
635
  if (!memoryFirewall || typeof memoryFirewall.evaluateMemoryIngress !== 'function') {
548
636
  return null;
@@ -559,6 +647,7 @@ function maybeBlockMemoryIngress({ feedbackEvent, memoryRecord = null, summary,
559
647
  }
560
648
 
561
649
  appendDiagnosticRecord({
650
+ ...require('./project-identity').projectForRecord(feedbackEvent),
562
651
  source: 'memory_firewall',
563
652
  step: 'memory_ingress',
564
653
  context: decision.redactedPreview || '',
@@ -581,11 +670,11 @@ function maybeBlockMemoryIngress({ feedbackEvent, memoryRecord = null, summary,
581
670
  ...(decision.threatIndicators || []),
582
671
  ].filter(Boolean),
583
672
  },
584
- });
673
+ }, options);
585
674
 
586
675
  summary.rejected += 1;
587
676
  summary.lastUpdated = now;
588
- saveSummary(summary);
677
+ saveSummary(summary, options);
589
678
 
590
679
  return {
591
680
  accepted: false,
@@ -638,6 +727,7 @@ function getPendingBackgroundSideEffectCount() {
638
727
  }
639
728
 
640
729
  function readJSONL(filePath, { maxLines = 500, maxBytes = 4 * 1024 * 1024 } = {}) {
730
+ assertScopedDataPath(filePath);
641
731
  if (!fs.existsSync(filePath)) return [];
642
732
  // Always go through readTextTail. A maxLines slice after readFileSync still
643
733
  // materializes the whole file and throws on prod-sized JSONL (0x1fffffe8).
@@ -955,8 +1045,8 @@ function parseOptionalObject(input, name) {
955
1045
  throw new Error(`${name} must be object or JSON string`);
956
1046
  }
957
1047
 
958
- function loadSummary() {
959
- const { SUMMARY_PATH } = getFeedbackPaths();
1048
+ function loadSummary(options = {}) {
1049
+ const { SUMMARY_PATH } = getFeedbackPaths(options);
960
1050
  if (!fs.existsSync(SUMMARY_PATH)) {
961
1051
  return {
962
1052
  total: 0,
@@ -970,8 +1060,8 @@ function loadSummary() {
970
1060
  return JSON.parse(fs.readFileSync(SUMMARY_PATH, 'utf-8'));
971
1061
  }
972
1062
 
973
- function saveSummary(summary) {
974
- const { SUMMARY_PATH } = getFeedbackPaths();
1063
+ function saveSummary(summary, options = {}) {
1064
+ const { SUMMARY_PATH } = getFeedbackPaths(options);
975
1065
  ensureDir(path.dirname(SUMMARY_PATH));
976
1066
  fs.writeFileSync(SUMMARY_PATH, `${JSON.stringify(summary, null, 2)}\n`);
977
1067
  }
@@ -1282,9 +1372,11 @@ function inferLessonFromConversation(conversationWindow, signal) {
1282
1372
  };
1283
1373
  }
1284
1374
 
1285
- function captureFeedback(params) {
1375
+ function captureFeedback(params, options = {}) {
1376
+ options = { ...options, hosted: options.hosted || Boolean(tenantDataScope()) };
1286
1377
  const _captureStart = Date.now();
1287
- const { FEEDBACK_LOG_PATH, MEMORY_LOG_PATH, FEEDBACK_DIR } = getFeedbackPaths();
1378
+ const project = require('./project-identity').projectForCapture(params, options);
1379
+ const { FEEDBACK_LOG_PATH, MEMORY_LOG_PATH, FEEDBACK_DIR } = getFeedbackPaths(options);
1288
1380
  const signal = normalizeSignal(params.signal);
1289
1381
  if (!signal) {
1290
1382
  return {
@@ -1293,6 +1385,26 @@ function captureFeedback(params) {
1293
1385
  };
1294
1386
  }
1295
1387
 
1388
+ const { isTranscriptShaped, resolveProjectFromCwd } = require('./project-scope');
1389
+ if (isTranscriptShaped(params)) {
1390
+ return {
1391
+ accepted: false,
1392
+ reason: 'Rejected: feedback payload contains raw transport transcript tokens (<task-notification>, <tool-use-id>, etc.)',
1393
+ };
1394
+ }
1395
+
1396
+ // Record vote on lesson if lessonId or lessonKey is provided
1397
+ const targetLessonId = params.lessonId || params.lessonKey;
1398
+ let lessonVoteResult = null;
1399
+ if (targetLessonId) {
1400
+ try {
1401
+ const { voteOnLesson } = require('./verified-lessons');
1402
+ lessonVoteResult = voteOnLesson(targetLessonId, signal, { feedbackDir: options.feedbackDir || FEEDBACK_DIR });
1403
+ } catch (_voteErr) {
1404
+ /* lesson voting is non-blocking */
1405
+ }
1406
+ }
1407
+
1296
1408
  const submittedContext = params.context || '';
1297
1409
  const distillation = distillFeedbackHistory({
1298
1410
  signal,
@@ -1305,6 +1417,7 @@ function captureFeedback(params) {
1305
1417
  allowLocalConversationFallback: params.allowLocalConversationFallback === true,
1306
1418
  lastAction: params.lastAction,
1307
1419
  feedbackDir: FEEDBACK_DIR,
1420
+ projectKey: project.projectKey,
1308
1421
  });
1309
1422
 
1310
1423
  const shouldUseDistilledContext = !submittedContext || isGenericFeedbackText(submittedContext, signal);
@@ -1405,12 +1518,31 @@ function captureFeedback(params) {
1405
1518
  : null;
1406
1519
 
1407
1520
  const now = new Date().toISOString();
1521
+ const effectiveCwd = params.cwd || options.cwd || process.cwd();
1522
+ const detectedProject = options.hosted ? null : resolveProjectFromCwd(effectiveCwd);
1523
+ const normalizedScope = require('./memory-scope-readiness').normalizeScope(params);
1524
+ if (!normalizedScope.projectId && detectedProject) normalizedScope.projectId = detectedProject;
1525
+ if (!normalizedScope.processId) normalizedScope.processId = 'agent';
1526
+ if (!normalizedScope.sessionId) normalizedScope.sessionId = `session_${Date.now()}`;
1527
+
1528
+ const feedbackToolName = params.lastAction?.tool || params.tool || params.toolName || 'unknown';
1529
+ const feedbackFailureClass = params.failureType || params.errorType || (signal === 'negative' ? 'execution' : 'success');
1530
+ const metadata = {
1531
+ ...(params.metadata || {}),
1532
+ project: normalizedScope.projectId,
1533
+ repo: normalizedScope.projectId,
1534
+ tool: feedbackToolName,
1535
+ failureClass: feedbackFailureClass,
1536
+ };
1537
+
1408
1538
  const rawFeedbackEvent = {
1539
+ ...project,
1409
1540
  id: `fb_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
1410
1541
  signal,
1411
1542
  context,
1412
1543
  submittedContext,
1413
- scope: require('./memory-scope-readiness').normalizeScope(params),
1544
+ scope: normalizedScope,
1545
+ metadata,
1414
1546
  relatedFeedbackId: params.relatedFeedbackId || null,
1415
1547
  lastAction,
1416
1548
  whatWentWrong,
@@ -1492,16 +1624,16 @@ function captureFeedback(params) {
1492
1624
  }
1493
1625
  const historyEntries = readJSONL(FEEDBACK_LOG_PATH).slice(-SEQUENCE_WINDOW);
1494
1626
 
1495
- const summary = loadSummary();
1627
+ const summary = loadSummary(options);
1496
1628
  // Only count real user feedback in the summary, not audit-trail gate events
1497
1629
  const isAuditEntry = Array.isArray(tags) && tags.includes(AUDIT_TRAIL_TAG);
1498
- if (!isAuditEntry) {
1630
+ if (!tenantDataScope() && !isAuditEntry) {
1499
1631
  summary.total += 1;
1500
1632
  summary[signal] += 1;
1501
1633
  }
1502
1634
 
1503
1635
  if (action.type === 'no-action') {
1504
- const firewallBlocked = maybeBlockMemoryIngress({ feedbackEvent, summary, now });
1636
+ const firewallBlocked = maybeBlockMemoryIngress({ feedbackEvent, summary, now, options });
1505
1637
  if (firewallBlocked) {
1506
1638
  return firewallBlocked;
1507
1639
  }
@@ -1514,12 +1646,12 @@ function captureFeedback(params) {
1514
1646
  });
1515
1647
  summary.rejected += 1;
1516
1648
  summary.lastUpdated = now;
1517
- saveSummary(summary);
1649
+ saveSummary(summary, options);
1518
1650
  appendJSONL(FEEDBACK_LOG_PATH, feedbackEvent);
1519
1651
  emitAnonymousFeedbackPing(signal);
1520
- try { appendRejectionLedger(feedbackEvent, action.reason); } catch { /* non-critical */ }
1652
+ try { appendRejectionLedger(feedbackEvent, action.reason, options); } catch { /* non-critical */ }
1521
1653
  try {
1522
- appendSequence(historyEntries, feedbackEvent, getFeedbackPaths(), { accepted: false });
1654
+ appendSequence(historyEntries, feedbackEvent, getFeedbackPaths(options), { accepted: false });
1523
1655
  } catch { /* non-critical */ }
1524
1656
  try {
1525
1657
  const riskScorer = getRiskScorerModule();
@@ -1537,6 +1669,8 @@ function captureFeedback(params) {
1537
1669
  return {
1538
1670
  accepted: true,
1539
1671
  captured: true,
1672
+ success: true,
1673
+ lessonVote: lessonVoteResult,
1540
1674
  promoted: false,
1541
1675
  promotionAccepted: false,
1542
1676
  signalLogged: true,
@@ -1577,7 +1711,7 @@ function captureFeedback(params) {
1577
1711
  if (hardIssues.length > 0) {
1578
1712
  summary.rejected += 1;
1579
1713
  summary.lastUpdated = now;
1580
- saveSummary(summary);
1714
+ saveSummary(summary, options);
1581
1715
  const blockedEvent = {
1582
1716
  ...feedbackEvent,
1583
1717
  lifecycleDecision: lifecycle.decision,
@@ -1605,21 +1739,21 @@ function captureFeedback(params) {
1605
1739
 
1606
1740
  const prepared = prepareForStorage(action.memory);
1607
1741
  if (!prepared.ok) {
1608
- const firewallBlocked = maybeBlockMemoryIngress({ feedbackEvent, summary, now });
1742
+ const firewallBlocked = maybeBlockMemoryIngress({ feedbackEvent, summary, now, options });
1609
1743
  if (firewallBlocked) {
1610
1744
  return firewallBlocked;
1611
1745
  }
1612
1746
  summary.rejected += 1;
1613
1747
  summary.lastUpdated = now;
1614
- saveSummary(summary);
1748
+ saveSummary(summary, options);
1615
1749
  appendJSONL(FEEDBACK_LOG_PATH, {
1616
1750
  ...feedbackEvent,
1617
1751
  validationIssues: prepared.issues,
1618
1752
  });
1619
1753
  emitAnonymousFeedbackPing(signal);
1620
- try { appendRejectionLedger(feedbackEvent, `Schema validation failed: ${prepared.issues.join('; ')}`); } catch { /* non-critical */ }
1754
+ try { appendRejectionLedger(feedbackEvent, `Schema validation failed: ${prepared.issues.join('; ')}`, options); } catch { /* non-critical */ }
1621
1755
  try {
1622
- appendSequence(historyEntries, feedbackEvent, getFeedbackPaths(), { accepted: false });
1756
+ appendSequence(historyEntries, feedbackEvent, getFeedbackPaths(options), { accepted: false });
1623
1757
  } catch { /* non-critical */ }
1624
1758
  try {
1625
1759
  const riskScorer = getRiskScorerModule();
@@ -1641,15 +1775,25 @@ function captureFeedback(params) {
1641
1775
  }
1642
1776
 
1643
1777
  const memoryRecord = {
1778
+ ...project,
1644
1779
  id: `mem_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
1645
1780
  ...prepared.memory,
1646
1781
  scope: feedbackEvent.scope,
1782
+ metadata: feedbackEvent.metadata || null,
1647
1783
  richContext: feedbackEvent.richContext || null,
1648
1784
  distillation: feedbackEvent.distillation || null,
1649
1785
  diagnosis: storedDiagnosis,
1650
1786
  structuredRule: structuredRule || null,
1651
1787
  sourceFeedbackId: feedbackEvent.id,
1652
1788
  reviewOrigin: feedbackEvent.reviewOrigin,
1789
+ verificationStatus: 'unverified',
1790
+ verifications: [],
1791
+ verificationCount: 0,
1792
+ lastVerifiedAt: null,
1793
+ upVotes: 0,
1794
+ downVotes: 0,
1795
+ netVotes: 0,
1796
+ demoted: false,
1653
1797
  timestamp: now,
1654
1798
  };
1655
1799
 
@@ -1665,7 +1809,7 @@ function captureFeedback(params) {
1665
1809
  // Bayesian Belief Update (Project Bayes)
1666
1810
  try {
1667
1811
  const { updateBelief, shouldPrune } = require('./belief-update');
1668
- const existingMemories = readJSONL(MEMORY_LOG_PATH);
1812
+ const existingMemories = require('./project-catalog').readProjectRows(FEEDBACK_DIR, 'memory-log.jsonl', { projectKey: project.projectKey });
1669
1813
  const similarMemory = existingMemories.slice().reverse().find(m =>
1670
1814
  m.tags && m.tags.some(t => memoryRecord.tags.includes(t) && !GENERIC_TAGS.has(t))
1671
1815
  );
@@ -1683,6 +1827,7 @@ function captureFeedback(params) {
1683
1827
  } catch (_err) { /* bayesian update is non-blocking */ }
1684
1828
 
1685
1829
  const firewallBlocked = maybeBlockMemoryIngress({
1830
+ options,
1686
1831
  feedbackEvent,
1687
1832
  memoryRecord,
1688
1833
  summary,
@@ -1737,7 +1882,7 @@ function captureFeedback(params) {
1737
1882
  // memory-log rather than feedback-log because memory records
1738
1883
  // carry the richer title/content fields the validator scores
1739
1884
  // against, and findSimilarLesson already reads this file.
1740
- const recentEvents = readJSONL(MEMORY_LOG_PATH).slice(-50);
1885
+ const recentEvents = require('./project-catalog').readProjectRows(FEEDBACK_DIR, 'memory-log.jsonl', { projectKey: project.projectKey }).slice(-50);
1741
1886
  validation = validateProposedRule(rule, {
1742
1887
  seedLesson: merged,
1743
1888
  recentEvents,
@@ -1785,8 +1930,9 @@ function captureFeedback(params) {
1785
1930
 
1786
1931
  // Dual-write to SQLite lesson DB — deferred to avoid blocking response
1787
1932
  let correctiveActions = [];
1933
+ let lessonDB;
1788
1934
  try {
1789
- const lessonDB = getLessonDB();
1935
+ lessonDB = getLessonDB(options);
1790
1936
  if (lessonDB) {
1791
1937
  const { upsertLesson, inferCorrectiveActions } = require('./lesson-db');
1792
1938
  upsertLesson(lessonDB, feedbackEvent, memoryRecord);
@@ -1796,6 +1942,8 @@ function captureFeedback(params) {
1796
1942
  }
1797
1943
  } catch (_err) {
1798
1944
  // Lesson DB write is non-critical — never fail the capture pipeline
1945
+ } finally {
1946
+ if (tenantDataScope() && lessonDB) lessonDB.close();
1799
1947
  }
1800
1948
 
1801
1949
  try {
@@ -1814,7 +1962,7 @@ function captureFeedback(params) {
1814
1962
 
1815
1963
  summary.accepted += 1;
1816
1964
  summary.lastUpdated = now;
1817
- saveSummary(summary);
1965
+ saveSummary(summary, options);
1818
1966
 
1819
1967
  const _captureMs = Date.now() - _captureStart;
1820
1968
 
@@ -1887,7 +2035,7 @@ function captureFeedback(params) {
1887
2035
  });
1888
2036
 
1889
2037
  // --- Synchronous side-effects (fast, needed by analyzeFeedback) ---
1890
- const mlPaths = getFeedbackPaths();
2038
+ const mlPaths = getFeedbackPaths(options);
1891
2039
  try {
1892
2040
  appendSequence(historyEntries, feedbackEvent, mlPaths, { accepted: true });
1893
2041
  } catch { /* Sequence tracking failure is non-critical */ }
@@ -1898,6 +2046,13 @@ function captureFeedback(params) {
1898
2046
  const riskScorer = getRiskScorerModule();
1899
2047
  if (riskScorer) riskScorer.trainAndPersistRiskModel(FEEDBACK_DIR);
1900
2048
  } catch { /* non-critical */ }
2049
+ try {
2050
+ const { stageCandidateBrandRuleFromFeedback } = require('./brand-standards-gate');
2051
+ const candidateRule = stageCandidateBrandRuleFromFeedback(feedbackEvent, { feedbackDir: FEEDBACK_DIR });
2052
+ if (candidateRule) {
2053
+ result.candidateBrandRule = candidateRule;
2054
+ }
2055
+ } catch { /* brand rule candidate learning is non-blocking */ }
1901
2056
  try {
1902
2057
  const { trainAndPersistInterventionPolicy } = require('./intervention-policy');
1903
2058
  trainAndPersistInterventionPolicy(FEEDBACK_DIR);
@@ -1940,7 +2095,7 @@ function captureFeedback(params) {
1940
2095
  // Prompt-file mutation and git commits are explicit opt-in side effects.
1941
2096
  // Feedback capture must never detach an unrequested process that edits
1942
2097
  // AGENTS.md/GEMINI.md merely because a negative rule was promoted.
1943
- if (isSelfHarnessOptimizerEnabled()) {
2098
+ if (!tenantDataScope() && isSelfHarnessOptimizerEnabled()) {
1944
2099
  try {
1945
2100
  const { fork } = require('node:child_process');
1946
2101
  const localOptimizerPath = path.join(process.cwd(), 'scripts', 'self-harness-optimizer.js');
@@ -1960,7 +2115,7 @@ function captureFeedback(params) {
1960
2115
  }
1961
2116
 
1962
2117
  // Auto-export to Obsidian if configured (deferred but tracked)
1963
- if (process.env.THUMBGATE_OBSIDIAN_VAULT_PATH) {
2118
+ if (!tenantDataScope() && process.env.THUMBGATE_OBSIDIAN_VAULT_PATH) {
1964
2119
  const exportPromise = new Promise((resolve) => {
1965
2120
  setImmediate(() => {
1966
2121
  try {
@@ -2012,16 +2167,19 @@ function captureFeedback(params) {
2012
2167
  return result;
2013
2168
  }
2014
2169
 
2015
- function captureFeedbackIdempotent(params = {}) {
2016
- const paths = getFeedbackPaths();
2170
+ function captureFeedbackIdempotent(params = {}, options = {}) {
2171
+ options = { ...options, hosted: options.hosted || Boolean(tenantDataScope()) };
2172
+ const paths = getFeedbackPaths(options);
2173
+ const project = require('./project-identity').projectForCapture(params, options);
2017
2174
  const identity = normalizeFeedbackSourceIdentity(params.sourceEvent, params);
2018
- if (!identity) return captureFeedback(params);
2175
+ if (identity) { identity.key = 'fev_' + hashFeedbackSourcePart(project.projectKey + ':' + identity.key); identity.projectHash = hashFeedbackSourcePart(project.projectKey); }
2176
+ if (!identity) return captureFeedback(params, options);
2019
2177
 
2020
2178
  const claim = acquireFeedbackEventClaim(identity, paths);
2021
2179
  if (!claim.owned) return claim.result;
2022
2180
 
2023
2181
  try {
2024
- const result = captureFeedback({ ...params, sourceEvent: identity });
2182
+ const result = captureFeedback({ ...params, sourceEvent: identity }, options);
2025
2183
  finalizeFeedbackEventClaim(claim, result);
2026
2184
  return result;
2027
2185
  } catch (error) {
@@ -2258,14 +2416,17 @@ function addDiagnosticRecs(diagnostics, output) {
2258
2416
  }
2259
2417
 
2260
2418
  function getSQLiteFallback(useSQLite, entries) {
2261
- const db = useSQLite ? getLessonDB() : null;
2262
- if (!db || entries.length > 0) return null;
2419
+ if (!useSQLite || entries.length > 0) return null;
2420
+ const db = getLessonDB();
2421
+ if (!db) return null;
2263
2422
  try {
2264
2423
  const { getStatsFromDB } = require('./lesson-db');
2265
2424
  const sqliteStats = getStatsFromDB(db);
2266
2425
  return sqliteStats.total > 0 ? normalizeAnalysisShape(sqliteStats) : null;
2267
2426
  } catch {
2268
2427
  return null;
2428
+ } finally {
2429
+ if (tenantDataScope()) db.close();
2269
2430
  }
2270
2431
  }
2271
2432
 
@@ -2274,7 +2435,7 @@ function analyzeFeedback(logPath, options = {}) {
2274
2435
  const resolvedPath = logPath || FEEDBACK_LOG_PATH;
2275
2436
  const feedbackDir = path.dirname(resolvedPath);
2276
2437
  const paths = buildFeedbackPathsFromDir(feedbackDir);
2277
- const useSQLite = !options.humanOnly && (!logPath || path.resolve(resolvedPath) === path.resolve(FEEDBACK_LOG_PATH));
2438
+ const useSQLite = options.projectKey == null && !options.humanOnly && (!logPath || path.resolve(resolvedPath) === path.resolve(FEEDBACK_LOG_PATH));
2278
2439
  // Prefer caller-supplied entries (dashboard already bounded the read).
2279
2440
  let entries = Array.isArray(options.entries)
2280
2441
  ? options.entries.slice()
@@ -2282,6 +2443,7 @@ function analyzeFeedback(logPath, options = {}) {
2282
2443
  maxLines: Number(options.maxLines) > 0 ? Number(options.maxLines) : 20_000,
2283
2444
  maxBytes: Number(options.maxBytes) > 0 ? Number(options.maxBytes) : 4 * 1024 * 1024,
2284
2445
  });
2446
+ if (options.projectKey != null) entries = require('./project-catalog').readProjectRows(feedbackDir, 'feedback-log.jsonl', options);
2285
2447
  const rawTotal = entries.length;
2286
2448
  if (options.humanOnly) {
2287
2449
  entries = entries.filter((entry) => normalizeReviewOrigin(entry.reviewOrigin) === 'human');
@@ -2289,7 +2451,9 @@ function analyzeFeedback(logPath, options = {}) {
2289
2451
  const fallback = getSQLiteFallback(useSQLite, entries);
2290
2452
  if (fallback) return fallback;
2291
2453
 
2292
- const diagnosticEntries = readDiagnosticEntries(path.join(feedbackDir, 'diagnostic-log.jsonl'));
2454
+ const diagnosticEntries = options.projectKey != null
2455
+ ? require('./project-catalog').readProjectRows(feedbackDir, 'diagnostic-log.jsonl', options)
2456
+ : readDiagnosticEntries(path.join(feedbackDir, 'diagnostic-log.jsonl'));
2293
2457
  const summary = summarizeFeedbackEntries(entries);
2294
2458
  const { skills, tags, criteria, samples, blocked, positive, negative } = summary;
2295
2459
  const total = positive + negative;
@@ -2303,9 +2467,9 @@ function analyzeFeedback(logPath, options = {}) {
2303
2467
  addSkillRecs(skills, recs);
2304
2468
  addTagRecs(tags, recs);
2305
2469
  addTrendRecs({ recent, recentRate, approvalRate, trend, rate7d, rate30d }, recs);
2306
- const boostedRisk = addRiskRecs(paths.FEEDBACK_DIR, recs);
2470
+ const boostedRisk = options.projectKey != null ? null : addRiskRecs(paths.FEEDBACK_DIR, recs);
2307
2471
  const diagnostics = aggregateFailureDiagnostics([...entries, ...diagnosticEntries]);
2308
- const delegation = addDelegationRecs(paths.FEEDBACK_DIR, recs);
2472
+ const delegation = options.projectKey != null ? null : addDelegationRecs(paths.FEEDBACK_DIR, recs);
2309
2473
  addDiagnosticRecs(diagnostics, recs);
2310
2474
 
2311
2475
  return normalizeAnalysisShape({
@@ -2585,7 +2749,7 @@ function writePreventionRules(filePath, minOccurrences = 2) {
2585
2749
 
2586
2750
  function feedbackSummary(recentN = 20, options = {}) {
2587
2751
  const { FEEDBACK_LOG_PATH } = getFeedbackPaths(options);
2588
- let entries = readJSONL(FEEDBACK_LOG_PATH);
2752
+ let entries = require('./project-catalog').readProjectRows(path.dirname(FEEDBACK_LOG_PATH), 'feedback-log.jsonl', options);
2589
2753
  if (options.humanOnly) {
2590
2754
  entries = entries.filter((entry) => normalizeReviewOrigin(entry.reviewOrigin) === 'human');
2591
2755
  }
@@ -2598,7 +2762,7 @@ function feedbackSummary(recentN = 20, options = {}) {
2598
2762
  const negative = recent.filter((e) => e.signal === 'negative').length;
2599
2763
  const pct = Math.round((positive / recent.length) * 100);
2600
2764
 
2601
- const analysis = analyzeFeedback(FEEDBACK_LOG_PATH, { humanOnly: options.humanOnly });
2765
+ const analysis = analyzeFeedback(FEEDBACK_LOG_PATH, options);
2602
2766
 
2603
2767
  const lines = [
2604
2768
  `## Feedback Summary (last ${recent.length})`,
@@ -2829,6 +2993,8 @@ module.exports = {
2829
2993
  feedbackSummary,
2830
2994
  listEnforcementMatrix,
2831
2995
  readJSONL,
2996
+ renderRecentThumbs,
2997
+ syncRecentThumbsFromLog,
2832
2998
  appendDiagnosticRecord,
2833
2999
  readDiagnosticEntries,
2834
3000
  getFeedbackPaths,