@productbrain/mcp 0.0.1-beta.958 → 0.0.1-beta.978

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.
@@ -4263,6 +4263,25 @@ function sanitizeEntryData(data) {
4263
4263
  );
4264
4264
  return Object.keys(filtered).length > 0 ? filtered : void 0;
4265
4265
  }
4266
+ function renderWhyLine(e) {
4267
+ const why = typeof e.why === "string" ? e.why : "";
4268
+ if (e.whyQuality === "missing") {
4269
+ return { line: `**Why:** \u2014 (no rationale captured)`, why, whySourceKey: null };
4270
+ }
4271
+ if (why.length > 0) {
4272
+ const suffix = e.whyQuality === "restated" ? " (restated)" : "";
4273
+ const d = e.data ?? {};
4274
+ let whySourceKey = null;
4275
+ const kf = e.whyField;
4276
+ if ((kf === "rationale" || kf === "description") && typeof d[kf] === "string" && d[kf].trim().length > 0) {
4277
+ whySourceKey = kf;
4278
+ } else if (typeof d.rationale === "string" && d.rationale.trim().length > 0) {
4279
+ whySourceKey = "rationale";
4280
+ }
4281
+ return { line: `**Why:** ${why}${suffix}`, why, whySourceKey };
4282
+ }
4283
+ return { line: null, why, whySourceKey: null };
4284
+ }
4266
4285
  var ENTRIES_ACTIONS = ["list", "get", "batch", "search"];
4267
4286
  var entriesSchema = z4.object({
4268
4287
  action: z4.enum(ENTRIES_ACTIONS).describe(
@@ -4291,6 +4310,9 @@ var entriesGetOutputSchema = z4.object({
4291
4310
  verificationStatus: z4.string().optional(),
4292
4311
  sourceRef: z4.string().optional(),
4293
4312
  sourceExcerpt: z4.string().optional(),
4313
+ why: z4.string().optional(),
4314
+ // TEN-2191: quality of the captured WHY — 'rationale' | 'missing' | 'restated'.
4315
+ whyQuality: z4.enum(["rationale", "missing", "restated"]).optional(),
4294
4316
  data: z4.record(z4.unknown()).optional(),
4295
4317
  relations: z4.array(z4.object({
4296
4318
  entryId: z4.string().optional(),
@@ -4299,7 +4321,7 @@ var entriesGetOutputSchema = z4.object({
4299
4321
  direction: z4.string()
4300
4322
  })).optional(),
4301
4323
  labels: z4.array(z4.string()).optional()
4302
- });
4324
+ }).passthrough();
4303
4325
  var entriesListOutputSchema = z4.object({
4304
4326
  entries: z4.array(z4.object({
4305
4327
  entryId: z4.string(),
@@ -4332,8 +4354,11 @@ var entriesBatchOutputSchema = z4.object({
4332
4354
  verificationStatus: z4.string().optional(),
4333
4355
  sourceRef: z4.string().optional(),
4334
4356
  sourceExcerpt: z4.string().optional(),
4357
+ // TEN-2191: mirror entriesGetOutputSchema — batch entries now carry why/whyQuality.
4358
+ why: z4.string().optional(),
4359
+ whyQuality: z4.enum(["rationale", "missing", "restated"]).optional(),
4335
4360
  data: z4.record(z4.unknown()).optional()
4336
- })),
4361
+ }).passthrough()),
4337
4362
  total: z4.number()
4338
4363
  });
4339
4364
  function registerEntriesTools(server) {
@@ -4419,10 +4444,13 @@ async function handleGet(entryId) {
4419
4444
  if (epistemic) {
4420
4445
  lines.push(formatEpistemicLine(epistemic));
4421
4446
  }
4447
+ const { line: whyLine, why, whySourceKey } = renderWhyLine(e);
4448
+ if (whyLine !== null) lines.push(whyLine);
4422
4449
  const visibleData = sanitizeEntryData(e.data);
4423
- if (visibleData) {
4450
+ const filteredData = visibleData && whySourceKey ? Object.keys(visibleData).filter((k) => k !== whySourceKey).length > 0 ? Object.fromEntries(Object.entries(visibleData).filter(([k]) => k !== whySourceKey)) : void 0 : visibleData;
4451
+ if (filteredData) {
4424
4452
  lines.push("");
4425
- for (const [key, val] of Object.entries(visibleData)) {
4453
+ for (const [key, val] of Object.entries(filteredData)) {
4426
4454
  const display = typeof val === "string" ? val : JSON.stringify(val);
4427
4455
  lines.push(`**${key}:** ${display}`);
4428
4456
  }
@@ -4463,8 +4491,17 @@ async function handleGet(entryId) {
4463
4491
  ...e.verificationStatus ? { verificationStatus: String(e.verificationStatus) } : {},
4464
4492
  ...e.sourceRef ? { sourceRef: String(e.sourceRef) } : {},
4465
4493
  ...e.sourceExcerpt ? { sourceExcerpt: String(e.sourceExcerpt) } : {},
4494
+ // TEN-2191: surface the WHY and its quality in the structured payload too.
4495
+ ...why.length > 0 ? { why } : {},
4496
+ ...e.whyQuality ? { whyQuality: String(e.whyQuality) } : {},
4466
4497
  entries: [{ entryId: e.entryId, name: e.name, status: e.status, ...e.workflowStatus ? { workflowStatus: e.workflowStatus } : {}, collectionName: String(e.collectionName ?? e.canonicalKey ?? "\u2014") }],
4467
- ...visibleData ? { data: visibleData } : {},
4498
+ // Structured payload uses the same filteredData as the text render — the
4499
+ // WHY-source field (rationale or description) is intentionally omitted from
4500
+ // `data` because its full value is carried in the top-level `why` field
4501
+ // (no information loss; `why` is the complete untruncated extractWhy result).
4502
+ // This restores true STD-218 text/structured parity and removes the duplication
4503
+ // that commit 8f3b1664 left in the structured payload. (Codex finding, TEN-2191.)
4504
+ ...filteredData ? { data: filteredData } : {},
4468
4505
  ...Array.isArray(e.relations) && e.relations.length > 0 ? {
4469
4506
  relations: e.relations.map((r) => ({
4470
4507
  ...r.otherEntryId ? { entryId: r.otherEntryId } : {},
@@ -4521,10 +4558,13 @@ async function handleBatch(entryIds) {
4521
4558
  if (entry.sourceExcerpt) {
4522
4559
  lines.push(`**Source excerpt:** ${entry.sourceExcerpt}`);
4523
4560
  }
4561
+ const { line: whyLine, whySourceKey } = renderWhyLine(entry);
4562
+ if (whyLine !== null) lines.push(whyLine);
4524
4563
  const visibleData = sanitizeEntryData(entry.data);
4525
- if (visibleData) {
4564
+ const filteredData = visibleData && whySourceKey ? Object.keys(visibleData).filter((k) => k !== whySourceKey).length > 0 ? Object.fromEntries(Object.entries(visibleData).filter(([k]) => k !== whySourceKey)) : void 0 : visibleData;
4565
+ if (filteredData) {
4526
4566
  lines.push("");
4527
- for (const [key, val] of Object.entries(visibleData)) {
4567
+ for (const [key, val] of Object.entries(filteredData)) {
4528
4568
  const display = typeof val === "string" ? val : JSON.stringify(val);
4529
4569
  lines.push(`**${key}:** ${display}`);
4530
4570
  }
@@ -4555,6 +4595,9 @@ async function handleBatch(entryIds) {
4555
4595
  }
4556
4596
  const structuredEntries = results.filter((r) => !r.error && r.entry).map((r) => {
4557
4597
  const entry = r.entry;
4598
+ const { why: entryWhy, whySourceKey: entryWhySourceKey } = renderWhyLine(entry);
4599
+ const entryVisibleData = sanitizeEntryData(entry.data);
4600
+ const entryFilteredData = entryVisibleData && entryWhySourceKey ? Object.keys(entryVisibleData).filter((k) => k !== entryWhySourceKey).length > 0 ? Object.fromEntries(Object.entries(entryVisibleData).filter(([k]) => k !== entryWhySourceKey)) : void 0 : entryVisibleData;
4558
4601
  return {
4559
4602
  entryId: String(entry.entryId ?? ""),
4560
4603
  name: String(entry.name ?? ""),
@@ -4567,7 +4610,10 @@ async function handleBatch(entryIds) {
4567
4610
  ...entry.sourceRef ? { sourceRef: String(entry.sourceRef) } : {},
4568
4611
  ...entry.sourceExcerpt ? { sourceExcerpt: String(entry.sourceExcerpt) } : {},
4569
4612
  ...entry.workflowStatus ? { workflowStatus: String(entry.workflowStatus) } : {},
4570
- ...sanitizeEntryData(entry.data) ? { data: sanitizeEntryData(entry.data) } : {}
4613
+ // TEN-2191: surface why/whyQuality in structured payload — mirrors handleGet.
4614
+ ...entryWhy.length > 0 ? { why: entryWhy } : {},
4615
+ ...entry.whyQuality ? { whyQuality: String(entry.whyQuality) } : {},
4616
+ ...entryFilteredData ? { data: entryFilteredData } : {}
4571
4617
  };
4572
4618
  });
4573
4619
  const total = structuredEntries.length;
@@ -15222,4 +15268,4 @@ export {
15222
15268
  createProductBrainServer,
15223
15269
  initFeatureFlags
15224
15270
  };
15225
- //# sourceMappingURL=chunk-7BKN47NY.js.map
15271
+ //# sourceMappingURL=chunk-JJJO3SDX.js.map