samagotchi 0.172.1 → 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.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -1
  3. data/docs/architecture.md +16 -5
  4. data/docs/cli.md +2 -1
  5. data/docs/configuration.md +1 -1
  6. data/docs/internals/background-tasks.md +19 -6
  7. data/docs/internals/bridge.md +2 -2
  8. data/docs/internals/engine.md +2 -1
  9. data/docs/internals/participants.md +67 -9
  10. data/docs/internals/remote-sessions.md +1 -1
  11. data/docs/internals/web-frontend.md +11 -6
  12. data/docs/plugins.md +3 -1
  13. data/docs/sessions.md +2 -2
  14. data/docs/testing.md +26 -10
  15. data/lib/samagotchi/bridge.rb +3 -2
  16. data/lib/samagotchi/bundle_command/try/sandbox.rb +2 -2
  17. data/lib/samagotchi/bundles/core/manifest.yml +2 -2
  18. data/lib/samagotchi/bundles/slow-commands/manifest.yml +3 -3
  19. data/lib/samagotchi/bundles/slow-commands/plugin.rb +3 -3
  20. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  21. data/lib/samagotchi/engine/participants.rb +2 -2
  22. data/lib/samagotchi/engine.rb +0 -1
  23. data/lib/samagotchi/file_ref.rb +3 -5
  24. data/lib/samagotchi/guardrails/participant_refusal.rb +1 -1
  25. data/lib/samagotchi/memory_usage.rb +2 -1
  26. data/lib/samagotchi/message_parts.rb +5 -3
  27. data/lib/samagotchi/objectives_backing.rb +6 -10
  28. data/lib/samagotchi/parent_report.rb +1 -1
  29. data/lib/samagotchi/participant_prompts.rb +101 -0
  30. data/lib/samagotchi/participant_turn_mode.rb +1 -1
  31. data/lib/samagotchi/project_env.rb +7 -5
  32. data/lib/samagotchi/prompt_history.rb +2 -2
  33. data/lib/samagotchi/send_command/parent_gate.rb +2 -2
  34. data/lib/samagotchi/send_command.rb +4 -4
  35. data/lib/samagotchi/session_command_catalog.rb +210 -0
  36. data/lib/samagotchi/session_commands.rb +12 -183
  37. data/lib/samagotchi/session_manager/lifecycle.rb +5 -4
  38. data/lib/samagotchi/session_manager.rb +2 -1
  39. data/lib/samagotchi/session_stores.rb +2 -0
  40. data/lib/samagotchi/spawn_env.rb +75 -0
  41. data/lib/samagotchi/task_files.rb +51 -0
  42. data/lib/samagotchi/task_transcript.rb +67 -0
  43. data/lib/samagotchi/task_watch.rb +8 -6
  44. data/lib/samagotchi/terminal_ui/attached_loop/composer.rb +3 -3
  45. data/lib/samagotchi/terminal_ui/attached_loop/questions.rb +2 -2
  46. data/lib/samagotchi/terminal_ui/attached_loop.rb +3 -3
  47. data/lib/samagotchi/terminal_ui/input_support.rb +1 -1
  48. data/lib/samagotchi/testing/boundary.rb +5 -0
  49. data/lib/samagotchi/tool_activity.rb +63 -79
  50. data/lib/samagotchi/tool_names.rb +179 -0
  51. data/lib/samagotchi/tool_view.rb +3 -5
  52. data/lib/samagotchi/tools/ask_user_question.rb +2 -1
  53. data/lib/samagotchi/tools/builtins.rb +1 -1
  54. data/lib/samagotchi/tools/cancel_reminder.rb +2 -1
  55. data/lib/samagotchi/tools/cancel_schedule.rb +3 -1
  56. data/lib/samagotchi/tools/context_read.rb +2 -1
  57. data/lib/samagotchi/tools/delegate.rb +2 -1
  58. data/lib/samagotchi/tools/delegate_result.rb +2 -1
  59. data/lib/samagotchi/tools/edit.rb +2 -1
  60. data/lib/samagotchi/tools/execute.rb +22 -28
  61. data/lib/samagotchi/tools/forget_outputs.rb +2 -1
  62. data/lib/samagotchi/tools/list_reminders.rb +2 -1
  63. data/lib/samagotchi/tools/list_schedules.rb +3 -1
  64. data/lib/samagotchi/tools/list_sessions.rb +2 -1
  65. data/lib/samagotchi/tools/memory.rb +3 -2
  66. data/lib/samagotchi/tools/objectives_tool.rb +5 -4
  67. data/lib/samagotchi/tools/read.rb +2 -1
  68. data/lib/samagotchi/tools/register_reminder.rb +2 -1
  69. data/lib/samagotchi/tools/schedule_task.rb +3 -1
  70. data/lib/samagotchi/tools/send_note.rb +2 -1
  71. data/lib/samagotchi/tools/task_create.rb +2 -1
  72. data/lib/samagotchi/tools/task_get.rb +2 -1
  73. data/lib/samagotchi/tools/task_list.rb +2 -1
  74. data/lib/samagotchi/tools/task_runtime.rb +34 -154
  75. data/lib/samagotchi/tools/task_stop.rb +2 -1
  76. data/lib/samagotchi/tools/task_wait.rb +3 -2
  77. data/lib/samagotchi/tools/web_fetch.rb +2 -1
  78. data/lib/samagotchi/tools/write.rb +2 -1
  79. data/lib/samagotchi/turn_checkpoint.rb +1 -1
  80. data/lib/samagotchi/version.rb +1 -1
  81. data/lib/samagotchi/web/app.rb +38 -36
  82. data/lib/samagotchi/web/message_display.rb +1 -7
  83. data/lib/samagotchi/web/participant_access.rb +12 -4
  84. data/lib/samagotchi/web/participant_history.rb +68 -0
  85. data/lib/samagotchi/web/participant_images.rb +2 -1
  86. data/lib/samagotchi/web/participant_show.rb +5 -5
  87. data/lib/samagotchi/web/participants_admin.rb +1 -1
  88. data/lib/samagotchi/web/public/app.js +11 -9
  89. data/lib/samagotchi/web/public/card_registry.js +248 -0
  90. data/lib/samagotchi/web/public/cards_offscreen.js +3 -3
  91. data/lib/samagotchi/web/public/cards_place.js +8 -2
  92. data/lib/samagotchi/web/public/history_shape.js +1 -2
  93. data/lib/samagotchi/web/public/participant_history.js +27 -0
  94. data/lib/samagotchi/web/public/question_cards.js +1 -15
  95. data/lib/samagotchi/web/public/reload_check.js +90 -72
  96. data/lib/samagotchi/web/public/session_view.js +6 -1
  97. data/lib/samagotchi/web/public/stage_asking.js +6 -20
  98. data/lib/samagotchi/web/public/stage_view.js +2 -2
  99. data/lib/samagotchi/web/public/stage_waiting.js +4 -10
  100. data/lib/samagotchi/web/public/task_stop.js +1 -1
  101. data/lib/samagotchi/web/push_routes.rb +1 -1
  102. data/lib/samagotchi/web/reload_check_route.rb +5 -2
  103. data/lib/samagotchi/web/request_body.rb +72 -0
  104. data/lib/samagotchi/web/server.rb +70 -0
  105. data/lib/samagotchi/web/session_access_routes.rb +13 -11
  106. data/lib/samagotchi/web/session_control.rb +21 -15
  107. data/lib/samagotchi/web/session_create.rb +2 -1
  108. data/lib/samagotchi/web/session_show.rb +8 -8
  109. data/lib/samagotchi/web/viewer.rb +7 -2
  110. data/lib/samagotchi/web/working_set_routes.rb +3 -3
  111. data/lib/samagotchi/worker.rb +49 -182
  112. data/lib/samagotchi/worker_exit_claim.rb +102 -0
  113. data/lib/samagotchi/worker_participant_gate.rb +156 -0
  114. data/lib/samagotchi/worker_task_wakes.rb +2 -2
  115. metadata +13 -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
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "command_steps"
4
- require_relative "tools/execute"
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 = [Tools::Execute::NAME, Tools::TaskCreate::NAME].freeze
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 == Tools::TaskWait::NAME && call.is_a?(Hash)
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 = "ask_user_question"
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 (TaskRuntime::SANITIZED_ENV_KEYS).
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 = "cancel_reminder"
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 = "cancel_schedule"
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 = "context_read"
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 = "delegate"
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 = "delegate_result"
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 = "edit"
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 = "execute"
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
- NOT_RUN_ON_STOP = "Error: not run, the user stopped the turn"
30
- # The first words of a command the user's Stop killed.
31
- STOPPED_BY_USER = "Error: command stopped by the user"
32
- # The same two when a signal to chi (a worker's TERM, HUP or INT)
33
- # stopped the turn: its cancel reason is :signal.
34
- NOT_RUN_ON_SIGNAL = "Error: not run, a signal to chi stopped the turn"
35
- STOPPED_BY_SIGNAL = "Error: command stopped by a signal to chi"
36
- # The same two when a session stop (chi sessions stop, the web's stop,
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 still running and handed over as a
71
- # task (handed_over_line at the limit, early_handed_over_line for a
72
- # message). TaskRuntime.handed_over_id, the web's task_stop.js and the
73
- # slow-commands bundle match on them; the bundle reads only the limit's
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
- # (TaskRuntime.sanitized_spawn_env); chi's callers build it, so it
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 = { signal: NOT_RUN_ON_SIGNAL, session_stopped: NOT_RUN_ON_SESSION_STOP }.freeze
162
- STOPPED_BY = { signal: STOPPED_BY_SIGNAL, session_stopped: STOPPED_BY_SESSION_STOP }.freeze
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, TaskRuntime::EXIT_CODE_FILENAME)
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(TaskRuntime.sanitized_spawn_env.merge(env || {}), *Shell.argv(TaskRuntime.wrapped_shell_command(command, exit_code_path)),
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(TaskRuntime.metadata_path(record.id)))
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 = "forget_outputs"
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 = "list_reminders"
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 = "list_schedules"
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 = "list_sessions"
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 = "memory_read"
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 = "memory_write"
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 = "objectives"
19
+ NAME = ToolNames::ObjectivesTool::NAME
19
20
  MOVE = "move"
20
- PROPOSE = "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 = "blocked"
29
- DONE = "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 = "read"
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 = "register_reminder"
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 = "schedule_task"
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 = "send_note"
15
+ NAME = ToolNames::SendNote::NAME
15
16
 
16
17
  def self.name = NAME
17
18
 
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "task_runtime"
4
+ require_relative "../tool_names"
4
5
 
5
6
  module Samagotchi
6
7
  module Tools
7
8
  class TaskCreate
8
- NAME = "task_create"
9
+ NAME = ToolNames::TaskCreate::NAME
9
10
 
10
11
  def self.name = NAME
11
12