scout-ai 2.0.0 → 2.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.
Files changed (185) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +135 -55
  3. data/README.md +2 -1
  4. data/VERSION +1 -1
  5. data/doc/Improvements.md +490 -148
  6. data/doc/Model.md +53 -10
  7. data/doc/StartHere.md +44 -19
  8. data/doc/developer/Architecture.md +25 -6
  9. data/doc/developer/Backends.md +207 -48
  10. data/doc/developer/ChatLifecycle.md +121 -20
  11. data/doc/developer/DelegationInternals.md +320 -34
  12. data/doc/developer/DesignPrinciples.md +205 -16
  13. data/doc/developer/PathEngine.md +628 -0
  14. data/doc/developer/PromptProcessing.md +332 -82
  15. data/doc/developer/Provenance.md +402 -44
  16. data/doc/developer/Sandbox.md +213 -0
  17. data/doc/user/BuildingAgents.md +130 -18
  18. data/doc/user/Cookbook.md +29 -8
  19. data/doc/user/CoreConcepts.md +7 -6
  20. data/doc/user/Delegation.md +166 -15
  21. data/doc/user/GettingStarted.md +20 -16
  22. data/doc/user/ManagingContext.md +155 -17
  23. data/doc/user/MultiAgentWorkflows.md +105 -15
  24. data/doc/user/Python.md +11 -1
  25. data/doc/user/RunningInference.md +90 -47
  26. data/doc/user/ToolCalling.md +134 -29
  27. data/doc/user/WritingChats.md +56 -27
  28. data/lib/scout/llm/agent/attach.rb +64 -0
  29. data/lib/scout/llm/agent/chat.rb +32 -0
  30. data/lib/scout/llm/agent/construction.rb +64 -0
  31. data/lib/scout/llm/agent/conversation.rb +304 -0
  32. data/lib/scout/llm/agent/delegate.rb +56 -238
  33. data/lib/scout/llm/agent/path/edit.rb +230 -0
  34. data/lib/scout/llm/agent/path/patch.rb +252 -0
  35. data/lib/scout/llm/agent/path/workflow_kinds.rb +175 -0
  36. data/lib/scout/llm/agent/path.rb +1777 -0
  37. data/lib/scout/llm/agent/save.rb +11 -9
  38. data/lib/scout/llm/agent/workflow.rb +79 -17
  39. data/lib/scout/llm/agent.rb +151 -27
  40. data/lib/scout/llm/ask.rb +37 -27
  41. data/lib/scout/llm/backends/anthropic.rb +1 -1
  42. data/lib/scout/llm/backends/bedrock.rb +3 -2
  43. data/lib/scout/llm/backends/default.rb +131 -32
  44. data/lib/scout/llm/backends/glm.rb +28 -1
  45. data/lib/scout/llm/backends/huggingface.rb +1 -1
  46. data/lib/scout/llm/backends/ollama.rb +1 -1
  47. data/lib/scout/llm/backends/openai.rb +7 -6
  48. data/lib/scout/llm/backends/openwebui.rb +14 -7
  49. data/lib/scout/llm/backends/relay.rb +8 -2
  50. data/lib/scout/llm/chat/agent_meta.rb +24 -60
  51. data/lib/scout/llm/chat/parse.rb +1 -1
  52. data/lib/scout/llm/chat/process/files.rb +10 -0
  53. data/lib/scout/llm/chat/process/meta.rb +5 -7
  54. data/lib/scout/llm/chat/process/tools.rb +104 -52
  55. data/lib/scout/llm/chat/prompt/epoch_tool_compactation.rb +355 -0
  56. data/lib/scout/llm/chat/prompt/inbox.rb +188 -0
  57. data/lib/scout/llm/chat/prompt/shorten_tools.rb +797 -13
  58. data/lib/scout/llm/chat/prompt/shorten_tools_epoch.rb +1 -365
  59. data/lib/scout/llm/chat/prompt/shorten_tools_epoch_increment.rb +1 -0
  60. data/lib/scout/llm/chat/prompt.rb +24 -10
  61. data/lib/scout/llm/chat/provenance/live.rb +1080 -0
  62. data/lib/scout/llm/chat/provenance/tokens.rb +386 -0
  63. data/lib/scout/llm/chat/provenance.rb +352 -626
  64. data/lib/scout/llm/chat.rb +8 -2
  65. data/lib/scout/llm/embed.rb +15 -3
  66. data/lib/scout/llm/image.rb +4 -1
  67. data/lib/scout/llm/mcp.rb +4 -2
  68. data/lib/scout/llm/request_context.rb +234 -0
  69. data/lib/scout/llm/sandbox.rb +263 -0
  70. data/lib/scout/llm/tools/call.rb +163 -42
  71. data/lib/scout/llm/tools/definition.rb +48 -0
  72. data/lib/scout/llm/tools/knowledge_base.rb +1 -0
  73. data/lib/scout/llm/tools/mcp.rb +50 -43
  74. data/lib/scout/llm/tools/workflow.rb +90 -20
  75. data/lib/scout/llm/tools.rb +14 -41
  76. data/lib/scout/model/decision/base.rb +43 -0
  77. data/lib/scout/model/decision/jev.rb +161 -0
  78. data/lib/scout/model/python/torch.rb +1 -1
  79. data/research/clear-tools-inherit.md +171 -0
  80. data/research/path-engine-dc1-dc2-dc3-fixes.md +279 -0
  81. data/research/path-kind-chat-role.md +96 -0
  82. data/research/path-kind-contract-fixes-engine.md +307 -0
  83. data/research/scout-ai-runtime-availability.md +65 -0
  84. data/research/subsys/README.md +127 -0
  85. data/research/subsys/agent-delegation.md +201 -0
  86. data/research/subsys/agent-society.md +275 -0
  87. data/research/subsys/agentworkflow.md +233 -0
  88. data/research/subsys/backends.md +221 -0
  89. data/research/subsys/chat.md +314 -0
  90. data/research/subsys/embed-image.md +244 -0
  91. data/research/subsys/entry-cli.md +253 -0
  92. data/research/subsys/model-ml.md +326 -0
  93. data/research/subsys/provenance.md +290 -0
  94. data/research/subsys/tools.md +334 -0
  95. data/scout-ai.gemspec +72 -26
  96. data/scout_commands/agent/ask +8 -7
  97. data/scout_commands/llm/abridged +40 -0
  98. data/scout_commands/llm/ask +9 -9
  99. data/scout_commands/llm/md +2 -0
  100. data/scout_commands/llm/prov +845 -80
  101. data/scout_commands/llm/word +4 -0
  102. data/share/word/reference.docx +0 -0
  103. data/test/integration/scout/model/decision/test_jev.rb +144 -0
  104. data/test/scout/llm/agent/test_attach.rb +117 -0
  105. data/test/scout/llm/agent/test_conversation.rb +407 -0
  106. data/test/scout/llm/agent/test_delegate.rb +209 -0
  107. data/test/scout/llm/agent/test_path.rb +1812 -0
  108. data/test/scout/llm/agent/test_path_edit.rb +908 -0
  109. data/test/scout/llm/agent/test_path_errors.rb +390 -0
  110. data/test/scout/llm/agent/test_path_filesystem.rb +532 -0
  111. data/test/scout/llm/agent/test_path_patch.rb +233 -0
  112. data/test/scout/llm/agent/test_path_promotion.rb +386 -0
  113. data/test/scout/llm/agent/test_path_workflow_integration.rb +665 -0
  114. data/test/scout/llm/agent/test_save.rb +70 -15
  115. data/test/scout/llm/agent/test_workflow.rb +130 -4
  116. data/test/scout/llm/backends/test_anthropic.rb +4 -4
  117. data/test/scout/llm/backends/test_bedrock.rb +4 -4
  118. data/test/scout/llm/backends/test_format_other.rb +43 -0
  119. data/test/scout/llm/backends/test_ollama.rb +2 -2
  120. data/test/scout/llm/backends/test_openwebui.rb +12 -8
  121. data/test/scout/llm/backends/test_reasoning.rb +114 -0
  122. data/test/scout/llm/chat/agent_meta_fixtures.rb +109 -22
  123. data/test/scout/llm/chat/prompt/test_epoch_tool_compactation.rb +612 -0
  124. data/test/scout/llm/chat/prov_plot_fixtures.rb +131 -0
  125. data/test/scout/llm/chat/test_agent_meta.rb +40 -80
  126. data/test/scout/llm/chat/test_agent_meta_provenance.rb +200 -28
  127. data/test/scout/llm/chat/test_agent_meta_tokens.rb +112 -7
  128. data/test/scout/llm/chat/test_agent_view.rb +178 -0
  129. data/test/scout/llm/chat/test_live_report.rb +282 -0
  130. data/test/scout/llm/chat/test_live_workload.rb +193 -0
  131. data/test/scout/llm/chat/test_parse.rb +32 -2
  132. data/test/scout/llm/chat/test_prompt.rb +411 -0
  133. data/test/scout/llm/chat/test_prov_cli.rb +708 -13
  134. data/test/scout/llm/chat/test_prov_cli_live.rb +152 -0
  135. data/test/scout/llm/chat/test_prov_plot.rb +213 -0
  136. data/test/scout/llm/chat/test_prov_timeline.rb +355 -0
  137. data/test/scout/llm/chat/test_provenance.rb +67 -22
  138. data/test/scout/llm/chat/test_provenance_index.rb +479 -0
  139. data/test/scout/llm/chat/test_society_view.rb +159 -0
  140. data/test/scout/llm/test_agent.rb +1 -1
  141. data/test/scout/llm/test_embed.rb +103 -1
  142. data/test/scout/llm/test_request_context.rb +299 -0
  143. data/test/scout/llm/test_sandbox.rb +249 -0
  144. data/test/scout/llm/tools/test_agent_pairing.rb +150 -0
  145. data/test/scout/llm/tools/test_call_delegation_conflict.rb +316 -0
  146. data/test/scout/llm/tools/test_definition.rb +332 -0
  147. data/test/scout/llm/tools/test_jobs_file.rb +211 -0
  148. data/test/scout/llm/tools/test_mcp.rb +37 -8
  149. data/test/scout/llm/tools/test_workflow.rb +45 -1
  150. data/test/scout/model/decision/test_jev.rb +453 -0
  151. data/test/scout/model/python/huggingface/causal/test_next_token.rb +7 -10
  152. data/test/scout/model/python/huggingface/test_causal.rb +11 -2
  153. data/test/scout/model/python/huggingface/test_classification.rb +5 -3
  154. data/test/scout/model/python/test_availability.rb +116 -0
  155. data/test/scout/model/python/test_torch.rb +54 -2
  156. data/test/support/availability.rb +72 -174
  157. data/test/support/fake_clients.rb +18 -9
  158. data/test/support/fixtures.rb +75 -6
  159. data/test/support/mock_backend.rb +9 -1
  160. data/test/support/test_fixtures.rb +156 -0
  161. data/test/test_helper.rb +14 -4
  162. metadata +71 -25
  163. data/research/ChatAnalyst-required-changes.md +0 -167
  164. data/research/agent-delegation-analysis.md +0 -810
  165. data/research/agent-meta-provenance-integration-plan.md +0 -622
  166. data/research/agent-workflow-analysis.md +0 -1120
  167. data/research/backends-analysis.md +0 -836
  168. data/research/chat-core-analysis.md +0 -946
  169. data/research/chatanalyst-provenance/00-baseline.md +0 -30
  170. data/research/chatanalyst-provenance/01-repo-map.md +0 -60
  171. data/research/chatanalyst-provenance/02-event-reconstruction.md +0 -55
  172. data/research/chatanalyst-provenance/03-duplication-evidence.md +0 -45
  173. data/research/chatanalyst-provenance/04-tooling-root-cause.md +0 -57
  174. data/research/chatanalyst-provenance/05-fix-plan.md +0 -46
  175. data/research/chatanalyst-provenance/07-critic-review.md +0 -25
  176. data/research/chatanalyst-provenance/final-report.md +0 -45
  177. data/research/chatanalyst-provenance/resumption.md +0 -37
  178. data/research/coding-philosophy-analysis.md +0 -928
  179. data/research/commands-analysis.md +0 -947
  180. data/research/multi-agent-patterns-analysis.md +0 -853
  181. data/research/prompt-strategies-analysis.md +0 -630
  182. data/research/prov-verbosity-fix-notes.md +0 -77
  183. data/research/provenance-analysis.md +0 -469
  184. data/research/synthesis-report.md +0 -487
  185. data/research/tools-system-analysis.md +0 -779
@@ -0,0 +1,532 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/lib/scout/llm/agent/path.rb')
3
+
4
+ require "tmpdir"
5
+
6
+ class TestPathFilesystem < Test::Unit::TestCase
7
+ def setup
8
+ @tmpdir = Scout.tmp.agent_path_test.find
9
+ FileUtils.mkdir_p(@tmpdir)
10
+ @agent = LLM.agent
11
+ end
12
+
13
+ def teardown
14
+ FileUtils.remove_entry(@tmpdir) if @tmpdir && File.exist?(@tmpdir)
15
+ end
16
+
17
+ def register_text_kind(name = "text", capabilities = {})
18
+ @agent.register_path_kind(
19
+ name,
20
+ "description" => "Test text paths",
21
+ "locations" => ["project", "tmp"],
22
+ "default_location" => "project",
23
+ "roots" => {
24
+ "project" => @tmpdir,
25
+ "tmp" => File.join(@tmpdir, "tmp")
26
+ },
27
+ "capabilities" => capabilities
28
+ )
29
+ end
30
+
31
+ def test_sandbox_defaults_on_and_can_be_disabled
32
+ assert_equal true, register_text_kind["sandbox"]
33
+ assert_equal false, @agent.register_path_kind(
34
+ "unsandboxed", "sandbox" => false, "locations" => ["project"],
35
+ "roots" => {"project" => @tmpdir}
36
+ )["sandbox"]
37
+ end
38
+
39
+ def test_sandbox_denies_custom_operation_before_callback
40
+ called = false
41
+ outside = Dir.mktmpdir("path-outside")
42
+ @agent.register_path_kind(
43
+ "custom", "locations" => ["tmp"], "default_location" => "tmp",
44
+ "roots" => {"tmp" => @tmpdir}, "capabilities" => {"validate" => true},
45
+ "resolve" => ->(_agent, _path, _location) { outside },
46
+ "validate" => ->(*) { called = true }
47
+ )
48
+
49
+ assert_raise(ParameterException) do
50
+ @agent.path_validate("kind" => "custom", "path" => "item")
51
+ end
52
+ assert_false called
53
+ ensure
54
+ FileUtils.remove_entry(outside) if outside && File.exist?(outside)
55
+ end
56
+
57
+ def test_sandbox_disabled_skips_authorization
58
+ @agent.register_path_kind(
59
+ "custom", "sandbox" => false, "locations" => ["tmp"],
60
+ "default_location" => "tmp", "roots" => {"tmp" => @tmpdir},
61
+ "resolve" => ->(_agent, _path, _location) { File.join(@tmpdir, "item") }
62
+ )
63
+ assert_equal true, @agent.path_write("kind" => "custom", "path" => "item",
64
+ "content" => "ok")["written"]
65
+ end
66
+
67
+ def test_sandbox_fails_closed_when_authorizer_is_unavailable
68
+ register_text_kind
69
+ sandbox = LLM::Sandbox
70
+ original = sandbox.method(:authorize_path)
71
+ sandbox.define_singleton_method(:authorize_path) { |*| raise NoMethodError, "unavailable" }
72
+
73
+ assert_raise(ParameterException) do
74
+ @agent.path_read("kind" => "text", "path" => "item")
75
+ end
76
+ ensure
77
+ sandbox.define_singleton_method(:authorize_path, original) if sandbox && original
78
+ end
79
+
80
+ def test_move_authorizes_source_and_missing_destination
81
+ register_text_kind
82
+ calls = []
83
+ sandbox = LLM::Sandbox
84
+ original = sandbox.method(:authorize_path)
85
+ sandbox.define_singleton_method(:authorize_path) do |path, **options|
86
+ calls << [path, options[:mode]]
87
+ original.call(path, **options)
88
+ end
89
+ @agent.path_write("kind" => "text", "path" => "source", "content" => "x")
90
+ calls.clear
91
+
92
+ @agent.path_move("kind" => "text", "path" => "source", "destination" => "new/target")
93
+
94
+ assert_equal [[File.join(@tmpdir, "source"), :write],
95
+ [File.join(@tmpdir, "new/target"), :write]], calls
96
+ assert File.file?(File.join(@tmpdir, "new/target"))
97
+ ensure
98
+ sandbox.define_singleton_method(:authorize_path, original) if sandbox && original
99
+ end
100
+
101
+ def test_move_denies_symlinked_destination_outside_root
102
+ register_text_kind
103
+ outside = Dir.mktmpdir("path-outside")
104
+ FileUtils.mkdir_p(@tmpdir.to_s)
105
+ File.symlink(outside, File.join(@tmpdir, "escape"))
106
+ @agent.path_write("kind" => "text", "path" => "source", "content" => "x")
107
+
108
+ assert_raise(ParameterException) do
109
+ @agent.path_move("kind" => "text", "path" => "source", "destination" => "escape/new")
110
+ end
111
+ assert File.file?(File.join(@tmpdir, "source"))
112
+ ensure
113
+ FileUtils.remove_entry(outside) if outside && File.exist?(outside)
114
+ end
115
+
116
+ def test_path_doc_id
117
+ assert_equal "view::show.slim", @agent.path_doc_id("view", "show.slim")
118
+ assert_equal "view::show.slim@3", @agent.path_doc_id("view", "show.slim", 3)
119
+ end
120
+
121
+ def test_resolve_path
122
+ register_text_kind
123
+
124
+ target = @agent.resolve_path("text", "hello.txt")
125
+
126
+ assert_equal File.join(@tmpdir, "hello.txt"), target
127
+ end
128
+
129
+ def test_resolve_path_with_location
130
+ register_text_kind
131
+
132
+ target = @agent.resolve_path("text", "hello.txt", "tmp")
133
+
134
+ assert_equal File.join(@tmpdir, "tmp", "hello.txt"), target
135
+ end
136
+
137
+ def test_resolve_path_rejects_invalid_location
138
+ register_text_kind
139
+
140
+ assert_raise(ParameterException) do
141
+ @agent.resolve_path("text", "hello.txt", "missing")
142
+ end
143
+ end
144
+
145
+ def test_path_write_and_read
146
+ register_text_kind
147
+
148
+ result = @agent.path_write(
149
+ "kind" => "text",
150
+ "path" => "hello.txt",
151
+ "content" => "hello world"
152
+ )
153
+
154
+ assert_equal true, result["written"]
155
+ assert_equal "text::hello.txt", result["doc_id"]
156
+
157
+ assert_equal(
158
+ "hello world",
159
+ @agent.path_read(
160
+ "kind" => "text",
161
+ "path" => "hello.txt"
162
+ )["content"]
163
+ )
164
+ end
165
+
166
+ def test_absolute_path_write_and_read_use_exact_target
167
+ register_text_kind
168
+ target = File.join(@tmpdir, "absolute/location.txt")
169
+
170
+ result = @agent.path_write(
171
+ "kind" => "text",
172
+ "path" => target,
173
+ "content" => "at the exact absolute target"
174
+ )
175
+
176
+ assert_equal true, result["written"]
177
+ assert File.file?(target)
178
+ assert_equal "at the exact absolute target", File.read(target)
179
+ assert_equal "at the exact absolute target",
180
+ @agent.path_read("kind" => "text", "path" => target)["content"]
181
+ assert_false File.exist?(File.join(@tmpdir, target))
182
+ end
183
+
184
+ def test_absolute_path_outside_configured_root_is_denied_without_side_effect
185
+ register_text_kind
186
+ outside = Dir.mktmpdir("path-outside")
187
+ target = File.join(outside, "must-not-exist.txt")
188
+
189
+ error = assert_raise(ParameterException) do
190
+ @agent.path_write("kind" => "text", "path" => target, "content" => "denied")
191
+ end
192
+
193
+ assert_equal "Path access denied by sandbox (outside_grants)", error.message
194
+ assert_false File.exist?(target)
195
+ ensure
196
+ FileUtils.remove_entry(outside) if outside && File.exist?(outside)
197
+ end
198
+
199
+ def test_absolute_path_list_and_move_use_exact_endpoints
200
+ register_text_kind
201
+ subdir = File.join(@tmpdir, "listed")
202
+ FileUtils.mkdir_p(subdir)
203
+ source = File.join(subdir, "absolute-source.txt")
204
+ destination = File.join(subdir, "absolute-destination.txt")
205
+ @agent.path_write("kind" => "text", "path" => source, "content" => "move me")
206
+
207
+ assert_equal ["listed/absolute-source.txt"],
208
+ @agent.path_list("kind" => "text", "path" => subdir)
209
+ @agent.path_write("kind" => "text", "path" => File.join(@tmpdir, "sibling.txt"),
210
+ "content" => "not in the requested directory")
211
+ result = @agent.path_move("kind" => "text", "path" => source,
212
+ "destination" => destination)
213
+
214
+ assert_equal true, result["moved"]
215
+ assert_false File.exist?(source)
216
+ assert_equal "move me", File.read(destination)
217
+
218
+ outside = Dir.mktmpdir("path-outside")
219
+ denied_destination = File.join(outside, "must-not-exist.txt")
220
+ @agent.path_write("kind" => "text", "path" => source, "content" => "stay put")
221
+ error = assert_raise(ParameterException) do
222
+ @agent.path_move("kind" => "text", "path" => source,
223
+ "destination" => denied_destination)
224
+ end
225
+ assert_equal "Path access denied by sandbox (outside_grants)", error.message
226
+ assert_equal "stay put", File.read(source)
227
+ assert_false File.exist?(denied_destination)
228
+ ensure
229
+ FileUtils.remove_entry(outside) if outside && File.exist?(outside)
230
+ end
231
+
232
+ def test_path_write_success_is_at_the_authorized_target
233
+ register_text_kind
234
+ target = File.join(@tmpdir, "actual/location.txt")
235
+
236
+ result = @agent.path_write(
237
+ "kind" => "text",
238
+ "path" => "actual/location.txt",
239
+ "content" => "written at the authorized target"
240
+ )
241
+
242
+ assert_equal true, result["written"]
243
+ assert File.file?(target)
244
+ assert_equal "written at the authorized target", File.read(target)
245
+ end
246
+
247
+ def test_path_write_denies_resolver_target_outside_root
248
+ outside = Dir.mktmpdir("path-outside")
249
+ outside_target = File.join(outside, "must-not-exist.txt")
250
+ @agent.register_path_kind(
251
+ "custom", "locations" => ["project"], "default_location" => "project",
252
+ "roots" => {"project" => @tmpdir},
253
+ "resolve" => ->(_agent, _path, _location) { outside_target }
254
+ )
255
+
256
+ error = assert_raise(ParameterException) do
257
+ @agent.path_write("kind" => "custom", "path" => "item", "content" => "denied")
258
+ end
259
+
260
+ assert_equal "Path access denied by sandbox (outside_grants)", error.message
261
+ assert_false File.exist?(outside_target)
262
+ ensure
263
+ FileUtils.remove_entry(outside) if outside && File.exist?(outside)
264
+ end
265
+
266
+ def test_path_write_creates_parent_directories
267
+ register_text_kind
268
+
269
+ @agent.path_write(
270
+ "kind" => "text",
271
+ "path" => "nested/hello.txt",
272
+ "content" => "hello"
273
+ )
274
+
275
+ assert File.file?(File.join(@tmpdir, "nested/hello.txt"))
276
+ end
277
+
278
+ def test_path_write_filesystem_failure_does_not_return_success
279
+ register_text_kind
280
+ # The authorized target exists as a directory, so the filesystem rejects
281
+ # File.write. This exercises the real write failure path without stubbing.
282
+ # ("." no longer reaches File.write: the root-selector guard rejects it,
283
+ # so the directory target is spelled explicitly.)
284
+ FileUtils.mkdir_p(File.join(@tmpdir, "directory_target"))
285
+ assert_raise(Errno::EISDIR) do
286
+ @agent.path_write("kind" => "text", "path" => "directory_target", "content" => "cannot replace directory")
287
+ end
288
+ end
289
+
290
+ def test_path_write_respects_write_capability
291
+ register_text_kind("text", "write" => false)
292
+
293
+ assert_raise(ParameterException) do
294
+ @agent.path_write(
295
+ "kind" => "text",
296
+ "path" => "hello.txt",
297
+ "content" => "hello"
298
+ )
299
+ end
300
+ end
301
+
302
+ def test_path_read_rejects_missing_path
303
+ register_text_kind
304
+
305
+ assert_raise(ParameterException) do
306
+ @agent.path_read(
307
+ "kind" => "text",
308
+ "path" => "missing.txt"
309
+ )
310
+ end
311
+ end
312
+
313
+ def test_path_list
314
+ register_text_kind
315
+
316
+ @agent.path_write(
317
+ "kind" => "text",
318
+ "path" => "one.txt",
319
+ "content" => "one"
320
+ )
321
+ @agent.path_write(
322
+ "kind" => "text",
323
+ "path" => "nested/two.txt",
324
+ "content" => "two"
325
+ )
326
+
327
+ result = @agent.path_list("kind" => "text")
328
+
329
+ assert_equal ["nested/two.txt", "one.txt"], result
330
+ end
331
+
332
+ def test_path_list_with_prefix
333
+ register_text_kind
334
+
335
+ @agent.path_write(
336
+ "kind" => "text",
337
+ "path" => "nested/one.txt",
338
+ "content" => "one"
339
+ )
340
+ @agent.path_write(
341
+ "kind" => "text",
342
+ "path" => "nested/two.txt",
343
+ "content" => "two"
344
+ )
345
+ @agent.path_write(
346
+ "kind" => "text",
347
+ "path" => "other.txt",
348
+ "content" => "other"
349
+ )
350
+
351
+ result = @agent.path_list(
352
+ "kind" => "text",
353
+ "path" => "nested"
354
+ )
355
+
356
+ assert_equal ["nested/one.txt", "nested/two.txt"], result
357
+ end
358
+
359
+ # ------------------------------------------------------------------
360
+ # path_list subdirectory contract: `path` is OPTIONAL. Omitted, it lists
361
+ # the kind root exactly as before; a relative subdirectory lists that
362
+ # subtree, still expressed root-relative, and still resolved/authorized
363
+ # through the engine's normal resolve/authorize machinery (never a
364
+ # parallel mechanism).
365
+ # ------------------------------------------------------------------
366
+
367
+ def test_path_list_omitted_path_lists_kind_root
368
+ register_text_kind
369
+
370
+ @agent.path_write("kind" => "text", "path" => "top.txt", "content" => "top")
371
+ @agent.path_write("kind" => "text", "path" => "a/one.txt", "content" => "one")
372
+ @agent.path_write("kind" => "text", "path" => "a/b/two.txt", "content" => "two")
373
+
374
+ assert_equal ["a/b/two.txt", "a/one.txt", "top.txt"],
375
+ @agent.path_list("kind" => "text")
376
+ end
377
+
378
+ def test_path_list_relative_subdirectory_lists_only_that_subtree
379
+ register_text_kind
380
+
381
+ @agent.path_write("kind" => "text", "path" => "top.txt", "content" => "top")
382
+ @agent.path_write("kind" => "text", "path" => "a/one.txt", "content" => "one")
383
+ @agent.path_write("kind" => "text", "path" => "a/b/two.txt", "content" => "two")
384
+ @agent.path_write("kind" => "text", "path" => "other/three.txt", "content" => "three")
385
+
386
+ result = @agent.path_list("kind" => "text", "path" => "a")
387
+
388
+ assert_equal ["a/b/two.txt", "a/one.txt"], result
389
+ assert_not_equal @agent.path_list("kind" => "text"), result
390
+ assert_false result.include?("other/three.txt")
391
+ end
392
+
393
+ def test_path_list_nested_relative_path
394
+ register_text_kind
395
+
396
+ @agent.path_write("kind" => "text", "path" => "a/one.txt", "content" => "one")
397
+ @agent.path_write("kind" => "text", "path" => "a/b/two.txt", "content" => "two")
398
+ @agent.path_write("kind" => "text", "path" => "a/b/c/three.txt", "content" => "three")
399
+
400
+ assert_equal ["a/b/c/three.txt", "a/b/two.txt"],
401
+ @agent.path_list("kind" => "text", "path" => "a/b")
402
+ end
403
+
404
+ def test_path_list_rejects_traversal_outside_root
405
+ register_text_kind
406
+ # See the note in the symlink test: the class-level setup block wipes the
407
+ # shared tmpdir after instance setup, so the root is recreated here.
408
+ FileUtils.mkdir_p(@tmpdir)
409
+
410
+ error = assert_raise(ParameterException) do
411
+ @agent.path_list("kind" => "text", "path" => "../outside")
412
+ end
413
+ assert_equal "Path access denied by sandbox (outside_grants)", error.message
414
+ end
415
+
416
+ def test_path_list_rejects_absolute_path_outside_grants
417
+ register_text_kind
418
+ outside = Dir.mktmpdir("path-list-outside")
419
+
420
+ error = assert_raise(ParameterException) do
421
+ @agent.path_list("kind" => "text", "path" => File.join(outside, "sub"))
422
+ end
423
+ assert_equal "Path access denied by sandbox (outside_grants)", error.message
424
+ ensure
425
+ FileUtils.remove_entry(outside) if outside && File.exist?(outside)
426
+ end
427
+
428
+ def test_path_list_denies_symlinked_subdirectory_outside_grants
429
+ register_text_kind
430
+ # The class-level teardown (Open.rm_rf on the shared TestCase tmpdir) can
431
+ # wipe Scout.tmp.agent_path_test after setup in this suite's process, so
432
+ # the root is (re)created defensively inside the test.
433
+ FileUtils.mkdir_p(@tmpdir)
434
+ outside = Dir.mktmpdir("path-list-symlink")
435
+ File.symlink(outside, File.join(@tmpdir, "link"))
436
+
437
+ error = assert_raise(ParameterException) do
438
+ @agent.path_list("kind" => "text", "path" => "link")
439
+ end
440
+ assert_equal "Path access denied by sandbox (outside_grants)", error.message
441
+ ensure
442
+ FileUtils.remove_entry(outside) if outside && File.exist?(outside)
443
+ end
444
+
445
+ def test_path_list_non_directory_target_returns_empty_listing
446
+ # Established engine behavior, kept as-is (no new error class): a file or
447
+ # missing prefix has no descendants, so the listing is empty, while the
448
+ # target was still resolved and authorized like any other list target.
449
+ register_text_kind
450
+
451
+ @agent.path_write("kind" => "text", "path" => "plain.txt", "content" => "p")
452
+ @agent.path_write("kind" => "text", "path" => "a/one.txt", "content" => "one")
453
+
454
+ assert_equal [], @agent.path_list("kind" => "text", "path" => "plain.txt")
455
+ assert_equal [], @agent.path_list("kind" => "text", "path" => "missing_dir")
456
+ end
457
+
458
+ def test_path_list_tool_callable_without_path_lists_root
459
+ register_text_kind
460
+
461
+ @agent.path_write("kind" => "text", "path" => "one.txt", "content" => "one")
462
+
463
+ tools = @agent.instance_variable_get(:@other_options)[:tools]
464
+ result = tools["path_list"].first.call("path_list", {"kind" => "text"})
465
+
466
+ assert_equal ["one.txt"], result
467
+ end
468
+
469
+ def test_path_move
470
+ register_text_kind
471
+
472
+ @agent.path_write(
473
+ "kind" => "text",
474
+ "path" => "one.txt",
475
+ "content" => "hello"
476
+ )
477
+
478
+ result = @agent.path_move(
479
+ "kind" => "text",
480
+ "path" => "one.txt",
481
+ "destination" => "two.txt"
482
+ )
483
+
484
+ assert_equal true, result["moved"]
485
+ assert !File.exist?(File.join(@tmpdir, "one.txt"))
486
+ assert_equal "hello", File.read(File.join(@tmpdir, "two.txt"))
487
+ end
488
+
489
+ def test_path_rename
490
+ register_text_kind
491
+
492
+ @agent.path_write(
493
+ "kind" => "text",
494
+ "path" => "one.txt",
495
+ "content" => "hello"
496
+ )
497
+
498
+ result = @agent.path_rename(
499
+ "kind" => "text",
500
+ "path" => "one.txt",
501
+ "name" => "two.txt"
502
+ )
503
+
504
+ assert_equal true, result["renamed"]
505
+ assert !File.exist?(File.join(@tmpdir, "one.txt"))
506
+ assert_equal "hello", File.read(File.join(@tmpdir, "two.txt"))
507
+ end
508
+
509
+ def test_path_delete
510
+ register_text_kind
511
+
512
+ @agent.path_write(
513
+ "kind" => "text",
514
+ "path" => "hello.txt",
515
+ "content" => "hello"
516
+ )
517
+
518
+ result = @agent.path_delete(
519
+ "kind" => "text",
520
+ "path" => "hello.txt"
521
+ )
522
+
523
+ assert_equal true, result["deleted"]
524
+ assert !File.exist?(File.join(@tmpdir, "hello.txt"))
525
+ end
526
+
527
+ # Review point 4 (Phase 0 fixes): deleting a nonexistent target is invalid
528
+ # input and must surface as ParameterException using the engine's uniform
529
+ # "does not exist" contract, not as a raw Errno::ENOENT escaping the tool
530
+ # callable's ScoutException-only rescue.
531
+
532
+ end