@productbrain/mcp 0.0.1-beta.14629 → 0.0.1-beta.14631

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.
@@ -269,6 +269,7 @@ var ENTRY_BODY_CAPS = {
269
269
  var KEY_RESULT_BODY_HELP = `For a key result, open with what counts toward it; at most ${ENTRY_BODY_CAPS["key-results"].max} characters.`;
270
270
  var ENTRY_BODY_HELP = `The detail, in Markdown. ${KEY_RESULT_BODY_HELP}`;
271
271
  var SOURCE_EXCERPT_MAX_CHARS = 4e3;
272
+ var READING_SOURCE_MAX_CHARS = 500;
272
273
  var LABEL_DESCRIPTION_MAX_CHARS = 2e3;
273
274
  var REASON_MAX_LENGTH = 200;
274
275
  var REASON_LENGTH_FIX = `Keep the reason to one line of at most ${REASON_MAX_LENGTH} characters.`;
@@ -4029,41 +4030,47 @@ var outcomeSchema = z17.object({
4029
4030
  // the backend's `v.number()` validator then rejects a call this tool's own schema accepted.
4030
4031
  // `.finite()` rejects it here, matching the explicit finite-value checks the CLI/other outcome
4031
4032
  // entry surfaces already use.
4032
- value: z17.number().finite().optional().describe("'record': the measured value. Required for 'record'."),
4033
+ value: z17.number().finite().optional().describe("'record': the measured value; or leave it out and give count and total."),
4034
+ count: z17.number().finite().optional().describe("'record': The number counted"),
4035
+ total: z17.number().finite().optional().describe("'record': Out of how many"),
4033
4036
  valueText: z17.string().max(500).optional().describe("'record': verbatim as-reported form when the source was not clean, e.g. '~62%'. Display only."),
4034
4037
  asOf: z17.string().max(64).optional().describe("'record': when the world was in this state, as a parseable date (default: now). Back-dating a backfill is legitimate \u2014 it shows up as asOf earlier than recordedAt."),
4035
4038
  kind: z17.enum(READING_KINDS).optional().describe("'record': measurement | estimate | correction (default: measurement)."),
4036
4039
  correctsReadingId: z17.string().max(200).optional().describe("'record': required with kind='correction' \u2014 the reading id this replaces. Refused if that row is already superseded."),
4037
4040
  recordedByRoleId: z17.string().max(200).optional().describe("'record': the accountable role (default: the entry's reporterRoleId, then its owning role)."),
4038
4041
  note: z17.string().max(2e3).optional().describe("'record': free-text note recorded with the reading."),
4039
- source: z17.string().max(500).optional().describe("'record': where the number came from \u2014 a dashboard name, a query, a URL.")
4042
+ source: z17.string().max(READING_SOURCE_MAX_CHARS).optional().describe("'record': Where the number comes from (required for a KPI)")
4040
4043
  });
4041
4044
  var recordVariant = z17.object({
4042
4045
  action: z17.literal("record"),
4043
4046
  entryId: z17.string().max(200),
4044
- value: z17.number().finite(),
4047
+ value: z17.number().finite().optional(),
4048
+ count: z17.number().finite().optional(),
4049
+ total: z17.number().finite().optional(),
4045
4050
  valueText: z17.string().max(500).optional(),
4046
4051
  asOf: z17.string().max(64).optional(),
4047
4052
  kind: z17.enum(READING_KINDS).optional(),
4048
4053
  correctsReadingId: z17.string().max(200).optional(),
4049
4054
  recordedByRoleId: z17.string().max(200).optional(),
4050
4055
  note: z17.string().max(2e3).optional(),
4051
- source: z17.string().max(500).optional()
4056
+ source: z17.string().max(READING_SOURCE_MAX_CHARS).optional()
4052
4057
  });
4053
4058
  var outcomeActionUnion = z17.discriminatedUnion("action", [recordVariant]);
4054
4059
  var OUTCOME_ACTION_SPECS = {
4055
4060
  record: {
4056
- params: ["entryId", "value", "valueText", "asOf", "kind", "correctsReadingId", "recordedByRoleId", "note", "source"],
4057
- description: "entryId and value are required; the rest are optional."
4061
+ params: ["entryId", "value", "count", "total", "valueText", "asOf", "kind", "correctsReadingId", "recordedByRoleId", "note", "source"],
4062
+ description: "entryId is required, with a value or a count and a total; the rest are optional."
4058
4063
  }
4059
4064
  };
4060
4065
  function safeDateSlice(ms) {
4061
4066
  const d = new Date(ms);
4062
4067
  return Number.isNaN(d.getTime()) ? "invalid-date" : d.toISOString().slice(0, 10);
4063
4068
  }
4064
- function formatRecordReceipt(numericValue, entryId, valueText, receipt) {
4069
+ function formatRecordReceipt(value, entryId, valueText, receipt) {
4070
+ const text = valueText ? ` ("${sanitizeSingleLineField(valueText)}")` : "";
4065
4071
  const lines = [
4066
- `Recorded ${numericValue}${valueText ? ` ("${sanitizeSingleLineField(valueText)}")` : ""} on ${sanitizeSingleLineField(entryId)}.`,
4072
+ // The server's reading line, printed as sent; a key result's typed value as before.
4073
+ receipt.line ? `Recorded on ${sanitizeSingleLineField(entryId)}: ${sanitizeSingleLineField(receipt.line)}${text}` : `Recorded ${value}${text} on ${sanitizeSingleLineField(entryId)}.`,
4067
4074
  ` attributed: ${receipt.actorKind ?? "unknown"}`
4068
4075
  ];
4069
4076
  return lines.join("\n");
@@ -4077,7 +4084,8 @@ function formatReadingsList(entryId, result2) {
4077
4084
  const superseded = row.supersededByReadingId ? ` <- superseded by ${row.supersededByReadingId}` : "";
4078
4085
  const text = row.valueText ? ` ("${sanitizeSingleLineField(row.valueText)}")` : "";
4079
4086
  const note = row.note ? ` - ${sanitizeSingleLineField(row.note)}` : "";
4080
- return ` ${when} ${String(row.value).padStart(8)}${text} [${row.kind}] ${row.readingId}${note}${superseded}`;
4087
+ const reading = row.line ? sanitizeSingleLineField(row.line) : String(row.value).padStart(8);
4088
+ return ` ${when} ${reading}${text} [${row.kind}] ${row.readingId}${note}${superseded}`;
4081
4089
  });
4082
4090
  const tail = result2?.pageExhausted === false ? "\n (older readings not loaded - raise --limit)" : "";
4083
4091
  return `${rows.length} reading(s) on ${safeEntryId}, newest first:
@@ -4118,12 +4126,17 @@ function formatKpiShow(result2) {
4118
4126
  return [
4119
4127
  `${sanitizeSingleLineField(result2.entryId)} \u2014 ${sanitizeSingleLineField(result2.name)}`,
4120
4128
  ` standing ${sanitizeSingleLineField(o.kpiState.text)}`,
4121
- ` current ${o.current ? `${o.current.value}${unit} on ${safeDateSlice(o.current.asOf)}` : "\u2014"} (${o.readingCount} reading(s))`,
4129
+ ` current ${kpiCurrent(o.current, unit)} (${o.readingCount} reading(s))`,
4122
4130
  ` next due ${o.nextDueAt ? safeDateSlice(o.nextDueAt) : "no cadence set"}`,
4123
4131
  ` owner ${roleLabel(o.ownerRole)}`,
4124
4132
  ` reporter ${roleLabel(o.reporterRole)}`
4125
4133
  ].join("\n");
4126
4134
  }
4135
+ function kpiCurrent(current, unit) {
4136
+ if (!current) return "\u2014";
4137
+ if (current.line) return `${safeDateSlice(current.asOf)}: ${sanitizeSingleLineField(current.line)}`;
4138
+ return `${current.value}${unit} on ${safeDateSlice(current.asOf)}`;
4139
+ }
4127
4140
  function outcomeErrorResult(err, action, entryId, params = {}) {
4128
4141
  const classified = classifyError(err);
4129
4142
  const definedParams = Object.fromEntries(Object.entries(params).filter(([, v]) => v !== void 0));
@@ -4133,6 +4146,8 @@ function outcomeErrorResult(err, action, entryId, params = {}) {
4133
4146
  { tool: "context", description: "Check whether the reading already landed", parameters: { action: "readings", entryId } },
4134
4147
  { tool: "context", description: "Check the derived view", parameters: { action: "outcome", entryId } }
4135
4148
  ] : isMissingCorrectionTarget ? [{ tool: "context", description: "List readings for this entry to find a valid correctsReadingId", parameters: { action: "readings", entryId } }] : retryIsFutile(classified.code) ? void 0 : [retryAction(action, definedParams)];
4149
+ const withSource = `${classified.message} Add source.`;
4150
+ if (action === "record" && sourceMissing(err)) return failureResult(errorText({ message: withSource }), classified.code, withSource, "Add source.");
4136
4151
  const recovery = isMissingCorrectionTarget ? `The reading you name as correctsReadingId does not exist on ${entryId}. Use context action=readings to see its reading ids.` : classified.recovery ?? "Use context action=outcome with a valid entryId to check the key result exists.";
4137
4152
  return failureResult(
4138
4153
  errorText({ message: classified.message, recovery }),
@@ -4143,6 +4158,7 @@ function outcomeErrorResult(err, action, entryId, params = {}) {
4143
4158
  classified.diagnostics
4144
4159
  );
4145
4160
  }
4161
+ var sourceMissing = (err) => [err?.details].flat().some((d) => d?.fieldKey === "source" && d.errorType === "required");
4146
4162
  function retryAction(action, params) {
4147
4163
  if (action === "record") return { tool: "outcome", description: "Retry record", parameters: { action, ...params } };
4148
4164
  const read = action === "show" ? "outcome" : "readings";
@@ -4183,7 +4199,9 @@ async function handleOutcomeRecord(entryId, value, opts = {}) {
4183
4199
  const agentSessionId = getAgentSessionId();
4184
4200
  const receipt = await kernelMutation("outcomes.recordReading", {
4185
4201
  entryId,
4186
- value,
4202
+ ...value !== void 0 ? { value } : {},
4203
+ ...opts.count !== void 0 ? { count: opts.count } : {},
4204
+ ...opts.total !== void 0 ? { total: opts.total } : {},
4187
4205
  ...asOf !== void 0 ? { asOf } : {},
4188
4206
  ...opts.kind ? { kind: opts.kind } : {},
4189
4207
  ...opts.correctsReadingId ? { correctsReadingId: opts.correctsReadingId } : {},
@@ -4223,6 +4241,8 @@ async function handleOutcomeShow(entryId) {
4223
4241
  function registerOutcomeTools(server) {
4224
4242
  const outcomeHandlers = {
4225
4243
  record: (data) => handleOutcomeRecord(data.entryId, data.value, {
4244
+ count: data.count,
4245
+ total: data.total,
4226
4246
  valueText: data.valueText,
4227
4247
  asOf: data.asOf,
4228
4248
  kind: data.kind,
@@ -12433,4 +12453,4 @@ export {
12433
12453
  SERVER_VERSION,
12434
12454
  createProductBrainServer
12435
12455
  };
12436
- //# sourceMappingURL=chunk-252BGUM5.js.map
12456
+ //# sourceMappingURL=chunk-556VC5QK.js.map