aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-09 00:33:44 +0100
committerDanilo M. <danix@danix.xyz>2026-11-09 00:33:44 +0100
commitaebcf0c91e3a8cb346321d86cc5dba0cbacfc3f4 (patch)
treeebc7d0bde3fc3b33c10acf9e0b6bd0f933a0049e
parente849d5ffbe56f0d04593ebee4255892c9be0984e (diff)
downloaddesktop-assistant-aebcf0c91e3a8cb346321d86cc5dba0cbacfc3f4.tar.gz
desktop-assistant-aebcf0c91e3a8cb346321d86cc5dba0cbacfc3f4.zip
attach: file and image blocks carry the path
Images get a one-line block so a tool (redact) can learn their path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-rw-r--r--assistant.py9
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}]