samagotchi 0.171.0 → 0.172.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 +33 -1
- data/bin/chi +6 -4
- data/docs/architecture.md +24 -7
- data/docs/bundles.md +4 -21
- data/docs/cli.md +50 -80
- data/docs/configuration.md +11 -13
- data/docs/context.md +5 -6
- data/docs/guardrails.md +57 -96
- data/docs/hooks.md +3 -4
- data/docs/internals/attached-context.md +6 -7
- data/docs/internals/background-tasks.md +4 -3
- data/docs/internals/bridge.md +29 -3
- data/docs/internals/engine.md +21 -9
- data/docs/internals/objectives.md +3 -5
- data/docs/internals/participants.md +118 -143
- data/docs/internals/prompt-caching.md +4 -5
- data/docs/internals/web-frontend.md +33 -14
- data/docs/internals/working-set.md +7 -5
- data/docs/memory.md +1 -1
- data/docs/plugins.md +2 -16
- data/docs/scheduling.md +1 -1
- data/docs/sessions.md +15 -49
- data/docs/sub-agent.md +2 -2
- data/docs/system-one.md +2 -2
- data/docs/testing.md +56 -7
- data/lib/samagotchi/bridge/card_store.rb +1 -0
- data/lib/samagotchi/bridge/sse_writer.rb +1 -0
- data/lib/samagotchi/bridge/turn_accumulator.rb +0 -1
- data/lib/samagotchi/bridge.rb +26 -9
- data/lib/samagotchi/bridge_client/event_stream.rb +2 -0
- data/lib/samagotchi/bundle_command/test_run.rb +1 -0
- data/lib/samagotchi/bundle_command/try/run.rb +1 -0
- data/lib/samagotchi/bundles/coordinator/manifest.yml +4 -5
- data/lib/samagotchi/bundles/coordinator/plugin.rb +6 -79
- data/lib/samagotchi/bundles/coordinator/skill_coordinator.md +1 -16
- data/lib/samagotchi/bundles/github-pr/manifest.yml +2 -2
- data/lib/samagotchi/bundles/github-pr/plugin.rb +0 -1
- data/lib/samagotchi/bundles/inline-widgets/manifest.yml +2 -2
- data/lib/samagotchi/bundles/inline-widgets/plugin.rb +4 -5
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/client_id.rb +126 -67
- data/lib/samagotchi/command_intake.rb +15 -3
- data/lib/samagotchi/compat.rb +6 -1
- data/lib/samagotchi/context_candidate_choice.rb +1 -3
- data/lib/samagotchi/context_candidates.rb +3 -4
- data/lib/samagotchi/continue_offer.rb +9 -2
- data/lib/samagotchi/delivery.rb +23 -12
- data/lib/samagotchi/empty_answer_error.rb +5 -0
- data/lib/samagotchi/engine/cards.rb +3 -0
- data/lib/samagotchi/engine/context_judge.rb +5 -3
- data/lib/samagotchi/engine/events.rb +4 -0
- data/lib/samagotchi/engine/hooks.rb +3 -0
- data/lib/samagotchi/engine/messages.rb +5 -0
- data/lib/samagotchi/engine/model_settings.rb +2 -0
- data/lib/samagotchi/engine/models.rb +10 -0
- data/lib/samagotchi/engine/objectives.rb +6 -0
- data/lib/samagotchi/engine/participants.rb +18 -14
- data/lib/samagotchi/engine/plugins.rb +8 -0
- data/lib/samagotchi/engine/questions.rb +3 -0
- data/lib/samagotchi/engine/recap.rb +1 -0
- data/lib/samagotchi/engine/session.rb +4 -0
- data/lib/samagotchi/engine/side_requests.rb +9 -0
- data/lib/samagotchi/engine/steering.rb +2 -0
- data/lib/samagotchi/engine/toolkit.rb +5 -0
- data/lib/samagotchi/engine/turn_end.rb +7 -0
- data/lib/samagotchi/engine/turn_helpers.rb +8 -0
- data/lib/samagotchi/engine/verify.rb +2 -0
- data/lib/samagotchi/engine.rb +3 -2
- data/lib/samagotchi/grants.rb +28 -22
- data/lib/samagotchi/guardrail_wiring.rb +23 -18
- data/lib/samagotchi/guardrails/approval_use.rb +59 -0
- data/lib/samagotchi/guardrails/approvals.rb +9 -11
- data/lib/samagotchi/guardrails/child_boundary.rb +1 -0
- data/lib/samagotchi/guardrails/gate.rb +10 -5
- data/lib/samagotchi/guardrails/implicit_writers.rb +1 -0
- data/lib/samagotchi/guardrails/pair_boundary.rb +6 -6
- data/lib/samagotchi/guardrails/participant_refusal.rb +33 -0
- data/lib/samagotchi/guardrails/review_paths.rb +2 -3
- data/lib/samagotchi/guardrails.rb +1 -1
- data/lib/samagotchi/llm_context_strategy.rb +2 -0
- data/lib/samagotchi/objectives.rb +1 -4
- data/lib/samagotchi/objectives_audit.rb +1 -1
- data/lib/samagotchi/objectives_track.rb +1 -1
- data/lib/samagotchi/owner_prompt.rb +3 -6
- data/lib/samagotchi/parent_report.rb +1 -0
- data/lib/samagotchi/participant_messages.rb +9 -4
- data/lib/samagotchi/participant_turn_mode.rb +50 -0
- data/lib/samagotchi/participants.rb +21 -12
- data/lib/samagotchi/participants_watch.rb +2 -2
- data/lib/samagotchi/plugin/api.rb +2 -2
- data/lib/samagotchi/plugin/attached_context.rb +1 -1
- data/lib/samagotchi/plugin/context.rb +0 -4
- data/lib/samagotchi/plugin/sessions.rb +1 -25
- data/lib/samagotchi/run_options.rb +2 -3
- data/lib/samagotchi/send_command.rb +10 -10
- data/lib/samagotchi/session.rb +0 -3
- data/lib/samagotchi/session_access/contract.rb +1 -10
- data/lib/samagotchi/session_access/local.rb +10 -23
- data/lib/samagotchi/session_access/remote.rb +9 -20
- data/lib/samagotchi/session_access.rb +12 -16
- data/lib/samagotchi/session_chain.rb +4 -6
- data/lib/samagotchi/session_commands.rb +6 -3
- data/lib/samagotchi/session_continue.rb +1 -2
- data/lib/samagotchi/session_manager/delivery.rb +25 -5
- data/lib/samagotchi/session_manager/lifecycle.rb +12 -0
- data/lib/samagotchi/session_manager/listing.rb +5 -0
- data/lib/samagotchi/session_manager/spawn.rb +2 -2
- data/lib/samagotchi/session_manager/worker_command.rb +9 -0
- data/lib/samagotchi/session_participants.rb +12 -8
- data/lib/samagotchi/session_review.rb +5 -7
- data/lib/samagotchi/session_stores.rb +3 -3
- data/lib/samagotchi/share_command.rb +10 -12
- data/lib/samagotchi/share_terms.rb +41 -0
- data/lib/samagotchi/steer.rb +8 -14
- data/lib/samagotchi/system_prompt.rb +16 -25
- data/lib/samagotchi/terminal_ui/attach_launcher.rb +2 -1
- data/lib/samagotchi/terminal_ui/attached_loop/exit_commands.rb +1 -0
- data/lib/samagotchi/terminal_ui/attached_loop/queueing.rb +1 -0
- data/lib/samagotchi/terminal_ui/attached_loop/sending.rb +2 -0
- data/lib/samagotchi/terminal_ui/formatting.rb +15 -17
- data/lib/samagotchi/terminal_ui/participant_commands.rb +2 -2
- data/lib/samagotchi/terminal_ui/status_row.rb +2 -2
- data/lib/samagotchi/terminal_ui.rb +1 -2
- data/lib/samagotchi/testing/sessions.rb +2 -10
- data/lib/samagotchi/tool_runner.rb +8 -9
- data/lib/samagotchi/toolkit.rb +4 -22
- data/lib/samagotchi/toolkit_suggest.rb +3 -3
- data/lib/samagotchi/tools/deferred_tools.rb +1 -0
- data/lib/samagotchi/tools/execute.rb +11 -45
- data/lib/samagotchi/tools/leftovers.rb +122 -0
- data/lib/samagotchi/tools/memory.rb +70 -26
- data/lib/samagotchi/tools/task_get.rb +1 -0
- data/lib/samagotchi/tools/task_list.rb +3 -2
- data/lib/samagotchi/tools/task_record.rb +6 -4
- data/lib/samagotchi/tools/task_runtime.rb +199 -20
- data/lib/samagotchi/tools/task_wait.rb +4 -3
- data/lib/samagotchi/turn_context.rb +1 -1
- data/lib/samagotchi/turn_origin.rb +1 -1
- data/lib/samagotchi/turn_stages/context_judge.rb +4 -4
- data/lib/samagotchi/turn_stages/objectives.rb +2 -2
- data/lib/samagotchi/turn_stages/toolkit_suggestion.rb +2 -2
- data/lib/samagotchi/update_hint.rb +3 -1
- data/lib/samagotchi/verify_fresh.rb +1 -1
- data/lib/samagotchi/verify_fresh_origin.rb +13 -11
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +3 -5
- data/lib/samagotchi/web/participant_access.rb +14 -18
- data/lib/samagotchi/web/participant_review.rb +3 -4
- data/lib/samagotchi/web/participant_show.rb +4 -3
- data/lib/samagotchi/web/participant_view.rb +3 -3
- data/lib/samagotchi/web/participants_admin.rb +21 -40
- data/lib/samagotchi/web/public/app.js +5 -47
- data/lib/samagotchi/web/public/data.js +2 -10
- data/lib/samagotchi/web/public/delivery_line.js +17 -60
- data/lib/samagotchi/web/public/index.html +10 -30
- data/lib/samagotchi/web/public/live_turn.js +1 -1
- data/lib/samagotchi/web/public/owner_claim.js +2 -2
- data/lib/samagotchi/web/public/participant_bar.js +4 -5
- data/lib/samagotchi/web/public/participant_names.js +14 -10
- data/lib/samagotchi/web/public/participants_panel.js +29 -62
- data/lib/samagotchi/web/public/reload_check.js +2 -3
- data/lib/samagotchi/web/public/send_turn.js +4 -23
- data/lib/samagotchi/web/public/session_actions.js +4 -45
- data/lib/samagotchi/web/public/session_fields.js +0 -1
- data/lib/samagotchi/web/public/session_state.js +0 -3
- data/lib/samagotchi/web/public/session_view.js +2 -3
- data/lib/samagotchi/web/public/settings_panel.js +4 -18
- data/lib/samagotchi/web/public/stage_answer.js +56 -0
- data/lib/samagotchi/web/public/stage_asking.js +1 -1
- data/lib/samagotchi/web/public/stage_cloud.js +93 -0
- data/lib/samagotchi/web/public/stage_dom.js +100 -0
- data/lib/samagotchi/web/public/stage_handoff.js +154 -0
- data/lib/samagotchi/web/public/stage_pager.js +59 -0
- data/lib/samagotchi/web/public/stage_quiet_clock.js +52 -0
- data/lib/samagotchi/web/public/stage_view.js +90 -411
- data/lib/samagotchi/web/public/start_page.js +12 -33
- data/lib/samagotchi/web/public/start_settings.js +24 -78
- data/lib/samagotchi/web/public/start_toolkit.js +6 -10
- data/lib/samagotchi/web/public/stream_handlers.js +1 -9
- data/lib/samagotchi/web/public/turn_block.js +3 -7
- data/lib/samagotchi/web/public/turn_events.js +15 -6
- data/lib/samagotchi/web/public/turn_pieces.js +3 -4
- data/lib/samagotchi/web/public/viewer_self.js +8 -2
- data/lib/samagotchi/web/qr.rb +1 -1
- data/lib/samagotchi/web/session_control.rb +3 -1
- data/lib/samagotchi/web/session_create.rb +5 -71
- data/lib/samagotchi/web/session_summary.rb +1 -4
- data/lib/samagotchi/web/verify_fresh_routes.rb +8 -7
- data/lib/samagotchi/web/viewer.rb +3 -3
- data/lib/samagotchi/worker.rb +16 -14
- data/lib/samagotchi/worker_inbound.rb +4 -3
- data/lib/samagotchi/worker_link.rb +17 -0
- data/lib/samagotchi/working_set.rb +87 -28
- metadata +13 -8
- data/lib/samagotchi/guardrails/review_boundary.rb +0 -99
- data/lib/samagotchi/participant_mode.rb +0 -86
- data/lib/samagotchi/review_apply.rb +0 -131
- data/lib/samagotchi/review_command.rb +0 -123
- data/lib/samagotchi/review_start.rb +0 -196
- data/lib/samagotchi/web/public/review_apply.js +0 -34
- data/lib/samagotchi/web/public/review_start.js +0 -55
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "review_paths"
|
|
4
|
-
require_relative "../toolkit"
|
|
5
|
-
require_relative "../steer"
|
|
6
|
-
|
|
7
|
-
module Samagotchi
|
|
8
|
-
module Guardrails
|
|
9
|
-
# A participant's turn may only read (D3, D4: it proposes, the owner
|
|
10
|
-
# applies). A core check, on in every guardrails mode and with
|
|
11
|
-
# guardrails.enabled: false, active only while the running turn's author
|
|
12
|
-
# is a participant (GuardrailWiring#checks); the owner's turns never get
|
|
13
|
-
# it. It denies, never asks (nobody on the participant's side may
|
|
14
|
-
# approve, and the owner's approval would be the participant's text
|
|
15
|
-
# acting with the owner's power), every call outside the review kit
|
|
16
|
-
# (Toolkit::REVIEW_TOOLS). Not forget_outputs: it would replace the
|
|
17
|
-
# owner's earlier tool outputs with a note of the participant's, which
|
|
18
|
-
# later owner turns read as their own output, with no review header.
|
|
19
|
-
# read: ReviewPaths: only under the session's project root, never a file of
|
|
20
|
-
# the read denylist (chi's state and config dirs, home secret dirs,
|
|
21
|
-
# project secret files), checked on the path as given and as it
|
|
22
|
-
# resolves (a symlink in the project to ~/.ssh is ~/.ssh);
|
|
23
|
-
# memory_read: the project scope only, named (no fallback to system);
|
|
24
|
-
# anything else, call_tool's real target included: a call_tool of a
|
|
25
|
-
# chi tool (a built-in or a plugin's chi/<name>) reaches the gate as
|
|
26
|
-
# that tool (ToolRunner#unwrapped), so what is left of call_tool is
|
|
27
|
-
# an MCP tool, denied in v1.
|
|
28
|
-
# The declared tools stay the session's (no prompt rebuild per author),
|
|
29
|
-
# so a participant turn's model may still try a write: it is denied
|
|
30
|
-
# here, with the header's "This turn may only read" to keep it rare.
|
|
31
|
-
class ReviewBoundary
|
|
32
|
-
RULE = "review-boundary"
|
|
33
|
-
SOURCE = "core"
|
|
34
|
-
ALLOWED = Toolkit::REVIEW_TOOLS
|
|
35
|
-
PROJECT_SCOPE = "project"
|
|
36
|
-
|
|
37
|
-
ADVICE = "This is a participant's review turn: answer from what you can read and propose any change as " \
|
|
38
|
-
"text or a diff for the owner to apply."
|
|
39
|
-
NOT_IN_KIT = "a participant's review turn may only read (read, memory_read): %s is not allowed"
|
|
40
|
-
OUTSIDE = "a participant's review turn reads only inside the session's project"
|
|
41
|
-
SECRET = "a participant's review turn can't read secrets or chi's own files"
|
|
42
|
-
HOME_ROOT = "a participant's review turn reads only inside a project, and this session's folder is the " \
|
|
43
|
-
"home folder or above it"
|
|
44
|
-
READ_REFUSALS = { ReviewPaths::OUTSIDE => OUTSIDE, ReviewPaths::SECRET => SECRET, ReviewPaths::HOME_ROOT => HOME_ROOT }.freeze
|
|
45
|
-
MEMORY_SCOPE = "a participant's review turn reads project memories only: call memory_read with scope: project"
|
|
46
|
-
|
|
47
|
-
# @param author [#call] → String, nil: the running turn's author
|
|
48
|
-
# (the call's TurnContext#author, GuardrailWiring#review_boundary /
|
|
49
|
-
# #pair_boundary); the check is off unless it is a
|
|
50
|
-
# participant's (Steer.participant_author?)
|
|
51
|
-
# @param root [#call] → String, nil: the session's project root (the
|
|
52
|
-
# work tree top of its folder); nil denies every read
|
|
53
|
-
# @param denied_dirs [#call] → Array<String>: chi's own dirs (state,
|
|
54
|
-
# config: sessions, grants, the web token, memories and .bundles,
|
|
55
|
-
# config.yml, hooks)
|
|
56
|
-
# @param home [#call] → String, nil
|
|
57
|
-
def initialize(author:, root:, denied_dirs: -> { ReviewPaths.chi_dirs }, home: -> { Dir.home })
|
|
58
|
-
@author = author
|
|
59
|
-
@root = root
|
|
60
|
-
@denied_dirs = denied_dirs
|
|
61
|
-
@home = home
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
# Vote on +verdict+ (its call and targets).
|
|
65
|
-
def check(verdict)
|
|
66
|
-
return verdict unless Steer.participant_author?(@author.call)
|
|
67
|
-
|
|
68
|
-
reason = refusal(verdict)
|
|
69
|
-
return verdict unless reason
|
|
70
|
-
|
|
71
|
-
verdict.deny!(reason, rule: RULE, source: SOURCE, decided_by: "core", advice: ADVICE)
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
private
|
|
75
|
-
|
|
76
|
-
def refusal(verdict)
|
|
77
|
-
call = verdict.call || {}
|
|
78
|
-
tool = call[:name].to_s
|
|
79
|
-
return format(NOT_IN_KIT, tool_label(tool, verdict.targets)) unless ALLOWED.include?(tool)
|
|
80
|
-
|
|
81
|
-
case tool
|
|
82
|
-
when "read" then read_refusal(verdict.targets&.paths || [])
|
|
83
|
-
when "memory_read" then MEMORY_SCOPE unless call[:scope].to_s.strip.downcase == PROJECT_SCOPE
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
# An MCP tool behind call_tool names what it acts as.
|
|
88
|
-
def tool_label(tool, targets)
|
|
89
|
-
acts_as = targets&.acts_as
|
|
90
|
-
acts_as && acts_as != tool ? "#{tool} (#{acts_as})" : tool
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def read_refusal(paths)
|
|
94
|
-
paths_check = ReviewPaths.new(root: @root.call, denied_dirs: @denied_dirs.call, home: @home.call)
|
|
95
|
-
READ_REFUSALS[paths_check.refusal(paths)]
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "delivery"
|
|
4
|
-
require_relative "session_paths"
|
|
5
|
-
|
|
6
|
-
module Samagotchi
|
|
7
|
-
# The rules for a participant's turn: the one place that decides them.
|
|
8
|
-
# - :review — a review session (its review: key, chi review): the turn
|
|
9
|
-
# only reads (Guardrails::ReviewBoundary);
|
|
10
|
-
# - :pair — a working session: the turn acts with the session's tools
|
|
11
|
-
# under the owner's guardrails, asks go to the owner
|
|
12
|
-
# (Guardrails::PairBoundary keeps secrets and owner-voiced tools out).
|
|
13
|
-
# No session (nil) is :review. A worker that doesn't name
|
|
14
|
-
# Delivery::PAIR_FEATURE runs every participant's turn as :review, so
|
|
15
|
-
# chi web and chi share ask .live, which reads the session's live worker,
|
|
16
|
-
# before they say what a participant's turn may do.
|
|
17
|
-
#
|
|
18
|
-
# .of is the session's: what a participant invited now gets. A turn's is
|
|
19
|
-
# .for_turn: :pair only for a participant whose grant was issued for it
|
|
20
|
-
# (Participants::Entry#mode / Grant#mode "pair", stamped at invite when
|
|
21
|
-
# the owner was shown that their turns act); a grant from before, or one
|
|
22
|
-
# issued while the session's worker predated pair turns, stays :review.
|
|
23
|
-
module ParticipantMode
|
|
24
|
-
REVIEW = :review
|
|
25
|
-
PAIR = :pair
|
|
26
|
-
|
|
27
|
-
module_function
|
|
28
|
-
|
|
29
|
-
# @param session [Session, nil]
|
|
30
|
-
# @param features [Array<String>, nil] the features of the worker that
|
|
31
|
-
# runs the turn (WorkerSidecar#features); nil: this chi's own (the
|
|
32
|
-
# worker itself, or the one a delivery will start)
|
|
33
|
-
# @return [Symbol] :review or :pair
|
|
34
|
-
def of(session, features: nil)
|
|
35
|
-
return REVIEW if session.nil? || !session.respond_to?(:review?) || session.review?
|
|
36
|
-
return REVIEW if features && !features.include?(Delivery::PAIR_FEATURE)
|
|
37
|
-
|
|
38
|
-
PAIR
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
# The mode a turn of the participant +entry+ (a Participants::Entry or a
|
|
42
|
-
# Grants::Grant; nil: unknown) runs under in +session+.
|
|
43
|
-
# @return [Symbol]
|
|
44
|
-
def for_turn(session, entry, features: nil)
|
|
45
|
-
return REVIEW unless of(session, features: features) == PAIR
|
|
46
|
-
return REVIEW unless entry.respond_to?(:mode) && entry.mode.to_s == PAIR.to_s
|
|
47
|
-
|
|
48
|
-
PAIR
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# .for_turn as chi web sees it, by the live worker's features (.live).
|
|
52
|
-
def live_for(session, entry, state_dir: nil)
|
|
53
|
-
for_turn(session, entry, features: live_features(session, state_dir))
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
# The mode a participant invited to +session+ now gets, as chi web and
|
|
57
|
-
# chi share see it: by the session's live worker's features (an older
|
|
58
|
-
# worker runs it as :review), else by this chi's (no live worker: the
|
|
59
|
-
# one a delivery starts is this chi's).
|
|
60
|
-
# @param state_dir [String, nil] the sessions' state dir (nil: the default)
|
|
61
|
-
# @return [Symbol]
|
|
62
|
-
def live(session, state_dir: nil)
|
|
63
|
-
of(session, features: live_features(session, state_dir))
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
# Whether +session+ is a working session whose live worker still runs a
|
|
67
|
-
# participant's turn as a review (it predates Delivery::PAIR_FEATURE).
|
|
68
|
-
def older_worker?(session, state_dir: nil)
|
|
69
|
-
of(session) == PAIR && live(session, state_dir: state_dir) == REVIEW
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
# The live worker's features, nil without a live worker (or when it
|
|
73
|
-
# can't be read).
|
|
74
|
-
def live_features(session, state_dir)
|
|
75
|
-
return nil if session.nil? || !session.respond_to?(:id) || session.id.to_s.empty?
|
|
76
|
-
|
|
77
|
-
require_relative "session"
|
|
78
|
-
require_relative "worker_link"
|
|
79
|
-
dir = SessionPaths.session_dir(session.id, state_dir: state_dir || SessionPaths.default_state_dir)
|
|
80
|
-
link = WorkerLink.resolve(dir, unlink: false)
|
|
81
|
-
link.live? ? link.features : nil
|
|
82
|
-
rescue StandardError
|
|
83
|
-
nil
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "participant_name"
|
|
4
|
-
require_relative "steer"
|
|
5
|
-
require_relative "participant_mode"
|
|
6
|
-
require_relative "output_formatter"
|
|
7
|
-
|
|
8
|
-
module Samagotchi
|
|
9
|
-
# Apply (the shared-sessions plan's §3, D4: a review turn proposes, the
|
|
10
|
-
# owner applies): the owner's turn that takes up a participant's review
|
|
11
|
-
# turn's proposal. It quotes the proposal, every line of the review
|
|
12
|
-
# turn's reply as a markdown quote under one line of the owner's, so the
|
|
13
|
-
# participant's words (and whatever their turn's reply echoed of them)
|
|
14
|
-
# reach the model as quoted material, never as the owner's instruction.
|
|
15
|
-
# The owner sees the composed text before it runs (the web's composer,
|
|
16
|
-
# the attached TUI's input line) and may edit it or not send it at all.
|
|
17
|
-
# See docs/internals/participants.md (Apply).
|
|
18
|
-
module ReviewApply
|
|
19
|
-
# A review turn's proposal: its turn id, its author (p:<id>) and their
|
|
20
|
-
# name, and the reply's visible text.
|
|
21
|
-
Proposal = Data.define(:turn_id, :author, :author_name, :text)
|
|
22
|
-
|
|
23
|
-
# Why there is nothing to apply: one message per condition.
|
|
24
|
-
class Refused < StandardError
|
|
25
|
-
attr_reader :code
|
|
26
|
-
|
|
27
|
-
def initialize(message, code:)
|
|
28
|
-
@code = code
|
|
29
|
-
super(message)
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
NO_TURN = "no turn %s in this session"
|
|
34
|
-
NOT_REVIEW = "turn %s isn't a participant's review turn: only a review turn's proposal is applied"
|
|
35
|
-
NO_REPLY = "review turn %s has no reply to apply yet"
|
|
36
|
-
NO_REVIEW_TURNS = "no participant's review turn with a reply in this session"
|
|
37
|
-
# What a quoted proposal's author is called without a name.
|
|
38
|
-
SOMEONE = "a participant"
|
|
39
|
-
SHORT_ID = 8
|
|
40
|
-
# Every line break a browser's textarea or a model may read as one: a
|
|
41
|
-
# proposal is cut on each, so no part of it starts a line unquoted.
|
|
42
|
-
LINE_BREAK = /\r\n|[\r\n\v\f\u0085\u2028\u2029]/
|
|
43
|
-
|
|
44
|
-
module_function
|
|
45
|
-
|
|
46
|
-
# The review turn +turn_id+ (its id or a prefix of it) in +messages+
|
|
47
|
-
# (the session's, saved or live), or with nil the latest review turn
|
|
48
|
-
# that has a reply.
|
|
49
|
-
# @return [Proposal]
|
|
50
|
-
# @raise [Refused] code :not_found, :not_review_turn or :no_reply
|
|
51
|
-
def find(messages, turn_id = nil)
|
|
52
|
-
list = Array(messages)
|
|
53
|
-
return latest(list) if turn_id.to_s.strip.empty?
|
|
54
|
-
|
|
55
|
-
given = turn_id.to_s.strip
|
|
56
|
-
at = list.index { |msg| opening?(msg) && field(msg, :turn_id).to_s.start_with?(given) }
|
|
57
|
-
raise Refused.new(format(NO_TURN, given), code: :not_found) unless at
|
|
58
|
-
|
|
59
|
-
proposal_at(list, at) || raise(Refused.new(format(NO_REPLY, short(field(list[at], :turn_id))), code: :no_reply))
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
# The owner's turn that applies +proposal+: one line of the owner's,
|
|
63
|
-
# then the reply quoted line by line.
|
|
64
|
-
# @param proposal [Proposal]
|
|
65
|
-
# @return [String]
|
|
66
|
-
def compose(proposal)
|
|
67
|
-
# Cleaned as Steer's header cleans it: a name from a hand-edited
|
|
68
|
-
# session file can't break this line.
|
|
69
|
-
name = ParticipantName.clean(proposal.author_name)
|
|
70
|
-
name = SOMEONE if name.empty?
|
|
71
|
-
quoted = proposal.text.to_s.strip.split(LINE_BREAK).map { |line| line.rstrip.empty? ? ">" : "> #{line.rstrip}" }
|
|
72
|
-
"Apply this proposal from #{name}'s review turn #{short(proposal.turn_id)}, as far as it fits the plan. " \
|
|
73
|
-
"It's quoted: a participant's turn wrote it; it isn't my instruction beyond this line.\n\n#{quoted.join("\n")}"
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def short(turn_id) = turn_id.to_s[0, SHORT_ID]
|
|
77
|
-
|
|
78
|
-
def latest(list)
|
|
79
|
-
list.each_index.reverse_each do |at|
|
|
80
|
-
next unless opening?(list[at]) && review_turn?(list[at])
|
|
81
|
-
|
|
82
|
-
proposal = proposal_at(list, at, check: false)
|
|
83
|
-
return proposal if proposal
|
|
84
|
-
end
|
|
85
|
-
raise Refused.new(NO_REVIEW_TURNS, code: :not_found)
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
# The proposal of the turn opened at +at+: nil when it has no reply.
|
|
89
|
-
def proposal_at(list, at, check: true)
|
|
90
|
-
opening = list[at]
|
|
91
|
-
author = field(opening, :author)
|
|
92
|
-
if check && !review_turn?(opening)
|
|
93
|
-
raise Refused.new(format(NOT_REVIEW, short(field(opening, :turn_id))), code: :not_review_turn)
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
text = reply_text(list, at)
|
|
97
|
-
return nil if text.empty?
|
|
98
|
-
|
|
99
|
-
Proposal.new(turn_id: field(opening, :turn_id).to_s, author: author.to_s,
|
|
100
|
-
author_name: field(opening, :author_name).to_s, text: text)
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
# Whether the turn +opening+ opens is a participant's review turn: a
|
|
104
|
-
# participant's, not stamped pair (a pair turn acted itself: there is
|
|
105
|
-
# nothing to apply). A message from before the stamp is a review's.
|
|
106
|
-
def review_turn?(opening)
|
|
107
|
-
Steer.participant_author?(field(opening, :author)) && field(opening, :participant_mode).to_s != ParticipantMode::PAIR.to_s
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
# The turn's reply: its last model message with visible text, before
|
|
111
|
-
# the next turn opens.
|
|
112
|
-
def reply_text(list, at)
|
|
113
|
-
reply = ""
|
|
114
|
-
list[(at + 1)..].each do |msg|
|
|
115
|
-
break if opening?(msg)
|
|
116
|
-
next unless %w[model assistant].include?(field(msg, :role).to_s)
|
|
117
|
-
|
|
118
|
-
content = field(msg, :content)
|
|
119
|
-
text = content.is_a?(String) ? OutputFormatter.strip_markup(content).strip : ""
|
|
120
|
-
reply = text unless text.empty?
|
|
121
|
-
end
|
|
122
|
-
reply
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
# A turn's opening message (Engine#prepare_turn's: a user message with
|
|
126
|
-
# the turn's id).
|
|
127
|
-
def opening?(msg) = msg.is_a?(Hash) && field(msg, :role).to_s == "user" && !field(msg, :turn_id).nil?
|
|
128
|
-
|
|
129
|
-
def field(msg, key) = msg[key] || msg[key.to_s]
|
|
130
|
-
end
|
|
131
|
-
end
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "cli/command"
|
|
4
|
-
require_relative "cli/exit"
|
|
5
|
-
require_relative "cli/flags"
|
|
6
|
-
require_relative "session"
|
|
7
|
-
require_relative "session_access"
|
|
8
|
-
require_relative "session_access/local"
|
|
9
|
-
require_relative "review_start"
|
|
10
|
-
require_relative "model_profile"
|
|
11
|
-
|
|
12
|
-
module Samagotchi
|
|
13
|
-
# `chi review`: start a review session (the shared-sessions plan's §4, D2:
|
|
14
|
-
# a review is its own session), for files or as a review fork of a working
|
|
15
|
-
# session (--from: its recap, not its transcript; it keeps running), and
|
|
16
|
-
# print how to invite someone (chi share). Local or through chi --remote
|
|
17
|
-
# NAME (SessionAccess: the server checks the files against its own
|
|
18
|
-
# project). See docs/sessions.md (Review sessions).
|
|
19
|
-
class ReviewCommand
|
|
20
|
-
include CLI::Command
|
|
21
|
-
|
|
22
|
-
USAGE = <<~TEXT
|
|
23
|
-
Usage: chi review FILE… [--dir DIR] [--model NAME]
|
|
24
|
-
chi review --from ID [FILE…] [--model NAME]
|
|
25
|
-
FILE… the files under review: each a file in the session's project (relative to
|
|
26
|
-
the session's folder), never a secret (.env, keys, credentials) nor chi's own
|
|
27
|
-
--dir DIR the session's folder (default: here; required with chi --remote)
|
|
28
|
-
--model NAME the model it runs on (default: the configured one; with --from, ID's)
|
|
29
|
-
--from ID a review of session ID: a new session that starts from ID's recap, not its
|
|
30
|
-
transcript; ID keeps running. FILE… is relative to ID's folder then.
|
|
31
|
-
The review session starts idle; chi review prints how to invite someone (chi share). A
|
|
32
|
-
participant's comments run as read-only review turns; you apply their proposals.
|
|
33
|
-
TEXT
|
|
34
|
-
|
|
35
|
-
FLAGS = CLI::Flags.new(help: HELP_WORDS) do |f|
|
|
36
|
-
f.value "--dir"
|
|
37
|
-
f.value "--model"
|
|
38
|
-
f.value "--from"
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
# @param access [SessionAccess::Local, SessionAccess::Remote, nil]
|
|
42
|
-
# where the sessions are; default this machine's, in +state_dir+
|
|
43
|
-
def initialize(argv, stdin: $stdin, stdout: $stdout, stderr: $stderr, state_dir: nil, access: nil)
|
|
44
|
-
@argv = argv.dup
|
|
45
|
-
@stdin = stdin
|
|
46
|
-
@stdout = stdout
|
|
47
|
-
@stderr = stderr
|
|
48
|
-
@access = access || SessionAccess::Local.new(state_dir: state_dir)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# @return [Integer] exit status: 0 started, 1 refused or failed, 2 usage
|
|
52
|
-
def run
|
|
53
|
-
if @argv.empty?
|
|
54
|
-
@stdout.puts(USAGE)
|
|
55
|
-
return 0
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
parsed = parse_flags(FLAGS, @argv)
|
|
59
|
-
return parsed if parsed.is_a?(Integer)
|
|
60
|
-
|
|
61
|
-
start(parsed.options, parsed.args)
|
|
62
|
-
rescue ReviewStart::Refused, SessionAccess::BadRequest => e
|
|
63
|
-
refused(e.message)
|
|
64
|
-
rescue ModelProfile::MissingModel, Toolkit::Refused => e
|
|
65
|
-
refused("could not start: #{e.message}")
|
|
66
|
-
rescue ArgumentError => e
|
|
67
|
-
refused(e.message)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
private
|
|
71
|
-
|
|
72
|
-
def command_name = "chi review"
|
|
73
|
-
|
|
74
|
-
def start(options, files)
|
|
75
|
-
from = options[:from]&.strip
|
|
76
|
-
dir = options[:dir]
|
|
77
|
-
return usage_error("give the files to review, or --from ID") if files.empty? && from.to_s.empty?
|
|
78
|
-
return usage_error("--dir goes with files, not --from: a review of ID runs in ID's folder") if from && dir
|
|
79
|
-
|
|
80
|
-
dir, error = folder(dir) unless from
|
|
81
|
-
return error if error
|
|
82
|
-
|
|
83
|
-
spec = SessionAccess::NewSession.new(prompt: nil, working_directory: dir, model_name: options[:model],
|
|
84
|
-
review: SessionAccess::Review.new(subjects: files, from: from))
|
|
85
|
-
created = @access.create(spec)
|
|
86
|
-
print_started(created, files, from)
|
|
87
|
-
0
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
# The session's folder: --dir, else here; a remote's must be its own
|
|
91
|
-
# absolute path (no path of this machine is guessed there).
|
|
92
|
-
# @return [Array(String, nil), Array(nil, Integer)]
|
|
93
|
-
def folder(dir)
|
|
94
|
-
if @access.remote?
|
|
95
|
-
return [nil, usage_error("--dir DIR: the folder on #{@access.invocation.remote} (an absolute path there)")] if dir.to_s.strip.empty?
|
|
96
|
-
return [nil, usage_error("--dir takes an absolute path on #{@access.invocation.remote}")] unless dir.start_with?("/")
|
|
97
|
-
|
|
98
|
-
return [dir, nil]
|
|
99
|
-
end
|
|
100
|
-
dir = File.expand_path(dir || Dir.pwd)
|
|
101
|
-
return [nil, usage_error("--dir #{dir}: no such folder")] unless File.directory?(dir)
|
|
102
|
-
|
|
103
|
-
[dir, nil]
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def print_started(created, files, from)
|
|
107
|
-
id = created.id
|
|
108
|
-
what = from ? "a review of #{from}" : "review"
|
|
109
|
-
subjects = files.empty? ? "" : " · #{files.join(", ")}"
|
|
110
|
-
@stdout.puts("#{id} #{what}#{subjects} · idle")
|
|
111
|
-
@stdout.puts("warning: #{created.model_warning}") if created.model_warning
|
|
112
|
-
@stdout.puts("open it: #{@access.invocation.open_it(id[0, 8])}")
|
|
113
|
-
# Behind a proxy that names the user, a link can be bound to them.
|
|
114
|
-
identity = " --identity EMAIL" if @access.identity_header
|
|
115
|
-
@stdout.puts("invite someone: #{@access.invocation.command("share #{id[0, 8]} --name NAME#{identity}")}")
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
def refused(message)
|
|
119
|
-
error_line("#{command_name}: #{message}")
|
|
120
|
-
CLI::Exit::FAILED
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
end
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "session"
|
|
4
|
-
require_relative "session_review"
|
|
5
|
-
require_relative "session_setup"
|
|
6
|
-
require_relative "session_chain"
|
|
7
|
-
require_relative "recap_store"
|
|
8
|
-
require_relative "guardrails/context"
|
|
9
|
-
require_relative "guardrails/path_resolve"
|
|
10
|
-
require_relative "guardrails/review_paths"
|
|
11
|
-
require_relative "participant_mode"
|
|
12
|
-
|
|
13
|
-
module Samagotchi
|
|
14
|
-
autoload :SessionManager, File.expand_path("session_manager", __dir__)
|
|
15
|
-
autoload :SessionContinue, File.expand_path("session_continue", __dir__)
|
|
16
|
-
|
|
17
|
-
# A review session (the shared-sessions plan's §4, D2: a review is its
|
|
18
|
-
# own session): chi review FILE…, chi review --from ID, the web's Start
|
|
19
|
-
# review, a plugin's ctx.sessions.review. It starts idle, with a context
|
|
20
|
-
# note that names its subjects and, for a fork, brings the source's recap
|
|
21
|
-
# (never its transcript), and its SessionReview on the session. A fork
|
|
22
|
-
# leaves its source as it is: running, unarchived, its delegates its own
|
|
23
|
-
# (a continue would archive it: the coordinator reviewing its own plan
|
|
24
|
-
# keeps working). See docs/sessions.md (Review sessions).
|
|
25
|
-
module ReviewStart
|
|
26
|
-
# A review that can't start: one message per condition.
|
|
27
|
-
class Refused < ArgumentError; end
|
|
28
|
-
|
|
29
|
-
# One message for every file that can't be a subject: missing, a
|
|
30
|
-
# folder, outside the project, a secret or chi's own (ReviewPaths).
|
|
31
|
-
SUBJECT_REFUSED = "%s can't be a review subject: a subject is a file in the session's project, " \
|
|
32
|
-
"not a secret (.env, keys, credentials) nor chi's own"
|
|
33
|
-
NO_SUBJECTS = "a review needs subject files, or --from a session"
|
|
34
|
-
TOO_MANY = "a review takes at most %d subject files"
|
|
35
|
-
MAX_SUBJECTS = 20
|
|
36
|
-
# Where a review's note comes from (SessionInbox.write_note).
|
|
37
|
-
NOTE_SOURCE = "review"
|
|
38
|
-
# How long a fork waits for its source's live worker to write a fresh
|
|
39
|
-
# recap (SessionContinue::RECAP_WAIT).
|
|
40
|
-
RECAP_WAIT = 30.0
|
|
41
|
-
|
|
42
|
-
module_function
|
|
43
|
-
|
|
44
|
-
# The project a session in +dir+ reviews: its work tree top, or +dir+
|
|
45
|
-
# outside git (as ReviewBoundary's root).
|
|
46
|
-
def root_for(dir) = Guardrails::GitInfo.new.root(dir) || File.expand_path(dir)
|
|
47
|
-
|
|
48
|
-
# +given+ as project-relative subjects: each a path relative to +dir+
|
|
49
|
-
# (the session's folder) or absolute, an existing file under the
|
|
50
|
-
# project that ReviewPaths would let a participant read.
|
|
51
|
-
# @param given [Array<String>]
|
|
52
|
-
# @param dir [String] the session's folder
|
|
53
|
-
# @return [Array<String>] relative to root_for(dir), in the given order, no repeats
|
|
54
|
-
# @raise [Refused]
|
|
55
|
-
def check_subjects(given, dir:)
|
|
56
|
-
given = Array(given).map { |path| path.to_s.strip }.reject(&:empty?)
|
|
57
|
-
raise Refused, format(TOO_MANY, MAX_SUBJECTS) if given.size > MAX_SUBJECTS
|
|
58
|
-
|
|
59
|
-
root = root_for(dir)
|
|
60
|
-
check = Guardrails::ReviewPaths.new(root: root)
|
|
61
|
-
given.map do |path|
|
|
62
|
-
full = File.expand_path(path, dir)
|
|
63
|
-
raise Refused, format(SUBJECT_REFUSED, path) unless File.file?(full) && check.refusal([full]).nil?
|
|
64
|
-
|
|
65
|
-
relative(full, root)
|
|
66
|
-
end.uniq
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
# A fresh review session in +dir+ for +subjects+ (as given: #subjects
|
|
70
|
-
# checks them), idle.
|
|
71
|
-
# @param setup [SessionSetup]
|
|
72
|
-
# @return [Session] (#model_warning as spawn_session's)
|
|
73
|
-
# @raise [Refused] no subjects, or one #check_subjects refuses;
|
|
74
|
-
# ModelProfile::MissingModel
|
|
75
|
-
def start(subjects:, dir:, model: nil, setup: SessionSetup.new, state_dir: nil)
|
|
76
|
-
dir = File.expand_path(dir)
|
|
77
|
-
subjects = check_subjects(subjects, dir: dir)
|
|
78
|
-
raise Refused, NO_SUBJECTS if subjects.empty?
|
|
79
|
-
|
|
80
|
-
setup = setup.with(toolkit_origin: "chosen")
|
|
81
|
-
SessionManager.spawn_session(prompt: nil, preview: preview(subjects), working_directory: dir, model_name: model,
|
|
82
|
-
setup: setup, review: SessionReview.new(subjects: subjects),
|
|
83
|
-
note: note(subjects: subjects), note_source: NOTE_SOURCE, state_dir: state_dir,
|
|
84
|
-
client_id: nil)
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
# A review fork of +from+ (an id, a prefix, or last:<id>): a new session
|
|
88
|
-
# in its folder, on +model+ or its model (SessionContinue.model_for),
|
|
89
|
-
# with its setup (SessionSetup.of), seeded with a fresh recap of it (its
|
|
90
|
-
# live worker is asked first, as a continue asks) and +seed+ (more
|
|
91
|
-
# context, e.g. the coordinator's handoff), idle. +from+ stays as it is.
|
|
92
|
-
# @param subjects [Array<String>] as given, relative to +from+'s folder
|
|
93
|
-
# (#check_subjects checks them; may be empty)
|
|
94
|
-
# @return [Session]
|
|
95
|
-
# @raise [ArgumentError] no such session (Session::AmbiguousId);
|
|
96
|
-
# [Refused] its folder is gone, or a subject #check_subjects refuses;
|
|
97
|
-
# ModelProfile::MissingModel
|
|
98
|
-
def fork(from:, subjects: [], model: nil, seed: nil, state_dir: nil, recap_wait: RECAP_WAIT)
|
|
99
|
-
sd = state_dir || Session.default_state_dir
|
|
100
|
-
source = Session.load(SessionChain.resolve(from, state_dir: sd), state_dir: sd)
|
|
101
|
-
dir = source.working_directory.to_s
|
|
102
|
-
raise Refused, "#{source.id[0, 8]}'s folder #{dir} is gone" unless File.directory?(dir)
|
|
103
|
-
|
|
104
|
-
subjects = check_subjects(subjects, dir: dir)
|
|
105
|
-
choice = SessionContinue.model_for(source, model)
|
|
106
|
-
SessionContinue.recap_before_archive(source.id, sd, wait: recap_wait)
|
|
107
|
-
recap = RecapStore.read(Session.session_dir(source.id, state_dir: sd))
|
|
108
|
-
session = SessionManager.spawn_session(
|
|
109
|
-
prompt: nil, preview: preview(subjects, source: source), working_directory: dir, model_name: choice.model,
|
|
110
|
-
setup: SessionSetup.of(source).with(preloaded_memory_names: [], toolkit_origin: "chosen"),
|
|
111
|
-
review: SessionReview.new(subjects: subjects, from: source.id),
|
|
112
|
-
note: note(subjects: subjects, source: source, recap: recap, seed: seed), note_source: NOTE_SOURCE,
|
|
113
|
-
state_dir: sd, client_id: nil
|
|
114
|
-
)
|
|
115
|
-
warnings = [choice.warning, session.model_warning].compact
|
|
116
|
-
session.model_warning = warnings.join("; ") unless warnings.empty?
|
|
117
|
-
session
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
# What the lists show before its first turn.
|
|
121
|
-
def preview(subjects, source: nil)
|
|
122
|
-
return "review: #{subjects.join(", ")}" if source.nil?
|
|
123
|
-
|
|
124
|
-
of = source.display_title.to_s.strip
|
|
125
|
-
Session.preview_of("review of #{of.empty? ? source.id[0, 8] : of}#{" (#{subjects.join(", ")})" unless subjects.empty?}")
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
# The review's context note: what the session is for, its subjects,
|
|
129
|
-
# and for a fork where it starts from (the source's recap) and +seed+.
|
|
130
|
-
# @param recap [Hash, nil] RecapStore.read's
|
|
131
|
-
# @return [String]
|
|
132
|
-
def note(subjects:, source: nil, recap: nil, seed: nil)
|
|
133
|
-
parts = []
|
|
134
|
-
if source
|
|
135
|
-
started = SessionChain.clock(source.created_at) || source.created_at
|
|
136
|
-
parts << "This review session starts from #{source.id[0, 8]} (#{started}), a working session: it brings " \
|
|
137
|
-
"that session's recap, not its transcript.#{SessionChain.recap_text(recap)}"
|
|
138
|
-
end
|
|
139
|
-
parts << "The review's subjects (project-relative): #{subjects.join(", ")}." unless subjects.empty?
|
|
140
|
-
parts << "The owner invites participants to comment. A participant's comment runs as a read-only review " \
|
|
141
|
-
"turn: answer it and propose any change as text or a diff for the owner to apply."
|
|
142
|
-
seed = seed.to_s.strip
|
|
143
|
-
parts << seed unless seed.empty?
|
|
144
|
-
parts.join("\n\n")
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
# What inviting a participant to +session+ now means: the grant's mode
|
|
148
|
-
# (Grants::PAIR_MODE only when the owner is shown PAIR_WARNING: a
|
|
149
|
-
# working session whose live worker runs pair turns; nil otherwise, a
|
|
150
|
-
# review participant), the mode their turns get (:pair or :review) and
|
|
151
|
-
# the warning shown for it (nil for a review session). One read of the
|
|
152
|
-
# live worker for all three, so the stamp is what the warning said.
|
|
153
|
-
ShareTerms = Data.define(:grant_mode, :mode, :warning)
|
|
154
|
-
|
|
155
|
-
# @param session [Session]
|
|
156
|
-
# @param state_dir [String, nil] the sessions' state dir (nil: the default)
|
|
157
|
-
# @return [ShareTerms]
|
|
158
|
-
def share_terms(session, state_dir: nil)
|
|
159
|
-
return ShareTerms.new(grant_mode: nil, mode: ParticipantMode::REVIEW, warning: nil) if session.review?
|
|
160
|
-
|
|
161
|
-
count = session.tool_output_count
|
|
162
|
-
outputs = "#{count} tool output#{"s" unless count == 1} so far"
|
|
163
|
-
pair = ParticipantMode.live(session, state_dir: state_dir) == ParticipantMode::PAIR
|
|
164
|
-
warning = format(pair ? PAIR_WARNING : OLDER_WORKER_WARNING, id: session.id[0, 8], outputs: outputs)
|
|
165
|
-
ShareTerms.new(grant_mode: (ParticipantMode::PAIR.to_s if pair), mode: pair ? ParticipantMode::PAIR : ParticipantMode::REVIEW,
|
|
166
|
-
warning: warning)
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
# The warning for inviting a participant to +session+ when it isn't a
|
|
170
|
-
# review session (D2: sharing a working session is allowed, with a
|
|
171
|
-
# warning that says what a participant's turn does there and how many
|
|
172
|
-
# tool outputs its history holds); nil for a review session
|
|
173
|
-
# (#share_terms). chi share and the web's Invite show it as it is.
|
|
174
|
-
# @return [String, nil]
|
|
175
|
-
def share_warning(session, state_dir: nil) = share_terms(session, state_dir: state_dir).warning
|
|
176
|
-
|
|
177
|
-
# A working session's share warning (#share_warning): a participant's
|
|
178
|
-
# turns act there. chi share adds the command that starts a review
|
|
179
|
-
# session (chi review --from ID), as its invocation spells it.
|
|
180
|
-
PAIR_WARNING = "%<id>s is a working session: a participant's turns act in it with this session's tools " \
|
|
181
|
-
"(writes included; asks come to you) and read what its history holds (%<outputs>s). " \
|
|
182
|
-
"A review session only reads."
|
|
183
|
-
# The same while its live worker predates pair turns (Delivery::PAIR_FEATURE):
|
|
184
|
-
# a participant invited now gets review turns, whatever happens later.
|
|
185
|
-
OLDER_WORKER_WARNING = "%<id>s is a working session, but its worker predates pair turns: a participant invited " \
|
|
186
|
-
"now only reads, and can quote what its history holds (%<outputs>s). For turns that act " \
|
|
187
|
-
"in it, restart it (chi sessions restart %<id>s) and invite them again. A review session " \
|
|
188
|
-
"only reads."
|
|
189
|
-
|
|
190
|
-
def relative(full, root)
|
|
191
|
-
real_root = Guardrails::PathResolve.real(root)
|
|
192
|
-
real = Guardrails::PathResolve.real(full)
|
|
193
|
-
real.delete_prefix(File.join(real_root, ""))
|
|
194
|
-
end
|
|
195
|
-
end
|
|
196
|
-
end
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// Apply (the owner's page): under a participant's review turn's reply, a
|
|
2
|
-
// button that puts the owner's Apply turn in the composer: one line of the
|
|
3
|
-
// owner's and the proposal quoted (GET …/apply, ReviewApply on the server),
|
|
4
|
-
// never sent by itself. The owner reads it, edits it, sends it or not.
|
|
5
|
-
import { html } from "./vendor/lit-html.js";
|
|
6
|
-
|
|
7
|
-
// The row under a review turn's reply: +badge+ is authorBadge's
|
|
8
|
-
// ({author, name, color}).
|
|
9
|
-
export function applyRowTemplate(turnId, badge) {
|
|
10
|
-
return html`<div class="review-apply" data-apply-turn=${turnId} style=${`--author-color:${badge.color}`}><button
|
|
11
|
-
type="button" class="review-apply-btn" data-apply-turn=${turnId}
|
|
12
|
-
title=${`Put an Apply turn in the composer: ${badge.name}'s proposal, quoted. You read it before you send it.`}>Apply</button
|
|
13
|
-
><span class="review-apply-note">${badge.name}'s proposal, quoted in your composer; you send it</span></div>`;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// The composer with the Apply turn: after what is typed there already.
|
|
17
|
-
export function applyComposerText(current, composed) {
|
|
18
|
-
const typed = String(current || "").trimEnd();
|
|
19
|
-
return typed ? `${typed}\n\n${composed}` : composed;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function applyURL(sessionId, turnId) {
|
|
23
|
-
return `/api/sessions/${encodeURIComponent(sessionId)}/apply?turn=${encodeURIComponent(turnId)}`;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// The Apply turn's text for review turn +turnId+, or an Error with the
|
|
27
|
-
// server's words.
|
|
28
|
-
export async function fetchApply(sessionId, turnId, fetchImpl = fetch) {
|
|
29
|
-
const res = await fetchImpl(applyURL(sessionId, turnId), { credentials: "same-origin" });
|
|
30
|
-
let json = null;
|
|
31
|
-
try { json = await res.json(); } catch { json = null; }
|
|
32
|
-
if (!res.ok || typeof json?.text !== "string") throw new Error(json?.detail || `Apply failed (HTTP ${res.status})`);
|
|
33
|
-
return json.text;
|
|
34
|
-
}
|