← Back to Pull requests

feat(dsl): code nodes get dates, calendar arithmetic with no clock #4524

Open
claudio-michel[bot] opened this pull request with 233 lines diff across 12 files
View on GitHub
claudio-michel[bot] claudio-michel[bot] commented on Dec 01, 2026 22:35 UTC
Author

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 code node. Date is 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

packages/dsl/src/
  code-helpers.ts        CODE_HELPERS_SOURCE: `const dates = ...`, frozen, integer math only
  code-exec.ts           code nodes bind `dates` next to the denied globals
  index.ts               exports CODE_HELPERS_SOURCE, CODE_HELPER_NAMES, type CodeDates
  author.ts, author-references.ts, skills/author/references/*.md   the contract names `dates`
packages/dsl/test/code-dates.test.mjs                               6 tests
packages/dsl/README.md, changes/dsl-code-dates.md

<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) and isDate(value), on YYYY-MM-DD strings. 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 a TypeError naming the value.

CODE_HELPERS_SOURCE (string)
  ├─ evaluated once by the engine -> codeHelpers.dates (frozen)
  └─ prepended by a host whose runCode runs code nodes elsewhere -> the same binding there

</details>

<details><summary><code>packages/dsl/src/code-exec.ts</code>: binding</summary>

compileTransform(src)
  └─ new Function(...DENIED_GLOBALS, ...CODE_HELPER_NAMES, body)(undefined..., dates)

Date stays denied. The helper object is frozen, so one code node cannot change it for the next.
</details>

Before / After

before: code: '({ due }) => dates.daysBetween(due, "2026-03-01")'  ->  ReferenceError: dates is not defined
after:  same code                                                    ->  the day count (integer); Date is still undefined

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_SOURCE gives a separate executor the same binding; a workflow using dates validates, dry-runs on synthesized dates and runs.

  • Lean: not needed. Validation, state paths, merges, loops and desugaring are unchanged.

  • autoqa and blast-radius: none (library change, no deployment).
  • Test plan

  • pnpm --filter @parcha/agentrun-dsl run build && cd packages/dsl && node --test test/*.test.mjs

  • pnpm run export:source && pnpm run verify:source
  • Migration 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 -->

    Diff: 233 lines (+223 / -10) across 12 files Reviewer: greptile-apps[bot] Review duration: 7067m
    All Vouch review confidence checks passed
    Residual risk 0.10 = Change Risk (0.52) × (1 − Review Confidence (0.80)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 233 lines diff across 12 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.63 · 5 substantive comment(s)
    0.63
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    80%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.326
    Real PR Conversation Timeline
    6 items
    greptile-apps[bot] greptile-apps[bot] commented on Dec 01, 2026 22:39 UTC
    Bot

    <!-- greptile_summary -->

    <h2>Confidence Score: 5/5<a href="https://app.greptile.com/api/retrigger?id=126192770&amp;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&amp;next=%2Fparcha-ai%2Fagentrun%2Fpull%2F4524&amp;utm_source=greptile_review&amp;utm_medium=github&amp;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.

  • Code nodes can calculate calendar dates without reading the clock.

  • Dry runs can synthesize plain date fields for code nodes.
  • <!-- greptile_confidence_score:5 -->

    <sub>Reviews (3) · Last reviewed commit: "fix(dsl): a date beside an anyOf, a oneO..." · Reviewed by Greptile</sub>

    greptile-apps[bot] greptile-apps[bot] commented on code on Dec 01, 2026 22:39 UTC
    Code Review
    packages/dsl/src/author.ts:1
    @@ -125,7 +125,7 @@ Typed questions answered by the host's judge in one request each: no tools, no s
     - ${code("loop")}: ${code("body")}, ${code("until")} (a predicate) and an integer ${code("maxIters")} of at least 1 (no maximum), optionally an integer ${code("expect_iters")} of at least 1 (priced passes). At the bound the state passes through with ${code("until")} unmet; follow the loop with an escalate or gate on that condition.
     - ${code("escalate")}: ${code("when")} (a predicate), and non-empty ${code("kind")}, ${code("stage")} and ${code("summary")}. When the predicate holds the run stops without output and returns the escalation with its interpolated summary.
     - ${code("workflow")}: ${code("label")}, ${code("workflow")} (a complete inline child), ${code("input")} (an object, interpolated, the child's entire initial state), ${code("out")} (a parent schema checked against the child's output) and ${code("as")}. The child declares ${code("input.schemaId")} in its own schemas and contains no report or artifact.
    -- ${code("code")}: ${code("code")} is one synchronous function expression such as "(s) => ({ total: s.items.length })". It receives the full state; return new values and never mutate it. ${code("Date")}, ${code("Promise")}, timers, ${code("fetch")}, ${code("require")}, ${code("process")}, ${code("Function")} and ${code("globalThis")} are unavailable. It is trusted host JavaScript, not a sandbox. Use code for typed-state mechanics, never to read meaning from prose.
    +- ${code("code")}: ${code("code")} is one synchronous function expression such as "(s) => ({ total: s.items.length })". It receives the full state; return new values and never mutate it. ${code("Date")}, ${code("Promise")}, timers, ${code("fetch")}, ${code("require")}, ${code("process")}, ${code("Function")} and ${code("globalThis")} are unavailable. For calendar dates it has ${code("dates")}, pure arithmetic on YYYY-MM-DD strings with no clock: ${code("dates.daysBetween(a, b)")} (whole days, positive when b is later), ${code("dates.addDays(date, n)")}, ${code("dates.compare(a, b)")} (-1, 0 or 1), ${code("dates.weekday(date)")} (1 Monday to 7 Sunday) and ${code("dates.isDate(value)")}; anything else throws. Give date fields ${code("format: \"date\"")} so a dry run synthesizes real dates. It is trusted host JavaScript, not a sandbox. Use code for typed-state mechanics, never to read meaning from prose.

    <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.

    claudio-michel[bot] claudio-michel[bot] commented on code on Dec 01, 2026 22:51 UTC
    Code Review
    packages/dsl/src/author.ts:1
    @@ -125,7 +125,7 @@ Typed questions answered by the host's judge in one request each: no tools, no s
     - ${code("loop")}: ${code("body")}, ${code("until")} (a predicate) and an integer ${code("maxIters")} of at least 1 (no maximum), optionally an integer ${code("expect_iters")} of at least 1 (priced passes). At the bound the state passes through with ${code("until")} unmet; follow the loop with an escalate or gate on that condition.
     - ${code("escalate")}: ${code("when")} (a predicate), and non-empty ${code("kind")}, ${code("stage")} and ${code("summary")}. When the predicate holds the run stops without output and returns the escalation with its interpolated summary.
     - ${code("workflow")}: ${code("label")}, ${code("workflow")} (a complete inline child), ${code("input")} (an object, interpolated, the child's entire initial state), ${code("out")} (a parent schema checked against the child's output) and ${code("as")}. The child declares ${code("input.schemaId")} in its own schemas and contains no report or artifact.
    -- ${code("code")}: ${code("code")} is one synchronous function expression such as "(s) => ({ total: s.items.length })". It receives the full state; return new values and never mutate it. ${code("Date")}, ${code("Promise")}, timers, ${code("fetch")}, ${code("require")}, ${code("process")}, ${code("Function")} and ${code("globalThis")} are unavailable. It is trusted host JavaScript, not a sandbox. Use code for typed-state mechanics, never to read meaning from prose.
    +- ${code("code")}: ${code("code")} is one synchronous function expression such as "(s) => ({ total: s.items.length })". It receives the full state; return new values and never mutate it. ${code("Date")}, ${code("Promise")}, timers, ${code("fetch")}, ${code("require")}, ${code("process")}, ${code("Function")} and ${code("globalThis")} are unavailable. For calendar dates it has ${code("dates")}, pure arithmetic on YYYY-MM-DD strings with no clock: ${code("dates.daysBetween(a, b)")} (whole days, positive when b is later), ${code("dates.addDays(date, n)")}, ${code("dates.compare(a, b)")} (-1, 0 or 1), ${code("dates.weekday(date)")} (1 Monday to 7 Sunday) and ${code("dates.isDate(value)")}; anything else throws. Give date fields ${code("format: \"date\"")} so a dry run synthesizes real dates. It is trusted host JavaScript, not a sandbox. Use code for typed-state mechanics, never to read meaning from prose.

    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.

    greptile-apps[bot] greptile-apps[bot] commented on code on Dec 01, 2026 22:53 UTC
    Code Review
    packages/dsl/src/dry-run.ts:1
    @@ -147,10 +148,19 @@ function synthesize(schema: unknown, definitions: Record<string, unknown>, depth
       return "x";
     }
     
    +// A calendar date (`format: "date"`, YYYY-MM-DD) is the one format synthesis writes, so a code node's `dates` helpers
    +// run on a real date in a dry run. Fixed, like every synthesized value.
    +const SYNTHETIC_DATE = "2001-02-03";
    +function synthesizableDate(spec: Record<string, any>): boolean {
    +  return spec.format === "date" && (Array.isArray(spec.type) ? spec.type[0] : spec.type) === "string"
    +    && !(spec.minLength > SYNTHETIC_DATE.length) && !(spec.maxLength < SYNTHETIC_DATE.length);
    +}
    +
     function unsupportedConstructs(schema: unknown, path: string, found: string[], depth = 0): string[] {
       if (depth > 12 || !schema || typeof schema !== "object") return found;
       const spec = schema as Record<string, any>;
       for (const keyword of ["pattern", "format", "not", "allOf", "if", "uniqueItems", "multipleOf", "propertyNames", "patternProperties"]) {
    +    if (keyword === "format" && synthesizableDate(spec)) continue;

    <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:

  • Workflow validation and diagnostics

  • Fix beta workflow cancellation, recovery, and launch guidance
  • claudio-michel[bot] claudio-michel[bot] commented on code on Dec 01, 2026 23:21 UTC
    Code Review
    packages/dsl/src/dry-run.ts:1
    @@ -147,10 +148,19 @@ function synthesize(schema: unknown, definitions: Record<string, unknown>, depth
       return "x";
     }
     
    +// A calendar date (`format: "date"`, YYYY-MM-DD) is the one format synthesis writes, so a code node's `dates` helpers
    +// run on a real date in a dry run. Fixed, like every synthesized value.
    +const SYNTHETIC_DATE = "2001-02-03";
    +function synthesizableDate(spec: Record<string, any>): boolean {
    +  return spec.format === "date" && (Array.isArray(spec.type) ? spec.type[0] : spec.type) === "string"
    +    && !(spec.minLength > SYNTHETIC_DATE.length) && !(spec.maxLength < SYNTHETIC_DATE.length);
    +}
    +
     function unsupportedConstructs(schema: unknown, path: string, found: string[], depth = 0): string[] {
       if (depth > 12 || !schema || typeof schema !== "object") return found;
       const spec = schema as Record<string, any>;
       for (const keyword of ["pattern", "format", "not", "allOf", "if", "uniqueItems", "multipleOf", "propertyNames", "patternProperties"]) {
    +    if (keyword === "format" && synthesizableDate(spec)) continue;

    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.

    Assignees
    claudio-michel[bot] claudio-michel[bot]
    Labels
    risk: low confidence: 80% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 51.8% (MEDIUM) · Higher = larger blast radius
    51.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 80% · Lower = rushed or shallow review
    80%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 10.3% · Safe to merge
    10.3%