pikuri-workspace 0.0.7 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,117 +4,71 @@ require 'ruby_llm'
4
4
 
5
5
  module Pikuri
6
6
  module Workspace
7
- # The +read+ tool, expressed as a {Pikuri::Tool} subclass: instantiating
8
- # +Read.new(workspace: ws)+ produces a tool whose
9
- # {Pikuri::Tool#to_ruby_llm_tool} wiring is identical to any bundled
10
- # tool's, so ruby_llm sees nothing special about it. Same shape as
11
- # the +agent+ tool from +pikuri-subagents+ — workspace is captured by
12
- # the +execute+ closure at construction.
7
+ # The +read+ tool as a {Pikuri::Tool} subclass: +Read.new(workspace: ws)+
8
+ # produces a tool whose {Pikuri::Tool#to_ruby_llm_tool} wiring is identical
9
+ # to any bundled tool's. Workspace is captured by the +execute+ closure.
13
10
  #
14
11
  # == Output format
15
12
  #
16
- # cat-n: each line is rendered as +"%6d\t%s"+ (six-column right-
17
- # padded line number, tab, content). Chosen for breadth of training-
18
- # data exposure: +cat -n+ output shows up across virtually every Unix
19
- # tutorial and Stack Overflow answer, so even small local models
20
- # recognize the shape. opencode's shorter +"<n>: <content>"+ format
21
- # saves a few thousand tokens per 2K-line file but trades model
22
- # familiarity; pi omits line numbers entirely (cheapest tokens, but
23
- # the model loses the ability to cite ranges or pick {Edit}
24
- # boundaries precisely).
13
+ # cat-n: each line +"%6d\t%s"+ (6-col line number, tab, content). Chosen for
14
+ # training-data familiarity — +cat -n+ is everywhere, so even small local
15
+ # models recognize it; opencode's +"<n>: "+ saves tokens but trades
16
+ # familiarity, pi omits numbers (cheapest, but no range citation or {Edit}
17
+ # boundaries).
18
+ # The numbering and {DESCRIPTION}'s read-a-larger-window nudge were
19
+ # confirmed as a pair by an outside-model review (Grok 4.6, 2026-08) —
20
+ # don't trade either back for tokens.
25
21
  #
26
22
  # == Truncation rules
27
23
  #
28
- # The line/byte windowing is delegated to
29
- # {Pikuri::FileType.read_as_text_paged}, which returns a
30
- # {Pikuri::Extractor::Page} this tool renders; the same windower
31
- # backs +VectorDb::Tools::Read+. Two independent limits, whichever fires
32
- # first wins:
24
+ # Line/byte windowing is delegated to {Pikuri::FileType.read_as_text_paged},
25
+ # which returns a {Pikuri::Extractor::Page} this tool renders through
26
+ # {Pikuri::Tool::Result.page} (the one paging trailer every reader shares).
27
+ # Two limits, first to fire wins: a line
28
+ # limit ({DEFAULT_LIMIT}, overridable via +limit+) and a byte cap
29
+ # ({MAX_BYTES}, not a parameter, bypassable by paging via +offset+). Lines
30
+ # over {MAX_LINE_LENGTH} are truncated with {LINE_TRUNCATION_MARKER}. (The
31
+ # constants alias the +PAGE_*+ ones on {Pikuri::Extractor}.)
33
32
  #
34
- # * *Line limit* — {DEFAULT_LIMIT} lines (overridable via +limit+).
35
- # * *Byte cap* — {MAX_BYTES} bytes of input content; not exposed as a
36
- # parameter. Bypassable in practice by paging via +offset+.
33
+ # == PDF and other extracted formats
37
34
  #
38
- # Additionally, individual lines longer than {MAX_LINE_LENGTH} chars
39
- # are truncated with {LINE_TRUNCATION_MARKER} appended; the model is
40
- # told to reach for +grep+ to find content inside such files. (These
41
- # constants alias the +PAGE_*+ ones on {Pikuri::Extractor} — one
42
- # source of truth, shared with +VectorDb::Tools::Read+.)
43
- #
44
- # == PDF (and other extracted formats)
45
- #
46
- # Which formats read as text is the {Pikuri::Extractor} registry's
47
- # business, not this tool's: with pikuri-pdf's extractor
48
- # registered, PDFs are claimed by their +%PDF-+ magic prefix ahead
49
- # of the binary refusal and extracted with one synthetic
50
- # +"--- Page N ---"+ header line per page (see
51
- # +Pikuri::Extractors::PDF+); a gem plugging another extractor
52
- # into the registry extends this tool for free. Extraction is lazy
53
- # where the format allows (+extract_lines+): reading the first
54
- # window of a 500-page PDF parses only the pages the window needs.
55
- # Formats without a lazy line shape (HTML) are extracted in full
56
- # and then windowed. Line numbers in PDF output are for citation
57
- # back to the user only; PDFs are not editable through {Edit}.
58
- #
59
- # PDFs with no extractable text (scanned images, empty documents) come
60
- # back with an LLM-actionable hint string rather than an empty
61
- # observation. Encrypted / malformed / XFA-form PDFs surface as
62
- # +"Error: ..."+ — same convention as other tool errors the model
63
- # can react to. No OCR.
35
+ # Which formats read as text is the {Pikuri::Extractor} registry's business:
36
+ # with pikuri-pdf registered, PDFs are claimed by +%PDF-+ ahead of the
37
+ # binary refusal and extracted with one +"--- Page N ---"+ header per page,
38
+ # lazily where the format allows (a 500-page PDF's first window parses only
39
+ # its pages). PDF line numbers are for citation only — PDFs aren't editable.
40
+ # No extractable text (scanned/empty) → an LLM-actionable hint;
41
+ # encrypted/malformed → +"Error: ..."+. No OCR.
64
42
  #
65
43
  # == Image attachments
66
44
  #
67
- # PNG / JPEG / GIF / WebP files are detected by magic bytes (see
68
- # {.image_mime}) and routed to {.format_image} ahead of the binary
69
- # sniff. Instead of a +String+ observation, the tool returns a
70
- # +RubyLLM::Content+ carrying a short metadata note ("Read image:
71
- # path (bytes, mime)") plus the file as an attachment; the
72
- # per-provider Media formatter turns that into the right image
73
- # content block inside the +tool_result+. The text half is what the
74
- # model cites back ("the image at lib/foo.png shows…"); the image
75
- # half is what the model actually looks at.
76
- #
77
- # +offset+ / +limit+ are ignored on the image path — there's no
78
- # line-paging concept. The hard size cap is {MAX_IMAGE_BYTES}; files
79
- # above that come back as +"Error: image too large…"+ rather than
80
- # being silently encoded into a payload the upstream API would
81
- # reject. No auto-resize: pikuri doesn't pull in an image-processing
82
- # dep for one tool's ergonomics. See +IDEAS.md+ for the deferred
83
- # auto-resize discussion.
45
+ # PNG/JPEG/GIF/WebP (magic-byte detected) route to {.format_image} ahead of
46
+ # the binary sniff, answering the one {Pikuri::Tool::Result} in pikuri with
47
+ # +attachments+: a metadata note ("Read image: …") as +content+ for the
48
+ # model to cite, plus the file as an attachment the model looks at.
49
+ # +offset+/+limit+ are ignored (no line paging). Over
50
+ # {Pikuri::Attachment::MAX_IMAGE_BYTES} → +"Error: image too large…"+ rather than a payload the
51
+ # provider rejects; no auto-resize (see +design/ideas/coding-agent.md+). Vision
52
+ # capability is not checked — a non-vision model's provider error is
53
+ # something the LLM reacts to, cheaper than tracking model metadata.
84
54
  #
85
- # Vision capability of the underlying model is *not* checked here.
86
- # Sending an image to a non-vision model produces a provider error
87
- # the LLM can react to on the next turn; coupling Read to model
88
- # capability metadata (notoriously incomplete for local servers)
89
- # buys less than the friction it adds.
55
+ # == Refusals (all as +"Error: ..."+)
90
56
  #
91
- # == Refusals
57
+ # Path outside the workspace ({Filesystem::Error}), not found, EACCES, a
58
+ # directory (refused, but the refusal carries the directory's own entries —
59
+ # see {.directory_refusal}), image over {Pikuri::Attachment::MAX_IMAGE_BYTES}, binary content
60
+ # (nothing in the registry claims it — the {Pikuri::FileType.binary?}
61
+ # heuristic catches archives/artifacts with no extension list), offset past
62
+ # EOF.
92
63
  #
93
- # * Path outside the workspace → caught from
94
- # {Filesystem::Error}, returned as +"Error: ..."+.
95
- # * File not found, EACCES → +"Error: ..."+.
96
- # * Path is a directory → +"Error: ... use the glob tool"+, keeping
97
- # directory listing as the glob tool's responsibility (Step 9).
98
- # * Image larger than {MAX_IMAGE_BYTES} → +"Error: image too large…"+,
99
- # leaving the model to pick a different file or ask the user to
100
- # resize.
101
- # * Binary content → nothing in the {Pikuri::Extractor} registry
102
- # claims it ({Pikuri::Extractor::Passthrough} declines on the
103
- # {Pikuri::FileType.binary?} heuristic: any +NUL+ byte or a
104
- # sample dense in control characters). Catches archives and
105
- # compiled artifacts without an extension list to maintain.
106
- # Registered extractors (pikuri-pdf's PDF, pikuri-extractors'
107
- # office formats) claim their bytes ahead of that refusal;
108
- # images are intercepted here via {Pikuri::FileType.detect_mime}
109
- # before extraction is attempted — see above.
110
- # * Offset past EOF → +"Error: offset N is beyond end of file (M lines total)"+.
64
+ # Sharing: +P_one_agent+ — every successful read marks the path on its
65
+ # {Workspace}, which *is* the read-before-edit gate's state, so a shared
66
+ # instance would let one agent's read unlock another's {Edit}.
111
67
  class Read < Pikuri::Tool
112
- # The windowing constants live on {Pikuri::Extractor} (shared
113
- # with +VectorDb::Tools::Read+); these aliases keep the names this tool's
114
- # description and specs reference pointing at the single source.
68
+ # These alias the +PAGE_*+ constants on {Pikuri::Extractor} (one source of
69
+ # truth, shared with +Fileindex::Read+).
115
70
 
116
- # @return [Integer] default value of the +limit+ parameter (number
117
- # of lines to read per call).
71
+ # @return [Integer] default value of the +limit+ parameter (lines per call).
118
72
  DEFAULT_LIMIT = Pikuri::Extractor::PAGE_DEFAULT_LIMIT
119
73
 
120
74
  # @return [Integer] per-line character cap; longer lines are
@@ -125,30 +79,16 @@ module Pikuri
125
79
  # {MAX_LINE_LENGTH}.
126
80
  LINE_TRUNCATION_MARKER = Pikuri::Extractor::PAGE_LINE_TRUNCATION_MARKER
127
81
 
128
- # @return [Integer] hard byte cap on input content collected per
129
- # call. Counted on the line bytes (plus one for the joining
130
- # newline); the rendered output is slightly larger due to the
131
- # per-line +"%6d\t"+ prefix.
82
+ # @return [Integer] hard byte cap on input content per call (line bytes +
83
+ # the joining newline; rendered output is larger due to the +"%6d\t"+
84
+ # prefix).
132
85
  MAX_BYTES = Pikuri::Extractor::PAGE_MAX_BYTES
133
86
 
134
- # @return [String] human-readable form of {MAX_BYTES} for the
135
- # continuation marker.
136
- MAX_BYTES_LABEL = "#{MAX_BYTES / 1024} KB"
87
+ # @return [String] human-readable {Pikuri::Attachment::MAX_IMAGE_BYTES} for refusal messages.
88
+ MAX_IMAGE_BYTES_LABEL = "#{Pikuri::Attachment::MAX_IMAGE_BYTES / (1024 * 1024)} MB"
137
89
 
138
- # @return [Integer] hard size cap on inline-attached images. Matches
139
- # Anthropic's per-image limit; same order of magnitude on
140
- # OpenAI / Gemini. Above this we refuse rather than encode a
141
- # payload the provider would reject.
142
- MAX_IMAGE_BYTES = 5 * 1024 * 1024
143
-
144
- # @return [String] human-readable form of {MAX_IMAGE_BYTES} for
145
- # refusal messages.
146
- MAX_IMAGE_BYTES_LABEL = "#{MAX_IMAGE_BYTES / (1024 * 1024)} MB"
147
-
148
- # Description shown to the LLM. Follows the opencode-shape (summary
149
- # + +Usage:+ bullets) prescribed by the project's tool-description
150
- # convention. Per-parameter constraints (defaults, format) live in
151
- # the parameter descriptions, not here.
90
+ # Description shown to the LLM (opencode-shape). Per-parameter constraints
91
+ # live in the parameter descriptions.
152
92
  #
153
93
  # @return [String]
154
94
  DESCRIPTION = <<~DESC
@@ -161,13 +101,12 @@ module Pikuri
161
101
  - PDFs are text-extracted page-by-page with `--- Page N ---` markers in the output. Cite pages back to the user from those markers. PDFs cannot be modified with `edit`.
162
102
  - PNG / JPEG / GIF / WebP files are attached as images you can see directly, alongside a short text note with the path and size. Requires a vision-capable model; on a text-only model the provider will reject the call. Images cannot be modified with `edit`.
163
103
  - Other binary files (archives, compiled artifacts) are refused; this tool reads text otherwise.
164
- - Directories are refused — use the `glob` tool to list files.
165
104
  - If unsure of the path, use `glob` first to look up filenames.
166
105
  - Avoid tiny repeated slices — if you need more context, read a larger window.
167
106
  DESC
168
107
 
169
- # @param workspace [Filesystem] captured for path resolution;
170
- # all reads route through +workspace.resolve_for_read+.
108
+ # @param workspace [Workspace] captured for path resolution and
109
+ # read-ledger marking (+resolve_for_read+ / +mark_read+).
171
110
  # @return [Read]
172
111
  def initialize(workspace:)
173
112
  super(
@@ -187,41 +126,35 @@ module Pikuri
187
126
  },
188
127
  execute: ->(path:, offset: 1, limit: DEFAULT_LIMIT) {
189
128
  Read.read(workspace: workspace, path: path, offset: offset, limit: limit)
190
- }
129
+ },
130
+ trifecta_legs: Tool::TrifectaLegs.new(
131
+ private: workspace.filesystem.private?,
132
+ untrusted: workspace.filesystem.trusted? ? :none : :hard,
133
+ egress_payload_review: :no_egress
134
+ )
191
135
  )
192
136
  end
193
137
 
194
- # Produce a new {Read} bound to +workspace+. Used by
195
- # {Pikuri::SubAgent::SubAgentTool} when a persona supplies a
196
- # +workspace_factory:+ — the parent's instance is rebuilt for
197
- # the sub-agent's fresh workspace so paths resolve against the
198
- # right root.
138
+ # Resolve +path+ against +workspace+, refuse directories/binaries/missing
139
+ # files, return the cat-n slice.
199
140
  #
200
- # @param workspace [Filesystem]
201
- # @return [Read]
202
- def with_workspace(workspace)
203
- self.class.new(workspace: workspace)
204
- end
205
-
206
- # Resolve +path+ against +workspace+, refuse directories / binaries /
207
- # missing files, and return either the cat-n-formatted slice or an
208
- # +"Error: ..."+ observation.
209
- #
210
- # @param workspace [Filesystem]
211
- # @param path [String] raw path as supplied by the LLM
212
- # @param offset [Integer] 1-indexed line number to start at
213
- # @param limit [Integer] maximum lines to return
214
- # @return [String, RubyLLM::Content] tool observation. Text and PDF
215
- # paths return a +String+; supported images return a
216
- # +RubyLLM::Content+ with the file attached so the model receives
217
- # the image inline. See "Image attachments" above.
141
+ # @param workspace [Workspace]
142
+ # @param path [String] raw path from the LLM
143
+ # @param offset [Integer] 1-indexed start line
144
+ # @param limit [Integer] maximum lines
145
+ # @return [Tool::Result] text/PDF → the cat-n slice (+"Read 214 lines"+);
146
+ # a supported image → a note with the file in
147
+ # {Tool::Result#attachments} (see "Image attachments"); else
148
+ # {Pikuri::Tool::Result.error}
218
149
  def self.read(workspace:, path:, offset:, limit:)
219
- return "Error: offset must be >= 1, got #{offset}" if offset < 1
220
- return "Error: limit must be >= 1, got #{limit}" if limit < 1
150
+ return Tool::Result.error("offset must be >= 1, got #{offset}") if offset < 1
151
+ return Tool::Result.error("limit must be >= 1, got #{limit}") if limit < 1
221
152
 
222
153
  resolved = workspace.resolve_for_read(path)
223
- return "Error: file not found: #{path}" unless resolved.exist?
224
- return "Error: #{path} is a directory; use the glob tool to list files." if resolved.directory?
154
+ return Tool::Result.error(workspace.not_found(path)) unless resolved.exist?
155
+ if resolved.directory?
156
+ return Tool::Result.error(directory_refusal(workspace: workspace, path: path, resolved: resolved))
157
+ end
225
158
 
226
159
  mime = Pikuri::FileType.detect_mime(resolved)
227
160
  return format_image(path: path, resolved: resolved, mime: mime) if mime&.start_with?('image/')
@@ -230,104 +163,85 @@ module Pikuri
230
163
  resolved, offset: offset, limit: limit,
231
164
  max_bytes: MAX_BYTES, max_line_length: MAX_LINE_LENGTH
232
165
  )
233
- render_page(page)
166
+ # Record the read so a later edit/overwrite clears the read-before-edit
167
+ # gate. Any successful text/PDF read counts (even a partial window) —
168
+ # the exact-bytes guard is Edit's +old_string+ match; the ledger only
169
+ # attests "engaged via read".
170
+ workspace.mark_read(resolved)
171
+ Tool::Result.page(page)
234
172
  rescue Filesystem::Error => e
235
- "Error: #{e.message}"
173
+ Tool::Result.error(e.message)
236
174
  rescue Errno::EACCES => e
237
- "Error: cannot read #{path}: #{e.message}"
175
+ Tool::Result.error("cannot read #{path}: #{e.message}")
238
176
  rescue ArgumentError
239
177
  # Nothing in the Extractor registry claimed the content —
240
178
  # read_as_text_paged's binary refusal (directories and images
241
179
  # were already handled above).
242
- "Error: cannot read binary file: #{path}"
180
+ Tool::Result.error("cannot read binary file: #{path}")
243
181
  rescue RuntimeError => e
244
182
  # Extraction failure (malformed / unsupported PDF, ...)
245
183
  # surfaced by read_as_text_paged.
246
- "Error: #{e.message}"
184
+ Tool::Result.error(e.message)
247
185
  end
248
186
 
249
- # Render a {Pikuri::Extractor::Page} as the cat-n observation: a
250
- # six-column line number, a tab, then the (already-truncated)
251
- # content, followed by a trailer that tells the model whether to
252
- # page on. PDF pages carry +"--- Page N ---"+ marker lines from
253
- # the extractor; the +kind+ only changes trailer wording here.
187
+ # Refuses, but hands back the directory's entries so the model recovers
188
+ # with no extra round-trip — the {Search::Utils.oversized_root_refusal}
189
+ # move:
254
190
  #
255
- # @param page [Pikuri::Extractor::Page]
256
- # @return [String]
257
- def self.render_page(page)
258
- if page.lines.empty?
259
- return empty_message(page) if page.total_lines.zero?
260
-
261
- return "Error: offset #{page.start_line} is beyond end of file " \
262
- "(#{page.total_lines} lines total)"
263
- end
264
-
265
- noun = page.kind == :pdf ? 'PDF ' : ''
266
- last = page.start_line + page.lines.length - 1
267
- body = page.lines.each_with_index.map { |line, i| format("%6d\t%s", i + page.start_line, line) }.join("\n")
268
-
269
- trailer =
270
- if page.byte_capped
271
- "(Output capped at #{MAX_BYTES_LABEL}. Showing #{noun}lines #{page.start_line}-#{last}. " \
272
- "Use offset=#{last + 1} to continue.)"
273
- elsif page.more
274
- total = page.total_lines ? " of #{page.total_lines}" : ''
275
- "(Showing #{noun}lines #{page.start_line}-#{last}#{total}. " \
276
- "Use offset=#{last + 1} to continue.)"
277
- else
278
- "(End of #{page.kind == :pdf ? 'PDF' : 'file'} - total #{page.total_lines} lines)"
279
- end
280
-
281
- "#{body}\n\n#{trailer}"
282
- end
283
- private_class_method :render_page
284
-
285
- # The empty-document message, worded by content kind: a scanned /
286
- # text-free PDF gets an LLM-actionable hint rather than the
287
- # plain-file "(Empty file)".
191
+ # Error: lib is a directory, not a file. It contains (directories end with `/`):
192
+ # pikuri/ [3 dirs, 1 file]
193
+ # version.rb 48B
288
194
  #
289
- # @param page [Pikuri::Extractor::Page]
290
- # @return [String]
291
- def self.empty_message(page)
292
- if page.kind == :pdf
293
- '(PDF has no extractable text; likely scanned image content)'
294
- else
295
- '(Empty file)'
296
- end
195
+ # **Keep this out of {DESCRIPTION}.** It is error recovery, not a
196
+ # documented capability: teaching +read+ as a second way to list hands
197
+ # the model a two-tools-no-criterion coin flip (+D_directory_listing+).
198
+ #
199
+ # Never marks the read ledger — a directory can't be edited, so counting
200
+ # it would clear the read-before-edit gate for a path nobody read.
201
+ #
202
+ # @param workspace [Workspace]
203
+ # @param path [String] raw path from the LLM (for the message)
204
+ # @param resolved [Pathname] workspace-resolved path
205
+ # @return [String] the refusal message, carrying the depth-1 listing —
206
+ # text for {Tool::Result.error} to wrap, not an observation itself
207
+ def self.directory_refusal(workspace:, path:, resolved:)
208
+ base = "Error: #{path} is a directory, not a file."
209
+ listing = Listing.render(resolved, filesystem: workspace.filesystem)
210
+ return "#{base} It is empty." if listing.empty?
211
+
212
+ "#{base} It contains (directories end with `/`):\n#{listing}"
213
+ rescue SystemCallError => e
214
+ "#{base} It cannot be listed: #{e.message}"
297
215
  end
298
- private_class_method :empty_message
299
-
300
- # Build a multimodal observation: a short metadata note ("Read
301
- # image: …") plus the file itself attached as a path. The model
302
- # sees the note as the text half of the +tool_result+ and the
303
- # image as the image half — both arrive in the same turn.
216
+ private_class_method :directory_refusal
217
+
218
+ # Build a multimodal observation: a metadata note ("Read image: …") plus
219
+ # the file attached, both arriving in the same +tool_result+ turn. Over
220
+ # {Pikuri::Attachment::MAX_IMAGE_BYTES} we refuse (an +"Error: ..."+ the model reacts to)
221
+ # rather than encoding a payload the provider rejects. The bytes are read
222
+ # here, once, at most one past the cap — what the model sees is what was
223
+ # checked, and an oversized file is never loaded whole.
304
224
  #
305
- # Anthropic's per-image cap is 5 MB on the encoded data, and the
306
- # other providers we target sit in the same order of magnitude.
307
- # Above {MAX_IMAGE_BYTES} we refuse rather than encoding a payload
308
- # the provider will reject; the +"Error: image too large…"+ string
309
- # is something the model can react to (pick a different file or
310
- # ask the user to resize). Reading the file size via
311
- # +Pathname#size+ avoids loading the bytes just to discover they
312
- # were over-cap; +RubyLLM::Attachment+ does the actual base64
313
- # encoding lazily, once the message is being formatted for the
314
- # provider.
225
+ # The one place a {Tool::Result} carries +attachments+: the attached
226
+ # bytes *are* the observation, so the display
227
+ # line is derived from mime and size rather than authored here (see
228
+ # {Pikuri::Tool::Result}'s +== Text or an attachment+).
315
229
  #
316
- # @param path [String] raw path as supplied by the LLM (kept for
317
- # the metadata note)
230
+ # @param path [String] raw path from the LLM (for the note)
318
231
  # @param resolved [Pathname] workspace-resolved path
319
- # @param mime [String] MIME type from {.image_mime}
320
- # @return [String, RubyLLM::Content] +RubyLLM::Content+ on success;
321
- # +"Error: ..."+ String on size refusal.
232
+ # @param mime [String] MIME type
233
+ # @return [Tool::Result] attachment-carrying on success;
234
+ # {Pikuri::Tool::Result.error} on size refusal
322
235
  def self.format_image(path:, resolved:, mime:)
323
- size = resolved.size
324
- if size > MAX_IMAGE_BYTES
325
- return "Error: image too large to inline: #{path} is " \
326
- "#{size} bytes; max #{MAX_IMAGE_BYTES_LABEL}."
236
+ bytes = File.binread(resolved, Pikuri::Attachment::MAX_IMAGE_BYTES + 1)
237
+ if bytes.bytesize > Pikuri::Attachment::MAX_IMAGE_BYTES
238
+ return Tool::Result.error("image too large to inline: #{path} is " \
239
+ "#{resolved.size} bytes; max #{MAX_IMAGE_BYTES_LABEL}.")
327
240
  end
328
241
 
329
- note = "Read image: #{path} (#{size} bytes, #{mime})"
330
- RubyLLM::Content.new(note, [resolved.to_s])
242
+ image = Pikuri::Attachment.new(mime: mime, filename: resolved.basename.to_s, bytes: bytes)
243
+ note = "Read image: #{path} (#{bytes.bytesize} bytes, #{mime})"
244
+ Tool::Result.new(content: note, attachments: [image], summary: Pikuri::Tool.one_line(note))
331
245
  end
332
246
  private_class_method :format_image
333
247
  end