samagotchi 0.172.0 → 0.173.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/CHANGELOG.md +44 -1
- data/docs/architecture.md +16 -5
- data/docs/cli.md +2 -1
- data/docs/configuration.md +1 -1
- data/docs/internals/background-tasks.md +20 -7
- data/docs/internals/bridge.md +2 -2
- data/docs/internals/engine.md +2 -1
- data/docs/internals/participants.md +67 -9
- data/docs/internals/remote-sessions.md +1 -1
- data/docs/internals/web-frontend.md +44 -15
- data/docs/plugins.md +3 -1
- data/docs/sessions.md +2 -2
- data/docs/testing.md +43 -3
- data/lib/samagotchi/bridge.rb +3 -2
- data/lib/samagotchi/bundle_command/try/sandbox.rb +2 -2
- data/lib/samagotchi/bundles/core/manifest.yml +2 -2
- data/lib/samagotchi/bundles/slow-commands/manifest.yml +3 -3
- data/lib/samagotchi/bundles/slow-commands/plugin.rb +3 -3
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/engine/participants.rb +2 -2
- data/lib/samagotchi/engine.rb +0 -1
- data/lib/samagotchi/file_ref.rb +3 -5
- data/lib/samagotchi/guardrails/participant_refusal.rb +1 -1
- data/lib/samagotchi/memory_usage.rb +2 -1
- data/lib/samagotchi/message_parts.rb +5 -3
- data/lib/samagotchi/objectives_backing.rb +6 -10
- data/lib/samagotchi/parent_report.rb +1 -1
- data/lib/samagotchi/participant_prompts.rb +101 -0
- data/lib/samagotchi/participant_turn_mode.rb +1 -1
- data/lib/samagotchi/project_env.rb +7 -5
- data/lib/samagotchi/prompt_history.rb +2 -2
- data/lib/samagotchi/send_command/parent_gate.rb +2 -2
- data/lib/samagotchi/send_command.rb +4 -4
- data/lib/samagotchi/session_command_catalog.rb +210 -0
- data/lib/samagotchi/session_commands.rb +12 -183
- data/lib/samagotchi/session_manager/lifecycle.rb +5 -4
- data/lib/samagotchi/session_manager.rb +2 -1
- data/lib/samagotchi/session_stores.rb +2 -0
- data/lib/samagotchi/spawn_env.rb +75 -0
- data/lib/samagotchi/task_files.rb +51 -0
- data/lib/samagotchi/task_transcript.rb +67 -0
- data/lib/samagotchi/task_watch.rb +8 -6
- data/lib/samagotchi/terminal_ui/attached_loop/composer.rb +3 -3
- data/lib/samagotchi/terminal_ui/attached_loop/questions.rb +2 -2
- data/lib/samagotchi/terminal_ui/attached_loop.rb +3 -3
- data/lib/samagotchi/terminal_ui/input_support.rb +1 -1
- data/lib/samagotchi/testing/boundary.rb +5 -0
- data/lib/samagotchi/tool_activity.rb +63 -79
- data/lib/samagotchi/tool_names.rb +179 -0
- data/lib/samagotchi/tool_view.rb +3 -5
- data/lib/samagotchi/tools/ask_user_question.rb +2 -1
- data/lib/samagotchi/tools/builtins.rb +1 -1
- data/lib/samagotchi/tools/cancel_reminder.rb +2 -1
- data/lib/samagotchi/tools/cancel_schedule.rb +3 -1
- data/lib/samagotchi/tools/context_read.rb +2 -1
- data/lib/samagotchi/tools/delegate.rb +2 -1
- data/lib/samagotchi/tools/delegate_result.rb +2 -1
- data/lib/samagotchi/tools/edit.rb +2 -1
- data/lib/samagotchi/tools/execute.rb +22 -28
- data/lib/samagotchi/tools/forget_outputs.rb +2 -1
- data/lib/samagotchi/tools/leftovers.rb +8 -4
- data/lib/samagotchi/tools/list_reminders.rb +2 -1
- data/lib/samagotchi/tools/list_schedules.rb +3 -1
- data/lib/samagotchi/tools/list_sessions.rb +2 -1
- data/lib/samagotchi/tools/memory.rb +3 -2
- data/lib/samagotchi/tools/objectives_tool.rb +5 -4
- data/lib/samagotchi/tools/read.rb +2 -1
- data/lib/samagotchi/tools/register_reminder.rb +2 -1
- data/lib/samagotchi/tools/schedule_task.rb +3 -1
- data/lib/samagotchi/tools/send_note.rb +2 -1
- data/lib/samagotchi/tools/task_create.rb +2 -1
- data/lib/samagotchi/tools/task_get.rb +2 -1
- data/lib/samagotchi/tools/task_list.rb +2 -1
- data/lib/samagotchi/tools/task_runtime.rb +34 -154
- data/lib/samagotchi/tools/task_stop.rb +2 -1
- data/lib/samagotchi/tools/task_wait.rb +3 -2
- data/lib/samagotchi/tools/web_fetch.rb +2 -1
- data/lib/samagotchi/tools/write.rb +2 -1
- data/lib/samagotchi/turn_checkpoint.rb +1 -1
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +38 -36
- data/lib/samagotchi/web/message_display.rb +1 -7
- data/lib/samagotchi/web/participant_access.rb +12 -4
- data/lib/samagotchi/web/participant_history.rb +68 -0
- data/lib/samagotchi/web/participant_images.rb +2 -1
- data/lib/samagotchi/web/participant_show.rb +5 -5
- data/lib/samagotchi/web/participants_admin.rb +1 -1
- data/lib/samagotchi/web/public/app.js +13 -10
- data/lib/samagotchi/web/public/card_kinds.js +51 -0
- data/lib/samagotchi/web/public/card_registry.js +248 -0
- data/lib/samagotchi/web/public/cards_offscreen.js +3 -3
- data/lib/samagotchi/web/public/cards_place.js +21 -4
- data/lib/samagotchi/web/public/history_shape.js +1 -2
- data/lib/samagotchi/web/public/participant_history.js +27 -0
- data/lib/samagotchi/web/public/question_cards.js +16 -15
- data/lib/samagotchi/web/public/reload_check.js +90 -72
- data/lib/samagotchi/web/public/session_sync.js +4 -2
- data/lib/samagotchi/web/public/session_view.js +6 -1
- data/lib/samagotchi/web/public/stage_asking.js +18 -13
- data/lib/samagotchi/web/public/stage_place.js +144 -0
- data/lib/samagotchi/web/public/stage_probe.js +64 -0
- data/lib/samagotchi/web/public/stage_view.js +52 -104
- data/lib/samagotchi/web/public/stage_waiting.js +28 -17
- data/lib/samagotchi/web/public/task_stop.js +1 -1
- data/lib/samagotchi/web/push_routes.rb +1 -1
- data/lib/samagotchi/web/reload_check_route.rb +5 -2
- data/lib/samagotchi/web/request_body.rb +72 -0
- data/lib/samagotchi/web/server.rb +70 -0
- data/lib/samagotchi/web/session_access_routes.rb +13 -11
- data/lib/samagotchi/web/session_control.rb +21 -15
- data/lib/samagotchi/web/session_create.rb +2 -1
- data/lib/samagotchi/web/session_show.rb +8 -8
- data/lib/samagotchi/web/viewer.rb +7 -2
- data/lib/samagotchi/web/working_set_routes.rb +3 -3
- data/lib/samagotchi/worker.rb +49 -182
- data/lib/samagotchi/worker_exit_claim.rb +102 -0
- data/lib/samagotchi/worker_participant_gate.rb +156 -0
- data/lib/samagotchi/worker_task_wakes.rb +2 -2
- metadata +16 -1
|
@@ -4,25 +4,9 @@ require "json"
|
|
|
4
4
|
require_relative "log"
|
|
5
5
|
require_relative "command_steps"
|
|
6
6
|
require_relative "tool_view"
|
|
7
|
-
require_relative "
|
|
7
|
+
require_relative "tool_names"
|
|
8
8
|
require_relative "tools/registry"
|
|
9
|
-
require_relative "
|
|
10
|
-
require_relative "tools/write"
|
|
11
|
-
require_relative "tools/memory"
|
|
12
|
-
require_relative "tools/edit"
|
|
13
|
-
require_relative "tools/task_create"
|
|
14
|
-
require_relative "tools/task_get"
|
|
15
|
-
require_relative "tools/task_list"
|
|
16
|
-
require_relative "tools/task_runtime"
|
|
17
|
-
require_relative "tools/task_stop"
|
|
18
|
-
require_relative "tools/task_wait"
|
|
19
|
-
require_relative "tools/web_fetch"
|
|
20
|
-
require_relative "tools/ask_user_question"
|
|
21
|
-
require_relative "tools/list_sessions"
|
|
22
|
-
require_relative "tools/send_note"
|
|
23
|
-
require_relative "tools/context_read"
|
|
24
|
-
require_relative "tools/delegate"
|
|
25
|
-
require_relative "tools/delegate_result"
|
|
9
|
+
require_relative "task_files"
|
|
26
10
|
require_relative "tools/forget_outputs"
|
|
27
11
|
require_relative "tools/objectives_tool"
|
|
28
12
|
|
|
@@ -68,7 +52,7 @@ module Samagotchi
|
|
|
68
52
|
}
|
|
69
53
|
# A grep that found nothing: ok, and the web row says "no match".
|
|
70
54
|
# Not a hand-over: an "exit: 1" in its output tail is the command's.
|
|
71
|
-
if event[:status] == "ok" && tool_name ==
|
|
55
|
+
if event[:status] == "ok" && tool_name == ToolNames::Execute::NAME && !handed_over?(tool_name, result) &&
|
|
72
56
|
execute_failed?(result.to_s)
|
|
73
57
|
event[:no_match] = true
|
|
74
58
|
end
|
|
@@ -87,7 +71,7 @@ module Samagotchi
|
|
|
87
71
|
event
|
|
88
72
|
end
|
|
89
73
|
|
|
90
|
-
def objectives_proposal?(call) = call[:action].to_s.strip.downcase ==
|
|
74
|
+
def objectives_proposal?(call) = call[:action].to_s.strip.downcase == ToolNames::ObjectivesTool::PROPOSE
|
|
91
75
|
|
|
92
76
|
# A move's state=, before note= so a cut can't drop it: the page reads it from
|
|
93
77
|
# the params (the title stays as an older page reads it). None for a
|
|
@@ -96,12 +80,12 @@ module Samagotchi
|
|
|
96
80
|
return [] if objectives_proposal?(call)
|
|
97
81
|
|
|
98
82
|
state = Tools::ObjectivesTool.state_of(call)
|
|
99
|
-
[
|
|
83
|
+
[ToolNames::ObjectivesTool::BLOCKED, ToolNames::ObjectivesTool::DONE].include?(state) ? ["state=#{preview_tool_param(state)}"] : []
|
|
100
84
|
end
|
|
101
85
|
|
|
102
86
|
# An objectives row's words: "O2 note · evidence", or "propose done O2 note".
|
|
103
87
|
def objectives_title(call)
|
|
104
|
-
return "#{
|
|
88
|
+
return "#{ToolNames::ObjectivesTool::PROPOSE} #{call[:change]} #{call[:id]} #{call[:text]} · #{call[:note]}".squeeze(" ") if objectives_proposal?(call)
|
|
105
89
|
|
|
106
90
|
"#{call[:id]} #{call[:note]}#{" · #{call[:evidence]}" unless call[:evidence].to_s.strip.empty?}"
|
|
107
91
|
end
|
|
@@ -124,22 +108,22 @@ module Samagotchi
|
|
|
124
108
|
def tool_title(tool_name, call, cwd: nil)
|
|
125
109
|
return task_title(tool_name, call, cwd) if TASK_TOOLS.include?(tool_name)
|
|
126
110
|
|
|
127
|
-
if [
|
|
111
|
+
if [ToolNames::Execute::NAME, ToolNames::TaskCreate::NAME].include?(tool_name)
|
|
128
112
|
title = command_description(tool_name, call) || steps_title(call[:content])
|
|
129
113
|
return title if title
|
|
130
114
|
end
|
|
131
115
|
|
|
132
116
|
text = case tool_name
|
|
133
|
-
when
|
|
134
|
-
when
|
|
135
|
-
when
|
|
136
|
-
when
|
|
117
|
+
when ToolNames::Read::NAME, ToolNames::MemoryRead::NAME then call[:content]
|
|
118
|
+
when ToolNames::Write::NAME, ToolNames::Edit::NAME, ToolNames::MemoryWrite::NAME then call[:path]
|
|
119
|
+
when ToolNames::Execute::NAME, ToolNames::TaskCreate::NAME then command_title(call[:content])
|
|
120
|
+
when ToolNames::ObjectivesTool::NAME then objectives_title(call)
|
|
137
121
|
end
|
|
138
122
|
text = text.to_s.strip
|
|
139
123
|
return nil if text.empty?
|
|
140
124
|
|
|
141
125
|
case tool_name
|
|
142
|
-
when
|
|
126
|
+
when ToolNames::Read::NAME, ToolNames::Write::NAME, ToolNames::Edit::NAME
|
|
143
127
|
path = relative_path(text, cwd)
|
|
144
128
|
path.length > TOOL_ACTIVITY_PREVIEW_LIMIT ? "…#{path[-(TOOL_ACTIVITY_PREVIEW_LIMIT - 1)..]}" : path
|
|
145
129
|
else
|
|
@@ -148,20 +132,20 @@ module Samagotchi
|
|
|
148
132
|
end
|
|
149
133
|
end
|
|
150
134
|
|
|
151
|
-
TASK_TOOLS = [
|
|
135
|
+
TASK_TOOLS = [ToolNames::TaskWait::NAME, ToolNames::TaskGet::NAME, ToolNames::TaskStop::NAME].freeze
|
|
152
136
|
|
|
153
137
|
# A task_wait / task_get / task_stop row's title: the task's command
|
|
154
138
|
# (its record under +cwd+, the process's directory when nil) as a
|
|
155
139
|
# command's title, and for a wait how long it waits ("npm test · up to
|
|
156
140
|
# 600s"). nil when there is no record: the row keeps its id.
|
|
157
141
|
def task_title(tool_name, call, cwd)
|
|
158
|
-
command =
|
|
142
|
+
command = TaskFiles.command_of(call[:content], root: cwd)
|
|
159
143
|
return nil unless command
|
|
160
144
|
|
|
161
145
|
suffix = ""
|
|
162
|
-
if tool_name ==
|
|
146
|
+
if tool_name == ToolNames::TaskWait::NAME
|
|
163
147
|
timeout = call[:timeout].to_s.strip
|
|
164
|
-
suffix = " · up to #{timeout.empty? ?
|
|
148
|
+
suffix = " · up to #{timeout.empty? ? ToolNames::TaskWait::TIMEOUT_DEFAULT : timeout.to_i}s"
|
|
165
149
|
end
|
|
166
150
|
room = TOOL_ACTIVITY_PREVIEW_LIMIT - suffix.length
|
|
167
151
|
text = steps_title(command, room) || command_title(command).gsub(/\s+/, " ")
|
|
@@ -208,26 +192,26 @@ module Samagotchi
|
|
|
208
192
|
# @param call [Hash, nil] the call, for a label that depends on its form
|
|
209
193
|
def tool_activity_action(tool_name, registry: nil, call: nil)
|
|
210
194
|
case tool_name
|
|
211
|
-
when
|
|
212
|
-
when
|
|
213
|
-
when
|
|
214
|
-
when
|
|
215
|
-
when
|
|
216
|
-
when
|
|
217
|
-
when
|
|
218
|
-
when
|
|
219
|
-
when
|
|
220
|
-
when
|
|
221
|
-
when
|
|
222
|
-
when
|
|
223
|
-
when
|
|
224
|
-
when
|
|
225
|
-
when
|
|
226
|
-
when
|
|
227
|
-
when
|
|
228
|
-
when
|
|
229
|
-
when
|
|
230
|
-
when
|
|
195
|
+
when ToolNames::Execute::NAME then "running command"
|
|
196
|
+
when ToolNames::Read::NAME then "reading file"
|
|
197
|
+
when ToolNames::Write::NAME then "writing file"
|
|
198
|
+
when ToolNames::Edit::NAME then "editing file"
|
|
199
|
+
when ToolNames::MemoryRead::NAME then "reading memory"
|
|
200
|
+
when ToolNames::MemoryWrite::NAME then memory_write_action(call)
|
|
201
|
+
when ToolNames::TaskCreate::NAME then "starting background task"
|
|
202
|
+
when ToolNames::TaskGet::NAME then "checking task"
|
|
203
|
+
when ToolNames::TaskList::NAME then "listing tasks"
|
|
204
|
+
when ToolNames::TaskStop::NAME then "stopping task"
|
|
205
|
+
when ToolNames::TaskWait::NAME then "waiting for task"
|
|
206
|
+
when ToolNames::WebFetch::NAME then "fetching URL"
|
|
207
|
+
when ToolNames::AskUserQuestion::NAME then "asking user"
|
|
208
|
+
when ToolNames::ListSessions::NAME then "listing sessions"
|
|
209
|
+
when ToolNames::SendNote::NAME then "sending a note"
|
|
210
|
+
when ToolNames::ContextRead::NAME then "reading attached context"
|
|
211
|
+
when ToolNames::Delegate::NAME then "delegating"
|
|
212
|
+
when ToolNames::DelegateResult::NAME then "waiting for a delegate"
|
|
213
|
+
when ToolNames::ForgetOutputs::NAME then forget_outputs_action(call)
|
|
214
|
+
when ToolNames::ObjectivesTool::NAME then objectives_proposal?(call) ? "proposing a change" : "recording a move"
|
|
231
215
|
else registry_entry(registry, tool_name)&.label || "calling tool"
|
|
232
216
|
end
|
|
233
217
|
end
|
|
@@ -265,19 +249,19 @@ module Samagotchi
|
|
|
265
249
|
# can print any line, "status: stopped" included.
|
|
266
250
|
def tool_activity_status(result, tool_name = nil, command: nil)
|
|
267
251
|
text = result.to_s
|
|
268
|
-
return "stopped" if [
|
|
269
|
-
if tool_name ==
|
|
270
|
-
text.start_with?(
|
|
252
|
+
return "stopped" if [ToolNames::Execute::NOT_RUN_ON_STOP, *ToolNames::Execute::NOT_RUN.values].include?(text)
|
|
253
|
+
if tool_name == ToolNames::Execute::NAME &&
|
|
254
|
+
text.start_with?(ToolNames::Execute::STOPPED_BY_USER, *ToolNames::Execute::STOPPED_BY.values)
|
|
271
255
|
return "stopped"
|
|
272
256
|
end
|
|
273
257
|
return "error" if text.start_with?("Error:")
|
|
274
258
|
# Still running, as a task: its output tail may hold any "exit: N".
|
|
275
259
|
return "ok" if handed_over?(tool_name, text)
|
|
276
|
-
if tool_name ==
|
|
260
|
+
if tool_name == ToolNames::Execute::NAME && execute_failed?(text)
|
|
277
261
|
return no_match?(text, command) ? "ok" : "error"
|
|
278
262
|
end
|
|
279
263
|
|
|
280
|
-
if tool_name ==
|
|
264
|
+
if tool_name == ToolNames::TaskWait::NAME
|
|
281
265
|
# The header: every line before the log's tail (output_tail:), which can print any line.
|
|
282
266
|
header = text.split(/^output_tail:$/, 2).first.to_s
|
|
283
267
|
return "stopped" if header.match?(/^(wait_result: canceled|status: stopped)$/)
|
|
@@ -288,15 +272,15 @@ module Samagotchi
|
|
|
288
272
|
end
|
|
289
273
|
|
|
290
274
|
# An execute still running at its limit (or when a message from the user
|
|
291
|
-
# waited), handed over as a task (
|
|
275
|
+
# waited), handed over as a task (ToolNames::Execute::HANDED_OVER).
|
|
292
276
|
def handed_over?(tool_name, text)
|
|
293
|
-
return false unless tool_name ==
|
|
277
|
+
return false unless tool_name == ToolNames::Execute::NAME && text.to_s.start_with?(ToolNames::Execute::HANDED_OVER)
|
|
294
278
|
|
|
295
279
|
# The first line only, scrubbed: a regexp raises on bytes that aren't UTF-8.
|
|
296
280
|
text.to_s.each_line.first.to_s.scrub.match?(HANDED_OVER_START)
|
|
297
281
|
end
|
|
298
282
|
|
|
299
|
-
HANDED_OVER_START = /\A#{Regexp.escape(
|
|
283
|
+
HANDED_OVER_START = /\A#{Regexp.escape(ToolNames::Execute::HANDED_OVER)} #{ToolNames::Execute::HANDED_OVER_AFTER}/
|
|
300
284
|
|
|
301
285
|
def execute_failed?(text)
|
|
302
286
|
code = execute_exit_code(text)
|
|
@@ -375,28 +359,28 @@ module Samagotchi
|
|
|
375
359
|
# turn (+registry+'s entry then).
|
|
376
360
|
def tool_activity_params(tool_name, call, registry: nil, surface: nil)
|
|
377
361
|
case tool_name
|
|
378
|
-
when
|
|
362
|
+
when ToolNames::Execute::NAME
|
|
379
363
|
"command=#{preview_tool_param(call[:content])}"
|
|
380
|
-
when
|
|
364
|
+
when ToolNames::Read::NAME
|
|
381
365
|
parts = ["path=#{preview_tool_param(call[:content])}"]
|
|
382
366
|
range = format_line_range(call)
|
|
383
367
|
parts << "lines=#{range}" if range
|
|
384
368
|
parts.join(" ")
|
|
385
|
-
when
|
|
369
|
+
when ToolNames::Write::NAME
|
|
386
370
|
"path=#{preview_tool_param(call[:path])}"
|
|
387
|
-
when
|
|
371
|
+
when ToolNames::Edit::NAME
|
|
388
372
|
parts = ["path=#{preview_tool_param(call[:path])}"]
|
|
389
373
|
range = format_line_range(call)
|
|
390
374
|
parts << "lines=#{range}" if range
|
|
391
375
|
parts.join(" ")
|
|
392
|
-
when
|
|
376
|
+
when ToolNames::MemoryRead::NAME
|
|
393
377
|
parts = []
|
|
394
378
|
name = call[:content].to_s.strip
|
|
395
379
|
parts << "name=#{preview_tool_param(name)}" unless name.empty?
|
|
396
380
|
scope = call[:scope].to_s.strip
|
|
397
381
|
parts << "scope=#{preview_tool_param(scope)}" unless scope.empty?
|
|
398
382
|
parts.join(" ")
|
|
399
|
-
when
|
|
383
|
+
when ToolNames::MemoryWrite::NAME
|
|
400
384
|
parts = []
|
|
401
385
|
path = call[:path].to_s.strip
|
|
402
386
|
parts << "name=#{preview_tool_param(path)}" unless path.empty?
|
|
@@ -406,16 +390,16 @@ module Samagotchi
|
|
|
406
390
|
parts << "description=#{preview_tool_param(desc)}" unless desc.empty?
|
|
407
391
|
parts << "remove=true" if call[:remove].to_s.strip.downcase == "true"
|
|
408
392
|
parts.join(" ")
|
|
409
|
-
when
|
|
393
|
+
when ToolNames::TaskCreate::NAME
|
|
410
394
|
parts = ["command=#{preview_tool_param(call[:content])}"]
|
|
411
395
|
cwd = call[:cwd].to_s.strip
|
|
412
396
|
parts << "cwd=#{preview_tool_param(cwd)}" unless cwd.empty?
|
|
413
397
|
env = call[:env].to_s.strip
|
|
414
398
|
parts << "env=#{preview_tool_param(env)}" unless env.empty?
|
|
415
399
|
parts.join(" ")
|
|
416
|
-
when
|
|
400
|
+
when ToolNames::TaskGet::NAME, ToolNames::TaskStop::NAME
|
|
417
401
|
"id=#{preview_tool_param(call[:content])}"
|
|
418
|
-
when
|
|
402
|
+
when ToolNames::TaskWait::NAME
|
|
419
403
|
parts = ["id=#{preview_tool_param(call[:content])}"]
|
|
420
404
|
timeout = call[:timeout].to_s.strip
|
|
421
405
|
tail_lines = call[:tail_lines].to_s.strip
|
|
@@ -424,21 +408,21 @@ module Samagotchi
|
|
|
424
408
|
parts << "tail_lines=#{preview_tool_param(tail_lines)}" unless tail_lines.empty?
|
|
425
409
|
parts << "done_pattern=#{preview_tool_param(done_pattern)}" unless done_pattern.empty?
|
|
426
410
|
parts.join(" ")
|
|
427
|
-
when
|
|
411
|
+
when ToolNames::TaskList::NAME
|
|
428
412
|
nil
|
|
429
|
-
when
|
|
413
|
+
when ToolNames::WebFetch::NAME
|
|
430
414
|
"url=#{preview_tool_param(call[:content])}"
|
|
431
|
-
when
|
|
415
|
+
when ToolNames::ListSessions::NAME
|
|
432
416
|
call[:cwd].to_s.strip.empty? ? nil : "cwd=#{preview_tool_param(call[:cwd])}"
|
|
433
|
-
when
|
|
417
|
+
when ToolNames::SendNote::NAME
|
|
434
418
|
"session=#{preview_tool_param(call[:session])} text=#{preview_tool_param(call[:content])}"
|
|
435
|
-
when
|
|
419
|
+
when ToolNames::ContextRead::NAME
|
|
436
420
|
parts = []
|
|
437
421
|
parts << "name=#{preview_tool_param(call[:content])}" unless call[:content].to_s.strip.empty?
|
|
438
422
|
parts << "offset=#{preview_tool_param(call[:offset])}" unless call[:offset].to_s.strip.empty?
|
|
439
423
|
parts << "limit=#{preview_tool_param(call[:limit])}" unless call[:limit].to_s.strip.empty?
|
|
440
424
|
parts.empty? ? nil : parts.join(" ")
|
|
441
|
-
when
|
|
425
|
+
when ToolNames::Delegate::NAME
|
|
442
426
|
parts = []
|
|
443
427
|
parts << "session=#{preview_tool_param(call[:session])}" unless call[:session].to_s.strip.empty?
|
|
444
428
|
parts << "model=#{preview_tool_param(call[:model])}" unless call[:model].to_s.strip.empty?
|
|
@@ -446,9 +430,9 @@ module Samagotchi
|
|
|
446
430
|
parts << "task=#{preview_tool_param(call[:content])}"
|
|
447
431
|
parts << "wait=#{preview_tool_param(call[:wait])}" unless call[:wait].nil? || call[:wait].to_s.strip.empty?
|
|
448
432
|
parts.join(" ")
|
|
449
|
-
when
|
|
433
|
+
when ToolNames::DelegateResult::NAME
|
|
450
434
|
call[:session].to_s.strip.empty? ? nil : "session=#{preview_tool_param(call[:session])}"
|
|
451
|
-
when
|
|
435
|
+
when ToolNames::ForgetOutputs::NAME
|
|
452
436
|
request = Tools::ForgetOutputs.parse(call)
|
|
453
437
|
parts = []
|
|
454
438
|
parts << "ids=#{preview_tool_param(request.ids.join(","))}" unless request.ids.empty?
|
|
@@ -456,12 +440,12 @@ module Samagotchi
|
|
|
456
440
|
parts << "restore=#{preview_tool_param(request.restore.join(","))}" if request.restore?
|
|
457
441
|
parts << "note=#{preview_tool_param(request.note)}" unless request.note.empty?
|
|
458
442
|
parts.empty? ? nil : parts.join(" ")
|
|
459
|
-
when
|
|
443
|
+
when ToolNames::ObjectivesTool::NAME
|
|
460
444
|
parts = ["id=#{preview_tool_param(call[:id])}", *objectives_state_param(call), "note=#{preview_tool_param(call[:note])}"]
|
|
461
445
|
parts.unshift("change=#{preview_tool_param(call[:change])}") if objectives_proposal?(call)
|
|
462
446
|
parts << "evidence=#{preview_tool_param(call[:evidence])}" unless call[:evidence].to_s.strip.empty?
|
|
463
447
|
parts.join(" ")
|
|
464
|
-
when
|
|
448
|
+
when ToolNames::AskUserQuestion::NAME
|
|
465
449
|
parts = ["question=#{preview_tool_param(call[:question] || call[:content])}"]
|
|
466
450
|
opts = call[:options]
|
|
467
451
|
parts << "options=#{preview_tool_param(Array(opts).join(","))}" if opts && !Array(opts).empty?
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Samagotchi
|
|
4
|
+
# chi's built-in tools' names, and the fixed texts some of them write into
|
|
5
|
+
# their results, apart from the tool classes: the code that only names a
|
|
6
|
+
# tool or matches a result to draw a row (ToolActivity, ToolView, FileRef,
|
|
7
|
+
# ObjectivesBacking) reads them here and loads no tool class (Tools::Execute
|
|
8
|
+
# alone brings TaskRuntime, Shell, Leftovers, the process group…).
|
|
9
|
+
#
|
|
10
|
+
# Each tool class keeps its own constants, read from here
|
|
11
|
+
# (Tools::Execute::NAME = ToolNames::Execute::NAME): code that loads the
|
|
12
|
+
# class still names them on it, and bundles do (the bundle boundary allows
|
|
13
|
+
# Tools::Execute::NAME and ::HANDED_OVER; slow-commands looks Execute's stop
|
|
14
|
+
# texts up by reflection). A new built-in adds its module here
|
|
15
|
+
# (spec/tool_names_spec.rb holds the two in step).
|
|
16
|
+
#
|
|
17
|
+
# No requires: it is a leaf every client can load.
|
|
18
|
+
module ToolNames
|
|
19
|
+
module Execute
|
|
20
|
+
NAME = "execute"
|
|
21
|
+
NOT_RUN_ON_STOP = "Error: not run, the user stopped the turn"
|
|
22
|
+
# The first words of a command the user's Stop killed.
|
|
23
|
+
STOPPED_BY_USER = "Error: command stopped by the user"
|
|
24
|
+
# The same two when a signal to chi (a worker's TERM, HUP or INT)
|
|
25
|
+
# stopped the turn: its cancel reason is :signal.
|
|
26
|
+
NOT_RUN_ON_SIGNAL = "Error: not run, a signal to chi stopped the turn"
|
|
27
|
+
STOPPED_BY_SIGNAL = "Error: command stopped by a signal to chi"
|
|
28
|
+
# The same two when a session stop (chi sessions stop, the web's stop,
|
|
29
|
+
# a parent stopping its delegate) canceled the turn: :session_stopped.
|
|
30
|
+
NOT_RUN_ON_SESSION_STOP = "Error: not run, the session was stopped"
|
|
31
|
+
STOPPED_BY_SESSION_STOP = "Error: command stopped as the session was stopped"
|
|
32
|
+
# The texts above by the stop's reason; any other is the user's Stop.
|
|
33
|
+
NOT_RUN = { signal: NOT_RUN_ON_SIGNAL, session_stopped: NOT_RUN_ON_SESSION_STOP }.freeze
|
|
34
|
+
STOPPED_BY = { signal: STOPPED_BY_SIGNAL, session_stopped: STOPPED_BY_SESSION_STOP }.freeze
|
|
35
|
+
# The first words of a command still running and handed over as a
|
|
36
|
+
# task (handed_over_line at the limit, early_handed_over_line for a
|
|
37
|
+
# message). TaskTranscript.handed_over_id, the web's task_stop.js and the
|
|
38
|
+
# slow-commands bundle match on them; the bundle reads only the limit's
|
|
39
|
+
# form, "at the 120s limit".
|
|
40
|
+
HANDED_OVER = "Still running at the"
|
|
41
|
+
# What follows HANDED_OVER on the first line, as regexp source: "120s
|
|
42
|
+
# limit:" (the limit) or "4s mark:" (a message from the user ended the
|
|
43
|
+
# wait early). Every matcher of the line builds on it.
|
|
44
|
+
HANDED_OVER_AFTER = "(?:\\d+s limit|\\d+s mark):"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
module Read
|
|
48
|
+
NAME = "read"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
module Write
|
|
52
|
+
NAME = "write"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
module MemoryRead
|
|
56
|
+
NAME = "memory_read"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
module MemoryWrite
|
|
60
|
+
NAME = "memory_write"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
module Edit
|
|
64
|
+
NAME = "edit"
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
module TaskCreate
|
|
68
|
+
NAME = "task_create"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
module TaskGet
|
|
72
|
+
NAME = "task_get"
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
module TaskList
|
|
76
|
+
NAME = "task_list"
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
module TaskStop
|
|
80
|
+
NAME = "task_stop"
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
module TaskWait
|
|
84
|
+
NAME = "task_wait"
|
|
85
|
+
TIMEOUT_DEFAULT = 600
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
module WebFetch
|
|
89
|
+
NAME = "web_fetch"
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
module RegisterReminder
|
|
93
|
+
NAME = "register_reminder"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
module CancelReminder
|
|
97
|
+
NAME = "cancel_reminder"
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
module ListReminders
|
|
101
|
+
NAME = "list_reminders"
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
module ScheduleTask
|
|
105
|
+
NAME = "schedule_task"
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
module ListSchedules
|
|
109
|
+
NAME = "list_schedules"
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
module CancelSchedule
|
|
113
|
+
NAME = "cancel_schedule"
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
module ListSessions
|
|
117
|
+
NAME = "list_sessions"
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
module SendNote
|
|
121
|
+
NAME = "send_note"
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
module ContextRead
|
|
125
|
+
NAME = "context_read"
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
module Delegate
|
|
129
|
+
NAME = "delegate"
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
module DelegateResult
|
|
133
|
+
NAME = "delegate_result"
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
module AskUserQuestion
|
|
137
|
+
NAME = "ask_user_question"
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
module ObjectivesTool
|
|
141
|
+
NAME = "objectives"
|
|
142
|
+
PROPOSE = "propose"
|
|
143
|
+
# A move's states the row shows (ObjectivesTool::STATES has progress too).
|
|
144
|
+
BLOCKED = "blocked"
|
|
145
|
+
DONE = "done"
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
module ForgetOutputs
|
|
149
|
+
NAME = "forget_outputs"
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Every built-in's name, in the order above.
|
|
153
|
+
NAMES = constants.map { |tool| const_get(tool)::NAME }.freeze
|
|
154
|
+
|
|
155
|
+
# A built-in as a reader with no Engine sees it in a registry: chi's
|
|
156
|
+
# own (core), with no label and no preview, as Tools::Builtins
|
|
157
|
+
# registers each.
|
|
158
|
+
Entry = Data.define(:name) do
|
|
159
|
+
def core? = true
|
|
160
|
+
def source = "core"
|
|
161
|
+
def label = nil
|
|
162
|
+
def preview = nil
|
|
163
|
+
def preview_of(*) = nil
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# The built-ins as the registry a display reads when it is given none
|
|
167
|
+
# (MessageParts.for_message's default, which chi web and the bridge's
|
|
168
|
+
# drawings use): [name] is a built-in's Entry, nil for any other name.
|
|
169
|
+
# ToolActivity asks a registry's entry only whether it is core and its
|
|
170
|
+
# label and preview, so this answers as Tools::Builtins.default does
|
|
171
|
+
# without loading a tool (spec/tool_names_spec.rb compares the two).
|
|
172
|
+
module BuiltinRegistry
|
|
173
|
+
ENTRIES = NAMES.to_h { |name| [name, Entry.new(name: name)] }.freeze
|
|
174
|
+
|
|
175
|
+
def self.[](name) = ENTRIES[name.to_s]
|
|
176
|
+
def self.key?(name) = ENTRIES.key?(name.to_s)
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
data/lib/samagotchi/tool_view.rb
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "command_steps"
|
|
4
|
-
require_relative "
|
|
5
|
-
require_relative "tools/task_create"
|
|
6
|
-
require_relative "tools/task_wait"
|
|
4
|
+
require_relative "tool_names"
|
|
7
5
|
|
|
8
6
|
module Samagotchi
|
|
9
7
|
# What a richer UI shows of a tool call beyond its one-line params: the
|
|
@@ -29,7 +27,7 @@ module Samagotchi
|
|
|
29
27
|
# The longest command a view carries (the spike's longest was 3,799).
|
|
30
28
|
COMMAND_LIMIT = 8_000
|
|
31
29
|
|
|
32
|
-
TOOLS = [
|
|
30
|
+
TOOLS = [ToolNames::Execute::NAME, ToolNames::TaskCreate::NAME].freeze
|
|
33
31
|
|
|
34
32
|
# The longest description a view carries; a row's title shows the
|
|
35
33
|
# first TITLE_LIMIT characters of it.
|
|
@@ -39,7 +37,7 @@ module Samagotchi
|
|
|
39
37
|
# @return [ToolView, nil] nil for a tool without a view and for an
|
|
40
38
|
# empty command
|
|
41
39
|
def self.for(tool_name, call)
|
|
42
|
-
return task_wait(call) if tool_name ==
|
|
40
|
+
return task_wait(call) if tool_name == ToolNames::TaskWait::NAME && call.is_a?(Hash)
|
|
43
41
|
return nil unless TOOLS.include?(tool_name) && call.is_a?(Hash)
|
|
44
42
|
|
|
45
43
|
command = call[:content].to_s
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "json"
|
|
4
|
+
require_relative "../tool_names"
|
|
4
5
|
|
|
5
6
|
module Samagotchi
|
|
6
7
|
module Tools
|
|
@@ -15,7 +16,7 @@ module Samagotchi
|
|
|
15
16
|
#
|
|
16
17
|
# Single tool covers single + multi + freeform via flags: multi_select, allow_freeform.
|
|
17
18
|
class AskUserQuestion
|
|
18
|
-
NAME =
|
|
19
|
+
NAME = ToolNames::AskUserQuestion::NAME
|
|
19
20
|
|
|
20
21
|
def self.name = NAME
|
|
21
22
|
|
|
@@ -169,7 +169,7 @@ module Samagotchi
|
|
|
169
169
|
|
|
170
170
|
# The session's project env (ProjectEnv.current: the worker's mise env,
|
|
171
171
|
# the chi shim first on PATH) for the commands the owner's turns run;
|
|
172
|
-
# less what every tool runs without (
|
|
172
|
+
# less what every tool runs without (SpawnEnv::SANITIZED_ENV_KEYS).
|
|
173
173
|
# A participant's turn gets none of it: a project's [env] may load its
|
|
174
174
|
# .env files.
|
|
175
175
|
def project_env(kctx)
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "../reminder_store"
|
|
4
|
+
require_relative "../tool_names"
|
|
4
5
|
|
|
5
6
|
module Samagotchi
|
|
6
7
|
module Tools
|
|
7
8
|
# Cancels a previously registered reminder by name.
|
|
8
9
|
class CancelReminder
|
|
9
|
-
NAME =
|
|
10
|
+
NAME = ToolNames::CancelReminder::NAME
|
|
10
11
|
|
|
11
12
|
def self.name = NAME
|
|
12
13
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "../tool_names"
|
|
4
|
+
|
|
3
5
|
module Samagotchi
|
|
4
6
|
module Tools
|
|
5
7
|
# Cancel a durable schedule of this session's chain by its id, a unique
|
|
@@ -7,7 +9,7 @@ module Samagotchi
|
|
|
7
9
|
# session's chain is refused unless the call says `all: true`: `chi
|
|
8
10
|
# schedule cancel` is the machine-wide way.
|
|
9
11
|
class CancelSchedule
|
|
10
|
-
NAME =
|
|
12
|
+
NAME = ToolNames::CancelSchedule::NAME
|
|
11
13
|
|
|
12
14
|
def self.name = NAME
|
|
13
15
|
|
|
@@ -4,6 +4,7 @@ require "time"
|
|
|
4
4
|
require_relative "../config"
|
|
5
5
|
require_relative "../context_sources"
|
|
6
6
|
require_relative "../project_scope"
|
|
7
|
+
require_relative "../tool_names"
|
|
7
8
|
|
|
8
9
|
module Samagotchi
|
|
9
10
|
module Tools
|
|
@@ -13,7 +14,7 @@ module Samagotchi
|
|
|
13
14
|
# runs a source's command) and records what was read, so the web can
|
|
14
15
|
# show a change the agent hasn't read.
|
|
15
16
|
class ContextRead
|
|
16
|
-
NAME =
|
|
17
|
+
NAME = ToolNames::ContextRead::NAME
|
|
17
18
|
DEFAULT_MAX_CHARS = 10_000
|
|
18
19
|
# The smallest cap it pages to (a smaller one is taken as this).
|
|
19
20
|
MIN_CHARS = 2_000
|
|
@@ -11,6 +11,7 @@ require_relative "peers"
|
|
|
11
11
|
require_relative "delegate_wait"
|
|
12
12
|
require_relative "../child_reports"
|
|
13
13
|
require_relative "../worker_link"
|
|
14
|
+
require_relative "../tool_names"
|
|
14
15
|
|
|
15
16
|
module Samagotchi
|
|
16
17
|
# Loaded on first use (a delegate call): keeps the bundle test kit's load budget
|
|
@@ -35,7 +36,7 @@ module Samagotchi
|
|
|
35
36
|
# follow-up to a child that exists. Only the child's final
|
|
36
37
|
# reply comes back (DelegateWait), never its trace.
|
|
37
38
|
class Delegate
|
|
38
|
-
NAME =
|
|
39
|
+
NAME = ToolNames::Delegate::NAME
|
|
39
40
|
MAX_CHILDREN_KEY = "session.max_children"
|
|
40
41
|
MAX_CHILDREN_DEFAULT = 4
|
|
41
42
|
# A path in a task: absolute, ~/ or ../, not glued to a word (a URL's
|
|
@@ -4,6 +4,7 @@ require_relative "../session"
|
|
|
4
4
|
require_relative "peers"
|
|
5
5
|
require_relative "delegate"
|
|
6
6
|
require_relative "delegate_wait"
|
|
7
|
+
require_relative "../tool_names"
|
|
7
8
|
|
|
8
9
|
module Samagotchi
|
|
9
10
|
# Loaded on first use: this autoload keeps SessionManager and its ~80
|
|
@@ -14,7 +15,7 @@ module Samagotchi
|
|
|
14
15
|
# Wait for a delegated session's next reply: the one named, or this
|
|
15
16
|
# session's newest running child.
|
|
16
17
|
class DelegateResult
|
|
17
|
-
NAME =
|
|
18
|
+
NAME = ToolNames::DelegateResult::NAME
|
|
18
19
|
|
|
19
20
|
def self.name = NAME
|
|
20
21
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "output_guardrails"
|
|
4
4
|
require_relative "tool_path"
|
|
5
|
+
require_relative "../tool_names"
|
|
5
6
|
|
|
6
7
|
module Samagotchi
|
|
7
8
|
module Tools
|
|
@@ -12,7 +13,7 @@ module Samagotchi
|
|
|
12
13
|
# if the text is not found or appears more than once. new_text is
|
|
13
14
|
# required in both modes; "" deletes.
|
|
14
15
|
class Edit
|
|
15
|
-
NAME =
|
|
16
|
+
NAME = ToolNames::Edit::NAME
|
|
16
17
|
|
|
17
18
|
def self.name = NAME
|
|
18
19
|
|