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
|
@@ -14,6 +14,7 @@ require_relative "../client_id"
|
|
|
14
14
|
require_relative "../children_status"
|
|
15
15
|
require_relative "../session_metrics"
|
|
16
16
|
require_relative "../version"
|
|
17
|
+
require_relative "request_body"
|
|
17
18
|
require_relative "session_hub"
|
|
18
19
|
|
|
19
20
|
module Samagotchi
|
|
@@ -63,8 +64,9 @@ module Samagotchi
|
|
|
63
64
|
end
|
|
64
65
|
|
|
65
66
|
# The body as a Hash ({} when there is none), or nil when it isn't one.
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
# Read up to +limit+ bytes (RequestBody: over it is the 413).
|
|
68
|
+
def body_hash(req, limit = RequestBody::SMALL_BODY_LIMIT)
|
|
69
|
+
raw = request_body(req, limit)
|
|
68
70
|
return {} if raw.to_s.strip.empty?
|
|
69
71
|
|
|
70
72
|
parsed = parse_json(raw)
|
|
@@ -80,12 +82,12 @@ module Samagotchi
|
|
|
80
82
|
# where input for it goes (SessionAccess::Local#head): 200 {id, asked,
|
|
81
83
|
# via}, id the chain's newest link of a continued one.
|
|
82
84
|
def handle_resolve(req)
|
|
83
|
-
given = req.
|
|
85
|
+
given = req.GET["id"].to_s
|
|
84
86
|
return session_not_found(given) unless Session.valid_id?(given)
|
|
85
87
|
return participant_resolve(principal(req).grant, given) unless principal(req).owner?
|
|
86
88
|
|
|
87
89
|
id = session_access.resolve(given)
|
|
88
|
-
return json_response(200, { id: id }) unless truthy_param?(req.
|
|
90
|
+
return json_response(200, { id: id }) unless truthy_param?(req.GET["head"])
|
|
89
91
|
|
|
90
92
|
head = session_access.head(id)
|
|
91
93
|
json_response(200, { id: head.id, asked: head.asked, via: head.via.to_s })
|
|
@@ -122,18 +124,18 @@ module Samagotchi
|
|
|
122
124
|
# folder or below), live=1, archived=1, tests=0 (leave test runs out),
|
|
123
125
|
# sort, order, limit. An array, newest first by default.
|
|
124
126
|
def handle_summaries(req)
|
|
125
|
-
dir, error = scope_dir(req.
|
|
127
|
+
dir, error = scope_dir(req.GET["dir"])
|
|
126
128
|
return error if error
|
|
127
129
|
|
|
128
|
-
cwd = req.
|
|
130
|
+
cwd = req.GET["cwd"].to_s
|
|
129
131
|
cwd = nil if cwd.strip.empty?
|
|
130
132
|
return error_response(400, "invalid_cwd", "cwd is an absolute path: #{cwd[0, 200]}") if cwd && !cwd.start_with?("/")
|
|
131
133
|
|
|
132
134
|
rows = session_access.summaries(
|
|
133
|
-
live: truthy_param?(req.
|
|
134
|
-
include_tests: !%w[0 false no].include?(req.
|
|
135
|
-
project_root: dir && ProjectScope.root_for(dir), include_archived: truthy_param?(req.
|
|
136
|
-
sort: sanitize_sort(req.
|
|
135
|
+
live: truthy_param?(req.GET["live"]), cwd: cwd, limit: sanitize_limit(req.GET["limit"]),
|
|
136
|
+
include_tests: !%w[0 false no].include?(req.GET["tests"].to_s.strip.downcase),
|
|
137
|
+
project_root: dir && ProjectScope.root_for(dir), include_archived: truthy_param?(req.GET["archived"]),
|
|
138
|
+
sort: sanitize_sort(req.GET["sort"]), order: sanitize_order(req.GET["order"])
|
|
137
139
|
)
|
|
138
140
|
json_response(200, rows.map(&:to_summary_h))
|
|
139
141
|
end
|
|
@@ -465,7 +467,7 @@ module Samagotchi
|
|
|
465
467
|
# which an older Remote reads as not_push, nor "continued", which it
|
|
466
468
|
# reads as a continue's refusal); 400 invalid_text.
|
|
467
469
|
def handle_context_push(req, id, name)
|
|
468
|
-
body = body_hash(req) or return error_response(400, "invalid_json", "invalid JSON body")
|
|
470
|
+
body = body_hash(req, RequestBody::CONTEXT_PUSH_BODY_LIMIT) or return error_response(400, "invalid_json", "invalid JSON body")
|
|
469
471
|
return error_response(400, "missing_fields", "text is required") unless body["text"].is_a?(String)
|
|
470
472
|
|
|
471
473
|
fetched = begin
|
|
@@ -6,8 +6,9 @@ require_relative "../delivery"
|
|
|
6
6
|
require_relative "../image_store"
|
|
7
7
|
require_relative "../prompt_history"
|
|
8
8
|
require_relative "../session"
|
|
9
|
-
require_relative "../
|
|
9
|
+
require_relative "../session_command_catalog"
|
|
10
10
|
require_relative "../session_manager"
|
|
11
|
+
require_relative "request_body"
|
|
11
12
|
|
|
12
13
|
module Samagotchi
|
|
13
14
|
module Web
|
|
@@ -49,7 +50,8 @@ module Samagotchi
|
|
|
49
50
|
session = @session_class.load(id, state_dir: default_state_dir) rescue nil
|
|
50
51
|
return session_not_found(id) unless session
|
|
51
52
|
|
|
52
|
-
|
|
53
|
+
# Relayed to the Bridge, which takes up to its MAX_BODY_BYTES.
|
|
54
|
+
body = parse_json(request_body(req, RequestBody::BRIDGE_BODY_LIMIT))
|
|
53
55
|
return error_response(400, "invalid_json", "invalid JSON body") unless body.is_a?(Hash)
|
|
54
56
|
|
|
55
57
|
qid = body["id"]
|
|
@@ -155,7 +157,7 @@ module Samagotchi
|
|
|
155
157
|
# One of this chi's own commands the worker doesn't know: it runs an
|
|
156
158
|
# older chi. command: which one, so a remote TUI names it as its
|
|
157
159
|
# Bridge's own 400 unknown_command would (WebBridgeClient).
|
|
158
|
-
name = reply.json&.dig("error") == "unknown_command" &&
|
|
160
|
+
name = reply.json&.dig("error") == "unknown_command" && SessionCommandCatalog.builtin_name(line)
|
|
159
161
|
next older_worker_command(id, name) if name
|
|
160
162
|
|
|
161
163
|
error_response(400, reply.json&.dig("error") || "unknown_command", reply_detail(reply, "not a session command"))
|
|
@@ -181,7 +183,10 @@ module Samagotchi
|
|
|
181
183
|
end
|
|
182
184
|
|
|
183
185
|
def handle_turn(req, id)
|
|
184
|
-
|
|
186
|
+
# A participant's turn is relayed to the Bridge, which takes up to
|
|
187
|
+
# its MAX_BODY_BYTES; the owner's may be a big piped chi send.
|
|
188
|
+
cap = principal(req).owner? ? RequestBody::OWNER_TURN_BODY_LIMIT : RequestBody::BRIDGE_BODY_LIMIT
|
|
189
|
+
body = parse_json(request_body(req, cap))
|
|
185
190
|
unless body.is_a?(Hash)
|
|
186
191
|
return error_response(400, "invalid_json", "invalid JSON body")
|
|
187
192
|
end
|
|
@@ -279,7 +284,7 @@ module Samagotchi
|
|
|
279
284
|
return participant_image_upload(req, id, session_dir) unless principal(req).owner?
|
|
280
285
|
|
|
281
286
|
bytes = image_upload_bytes(req)
|
|
282
|
-
return error_response(413, "too_large",
|
|
287
|
+
return error_response(413, "too_large", bytes.message) if bytes.is_a?(RequestBody::BodyTooLarge)
|
|
283
288
|
|
|
284
289
|
ref = ImageStore.ingest(session_dir, bytes: bytes, name: upload_name(req), source: "user")
|
|
285
290
|
json_response(201, ref)
|
|
@@ -287,21 +292,22 @@ module Samagotchi
|
|
|
287
292
|
error_response(422, "bad_image", e.message)
|
|
288
293
|
end
|
|
289
294
|
|
|
290
|
-
# An upload's body, or
|
|
291
|
-
# its Content-Length or what came).
|
|
295
|
+
# An upload's body, or the BodyTooLarge when it is over
|
|
296
|
+
# MAX_IMAGE_UPLOAD_BYTES (by its Content-Length or what came).
|
|
297
|
+
# Rescued here, not left to App#route's 413: the participant's path
|
|
298
|
+
# (ParticipantImages#participant_upload) audits its refusal as
|
|
299
|
+
# too_large, and its own rescue StandardError would audit a raised one
|
|
300
|
+
# as internal_error.
|
|
292
301
|
def image_upload_bytes(req)
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
bytes.bytesize > MAX_IMAGE_UPLOAD_BYTES ? nil : bytes
|
|
302
|
+
request_body(req, MAX_IMAGE_UPLOAD_BYTES, what: "an image").b
|
|
303
|
+
rescue RequestBody::BodyTooLarge => e
|
|
304
|
+
e
|
|
297
305
|
end
|
|
298
306
|
|
|
299
|
-
def image_too_large_detail = "an image may be up to #{MAX_IMAGE_UPLOAD_BYTES / 1024 / 1024} MB"
|
|
300
|
-
|
|
301
307
|
# An upload's ?name=, a base name without control characters; "image"
|
|
302
308
|
# without one.
|
|
303
309
|
def upload_name(req)
|
|
304
|
-
name = File.basename(req.
|
|
310
|
+
name = File.basename(req.GET["name"].to_s).gsub(/[[:cntrl:]]/, "")[0, 120]
|
|
305
311
|
name.empty? ? "image" : name
|
|
306
312
|
end
|
|
307
313
|
|
|
@@ -517,15 +523,68 @@ module Samagotchi
|
|
|
517
523
|
# worker_running, as chi sessions delete without --force. A one-turn chi run's
|
|
518
524
|
# session is always refused.
|
|
519
525
|
def handle_delete(req, id)
|
|
520
|
-
result = @manager.delete_session(id, state_dir: @state_dir, stop: truthy_param?(req.
|
|
521
|
-
wait: STOP_WAIT_SECONDS)
|
|
522
|
-
|
|
523
|
-
json_response(200, { status: "deleted", session_id: result[:id], stopped: result[:stopped]
|
|
526
|
+
result = @manager.delete_session(id, state_dir: @state_dir, stop: truthy_param?(req.GET["force"]),
|
|
527
|
+
wait: STOP_WAIT_SECONDS, revive_previous: true, refuse_continuing: true)
|
|
528
|
+
touch_deleted(result[:id], result)
|
|
529
|
+
json_response(200, { status: "deleted", session_id: result[:id], stopped: result[:stopped],
|
|
530
|
+
unarchived: Array(result[:unarchived]), moved_back: Array(result[:moved_back]),
|
|
531
|
+
deleted: Array(result[:deleted] || [result[:id]]), left_running: Array(result[:left_running]) })
|
|
524
532
|
rescue SessionManager::OwnedByTUI => e
|
|
525
533
|
owned_by_one_shot(id, e)
|
|
526
534
|
rescue SessionManager::DeleteRefused => e
|
|
527
|
-
|
|
528
|
-
|
|
535
|
+
delete_refused(e)
|
|
536
|
+
end
|
|
537
|
+
|
|
538
|
+
# DELETE /api/sessions/:id/chain?force=: every link of the chain with
|
|
539
|
+
# their delegates (SessionManager.delete_chain). Query-only.
|
|
540
|
+
def handle_delete_chain(req, id)
|
|
541
|
+
result = @manager.delete_chain(id, state_dir: @state_dir, stop: truthy_param?(req.GET["force"]),
|
|
542
|
+
wait: STOP_WAIT_SECONDS)
|
|
543
|
+
touch_deleted(id, result)
|
|
544
|
+
json_response(200, { status: "deleted", session_id: id, deleted: result[:deleted], left: result[:left],
|
|
545
|
+
left_running: result[:left_running], unarchived: result[:unarchived],
|
|
546
|
+
stopped: result[:stopped], cut_off: result[:cut_off], refusal: result[:refusal] })
|
|
547
|
+
rescue SessionManager::OwnedByTUI => e
|
|
548
|
+
owned_by_one_shot(e.session_id, e)
|
|
549
|
+
rescue SessionManager::DeleteRefused => e
|
|
550
|
+
delete_refused(e)
|
|
551
|
+
end
|
|
552
|
+
|
|
553
|
+
# GET /api/sessions/:id/delete_plan: what the delete sheet shows for a
|
|
554
|
+
# chained session (SessionChain::Delete::Preview: the plan and the
|
|
555
|
+
# refusals the delete itself runs), {chained: false} for one in no
|
|
556
|
+
# chain. One session listing walk per call; the page asks only for a
|
|
557
|
+
# chained session, as the sheet opens. No query or body read; no-store
|
|
558
|
+
# (json_response's).
|
|
559
|
+
def handle_delete_plan(_req, id)
|
|
560
|
+
return unknown_session(id) unless Session.exist?(id, state_dir: @state_dir || Session.default_state_dir)
|
|
561
|
+
|
|
562
|
+
require_relative "../session_chain/delete_preview"
|
|
563
|
+
json_response(200, SessionChain::Delete::Preview.call(id, state_dir: @state_dir))
|
|
564
|
+
end
|
|
565
|
+
|
|
566
|
+
# The hub hears every session a delete changed: deleted, back in the
|
|
567
|
+
# lists, moved back to the previous link, left running without a parent.
|
|
568
|
+
def touch_deleted(id, result)
|
|
569
|
+
return unless @hub
|
|
570
|
+
|
|
571
|
+
ids = [id, *result[:deleted], *result[:unarchived], *result[:moved_back], *result[:left_running]]
|
|
572
|
+
ids.compact.uniq.each { |sid| @hub.touch(sid) }
|
|
573
|
+
end
|
|
574
|
+
|
|
575
|
+
# 409 with the refusal's reason as its code, and what a remote client
|
|
576
|
+
# raises it again from (ids, the schedule).
|
|
577
|
+
def delete_refused(error)
|
|
578
|
+
detail = error.reason == :still_stopping ? "#{error.message}; try again in a moment" : error.message
|
|
579
|
+
# A moved delegate that can't go back: whether the page can stop it
|
|
580
|
+
# (its "Stop its worker, then delete"), as the refusal saw it.
|
|
581
|
+
if error.reason == :delegate_unmovable
|
|
582
|
+
require_relative "../session_chain/delete"
|
|
583
|
+
stoppable = SessionChain::Delete.stoppable?(error.ids, @state_dir || Session.default_state_dir)
|
|
584
|
+
end
|
|
585
|
+
refusal_response(409, error.reason.to_s, error, detail: detail, session_id: error.session_id,
|
|
586
|
+
reason: error.reason.to_s, ids: error.ids.empty? ? nil : error.ids,
|
|
587
|
+
schedule_id: error.schedule_id, stoppable: stoppable)
|
|
529
588
|
end
|
|
530
589
|
|
|
531
590
|
# 409 owned_by_tui in the words a refused archive, delete or continue
|
|
@@ -17,6 +17,7 @@ require_relative "../session_setup"
|
|
|
17
17
|
require_relative "../thinking"
|
|
18
18
|
require_relative "../toolkit"
|
|
19
19
|
require_relative "../turn_flow"
|
|
20
|
+
require_relative "request_body"
|
|
20
21
|
|
|
21
22
|
module Samagotchi
|
|
22
23
|
module Web
|
|
@@ -40,7 +41,7 @@ module Samagotchi
|
|
|
40
41
|
private
|
|
41
42
|
|
|
42
43
|
def handle_create(req)
|
|
43
|
-
body = parse_json(request_body(req))
|
|
44
|
+
body = parse_json(request_body(req, RequestBody::OWNER_TURN_BODY_LIMIT))
|
|
44
45
|
unless body.is_a?(Hash)
|
|
45
46
|
return error_response(400, "invalid_json", "invalid JSON body")
|
|
46
47
|
end
|
|
@@ -12,7 +12,7 @@ require_relative "../objectives"
|
|
|
12
12
|
require_relative "../output_formatter"
|
|
13
13
|
require_relative "../question_asked"
|
|
14
14
|
require_relative "../guardrails/approvals"
|
|
15
|
-
require_relative "../
|
|
15
|
+
require_relative "../session_command_catalog"
|
|
16
16
|
require_relative "../session_metrics"
|
|
17
17
|
require_relative "../session_setting"
|
|
18
18
|
require_relative "../system_one/log"
|
|
@@ -53,10 +53,10 @@ module Samagotchi
|
|
|
53
53
|
return participant_show_read(req, id) unless principal(req).owner?
|
|
54
54
|
|
|
55
55
|
# The page's light re-reads: never the whole conversation.
|
|
56
|
-
return handle_cards_read(id) if req.
|
|
57
|
-
return handle_tail_read(req, id) if req.
|
|
58
|
-
return handle_timing_read(id) if req.
|
|
59
|
-
return handle_brief_read(id) if req.
|
|
56
|
+
return handle_cards_read(id) if req.GET["cards"] == "1"
|
|
57
|
+
return handle_tail_read(req, id) if req.GET["tail"] == "1"
|
|
58
|
+
return handle_timing_read(id) if req.GET["timing"] == "1"
|
|
59
|
+
return handle_brief_read(id) if req.GET["brief"] == "1"
|
|
60
60
|
|
|
61
61
|
session = @session_class.load(id, state_dir: default_state_dir)
|
|
62
62
|
# A tab opened at a chi scratch session's id: its terminal's alone.
|
|
@@ -141,7 +141,7 @@ module Samagotchi
|
|
|
141
141
|
cards: cards_for_display(raw_cards, cwd: session.working_directory),
|
|
142
142
|
# The composer's / autocomplete; the built-ins until a worker
|
|
143
143
|
# names its plugins' too.
|
|
144
|
-
commands: turn_snapshot&.fetch("commands", nil) ||
|
|
144
|
+
commands: turn_snapshot&.fetch("commands", nil) || SessionCommandCatalog.builtin_registry.listing,
|
|
145
145
|
markdown_warning: @markdown_renderer.warning,
|
|
146
146
|
markdown_tip: @markdown_renderer.tip,
|
|
147
147
|
**viewer_capabilities(req),
|
|
@@ -317,7 +317,7 @@ module Samagotchi
|
|
|
317
317
|
def handle_tail_read(req, id)
|
|
318
318
|
return session_not_found(id) unless session_exists?(id)
|
|
319
319
|
|
|
320
|
-
turn_id = req.
|
|
320
|
+
turn_id = req.GET["turn_id"].to_s.strip
|
|
321
321
|
turn_id = nil if turn_id.empty?
|
|
322
322
|
tail = live_tail(id, turn_id: turn_id)
|
|
323
323
|
state = tail && tail["session_state_snapshot"]
|
|
@@ -408,7 +408,7 @@ module Samagotchi
|
|
|
408
408
|
|
|
409
409
|
def handle_output(req, id)
|
|
410
410
|
# Query ?since= may be an ISO8601 time or numeric mtime; we treat it as Time parse.
|
|
411
|
-
since_param = req.
|
|
411
|
+
since_param = req.GET["since"]
|
|
412
412
|
since_time = parse_since(since_param)
|
|
413
413
|
session = @session_class.load(id, state_dir: default_state_dir)
|
|
414
414
|
raw = @manager.read_responses(id, since_time: since_time, state_dir: @state_dir)
|
|
@@ -58,12 +58,17 @@ module Samagotchi
|
|
|
58
58
|
# a message sent while their own turn runs goes in at its next step
|
|
59
59
|
# (a worker with Delivery::OWN_TURN_STEER_FEATURE); +revise_own_turn+:
|
|
60
60
|
# Revise on the answer to their own message with only their own turns
|
|
61
|
-
# after it (POST …/turn with revises, ParticipantRevise)
|
|
61
|
+
# after it (POST …/turn with revises, ParticipantRevise);
|
|
62
|
+
# +own_prompt_history+: ↑/↓ over their own accepted messages in this
|
|
63
|
+
# session, redacted (GET …/prompt_history, ParticipantHistory; never the
|
|
64
|
+
# owner's prompt_history, the machine-wide file). And of the owner's,
|
|
62
65
|
# those a participant's route serves filtered: +working_set+ (GET
|
|
63
66
|
# …/working_set, the project's files only) and +images+ (POST …/images
|
|
64
67
|
# within their cap and quota; GET …/images/<name> only for an image
|
|
65
68
|
# they uploaded; their turn takes only those: ParticipantImages).
|
|
66
|
-
Viewer::PARTICIPANT_CAPABILITIES = %w[
|
|
69
|
+
Viewer::PARTICIPANT_CAPABILITIES = %w[
|
|
70
|
+
send stop_own_turn steer_own_turn revise_own_turn own_prompt_history working_set images
|
|
71
|
+
].freeze
|
|
67
72
|
|
|
68
73
|
Viewer::OWNER = Viewer.new(kind: "owner", id: nil, name: nil, can: Viewer::CAPABILITIES)
|
|
69
74
|
end
|
|
@@ -53,8 +53,8 @@ module Samagotchi
|
|
|
53
53
|
# truncate_at_bytes, the ToolRunner cap). +now+ (a memory): what its
|
|
54
54
|
# latest read would answer now and the diff (WorkingSet.memory_now).
|
|
55
55
|
def handle_working_set_item(req, id)
|
|
56
|
-
kind = req.
|
|
57
|
-
key = req.
|
|
56
|
+
kind = req.GET["kind"].to_s
|
|
57
|
+
key = req.GET["key"].to_s
|
|
58
58
|
unless [WorkingSet::FILE, WorkingSet::MEMORY, WorkingSet::URL].include?(kind) && !key.strip.empty?
|
|
59
59
|
return error_response(400, "invalid_item", "expected kind (file, memory or url) and key")
|
|
60
60
|
end
|
|
@@ -63,7 +63,7 @@ module Samagotchi
|
|
|
63
63
|
source = working_set_source(bridge_get_json(id, "snapshot"), session)
|
|
64
64
|
timeline = WorkingSet.timeline_of(source.messages, kind: kind, key: key, strategy: source.strategy, cwd: source.cwd)
|
|
65
65
|
body = timeline.to_h
|
|
66
|
-
if req.
|
|
66
|
+
if req.GET["now"] == "1" && kind == WorkingSet::MEMORY
|
|
67
67
|
body[:now] = WorkingSet.memory_now(source.messages, key: key, strategy: source.strategy, cwd: source.cwd,
|
|
68
68
|
root: MemoryPaths.system_dir)&.to_h
|
|
69
69
|
end
|