Skip to content

{$now} param marker: dispatch-time dates with optional day offset - #16

Merged
aaltshuler merged 2 commits into
mainfrom
now-marker
Jul 4, 2026
Merged

aaltshuler merged 2 commits into
mainfrom
now-marker

Conversation

@aaltshuler

@aaltshuler aaltshuler commented Jul 4, 2026 •

Copy link
Copy Markdown
Collaborator

Real-graph mutations carry timestamp params by convention (update_issue_status($slug, $status, $actor, $at: Date) in the dev graph), but notebook YAML had no way to say "today" — a literal date goes stale; a manual session-date control is user ritual.

The marker: { $now: date } resolves at dispatch/read time to YYYY-MM-DD; { $now: datetime } to full ISO 8601. Optional offset_days shifts the instant — before: { $now: date, offset_days: -60 } is a sliding 60-days-ago threshold for stale-style queries. Resolved centrally in resolveExpr, so it works in mutation params and query params alike.

Validate: $now is treated like $row/$input — reliably present at dispatch (no spurious "can't confirm it will be set" warning) and never mistaken for a literal param value.

Verified live against the dev graph (graph.modernrelay.ai): a priority-edit round-trip carried at=<today> through the server's required-params contract, and a Triage stale list reads with before={$now, offset_days:-60} (58 truly-stale rows vs 227 unfiltered).

Tests: +2 (marker resolution date/datetime; offset window) — core at 116.

🤖 Generated with Claude Code

https://claude.ai/code/session_011TrhtF1SiJghJASMWECzBh

Greptile Summary

Introduces a { $now: "date" | "datetime", offset_days?: number } param marker that resolves at dispatch/read time to the local calendar date or a full UTC ISO-8601 instant, with an optional day offset for sliding-window thresholds. Previous review feedback has been addressed: the date form uses local date components instead of UTC, and any value other than "date" / "datetime" now resolves to undefined so the server's required-param check surfaces typos.

  • resolve.ts: New branch in resolveExpr handles $now before the plain-object recursion; uses getFullYear/getMonth/getDate (local) for "date" and toISOString() (UTC) for "datetime". The offset_days multiplier shifts by whole millisecond-equivalent days.
  • validate.ts: $now is classified as a "reliably present" dynamic source (same treatment as $row/$input) so no spurious "can't confirm it will be set" warning is emitted, and containsStateExpr recognises it so nested markers are detected correctly.
  • index.test.ts: Three new suites cover date/datetime resolution against local wall-clock, the typo-guard, and the offset window (59–62 day bounds).

Confidence Score: 5/5

Safe to merge; all logic is additive, the previous round's timezone and typo-guard concerns are addressed, and the new code is well-tested.

The change is a clean, self-contained addition to resolveExpr with no modifications to existing branches. The local-date fix and the undefined-for-typos guard are correctly implemented and covered by tests. The only item worth a second look is the isFinite gap on offset_days, which only affects obscure YAML edge cases (.nan, .inf) and does not touch any production path used today.

No files require special attention. The resolve.ts isFinite note is a minor hardening suggestion.

Important Files Changed

Filename Overview
packages/core/src/runtime/resolve.ts Adds $now marker resolution in resolveExpr: local date components for "date", UTC ISO string for "datetime", optional offset_days shift, and an undefined guard for unrecognized format values.
packages/cli/src/commands/validate.ts Registers $now as a "reliably present" dynamic source in literalForValidation and adds it to containsStateExpr, eliminating spurious "can't confirm it will be set" warnings.
packages/core/src/runtime/index.test.ts Adds three test suites: date/datetime resolution, the typo-guard (unrecognized format → undefined), and offset_days shifting with a 59–62 day bounds check.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant YAML as Notebook YAML
    participant Validate as validate.ts
    participant Runtime as resolveExpr
    participant Server as OmniGraph Server

    YAML->>Validate: "param: { $now: "date", offset_days: -60 }"
    Validate->>Validate: "literalForValidation → {kind:"dynamic", source:"input"}"
    Note over Validate: No spurious "can't confirm" warning

    YAML->>Runtime: "dispatch("mutate", { params: { before: { $now: "date", offset_days: -60 } } })"
    Runtime->>Runtime: "$now" in value → resolve
    Runtime->>Runtime: "offsetDays = -60"
    Runtime->>Runtime: "d = new Date(Date.now() - 60d)"
    Runtime->>Runtime: local components → "YYYY-MM-DD"
    Runtime->>Server: "resolvedParams: { before: "2026-05-05" }"
    Server-->>Runtime: ok
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant YAML as Notebook YAML
    participant Validate as validate.ts
    participant Runtime as resolveExpr
    participant Server as OmniGraph Server

    YAML->>Validate: "param: { $now: "date", offset_days: -60 }"
    Validate->>Validate: "literalForValidation → {kind:"dynamic", source:"input"}"
    Note over Validate: No spurious "can't confirm" warning

    YAML->>Runtime: "dispatch("mutate", { params: { before: { $now: "date", offset_days: -60 } } })"
    Runtime->>Runtime: "$now" in value → resolve
    Runtime->>Runtime: "offsetDays = -60"
    Runtime->>Runtime: "d = new Date(Date.now() - 60d)"
    Runtime->>Runtime: local components → "YYYY-MM-DD"
    Runtime->>Server: "resolvedParams: { before: "2026-05-05" }"
    Server-->>Runtime: ok
Loading

Reviews (2): Last reviewed commit: "$now: local calendar date + typo guard" | Re-trigger Greptile

Mutations against real graphs carry timestamp params by convention
(update_issue_status($slug,$status,$actor,$at: Date) in the dev graph) —
but notebook YAML had no way to say "today" without going stale or
forcing a manual session-date control.

{ $now: date } resolves at dispatch/read time to "YYYY-MM-DD";
{ $now: datetime } to full ISO 8601. Optional offset_days shifts the
instant — before: { $now: date, offset_days: -60 } gives a sliding
60-days-ago threshold for stale-style queries. Resolved in resolveExpr,
so it works in mutation params AND query params (both read paths).

validate treats $now like $row/$input: reliably present at dispatch, no
"can't confirm it will be set" warning, and a marker object is never
mistaken for a literal param value.

Proven live against the dev graph (graph.modernrelay.ai): a priority
round-trip carried at=<today>, and the Triage stale list reads via
before={$now,offset_days:-60}.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011TrhtF1SiJghJASMWECzBh
Comment thread packages/core/src/runtime/resolve.ts Outdated
Comment thread packages/core/src/runtime/resolve.ts Outdated
Greptile: (1) toISOString().slice(0,10) yielded the UTC calendar date —
wrong "today" for anyone west of UTC in the evening; date form now uses
local date components (datetime stays ISO/UTC — instants are tz-agnostic).
(2) Unrecognized $now values (e.g. "Date") silently fell through to the
date form; they now resolve to undefined so the server's required-param
check surfaces the typo instead of a subtly wrong value.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011TrhtF1SiJghJASMWECzBh
@aaltshuler
aaltshuler merged commit 2d174b0 into main Jul 4, 2026
2 checks passed
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.

1 participant