fix(sdk): populate f.agent artifacts instead of hardcoding []

Merged
KH
3mo ago
+330-1

Summary

  • authored-worker-step.ts's agent() always returned AgentResult.artifacts: [], so any flow gating on .gate((r) => r.artifacts.includes(...)) — including this repo's own examples/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 touched artifacts in 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, skipping node_modules and dotfiles/dotdirs (.git, the kernel's own .relayflowd data dir). Mirrors the existing convention in examples/research/shims/agent-cli.ts's snapshot(), extended to nested paths since social-post-pipeline.flow.ts's gates expect paths like research/notes.md.
  • agent() now snapshots options.cwd ?? process.cwd() before the step and diffs after, returning the real changed paths as artifacts.
  • 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, so artifacts stays [] 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) proving artifacts populates on the local-agent path and stays [] without one
  • tsc --noEmit clean on packages/sdk and packages/surface
  • Full packages/sdk vitest suite: 1586 passed / 60 failed, all 60 failing on ENOENT 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_modules and dotfiles/dotdirs (.git, .relayflowd) are skipped.
  • Only ENOENT errors are swallowed; any other filesystem error propagates instead of silently producing an incomplete artifacts list.
  • Unblocks examples/social-post-pipeline, whose gates expect paths like research/notes.md in artifacts.
  • Full packages/sdk vitest run: 1586 passed / 60 failed, all 60 from a missing Rust kernel binary (ENOENT relayflowd) — the same set fails without this change.