Skip to content

Add PlayNodeViewer: a play's rules as a read-only workflow, with its on/off switch - #3537

Merged
malibio merged 4 commits into
mainfrom
issue-3518-play-node-viewer
Oct 4, 2026
Merged

malibio merged 4 commits into
mainfrom
issue-3518-play-node-viewer

Conversation

@malibio

@malibio malibio commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

Closes #3518. Implements ADR-090 §2.

What changed

A play now opens in PlayNodeViewer instead of the generic viewer.

  • Header: title, description, state (On, Off, or Suspended with suspendedMessage and the time) and the on/off switch.
  • Body: one lane per rule, in order. The trigger is described from its fields (on/select/property_key, or cron/select); each condition and action shows its authored description, with the for_each collection named; invariant rules carry a marker. Raw CEL, params and the trigger JSON sit behind a closed disclosure.
  • The switch writes enabled through the typed play update (sharedNodeStore.updatePlayNode). Switching on a suspended play sends enabled: true, which is what clears the suspension.
  • Seeded-play warning (ADR-060 §8): switching off a play with isSeeded and an invariant rule first opens a dialog that lists each invariant rule's description. Cancel writes nothing.
  • Data: the play is $derived from SharedNodeStore. The only local $state is whether the warning is open, and there is no $effect.

Edit is not rendered. It needs the bound-chat creation from #3520, which adds the button with it.

Node type change

play is a structured core type (category: automation). One wire-only field is added; the schema, registry, stored shape and typed update are unchanged.

  • PlayNode.isSeeded: derived, read-only, true when the stored properties carry _seed. The marker itself still never reaches the wire. PlayNodeUpdate rejects isSeeded (deny_unknown_fields, now asserted).
  • The check has one definition, PlayFields::seeded_in, which core's is_seeded_play now calls.
  • The dev-proxy's mirror conversion (storageNodeToApiFields) derives the same field, so browser mode and Tauri hand the frontend the same shape.
  • bun run gen:types output is committed. The play sheet in node-types.md already documents isSeeded and the viewer, so there is no docs change.

Two supporting changes

  • A typed update's response now applies the type's read-only fields. The store applied only the fields a write sent, and a client's own writes are not echoed back, so after switching a suspended play on, the local node kept suspendedAt and the view stayed "Suspended". Read-only fields are the backend's alone, so the response is always current for them. Today only play has read-only typed fields.
  • The Switch wrapper binds checked through to the primitive, as the Checkbox wrapper already does. Without it a parent could not keep the switch on when the user cancels the warning. The viewer is the first use of Switch.

Tests

  • play-node-viewer.test.ts: each state, the switch's write payload (off, and on from suspended), the seeded warning and Cancel, lanes in order, step descriptions, raw content closed by default, nothing editable, and a redraw driven by an out-of-band store update.
  • play-node-model.test.ts: state precedence, a description for every trigger kind and selector kind, the warned rules.
  • update-typed-node.test.ts: a response clears a play's suspension locally.
  • node-normalize.test.ts, convert.rs, play.rs: isSeeded on both transports, and its rejection on update.
  • bun run test:changed passes (frontend, browser, scripts, types:check, node-types:check, Rust).
  • Checked in the running app on a scratch database, light and dark: the seeded "Complete a parent task" play renders, and switching it off reached the daemon.

🤖 Generated with Claude Code

@malibio

malibio commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review — PR #3537

Review Type: Initial review (no prior reviews on this PR)

Code Review Summary

The change is a clear net improvement and follows ADR-090 §2 closely. The viewer is a pure projection of the store's node (one $derived, no $effect, one piece of view-only $state for the dialog), the text derivation lives in a pure, separately tested model module, and the wire change keeps one definition of "seeded" (PlayFields::seeded_in) shared by core and the conversion. No Critical or Important findings; four optional suggestions.

What I ran: vitest run on play-node-viewer.test.ts, play-node-model.test.ts, update-typed-node.test.ts, node-normalize.test.ts — 4 files, 87 tests, all pass. I did not run the Rust tier, types:check, node-types:check, quality:fix or test:changed; the merge gate covers them.

Requirements Check (issue #3518)

  • ✅ PlayNode carries isSeeded — derived in node_to_typed_value before flatten_properties_for_api drops _seed (convert.rs:48-49), passed into play_node_to_value; PlayNodeUpdate rejects it (play.rs test extended with isSeeded); generated play-node.ts committed; node-types.md (play sheet, line 332) already documents it. node-types:check itself not run by me.
  • ✅ Registered for play — playNodePlugin in core-plugins.ts, lazy viewer, added to corePlugins; CORE_TYPES_WITHOUT_PLUGIN entry removed; pin-reachability guard updated. pane-content.svelte hydrates the tab root before mounting, so the viewer needs no fetch of its own.
  • ✅ Header: title, description, state — on / off / suspended with suspendedMessage and the formatted time; off wins over a stored suspension (playState).
  • ✅ Switch writes enabled through updatePlayNode — never lifecycleStatus or properties; a suspended play sends enabled: true (not filtered out as a no-op by updateTypedNode, and settle_play_update clears the suspension on it).
  • ✅ Seeded + invariant warning, Cancel writes nothing — the function binding's getter keeps the switch on while the dialog is open; Cancel, Escape and overlay all only reset confirmingDisable.
  • ✅ One lane per rule, in order — trigger from its fields, condition/action descriptions, for_each named, invariant marker, raw content in closed <details>.
  • ✅ Nothing in the body is editable — asserted by the "switch is the only control" test.
  • ✅ Live redraw on node:updated — test applies a database/domain-event setNode, which is what tauri-sync-listener does after its re-fetch.
  • ✅ No local $state copy, no state written from $effect — the file has no $effect.
  • ✅ Tests — each state, switch payloads, warning + confirm + cancel, every trigger kind, live redraw, the store's read-only-field apply, the dev-proxy mirror, Rust wire contract (seeded / not seeded / update rejects it).
  • ➖ quality:fix clean; test:changed passes — not verified by this review.
  • ✅ Edit "hidden until Let a native chat pin a skill and a node, and open a play's Edit chat bound to it #3520 lands" — not rendered at all, and the header comment says rules change through a bound chat. That is the honest reading of "hidden": a rendered-but-disabled button or a flag would be dead UI/transition code, which CLAUDE.md prohibits. Let a native chat pin a skill and a node, and open a play's Edit chat bound to it #3520 adds the button with the call it needs.

Code Review Findings

Critical Issues

None.

Important

None.

Areas examined and found sound

  • Store: applying read-only fields from a typed update's response (📁 packages/desktop-app/src/lib/services/shared-node-store.svelte.ts:3479-3484). I looked for a clobber against the per-field sequence guard and against remote updates and found none:
    • Read-only fields can never be in payload (writableTypedCoreKeys filters them), so they have no optimistic value and no sequence number to race; the sequence guard for writable fields is untouched.
    • While the write is pending, decideRemoteUpdate skips every database-source setNode for the node (hasPending), and the coordinator serializes RPCs per node, so no newer remote value of these fields can be in the store when the response is applied.
    • Rapid on→off on a suspended play: response A skips enabled (sequence moved) and still clears the suspension; the play reads off. Correct.
    • Scope note: the loop is generic, so a query typed update now also applies executionCount / lastExecuted from its response. That is the same authoritative value and is correct, but it is a behaviour change outside play (see suggestion 1).
  • Switch wrapper (📁 packages/desktop-app/src/lib/components/ui/switch/switch.svelte:9,16). checked = $bindable(false) + bind:checked is required for the viewer's function binding to reach the primitive. The two existing callers in labs-settings.svelte are unaffected.
  • Rust wire change. PlayNode is constructed in exactly one place; is_seeded_play now delegates to PlayFields::seeded_in, so core and the wire cannot disagree. No stored field, schema or relationship changes, so the node-type sequence's storage layers don't apply; wire type, generated TS, tests and the sheet are all covered.
  • Dev-proxy mirror (📁 packages/desktop-app/src/lib/services/node-normalize.ts:176-178). '_seed' in storageProperties matches Rust's get("_seed").is_some() (both true for a null-valued marker); uses isA, not a literal comparison.
  • Project rules. No literal node_type comparison, no lifecycle_status read, no compatibility code, generated TS regenerated rather than edited, no console.*, no {@html} (all rule text is rendered as escaped text, so authored descriptions and CEL can't inject markup), colours from tokens.

Suggested Improvements

  1. 🟢 Suggestion — 📁 packages/desktop-app/src/tests/services/update-typed-node.test.ts:200
    The new store loop is type-generic but only tested for play. A query typed update now takes executionCount / lastExecuted from its response and nothing pins that. One short case (store a query with executionCount: 1, respond with 2, expect 2) would document that the behaviour is intended for every type with read-only fields. Principle: test a generic mechanism at its generality, not only through its first caller.

  2. 🟢 Suggestion (accessibility) — 📁 packages/desktop-app/src/lib/components/viewers/play-node-viewer.svelte:193-204
    The invariant rules the warning names sit in a <ul> outside Dialog.Description. The dialog's aria-describedby points only at the description, so a screen reader announces "…While it is off, nothing enforces:" and stops; the concrete consequence ADR-060 §8 requires is the part that isn't announced. Move the list (and ideally the consequence sentence) inside Dialog.Description. Principle: the accessible description should carry the same information the visual dialog does.

  3. 🟢 Suggestion (accessibility) — 📁 packages/desktop-app/src/lib/components/viewers/play-node-viewer.svelte:99
    The switch's aria-label is an action that flips with state ("Turn this play off" / "…on"), while role="switch" already announces state through aria-checked. The result reads "Turn this play off, switch, on". A stable name (for example the play's title, or "Play enabled") is the usual pattern for a switch. Principle: a control's accessible name is stable; its state is conveyed by state attributes.

  4. 🟢 Suggestion — 📁 packages/desktop-app/src/lib/components/viewers/play-node-viewer.svelte:126 (and :201)
    Lanes are keyed by rule.name. Save-time validation rejects duplicate names (playbook/descriptions.rs), so this is safe for every validated write, but play_node_to_value deliberately keeps a play "written around the service layer" readable, and Svelte throws each_key_duplicate on a duplicate key, which would take the whole viewer down for exactly the malformed play the user most needs to inspect. Conditions and actions are already keyed by index; nothing in a lane holds per-item state, so keying rules by index costs nothing. Principle: a read-only diagnostic view should degrade, not crash, on data the backend tolerates.

Nitpicks

  • Nit: 📁 play-node-viewer.svelte:131-136 — the invariant marker's explanation is a title tooltip only, so keyboard and touch users never get it. Not blocking; the rule description carries the substance.
  • Nit: 📁 play-node-viewer.svelte:189 — if the play changes out-of-band while the dialog is open so that it no longer has an invariant rule, the dialog shows an empty list and "Turn off" still writes. Harmless (the user asked to turn it off), mentioned only for completeness.

Recommendation

APPROVE — all functional acceptance criteria are met, the store change is safe against the existing sequence guard and remote-update policy, and the remaining items are optional polish.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed

All four suggestions are implemented; none skipped.

  1. Read-only-field apply tested beyond play: a query's executionCount is taken from its typed update's response (update-typed-node.test.ts).
  2. Warning's accessible description: the invariant rules and the consequence sentence are now inside Dialog.Description; the test asserts the rule text through aria-describedby.
  3. Stable switch name: aria-label="Play on", with state carried by aria-checked.
  4. Lanes keyed by position: a play stored with a repeated rule name still renders (new test).

Nits left as they are: the invariant marker's tooltip repeats what the rule description already says, and a play that loses its invariant rule while the warning is open still turns off, which is what the user asked for.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: The review was an APPROVE with suggestions only. The changes are markup moves, an attribute, an each-block key and two tests, with no logic change. The touched test files and quality:fix pass.

malibio and others added 4 commits October 4, 2026 20:07
…3518)

PlayNode carries a derived, read-only isSeeded. The viewer reads the play from SharedNodeStore, shows its state and one lane per rule, writes enabled through the typed play update and warns before a seeded play with an invariant rule is switched off. A typed update's response now applies the type's read-only fields, so switching a suspended play on clears its suspension locally.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…y lanes by position

- The seeded-play warning's rules and consequence are inside the dialog description, so they are announced.
- The switch's accessible name no longer flips with its state.
- Rule lanes are keyed by position, so a play stored with a repeated rule name still renders.
- The store's read-only-field apply is tested for a query as well as a play.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@malibio
malibio force-pushed the issue-3518-play-node-viewer branch from 61c72f6 to 197157a Compare October 4, 2026 18:07
@malibio
malibio merged commit bacfc81 into main Oct 4, 2026
@malibio
malibio deleted the issue-3518-play-node-viewer branch October 4, 2026 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add PlayNodeViewer: a play's rules as a read-only workflow, with its on/off switch and Edit

1 participant