diff options
| -rw-r--r-- | assistant.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/assistant.py b/assistant.py index 96b9156..5c31167 100644 --- a/assistant.py +++ b/assistant.py @@ -368,8 +368,12 @@ def attach(paths, budget): for p, name, kind in loaded: chip = {"name": name, "kind": kind, "truncated": False} chips.append(chip) + # The path lets a tool (redact) open the file; a newline in it would + # close the block early, so such a path is left out. + where = f" ({p})" if "\n" not in p else "" if kind == "image": refs.append({"type": "image_ref", "name": name, "path": p, "sha256": sha256(p)}) + blocks.append(f"--- image: {name}{where} ---") continue if kind == "pdf": pages = pdf_pages(p) @@ -390,7 +394,7 @@ def attach(paths, budget): body += f"\n[scanned pages not shown: {', '.join(map(str, unseen))}]" chip["truncated"] = True note = " (truncated)" if chip["truncated"] else "" - blocks.append(f"--- file: {name}{note} ---\n{body}\n--- end file ---") + blocks.append(f"--- file: {name}{where}{note} ---\n{body}\n--- end file ---") return blocks, refs, chips @@ -1485,8 +1489,9 @@ def test(): f.write(b"a" * 4095 + "\u00e8 tail".encode()) assert kind_of(os.path.join(fd, "long")) == "text" blocks, refs, chips = attach([code, pdf, png], 100000) - assert blocks[0].startswith("--- file: a.py ---\nprint('hi')") and "(truncated)" not in blocks[0] + assert blocks[0].startswith(f"--- file: a.py ({code}) ---\nprint('hi')") and "(truncated)" not in blocks[0] assert "[page 1]\nhello pdf" in blocks[1] and "[page 2]" in blocks[1] + assert blocks[2] == f"--- image: red.png ({png}) ---" assert chips == [{"name": "a.py", "kind": "text", "truncated": False}, {"name": "doc.pdf", "kind": "pdf", "truncated": False, "pages": 2}, {"name": "red.png", "kind": "image", "truncated": False}] |
