Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f8a88d3
feat(spec): offer the hook texts row in the Studio hook form
claude Nov 19, 2026
0cfc18e
feat(spec): HookContext declares ctx.text
claude Nov 19, 2026
0d0744c
feat(platform-objects): the hook texts row in the eleven metadata-for…
claude Nov 19, 2026
5fb2206
test(spec): a parsed hook context needs its engine reference
claude Nov 19, 2026
13feefb
test(spec): the typed hook context literal carries its engine reference
claude Nov 19, 2026
772b1c3
chore(spec): regenerate the artifacts HookContext.text moves, add the…
claude Nov 19, 2026
3d0f92b
test(platform-objects): the hook form's texts record joins the enumer…
claude Nov 19, 2026
b702af9
chore(changeset): HookContext.text is an added protocol member, spec …
claude Nov 19, 2026
88900c1
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 19, 2026
a1fd42b
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 19, 2026
ab850bf
feat(spec): the Studio action form offers the action's declared texts
claude Nov 19, 2026
e2f6d2f
feat(platform-objects): the action texts row's label and help text in…
claude Nov 19, 2026
26fbd42
feat(spec): the Studio action form offers the action's refusal catalogue
claude Nov 19, 2026
52a32ad
feat(platform-objects): the action refusals row's label and help text…
claude Nov 19, 2026
6547df4
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 19, 2026
ef816f8
test(lint): the shipped-forms predicate census counts the action text…
claude Nov 19, 2026
5cddfca
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 19, 2026
7a158d4
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 19, 2026
d821bb8
fix(spec): the save door's literal ctx.text reader also reads ctx.tex…
claude Nov 19, 2026
2a7c8c9
fix(spec): register the narrowing and add its changeset
claude Nov 19, 2026
269566b
docs(spec): rewrap the key reader's TSDoc
claude Nov 19, 2026
0acd17d
fix(spec): drop the non-null ctx.text arm; pin the handler optional c…
claude Nov 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .changeset/35512-text-call-shapes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@objectstack/spec': minor
---

fix(spec): the save door refuses an undeclared text key asked for as `ctx.text?.('k')`, as it already did for `ctx.text('k')`

Clause-②: no (narrowing)
Metadata-protocol: narrowed

**BREAKING** for a hook that declares `texts` and whose code asks for a key `texts` does not declare through the optional call `ctx.text?.('k')`. Action `texts` is read the same way from the release that introduces it, so no released action is affected.

- FROM: `HookSchema` refused a key asked for literally and not declared in `texts` only for the plain call `ctx.text('k')`. `ctx.text?.('k')` and `await ctx.text?.('k')` with an undeclared key parsed green, and the runtime refused the key only when the hook ran.
- TO: the optional call is refused at save with the sentence the plain call already gets, at `body.source` for a `js` body or at `handler` for an in-process handler. Whitespace or a line break around `?.` is read too.
- Fix: declare the key under `texts.KEY` with the sentence the record keeps, or ask for one of the declared keys. A declared key is accepted in both shapes.

A key that arrives any other way (a variable, a computed name) is still judged when the code runs.

<!-- adr-0087: registered hook-action-text-key-optional-call-refused -->
5 changes: 3 additions & 2 deletions content/docs/automation/hooks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,9 @@ export const leadFollowUp = {
the organization's choice. Catch it if the hook should write anyway.
- **Only declared text is translated.** A string the hook builds itself is
written as it is. A key `texts` does not declare is refused when the hook is
saved if the hook names it literally in `ctx.text('key')`, otherwise when the
hook runs, as a `500` that names the hook and the key.
saved if the hook names it literally in `ctx.text('key')` or
`ctx.text?.('key')`, otherwise when the hook runs, as a `500` that names the
hook and the key.
- **It works whichever way the hook is written** — a TypeScript `handler` and a
sandboxed `js` body get the same `ctx.text`. An `expression` body cannot ask
for one, so `texts` is refused there.
Expand Down
25 changes: 18 additions & 7 deletions packages/spec/src/data/hook-refusal-codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,9 @@ function undeclaredRefusalReasonAtRun(
* (parameter 4).
*
* The same two halves as a refusal code: a key the hook's source asks for
* LITERALLY and `texts` does not declare is refused at save
* ({@link hookTextKeysAskedIn}); any other key is refused when the hook runs.
* LITERALLY — `ctx.text('key'` or `ctx.text?.('key'` — and `texts` does not
* declare is refused at save ({@link hookTextKeysAskedIn}); any other key is
* refused when the hook runs.
*/

/**
Expand All @@ -433,16 +434,26 @@ function undeclaredRefusalReasonAtRun(
*/
export const HOOK_TEXT_KEY_PATTERN = /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/;

/** `ctx.text('key'` — the call a hook's code asks for a declared text with. */
/**
* `ctx.text('key'` — the call a hook's code asks for a declared text with — and
* its optional-call shape `ctx.text?.('key'`, which strict TypeScript reaches
* for because `HookContext.text` is optional. Both ask for the key literally.
*
* A non-null `ctx.text!('key'` is not read: it is TypeScript with no
* JavaScript form. A handler's `!` is erased before the save reads
* `Function.prototype.toString()`, so it arrives as the plain call; in a `js`
* body it is a syntax error, and the body never runs.
*/
const TEXT_CALL = new RegExp(
String.raw`(?<![\w$.])ctx\s*\.\s*text\s*\(\s*(?<tquote>['"\x60])(?<key>[a-z][a-z0-9]*(?:_[a-z0-9]+)*)\k<tquote>`,
String.raw`(?<![\w$.])ctx\s*\.\s*text(?:\s*\?\.)?\s*\(\s*(?<tquote>['"\x60])(?<key>[a-z][a-z0-9]*(?:_[a-z0-9]+)*)\k<tquote>`,
'g',
);

/**
* The text keys a hook's source asks for LITERALLY — `ctx.text('key', …)` —
* in first-seen order: the cases a save can decide. A key that arrives any
* other way (a variable, a computed value) is left to the run-time refusal.
* The text keys a hook's source asks for LITERALLY — `ctx.text('key', …)` or
* `ctx.text?.('key', …)` — in first-seen order:
* the cases a save can decide. A key that arrives any other way (a variable,
* a computed value) is left to the run-time refusal.
* Comments and longer strings are blanked first, as for a refusal code.
*/
export function hookTextKeysAskedIn(source: string): string[] {
Expand Down
37 changes: 37 additions & 0 deletions packages/spec/src/data/hook-texts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,43 @@ describe('Hook.texts — a key the source asks for literally is refused at save
expect(hookTextKeysAskedIn(source)).toEqual(['follow_up_subject']);
});

// The optional-call shape is a literal ask too: strict TypeScript reaches for
// it once `HookContext.text` is optional.
const SHAPES = [
['ctx.text?.(', (k: string) => `ctx.text?.('${k}')`],
['await ctx.text?.(', (k: string) => `await ctx.text?.('${k}', { lead: ctx.input.name })`],
] as const;

it.each(SHAPES)('refuses an undeclared key asked for as %s at save, with the same sentence', (_shape, ask) => {
const r = HookSchema.safeParse({ ...base, body: body(`const s = ${ask('follow_up_title')};`), texts });
expect(r.success).toBe(false);
const issue = r.error!.issues.find((i) => i.path.join('.') === 'body.source')!;
expect(issue.message).toBe(undeclaredHookTextKeyAtSave('follow_up_title', ['follow_up_subject'], 'body.source'));
});

it.each(SHAPES)('CONTROL: a declared key asked for as %s, and a computed key in that shape, pass the save', (_shape, ask) => {
const computed = ask('follow_up_subject').replace("'follow_up_subject'", 'k');
const source = `${ask('follow_up_subject')};\nconst k = pick(); ${computed};`;
expect(HookSchema.safeParse({ ...base, body: body(source), texts }).success).toBe(true);
expect(hookTextKeysAskedIn(source)).toEqual(['follow_up_subject']);
});

it('reads the optional call with whitespace or a line break around the operator', () => {
expect(hookTextKeysAskedIn("ctx.text ?. ('a_key'); ctx.text\n ?.('b_key');")).toEqual(['a_key', 'b_key']);
});

it('refuses an inline handler asking ctx.text?.() for an undeclared key, at handler (the strict-TypeScript case)', () => {
const handler = async (ctx: any) => { await ctx.text?.('follow_up_title'); };
const r = HookSchema.safeParse({ ...base, handler, texts });
expect(r.success).toBe(false);
const issue = r.error!.issues.find((i) => i.path.join('.') === 'handler')!;
expect(issue.message).toBe(undeclaredHookTextKeyAtSave('follow_up_title', ['follow_up_subject'], 'handler'));
});

it('does not read a non-null ctx.text!() — TypeScript only: a handler reaches the save with the `!` erased, and a js body holding it never compiles', () => {
expect(hookTextKeysAskedIn("ctx.text!('a_key');")).toEqual([]);
});

it('a hook that declares no texts is not read for ctx.text calls (the run-time fault names it)', () => {
expect(HookSchema.safeParse({ ...base, body: body("await ctx.text('anything');") }).success).toBe(true);
expect(undeclaredHookTextAtRun('lead_follow_up', 'anything', [])).toMatch(/hook 'lead_follow_up' asked for text 'anything'.*declared: none/);
Expand Down
14 changes: 8 additions & 6 deletions packages/spec/src/data/hook.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,9 @@ function refuseUndeclaredLiteralRefusalCode(
/**
* [#34374, ruling 6913660232 parameter 7] The object-level check that refuses
* `texts` nothing could ask for, and a key a hook's source asks for literally
* (`ctx.text('key')`) that `texts` does not declare — the refusal catalogue's
* two halves above, for the sentences a hook writes into a record.
* (`ctx.text('key')` or `ctx.text?.('key')`) that `texts` does not declare —
* the refusal catalogue's two halves above, for the sentences a hook writes
* into a record.
*/
function refuseUndeclaredLiteralTextKey(
hook: {
Expand Down Expand Up @@ -816,8 +817,8 @@ export const HookSchema = lazySchema(() => strictObject(
* hook builds itself is written as it is (parameter 4).
*
* A key the hook's source asks for literally that `texts` does not declare
* is refused at save; any other undeclared key is refused when the hook
* runs. Served on every path a hook runs on — a sandboxed `js` body and an
* — `ctx.text('key')` or `ctx.text?.('key')` — is refused at save; any
* other undeclared key is refused when the hook runs. Served on every path a hook runs on — a sandboxed `js` body and an
* in-process `handler` — and refused on a hook whose code cannot ask for one
* (an `expression` body, or neither a body nor a handler). Keyed by hook
* name, not by object. Absent: `ctx.text` has nothing to answer.
Expand Down Expand Up @@ -1939,8 +1940,9 @@ export const HookContextSchema = lazySchema(() => z.object({
*
* The runtime binds it on every path a hook runs on — a sandboxed `js` body
* and an in-process `handler` (`buildHookTextSurface`). The save-time check
* reads the literal spelling `ctx.text('key'`, so a key asked for through
* an alias or a computed name is only judged when the hook runs.
* reads the literal spellings `ctx.text('key'` and `ctx.text?.('key'`, so a
* key asked for through an alias or a computed name is only judged when the
* hook runs.
*
* Runtime-only, like {@link api} and {@link notice}: a live function, so the
* RUNTIME schema is `z.unknown()` (JSON Schema `{}`) and the type is a static
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

import type { SemanticMigration } from '../../types.js';

// The D3 entry for the save door's literal `ctx.text` reader reading the
// optional-call shape `ctx.text?.('key')` (ruling 6913660232 parameter 7: a
// key asked for literally that `texts` does not declare is refused at save).
// It narrows the hook's accept set, the released half; the action half
// (`ActionSchema.texts`) ships already narrowed. No key is removed, so there is
// no tombstone and no D2 conversion: which sentence the author meant is a
// judgement about the hook.
export const entry: SemanticMigration = {
id: 'hook-action-text-key-optional-call-refused',
surface:
'hook.body.source / hook.handler on a hook that declares texts: a literal optional call ctx.text?.(KEY), '
+ 'awaited or not, whose KEY texts does not declare. A type: script action\'s body.source is read the same '
+ 'way from the release that introduces action texts, so no released action is affected',
replacement:
'Declare the key under texts.KEY with the sentence the record keeps, or ask for one of the declared keys. '
+ 'The optional call stays legal for a declared key.',
reason:
'A key a hook asks for literally that its texts does not declare was refused at save only for the plain '
+ 'call ctx.text(KEY). The optional call ctx.text?.(KEY), which strict TypeScript reaches for because '
+ 'HookContext.text is optional, passed the save, and the runtime refused the key only when the hook ran, '
+ 'as a fault naming the hook and the key. The save now refuses it with the same sentence, at body.source '
+ 'or handler. A key that arrives any other way (a variable, a computed name) is still judged when the code '
+ 'runs. There is no mechanical rewrite: the hook already failed at run time for that key, and whether to '
+ 'declare it or ask for another is a judgement about the sentence.',
acceptanceCriteria:
'objectstack validate reports no issue at body.source or handler for any hook that declares texts, and '
+ 'every key its code asks for through ctx.text or the optional call ctx.text?.( is a key of its texts.',
};
21 changes: 21 additions & 0 deletions packages/spec/src/ui/action-texts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,27 @@ describe('Action.texts — a key the body asks for literally is refused at save
expect(ActionSchema.safeParse({ ...base, body: body(source), texts: TEXTS }).success).toBe(true);
});

// The optional-call shape is a literal ask too, read by the one key reader
// the hook door shares. (An action's door reads `body.source` alone: it has
// no handler path.)
const SHAPES = [
['ctx.text?.(', (k: string) => `ctx.text?.('${k}')`],
['await ctx.text?.(', (k: string) => `await ctx.text?.('${k}', { subject: input.subject })`],
] as const;

it.each(SHAPES)('refuses an undeclared key asked for as %s at save, with the same sentence', (_shape, ask) => {
const r = ActionSchema.safeParse({ ...base, body: body(`const line = ${ask('email_body')};`), texts: TEXTS });
expect(r.success).toBe(false);
const issue = issuesOf(r).find((i) => i.path.join('.') === 'body.source')!;
expect(issue.message).toBe(undeclaredActionTextKeyAtSave('email_body', ['email_subject']));
});

it.each(SHAPES)('CONTROL: a declared key asked for as %s, and a computed key in that shape, pass the save', (_shape, ask) => {
const computed = ask('email_subject').replace("'email_subject'", 'k');
const source = `${ask('email_subject')};\nconst k = pick(); ${computed};`;
expect(ActionSchema.safeParse({ ...base, body: body(source), texts: TEXTS }).success).toBe(true);
});

it('CONTROL: an action that declares no texts is not read for ctx.text calls (the run-time fault names it)', () => {
expect(ActionSchema.safeParse({ ...base, body: body("await ctx.text('anything');") }).success).toBe(true);
expect(undeclaredActionTextAtRun('send_email', 'anything', [])).toMatch(/^action 'send_email' asked for text 'anything'.*declared: none/);
Expand Down
10 changes: 5 additions & 5 deletions packages/spec/src/ui/action.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1572,9 +1572,9 @@ const actionObject = () => strictObject({
* rejects the call. A string the body builds itself is written as it is
* (parameter 4).
*
* A key the body asks for literally that `texts` does not declare is
* refused at save; any other undeclared key is refused when the action
* runs, as a fault naming the action and the key. Served where an action
* A key the body asks for literally that `texts` does not declare —
* `ctx.text('key')` or `ctx.text?.('key')` — is refused at save; any other
* undeclared key is refused when the action runs, as a fault naming the action and the key. Served where an action
* runs code of its own: a `type: 'script'` action's sandboxed `js` body —
* which is also what `os build` lowers an inline `target` function to.
* Refused on every other action: another `type` (its `target` is a URL,
Expand Down Expand Up @@ -2658,8 +2658,8 @@ export type ActionText = z.input<typeof ActionTextSchema>;
* [#34374 PR2] The object-level check on an action's `texts`, the twin of
* `HookSchema`'s: `texts` nothing the action runs could ask for is refused at
* `texts`, and a key the body's source asks for literally
* (`ctx.text('key')`) that `texts` does not declare is refused at
* `body.source`, one issue each. A key that arrives any other way is the
* (`ctx.text('key')` or `ctx.text?.('key')`) that `texts` does not declare is
* refused at `body.source`, one issue each. A key that arrives any other way is the
* run-time refusal's.
*/
function refuseUndeclaredLiteralActionTextKey(
Expand Down
Loading