@mrrlin-dev/mcp 0.4.218 → 0.4.220

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 (2) hide show
  1. package/dist/bin.cjs +89 -68
  2. package/package.json +1 -1
package/dist/bin.cjs CHANGED
@@ -89031,63 +89031,60 @@ async function handleConsensusBlocked(result, ctx, input, resolvedTaskId) {
89031
89031
  }
89032
89032
  }
89033
89033
  }
89034
- let filedQuestionCount = 0;
89035
- if (toFile.length > 0) {
89036
- if (taskId) {
89037
- const scopeId = taskId;
89038
- const prefix = result.evaluatedClarificationKey ? mixedCodeClarificationIdPrefix(scopeId, result.evaluatedClarificationKey) : `II-${scopeId}-gate-`;
89039
- const groupId = toFile.length > 1 ? `${prefix}group-${(0, import_node_crypto10.createHash)("sha256").update(toFile.map((c) => c.rawQuestion).sort().join("\n")).digest("hex").slice(0, 10)}` : void 0;
89040
- for (const clarification of toFile) {
89041
- const id = `${prefix}${(0, import_node_crypto10.createHash)("sha256").update(clarification.rawQuestion).digest("hex").slice(0, 10)}`;
89042
- try {
89043
- const questionOptions = buildGateQuestionOptions(clarification.rawQuestion, clarification.category);
89044
- await ctx.client.createInboxItem(input.projectSlug, {
89045
- id,
89046
- kind: "question",
89047
- taskId: scopeId,
89048
- body: humanizeClarificationBody(clarification),
89049
- origin: "gate",
89050
- questionOptions,
89051
- ...groupId ? { groupId } : {}
89052
- });
89053
- } catch (err) {
89054
- const errObj = err;
89055
- const isConflict = errObj?.status === 409 || errObj?.statusCode === 409 || errObj?.code === "23505" || String(errObj?.message ?? "").includes("already exists") || String(errObj?.message ?? "").includes("duplicate key");
89056
- if (!isConflict) {
89057
- throw err;
89058
- }
89059
- }
89034
+ const confirmedQuestionIds = /* @__PURE__ */ new Set();
89035
+ let clarificationDeliveryIncomplete = false;
89036
+ const scopeId = taskId ?? planId;
89037
+ if (toFile.length > 0 && scopeId) {
89038
+ const clarificationKey = taskId ? result.evaluatedClarificationKey : void 0;
89039
+ const prefix = clarificationKey ? mixedCodeClarificationIdPrefix(scopeId, clarificationKey) : `II-${scopeId}-gate-`;
89040
+ const groupId = toFile.length > 1 ? `${prefix}group-${(0, import_node_crypto10.createHash)("sha256").update(toFile.map((c) => c.rawQuestion).sort().join("\n")).digest("hex").slice(0, 10)}` : void 0;
89041
+ const questions = toFile.map((clarification) => ({
89042
+ id: `${prefix}${(0, import_node_crypto10.createHash)("sha256").update(clarification.rawQuestion).digest("hex").slice(0, 10)}`,
89043
+ kind: "question",
89044
+ ...taskId ? { taskId } : { planId: scopeId },
89045
+ body: humanizeClarificationBody(clarification),
89046
+ origin: "gate",
89047
+ questionOptions: buildGateQuestionOptions(clarification.rawQuestion, clarification.category),
89048
+ ...groupId ? { groupId } : {}
89049
+ }));
89050
+ const matchesQuestion = (item, question) => {
89051
+ if (!item?.id || item.projectSlug !== input.projectSlug || item.kind !== "question" || item.origin !== "gate" || item.status !== "pending" || item.taskId !== taskId || item.planId !== planId || item.body !== question.body) return false;
89052
+ if (taskId && mixedCodeClarificationKeyFromId(taskId, item.id) !== clarificationKey) return false;
89053
+ const expected = question.questionOptions;
89054
+ const stored = item.questionOptions;
89055
+ if (!expected) return stored === null || stored === void 0;
89056
+ return stored?.length === expected.length && expected.every((option) => stored.some((actual) => actual.answer === option.answer && actual.label === option.label && actual.description === option.description));
89057
+ };
89058
+ const uncertain = [];
89059
+ for (const question of questions) {
89060
+ let item;
89061
+ try {
89062
+ item = await ctx.client.createInboxItem(input.projectSlug, question);
89063
+ } catch {
89064
+ uncertain.push(question);
89065
+ continue;
89060
89066
  }
89061
- filedQuestionCount = toFile.length;
89062
- } else if (planId) {
89063
- const scopeId = planId;
89064
- const groupId = toFile.length > 1 ? `II-${scopeId}-gate-group-${(0, import_node_crypto10.createHash)("sha256").update(toFile.map((c) => c.rawQuestion).sort().join("\n")).digest("hex").slice(0, 10)}` : void 0;
89065
- for (const clarification of toFile) {
89066
- const id = `II-${scopeId}-gate-${(0, import_node_crypto10.createHash)("sha256").update(clarification.rawQuestion).digest("hex").slice(0, 10)}`;
89067
- try {
89068
- const questionOptions = buildGateQuestionOptions(clarification.rawQuestion, clarification.category);
89069
- await ctx.client.createInboxItem(input.projectSlug, {
89070
- id,
89071
- kind: "question",
89072
- planId: scopeId,
89073
- body: humanizeClarificationBody(clarification),
89074
- origin: "gate",
89075
- questionOptions,
89076
- ...groupId ? { groupId } : {}
89077
- });
89078
- } catch (err) {
89079
- const errObj = err;
89080
- const isConflict = errObj?.status === 409 || errObj?.statusCode === 409 || errObj?.code === "23505" || String(errObj?.message ?? "").includes("already exists") || String(errObj?.message ?? "").includes("duplicate key");
89081
- if (!isConflict) {
89082
- throw err;
89083
- }
89084
- }
89067
+ if (matchesQuestion(item, question)) confirmedQuestionIds.add(item.id);
89068
+ else clarificationDeliveryIncomplete = true;
89069
+ }
89070
+ if (uncertain.length > 0) {
89071
+ const pending = await ctx.client.listInboxItems(input.projectSlug, {
89072
+ ...taskId ? { taskId } : {},
89073
+ kind: "question",
89074
+ status: "pending",
89075
+ limit: 100
89076
+ }).catch(() => []);
89077
+ for (const question of uncertain) {
89078
+ const item = pending.find((candidate) => matchesQuestion(candidate, question));
89079
+ if (item) confirmedQuestionIds.add(item.id);
89080
+ else clarificationDeliveryIncomplete = true;
89085
89081
  }
89086
- filedQuestionCount = toFile.length;
89087
89082
  }
89088
89083
  }
89084
+ const filedQuestionCount = confirmedQuestionIds.size;
89089
89085
  const existingQuestionCount = result.pendingReviewQuestionIds?.length ?? 0;
89090
- if (filedQuestionCount === 0 && existingQuestionCount === 0 && diagnostics.length === 0 && taskId && page) {
89086
+ let gateBlockQuestionAvailable;
89087
+ if (!clarificationDeliveryIncomplete && filedQuestionCount === 0 && existingQuestionCount === 0 && diagnostics.length === 0 && taskId && page) {
89091
89088
  const domain2 = await resolveSpecDomain(ctx.client, input.projectSlug, {
89092
89089
  id: page.id,
89093
89090
  taskId: page.taskId ?? null
@@ -89098,20 +89095,35 @@ async function handleConsensusBlocked(result, ctx, input, resolvedTaskId) {
89098
89095
  (item) => item.id === baseBlockItemId && item.status !== "pending" && item.answer === REVIEW_AGAIN_ANSWER
89099
89096
  );
89100
89097
  const blockItemId = reviewAgainAvailable ? baseBlockItemId : `${baseBlockItemId}-2`;
89098
+ const body = renderBlockDecisionBody(result.unresolved ?? []);
89099
+ const questionOptions = buildBlockDecisionOptions(result.escalation?.diagnosis, reviewAgainAvailable);
89100
+ const matchesPendingQuestion = (item) => {
89101
+ const storedOptions = item.questionOptions;
89102
+ return item.projectSlug === input.projectSlug && item.taskId === taskId && item.id === blockItemId && item.kind === "question" && item.origin === "gate_block" && item.status === "pending" && item.body === body && storedOptions?.length === questionOptions.length && questionOptions.every((option) => storedOptions.some((stored) => stored.answer === option.answer && stored.label === option.label && stored.description === option.description));
89103
+ };
89101
89104
  try {
89102
- await ctx.client.createInboxItem(input.projectSlug, {
89105
+ const item = await ctx.client.createInboxItem(input.projectSlug, {
89103
89106
  id: blockItemId,
89104
89107
  kind: "question",
89105
89108
  taskId,
89106
- body: renderBlockDecisionBody(result.unresolved ?? []),
89109
+ body,
89107
89110
  origin: "gate_block",
89108
- questionOptions: buildBlockDecisionOptions(result.escalation?.diagnosis, reviewAgainAvailable)
89111
+ questionOptions
89109
89112
  });
89113
+ gateBlockQuestionAvailable = matchesPendingQuestion(item);
89110
89114
  } catch {
89115
+ const pending = await ctx.client.listInboxItems(input.projectSlug, {
89116
+ taskId,
89117
+ kind: "question",
89118
+ status: "pending"
89119
+ }).catch(() => []);
89120
+ gateBlockQuestionAvailable = pending.some(matchesPendingQuestion);
89111
89121
  }
89112
89122
  }
89113
89123
  let error51;
89114
- if (filedQuestionCount > 0) {
89124
+ if (clarificationDeliveryIncomplete) {
89125
+ error51 = filedQuestionCount === 0 ? "No open clarification questions could be confirmed in the Inbox." : `Confirmed ${filedQuestionCount} open clarification question${filedQuestionCount === 1 ? "" : "s"} in the Inbox. Some questions could not be confirmed.`;
89126
+ } else if (filedQuestionCount > 0) {
89115
89127
  error51 = `Consensus blocked on ${filedQuestionCount} clarification(s); filed as operator question(s).`;
89116
89128
  } else if (existingQuestionCount > 0) {
89117
89129
  error51 = `Consensus still needs ${existingQuestionCount} pending clarification(s) answered in the spec.`;
@@ -89127,19 +89139,26 @@ async function handleConsensusBlocked(result, ctx, input, resolvedTaskId) {
89127
89139
  } else if (operatorClarifications.length > 0) {
89128
89140
  error51 = `Consensus blocked on ${operatorClarifications.length} clarification(s), but the spec page is not linked to a task or plan, so none could be filed as questions.`;
89129
89141
  } else {
89130
- error51 = DID_NOT_CONVERGE_ERROR;
89142
+ error51 = gateBlockQuestionAvailable === false ? "The reviewers could not agree on the spec." : DID_NOT_CONVERGE_ERROR;
89143
+ }
89144
+ if (gateBlockQuestionAvailable === false) {
89145
+ error51 += " No open decision question could be confirmed in the Inbox.";
89131
89146
  }
89132
- if (result.escalation) {
89147
+ if (result.escalation && !clarificationDeliveryIncomplete && gateBlockQuestionAvailable !== false) {
89133
89148
  error51 += ` (reason: ${result.escalation.diagnosis})`;
89134
89149
  }
89135
89150
  const isRelationshipDiagnostic = isSeedAbsence || result.diagnostics?.some((d) => d.kind === "spec_identity_mismatch") || result.escalation?.diagnosis === "spec_identity_mismatch";
89151
+ const attemptedClarifications = Boolean(scopeId && toFile.length > 0);
89152
+ const deliveryTaskId = attemptedClarifications || gateBlockQuestionAvailable !== void 0 ? taskId : resolvedTaskId;
89136
89153
  return {
89137
89154
  kind: "failed",
89138
89155
  failureReason: "consensus_blocked",
89139
89156
  error: error51,
89140
- filedQuestionCount: filedQuestionCount || existingQuestionCount,
89157
+ filedQuestionCount: attemptedClarifications ? filedQuestionCount : existingQuestionCount,
89158
+ ...clarificationDeliveryIncomplete ? { clarificationDeliveryIncomplete } : {},
89159
+ ...gateBlockQuestionAvailable !== void 0 ? { gateBlockQuestionAvailable } : {},
89141
89160
  finalReviewedHash: isRelationshipDiagnostic ? null : result.evaluatedReviewHash ?? result.evaluatedSnapshot?.contentHash ?? null,
89142
- ...resolvedTaskId ? { taskId: resolvedTaskId } : {}
89161
+ ...deliveryTaskId ? { taskId: deliveryTaskId } : {}
89143
89162
  };
89144
89163
  }
89145
89164
  function shouldRetireGateQuestions(outcome) {
@@ -89284,7 +89303,7 @@ async function run2(ctx, input, builders = defaultNativeSpecGateBuilders) {
89284
89303
  };
89285
89304
  }
89286
89305
  }
89287
- function onComplete(outcome, input) {
89306
+ function onComplete(outcome, input, context) {
89288
89307
  if (outcome.kind === "superseded") {
89289
89308
  return {
89290
89309
  kind: "info",
@@ -89324,7 +89343,7 @@ ${findings.map((f) => `\u2022 ${f}`).join("\n")}` : "";
89324
89343
  body: taskRef ? `The reviewers agreed on this spec \u2014 ${roster}.${findingsBlock}` : `The reviewers agreed on this spec (Specs/${input.pageId}) \u2014 ${roster}.${findingsBlock}`
89325
89344
  };
89326
89345
  }
89327
- if (outcome.kind === "failed" && (outcome.filedQuestionCount ?? 0) > 0) {
89346
+ if (outcome.kind === "failed" && !outcome.clarificationDeliveryIncomplete && (outcome.filedQuestionCount ?? 0) > 0) {
89328
89347
  const n = outcome.filedQuestionCount ?? 0;
89329
89348
  return {
89330
89349
  kind: "info",
@@ -89333,7 +89352,7 @@ ${findings.map((f) => `\u2022 ${f}`).join("\n")}` : "";
89333
89352
  body: taskRef ? `Consensus blocked on ${taskRef} (Specs/${input.pageId}); filed ${n} clarifying question${n === 1 ? "" : "s"} \u2014 answer to unblock the run.` : `Consensus blocked on Specs/${input.pageId}; filed ${n} clarifying question${n === 1 ? "" : "s"} \u2014 answer to unblock the run.`
89334
89353
  };
89335
89354
  }
89336
- if (outcome.kind === "failed" && outcome.error.startsWith(DID_NOT_CONVERGE_ERROR) && taskId) {
89355
+ if (outcome.kind === "failed" && outcome.gateBlockQuestionAvailable && taskId) {
89337
89356
  return {
89338
89357
  kind: "info",
89339
89358
  suppressInbox: true,
@@ -89342,10 +89361,11 @@ ${findings.map((f) => `\u2022 ${f}`).join("\n")}` : "";
89342
89361
  };
89343
89362
  }
89344
89363
  const handoffTaskRef = taskRef ? ` (${taskRef})` : "";
89345
- const revisionSuffix = "finalReviewedHash" in outcome && outcome.finalReviewedHash ? outcome.finalReviewedHash.slice(0, 8) : "init";
89364
+ const incompleteDelivery = outcome.kind === "failed" && (outcome.clarificationDeliveryIncomplete || outcome.gateBlockQuestionAvailable === false);
89365
+ const handoffSuffix = incompleteDelivery && context ? `job-${(0, import_node_crypto10.createHash)("sha256").update(JSON.stringify([context.projectSlug, context.jobId, context.createdAt])).digest("hex").slice(0, 32)}` : "finalReviewedHash" in outcome && outcome.finalReviewedHash ? outcome.finalReviewedHash.slice(0, 8) : "init";
89346
89366
  return {
89347
89367
  kind: "handoff",
89348
- id: `II-SPEC-STOPPED-${input.pageId}-${revisionSuffix}`,
89368
+ id: `II-SPEC-STOPPED-${input.pageId}-${handoffSuffix}`,
89349
89369
  ...taskId ? { taskId } : {},
89350
89370
  body: `The spec review stopped for Specs/${input.pageId}${handoffTaskRef}. ${outcome.error} Review the spec or consult the Director to update it.`
89351
89371
  };
@@ -99653,7 +99673,7 @@ Do NOT derail the current task - if the operator has an in-flight question, answ
99653
99673
  }
99654
99674
 
99655
99675
  // src/_generated/version.ts
99656
- var PKG_VERSION = "0.4.218";
99676
+ var PKG_VERSION = "0.4.220";
99657
99677
 
99658
99678
  // src/bridge-allowed-origins.ts
99659
99679
  var DEFAULT_DIRECTOR_BRIDGE_ALLOWED_ORIGINS = [
@@ -108764,6 +108784,7 @@ async function driveClaimableAsyncJob(deps, projectSlug, jobId, preClaimJob, sec
108764
108784
  if (reportAction && (claimed?.leaseId !== ownedClaim?.leaseId || claimed?.status !== "running")) return;
108765
108785
  if (shutdown?.aborted || !claimed || !claimed.leaseId) return;
108766
108786
  const leaseId = claimed.leaseId;
108787
+ const completionContext = { projectSlug: claimed.projectSlug, jobId: claimed.id, createdAt: claimed.createdAt };
108767
108788
  const ownership = reportAction ? new AbortController() : void 0;
108768
108789
  if (ownership) shutdown = shutdown ? AbortSignal.any([shutdown, ownership.signal]) : ownership.signal;
108769
108790
  let validUntil = claimStart + (ownedClaim?.leaseRemainingMs ?? 0);
@@ -108890,7 +108911,7 @@ async function driveClaimableAsyncJob(deps, projectSlug, jobId, preClaimJob, sec
108890
108911
  beginning = true;
108891
108912
  if (heartbeatPending) await heartbeatPending;
108892
108913
  if (!checkOwnership()) return;
108893
- const delivery2 = outcome.kind === "superseded" ? void 0 : descriptor2.onComplete(outcome, input);
108914
+ const delivery2 = outcome.kind === "superseded" ? void 0 : descriptor2.onComplete(outcome, input, completionContext);
108894
108915
  if (delivery2 && !delivery2.suppressInbox && delivery2.kind !== "info" && delivery2.kind !== "handoff") {
108895
108916
  throw new Error("Unsupported report evidence delivery kind");
108896
108917
  }
@@ -108947,7 +108968,7 @@ async function driveClaimableAsyncJob(deps, projectSlug, jobId, preClaimJob, sec
108947
108968
  }
108948
108969
  }
108949
108970
  if (shutdown?.aborted) return;
108950
- const delivery = descriptor2.onComplete(outcome, input);
108971
+ const delivery = descriptor2.onComplete(outcome, input, completionContext);
108951
108972
  if (!delivery.suppressInbox) {
108952
108973
  await deps.client.createInboxItem(projectSlug, {
108953
108974
  id: delivery.id ?? `II-${import_node_crypto27.default.randomUUID()}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrrlin-dev/mcp",
3
- "version": "0.4.218",
3
+ "version": "0.4.220",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mrrlin-mcp": "dist/bin.cjs"