Skip to content

Commit 727f578

Browse files
committed
feat(spec): an action can show the reader already pressed it — pressed
ActionSchema gains an optional per-reader pressed-state predicate (CEL over the visible scope, display only, no boolean arm). The expression lint judges it in the record scope as a served-row site, so an attachedOnRead block resolves there. Liveness row planned; console half is a follow-up. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibvXVNub8x3B5XhGFrP
1 parent 3a2f4c0 commit 727f578

14 files changed

Lines changed: 285 additions & 15 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@object-ui/core': patch
3+
---
4+
5+
`SPEC_ACTION_KEYS` lists `pressed`, the per-reader pressed-state predicate `@objectstack/spec` added to `ActionSchema`. An action that carries it is no longer counted as having an unknown key, and the inventory pin stays green. No surface reads the key yet.
6+
7+
Clause-②: no
8+
Metadata-protocol: none

‎.changeset/27946-action-pressed.md‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@objectstack/lint': minor
4+
---
5+
6+
feat(spec): an action can show the reader already pressed it — `pressed`
7+
8+
Clause-②: yes (widening)
9+
Metadata-protocol: added
10+
11+
`ActionSchema` gains one optional key, `pressed`: a CEL predicate over the same scope as `visible` (the record and the reader) that says this reader already acted, such as a "Helpful" vote on a knowledge article. While it evaluates TRUE an action surface draws the button pressed (`aria-pressed`). An action that does not declare it parses exactly as before.
12+
13+
```ts
14+
defineAction({
15+
name: 'mark_article_helpful',
16+
label: 'Helpful',
17+
objectName: 'kb_article',
18+
type: 'script',
19+
target: 'markHelpful',
20+
locations: ['record_header'],
21+
pressed: "has(record.viewer) && record.viewer.vote == 'helpful'",
22+
});
23+
```
24+
25+
- **A CEL predicate, not a boolean.** A string is normalized to the `{ dialect: 'cel', source }` envelope, and the envelope is accepted as written. `pressed: true` / `false` is refused at parse: a constant draws every reader's button the same way, which is a style and not the reader's state. The blank and `ast`-only shapes every evaluated slot refuses are refused here too. `active`, `activeWhen` and `pressedWhen` are renamed onto it.
26+
- **Display only.** It never gates, greys or routes the action. A pressed action stays runnable, and its own body decides what a second press does.
27+
- **The reader's own state.** A per-reader fact is usually a child row (one vote per user), not a column. Declare it as a block under the object's `attachedOnRead`, attach it on the serving side for the caller (a service, or an `afterFind` hook that shapes the rows it returns), and read `record.<block>.<leaf>` behind `has()`.
28+
- **Checked at build (`@objectstack/lint`).** `os build`, `os validate` and the object save door judge the predicate in the `record` scope, as they judge `visible`: a bare field reference is an error. An action's `pressed` is a served-row site, so a block the object declares under `attachedOnRead` resolves there and a misspelt leaf is refused.
29+
30+
Nothing draws the pressed face yet. The console's record header buttons and declared actions bar read the key in a follow-up change. Until then the liveness ledger marks it `planned` with `authorWarn`, so `os validate` warns an author who declares it that the button looks the same whatever the predicate answers.

‎content/docs/protocol/objectui/actions.mdx‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ interface Action {
246246
requiresFeature?: string; // Public auth feature flag gate — lowered into `visible` at parse time
247247
disabled?: boolean | ExpressionInput; // Disabled when TRUE (CEL)
248248
disabledReason?: I18nLabel; // Why it is greyed — hover title + accessible description (display only)
249+
pressed?: ExpressionInput; // Drawn as already pressed for this reader when TRUE (CEL; display only)
249250

250251
// Bulk
251252
bulkEnabled?: boolean; // Apply to multiple selected records
@@ -349,6 +350,26 @@ disabledReason: An approved legal review is required before the contract enters
349350
- A blank string (`''` or whitespace only) is refused at parse. Omit the key to keep the default.
350351
- It is **display only**. It does not change what `disabled` evaluates to, nothing reads it as a condition, and it is not access control: a call that reaches the server anyway is refused by the action's own rules (its body or hook, `requiredPermissions`), never by this text.
351352

353+
#### The reader's own state: `pressed`
354+
355+
An action the reader toggles, such as a "Helpful" vote on a knowledge article, says the reader **already acted** with `pressed`, a CEL predicate over the same scope as `visible`. While it is true the button is drawn pressed (`aria-pressed="true"`).
356+
357+
```yaml
358+
name: mark_article_helpful
359+
label: Helpful
360+
type: script
361+
locations: [record_header]
362+
pressed: "has(record.viewer) && record.viewer.vote == 'helpful'"
363+
```
364+
365+
- It is **display only**. A pressed action stays runnable, and the action's own body decides what a second press does (records the vote again, withdraws it, or answers "already").
366+
- A boolean literal is refused: `pressed: true` would draw the button pressed for every reader, which is a style rather than the reader's state.
367+
- A per-reader fact is usually not a column of the row (a vote is a child record per user). Declare it as a block under the object's `attachedOnRead`, have the serving side attach it to each row it returns for the caller (a service, or an `afterFind` hook that shapes the rows), and read it as `record.<block>.<leaf>`, guarded with `has()`. `os build` and `os validate` check the leaf against the declared block.
368+
369+
<Callout type="info">
370+
The spec, the build check and this contract are in place; the console's record header and declared actions bar do not draw the pressed face yet, so today the button looks the same whatever the predicate answers.
371+
</Callout>
372+
352373
#### Evaluation context
353374

354375
Action predicates evaluate against the **record the action is attached to**. Both `record.<field>` and the bare field name resolve to the current record's value:

‎packages/lint/src/validate-expressions.attached-on-read.test.ts‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* A read attachment is a block a service sets on each row it serves, computed
88
* per caller and never stored. At a served-row site (`SERVED_ROW_SITES`: an
9-
* action's `visible` and `disabled`), its block name joins the names
9+
* action's `visible`, `disabled` and `pressed`), its block name joins the names
1010
* `record.<x>` resolves to, and the second segment of `record.<block>.<leaf>`
1111
* is judged against the block's declared leaves — under the EXISTING
1212
* `unknown-field` refusal, with no new rule and nothing keyed on a block's
@@ -205,6 +205,28 @@ describe('attachedOnRead — record.<block>.<leaf> at a served-row site', () =>
205205
expect(issues[0].message).toContain('unknown field `viewer.can_actt` on `approval_probe`');
206206
});
207207

208+
it('an action `pressed` predicate is a served-row site too — the per-reader read it exists for', () => {
209+
// The worked case: a reader's own vote is a child row per user, so it
210+
// reaches the predicate only as a block the serving side attaches per
211+
// caller. `has()` guards a row fetched by another route.
212+
const VOTE = { vote: 'text' } as const;
213+
const pressedIssuesFor = (pressed: string, declared: boolean) => validateStackExpressions(
214+
specValid({
215+
objects: [{ ...probe(false), ...(declared ? { attachedOnRead: { reader: VOTE } } : {}) }],
216+
actions: [{ name: 'mark_helpful', label: 'Helpful', objectName: 'approval_probe', type: 'script', target: 'fn', pressed }],
217+
}),
218+
);
219+
expect(pressedIssuesFor("has(record.reader) && record.reader.vote == 'helpful'", true)).toEqual([]);
220+
const misspelt = pressedIssuesFor("has(record.reader) && record.reader.vot == 'helpful'", true);
221+
expect(misspelt).toHaveLength(1);
222+
expect(misspelt[0].where).toBe("stack · action 'mark_helpful' pressed");
223+
expect(misspelt[0].message).toContain('unknown field `reader.vot` on `approval_probe`');
224+
// Control: undeclared, the block is the unknown field it is at run time.
225+
const undeclared = pressedIssuesFor("has(record.reader) && record.reader.vote == 'helpful'", false);
226+
expect(undeclared.map((i) => [i.where, i.severity])).toContainEqual(["stack · action 'mark_helpful' pressed", 'error']);
227+
expect(undeclared.some((i) => i.message.includes('unknown field `reader` on `approval_probe`'))).toBe(true);
228+
});
229+
208230
it('an object without the key keeps today’s verdict (control)', () => {
209231
const issues = issuesFor('record.viewer.can_act', false);
210232
expect(issues).toHaveLength(1);

‎packages/lint/src/validate-expressions.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,25 @@ describe('validateStackExpressions (ADR-0032 build-time)', () => {
926926
expect(ok).toHaveLength(0);
927927
});
928928

929+
it('flags a bare-field `pressed` predicate and accepts the record-qualified form (#27946)', () => {
930+
// Same record scope and fault as `visible`: a bare `vote` throws at key
931+
// resolution, so the button would never be drawn pressed.
932+
const bad = validateStackExpressions({
933+
objects: [{ name: 'kb_article', fields: { my_vote: { type: 'text' } } }],
934+
actions: [{ name: 'mark_helpful', objectName: 'kb_article', type: 'script', target: 'fn', pressed: 'my_vote == "helpful"' }],
935+
});
936+
const pressedIssues = bad.filter(i => i.where.includes("action 'mark_helpful' pressed"));
937+
expect(pressedIssues).toHaveLength(1);
938+
expect(pressedIssues[0].severity).toBe('error');
939+
expect(pressedIssues[0].message).toMatch(/bare reference `my_vote`/);
940+
941+
const ok = validateStackExpressions({
942+
objects: [{ name: 'kb_article', fields: { my_vote: { type: 'text' } } }],
943+
actions: [{ name: 'mark_helpful', objectName: 'kb_article', type: 'script', target: 'fn', pressed: 'record.my_vote == "helpful"' }],
944+
});
945+
expect(ok).toHaveLength(0);
946+
});
947+
929948
it('never reads `disabledReason` as a predicate — it is display copy (#26619)', () => {
930949
// The same bare-field source that is an error on `disabled` above is a
931950
// plain sentence on `disabledReason`: nothing is checked, nothing flagged.

‎packages/lint/src/validate-expressions.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ function buildAttachedOnReadIndex(objects: AnyRec[]): Map<string, Record<string,
278278
* on `record` only where `record` is such a served row, and this list names
279279
* those sites:
280280
*
281-
* - an action's `visible` and `disabled` predicates. The client's action
282-
* runtime evaluates them against the row the surface fetched, and a surface
281+
* - an action's `visible`, `disabled` and `pressed` predicates. The client's
282+
* action runtime evaluates them against the row the surface fetched, and a surface
283283
* that reads the declaring service's own routes holds the row that service
284284
* served — the console reads `sys_approval_request` through the approvals
285285
* routes, whose rows carry the `viewer` block. A surface that fetched the
@@ -310,7 +310,7 @@ function buildAttachedOnReadIndex(objects: AnyRec[]): Map<string, Record<string,
310310
* new site is fields-only until its binding is shown to be a served row and it
311311
* is listed.
312312
*/
313-
const SERVED_ROW_SITES = ['action visible', 'action disabled'] as const;
313+
const SERVED_ROW_SITES = ['action visible', 'action disabled', 'action pressed'] as const;
314314
type ServedRowSite = (typeof SERVED_ROW_SITES)[number];
315315

316316
/**
@@ -3470,7 +3470,7 @@ export function runStackExpressionPasses(stack: AnyRec, options: StackExpression
34703470
}
34713471
}
34723472

3473-
// ── Action `visible` / `disabled` predicates ───────────────────────
3473+
// ── Action `visible` / `disabled` / `pressed` predicates ────────────
34743474
// Record-scoped, same as validation rules: a record-header / row action's
34753475
// `visible` is evaluated by ActionEngine against `{ record, recordId,
34763476
// objectName, user, … }` with fail-closed semantics, so a BARE field ref
@@ -3495,6 +3495,11 @@ export function runStackExpressionPasses(stack: AnyRec, options: StackExpression
34953495
if (typeof action.disabled !== 'boolean') {
34963496
check(`${where} · action '${name}' disabled`, action.disabled, obj, 'record', undefined, undefined, 'action disabled');
34973497
}
3498+
// [#27946] The pressed-state predicate binds the same row as `visible`, and
3499+
// it is the predicate a per-reader block exists for (`has(record.viewer) &&
3500+
// record.viewer.vote == 'helpful'`), so it is a served-row site too. No
3501+
// boolean skip: the schema refuses a boolean literal on this key.
3502+
check(`${where} · action '${name}' pressed`, action.pressed, obj, 'record', undefined, undefined, 'action pressed');
34983503
// No `checkNullGuards` here, and the reason is measured rather than assumed
34993504
// (#4811). These predicates DO reach real CEL — a bare authored string is
35003505
// normalized to a `{dialect:'cel'}` envelope by `ExpressionInputSchema` and

‎packages/qa/dogfood/test/expression-conformance.ledger.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,16 @@ export const EXPRESSION_SURFACE: ExprSurface[] = [
429429
covers: ['ui/action.zod.ts:actionObject.disabled'],
430430
note: 'Split from `cel-action-visible` rather than sharing one row with it, for the reason the collision assertion encodes: one classification covering both would have to pick one fail-policy, and the two faces are opposites — a faulting `visible` HIDES the action, a `disabled` the renderer cannot evaluate LEAVES IT RUNNABLE. A single row would have stated one of those and silently spoken for the other. ⛔ NOT MEASURED HERE: the renderer, and the `-log` half of `fail-soft-log` — the reading above establishes the soft DIRECTION from the objectui fix that removed the closed face, not that a line is logged; the same posture, and the same limit, as `cel-row-crud-disabled` on the built-in row buttons.',
431431
},
432+
{
433+
// The key arrived with #27946, its spec half; the console half is a follow-up card.
434+
id: 'cel-action-pressed',
435+
summary: 'registered action pressed state (Action.pressed) — the per-reader toggle face of a button, drawn as aria-pressed',
436+
dialect: 'cel', mode: 'interpret', state: 'experimental', failPolicy: 'unevaluated',
437+
enforcement:
438+
'PARSE ONLY — `EvaluatedExpressionInputSchema` normalizes a bare string to `{dialect:"cel",source}` and refuses a boolean literal, an `ast`-only envelope and a blank source; NO EVALUATOR FOUND: no action surface reads the key yet. The build-time gate is in place ahead of the reader: lint/validate-expressions.ts `checkAction` checks it against the `record` scope on every declared action, as a served-row site where a block the object declares under `attachedOnRead` resolves',
439+
covers: ['ui/action.zod.ts:actionObject.pressed'],
440+
note: 'EXPERIMENTAL until the console draws it: declared spec-first, with the liveness row `planned`. Display only by contract — it never gates, greys or routes the action — so when the reader lands its fault face is a plain, unpressed button, and this row is re-stated as `enforced` with that fail policy, naming the surfaces that evaluate it.',
441+
},
432442
{
433443
id: 'cel-record-alert-visible',
434444
summary: '`record:alert` banner visibility (RecordAlertProps.visible) — the one record component whose PROPS carry a real predicate',

‎packages/spec/liveness/action.json‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,15 @@
158158
"evidence": "ui/packages/components/src/renderers/layout/containers.tsx#disabledReasonFor (the record header, inline and in the ⋯ overflow: the declared reason, else `actions.notAvailableForRecord`); ui/packages/plugin-detail/src/renderers/record-quick-actions.tsx#QuickActionButton (the record section bar); ui/packages/app-shell/src/views/DeclaredActionsBar.tsx#DeclaredActionButton (the declared actions bar, button and override-menu item); ui/packages/components/src/renderers/action/disabled-reason.tsx#useDisabledReason (the four `action:*` renderers: `action-button.tsx`, `action-icon.tsx`, `action-group.tsx`, `action-menu.tsx`); ui/packages/react/src/hooks/useActionTextLocalizer.ts#useActionTextLocalizer and ui/packages/i18n/src/useObjectLabel.ts#useObjectLabel (`actionDisabledReason`: the bundle's `_actions.{a}.disabledReason` / `globalActions.{a}.disabledReason`, else the authored I18nLabel collapsed to the active language); packages/spec/src/system/i18n-resolver.ts#translateAction (the served overlay); packages/cli/src/utils/i18n-extract.ts#collectExpectedEntries (the extract).",
159159
"note": "LIVE since the console half of #26619 (ruling 6442737825, letter A: spec PR #26786 first, this console PR second). Each greyed-action surface shows the declared reason as the hover title and the accessible description (a menu item's second line), only while the DECLARED `disabled` predicate is TRUE, and shows `actions.notAvailableForRecord` (\"Not available for this record\") when the action declares none or a blank one. The record header, the section bar and the declared actions bar run actions through `useActionTextLocalizer`, so the bundle's sentence outranks the authored text; the four `action:*` renderers read the action as authored and honour its inline locale map. `authorWarn` / `authorHint` were dropped in the same edit (a warned `live` row reds this gate, #21127). Display only by contract: never a server admission input, never read as a predicate."
160160
},
161+
"pressed": {
162+
"status": "planned",
163+
"verifiedAt": "2026-10-30",
164+
"evidenceScope": "in-repo",
165+
"authorWarn": true,
166+
"authorHint": "Kept, but no console surface draws `pressed` yet: the button looks the same whatever the predicate answers. The predicate is still checked at build (record scope, declared fields and `attachedOnRead` blocks), so it is ready when the header buttons read it.",
167+
"evidence": "packages/spec/src/ui/action.zod.ts#pressed (the parse-time door: `EvaluatedExpressionInputSchema`, a CEL string normalized to the envelope, a boolean literal and the blank shapes refused); packages/lint/src/validate-expressions.ts#checkAction (the authoring gate at `os build` / `os validate` and the object save door: the predicate is judged in the `record` scope, and as a SERVED_ROW_SITES member a block the object declares under `attachedOnRead` resolves)",
168+
"note": "PLANNED — declared spec-first by #27946 (spec half; the console half is a follow-up domain:ui card). The reader to come is the record page header (`page:header` buttons) and `DeclaredActionsBar`, drawing the button with `aria-pressed` and a pressed face while the predicate is TRUE. Measured in this repo at origin/main 3a2f4c00: no source under ui/ reads `action.pressed` (the one hit is the inventory line in ui/packages/core/src/actions/actionKeys.ts SPEC_ACTION_KEYS, which restates the spec's declared keys and reads nothing), and no other package reads it. So an authored predicate draws nothing today; nothing is gated or stored differently, which is also the contract once it is live (display only). Flip to `live` on the console PR, citing its read points, and drop `authorWarn` / `authorHint` in the same edit (a warned `live` row reds this gate)."
169+
},
161170
"ai": {
162171
"status": "live",
163172
"verifiedAt": "2026-09-15",

0 commit comments

Comments
 (0)