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
|
@@ -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
|
|
|
@@ -8,7 +8,10 @@ require_relative "../process_group"
|
|
|
8
8
|
require_relative "leftovers"
|
|
9
9
|
require_relative "output_guardrails"
|
|
10
10
|
require_relative "shell"
|
|
11
|
+
require_relative "../spawn_env"
|
|
12
|
+
require_relative "../task_files"
|
|
11
13
|
require_relative "task_runtime"
|
|
14
|
+
require_relative "../tool_names"
|
|
12
15
|
|
|
13
16
|
module Samagotchi
|
|
14
17
|
module Tools
|
|
@@ -21,22 +24,19 @@ module Samagotchi
|
|
|
21
24
|
# <tool name="execute">bundle exec rspec spec/some_spec.rb --no-color</tool>
|
|
22
25
|
# <tool name="execute">ruby path/to/script.rb</tool>
|
|
23
26
|
class Execute
|
|
24
|
-
NAME =
|
|
27
|
+
NAME = ToolNames::Execute::NAME
|
|
25
28
|
TIMEOUT_SEC = 120
|
|
26
29
|
STOP_GRACE_SEC = 1.0
|
|
27
30
|
STOP_POLL_INTERVAL_SEC = 0.05
|
|
28
31
|
WAIT_SLICE_SEC = 0.2
|
|
29
|
-
|
|
30
|
-
#
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
# a parent stopping its delegate) canceled the turn: :session_stopped.
|
|
38
|
-
NOT_RUN_ON_SESSION_STOP = "Error: not run, the session was stopped"
|
|
39
|
-
STOPPED_BY_SESSION_STOP = "Error: command stopped as the session was stopped"
|
|
32
|
+
# What a stopped turn's command returns (ToolNames::Execute says which
|
|
33
|
+
# stop each is for). slow-commands looks them up here by reflection.
|
|
34
|
+
NOT_RUN_ON_STOP = ToolNames::Execute::NOT_RUN_ON_STOP
|
|
35
|
+
STOPPED_BY_USER = ToolNames::Execute::STOPPED_BY_USER
|
|
36
|
+
NOT_RUN_ON_SIGNAL = ToolNames::Execute::NOT_RUN_ON_SIGNAL
|
|
37
|
+
STOPPED_BY_SIGNAL = ToolNames::Execute::STOPPED_BY_SIGNAL
|
|
38
|
+
NOT_RUN_ON_SESSION_STOP = ToolNames::Execute::NOT_RUN_ON_SESSION_STOP
|
|
39
|
+
STOPPED_BY_SESSION_STOP = ToolNames::Execute::STOPPED_BY_SESSION_STOP
|
|
40
40
|
# The first words of a command killed at the limit in kill mode (hooks
|
|
41
41
|
# match on it).
|
|
42
42
|
TIMEOUT_PREFIX = "Error: command timed out after"
|
|
@@ -67,16 +67,10 @@ module Samagotchi
|
|
|
67
67
|
# record is gone or is older than RETENTION_DAYS.
|
|
68
68
|
ORPHAN_AGE_SEC = 24 * 3600
|
|
69
69
|
RETENTION_DAYS = 14
|
|
70
|
-
# The first words of a command
|
|
71
|
-
#
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
# form, "at the 120s limit".
|
|
75
|
-
HANDED_OVER = "Still running at the"
|
|
76
|
-
# What follows HANDED_OVER on the first line, as regexp source: "120s
|
|
77
|
-
# limit:" (the limit) or "4s mark:" (a message from the user ended the
|
|
78
|
-
# wait early). Every matcher of the line builds on it.
|
|
79
|
-
HANDED_OVER_AFTER = "(?:\\d+s limit|\\d+s mark):"
|
|
70
|
+
# The first words of a command handed over as a task, and what follows
|
|
71
|
+
# them on that line as regexp source (ToolNames::Execute says more).
|
|
72
|
+
HANDED_OVER = ToolNames::Execute::HANDED_OVER
|
|
73
|
+
HANDED_OVER_AFTER = ToolNames::Execute::HANDED_OVER_AFTER
|
|
80
74
|
# A message from the user waiting for the turn hands a command over
|
|
81
75
|
# early, but never before it has run this long: a short command ends
|
|
82
76
|
# on its own first, and its result is the better answer.
|
|
@@ -104,7 +98,7 @@ module Samagotchi
|
|
|
104
98
|
# instead of the user)
|
|
105
99
|
# @param env [Hash, nil] added to the command's environment, over
|
|
106
100
|
# chi's Ruby/Bundler variables scrubbed as task_create scrubs them
|
|
107
|
-
# (
|
|
101
|
+
# (SpawnEnv.sanitized_spawn_env); chi's callers build it, so it
|
|
108
102
|
# may set those keys (task_create refuses them from the model)
|
|
109
103
|
# @param on_timeout [Symbol, String, nil] :task or :kill (ON_TIMEOUT);
|
|
110
104
|
# nil reads execute.on_timeout
|
|
@@ -158,8 +152,8 @@ module Samagotchi
|
|
|
158
152
|
def self.not_run(stop_reason) = NOT_RUN.fetch(stop_reason.call, NOT_RUN_ON_STOP)
|
|
159
153
|
|
|
160
154
|
# The texts above by the stop's reason; any other is the user's Stop.
|
|
161
|
-
NOT_RUN =
|
|
162
|
-
STOPPED_BY =
|
|
155
|
+
NOT_RUN = ToolNames::Execute::NOT_RUN
|
|
156
|
+
STOPPED_BY = ToolNames::Execute::STOPPED_BY
|
|
163
157
|
|
|
164
158
|
# execute.on_timeout, or the caller's: :task (the default) or :kill.
|
|
165
159
|
def self.on_timeout_mode(value)
|
|
@@ -203,7 +197,7 @@ module Samagotchi
|
|
|
203
197
|
dir = File.join(logs_root, id)
|
|
204
198
|
FileUtils.mkdir_p(dir)
|
|
205
199
|
logs = [File.join(dir, STDOUT_LOG), File.join(dir, STDERR_LOG)]
|
|
206
|
-
exit_code_path = File.join(dir,
|
|
200
|
+
exit_code_path = File.join(dir, TaskFiles::EXIT_CODE_FILENAME)
|
|
207
201
|
begin
|
|
208
202
|
pid = spawn_logged(command, env: env, cwd: cwd, logs: logs, exit_code_path: exit_code_path)
|
|
209
203
|
rescue StandardError => e
|
|
@@ -309,7 +303,7 @@ module Samagotchi
|
|
|
309
303
|
# file, and each write lands at the end.
|
|
310
304
|
ios = logs.map { |path| File.open(path, "a") }
|
|
311
305
|
ios.each { |io| io.flock(File::LOCK_SH) }
|
|
312
|
-
ProcessGroup.spawn(
|
|
306
|
+
ProcessGroup.spawn(SpawnEnv.sanitized_spawn_env.merge(env || {}), *Shell.argv(TaskRuntime.wrapped_shell_command(command, exit_code_path)),
|
|
313
307
|
chdir: cwd, in: File::NULL, out: ios[0], err: ios[1])
|
|
314
308
|
ensure
|
|
315
309
|
ios&.each(&:close)
|
|
@@ -360,7 +354,7 @@ module Samagotchi
|
|
|
360
354
|
record, error = TaskRuntime.adopt(task)
|
|
361
355
|
return nil if error
|
|
362
356
|
|
|
363
|
-
File.write(File.join(dir, BACK_POINTER), File.expand_path(
|
|
357
|
+
File.write(File.join(dir, BACK_POINTER), File.expand_path(TaskFiles.metadata_path(record.id)))
|
|
364
358
|
TaskRuntime.record_exit_status(waiter, record.exit_code_path, task_id: record.id)
|
|
365
359
|
# Ended between the deadline and the adopt: the record says how.
|
|
366
360
|
TaskRuntime.get_record(record.id) unless waiter.alive?
|
|
@@ -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
|
|
@@ -12,7 +13,7 @@ module Samagotchi
|
|
|
12
13
|
# the handler's kctx). This reads the call: models write lists as JSON,
|
|
13
14
|
# as a JSON string, or as words, so every id form is taken.
|
|
14
15
|
class ForgetOutputs
|
|
15
|
-
NAME =
|
|
16
|
+
NAME = ToolNames::ForgetOutputs::NAME
|
|
16
17
|
|
|
17
18
|
def self.name = NAME
|
|
18
19
|
|
|
@@ -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
|
# Lists all active registered reminders.
|
|
8
9
|
class ListReminders
|
|
9
|
-
NAME =
|
|
10
|
+
NAME = ToolNames::ListReminders::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
|
# The durable schedules of this session's chain (docs/scheduling.md): id,
|
|
@@ -8,7 +10,7 @@ module Samagotchi
|
|
|
8
10
|
# machine-wide view. Schedules is required inside the call, so the testing
|
|
9
11
|
# kit does not pay for the session lifecycle at load time.
|
|
10
12
|
class ListSchedules
|
|
11
|
-
NAME =
|
|
13
|
+
NAME = ToolNames::ListSchedules::NAME
|
|
12
14
|
|
|
13
15
|
def self.name = NAME
|
|
14
16
|
|
|
@@ -4,6 +4,7 @@ require_relative "../paths"
|
|
|
4
4
|
require_relative "../project_scope"
|
|
5
5
|
require_relative "../session"
|
|
6
6
|
require_relative "peers"
|
|
7
|
+
require_relative "../tool_names"
|
|
7
8
|
|
|
8
9
|
module Samagotchi
|
|
9
10
|
# Loaded on first use: this autoload keeps SessionManager and its ~80
|
|
@@ -18,7 +19,7 @@ module Samagotchi
|
|
|
18
19
|
# they are cut short and labelled as such. A session this one delegated
|
|
19
20
|
# is marked child, the one that delegated this one parent.
|
|
20
21
|
class ListSessions
|
|
21
|
-
NAME =
|
|
22
|
+
NAME = ToolNames::ListSessions::NAME
|
|
22
23
|
LIMIT = 20
|
|
23
24
|
|
|
24
25
|
def self.name = NAME
|
|
@@ -7,6 +7,7 @@ require_relative "../atomic_file"
|
|
|
7
7
|
require_relative "../memory_orphans"
|
|
8
8
|
require_relative "../memory_paths"
|
|
9
9
|
require_relative "../model_match"
|
|
10
|
+
require_relative "../tool_names"
|
|
10
11
|
|
|
11
12
|
module Samagotchi
|
|
12
13
|
module Tools
|
|
@@ -19,7 +20,7 @@ module Samagotchi
|
|
|
19
20
|
# When scope is omitted, reads from project first and falls back to system.
|
|
20
21
|
# Usage: call("entry_name", scope: "project"|"system"|nil)
|
|
21
22
|
class MemoryRead
|
|
22
|
-
NAME =
|
|
23
|
+
NAME = ToolNames::MemoryRead::NAME
|
|
23
24
|
|
|
24
25
|
def self.name = NAME
|
|
25
26
|
|
|
@@ -223,7 +224,7 @@ module Samagotchi
|
|
|
223
224
|
# Passing path: "index" writes index.md verbatim (no index maintenance).
|
|
224
225
|
# Usage: call(content, path: "entry_name", scope: "project"|"system", description: "…")
|
|
225
226
|
class MemoryWrite
|
|
226
|
-
NAME =
|
|
227
|
+
NAME = ToolNames::MemoryWrite::NAME
|
|
227
228
|
|
|
228
229
|
def self.name = NAME
|
|
229
230
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "../tool_response"
|
|
4
|
+
require_relative "../tool_names"
|
|
4
5
|
|
|
5
6
|
module Samagotchi
|
|
6
7
|
# Read at a call only: the builtins' file list loads this, Session not with it.
|
|
@@ -15,9 +16,9 @@ module Samagotchi
|
|
|
15
16
|
# action being the /objectives line; the model never changes the list by
|
|
16
17
|
# itself. See docs/internals/objectives.md.
|
|
17
18
|
class ObjectivesTool
|
|
18
|
-
NAME =
|
|
19
|
+
NAME = ToolNames::ObjectivesTool::NAME
|
|
19
20
|
MOVE = "move"
|
|
20
|
-
PROPOSE =
|
|
21
|
+
PROPOSE = ToolNames::ObjectivesTool::PROPOSE
|
|
21
22
|
PROPOSED = "Proposed %s. The list is unchanged: the user sees a card and applies it or not."
|
|
22
23
|
RECORDED = "Recorded a move on %s."
|
|
23
24
|
EDITED_BY_USER = "The user edits the list with /objectives."
|
|
@@ -25,8 +26,8 @@ module Samagotchi
|
|
|
25
26
|
# A move's state: where the objective stands in the agent's view. DONE is
|
|
26
27
|
# its claim, never a status change (the user marks done).
|
|
27
28
|
PROGRESS = "progress"
|
|
28
|
-
BLOCKED =
|
|
29
|
-
DONE =
|
|
29
|
+
BLOCKED = ToolNames::ObjectivesTool::BLOCKED
|
|
30
|
+
DONE = ToolNames::ObjectivesTool::DONE
|
|
30
31
|
STATES = [PROGRESS, BLOCKED, DONE].freeze
|
|
31
32
|
|
|
32
33
|
def self.name = NAME
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
require_relative "output_guardrails"
|
|
4
4
|
require_relative "tool_path"
|
|
5
5
|
require_relative "../image_store"
|
|
6
|
+
require_relative "../tool_names"
|
|
6
7
|
|
|
7
8
|
module Samagotchi
|
|
8
9
|
module Tools
|
|
9
10
|
# Reads a file from disk and returns its contents as a string.
|
|
10
11
|
class Read
|
|
11
|
-
NAME =
|
|
12
|
+
NAME = ToolNames::Read::NAME
|
|
12
13
|
|
|
13
14
|
DEFAULT_HARD_MAX_BYTES = 2 * 1024 * 1024
|
|
14
15
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require "json"
|
|
4
4
|
require_relative "../reminder_store"
|
|
5
|
+
require_relative "../tool_names"
|
|
5
6
|
|
|
6
7
|
module Samagotchi
|
|
7
8
|
module Tools
|
|
@@ -12,7 +13,7 @@ module Samagotchi
|
|
|
12
13
|
# without blocking the main turn. The reminder fires when the agent is idle
|
|
13
14
|
# and a new turn is about to start.
|
|
14
15
|
class RegisterReminder
|
|
15
|
-
NAME =
|
|
16
|
+
NAME = ToolNames::RegisterReminder::NAME
|
|
16
17
|
|
|
17
18
|
def self.name = NAME
|
|
18
19
|
|
|
@@ -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
|
# Register a durable schedule for this session (docs/scheduling.md): a
|
|
@@ -9,7 +11,7 @@ module Samagotchi
|
|
|
9
11
|
# Unlike register_reminder, a schedule needs no live worker — a tick run by
|
|
10
12
|
# cron (or chi web's hub) wakes one — and it never holds an idle worker up.
|
|
11
13
|
class ScheduleTask
|
|
12
|
-
NAME =
|
|
14
|
+
NAME = ToolNames::ScheduleTask::NAME
|
|
13
15
|
|
|
14
16
|
def self.name = NAME
|
|
15
17
|
|
|
@@ -5,13 +5,14 @@ require_relative "../context_note"
|
|
|
5
5
|
require_relative "../session_inbox"
|
|
6
6
|
require_relative "../note_delivery"
|
|
7
7
|
require_relative "peers"
|
|
8
|
+
require_relative "../tool_names"
|
|
8
9
|
|
|
9
10
|
module Samagotchi
|
|
10
11
|
module Tools
|
|
11
12
|
# Tell another chi session something: a context note it sees on its next
|
|
12
13
|
# turn as background from this session. It never starts a turn there.
|
|
13
14
|
class SendNote
|
|
14
|
-
NAME =
|
|
15
|
+
NAME = ToolNames::SendNote::NAME
|
|
15
16
|
|
|
16
17
|
def self.name = NAME
|
|
17
18
|
|