fix(sdk): populate f.agent artifacts instead of hardcoding []
Summary
authored-worker-step.ts'sagent()always returnedAgentResult.artifacts: [], so any flow gating on.gate((r) => r.artifacts.includes(...))— including this repo's ownexamples/social-post-pipeline/social-post-pipeline.flow.ts— could never pass, regardless of what the agent actually wrote to disk. Confirmed only one commit had ever touchedartifactsin that file (its original introduction).- Adds
packages/sdk/src/agent-artifacts.ts: a recursive, content-hash (size + sha256, not mtime) snapshot/diff of a directory, skippingnode_modulesand dotfiles/dotdirs (.git, the kernel's own.relayflowddata dir). Mirrors the existing convention inexamples/research/shims/agent-cli.ts'ssnapshot(), extended to nested paths sincesocial-post-pipeline.flow.ts's gates expect paths likeresearch/notes.md. agent()now snapshotsoptions.cwd ?? process.cwd()before the step and diffs after, returning the real changed paths asartifacts.- Scoped to the local-agent path only (
localAgentStream !== undefined): that's the only worker attachment that runs in the same process/filesystem as the authoring code, so the cwd is provably where the CLI wrote. Any other attachment (a remote/relay worker) could be on a different host entirely, soartifactsstays[]there rather than guessing — this is intentional, not a shortcut.
Test plan
- New unit tests on
snapshotWorkspaceFiles/diffWorkspaceFiles(nested write, same-size content change, no-op,node_modules/dotdir skipping, missing dir) - New integration tests through
executeAuthoredFlow(fake-loopback-journal harness) provingartifactspopulates on the local-agent path and stays[]without one -
tsc --noEmitclean onpackages/sdkandpackages/surface - Full
packages/sdkvitest suite: 1586 passed / 60 failed, all 60 failing onENOENT relayflowd(this environment has no built Rust kernel binary) — identical failure set with and without this change, confirmed by reverting and re-running
🤖 Generated with Claude Code
https://claude.ai/code/session_01YcQh7UEGp1k8TzBH8aiZsu
[!NOTE]
Medium Risk
Changes authored-flow step results and filesystem I/O on every local direct agent step; behavior is scoped but affects gate logic that depends on artifacts.
Overview
f.agent() no longer always returns artifacts: []. On the local-agent direct path, the worker snapshots options.cwd (or process.cwd()) before the step and diffs after execution, returning sorted paths for new or content-changed files (size + SHA-256, not mtime). Dotfiles/dotdirs and node_modules are excluded; missing cwd yields an empty snapshot; non-ENOENT scan errors still fail the step.
Relay transport and runs without a local agent stream keep artifacts: [] so the SDK does not infer remote filesystem writes from the authoring process.
New agent-artifacts helpers and unit/integration tests cover nested paths, same-size edits, skip rules, and the local vs relay vs no-local-agent behavior—unblocking flows that gate on result.artifacts (e.g. paths like research/notes.md).
Reviewed by Cursor Bugbot for commit 8f3a45e43b1062454ca5b19a8f986a8e6d119978. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by cubic
Fixes f.agent() steps in authored flows always returning artifacts: [], so gates like .gate((r) => r.artifacts.includes(...)) can now pass when the agent writes files. The step snapshots its working directory before running and reports changed paths as artifacts; detection runs only on the local-agent direct transport path, since relay and other worker attachments may execute on a different host and keep returning [].
- Changed files are detected by content hash (size + sha256), not mtime.
node_modulesand dotfiles/dotdirs (.git,.relayflowd) are skipped.- Only
ENOENTerrors are swallowed; any other filesystem error propagates instead of silently producing an incompleteartifactslist. - Unblocks
examples/social-post-pipeline, whose gates expect paths likeresearch/notes.mdinartifacts. - Full
packages/sdkvitest run: 1586 passed / 60 failed, all 60 from a missing Rust kernel binary (ENOENT relayflowd) — the same set fails without this change.