samagotchi 0.172.1 → 0.174.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 +61 -1
- data/docs/architecture.md +16 -5
- data/docs/cli.md +11 -3
- data/docs/configuration.md +1 -1
- data/docs/internals/background-tasks.md +16 -6
- data/docs/internals/bridge.md +2 -2
- data/docs/internals/engine.md +2 -1
- data/docs/internals/participants.md +69 -9
- data/docs/internals/remote-sessions.md +9 -1
- data/docs/internals/web-frontend.md +34 -8
- data/docs/plugins.md +1 -1
- data/docs/scheduling.md +9 -3
- data/docs/sessions.md +5 -3
- data/docs/testing.md +32 -10
- data/lib/samagotchi/bridge.rb +4 -3
- 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/child_move.rb +11 -4
- data/lib/samagotchi/continued_from.rb +51 -0
- data/lib/samagotchi/engine/participants.rb +2 -2
- data/lib/samagotchi/engine.rb +1 -2
- 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/note_move.rb +11 -4
- 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/schedules.rb +13 -16
- data/lib/samagotchi/send_command/parent_gate.rb +2 -2
- data/lib/samagotchi/send_command.rb +4 -4
- data/lib/samagotchi/session_access/contract.rb +1 -0
- data/lib/samagotchi/session_access/local.rb +9 -1
- data/lib/samagotchi/session_access/remote.rb +26 -3
- data/lib/samagotchi/session_chain/delete.rb +405 -0
- data/lib/samagotchi/session_chain/delete_preview.rb +96 -0
- data/lib/samagotchi/session_chain/links.rb +38 -0
- data/lib/samagotchi/session_command_catalog.rb +210 -0
- data/lib/samagotchi/session_commands.rb +6 -187
- data/lib/samagotchi/session_continue.rb +51 -13
- data/lib/samagotchi/session_delete_command.rb +82 -17
- data/lib/samagotchi/session_manager/lifecycle.rb +5 -4
- data/lib/samagotchi/session_manager/removal.rb +137 -31
- data/lib/samagotchi/session_manager.rb +2 -1
- data/lib/samagotchi/session_stores.rb +4 -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/exit_commands.rb +2 -2
- data/lib/samagotchi/terminal_ui/attached_loop/questions.rb +2 -2
- data/lib/samagotchi/terminal_ui/attached_loop.rb +4 -4
- data/lib/samagotchi/terminal_ui/exit_lines.rb +16 -0
- data/lib/samagotchi/terminal_ui/input_support.rb +1 -1
- data/lib/samagotchi/terminal_ui/local_link.rb +7 -1
- data/lib/samagotchi/terminal_ui.rb +3 -3
- data/lib/samagotchi/testing/boundary.rb +2 -2
- data/lib/samagotchi/testing/bundle.rb +1 -1
- 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/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 +29 -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 +45 -37
- 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 +24 -12
- 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 +8 -2
- data/lib/samagotchi/web/public/chains.js +3 -3
- data/lib/samagotchi/web/public/data.js +12 -0
- data/lib/samagotchi/web/public/delete_sheet.js +344 -0
- data/lib/samagotchi/web/public/format.js +1 -1
- data/lib/samagotchi/web/public/history_shape.js +1 -2
- data/lib/samagotchi/web/public/index.html +27 -0
- data/lib/samagotchi/web/public/info_bar.js +3 -2
- data/lib/samagotchi/web/public/lists_view.js +2 -2
- data/lib/samagotchi/web/public/more_sheet.js +42 -5
- data/lib/samagotchi/web/public/participant_history.js +27 -0
- data/lib/samagotchi/web/public/question_cards.js +1 -15
- data/lib/samagotchi/web/public/reload_check.js +90 -72
- data/lib/samagotchi/web/public/session_actions.js +50 -6
- data/lib/samagotchi/web/public/session_view.js +6 -1
- data/lib/samagotchi/web/public/stage_asking.js +6 -20
- data/lib/samagotchi/web/public/stage_view.js +2 -2
- data/lib/samagotchi/web/public/stage_waiting.js +4 -10
- 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 +79 -20
- 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 +17 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "../../composer_route"
|
|
4
4
|
require_relative "../../prompt_history"
|
|
5
|
-
require_relative "../../
|
|
5
|
+
require_relative "../../session_command_catalog"
|
|
6
6
|
require_relative "../exit_lines"
|
|
7
7
|
require_relative "../reline_seam"
|
|
8
8
|
|
|
@@ -112,7 +112,7 @@ module Samagotchi
|
|
|
112
112
|
return submit(nil) if local == :detach
|
|
113
113
|
return end_scratch if local == :exit && @scratch
|
|
114
114
|
return refuse_scratch_archive if local == :archive && @scratch
|
|
115
|
-
return
|
|
115
|
+
return SessionCommandCatalog.delete_on_exit?(text) ? exit_and_delete : exit_worker if local == :exit
|
|
116
116
|
return archive_after_turn if local == :archive && (@running || !@queued_ids.empty?)
|
|
117
117
|
return exit_and_archive if local == :archive
|
|
118
118
|
|
|
@@ -173,7 +173,7 @@ module Samagotchi
|
|
|
173
173
|
# The session's commands as its worker's snapshot names them (its
|
|
174
174
|
# plugins' too); the built-ins until one arrives, or from a worker too
|
|
175
175
|
# old to name them. An unknown /foo is a prompt.
|
|
176
|
-
def command_registry = @command_registry ||
|
|
176
|
+
def command_registry = @command_registry || SessionCommandCatalog.builtin_registry
|
|
177
177
|
|
|
178
178
|
# Ctrl-C cancels the running turn (whoever started it). At an idle
|
|
179
179
|
# prompt it clears the line; on an empty one it says how to detach, and
|
|
@@ -99,8 +99,8 @@ module Samagotchi
|
|
|
99
99
|
# An empty session: the worker deletes it as it leaves.
|
|
100
100
|
return detach(ExitLines::EMPTY_EXIT) if ExitLines.discards?(reply)
|
|
101
101
|
|
|
102
|
-
@link.delete_session
|
|
103
|
-
detach("Detached; deleted session #{id}.")
|
|
102
|
+
result = @link.delete_session
|
|
103
|
+
detach("Detached; deleted session #{id}.#{ExitLines.deleted_tail(result, id)}")
|
|
104
104
|
rescue SystemCallError, IOError => e
|
|
105
105
|
detach("#{ExitLines.exit_failed_line(e.message, via: via, session_id: id)} Not deleted.")
|
|
106
106
|
rescue SessionManager::DeleteRefused, SessionManager::OwnedByTUI, ArgumentError => e
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "../../client_id"
|
|
4
4
|
require_relative "../exit_lines"
|
|
5
|
-
require_relative "../../
|
|
5
|
+
require_relative "../../session_command_catalog"
|
|
6
6
|
require_relative "../question_prompt"
|
|
7
7
|
|
|
8
8
|
module Samagotchi
|
|
@@ -29,7 +29,7 @@ module Samagotchi
|
|
|
29
29
|
|
|
30
30
|
# A bare answer at the continue prompt (an empty one is yes).
|
|
31
31
|
def continue_line(text)
|
|
32
|
-
text.empty? ?
|
|
32
|
+
text.empty? ? SessionCommandCatalog::CONTINUE_COMMAND : "#{SessionCommandCatalog::CONTINUE_COMMAND} #{text}"
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
def offer_continue(event)
|
|
@@ -35,7 +35,7 @@ require_relative "../steer"
|
|
|
35
35
|
require_relative "../turn_origin"
|
|
36
36
|
require_relative "../model_profile"
|
|
37
37
|
require_relative "../output_formatter"
|
|
38
|
-
require_relative "../
|
|
38
|
+
require_relative "../session_command_catalog"
|
|
39
39
|
require_relative "../session_manager"
|
|
40
40
|
require_relative "../session_metrics"
|
|
41
41
|
require_relative "../children_status"
|
|
@@ -118,7 +118,7 @@ module Samagotchi
|
|
|
118
118
|
def initialize(screen:, client_id:, client: nil, first_prompt: nil, first_command: nil, no_interrupt: false,
|
|
119
119
|
default_input: false, wait_at_eof: false, as_parent: false, scratch: false,
|
|
120
120
|
clock: -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) }, now: -> { MessageTime.now },
|
|
121
|
-
delete_session:
|
|
121
|
+
delete_session: LocalLink::DELETE,
|
|
122
122
|
archive_session: ->(id) { SessionManager.archive_session(id, wait: LocalLink::DELETE_WAIT) },
|
|
123
123
|
installed_version: -> { InstalledVersions.new.newest },
|
|
124
124
|
state_dir: Session.default_state_dir,
|
|
@@ -506,7 +506,7 @@ module Samagotchi
|
|
|
506
506
|
def older_worker_command(reply, line)
|
|
507
507
|
return nil unless reply.status == 400 && reply.json&.fetch("error", nil) == "unknown_command"
|
|
508
508
|
|
|
509
|
-
|
|
509
|
+
SessionCommandCatalog.builtin_name(line)
|
|
510
510
|
end
|
|
511
511
|
|
|
512
512
|
def stale_worker(cant)
|
|
@@ -556,7 +556,7 @@ module Samagotchi
|
|
|
556
556
|
@screen.commit(paint(version_line, 2)) if version_line
|
|
557
557
|
end
|
|
558
558
|
if snapshot[:commands]
|
|
559
|
-
@command_registry = Commands::Registry.from_listing(snapshot[:commands], base:
|
|
559
|
+
@command_registry = Commands::Registry.from_listing(snapshot[:commands], base: SessionCommandCatalog.builtin_registry)
|
|
560
560
|
end
|
|
561
561
|
Array(snapshot[:init_tasks]).each { |task| @view.init_started(task) }
|
|
562
562
|
cards = Array(snapshot[:cards])
|
|
@@ -10,6 +10,22 @@ module Samagotchi
|
|
|
10
10
|
module ExitLines
|
|
11
11
|
module_function
|
|
12
12
|
|
|
13
|
+
# What /exit --delete's line adds from the delete's result: the previous
|
|
14
|
+
# link back in the lists (D2), the delegates deleted with it and the
|
|
15
|
+
# ones left running (D7). "" for a plain delete.
|
|
16
|
+
def deleted_tail(result, id)
|
|
17
|
+
return "" unless result.is_a?(Hash)
|
|
18
|
+
|
|
19
|
+
back = Array(result[:unarchived]).first
|
|
20
|
+
gone = Array(result[:deleted]).reject { |sid| sid == id }.size
|
|
21
|
+
running = Array(result[:left_running])
|
|
22
|
+
parts = []
|
|
23
|
+
parts << " The previous link #{back[0, 8]} is back in the lists." if back
|
|
24
|
+
parts << " #{gone} delegate#{"s" unless gone == 1} deleted with it." if gone.positive?
|
|
25
|
+
parts << " #{running.size} left running: #{running.map { |sid| sid[0, 8] }.join(", ")}." unless running.empty?
|
|
26
|
+
parts.join
|
|
27
|
+
end
|
|
28
|
+
|
|
13
29
|
# Why a request the Bridge read after its deadline didn't go through.
|
|
14
30
|
LATE = "worker not answering in time"
|
|
15
31
|
# An exit the worker agreed to in an empty session. Said before it has
|
|
@@ -9,7 +9,7 @@ require_relative "../degrade"
|
|
|
9
9
|
require_relative "../memory_paths"
|
|
10
10
|
require_relative "../prompt_history"
|
|
11
11
|
require_relative "../tools/memory"
|
|
12
|
-
require_relative "../
|
|
12
|
+
require_relative "../session_command_catalog"
|
|
13
13
|
require_relative "line_reader"
|
|
14
14
|
require_relative "reline_history_hook"
|
|
15
15
|
|
|
@@ -26,6 +26,12 @@ module Samagotchi
|
|
|
26
26
|
# How long /exit --delete and /archive wait for the worker to let go
|
|
27
27
|
# (AttachedLoop's defaults too).
|
|
28
28
|
DELETE_WAIT = 10
|
|
29
|
+
# /exit --delete on this machine (LocalLink's and AttachedLoop's
|
|
30
|
+
# default): a user's delete, so a chain's newest link is undone and the
|
|
31
|
+
# previous one comes back (SessionManager.delete_session's keywords).
|
|
32
|
+
DELETE = lambda do |id|
|
|
33
|
+
SessionManager.delete_session(id, stop: true, wait: DELETE_WAIT, revive_previous: true, refuse_continuing: true)
|
|
34
|
+
end
|
|
29
35
|
|
|
30
36
|
attr_reader :client
|
|
31
37
|
|
|
@@ -37,7 +43,7 @@ module Samagotchi
|
|
|
37
43
|
# @param installed_version [#call] -> the newest chi installed
|
|
38
44
|
# @param children_counts [#call] session id -> ChildrenStatus::Counts
|
|
39
45
|
def initialize(client:, state_dir: Session.default_state_dir,
|
|
40
|
-
delete_session:
|
|
46
|
+
delete_session: DELETE,
|
|
41
47
|
archive_session: ->(id) { SessionManager.archive_session(id, wait: DELETE_WAIT) },
|
|
42
48
|
installed_version: -> { InstalledVersions.new.newest },
|
|
43
49
|
children_counts: ->(id) { ChildrenStatus.counts(id, state_dir: state_dir) })
|
|
@@ -198,7 +198,7 @@ module Samagotchi
|
|
|
198
198
|
# A UI-only command (/stats, /exit …) isn't run without a terminal,
|
|
199
199
|
# and isn't a prompt either: refused as chi send refuses it, before
|
|
200
200
|
# any session is made (bin/chi exits 1).
|
|
201
|
-
return refuse_one_shot_ui_command if
|
|
201
|
+
return refuse_one_shot_ui_command if SessionCommandCatalog.ui_only_entry(@prompt)
|
|
202
202
|
|
|
203
203
|
session = @resume_session || @engine.store_model!(Session.new_session(
|
|
204
204
|
mode: "assist",
|
|
@@ -356,8 +356,8 @@ module Samagotchi
|
|
|
356
356
|
# `chi -p /stats --non-interactive`: why it doesn't run, on stderr.
|
|
357
357
|
# @return [Symbol] :turn_failed
|
|
358
358
|
def refuse_one_shot_ui_command
|
|
359
|
-
name =
|
|
360
|
-
warn "chi: refused: #{
|
|
359
|
+
name = SessionCommandCatalog.ui_only_entry(@prompt).name
|
|
360
|
+
warn "chi: refused: #{SessionCommandCatalog.ui_only_refusal(name, @resume_session&.id, runner: "--non-interactive")}"
|
|
361
361
|
:turn_failed
|
|
362
362
|
end
|
|
363
363
|
|
|
@@ -36,8 +36,8 @@ module Samagotchi
|
|
|
36
36
|
Allowed.new(name: "Samagotchi::Tools::Execute::TIMEOUT_PREFIX", file: "samagotchi/tools/execute"),
|
|
37
37
|
Allowed.new(name: "Samagotchi::Tools::Execute::HANDED_OVER", file: "samagotchi/tools/execute"),
|
|
38
38
|
Allowed.new(name: "Samagotchi::Tools::Execute.timeout_seconds", file: "samagotchi/tools/execute"),
|
|
39
|
-
Allowed.new(name: "Samagotchi::
|
|
40
|
-
Allowed.new(name: "Samagotchi::
|
|
39
|
+
Allowed.new(name: "Samagotchi::TaskFiles::TASKS_DIR", file: "samagotchi/task_files"),
|
|
40
|
+
Allowed.new(name: "Samagotchi::TaskFiles::EXIT_CODE_FILENAME", file: "samagotchi/task_files"),
|
|
41
41
|
Allowed.new(name: "Samagotchi::AtomicFile.write", file: "samagotchi/atomic_file"),
|
|
42
42
|
Allowed.new(name: "Samagotchi::Log.warn", file: "samagotchi/log"),
|
|
43
43
|
Allowed.new(name: "Samagotchi::Log.debug", file: "samagotchi/log"),
|
|
@@ -99,7 +99,7 @@ module Samagotchi
|
|
|
99
99
|
# @return [Plugin::Registries]
|
|
100
100
|
def registries(**fields)
|
|
101
101
|
Plugin::Registries.new(
|
|
102
|
-
commands:
|
|
102
|
+
commands: SessionCommandCatalog.register_builtins(Commands::Registry.new), tools: Tools::Builtins.registry,
|
|
103
103
|
services: Plugin::Services.new, stage_tools: ->(*) {}, toolkits: [], tool_index: Tools::ToolIndex.new,
|
|
104
104
|
peer_sources: PeerSources.new, prompt_sections: Plugin::PromptSections.new,
|
|
105
105
|
judgments: SystemOne::Judgments.new, **fields
|
|
@@ -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?
|