fix(sdk): read helper references as syntax, and drop the surface peer override

Merged
KH
1mo ago
+342-17

Two cleanups, both unblocked by surface 2.0.30.

1. A helper named is not a helper used

Both readers tested the raw body text for f.<namespace>, so a mere mention declared a requirement and refused the flow:

f.run("echo f.gitlab")                                  → REFUSED helper_provider.mount_required
f.agent("a", { task: "explain how f.slack.post works" }) → REFUSED
/* f.gitlab */                                           → REFUSED

None of those touch a helper. The refusal demanded a relayfile mount the flow never uses — and it made the SDK stricter than Cloud, whose flow-source-requirements.ts already reads these shapes as syntax, so a flow Cloud accepts could be refused locally.

Now: dot access is read on the copy with comments and strings blanked; bracket access (f["gitlab"], whose key is a string) on the comments-only copy, then confirmed against the fully blanked one so the f[ must have survived. Real usage still refuses, verified in both forms.

Extracted into helper-reference.ts because preflightHelpers and flowRequirements each carried their own copy of the regex. The comment in flow-requirements.ts literally said "Same recognition as preflightHelpers" — which is how the two drifted into the same bug twice, and why fixing one first didn't change the CLI's behaviour at all.

2. Drop the overrides entry from #537

It existed only because the then-published surface pinned an exact peer relay-helpers 0.4.11 against this repo's 0.4.12. Surface 2.0.30 ships peer 0.4.12, so it is inert. #537 said it "becomes a no-op once a surface carrying peer 0.4.12 is published and should be deleted then" — this is that.

Verified rather than assumed: npm install and a clean npm ci both exit 0 without it, with the @relayfile/sdk peer still installed, and scripts/surface-package-gate.sh exits 0.

Checks

  • New regression test asserts both directions; red against main's code (2 failed), green here (6 passed).
  • scripts/surface-package-gate.sh → exit 0, PACKED_RUNTIME_OK, PACKED_TYPESCRIPT_OK, surface 52/52, SDK 34/34.
  • The daemon-backed suites fail identically before and after (7/7 on tests/yaml-local-agent-live either way) — they need a live relayflowd this environment lacks, so CI is the real signal there.

🤖 Generated with Claude Code


[!NOTE]
Medium Risk
Changes deploy-time preflight and static requirement inference for all flows; incorrect detection could refuse valid deploys or miss required mounts, though tests cover both false-positive and false-negative cases.

Overview
Helper mount detection now parses flow bodies instead of scanning raw text, so mentions in strings, comments, template text, or regex literals no longer trigger false mount_required refusals or integration requirements. Real f.<namespace> access (including optional chaining, template interpolations, and bracket literals) is still detected via a shared helper-reference.ts module using acorn, with a permissive regex fallback when parsing fails.

Context-parameter handling is fixed for both preflightHelpers and flowRequirements: the first parameter name is returned unescaped for AST comparison (fixing flows whose parameter contains $ or other metacharacters), and the extraction regex now covers object-literal method bodies and generator methods so those shapes are scanned instead of skipped.

Dependency cleanup: adds acorn to @relayflows/sdk and removes the obsolete package.json overrides entry for @relayflows/surface / @relayfile/relay-helpers now that surface 2.0.30 aligns peers. Regression tests cover both preflight and flowRequirements.

Reviewed by Cursor Bugbot for commit 471e5ba4a5c4524867c724fbc92fe1169482b959. Bugbot is set up for automated code reviews on this repo. Configure here.


Summary by cubic

Reads helper references as syntax so a helper merely named in a string, comment, template text, or regex no longer demands a mount, and drops a now-inert peer override in packages/sdk/package.json.

Bug Fixes

  • The scan now parses the flow body with acorn instead of lexing it by hand, so regex-vs-division, templates, and optional chaining are settled by construction; a text fallback only runs when nothing parses.
  • The context parameter is no longer regex-escaped — an escaped name matched no AST identifier and hid every helper call, undeclaring a mount a flow really needed.
  • Parse attempts must now consume the whole body; parseExpressionAt read an object-literal method body as its async keyword and skipped its helper calls.
  • The context-parameter regex also matches generator and non-async method bodies (*gen(f), plain(f)), further Function.prototype.toString() shapes that previously left the body unscanned.
  • Recognition moved to helper-reference.ts, shared by preflightHelpers and flowRequirements; regression tests cover both directions.

Dependencies

  • Adds acorn and removes the overrides entry forcing @relayfile/relay-helpers; surface 2.0.30 ships peer 0.4.12, so it was a no-op.

Agent Relay sessions

  • claude session 7fa0c082 · opened via gh pr create · last active 2026-09-24