@productbrain/mcp 0.0.1-beta.35 → 0.0.1-beta.37

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.
@@ -25,7 +25,7 @@ import {
25
25
  startAgentSession,
26
26
  trackWriteTool,
27
27
  translateStaleToolNames
28
- } from "./chunk-TPX6TOGV.js";
28
+ } from "./chunk-Z2FGGJHI.js";
29
29
  import {
30
30
  trackQualityCheck,
31
31
  trackQualityVerdict
@@ -125,7 +125,7 @@ ${formatted}` }]
125
125
  },
126
126
  async ({ entryId }) => {
127
127
  requireWriteAccess();
128
- const { runContradictionCheck } = await import("./smart-capture-QMBL4KGX.js");
128
+ const { runContradictionCheck } = await import("./smart-capture-BIKEZC6P.js");
129
129
  const entry = await mcpQuery("chain.getEntry", { entryId });
130
130
  if (!entry) {
131
131
  return {
@@ -4797,9 +4797,23 @@ var CORE_PROTOCOL = [
4797
4797
  "**Reference by ID.** When discussing a topic that has Chain entries, cite them by entry ID (e.g. `DEC-50`, `PRI-3`). This keeps conversations grounded in shared knowledge.",
4798
4798
  "**Check scope.** If the proposed work doesn't fall under an active bet, stop and say so. Do not design implementation for out-of-scope work without explicit user go-ahead.",
4799
4799
  `**Capture continuously.** When a decision, tension, insight, or new term surfaces during work, capture it as a draft immediately. Don't defer to "later."`,
4800
- "**Validate against governance.** Before finalizing any proposal, check it against the Workspace Governance section above. If it conflicts with a principle, standard, or business rule, flag the conflict explicitly."
4800
+ "**Validate against governance.** Before proposing any solution, check it against the Workspace Governance directives below. If your proposal conflicts with a principle, standard, or business rule \u2014 stop, name the conflict, and get explicit user confirmation before proceeding."
4801
4801
  ];
4802
- function buildOperatingProtocol(workspaceStandards) {
4802
+ var MAX_ENTRIES_NO_TASK = 3;
4803
+ function extractKeywords(text) {
4804
+ return [...new Set(text.toLowerCase().split(/\s+/).filter((w) => w.length > 3))];
4805
+ }
4806
+ function scoreEntry(entry, keywords) {
4807
+ const text = `${entry.name} ${entry.description ?? ""}`.toLowerCase();
4808
+ return keywords.filter((kw) => text.includes(kw)).length;
4809
+ }
4810
+ function formatGovernanceEntry(entry) {
4811
+ const id = entry.entryId ?? entry.name;
4812
+ const desc = entry.description ? ` \u2014 ${entry.description.slice(0, 120)}${entry.description.length > 120 ? "..." : ""}` : "";
4813
+ return `- **[${id}]** ${entry.name}${desc}`;
4814
+ }
4815
+ function buildOperatingProtocol(governanceOrStandards, task) {
4816
+ const governance = Array.isArray(governanceOrStandards) ? { standards: governanceOrStandards } : governanceOrStandards ?? {};
4803
4817
  const lines = [
4804
4818
  "## Operating Protocol",
4805
4819
  "_How to work in this workspace. Follow these before and during every task._",
@@ -4808,13 +4822,56 @@ function buildOperatingProtocol(workspaceStandards) {
4808
4822
  for (let i = 0; i < CORE_PROTOCOL.length; i++) {
4809
4823
  lines.push(`${i + 1}. ${CORE_PROTOCOL[i]}`);
4810
4824
  }
4811
- if (workspaceStandards && workspaceStandards.length > 0) {
4825
+ const { principles = [], standards = [], businessRules = [] } = governance;
4826
+ const hasGovernance = principles.length > 0 || standards.length > 0 || businessRules.length > 0;
4827
+ if (hasGovernance) {
4812
4828
  lines.push("");
4813
- lines.push("**Workspace-specific standards:**");
4814
- for (const s of workspaceStandards) {
4815
- const id = s.entryId ?? s.name;
4816
- const desc = s.description ? ` \u2014 ${s.description.slice(0, 120)}${s.description.length > 120 ? "..." : ""}` : "";
4817
- lines.push(`- \`${id}\` **${s.name}**${desc}`);
4829
+ lines.push("### Workspace governance directives");
4830
+ const types = [
4831
+ { header: "**Active principles:**", entries: principles },
4832
+ { header: "**Active business rules:**", entries: businessRules },
4833
+ { header: "**Active standards:**", entries: standards }
4834
+ ];
4835
+ if (task) {
4836
+ const keywords = extractKeywords(task);
4837
+ let anyRelevant = false;
4838
+ for (const type of types) {
4839
+ if (type.entries.length === 0) continue;
4840
+ const scored = type.entries.map((e) => ({ entry: e, score: scoreEntry(e, keywords) })).filter((s) => s.score > 0).sort((a, b) => b.score - a.score);
4841
+ if (scored.length > 0) {
4842
+ anyRelevant = true;
4843
+ lines.push(type.header);
4844
+ for (const s of scored) {
4845
+ lines.push(formatGovernanceEntry(s.entry));
4846
+ }
4847
+ lines.push("");
4848
+ }
4849
+ }
4850
+ if (!anyRelevant) {
4851
+ for (const type of types) {
4852
+ if (type.entries.length === 0) continue;
4853
+ lines.push(type.header);
4854
+ for (const e of type.entries.slice(0, MAX_ENTRIES_NO_TASK)) {
4855
+ lines.push(formatGovernanceEntry(e));
4856
+ }
4857
+ lines.push("");
4858
+ }
4859
+ }
4860
+ lines.push(
4861
+ "_Governance filtered by task relevance. Run `orient` without a task to see all._"
4862
+ );
4863
+ } else {
4864
+ for (const type of types) {
4865
+ if (type.entries.length === 0) continue;
4866
+ lines.push(type.header);
4867
+ for (const e of type.entries.slice(0, MAX_ENTRIES_NO_TASK)) {
4868
+ lines.push(formatGovernanceEntry(e));
4869
+ }
4870
+ lines.push("");
4871
+ }
4872
+ lines.push(
4873
+ '_Showing top governance entries. Use `orient task="..."` for task-relevant filtering._'
4874
+ );
4818
4875
  }
4819
4876
  }
4820
4877
  lines.push("");
@@ -5048,7 +5105,9 @@ async function buildOrientResponse(wsCtx, agentSessionId, errors) {
5048
5105
  if (readiness) {
5049
5106
  lines.push(`Readiness: ${readiness.score}% (${readiness.passedChecks}/${readiness.totalChecks}).`);
5050
5107
  }
5108
+ let wsPrinciples = [];
5051
5109
  let wsStandards = [];
5110
+ let wsBusinessRules = [];
5052
5111
  try {
5053
5112
  const govSlugs = ["principles", "standards", "business-rules"];
5054
5113
  const govLabels = {
@@ -5062,7 +5121,9 @@ async function buildOrientResponse(wsCtx, agentSessionId, errors) {
5062
5121
  const active = (entries ?? []).filter((e) => e.status === "active" || e.status === "verified");
5063
5122
  if (active.length > 0) {
5064
5123
  govEntries.push({ slug, entries: active });
5124
+ if (slug === "principles") wsPrinciples = active;
5065
5125
  if (slug === "standards") wsStandards = active;
5126
+ if (slug === "business-rules") wsBusinessRules = active;
5066
5127
  }
5067
5128
  }
5068
5129
  if (govEntries.length > 0) {
@@ -5096,12 +5157,16 @@ async function buildOrientResponse(wsCtx, agentSessionId, errors) {
5096
5157
  }
5097
5158
  } catch {
5098
5159
  }
5099
- const standardsForProtocol = wsStandards.map((e) => ({
5160
+ const mapGovEntry = (e) => ({
5100
5161
  entryId: e.entryId,
5101
5162
  name: e.name,
5102
5163
  description: typeof e.data?.description === "string" ? e.data.description : typeof e.description === "string" ? e.description : void 0
5164
+ });
5165
+ lines.push(...buildOperatingProtocol({
5166
+ principles: wsPrinciples.map(mapGovEntry),
5167
+ standards: wsStandards.map(mapGovEntry),
5168
+ businessRules: wsBusinessRules.map(mapGovEntry)
5103
5169
  }));
5104
- lines.push(...buildOperatingProtocol(standardsForProtocol));
5105
5170
  const plannedWork = await queryPlannedWork();
5106
5171
  if (hasPlannedWork(plannedWork)) {
5107
5172
  lines.push("");
@@ -7187,6 +7252,19 @@ function registerHealthTools(server) {
7187
7252
  const modified = Array.isArray(last.entriesModified) ? last.entriesModified.length : last.entriesModified ?? 0;
7188
7253
  lines.push(`Last session (${date}): ${created} created, ${modified} modified`);
7189
7254
  }
7255
+ if (orientEntries) {
7256
+ const mapGovernanceEntry = (e) => ({
7257
+ entryId: e.entryId,
7258
+ name: e.name,
7259
+ description: typeof e.preview === "string" ? e.preview : void 0
7260
+ });
7261
+ lines.push("");
7262
+ lines.push(...buildOperatingProtocol({
7263
+ principles: (orientEntries.principles ?? []).map(mapGovernanceEntry),
7264
+ standards: (orientEntries.standards ?? []).map(mapGovernanceEntry),
7265
+ businessRules: (orientEntries.businessRules ?? []).map(mapGovernanceEntry)
7266
+ }, task));
7267
+ }
7190
7268
  if (agentSessionId) {
7191
7269
  try {
7192
7270
  await mcpCall("agent.markOriented", { sessionId: agentSessionId });
@@ -7376,12 +7454,16 @@ function registerHealthTools(server) {
7376
7454
  orientEntries.architectureNotes.forEach((e) => lines.push(fmt(e)));
7377
7455
  lines.push("");
7378
7456
  }
7379
- const standardsForProtocol = (orientEntries.standards ?? []).map((e) => ({
7457
+ const mapGovernanceEntry = (e) => ({
7380
7458
  entryId: e.entryId,
7381
7459
  name: e.name,
7382
7460
  description: typeof e.preview === "string" ? e.preview : void 0
7383
- }));
7384
- lines.push(...buildOperatingProtocol(standardsForProtocol));
7461
+ });
7462
+ lines.push(...buildOperatingProtocol({
7463
+ principles: (orientEntries.principles ?? []).map(mapGovernanceEntry),
7464
+ standards: (orientEntries.standards ?? []).map(mapGovernanceEntry),
7465
+ businessRules: (orientEntries.businessRules ?? []).map(mapGovernanceEntry)
7466
+ }, task));
7385
7467
  }
7386
7468
  const plannedWork = await queryPlannedWork();
7387
7469
  if (hasPlannedWork(plannedWork)) {
@@ -8587,4 +8669,4 @@ export {
8587
8669
  SERVER_VERSION,
8588
8670
  createProductBrainServer
8589
8671
  };
8590
- //# sourceMappingURL=chunk-HTL6Y2AO.js.map
8672
+ //# sourceMappingURL=chunk-7CD66MUS.js.map