@productbrain/mcp 0.0.1-beta.9000 → 0.0.1-beta.9001

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.
@@ -769,174 +769,6 @@ async function resolveCollection(params) {
769
769
  return result2 ?? null;
770
770
  }
771
771
 
772
- // src/tools/coherency-refusal.ts
773
- function asDescription(value) {
774
- if (typeof value !== "string") return void 0;
775
- const trimmed = value.trim();
776
- return trimmed.length > 0 ? trimmed : void 0;
777
- }
778
- var GENERIC_RECOVERY_LINE = "Respond and retry: link the entry to the strategic spine, pass `coherencyAcknowledgement`, or supply a typed `steeringOverrideReason`.";
779
- function coherencyRefusedResult(toolName, entryId, refusal, options) {
780
- const headingLevel = options?.headingLevel ?? 1;
781
- const heading = "#".repeat(headingLevel);
782
- const lines = [
783
- `${heading} Write refused by the coherency gate`,
784
- "",
785
- refusal.reason ?? `The coherency gate refused this write on ${entryId}.`
786
- ];
787
- if (refusal.subject?.name) {
788
- lines.push(`On: ${refusal.subject.name}`);
789
- }
790
- if (refusal.mode) {
791
- lines.push("", `Mode: ${refusal.mode}`);
792
- }
793
- const routes = refusal.routes;
794
- const routeKeys = routes ? Object.keys(routes) : [];
795
- if (routeKeys.length > 0) {
796
- lines.push("", `${"#".repeat(headingLevel + 1)} Recovery routes`);
797
- const beforeRoutes = lines.length;
798
- if (routes && typeof routes.link === "object" && routes.link !== null) {
799
- const link = routes.link;
800
- lines.push(`- **link:** ${asDescription(link.description) ?? "Link the entry to the strategic spine."}`);
801
- }
802
- if (routes && typeof routes.acknowledge === "object" && routes.acknowledge !== null) {
803
- const ack = routes.acknowledge;
804
- const responses = ack.responses?.join(" | ") ?? "linked | accepted-fix | diverged";
805
- lines.push(
806
- `- **acknowledge** (\`${ack.param ?? "coherencyAcknowledgement"}\`): ${responses}${ack.minReasonChars ? ` (\u2265${ack.minReasonChars} chars for diverged)` : ""}. ${asDescription(ack.description) ?? ""}`.trim()
807
- );
808
- }
809
- if (routes && typeof routes.override === "object" && routes.override !== null) {
810
- const ov = routes.override;
811
- lines.push(
812
- `- **override** (\`${ov.param ?? "steeringOverrideReason"}\`): \u2265${ov.minChars ?? 12} chars. ${asDescription(ov.description) ?? ""}`.trim()
813
- );
814
- }
815
- if (lines.length === beforeRoutes) {
816
- lines.push(GENERIC_RECOVERY_LINE);
817
- }
818
- } else {
819
- lines.push("", GENERIC_RECOVERY_LINE);
820
- }
821
- return failureResult(
822
- lines.join("\n"),
823
- "COHERENCY_REFUSED",
824
- `Coherency gate refused ${toolName} on ${entryId}.`,
825
- "Use one of the refusal's routes (link / coherencyAcknowledgement / steeringOverrideReason), then retry.",
826
- void 0,
827
- { entryId, refusal }
828
- );
829
- }
830
-
831
- // src/lib/collectionCache.ts
832
- var collectionCache = new ScopedCache(COLLECTION_CACHE_TTL_MS);
833
- async function getCollections() {
834
- const scope = cacheScope();
835
- const hit = collectionCache.get(scope);
836
- if (hit) return hit.collections;
837
- const result2 = await kernelQuery("chain.listCollections") ?? [];
838
- const bySlug = new Map(result2.map((c) => [c.slug, c]));
839
- collectionCache.set(scope, { collections: result2, bySlug });
840
- return result2;
841
- }
842
- async function getCollectionBySlug(slug) {
843
- await getCollections();
844
- return collectionCache.get(cacheScope())?.bySlug.get(slug);
845
- }
846
- function invalidateCollectionCacheForScope() {
847
- collectionCache.delete(cacheScope());
848
- }
849
- async function isGoverned(slug) {
850
- const col = await getCollectionBySlug(slug);
851
- return !!col?.governed;
852
- }
853
-
854
- // src/lib/versionWrite.ts
855
- function buildVersionPatch(params) {
856
- const { capture, targetProseKey } = params;
857
- const data = { ...capture.fields ?? {} };
858
- if (capture.prose.trim()) data[targetProseKey] = capture.prose;
859
- return capture.name ? { name: capture.name, data } : { data };
860
- }
861
- function readVersionWriteOutcome(result2) {
862
- if (result2 && typeof result2 === "object" && result2.outcome === "refused") {
863
- const rawRefusal = result2.refusal;
864
- const refusal = rawRefusal && typeof rawRefusal === "object" ? rawRefusal : { reason: "The workspace refused this update." };
865
- return { ok: false, refusal };
866
- }
867
- if (result2 && typeof result2 === "object" && typeof result2.id === "string") {
868
- return { ok: true, id: result2.id };
869
- }
870
- return { ok: false, refusal: { reason: "The workspace refused this update." } };
871
- }
872
-
873
- // src/tools/captureVersion.ts
874
- function buildVersionPreviewResult(groundingEntry, name) {
875
- return successResult(
876
- `# Would save as a new version of ${groundingEntry.entryId}
877
-
878
- No DB writes \u2014 call without \`preview:true\` to version for real.`,
879
- `Would save as a new version of ${groundingEntry.entryId}.`,
880
- { id: groundingEntry.entryId, kind: "version", preview: true, name }
881
- );
882
- }
883
- async function resolveTargetProseKey(collectionSlug) {
884
- const col = await getCollectionBySlug(collectionSlug).catch(() => void 0);
885
- return col?.descriptionFieldKey || "description";
886
- }
887
- function captureChangeReason(description, data) {
888
- const text = description.trim() || Object.keys(data ?? {}).map((k) => `${k} set`).join(", ");
889
- return text ? { changeReason: `Captured: ${text.slice(0, 300)}` } : {};
890
- }
891
- async function runVersionCapture(params) {
892
- const { groundingEntry, name, description, data, sourceRef, sourceExcerpt, links, groundingElapsedMs } = params;
893
- const versionAgentId = getAgentSessionId();
894
- const targetProseKey = await resolveTargetProseKey(groundingEntry.collectionSlug);
895
- const patch = buildVersionPatch({ capture: { prose: description ?? "", fields: data ?? void 0 }, targetProseKey });
896
- try {
897
- const rawResult = await kernelMutation("chain.updateEntry", {
898
- entryId: groundingEntry.entryId,
899
- ...patch,
900
- autoPublish: true,
901
- changeNote: "Captured as a new version via MCP",
902
- ...captureChangeReason(description ?? "", data ?? void 0),
903
- changedBy: versionAgentId ? `agent:${versionAgentId}` : "capture",
904
- ...sourceRef ? { sourceRef } : {},
905
- ...sourceExcerpt ? { sourceExcerpt } : {}
906
- });
907
- void kernelMutation("chain.recordGroundingOutcome", {
908
- surface: "mcp",
909
- promptShown: false,
910
- highestRatio: groundingEntry.score,
911
- hadGovernance: false,
912
- grounding_ms: groundingElapsedMs
913
- }).catch(() => void 0);
914
- const outcome = readVersionWriteOutcome(rawResult);
915
- if (!outcome.ok) {
916
- return coherencyRefusedResult("capture", groundingEntry.entryId, outcome.refusal);
917
- }
918
- if (links && links.length > 0) {
919
- await kernelMutation("chain.createEntryRelations", {
920
- relations: links.slice(0, 25).map((l) => ({ fromEntryId: groundingEntry.entryId, toEntryId: l.to, type: l.type, proposedBy: "user" })),
921
- sessionId: versionAgentId ?? void 0
922
- }).catch(() => void 0);
923
- }
924
- return successResult(
925
- `# Saved as a new version of ${groundingEntry.entryId}
926
-
927
- ${name}`,
928
- `Saved as a new version of ${groundingEntry.entryId}.`,
929
- { id: groundingEntry.entryId, kind: "version" }
930
- );
931
- } catch (error) {
932
- const classified = classifyError(error);
933
- return failureResult(classified.message, classified.code, classified.message, classified.recovery, classified.availableActions, classified.diagnostics);
934
- }
935
- }
936
- async function captureVersionOrPreview(preview, params) {
937
- return preview ? buildVersionPreviewResult(params.groundingEntry, params.name) : runVersionCapture(params);
938
- }
939
-
940
772
  // src/lib/inferSourceDate.ts
941
773
  function inferSourceDate(...values) {
942
774
  const combined = values.filter((value) => typeof value === "string" && value.trim().length > 0).join("\n");
@@ -968,6 +800,29 @@ function inferSourceDate(...values) {
968
800
  return `${inferredYear}-${month}-${day}`;
969
801
  }
970
802
 
803
+ // src/lib/collectionCache.ts
804
+ var collectionCache = new ScopedCache(COLLECTION_CACHE_TTL_MS);
805
+ async function getCollections() {
806
+ const scope = cacheScope();
807
+ const hit = collectionCache.get(scope);
808
+ if (hit) return hit.collections;
809
+ const result2 = await kernelQuery("chain.listCollections") ?? [];
810
+ const bySlug = new Map(result2.map((c) => [c.slug, c]));
811
+ collectionCache.set(scope, { collections: result2, bySlug });
812
+ return result2;
813
+ }
814
+ async function getCollectionBySlug(slug) {
815
+ await getCollections();
816
+ return collectionCache.get(cacheScope())?.bySlug.get(slug);
817
+ }
818
+ function invalidateCollectionCacheForScope() {
819
+ collectionCache.delete(cacheScope());
820
+ }
821
+ async function isGoverned(slug) {
822
+ const col = await getCollectionBySlug(slug);
823
+ return !!col?.governed;
824
+ }
825
+
971
826
  // src/lib/textMatch.ts
972
827
  var STOP_WORDS = /* @__PURE__ */ new Set([
973
828
  "the",
@@ -1868,7 +1723,6 @@ async function handleCapture(server, { collection, name, description, context, e
1868
1723
  duplicates: groundingEntry?.kind === "ask" ? groundingEntry.candidates.map((c) => ({ entryId: c.entryId, name: c.name, collectionSlug: c.collectionSlug, overlapRatio: c.score })) : []
1869
1724
  };
1870
1725
  const groundingCaveat = !groundingEntry ? "Grounding could not be completed; duplicate presence is unknown. Review existing entries before creating another." : groundingReport.scanTruncated !== false ? "Grounding covered a bounded sample; completeness is unverified and additional matching entries may exist. Review existing entries before creating another." : "";
1871
- if (groundingEntry?.kind === "version") return captureVersionOrPreview(preview ?? false, { groundingEntry, name, description, data: userData, sourceRef, sourceExcerpt, links, groundingElapsedMs });
1872
1726
  const built = buildDataFromFieldsOrRefuse(col.fields ?? [], profile.descriptionField, description, resolvedCollection);
1873
1727
  if ("refusal" in built) return built.refusal;
1874
1728
  const { data, descriptionField } = built;
@@ -2237,6 +2091,8 @@ Use \`entries action=get\` to inspect the existing entry, or \`entries action=up
2237
2091
  lines.push(`Next: \`entries action=commit entryId="${finalEntryId}"\`.`);
2238
2092
  }
2239
2093
  if (groundingCaveat) lines.push("", groundingCaveat);
2094
+ const named = groundingReport.duplicates.slice(0, 3).map((d) => `${d.entryId} "${d.name}"`).join(", ");
2095
+ if (named) lines.push("", `**Possible match:** ${named}. Nothing was written to it; to change it, use \`entries action=update\`.`);
2240
2096
  if (formativeHints.length > 0) {
2241
2097
  lines.push("");
2242
2098
  lines.push("## Quality Hints (advisory)");
@@ -2535,6 +2391,65 @@ function pushAppliedFieldsLines(responseLines, fieldsProvided, appliedFields, re
2535
2391
  }
2536
2392
  }
2537
2393
 
2394
+ // src/tools/coherency-refusal.ts
2395
+ function asDescription(value) {
2396
+ if (typeof value !== "string") return void 0;
2397
+ const trimmed = value.trim();
2398
+ return trimmed.length > 0 ? trimmed : void 0;
2399
+ }
2400
+ var GENERIC_RECOVERY_LINE = "Respond and retry: link the entry to the strategic spine, pass `coherencyAcknowledgement`, or supply a typed `steeringOverrideReason`.";
2401
+ function coherencyRefusedResult(toolName, entryId, refusal, options) {
2402
+ const headingLevel = options?.headingLevel ?? 1;
2403
+ const heading = "#".repeat(headingLevel);
2404
+ const lines = [
2405
+ `${heading} Write refused by the coherency gate`,
2406
+ "",
2407
+ refusal.reason ?? `The coherency gate refused this write on ${entryId}.`
2408
+ ];
2409
+ if (refusal.subject?.name) {
2410
+ lines.push(`On: ${refusal.subject.name}`);
2411
+ }
2412
+ if (refusal.mode) {
2413
+ lines.push("", `Mode: ${refusal.mode}`);
2414
+ }
2415
+ const routes = refusal.routes;
2416
+ const routeKeys = routes ? Object.keys(routes) : [];
2417
+ if (routeKeys.length > 0) {
2418
+ lines.push("", `${"#".repeat(headingLevel + 1)} Recovery routes`);
2419
+ const beforeRoutes = lines.length;
2420
+ if (routes && typeof routes.link === "object" && routes.link !== null) {
2421
+ const link = routes.link;
2422
+ lines.push(`- **link:** ${asDescription(link.description) ?? "Link the entry to the strategic spine."}`);
2423
+ }
2424
+ if (routes && typeof routes.acknowledge === "object" && routes.acknowledge !== null) {
2425
+ const ack = routes.acknowledge;
2426
+ const responses = ack.responses?.join(" | ") ?? "linked | accepted-fix | diverged";
2427
+ lines.push(
2428
+ `- **acknowledge** (\`${ack.param ?? "coherencyAcknowledgement"}\`): ${responses}${ack.minReasonChars ? ` (\u2265${ack.minReasonChars} chars for diverged)` : ""}. ${asDescription(ack.description) ?? ""}`.trim()
2429
+ );
2430
+ }
2431
+ if (routes && typeof routes.override === "object" && routes.override !== null) {
2432
+ const ov = routes.override;
2433
+ lines.push(
2434
+ `- **override** (\`${ov.param ?? "steeringOverrideReason"}\`): \u2265${ov.minChars ?? 12} chars. ${asDescription(ov.description) ?? ""}`.trim()
2435
+ );
2436
+ }
2437
+ if (lines.length === beforeRoutes) {
2438
+ lines.push(GENERIC_RECOVERY_LINE);
2439
+ }
2440
+ } else {
2441
+ lines.push("", GENERIC_RECOVERY_LINE);
2442
+ }
2443
+ return failureResult(
2444
+ lines.join("\n"),
2445
+ "COHERENCY_REFUSED",
2446
+ `Coherency gate refused ${toolName} on ${entryId}.`,
2447
+ "Use one of the refusal's routes (link / coherencyAcknowledgement / steeringOverrideReason), then retry.",
2448
+ void 0,
2449
+ { entryId, refusal }
2450
+ );
2451
+ }
2452
+
2538
2453
  // src/tools/knowledge/getHistory.ts
2539
2454
  import { z as z5 } from "zod/v3";
2540
2455
  var getHistorySchema = z5.object({
@@ -13677,4 +13592,4 @@ export {
13677
13592
  createProductBrainServer,
13678
13593
  initFeatureFlags
13679
13594
  };
13680
- //# sourceMappingURL=chunk-H3MBX75V.js.map
13595
+ //# sourceMappingURL=chunk-IDJEB3WM.js.map