runner: stage attached files into per-run cwd, drop broken --files arg

The old code passed `--files <abspath>` to `claude -p`, but the CLI has
no such flag — it errored out with "unknown option '--files'" on the
first /run call carrying a file. The flag had been there since the
file-attachment path was added and was apparently never exercised end
to end against current claude versions.

New behavior: each file_path is hardlinked (cross-fs falls back to
copy) into the per-run cwd under a stable `attachment-N.<ext>` name,
and the prompt is appended with a `Attached files in the current
directory:` manifest pointing at the relative paths. claude -p's Read
tool then loads each file on demand — including image content for
vision models.

acpx /sessions path unaffected — it has its own _format_prompt_with_files.
This commit is contained in:
Kayos 2026-05-20 08:37:46 -07:00
parent 54e6732e39
commit 99ce6a9fc2

View file

@ -63,9 +63,6 @@ class Runner:
cmd += ["--append-system-prompt", system] cmd += ["--append-system-prompt", system]
if effort: if effort:
cmd += ["--effort", effort] cmd += ["--effort", effort]
if files:
for f in files:
cmd += ["--files", f]
timeout = timeout_secs or self.default_timeout timeout = timeout_secs or self.default_timeout
@ -74,6 +71,41 @@ class Runner:
cwd = Path(self.runs_dir) / run_id cwd = Path(self.runs_dir) / run_id
cwd.mkdir(parents=True, exist_ok=True) 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.<ext>`, 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() started = time.monotonic()
try: try:
proc = subprocess.run( proc = subprocess.run(