diff --git a/clawdforge/runner.py b/clawdforge/runner.py index 80e4216..35ca569 100644 --- a/clawdforge/runner.py +++ b/clawdforge/runner.py @@ -63,9 +63,6 @@ class Runner: cmd += ["--append-system-prompt", system] if effort: cmd += ["--effort", effort] - if files: - for f in files: - cmd += ["--files", f] timeout = timeout_secs or self.default_timeout @@ -74,6 +71,41 @@ class Runner: cwd = Path(self.runs_dir) / run_id cwd.mkdir(parents=True, exist_ok=True) + # File attachments are surfaced to claude by hardlinking (or + # copying, cross-fs) them into the per-run cwd under stable + # names `attachment-N.`, then appending a short manifest to + # the prompt that references them by relative path. claude -p's + # built-in Read tool then loads each on demand — including image + # content for vision models. + # + # Earlier impl tried `--files` / `--file` flags on the CLI but + # both are claude.ai-hosted file_id forms, not local-path + # accepting; pure-CWD staging is the only sane local path. + attachment_lines: list[str] = [] + if files: + for idx, src in enumerate(files, start=1): + src_p = Path(src) + ext = src_p.suffix.lstrip(".") or "bin" + staged_name = f"attachment-{idx}.{ext}" + staged_path = cwd / staged_name + try: + os.link(src, staged_path) + except OSError: + # Cross-filesystem hardlinks fail with EXDEV; fall back to copy. + shutil.copy2(src, staged_path) + attachment_lines.append(f"- ./{staged_name}") + if attachment_lines: + manifest = ( + "\n\nAttached files in the current directory (use the Read tool to view):\n" + + "\n".join(attachment_lines) + ) + if use_stdin: + # Mutate the input that goes to stdin. + prompt = prompt + manifest + else: + # Mutate the inline-positional arg we already pushed. + cmd[2] = cmd[2] + manifest + started = time.monotonic() try: proc = subprocess.run(