examples/marketing-agent.ts: FS sweep dumps the materialized GAP repo into user's project dir
Symptom
Running `examples/marketing-agent.ts` against a public GAP repo (e.g. `github.com/shreyas-lyzr/marketing-agent`) leaves ~50 stray files under `examples/marketing-outputs/agent-workdir-*`:
``` agent-workdir-skills-cold-email-SKILL.md agent-workdir-skills-copywriting-SKILL.md agent-workdir-skills-page-cro-SKILL.md ... (one per skill — 32 files) agent-workdir-README.md agent-workdir-RULES.md agent-workdir-SOUL.md agent-workdir-agent.yaml agent-workdir-.git-config agent-workdir-.git-index ... (.git internals — ~15 files) ```
These are not files the agent wrote. They are the materialized GAP repo cloned into the substrate's workdir at session boot. The example is vacuuming them back out into the user's project directory.
Root cause
`examples/marketing-agent.ts:200-218` runs:
```ts const tree = await treeRes.json(); for (const e of tree.entries) { if (e.type === "file") { const content = await fetchAgentFile(harnessUrl, finalSession, e.path); await saveOutput(`agent-workdir-${outName}`, content); // ← saves EVERYTHING } } ```
The intent of the block is "show what files the agent wrote during the session" (Path 2 from the artifact-output design — agent uses `Write`/`Bash` to create binaries the user fetches). The actual behavior is "copy the entire workdir, including the materialized GAP repo, into the user's CWD."
For `LocalSubstrate` this leaks ~200KB of files into the user's project. For `E2BSubstrate`/`VZVMSubstrate` the workdir lives inside the cloud sandbox / VM and is invisible to the user — but the example would still pull it all out over HTTP if the run completed.
Fix options
- Whitelist — only fetch files matching a caller-provided glob (e.g. `*.pptx`, `outputs/**`).
- Diff against boot snapshot — at session start, snapshot the workdir tree (paths + mtimes). At session end, only fetch files that are new or whose mtime advanced.
- Convention — agree that agents write deliverables under `/outputs/` (or some canonical path) and only sweep that prefix.
`#2` is the most ergonomic and substrate-agnostic. `#3` is a stronger contract that would benefit from a small GAP convention. `#1` is a quick fix for the example.
Definition of done
- The example no longer copies the materialized GAP repo into the user's CWD.
- A doc comment in the example explains why the workdir contains the GAP repo (so users don't get confused by a mostly-empty sweep).
- Add a test fixture that runs the example against `MockEngine` and asserts no `agent-workdir-*` files land in the project dir.
- (Optional) Document the "agents should write deliverables to `/outputs/`" convention if we go with option 3.
Related
- Issue #1 (binary artifact output) — the right long-term fix is a typed `agent.fetchArtifact()` helper plus a convention for where agents put deliverables. That makes this whole class of bug go away.
- Issue #2 (multi-turn replay) — surfaced during the same run.
Severity
Low for correctness (no data loss, no security issue), high for first-impressions UX. A new user runs the example, sees 50 mystery files in their repo, and wonders if ComputerAgent secretly committed the agent's source into their project. Bad first impression for what is otherwise a clean demo.
Fixed in b31b91c.
examples/marketing-agent.ts now snapshots the workdir tree right after turn 1 (after the GAP repo is materialized) and only fetches files that are new or modified relative to the snapshot at the end. The materialized GAP repo (~50 files) is excluded by definition.
Went with option 2 from the proposal (diff against boot snapshot) — it's substrate-agnostic and needs no convention from agents. Caller just gets back files the agent actually wrote.
Verified: marketing-outputs/ now contains only the 3 real deliverables + SessionStore JSONL. No agent-workdir-* leakage. The FS sweep block correctly reports "agent didn't write any files" when the agent only produced inline text — and would surface real Write-tool outputs cleanly when present.
The broader artifact story (typed agent.fetchArtifact() + standard /outputs/ convention) remains tracked in #1.