Skip to content

Commit 3f315cd

Browse files
committed
feat(mcp): validate_expression takes a time-relative flow's swept object
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CaUg3ibF939L2RFB5D
1 parent 4258030 commit 3f315cd

4 files changed

Lines changed: 94 additions & 27 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
'@objectstack/lint': minor
3+
'@objectstack/mcp': minor
4+
---
5+
6+
fix(lint)!: a time-relative flow whose start node names no `objectName` has its conditions typed against the object it sweeps (`timeRelative.object`), so a text-vs-number comparison there is refused like on a sweep of the start node's object; a sweep of another object is told why it only warns; and `validate_expression` takes the swept object (#30026)
7+
8+
Clause-②: yes (narrowing) — the author-time gate (`os build`, `os validate`, the package publish and the flow publish door) refuses a `type-mismatch` in the start, edge and `decision` conditions of a time-relative flow whose start node names no `objectName`, which it passed with no type verdict at all before. Added beside it (the widening half): the optional `sweepObject` input of the `validate_expression` MCP tool.
9+
Metadata-protocol: narrowed
10+
Skills-docs: updated here — the MCP skill text in `packages/mcp/src/skill-md.ts` (the new `sweepObject` input); `skills/**` teaches no time-relative flow condition with a text-vs-number comparison, so no skill or eval moves.
11+
12+
<!-- adr-0087: not-required (already-registered flow-record-read-and-decision-type-mismatch-refused) the entry already prescribes this exact rewrite for a time-relative flow's conditions: the same refusal code, the same replacement and the same reason (each run's record is a row of the swept object); this change extends it to a sweep whose start names no objectName -->
13+
14+
**BREAKING** accept-set narrowing at the author-time expression gate, served by `os build`, `os validate` and `POST /api/v1/packages/:id/publish-drafts`.
15+
16+
- **Before.** A time-relative flow was typed only against its start node's `objectName`. A start that named none, with the swept object in `timeRelative.object` (the key the descriptor requires), got no type verdict on its conditions at all: `title > 5` on a text field published clean, and every run the sweep launched failed at that condition.
17+
- **Now.** The conditions of such a flow are typed against `timeRelative.object`: each run's record is a row of that object, so a text-vs-number comparison in its start, edge or `decision` conditions is refused as `type-mismatch-run-fails`, the verdict a sweep of the start node's object already gets. Field reads, the shadowing warning and the root check are judged against the same object.
18+
- **A sweep of another object** (the start node's `objectName` is not `timeRelative.object`) keeps the `type-mismatch-run-may-fail` warning, and the flow now gets one more warning, at its start node's `config.objectName`, saying why: the conditions are checked against that object's fields while each run's record is a row of the swept one. It is served only on a flow that got a warning it explains.
19+
- **`validate_expression` (MCP).** New optional input `sweepObject` (site `flow_condition` with `triggerKind: 'time_relative'` only; a tool error anywhere else): the flow's `timeRelative.object`. When it is another object than `objectName`, a type mismatch is the gate's warning instead of the run-fails error. A call that does not pass it answers as before.
20+
- **Correction to the 18.x changeset of the flow-condition type check.** It described a time-relative flow whose `timeRelative.object` "is omitted" as sweeping the start node's object. That shape never binds: `TimeRelativeTriggerSchema` requires `object`, and the gate refuses its absence (`flow-time-relative-descriptor-invalid`). Such a flow now gets the warning, not the run-fails verdict, on its conditions, since no run of it binds a row.
21+
22+
**FROM → TO.** In a time-relative flow whose start names no `objectName`, sweeping `crm_opportunity` with a text field `title`: `title > 5` (or `record.title > 5`, or a decision branch `title * 2 > 10`) → `size(title) > 5` for its length, a number field for a value, or `double(title) > 5` only when every value is numeric text. A flow whose start names one object and sweeps another: set the start node's `objectName` to the swept object, or remove it.

‎packages/mcp/src/mcp-http-tools.ts‎

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -644,9 +644,15 @@ const VALIDATE_SITE_MAP: Record<
644644
* [#29904, #29926, #29959] What the gate's runtime does on a fault at this
645645
* site, from the caller's optional `severity` / `triggerKind` — the two
646646
* facts `@objectstack/lint`'s `faultOutcomeOf` ledger reads off the rule
647-
* and the flow. Absent: the site declares none.
647+
* and the flow — and (#30026) `sweepsTypedObject`, the ledger's third: a
648+
* time-relative sweep's object is `objectName` (no `sweepObject`, or the
649+
* same one). Absent: the site declares none.
648650
*/
649-
faultOutcome?: (inputs: { severity: ValidationSeverity; triggerKind: FlowTriggerOrNone }) => ExprFaultOutcome | undefined;
651+
faultOutcome?: (inputs: {
652+
severity: ValidationSeverity;
653+
triggerKind: FlowTriggerOrNone;
654+
sweepsTypedObject: boolean;
655+
}) => ExprFaultOutcome | undefined;
650656
}
651657
> = {
652658
formula: { role: 'value', scope: 'record', slot: EvaluatedExpressionInputSchema, optionLabels: true },
@@ -663,14 +669,15 @@ const VALIDATE_SITE_MAP: Record<
663669
// branch condition (the default `triggerKind`): the trigger record is
664670
// flattened into the run's variables, a fault fails the run while the write
665671
// that fired it lands, and the gate grades a text-vs-number comparison an
666-
// error worded so. A time-relative sweep launches each run with the swept
667-
// row of `objectName` as its record, so it is graded the same. Any other
668-
// trigger kind declares no outcome: the gate's `type-mismatch-run-may-fail`
669-
// warning.
672+
// error worded so. A time-relative sweep launches each run with a row of
673+
// the swept object as its record, so a sweep of `objectName` is graded the
674+
// same; a sweep of another object (`sweepObject`, #30026) binds a row of
675+
// THAT object, and like any other trigger kind declares no outcome: the
676+
// gate's `type-mismatch-run-may-fail` warning.
670677
flow_condition: {
671678
role: 'predicate', scope: 'flattened', slot: EvaluatedExpressionInputSchema,
672-
faultOutcome: ({ triggerKind }) =>
673-
(triggerKind === 'record_change' || triggerKind === 'time_relative' ? 'run-fails' : undefined),
679+
faultOutcome: ({ triggerKind, sweepsTypedObject }) =>
680+
(triggerKind === 'record_change' || (triggerKind === 'time_relative' && sweepsTypedObject) ? 'run-fails' : undefined),
674681
},
675682
template: { role: 'template', scope: 'record', slot: TemplateExpressionInputSchema },
676683
};
@@ -1092,11 +1099,12 @@ export function registerObjectTools(
10921099
'build-time errors (bare field refs, unknown fields, unknown functions) and advisory warnings ' +
10931100
'(text/boolean fields misused in arithmetic, an error at a `validation` site, worded for the rule\'s ' +
10941101
'`severity`, and at a `flow_condition` of a record-triggered or time-relative flow, where it fails the run; ' +
1095-
'a warning on any other flow; date-equality pitfalls), plus the fields and stdlib ' +
1102+
'a warning on any other flow, a time-relative sweep of another object included; date-equality pitfalls), plus the fields and stdlib ' +
10961103
'functions in scope so you can self-correct. `site` says where the expression will live: a `formula` ' +
10971104
'field, a `validation`/predicate, or a `flow_condition` (fields are bound bare in flow conditions). ' +
1098-
'Pass the rule\'s `severity` (validation) or the flow\'s `triggerKind` (flow_condition) so the verdict ' +
1099-
'is the one the publish gate gives that rule or flow.',
1105+
'Pass the rule\'s `severity` (validation) or the flow\'s `triggerKind` (flow_condition), and a time-relative ' +
1106+
'flow\'s `sweepObject` when it sweeps another object than objectName, so the verdict is the one the publish ' +
1107+
'gate gives that rule or flow.',
11001108
inputSchema: strictToolInput(
11011109
{
11021110
surface: 'this validate_expression call',
@@ -1133,11 +1141,20 @@ export function registerObjectTools(
11331141
'is an error on a record_change or time_relative flow (its record is a row of objectName) and a warning ' +
11341142
'on any other. Default: record_change.',
11351143
),
1144+
sweepObject: z
1145+
.string()
1146+
.optional()
1147+
.describe(
1148+
'site flow_condition with triggerKind time_relative only: the flow\'s `timeRelative.object`, whose rows ' +
1149+
'the sweep hands each run as its record. objectName is the object the conditions are typed against: the ' +
1150+
'start node\'s objectName, else the swept object itself. When sweepObject is another object, a type ' +
1151+
'mismatch is a warning, not an error: the run\'s record is a row of sweepObject. Default: objectName.',
1152+
),
11361153
},
11371154
),
11381155
annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false },
11391156
},
1140-
async ({ objectName, expression, site, severity, triggerKind }) => {
1157+
async ({ objectName, expression, site, severity, triggerKind, sweepObject }) => {
11411158
const bad = guard(objectName);
11421159
if (bad) return errorResult(bad);
11431160
// [#29959] Each input describes one site; on another it would be
@@ -1148,6 +1165,13 @@ export function registerObjectTools(
11481165
if (triggerKind !== undefined && site !== 'flow_condition') {
11491166
return errorResult(`\`triggerKind\` describes a flow; it applies only with site "flow_condition", not "${site ?? 'formula'}".`);
11501167
}
1168+
// [#30026] The swept object describes a time-relative flow alone.
1169+
if (sweepObject !== undefined && (site !== 'flow_condition' || triggerKind !== 'time_relative')) {
1170+
return errorResult(
1171+
`\`sweepObject\` describes a time-relative sweep; it applies only with site "flow_condition" and triggerKind ` +
1172+
`"time_relative", not site "${site ?? 'formula'}" with triggerKind "${triggerKind ?? 'record_change'}".`,
1173+
);
1174+
}
11511175
try {
11521176
const def = (await bridge.describeObject(objectName)) as { fields?: unknown } | null;
11531177
if (!def) return errorResult(`Object "${objectName}" not found`);
@@ -1160,7 +1184,11 @@ export function registerObjectTools(
11601184
if (typeof f?.type === 'string') fieldTypes[f.name] = f.type;
11611185
}
11621186
const { role, scope, slot, optionLabels, faultOutcome: outcomeOf } = VALIDATE_SITE_MAP[site ?? 'formula'];
1163-
const faultOutcome = outcomeOf?.({ severity: severity ?? 'error', triggerKind: triggerKind ?? 'record_change' });
1187+
const faultOutcome = outcomeOf?.({
1188+
severity: severity ?? 'error',
1189+
triggerKind: triggerKind ?? 'record_change',
1190+
sweepsTypedObject: sweepObject === undefined || sweepObject === objectName,
1191+
});
11641192
// [#28715] The object's option-bearing fields, where the gate reads
11651193
// them: `label(record.<field>)` on a declared field outside this list
11661194
// is refused as `label-field-no-options` by the one validator.

‎packages/mcp/src/mcp-validate-expression.test.ts‎

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,32 +163,42 @@ describe('validate_expression MCP tool (#1928)', () => {
163163
}
164164

165165
// The severity column is the ledger's own answer (`faultOutcomeOf`): a
166-
// time-relative sweep binds a row of `objectName` as its record (#29959).
167-
for (const [triggerKind, startConfig, flowType, severity] of [
168-
[undefined, { triggerType: 'record-after-update' }, 'autolaunched', 'error'],
169-
['record_change', { triggerType: 'record-after-create' }, 'autolaunched', 'error'],
170-
['time_relative', { timeRelative: { object: 'crm_opportunity', field: 'close_date', offsetDays: 1 }, schedule: '0 * * * *' }, 'autolaunched', 'error'],
171-
['schedule', { schedule: '0 * * * *' }, 'autolaunched', 'warning'],
172-
['api', {}, 'api', 'warning'],
173-
['none', {}, 'autolaunched', 'warning'],
166+
// time-relative sweep binds a row of the swept object as its record
167+
// (#29959) — `objectName`'s, unless `sweepObject` names another (#30026).
168+
// `startObject: null` is a start node naming no objectName: the gate then
169+
// types the conditions against the swept object, the tool's `objectName`.
170+
const sweep = (object: string) => ({ timeRelative: { object, field: 'close_date', offsetDays: 1 }, schedule: '0 * * * *' });
171+
for (const [label, triggerKind, sweepObject, startObject, startConfig, flowType, severity] of [
172+
['(omitted)', undefined, undefined, 'crm_opportunity', { triggerType: 'record-after-update' }, 'autolaunched', 'error'],
173+
['record_change', 'record_change', undefined, 'crm_opportunity', { triggerType: 'record-after-create' }, 'autolaunched', 'error'],
174+
['time_relative', 'time_relative', undefined, 'crm_opportunity', sweep('crm_opportunity'), 'autolaunched', 'error'],
175+
['time_relative, sweepObject objectName', 'time_relative', 'crm_opportunity', 'crm_opportunity', sweep('crm_opportunity'), 'autolaunched', 'error'],
176+
['time_relative, start names no objectName', 'time_relative', undefined, null, sweep('crm_opportunity'), 'autolaunched', 'error'],
177+
['time_relative, sweepObject another object', 'time_relative', 'crm_task', 'crm_opportunity', sweep('crm_task'), 'autolaunched', 'warning'],
178+
['schedule', 'schedule', undefined, 'crm_opportunity', { schedule: '0 * * * *' }, 'autolaunched', 'warning'],
179+
['api', 'api', undefined, 'crm_opportunity', {}, 'api', 'warning'],
180+
['none', 'none', undefined, 'crm_opportunity', {}, 'autolaunched', 'warning'],
174181
] as const) {
175-
it(`site flow_condition, triggerKind ${triggerKind ?? '(omitted)'}`, async () => {
182+
it(`site flow_condition, triggerKind ${label}`, async () => {
176183
const expression = 'title * 2 > 10';
177184
const gate = typeVerdicts(validateStackExpressions({
178-
objects: [{ name: 'crm_opportunity', fields }],
185+
objects: [{ name: 'crm_opportunity', fields }, { name: 'crm_task', fields: { close_date: { type: 'date' } } }],
179186
flows: [{
180187
name: 'f',
181188
type: flowType,
182189
nodes: [
183-
{ id: 'start', type: 'start', config: { objectName: 'crm_opportunity', condition: expression, ...startConfig } },
190+
{ id: 'start', type: 'start', config: { ...(startObject ? { objectName: startObject } : {}), condition: expression, ...startConfig } },
184191
{ id: 'end', type: 'end' },
185192
],
186193
edges: [{ id: 'e1', source: 'start', target: 'end' }],
187194
}],
188195
}));
189196
expect(gate).toHaveLength(1);
190197
expect(gate[0]![0]).toBe(severity);
191-
const r = await validate(runtime, bridge, { objectName: 'crm_opportunity', expression, site: 'flow_condition', ...(triggerKind ? { triggerKind } : {}) });
198+
const r = await validate(runtime, bridge, {
199+
objectName: 'crm_opportunity', expression, site: 'flow_condition',
200+
...(triggerKind ? { triggerKind } : {}), ...(sweepObject ? { sweepObject } : {}),
201+
});
192202
expect(toolVerdicts(r)).toEqual(gate);
193203
});
194204
}
@@ -200,6 +210,11 @@ describe('validate_expression MCP tool (#1928)', () => {
200210
{ severity: 'info' },
201211
{ site: 'validation', triggerKind: 'api' },
202212
{ triggerKind: 'record_change' },
213+
// [#30026] The swept object describes a time-relative flow alone.
214+
{ site: 'flow_condition', sweepObject: 'crm_task' },
215+
{ site: 'flow_condition', triggerKind: 'record_change', sweepObject: 'crm_task' },
216+
{ site: 'validation', sweepObject: 'crm_task' },
217+
{ sweepObject: 'crm_task' },
203218
]) {
204219
const { json } = await call(runtime, toolsCall(1, 'validate_expression', { objectName: 'crm_opportunity', expression: 'record.title > 5', ...args }), bridge);
205220
const { result } = json as { result: { isError?: boolean; content: { text: string }[] } };

‎packages/mcp/src/skill-md.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ create/update payload.
264264
265265
- **list_objects()** — list available objects (system \`sys_*\` objects are hidden).
266266
- **describe_object({ objectName })** — an object's fields and features.
267-
- **validate_expression({ objectName, expression, site?, severity?, triggerKind? })** — check a CEL
267+
- **validate_expression({ objectName, expression, site?, severity?, triggerKind?, sweepObject? })** — check a CEL
268268
expression against an object's schema *before* you author it into a formula,
269269
validation, or flow condition. Returns build-time errors (bare field refs,
270270
unknown fields/functions) and advisory warnings (text/boolean fields misused
@@ -274,7 +274,9 @@ create/update payload.
274274
stdlib functions in scope. \`site\` is \`formula\` | \`validation\` |
275275
\`flow_condition\` | \`template\` (default \`formula\`). Pass the rule's
276276
\`severity\` or the flow's \`triggerKind\` (\`record_change\` by default) to
277-
get the verdict the publish gate gives that rule or flow.
277+
get the verdict the publish gate gives that rule or flow; for a
278+
\`time_relative\` flow that sweeps another object than \`objectName\`, also
279+
pass its \`timeRelative.object\` as \`sweepObject\` (then a mismatch warns).
278280
- **query_records({ objectName, where?, fields?, limit?, offset?, orderBy? })** —
279281
read records. \`where\` is a field→value match, e.g. \`{ "status": "open" }\`.
280282
Results are page-capped; use \`limit\`/\`offset\` to page.

0 commit comments

Comments
 (0)