feat(dsl): code nodes get dates, calendar arithmetic with no clock #4524
<!-- greptile_summary -->
<h2>Confidence Score: 5/5<a href="https://app.greptile.com/api/retrigger?id=126192770&sig=edee1d16bfd6269b1b503aa82a917230fff5f99dd3d0f268dfd7aa5c7519164a"><picture><source media="(prefers-color-scheme: dark)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/RetriggerDark.svg?v=2"><source media="(prefers-color-scheme: light)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"><img alt="Retrigger" src="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2" align="right"></picture></a><a href="https://app.greptile.com/-/switch-tenant?tenant=parcha&next=%2Fparcha-ai%2Fagentrun%2Fpull%2F4524&utm_source=greptile_review&utm_medium=github&utm_campaign=view_in_greptile"><picture><source media="(prefers-color-scheme: dark)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptileDark.svg?v=2"><source media="(prefers-color-scheme: light)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"><img alt="View in Greptile" src="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2" align="right"></picture></a></h2>
[Medium impact] The PR appears safe to merge; the previous date-synthesis issue is fixed.
<h3>Summary</h3>
The PR adds clock-free dates helpers to code nodes and fixed-date synthesis for dry runs.
<!-- greptile_confidence_score:5 -->
<sub>Reviews (3) · Last reviewed commit: "fix(dsl): a date beside an anyOf, a oneO..." · Reviewed by Greptile</sub>
<a href=""><img alt="P2" src="https://greptile-static-assets.s3.amazonaws.com/badges/p2.svg?v=9" align="top"></a> Date dry runs are skipped
The new guidance says format: "date" lets a dry run synthesize dates, but dryRunWorkflow treats every format as unsupported and returns status: "not_run" before running any nodes. The new test misses this because it checks only dry.ok, which is also true for a skipped run.
Either add date synthesis support or correct the guidance, and assert dry.status === "passed" so the test proves the workflow actually ran.
Fixed in a0114e765f, by supporting it rather than dropping the guidance. A dry run now synthesizes a string with format: "date" as a fixed calendar date (2001-02-03) instead of standing down. Any other format, or a date field that also has a pattern or a minLength/maxLength that excludes 10 characters, still stands the dry run down. The test now asserts { ok: true, status: "passed" } and the synthesized output, and a second test pins the cases that stay not_run.
One existing test changed with it: the CLI --strict exit-code test used format: "date" as its example of a dry run that cannot run, and a date now runs. It now uses format: "date-time", which still cannot, so it asserts the same exit codes.
<a href=""><img alt="P2" src="https://greptile-static-assets.s3.amazonaws.com/badges/p2.svg?v=9" align="top"></a> Union branches lose date constraints
The new exemption allows date schemas containing anyOf or oneOf to proceed, but synthesize selects a branch before creating a date. For example, {type: "string", format: "date", anyOf: [{type: "string"}, {type: "null"}]} produces "x". A later dates.addDays call then throws, wrongly failing the dry run even though the field requires a date.
Preserve the parent’s date constraint when choosing a branch, or return not_run for combinations synthesis cannot honor.
Knowledge Base Used:
Fixed in 6edbaac317. I reproduced it: in a dry run, an extract whose output field is {type: "string", format: "date", anyOf: [{type: "string"}, {type: "null"}]} failed at that node with must match format "date". Synthesis took the branch and made "x".
A date beside a $ref, an anyOf or a oneOf is no longer treated as a synthesizable date. Its format counts as unsupported again, so the dry run stands down (not_run), as it did before dates were synthesized. A date inside the branch synthesis takes (anyOf: [{type: "string", format: "date"}, {type: "null"}]) is still synthesized, and the dry run passes. The new test in code-dates.test.mjs covers both shapes, and its stand-down cases fail without the fix.
greptile-apps[bot]
claudio-michel[bot]
This PR rebases after #4523 merges (both touch the author contract, its generated references and
index.ts); I'll rebase it and regenerate the contract, then the references, then rebuild.Why
Workflows that apply a policy to dates (a return window, a due date, an SLA in business days) need calendar arithmetic in a
codenode.Dateis denied there on purpose: it reads the clock, and a run should stay a function of its input. So authors hand-roll a Julian-day function in every code node that needs one, and those copies get leap years and month lengths wrong. This is a generic host feature: any workflow author gets the same small, clock-free helper.What
<details><summary><code>packages/dsl/src/code-helpers.ts</code>: the helpers, written once as source</summary>
dates.daysBetween(a, b),addDays(date, n),compare(a, b),weekday(date)(ISO, 1 Monday to 7 Sunday) andisDate(value), onYYYY-MM-DDstrings. Day numbers use the proleptic Gregorian calendar with integer arithmetic. Anything that is not a calendar date, or a day count that is not a whole number, throws aTypeErrornaming the value.</details>
<details><summary><code>packages/dsl/src/code-exec.ts</code>: binding</summary>
Datestays denied. The helper object is frozen, so one code node cannot change it for the next.</details>
Before / After
Evidence
packages/dsl/test/code-dates.test.mjs, 6 tests: calendar facts; every day from 1900 to 2100 checked against the proleptic Gregorian calendar; non-dates are errors that name the value; no clock and no mutation across nodes;CODE_HELPERS_SOURCEgives a separate executor the same binding; a workflow usingdatesvalidates, dry-runs on synthesized dates and runs.Test plan
pnpm --filter @parcha/agentrun-dsl run build && cd packages/dsl && node --test test/*.test.mjspnpm run export:source && pnpm run verify:sourceMigration notes
None
Source: no linked issue; a workflow-authoring feature, described under Why.
🤖 Generated with Claude Code
<!-- codesmith:footer -->
---
<a href="https://dashboardbackend.blacksmith.sh/track/run-proof?expires=1798756534&installation_model_id=431113&pr_number=4524&ref=codesmith_pr_footer&repository=Parcha-ai%2Fagentrun&return_to=https%3A%2F%2Fgithub.com%2FParcha-ai%2Fagentrun%2Fpull%2F4524&variant=prove_it_works&signature=ad1f8d2f165586f243a52445d0ebdf3206b1b45d77bdebfd29c5cdf4bb676b48"><picture><source media="(prefers-color-scheme: dark)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/proof-prove-it-works-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/proof-prove-it-works-v2-light.svg"><img alt="Prove it works" src="https://pr-comments-assets.blacksmith.sh/codesmith/proof-prove-it-works-v2-dark-3x.png" width="129" height="28"></picture></a>
<sup><a href="https://app.blacksmith.sh/Parcha-ai/codesmith/agentrun/pr/4524?autoLogin=true&ref=codesmith_pr_footer">Open in [code]smith</a> · Need help on this PR? Tag <code>@codesmith-bot</code> with what you need.</sup>
<!-- codesmith:autofix:disabled -->
<!-- /codesmith:footer -->