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.
- checksums.yaml +4 -4
- data/README.md +23 -16
- data/lib/pikuri/workspace/confirmer/terminal.rb +252 -0
- data/lib/pikuri/workspace/confirmer.rb +184 -123
- data/lib/pikuri/workspace/edit.rb +261 -101
- data/lib/pikuri/workspace/extension.rb +163 -0
- data/lib/pikuri/workspace/file_list.rb +125 -0
- data/lib/pikuri/workspace/filesystem.rb +160 -446
- data/lib/pikuri/workspace/listing.rb +204 -0
- data/lib/pikuri/workspace/read.rb +139 -225
- data/lib/pikuri/workspace/search/glob.rb +310 -0
- data/lib/pikuri/workspace/search/grep.rb +353 -0
- data/lib/pikuri/workspace/search/utils.rb +173 -0
- data/lib/pikuri/workspace/workspace.rb +105 -0
- data/lib/pikuri/workspace/write.rb +129 -78
- data/lib/pikuri/workspace/write_gate.rb +74 -0
- data/lib/pikuri-workspace.rb +8 -10
- data/prompts/pikuri-files.txt +6 -0
- metadata +32 -11
- data/lib/pikuri/workspace/glob.rb +0 -322
- data/lib/pikuri/workspace/grep.rb +0 -350
- data/lib/pikuri/workspace/project_root.rb +0 -102
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Pikuri
|
|
4
|
+
module Workspace
|
|
5
|
+
# The +file_list+ tool — the only way the model learns that a directory
|
|
6
|
+
# *exists*. {Search::Glob} is built on +rg --files+, which emits files
|
|
7
|
+
# only, so +glob '*'+ at a monorepo root shows the loose root files and
|
|
8
|
+
# hides every gem.
|
|
9
|
+
#
|
|
10
|
+
# FileList.list(workspace: ws, path: 'pikuri-workspace/lib', depth: 2) # =>
|
|
11
|
+
# pikuri/
|
|
12
|
+
# workspace/ [2 dirs, 12 files]
|
|
13
|
+
# pikuri-workspace.rb 961B
|
|
14
|
+
#
|
|
15
|
+
# Row format is {Listing}'s; this class owns only the LLM-facing surface —
|
|
16
|
+
# parameter validation, +resolve_for_read+, and the refusals.
|
|
17
|
+
#
|
|
18
|
+
# Not under +Workspace::Search::+ where Grep and Glob live: listing a
|
|
19
|
+
# folder is a read of it, not a search. Borrowing {Search::Utils} is reuse,
|
|
20
|
+
# not membership.
|
|
21
|
+
#
|
|
22
|
+
# == Refusals (all as +"Error: ..."+)
|
|
23
|
+
#
|
|
24
|
+
# +depth+ below 1; +path+ is a regular file (→ read tool); +path+ not
|
|
25
|
+
# found; +path+ outside the workspace ({Filesystem::Error}); an oversized
|
|
26
|
+
# root, which hands back the root's own entries to pick from rather than
|
|
27
|
+
# dead-ending (see {Search::Utils.oversized_root_refusal}). A +depth+ over
|
|
28
|
+
# {Listing::MAX_DEPTH} is clamped, not refused — the answer is still the
|
|
29
|
+
# one asked for, just shallower.
|
|
30
|
+
#
|
|
31
|
+
# Sharing: +P_one_agent+ — it never touches the read record, so nothing
|
|
32
|
+
# races; what makes it one agent's is the {Workspace} it enumerates, since
|
|
33
|
+
# that is one agent's project view.
|
|
34
|
+
class FileList < Pikuri::Tool
|
|
35
|
+
# Description shown to the LLM (opencode-shape). Per-parameter constraints
|
|
36
|
+
# live in the parameter descriptions.
|
|
37
|
+
#
|
|
38
|
+
# @return [String]
|
|
39
|
+
DESCRIPTION = <<~DESC
|
|
40
|
+
List what is inside a directory: subdirectories first, then files, sorted by name.
|
|
41
|
+
|
|
42
|
+
Usage:
|
|
43
|
+
- Reach for this first in an unfamiliar tree — it is the only tool that shows you which subdirectories exist.
|
|
44
|
+
- Directories end with `/` and carry a count of what is inside them (`[3 dirs, 1 file]`); files carry their size.
|
|
45
|
+
- Raise `depth` to see nested structure in one call rather than listing each subdirectory in turn.
|
|
46
|
+
- Everything on disk is listed, including files `.gitignore` hides; use `glob` instead when you want a gitignore-respecting search by filename pattern.
|
|
47
|
+
- Output is truncated to #{Listing::MAX_BYTES_LABEL}; list a subdirectory if the response ends in a truncation marker.
|
|
48
|
+
DESC
|
|
49
|
+
|
|
50
|
+
# @param workspace [Workspace] captured for path resolution; path
|
|
51
|
+
# arguments route through +resolve_for_read+.
|
|
52
|
+
# @return [FileList]
|
|
53
|
+
def initialize(workspace:)
|
|
54
|
+
super(
|
|
55
|
+
name: 'file_list',
|
|
56
|
+
description: DESCRIPTION,
|
|
57
|
+
parameters: Parameters.build { |p|
|
|
58
|
+
p.optional_string :path,
|
|
59
|
+
'Directory to list (e.g. "lib" or ' \
|
|
60
|
+
'"spec/pikuri"). Relative paths resolve against ' \
|
|
61
|
+
'the workspace root. Defaults to the workspace ' \
|
|
62
|
+
'root if missing.'
|
|
63
|
+
p.optional_integer :depth,
|
|
64
|
+
'How many levels to descend. Defaults to ' \
|
|
65
|
+
"#{Listing::DEFAULT_DEPTH} (immediate children " \
|
|
66
|
+
"only); values above #{Listing::MAX_DEPTH} are " \
|
|
67
|
+
"capped at #{Listing::MAX_DEPTH}."
|
|
68
|
+
},
|
|
69
|
+
execute: lambda { |path: nil, depth: Listing::DEFAULT_DEPTH|
|
|
70
|
+
FileList.list(workspace: workspace, path: path, depth: depth)
|
|
71
|
+
},
|
|
72
|
+
# Filenames and sizes, not contents — same reasoning as Glob: a path
|
|
73
|
+
# can be as sensitive as a file and is as attacker-authorable, so
|
|
74
|
+
# this reads the same as Read.
|
|
75
|
+
trifecta_legs: Tool::TrifectaLegs.new(
|
|
76
|
+
private: workspace.filesystem.private?,
|
|
77
|
+
untrusted: workspace.filesystem.trusted? ? :none : :hard,
|
|
78
|
+
egress_payload_review: :no_egress
|
|
79
|
+
)
|
|
80
|
+
)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# The workspace root renders as +.+ rather than as nothing: +path+ is
|
|
84
|
+
# optional and the model usually omits it, which the generic default
|
|
85
|
+
# would show as a bare +FileList+.
|
|
86
|
+
#
|
|
87
|
+
# @param arguments [Hash] raw tool-call arguments
|
|
88
|
+
# @return [String]
|
|
89
|
+
def describe_call(arguments)
|
|
90
|
+
Pikuri::Tool.one_line((arguments['path'] || arguments[:path] || '.').to_s)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Resolve +path+, refuse a file / missing / oversized root, render.
|
|
94
|
+
#
|
|
95
|
+
# @param workspace [Workspace]
|
|
96
|
+
# @param path [String, nil] raw path from the LLM; +nil+ means the
|
|
97
|
+
# workspace root
|
|
98
|
+
# @param depth [Integer] levels to descend
|
|
99
|
+
# @return [Tool::Result] the listing (+"Listed 31 entries"+), or
|
|
100
|
+
# {Pikuri::Tool::Result.error}
|
|
101
|
+
def self.list(workspace:, path:, depth:)
|
|
102
|
+
return Tool::Result.error("depth must be >= 1, got #{depth}") if depth < 1
|
|
103
|
+
|
|
104
|
+
resolved = path ? workspace.resolve_for_read(path) : workspace.project_root
|
|
105
|
+
return Tool::Result.error("path not found: #{path}") unless resolved.exist?
|
|
106
|
+
return Tool::Result.error("#{path} is a file, not a directory; use the read tool to view it.") if resolved.file?
|
|
107
|
+
|
|
108
|
+
if (refusal = Search::Utils.oversized_root_refusal(resolved, filesystem: workspace.filesystem,
|
|
109
|
+
verb: 'list'))
|
|
110
|
+
return Tool::Result.error(refusal)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
listing, entries = Listing.render_with_count(resolved, filesystem: workspace.filesystem, depth: depth)
|
|
114
|
+
return Tool::Result.new(content: '(Empty directory)', summary: 'Listed 0 entries') if listing.empty?
|
|
115
|
+
|
|
116
|
+
Tool::Result.new(content: listing,
|
|
117
|
+
summary: "Listed #{Pikuri::Tool.pluralize(entries, 'entry', 'entries')}")
|
|
118
|
+
rescue Filesystem::Error => e
|
|
119
|
+
Tool::Result.error(e.message)
|
|
120
|
+
rescue SystemCallError => e
|
|
121
|
+
Tool::Result.error("cannot list #{path || '.'}: #{e.message}")
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|