Repository navigation
Description
flows: f.slack helper namespace — establish the helper pattern (SURFACE §1, §2)
Closes the first-provider slice of the SURFACE.md helper-namespace contract. Once merged, the other 50 providers follow this pattern; nothing about them requires further kernel work.
Spec text (verbatim)
From docs/SURFACE.md §1 (the super-simple relayflow, lines 22-28):
export default flow("release-note", async (f) => {
const diff = await f.run("git diff main");
const note = await f.llm`One-line release note for: ${diff}`.gate(s => s.length < 200);
await f.slack.post("#releases", note); // returns a typed receipt
});From docs/SURFACE.md §2 rule 3 (Helpers, not primitives, lines 65-69):
Helpers, not primitives. Authors never see mount paths, tokens, or protocol frames. Named helpers wrap every substrate:
f.slack/f.github/f.linear/ … — generated from the relayfile adapters (50 providers → 50 namespaces for free), each verb compiling to a mount write. The receipt a helper returns is the journaled effect record (RFC Appendix A), so exactly-once dedup rides along invisibly.
Why this is a first-slice, not "generate 50 namespaces"
@relayfile/relay-helpers already ships slackClient, githubClient, linearClient, redditClient, telegramClient, plus a generated-clients bundle at packages/relay-helpers/src/generated/clients.js. What is missing is the flows-side wiring:
Ctx.slacktyped surface, so authors getawait f.slack.post(...)with type-checked args and aStep<SlackReceipt>return.- An executor path that turns a helper call into one journaled effect step (kernel primitive:
effect, NOT a new verb — SURFACE covenant §2 rule 1: kernel vocabulary is closed). - Preflight for
SLACK_BOT_TOKEN(or equivalent) presence, refused withcredential_missingwhen absent. - Idempotency: reuse
writeback-idempotency.ts— the effect key isflow-run-id + step-id, not the process-tick key that ships today. ExistingwithProcessWritebackIdempotencyis a caller for the tick case; keep it, add a flow-run key path. - A test mode that captures intended payloads to disk without touching Slack, so CI can assert send-shape without a live workspace.
The other 50 providers land as PRs that add one file each (packages/surface/src/<provider>.ts) plus one line to Ctx — no further kernel changes.
Scope
Surface
-
Add
slack: SlackHelpertoCtxinpackages/surface/src/context.ts. -
New
packages/surface/src/slack.tsdeclaring theSlackHelperinterface:export interface SlackReceipt { channel: string; ts: string; ref: string; } export interface SlackHelper { post(channel: string, text: string, opts?: { replyTo?: string }): Step<SlackReceipt>; dm(user: string, text: string): Step<{ user: string; ts: string }>; reply(channel: string, threadTs: string, text: string): Step<SlackReceipt>; react(channel: string, messageTs: string, emoji: string): Step<void>; }
-
Re-export from
packages/surface/src/index.ts.
SDK
- Route
f.slack.<verb>()through a new authored-flow executor path that:- Constructs a
Step<T>immediately (surface authoring contract requires this — lifecycle catches unawaited steps). - Journals one
effectstep per call:type: 'effect', provider: 'slack', verb, params. - Awaits the underlying
slackClientcall from@relayfile/relay-helpers. - Records the receipt on
step.completed— so resume replays the same receipt without re-hitting Slack.
- Constructs a
- Wire the executor in
packages/sdk/src/authored-flow-executor.tsalongsiderun/llm/agent. - Add a helper-step registration in the worker:
packages/sdk/src/worker.ts(or the effect worker file — pick the smallest change).
Preflight
packages/sdk/src/preflight.ts— new checkhelper_slack:- Runs when the flow body references
f.slack.*OR the header declarestools: { slack: true }. - Refuses
credential_missingifSLACK_BOT_TOKENis absent from env AND no relayfile mount at<mount>/slack/is present (either path unlocks — relayfile mount OR direct env). - Refusal shape matches the existing
cli_unresolvedetc. — one line, named category, exit 2.
- Runs when the flow body references
Idempotency
- New export
flowRunWritebackIdempotency(runId: string, stepId: string)inpackages/surface/src/slack.tsOR consumed directly from@relayfile/relay-helperscreateWritebackIdempotencywith agetDeliveryId: () => \${runId}:${stepId}`` shim. - The executor stamps every helper call's body with the resulting key BEFORE writing to the mount, so a re-attempt after crash-resume rides the same idempotency token and Slack returns the same
ts.
Test/mock mode
- New env
RELAYFLOWS_SLACK_MOCK=1. When set:- The helper writes each intended payload to
<data-dir>/mock-writeback/slack/<step-id>.json({channel, text, replyTo, thread_ts, idempotencyKey}). - Returns a synthetic receipt:
{channel, ts: 'mock-<stepid>', ref: 'mock-ref-<stepid>'}. - Nothing is sent over the wire.
- The helper writes each intended payload to
Acceptance evidence
- Journaled effect step. A test in
packages/sdk/tests/authored-flow-slack.test.tsruns an authored body containingawait f.slack.post('#test','hi')underRELAYFLOWS_SLACK_MOCK=1. The run journal shows exactly onestep.completedwithtype: 'effect',provider: 'slack',verb: 'post'. Assert on the JSON. - Preflight refusal. With no
SLACK_BOT_TOKENset and no--mock,flows checkon a body that usesf.slack.postprintsREFUSED [helper_slack.credential_missing]and exits 2. - Idempotency replay. A crash-resume test kills the run mid-write and resumes; the mock-payload file for that step's write body carries the same
idempotencyKeyin both attempts. The final journal has exactly onestep.completed. - Mock capture. With
RELAYFLOWS_SLACK_MOCK=1, running a two-post body writes exactly two files under<data-dir>/mock-writeback/slack/with the expected step IDs. - Type-consumer gate.
scripts/surface-package-gate.shextended so the packed-consumer's TS block importsSlackHelperand callsf.slack.post(...)in a typed body — a downstream author sees the type.
Files to touch
packages/surface/src/context.ts— addslack: SlackHelpertoCtx.packages/surface/src/slack.ts(new) — helper type contract.packages/surface/src/index.ts— re-exportSlackHelper,SlackReceipt.packages/surface/package.json— add@relayfile/relay-helpersas a peer dep (surface stays authoring-only; runtime consumes it).packages/sdk/src/authored-flow-executor.ts— route helper steps.packages/sdk/src/worker.ts(or the effect-worker file) — register the slack effect worker.packages/sdk/src/preflight.ts—helper_slackcheck.packages/sdk/src/observer-link.ts— no change; effect steps show up like other steps.packages/sdk/package.json— add@relayfile/relay-helpersas a dependency.packages/sdk/tests/authored-flow-slack.test.ts(new) — acceptance suite.scripts/surface-package-gate.sh— extend the packed-consumer TS block.docs/SURFACE.md— the helper section already exists; a small note thatf.slackis the first-generation pattern is fine but not required.
Not in scope
- The other 50 providers. They follow this pattern; each is a small follow-up PR.
- Rich Block Kit / message-formatting types.
- Event triggers (
on(slack.mention(...))) — that's slice E. f.memory— deferred.- Plugin registry (
flows add helper-*) — deferred until the helper contract is stable. - Anything cloud-side (cloud repo remains untouched).
Adjacent context
f.llmexecutor + declarative binding landed in flows#296 (commit9bd8c8095) — same authored-executor scaffold is where the slack path plugs in.CloudHelperinpackages/surface/src/cloud.tsis the existing helper-namespace shape to mirror.@relayfile/relay-helpersslack.ts— SlackClient interface +slackClient()factory that already returns the shape we surface.
Definition of done
CI green on linux-x64-artifact + packed-consumer, all bot findings ≥ Medium addressed, acceptance evidence #1–#5 above, and a one-line changelog entry in DRIVE-LOG.md pointing to the merged PR.
Activity
feat(surface,sdk): f.slack helper namespace (#299) (#314)