samagotchi 0.171.0 → 0.172.1
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 +46 -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 +70 -27
- 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 +81 -8
- 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 +126 -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 +7 -48
- data/lib/samagotchi/web/public/card_kinds.js +51 -0
- data/lib/samagotchi/web/public/cards_place.js +13 -2
- 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/question_cards.js +29 -14
- 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_sync.js +4 -2
- 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 +30 -11
- 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_place.js +144 -0
- data/lib/samagotchi/web/public/stage_probe.js +64 -0
- data/lib/samagotchi/web/public/stage_quiet_clock.js +52 -0
- data/lib/samagotchi/web/public/stage_view.js +133 -506
- data/lib/samagotchi/web/public/stage_waiting.js +30 -13
- 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 +16 -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,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
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
// Start review (the web's entry points to a review session, docs/sessions.md
|
|
2
|
-
// Review sessions): the start page's review files (the ⚙ panel's review
|
|
3
|
-
// view, start_settings.js), which make the new session a review session
|
|
4
|
-
// (POST /api/sessions {review: {subjects}}), and the session bar's review
|
|
5
|
-
// button, a review fork of the open session ({review: {from}}): its recap,
|
|
6
|
-
// not its transcript; it keeps running.
|
|
7
|
-
import { html, nothing } from "./vendor/lit-html.js";
|
|
8
|
-
|
|
9
|
-
// The files typed: split on commas, spaces and new lines, no repeats; a
|
|
10
|
-
// path with a space (or a comma) in double quotes ("docs/my plan.md").
|
|
11
|
-
// @return {subjects, error}: error, a quote left open (then no subjects)
|
|
12
|
-
export function readSubjects(text) {
|
|
13
|
-
const found = [];
|
|
14
|
-
for (const m of String(text || "").matchAll(/"([^"]*)("?)|[^\s,"]+/g)) {
|
|
15
|
-
if (m[1] !== undefined && !m[2]) return { subjects: [], error: `A quote isn't closed: "${m[1].trim()}` };
|
|
16
|
-
const path = (m[1] ?? m[0]).trim();
|
|
17
|
-
if (path) found.push(path);
|
|
18
|
-
}
|
|
19
|
-
return { subjects: [...new Set(found)], error: null };
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// The files as the form shows them again: a path with a space, a comma or
|
|
23
|
-
// a quote in quotes, so readSubjects reads it back whole.
|
|
24
|
-
export function formatSubjects(subjects) {
|
|
25
|
-
return (subjects || []).map((s) => (/[\s,"]/.test(s) ? `"${s}"` : s)).join(", ");
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// The start page's override chip: "review…" with none, else the files' names.
|
|
29
|
-
export function reviewChipModel(subjects) {
|
|
30
|
-
const list = subjects || [];
|
|
31
|
-
if (!list.length) {
|
|
32
|
-
return { text: "review…", own: false, title: "Start a review session instead: pick the project files participants will read beside the thread" };
|
|
33
|
-
}
|
|
34
|
-
const names = list.map((s) => s.split("/").pop());
|
|
35
|
-
return { text: `review: ${names[0]}${names.length > 1 ? ` +${names.length - 1}` : ""}`, own: true,
|
|
36
|
-
title: `A review session of ${list.join(", ")}: Start makes it (your message, if any, is its first turn); then invite someone from the participants chip` };
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// +error+: why the files weren't taken (a quote left open, the server's
|
|
40
|
-
// refusal at Start), shown above Set; +text+ the form's text as typed;
|
|
41
|
-
// +back+: a ‹ before the heading (data-act="back": the start page's ⚙
|
|
42
|
-
// panel, start_settings.js, whose view this is).
|
|
43
|
-
export function reviewFormTemplate(subjects, { error = null, text = null, back = false } = {}) {
|
|
44
|
-
return html`<div class="ctx-pop-head">${back ? html`<button type="button" class="sset-back" data-act="back"
|
|
45
|
-
aria-label="Back to the settings" title="Back to the settings">‹</button>` : nothing}<strong>Review</strong><span class="ctx-pop-kind">new session</span
|
|
46
|
-
><button type="button" class="ctx-pop-close" data-act="close" aria-label="Close">×</button></div>
|
|
47
|
-
<div class="ctx-pop-meta" id="reviewNewHelp">The files participants read beside the thread: project paths, relative to this folder,
|
|
48
|
-
a path with a space in quotes. Secrets (.env, keys) and files outside the project are refused.</div>
|
|
49
|
-
<form class="rs-form"><textarea name="subjects" rows="2" placeholder="docs/plan.md, docs/spec.md" aria-label="Files to review"
|
|
50
|
-
aria-describedby="reviewNewHelp" aria-invalid=${error ? "true" : "false"}
|
|
51
|
-
autocomplete="off" spellcheck="false" .value=${text ?? formatSubjects(subjects)}></textarea>
|
|
52
|
-
<div class="ctx-pop-error" role="alert" ?hidden=${!error}>${error || ""}</div>
|
|
53
|
-
<div class="ctx-pop-actions">${subjects?.length ? html`<button type="button" data-act="clear">No review</button>` : nothing}<button
|
|
54
|
-
type="submit">Set</button></div></form>`;
|
|
55
|
-
}
|