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

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.
@@ -267,7 +267,8 @@ function ownerLineParts(owner) {
267
267
  }
268
268
  function formatOwnerLine(owner, options = {}) {
269
269
  const ids = options.ids ?? true;
270
- const label = options.label ?? "Owner:";
270
+ const word = owner.kind === "placed" ? "Home:" : "Owner:";
271
+ const label = options.bold ? `**${word}**` : word;
271
272
  switch (owner.kind) {
272
273
  case "one": {
273
274
  const { role, team } = ownerLineParts(owner);
@@ -275,6 +276,8 @@ function formatOwnerLine(owner, options = {}) {
275
276
  }
276
277
  case "none":
277
278
  return `${label} none`;
279
+ case "placed":
280
+ return `${label} ${owner.team.name}`;
278
281
  case "many":
279
282
  return `${label} conflicting \u2014 ${owner.count}${owner.truncated ? "+" : ""} owners recorded`;
280
283
  case "dangling": {
@@ -364,7 +367,9 @@ var ownerOutputShape = z2.discriminatedUnion("kind", [
364
367
  // WP-753 O5b fix round 1 (item 1), nested round 3 (item 6): team/role optional — present only
365
368
  // when entryOwnershipRead.ts could name the archived/dead target without leaking a foreign
366
369
  // workspace's name. Nested (not flat teamName/roleName) to match the `one` kind.
367
- z2.object({ kind: z2.literal("dangling"), teamId: z2.string(), roleId: z2.string(), team: ownerTeam.pick({ name: true }).optional(), role: ownerRole.pick({ name: true }).optional() })
370
+ z2.object({ kind: z2.literal("dangling"), teamId: z2.string(), roleId: z2.string(), team: ownerTeam.pick({ name: true }).optional(), role: ownerRole.pick({ name: true }).optional() }),
371
+ // DEC-1944 (TASK-614; WP-783): where a role or a team lives — its team's name only.
372
+ z2.object({ kind: z2.literal("placed"), team: ownerTeam.pick({ name: true }) })
368
373
  ]);
369
374
  function parseOwnerOutput(raw) {
370
375
  if (!raw) return void 0;
@@ -372,8 +377,8 @@ function parseOwnerOutput(raw) {
372
377
  return result2.success ? result2.data : void 0;
373
378
  }
374
379
  function formatOwnerLine2(owner) {
375
- const sanitized = owner.kind === "one" ? { ...owner, team: { name: sanitizeSingleLineField(owner.team.name) }, role: { name: sanitizeSingleLineField(owner.role.name) } } : owner.kind === "dangling" ? { ...owner, ...owner.team ? { team: { name: sanitizeSingleLineField(owner.team.name) } } : {}, ...owner.role ? { role: { name: sanitizeSingleLineField(owner.role.name) } } : {} } : owner;
376
- return formatOwnerLine(sanitized, { label: "**Owner:**" });
380
+ const sanitized = owner.kind === "one" ? { ...owner, team: { name: sanitizeSingleLineField(owner.team.name) }, role: { name: sanitizeSingleLineField(owner.role.name) } } : owner.kind === "dangling" ? { ...owner, ...owner.team ? { team: { name: sanitizeSingleLineField(owner.team.name) } } : {}, ...owner.role ? { role: { name: sanitizeSingleLineField(owner.role.name) } } : {} } : owner.kind === "placed" ? { ...owner, team: { name: sanitizeSingleLineField(owner.team.name) } } : owner;
381
+ return formatOwnerLine(sanitized, { bold: true });
377
382
  }
378
383
  function extractPreview(data, maxLen) {
379
384
  if (!data || typeof data !== "object") return "";
@@ -769,174 +774,6 @@ async function resolveCollection(params) {
769
774
  return result2 ?? null;
770
775
  }
771
776
 
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
777
  // src/lib/inferSourceDate.ts
941
778
  function inferSourceDate(...values) {
942
779
  const combined = values.filter((value) => typeof value === "string" && value.trim().length > 0).join("\n");
@@ -968,6 +805,29 @@ function inferSourceDate(...values) {
968
805
  return `${inferredYear}-${month}-${day}`;
969
806
  }
970
807
 
808
+ // src/lib/collectionCache.ts
809
+ var collectionCache = new ScopedCache(COLLECTION_CACHE_TTL_MS);
810
+ async function getCollections() {
811
+ const scope = cacheScope();
812
+ const hit = collectionCache.get(scope);
813
+ if (hit) return hit.collections;
814
+ const result2 = await kernelQuery("chain.listCollections") ?? [];
815
+ const bySlug = new Map(result2.map((c) => [c.slug, c]));
816
+ collectionCache.set(scope, { collections: result2, bySlug });
817
+ return result2;
818
+ }
819
+ async function getCollectionBySlug(slug) {
820
+ await getCollections();
821
+ return collectionCache.get(cacheScope())?.bySlug.get(slug);
822
+ }
823
+ function invalidateCollectionCacheForScope() {
824
+ collectionCache.delete(cacheScope());
825
+ }
826
+ async function isGoverned(slug) {
827
+ const col = await getCollectionBySlug(slug);
828
+ return !!col?.governed;
829
+ }
830
+
971
831
  // src/lib/textMatch.ts
972
832
  var STOP_WORDS = /* @__PURE__ */ new Set([
973
833
  "the",
@@ -1868,7 +1728,6 @@ async function handleCapture(server, { collection, name, description, context, e
1868
1728
  duplicates: groundingEntry?.kind === "ask" ? groundingEntry.candidates.map((c) => ({ entryId: c.entryId, name: c.name, collectionSlug: c.collectionSlug, overlapRatio: c.score })) : []
1869
1729
  };
1870
1730
  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
1731
  const built = buildDataFromFieldsOrRefuse(col.fields ?? [], profile.descriptionField, description, resolvedCollection);
1873
1732
  if ("refusal" in built) return built.refusal;
1874
1733
  const { data, descriptionField } = built;
@@ -2237,6 +2096,8 @@ Use \`entries action=get\` to inspect the existing entry, or \`entries action=up
2237
2096
  lines.push(`Next: \`entries action=commit entryId="${finalEntryId}"\`.`);
2238
2097
  }
2239
2098
  if (groundingCaveat) lines.push("", groundingCaveat);
2099
+ const named = groundingReport.duplicates.slice(0, 3).map((d) => `${d.entryId} "${d.name}"`).join(", ");
2100
+ if (named) lines.push("", `**Possible match:** ${named}. Nothing was written to it; to change it, use \`entries action=update\`.`);
2240
2101
  if (formativeHints.length > 0) {
2241
2102
  lines.push("");
2242
2103
  lines.push("## Quality Hints (advisory)");
@@ -2535,6 +2396,65 @@ function pushAppliedFieldsLines(responseLines, fieldsProvided, appliedFields, re
2535
2396
  }
2536
2397
  }
2537
2398
 
2399
+ // src/tools/coherency-refusal.ts
2400
+ function asDescription(value) {
2401
+ if (typeof value !== "string") return void 0;
2402
+ const trimmed = value.trim();
2403
+ return trimmed.length > 0 ? trimmed : void 0;
2404
+ }
2405
+ var GENERIC_RECOVERY_LINE = "Respond and retry: link the entry to the strategic spine, pass `coherencyAcknowledgement`, or supply a typed `steeringOverrideReason`.";
2406
+ function coherencyRefusedResult(toolName, entryId, refusal, options) {
2407
+ const headingLevel = options?.headingLevel ?? 1;
2408
+ const heading = "#".repeat(headingLevel);
2409
+ const lines = [
2410
+ `${heading} Write refused by the coherency gate`,
2411
+ "",
2412
+ refusal.reason ?? `The coherency gate refused this write on ${entryId}.`
2413
+ ];
2414
+ if (refusal.subject?.name) {
2415
+ lines.push(`On: ${refusal.subject.name}`);
2416
+ }
2417
+ if (refusal.mode) {
2418
+ lines.push("", `Mode: ${refusal.mode}`);
2419
+ }
2420
+ const routes = refusal.routes;
2421
+ const routeKeys = routes ? Object.keys(routes) : [];
2422
+ if (routeKeys.length > 0) {
2423
+ lines.push("", `${"#".repeat(headingLevel + 1)} Recovery routes`);
2424
+ const beforeRoutes = lines.length;
2425
+ if (routes && typeof routes.link === "object" && routes.link !== null) {
2426
+ const link = routes.link;
2427
+ lines.push(`- **link:** ${asDescription(link.description) ?? "Link the entry to the strategic spine."}`);
2428
+ }
2429
+ if (routes && typeof routes.acknowledge === "object" && routes.acknowledge !== null) {
2430
+ const ack = routes.acknowledge;
2431
+ const responses = ack.responses?.join(" | ") ?? "linked | accepted-fix | diverged";
2432
+ lines.push(
2433
+ `- **acknowledge** (\`${ack.param ?? "coherencyAcknowledgement"}\`): ${responses}${ack.minReasonChars ? ` (\u2265${ack.minReasonChars} chars for diverged)` : ""}. ${asDescription(ack.description) ?? ""}`.trim()
2434
+ );
2435
+ }
2436
+ if (routes && typeof routes.override === "object" && routes.override !== null) {
2437
+ const ov = routes.override;
2438
+ lines.push(
2439
+ `- **override** (\`${ov.param ?? "steeringOverrideReason"}\`): \u2265${ov.minChars ?? 12} chars. ${asDescription(ov.description) ?? ""}`.trim()
2440
+ );
2441
+ }
2442
+ if (lines.length === beforeRoutes) {
2443
+ lines.push(GENERIC_RECOVERY_LINE);
2444
+ }
2445
+ } else {
2446
+ lines.push("", GENERIC_RECOVERY_LINE);
2447
+ }
2448
+ return failureResult(
2449
+ lines.join("\n"),
2450
+ "COHERENCY_REFUSED",
2451
+ `Coherency gate refused ${toolName} on ${entryId}.`,
2452
+ "Use one of the refusal's routes (link / coherencyAcknowledgement / steeringOverrideReason), then retry.",
2453
+ void 0,
2454
+ { entryId, refusal }
2455
+ );
2456
+ }
2457
+
2538
2458
  // src/tools/knowledge/getHistory.ts
2539
2459
  import { z as z5 } from "zod/v3";
2540
2460
  var getHistorySchema = z5.object({
@@ -13677,4 +13597,4 @@ export {
13677
13597
  createProductBrainServer,
13678
13598
  initFeatureFlags
13679
13599
  };
13680
- //# sourceMappingURL=chunk-H3MBX75V.js.map
13600
+ //# sourceMappingURL=chunk-WTUALZ6W.js.map