samagotchi 0.125.0 → 0.126.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 +25 -1
- data/docs/guardrails.md +22 -0
- data/docs/internals/participants.md +70 -2
- data/docs/internals/web-push.md +10 -6
- data/docs/sessions.md +3 -0
- data/lib/samagotchi/bridge.rb +4 -3
- data/lib/samagotchi/bridge_client.rb +8 -1
- data/lib/samagotchi/bundles/known-names/hooks/known_names.rb +25 -4
- data/lib/samagotchi/bundles/known-names/manifest.yml +2 -2
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/child_reports.rb +3 -0
- data/lib/samagotchi/children_status.rb +6 -1
- data/lib/samagotchi/engine.rb +43 -7
- data/lib/samagotchi/guardrail_wiring.rb +10 -1
- data/lib/samagotchi/llm/chat_loop.rb +1 -0
- data/lib/samagotchi/session.rb +40 -3
- data/lib/samagotchi/session_inbox.rb +14 -8
- data/lib/samagotchi/session_manager.rb +11 -4
- data/lib/samagotchi/session_participants.rb +10 -2
- data/lib/samagotchi/verdict.rb +20 -0
- data/lib/samagotchi/verify_anchor.rb +28 -0
- data/lib/samagotchi/verify_fresh.rb +275 -0
- data/lib/samagotchi/verify_fresh_origin.rb +71 -0
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +3 -0
- data/lib/samagotchi/web/participant_access.rb +15 -4
- data/lib/samagotchi/web/participant_review.rb +7 -1
- data/lib/samagotchi/web/participant_view.rb +46 -5
- data/lib/samagotchi/web/public/annotate_bar.js +9 -1
- data/lib/samagotchi/web/public/app.js +69 -4
- data/lib/samagotchi/web/public/data.js +2 -1
- data/lib/samagotchi/web/public/index.html +1 -0
- data/lib/samagotchi/web/public/notify.js +13 -2
- data/lib/samagotchi/web/public/participant.html +2 -1
- data/lib/samagotchi/web/public/participant.js +69 -7
- data/lib/samagotchi/web/public/send_turn.js +6 -1
- data/lib/samagotchi/web/public/session_state.js +5 -0
- data/lib/samagotchi/web/public/stream_handlers.js +3 -0
- data/lib/samagotchi/web/public/verdict_card.js +65 -0
- data/lib/samagotchi/web/public/verdict_fresh.js +120 -0
- data/lib/samagotchi/web/public/verify_card.css +17 -0
- data/lib/samagotchi/web/push/attention.rb +25 -5
- data/lib/samagotchi/web/push/notifier.rb +4 -3
- data/lib/samagotchi/web/session_control.rb +2 -0
- data/lib/samagotchi/web/session_summary.rb +25 -1
- data/lib/samagotchi/web/verify_fresh_routes.rb +110 -0
- data/lib/samagotchi/worker.rb +68 -9
- data/lib/samagotchi/worker_inbound.rb +4 -4
- metadata +9 -1
data/lib/samagotchi/web/app.rb
CHANGED
|
@@ -69,6 +69,7 @@ require_relative "message_display"
|
|
|
69
69
|
require_relative "session_show"
|
|
70
70
|
require_relative "session_create"
|
|
71
71
|
require_relative "session_control"
|
|
72
|
+
require_relative "verify_fresh_routes"
|
|
72
73
|
require_relative "push_routes"
|
|
73
74
|
require_relative "update_check"
|
|
74
75
|
require_relative "proxy_gate"
|
|
@@ -99,6 +100,7 @@ module Samagotchi
|
|
|
99
100
|
include SessionShow
|
|
100
101
|
include SessionCreate
|
|
101
102
|
include SessionControl
|
|
103
|
+
include VerifyFreshRoutes
|
|
102
104
|
include PushRoutes
|
|
103
105
|
include ProxyGate
|
|
104
106
|
|
|
@@ -265,6 +267,7 @@ module Samagotchi
|
|
|
265
267
|
["POST", %r{\A/api/sessions/([^/]+)/turn\z}, :handle_turn, :participant, :session],
|
|
266
268
|
["POST", %r{\A/api/sessions/([^/]+)/wait/prepare\z}, :handle_wait_prepare, :participant, :session],
|
|
267
269
|
["POST", %r{\A/api/sessions/([^/]+)/wait\z}, :handle_wait, :participant, :session],
|
|
270
|
+
["POST", %r{\A/api/sessions/([^/]+)/verdicts/([^/]+)/fresh\z}, :handle_verify_fresh, :participant, :session],
|
|
268
271
|
["POST", %r{\A/api/sessions/([^/]+)/notes\z}, :handle_notes, :owner, :session],
|
|
269
272
|
["POST", %r{\A/api/sessions/([^/]+)/wake\z}, :handle_wake, :owner, :session],
|
|
270
273
|
["GET", %r{\A/api/sessions/([^/]+)/worker\z}, :handle_worker, :owner, :session],
|
|
@@ -14,6 +14,7 @@ require_relative "../participant_messages"
|
|
|
14
14
|
require_relative "../participants"
|
|
15
15
|
require_relative "../session"
|
|
16
16
|
require_relative "../turn_checkpoint"
|
|
17
|
+
require_relative "../verify_fresh"
|
|
17
18
|
require_relative "../log"
|
|
18
19
|
|
|
19
20
|
module Samagotchi
|
|
@@ -271,8 +272,10 @@ module Samagotchi
|
|
|
271
272
|
reason = participant_turn_refusal(grant, prompt, body)
|
|
272
273
|
return participant_turn_refused(grant, prompt, *reason) if reason
|
|
273
274
|
|
|
275
|
+
verify = VerifyAnchor.from(body["verify"])
|
|
274
276
|
result = SessionManager.deliver_turn(id, prompt: prompt, client_id: ClientId.review(grant.id),
|
|
275
277
|
delivery: Delivery::QUEUE, author: grant.author,
|
|
278
|
+
verify: verify,
|
|
276
279
|
pending_limit: grant.queue_limit + 1,
|
|
277
280
|
state_dir: @state_dir, manager: @manager,
|
|
278
281
|
bridge: -> { live_bridge_client(id) })
|
|
@@ -291,15 +294,23 @@ module Samagotchi
|
|
|
291
294
|
|
|
292
295
|
# [429, cap_reached, …] once the grant spent its cap (D7: their turns
|
|
293
296
|
# and the side requests they caused, from the session's saved
|
|
294
|
-
# analytics; a running turn's
|
|
295
|
-
#
|
|
297
|
+
# analytics, and their Verify fresh children's; a running turn's
|
|
298
|
+
# spend counts from its end, and the worker checks again before a
|
|
299
|
+
# queued one starts), nil before.
|
|
296
300
|
def participant_cap_refusal(grant)
|
|
297
|
-
|
|
298
|
-
return nil if SessionMetrics.saved_spend(dir, grant.author) < grant.spend_cap
|
|
301
|
+
return nil if participant_saved_spend(grant) < grant.spend_cap
|
|
299
302
|
|
|
300
303
|
[429, "cap_reached", ParticipantMessages::CAP_REACHED]
|
|
301
304
|
end
|
|
302
305
|
|
|
306
|
+
# What +grant+'s participant spent, saved: in the session and in
|
|
307
|
+
# their Verify fresh children (VerifyFresh.children_spend).
|
|
308
|
+
def participant_saved_spend(grant)
|
|
309
|
+
dir = Session.session_dir(grant.session_id, state_dir: default_state_dir)
|
|
310
|
+
SessionMetrics.saved_spend(dir, grant.author) +
|
|
311
|
+
VerifyFresh.children_spend(grant.session_id, grant.author, state_dir: default_state_dir)
|
|
312
|
+
end
|
|
313
|
+
|
|
303
314
|
def participant_turn_refused(grant, prompt, status, code, detail)
|
|
304
315
|
audit_turn(grant, prompt, status: "refused", reason: code)
|
|
305
316
|
error_response(status, code, detail)
|
|
@@ -7,6 +7,7 @@ require_relative "../session_metrics"
|
|
|
7
7
|
require_relative "../review_start"
|
|
8
8
|
require_relative "../guardrails/review_paths"
|
|
9
9
|
require_relative "../participant_mode"
|
|
10
|
+
require_relative "../verify_fresh"
|
|
10
11
|
|
|
11
12
|
module Samagotchi
|
|
12
13
|
module Web
|
|
@@ -73,6 +74,10 @@ module Samagotchi
|
|
|
73
74
|
current_turn: current,
|
|
74
75
|
waiting_for_owner: waiting,
|
|
75
76
|
queued: review_queue(queued || [], viewer),
|
|
77
|
+
verdicts: ParticipantView.verdicts(VerifyFresh.verdicts_of(session, Session.session_dir(id, state_dir: default_state_dir)), viewer),
|
|
78
|
+
# The verdicts a fresh check runs for now (their check_turn_id;
|
|
79
|
+
# never the child's id: a participant can't open it).
|
|
80
|
+
fresh_running: VerifyFresh.running(id, state_dir: default_state_dir).map { |row| row[:of] }.uniq,
|
|
76
81
|
last_event_id: turn_snapshot && turn_snapshot["event_id"]
|
|
77
82
|
})
|
|
78
83
|
end
|
|
@@ -190,7 +195,8 @@ module Samagotchi
|
|
|
190
195
|
dir = Session.session_dir(grant.session_id, state_dir: default_state_dir)
|
|
191
196
|
saved = SessionMetrics.saved_spend(dir, grant.author)
|
|
192
197
|
live = live_spend(state, grant.author)
|
|
193
|
-
|
|
198
|
+
fresh = VerifyFresh.children_spend(grant.session_id, grant.author, state_dir: default_state_dir)
|
|
199
|
+
([saved, live].max + fresh).round(4)
|
|
194
200
|
end
|
|
195
201
|
|
|
196
202
|
# +author+'s cost in the live worker's metrics (spend_by_author), 0.0
|
|
@@ -4,15 +4,17 @@ require_relative "../output_formatter"
|
|
|
4
4
|
require_relative "../steer"
|
|
5
5
|
require_relative "../turn_origin"
|
|
6
6
|
require_relative "../participant_mode"
|
|
7
|
+
require_relative "../verify_anchor"
|
|
7
8
|
|
|
8
9
|
module Samagotchi
|
|
9
10
|
module Web
|
|
10
11
|
# What a participant sees of their session (D5 a): prompts and replies
|
|
11
12
|
# with their authors, one-line tool rows (the tool's name, and a
|
|
12
13
|
# project-relative path for a file tool), turn boundaries, and the
|
|
13
|
-
# waiting states.
|
|
14
|
-
#
|
|
15
|
-
#
|
|
14
|
+
# waiting states. Verdict cards expose only their anchor, verdict,
|
|
15
|
+
# reason and author. Never: tool output or arguments, thinking, context
|
|
16
|
+
# notes, plugin steers, automatic input, other cards, commands,
|
|
17
|
+
# questions' internals, memories, the working set, cost or timing, host paths.
|
|
16
18
|
#
|
|
17
19
|
# Every read a participant reaches goes through here: the stream's
|
|
18
20
|
# events (#event, ParticipantStreamFilter), the review route's
|
|
@@ -47,6 +49,9 @@ module Samagotchi
|
|
|
47
49
|
"turn_completed" => :turn_ended,
|
|
48
50
|
"turn_canceled" => :turn_ended,
|
|
49
51
|
"turn_failed" => :turn_ended,
|
|
52
|
+
# A Verify fresh child's verdict landing on its card: the card's
|
|
53
|
+
# fields only (#verdict_record).
|
|
54
|
+
"verdict_recorded" => :verdict_recorded,
|
|
50
55
|
"generation_chunk" => :generation_chunk,
|
|
51
56
|
"generation_retrying" => :generation_retrying,
|
|
52
57
|
"tool_call_started" => :tool_call_started,
|
|
@@ -125,8 +130,44 @@ module Samagotchi
|
|
|
125
130
|
out
|
|
126
131
|
end
|
|
127
132
|
|
|
128
|
-
def turn_ended(event,
|
|
129
|
-
{ "type" => field(event, :type).to_s, **id_fields(event) }
|
|
133
|
+
def turn_ended(event, viewer)
|
|
134
|
+
out = { "type" => field(event, :type).to_s, **id_fields(event) }
|
|
135
|
+
verdict = verdict_record(field(event, :verdict), viewer)
|
|
136
|
+
out["verdict"] = verdict if verdict
|
|
137
|
+
out
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def verdicts(records, viewer)
|
|
141
|
+
Array(records).filter_map { |record| verdict_record(record, viewer) }
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def verdict_record(raw, viewer)
|
|
145
|
+
return unless raw.is_a?(Hash)
|
|
146
|
+
|
|
147
|
+
anchor = VerifyAnchor.from(field(raw, :anchor))
|
|
148
|
+
verdict = field(raw, :verdict).to_s
|
|
149
|
+
reason = field(raw, :reason)
|
|
150
|
+
check_turn_id = field(raw, :check_turn_id)
|
|
151
|
+
by = field(raw, :by)
|
|
152
|
+
return unless anchor && %w[confirmed refuted unclear].include?(verdict) && reason.is_a?(String)
|
|
153
|
+
return unless check_turn_id.is_a?(String) && !check_turn_id.empty?
|
|
154
|
+
return unless by.nil? || by.is_a?(String)
|
|
155
|
+
|
|
156
|
+
out = {
|
|
157
|
+
"anchor" => { "turn_id" => anchor.turn_id, "quote" => anchor.quote },
|
|
158
|
+
"verdict" => verdict, "reason" => reason, "by" => by,
|
|
159
|
+
"check_turn_id" => check_turn_id
|
|
160
|
+
}
|
|
161
|
+
# A Verify fresh verdict: which verdict it checked again (never the
|
|
162
|
+
# child's id: a participant can't open that session).
|
|
163
|
+
of = field(raw, :of)
|
|
164
|
+
out.merge!("fresh" => true, "of" => of) if field(raw, :fresh) == true && of.is_a?(String) && !of.empty?
|
|
165
|
+
Redact.deep(out, viewer)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def verdict_recorded(event, viewer)
|
|
169
|
+
verdict = verdict_record(field(event, :verdict), viewer) or return nil
|
|
170
|
+
{ "type" => "verdict_recorded", "verdict" => verdict }
|
|
130
171
|
end
|
|
131
172
|
|
|
132
173
|
# The reply's visible text only: never thinking, a tool call's bytes
|
|
@@ -56,7 +56,7 @@ import { actionEnabled, actionTitle, sameActions, selectionFields, splitInline }
|
|
|
56
56
|
// @return {schedule(), hide(), el}; schedule() re-reads the selection on the
|
|
57
57
|
// next frame (call it on scroll)
|
|
58
58
|
export function createAnnotateBar({
|
|
59
|
-
presets, canAnnotate, roots, isLive, onQuote, actions = () => [], running = () => false, onAction = () => {},
|
|
59
|
+
presets, canAnnotate, roots, isLive, onQuote, onPreset = () => {}, actions = () => [], running = () => false, onAction = () => {},
|
|
60
60
|
dock = () => null, source: sourceOf = annotationSource, quote = quoteBlock, link = () => null, onLink = () => {},
|
|
61
61
|
doc = globalThis.document, win = globalThis.window,
|
|
62
62
|
}) {
|
|
@@ -93,6 +93,8 @@ export function createAnnotateBar({
|
|
|
93
93
|
const touch = win.matchMedia?.("(pointer: coarse)");
|
|
94
94
|
let pendingQuote = null;
|
|
95
95
|
let pendingFields = null;
|
|
96
|
+
let pendingSource = null;
|
|
97
|
+
let pendingRange = null;
|
|
96
98
|
let pendingLink = null;
|
|
97
99
|
let drawn = [];
|
|
98
100
|
let moreList = null;
|
|
@@ -141,6 +143,8 @@ export function createAnnotateBar({
|
|
|
141
143
|
function hide() {
|
|
142
144
|
pendingQuote = null;
|
|
143
145
|
pendingFields = null;
|
|
146
|
+
pendingSource = null;
|
|
147
|
+
pendingRange = null;
|
|
144
148
|
pendingLink = null;
|
|
145
149
|
if (moreList) moreList.hidden = true;
|
|
146
150
|
bar.hidden = true;
|
|
@@ -164,6 +168,8 @@ export function createAnnotateBar({
|
|
|
164
168
|
if (!block) return hide();
|
|
165
169
|
pendingQuote = block;
|
|
166
170
|
pendingFields = selectionFields(raw, source);
|
|
171
|
+
pendingSource = source;
|
|
172
|
+
pendingRange = clipped;
|
|
167
173
|
pendingLink = link(source, clipped) || null;
|
|
168
174
|
linkBtn.hidden = !pendingLink;
|
|
169
175
|
linkBtn.title = pendingLink?.title || "";
|
|
@@ -243,8 +249,10 @@ export function createAnnotateBar({
|
|
|
243
249
|
}
|
|
244
250
|
const preset = btn.dataset.index === undefined ? null : presets[Number(btn.dataset.index)];
|
|
245
251
|
const text = preset ? presetNote(pendingQuote, presetParts(preset).text) : pendingQuote;
|
|
252
|
+
const fields = { ...pendingFields, source: pendingSource, range: pendingRange };
|
|
246
253
|
win.getSelection()?.removeAllRanges();
|
|
247
254
|
hide();
|
|
255
|
+
if (preset) onPreset(preset, fields);
|
|
248
256
|
onQuote(text);
|
|
249
257
|
});
|
|
250
258
|
|
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
restartWorkers,
|
|
31
31
|
restartWeb,
|
|
32
32
|
onAuthLost,
|
|
33
|
+
api,
|
|
33
34
|
} from "./data.js";
|
|
34
35
|
import { authProbe, createAuthLost } from "./auth_lost.js";
|
|
35
36
|
import { REPLACE_SESSION_TEXT, fragmentCode, tradeFragmentCode } from "./token_fragment.js";
|
|
@@ -58,10 +59,12 @@ import { createTaskStopper } from "./task_stop.js";
|
|
|
58
59
|
import { createSystemOneWrongAction } from "./system_one_wrong.js";
|
|
59
60
|
import { appendQuote } from "./annotations.js";
|
|
60
61
|
import { applyComposerText, applyRowTemplate, fetchApply } from "./review_apply.js";
|
|
62
|
+
import { nameVerdictCards } from "./verdict_card.js";
|
|
63
|
+
import { freshURL, placeVerdictWithFresh, settleRunning } from "./verdict_fresh.js";
|
|
61
64
|
import { authorBadge, nameUnnamedBadges } from "./participant_names.js";
|
|
62
65
|
import { parsePresets } from "./annotate_presets.js";
|
|
63
66
|
import { createAnnotateBar } from "./annotate_bar.js";
|
|
64
|
-
import { withVerify } from "./verify_preset.js";
|
|
67
|
+
import { VERIFY_PRESET, withVerify } from "./verify_preset.js";
|
|
65
68
|
import { actionLine, annotationActions, composerWithAction } from "./annotate_actions.js";
|
|
66
69
|
import { copyText, installCopy } from "./copy.js";
|
|
67
70
|
import { createQuestionCards } from "./question_cards.js";
|
|
@@ -179,7 +182,13 @@ const participantsControl = createParticipantsControl({
|
|
|
179
182
|
startReview: (opts) => sessionActions.reviewSelected(opts),
|
|
180
183
|
reviewing: () => sessionActions.reviewing.has(selected),
|
|
181
184
|
// An older prompt drawn before the list came says "a participant": named now.
|
|
182
|
-
onNames: () =>
|
|
185
|
+
onNames: () => {
|
|
186
|
+
nameUnnamedBadges(document);
|
|
187
|
+
nameVerdictCards(historyEl, (author) => {
|
|
188
|
+
const badge = authorBadge(author);
|
|
189
|
+
return badge && !badge.unnamed ? badge.name : null;
|
|
190
|
+
});
|
|
191
|
+
},
|
|
183
192
|
onChange: () => updateInfoBar(),
|
|
184
193
|
toast: (text, action, options) => showToast(text, action, options),
|
|
185
194
|
});
|
|
@@ -224,6 +233,7 @@ const infoCancelBtn = $("#infoCancelBtn");
|
|
|
224
233
|
const composeHintEl = $("#composeHint");
|
|
225
234
|
|
|
226
235
|
let selected = null;
|
|
236
|
+
let pendingVerifyAnchor = null;
|
|
227
237
|
// The session the composer's text was last written in ("" the start page,
|
|
228
238
|
// undefined unknown): the composer is one for every session, and continue →
|
|
229
239
|
// keeps only a draft of its own (fillOpener).
|
|
@@ -970,13 +980,16 @@ function clearNotice() {
|
|
|
970
980
|
}
|
|
971
981
|
promptEl.addEventListener("input", clearNotice);
|
|
972
982
|
promptEl.addEventListener("input", () => noteDraft());
|
|
973
|
-
// An emptied composer lets go of its Apply turn.
|
|
983
|
+
// An emptied composer lets go of its Apply turn and its Verify claim.
|
|
974
984
|
promptEl.addEventListener("input", () => {
|
|
975
|
-
if (
|
|
985
|
+
if (promptEl.value.trim()) return;
|
|
986
|
+
deliveryControl.release();
|
|
987
|
+
pendingVerifyAnchor = null;
|
|
976
988
|
});
|
|
977
989
|
|
|
978
990
|
async function select(id) {
|
|
979
991
|
clearNotice();
|
|
992
|
+
if (selected !== id) pendingVerifyAnchor = null;
|
|
980
993
|
selected = id;
|
|
981
994
|
setSessionHash(id);
|
|
982
995
|
lists.paintActive();
|
|
@@ -1173,6 +1186,7 @@ function renderHistory(items) {
|
|
|
1173
1186
|
}
|
|
1174
1187
|
if (typeof items[0] === "object" && items[0].role) {
|
|
1175
1188
|
historyEl.replaceChildren(turnHistoryNodes(items, current.timing, { thumbs: (images) => thumbsTemplate(selected, images), workingSet: !!workingSet }));
|
|
1189
|
+
renderSavedVerdicts();
|
|
1176
1190
|
// The live dividers count from the history's last activity.
|
|
1177
1191
|
gapClock.seed(lastActivity(turnGroups(items, current.timing), items));
|
|
1178
1192
|
linkTextRefs();
|
|
@@ -1314,6 +1328,44 @@ function placeApply(data) {
|
|
|
1314
1328
|
appendToHistory(elementOf(applyRowTemplate(data.turn_id, badge)));
|
|
1315
1329
|
}
|
|
1316
1330
|
|
|
1331
|
+
function placeVerdict(record) {
|
|
1332
|
+
if (!record) return;
|
|
1333
|
+
const known = (current.verdicts || []).some((item) => item.check_turn_id === record.check_turn_id);
|
|
1334
|
+
if (!known) current.verdicts = [...(current.verdicts || []), record];
|
|
1335
|
+
// A fresh verdict ends its check's "verifying fresh" (the card shows it).
|
|
1336
|
+
if (record.fresh) current.verifyFresh = settleRunning(current.verifyFresh, record);
|
|
1337
|
+
const badge = record.by && authorBadge(record.by);
|
|
1338
|
+
placeVerdictWithFresh(historyEl, record, {
|
|
1339
|
+
who: badge ? badge.name : "You",
|
|
1340
|
+
author: record.by || null,
|
|
1341
|
+
}, verifyFreshState());
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
// The owner's Verify fresh on an unclear verdict's card (verdict_fresh.js):
|
|
1345
|
+
// always theirs to start; its running check links to the child's session.
|
|
1346
|
+
function verifyFreshState() {
|
|
1347
|
+
const id = selected;
|
|
1348
|
+
if (!Array.isArray(current.verifyFresh)) current.verifyFresh = [];
|
|
1349
|
+
return {
|
|
1350
|
+
verdicts: current.verdicts || [],
|
|
1351
|
+
running: current.verifyFresh,
|
|
1352
|
+
canStart: !!id,
|
|
1353
|
+
start: async (of) => {
|
|
1354
|
+
try {
|
|
1355
|
+
const body = await api(freshURL(id, of), { method: "POST", body: "{}" });
|
|
1356
|
+
return { ok: true, child_id: body.child_id || null };
|
|
1357
|
+
} catch (error) {
|
|
1358
|
+
return { ok: false, error: error.message };
|
|
1359
|
+
}
|
|
1360
|
+
},
|
|
1361
|
+
childHref: (childId) => sessionHash(childId),
|
|
1362
|
+
};
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
function renderSavedVerdicts() {
|
|
1366
|
+
for (const record of current.verdicts || []) placeVerdict(record);
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1317
1369
|
// Apply: the owner's Apply turn into the composer, after what is typed
|
|
1318
1370
|
// there; never sent from here.
|
|
1319
1371
|
historyEl.addEventListener("click", async (e) => {
|
|
@@ -1551,6 +1603,7 @@ const streamHandlers = createStreamHandlers({
|
|
|
1551
1603
|
workingSet,
|
|
1552
1604
|
participantsControl,
|
|
1553
1605
|
placeApply,
|
|
1606
|
+
placeVerdict,
|
|
1554
1607
|
sentIds,
|
|
1555
1608
|
earlyRestores,
|
|
1556
1609
|
stream: {
|
|
@@ -1656,6 +1709,8 @@ const sendTurnControl = createSendTurn({
|
|
|
1656
1709
|
sentIds,
|
|
1657
1710
|
earlyRestores,
|
|
1658
1711
|
api: { createIdleSession, uploadImage, sendTurn },
|
|
1712
|
+
verify: () => pendingVerifyAnchor,
|
|
1713
|
+
clearVerify: (anchor) => { if (pendingVerifyAnchor === anchor) pendingVerifyAnchor = null; },
|
|
1659
1714
|
dir: scope.dir,
|
|
1660
1715
|
startPage,
|
|
1661
1716
|
takeDelivery: () => deliveryControl.take(),
|
|
@@ -1899,6 +1954,9 @@ const annotateBar = createAnnotateBar({
|
|
|
1899
1954
|
roots: turnRoots,
|
|
1900
1955
|
isLive: (root) => liveTurn.running && turnDom.containsLive(root),
|
|
1901
1956
|
onQuote: (text) => fillComposer(appendQuote(promptEl.value, text)),
|
|
1957
|
+
onPreset: (preset, fields) => {
|
|
1958
|
+
pendingVerifyAnchor = preset === VERIFY_PRESET ? verifyAnchorFor(fields) : null;
|
|
1959
|
+
},
|
|
1902
1960
|
actions: () => annotationActions(current.commands),
|
|
1903
1961
|
running: () => liveTurn.running,
|
|
1904
1962
|
onAction: (action, fields) => {
|
|
@@ -1910,6 +1968,13 @@ const annotateBar = createAnnotateBar({
|
|
|
1910
1968
|
onLink: copyClaimLink,
|
|
1911
1969
|
dock: () => $("#dock"),
|
|
1912
1970
|
});
|
|
1971
|
+
|
|
1972
|
+
function verifyAnchorFor({ source, range }) {
|
|
1973
|
+
if (!source || !["answer", "step", "user"].includes(source.kind) || !historyEl.contains(source.root)) return null;
|
|
1974
|
+
const turnId = turnIdOf(historyEl, source.root);
|
|
1975
|
+
const quote = selectionClaim(source.root, range, claimOpts()).q;
|
|
1976
|
+
return turnId && quote ? { turn_id: turnId, quote } : null;
|
|
1977
|
+
}
|
|
1913
1978
|
historyEl.addEventListener("scroll", annotateBar.schedule);
|
|
1914
1979
|
// A command bubble's Apply (CacheConfirm): sends the change's --yes line
|
|
1915
1980
|
// once; its own bubble then says what it did.
|
|
@@ -140,11 +140,12 @@ export function getSession(id, { tail, recent, turnId, timing, parts, cards, ...
|
|
|
140
140
|
// image-only send, whose text is only its [image: …] placeholders).
|
|
141
141
|
// delivery: what the message does to a running turn ("cut": /cut TEXT);
|
|
142
142
|
// none = the server's default (the next step).
|
|
143
|
-
export function sendTurn(id, prompt, { clientId, images, history = true, delivery = null, ...opts } = {}) {
|
|
143
|
+
export function sendTurn(id, prompt, { clientId, images, history = true, delivery = null, verify = null, ...opts } = {}) {
|
|
144
144
|
const body = clientId ? { prompt, client_id: clientId } : { prompt };
|
|
145
145
|
if (images?.length) body.images = images;
|
|
146
146
|
if (delivery) body.delivery = delivery;
|
|
147
147
|
if (history === false) body.history = false;
|
|
148
|
+
if (verify) body.verify = verify;
|
|
148
149
|
return api(`/api/sessions/${id}/turn`, {
|
|
149
150
|
method: "POST",
|
|
150
151
|
body: JSON.stringify(body),
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
<meta name="apple-mobile-web-app-title" content="Chi">
|
|
11
11
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
12
12
|
<link rel="stylesheet" href="/assets/tokens.css">
|
|
13
|
+
<link rel="stylesheet" href="/assets/verify_card.css">
|
|
13
14
|
<link rel="stylesheet" href="/assets/annotate_bar.css">
|
|
14
15
|
<link rel="stylesheet" href="/assets/composer.css">
|
|
15
16
|
<link rel="stylesheet" href="/assets/forms.css">
|
|
@@ -20,6 +20,7 @@ export function notifyState({ hasNotification, secureContext, permission, wanted
|
|
|
20
20
|
// (task): nobody started it, so nobody watched it.
|
|
21
21
|
const DONE_MIN_SECONDS = 10;
|
|
22
22
|
const UNWATCHED_ORIGINS = ["delegate_report", "context", "task"];
|
|
23
|
+
const VERDICT_REASON_MAX = 120;
|
|
23
24
|
|
|
24
25
|
// The step-limit question (kind "continue": a turn ran out of iterations
|
|
25
26
|
// and asks whether to go on) has its own reason: "out of steps".
|
|
@@ -52,7 +53,7 @@ const RELAYED_KINDS = new Set(["approval", "hook"]);
|
|
|
52
53
|
// What changed between two summaries of one session that needs the user.
|
|
53
54
|
// @param prev the summary held before (null for a session not seen yet)
|
|
54
55
|
// @param next the new summary
|
|
55
|
-
// @return null | {reason: "question"|"approval"|"card"|"failed"|"done", sessionId, key}
|
|
56
|
+
// @return null | {reason: "question"|"approval"|"card"|"failed"|"done"|"verdict", sessionId, key}
|
|
56
57
|
// key names this one event, the same in every tab (the Notification tag);
|
|
57
58
|
// holdMs, when there, delays it (a delegated child's approval)
|
|
58
59
|
export function attentionFor(prev, next) {
|
|
@@ -75,6 +76,10 @@ export function attentionFor(prev, next) {
|
|
|
75
76
|
// A delegated child's turn is reported by its parent's.
|
|
76
77
|
if (next.parent_id) return null;
|
|
77
78
|
const key = `${next.id}:${turn.ended_at}`;
|
|
79
|
+
const verdict = next.last_verdict;
|
|
80
|
+
if (verdict?.check_turn_id && verdict.check_turn_id !== prev?.last_verdict?.check_turn_id) {
|
|
81
|
+
return { reason: "verdict", sessionId: next.id, key: `${next.id}:${verdict.check_turn_id}` };
|
|
82
|
+
}
|
|
78
83
|
if (turn.outcome === "failed") return { reason: "failed", sessionId: next.id, key };
|
|
79
84
|
if (turn.outcome === "completed" && (Number(turn.seconds) >= DONE_MIN_SECONDS || UNWATCHED_ORIGINS.includes(turn.origin))) {
|
|
80
85
|
return { reason: "done", sessionId: next.id, key };
|
|
@@ -157,13 +162,19 @@ export function attentionText(session, attention) {
|
|
|
157
162
|
const name = String(session?.title || session?.auto_title || session?.recap || session?.first_preview || session?.last_prompt || "chi session").trim();
|
|
158
163
|
const title = clip(name, 61);
|
|
159
164
|
const seconds = Math.round(Number(session?.last_turn?.seconds) || 0);
|
|
165
|
+
const verdict = session?.last_verdict;
|
|
166
|
+
const who = verdict?.by_name || (verdict?.by ? "A participant" : "You");
|
|
167
|
+
const verdictReason = clip(String(verdict?.reason || ""), VERDICT_REASON_MAX);
|
|
168
|
+
const verdictIcon = { confirmed: "✅", refuted: "❌", unclear: "❓" }[verdict?.verdict] || "";
|
|
169
|
+
const verdictBody = `${who}: ${verdictIcon} ${verdict?.verdict || ""} — ${verdictReason}`;
|
|
160
170
|
const body = {
|
|
161
171
|
question: "needs an answer",
|
|
162
172
|
approval: "needs approval",
|
|
163
173
|
continue: "hit its step limit",
|
|
164
174
|
card: "needs you",
|
|
165
175
|
failed: "turn failed",
|
|
166
|
-
done: `done in ${seconds} s
|
|
176
|
+
done: `done in ${seconds} s`,
|
|
177
|
+
verdict: verdictBody
|
|
167
178
|
}[attention.reason] || "";
|
|
168
179
|
return { title, body };
|
|
169
180
|
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
<link rel="icon" href="/assets/favicon.svg" type="image/svg+xml">
|
|
7
7
|
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
|
|
8
8
|
<link rel="stylesheet" href="/assets/tokens.css">
|
|
9
|
+
<link rel="stylesheet" href="/assets/verify_card.css">
|
|
9
10
|
<link rel="stylesheet" href="/assets/annotate_bar.css">
|
|
10
11
|
<link rel="stylesheet" href="/assets/composer.css">
|
|
11
12
|
<link rel="stylesheet" href="/assets/forms.css">
|
|
@@ -94,7 +95,7 @@ main{flex:1;min-height:0;overflow-y:auto;padding:16px 16px 8px}
|
|
|
94
95
|
.p-tools{font-size:12.5px;color:var(--text-muted)}
|
|
95
96
|
.p-tools summary{cursor:pointer;list-style:none;display:inline-flex;align-items:center;gap:6px;padding:2px 0}
|
|
96
97
|
.p-tools summary::-webkit-details-marker{display:none}
|
|
97
|
-
.p-tools summary::before{content:"▸"
|
|
98
|
+
.p-tools summary::before{content:"▸"}
|
|
98
99
|
.p-tools[open] summary::before{content:"▾"}
|
|
99
100
|
.p-tools ul{list-style:none;padding:2px 0 0 14px;display:flex;flex-direction:column;gap:1px}
|
|
100
101
|
.p-tools li{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
@@ -22,10 +22,11 @@ import { createAuthLost, lostAnswer } from "./auth_lost.js";
|
|
|
22
22
|
import { REPLACE_SESSION_TEXT, fragmentCode, tradeFragmentCode } from "./token_fragment.js";
|
|
23
23
|
import { createAnnotateBar } from "./annotate_bar.js";
|
|
24
24
|
import { parsePresets } from "./annotate_presets.js";
|
|
25
|
-
import { withVerify } from "./verify_preset.js";
|
|
25
|
+
import { VERIFY_PRESET, withVerify } from "./verify_preset.js";
|
|
26
26
|
import { appendQuote } from "./annotations.js";
|
|
27
27
|
import { messageAuthorData, participantQuote, participantSource } from "./participant_annotate.js";
|
|
28
|
-
import { claimFromHash, showClaim } from "./claim_link.js";
|
|
28
|
+
import { claimFromHash, selectionClaim, showClaim } from "./claim_link.js";
|
|
29
|
+
import { freshURL, placeVerdictWithFresh, settleRunning } from "./verdict_fresh.js";
|
|
29
30
|
import { mountComposer } from "./composer_mount.js";
|
|
30
31
|
import { PROMPT_LINE_PX } from "./composer_size.js";
|
|
31
32
|
import {
|
|
@@ -46,6 +47,7 @@ const ownerView = body.viewer === "owner";
|
|
|
46
47
|
const sessionId = body.session || new URLSearchParams(location.hash.slice(1)).get("s") || "";
|
|
47
48
|
|
|
48
49
|
let data = null;
|
|
50
|
+
let pendingVerifyAnchor = null;
|
|
49
51
|
let live = null;
|
|
50
52
|
// A turn boundary came after the data drawn: live events wait for the
|
|
51
53
|
// re-read (its stream replays them).
|
|
@@ -176,6 +178,16 @@ function connect() {
|
|
|
176
178
|
const onEvent = (event) => {
|
|
177
179
|
let parsed;
|
|
178
180
|
try { parsed = JSON.parse(event.data); } catch { return; }
|
|
181
|
+
if (parsed.verdict) {
|
|
182
|
+
const known = (data.verdicts || []).some((record) => record.check_turn_id === parsed.verdict.check_turn_id);
|
|
183
|
+
if (!known) {
|
|
184
|
+
data.verdicts = [...(data.verdicts || []), parsed.verdict];
|
|
185
|
+
// A fresh verdict ends its check's "verifying fresh".
|
|
186
|
+
data.fresh_running = settleRunning(data.fresh_running, parsed.verdict);
|
|
187
|
+
renderThread();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (parsed.type === "verdict_recorded") return;
|
|
179
191
|
if (reloads(parsed.type)) {
|
|
180
192
|
if (endsLiveTurn(parsed.type)) liveStale = true;
|
|
181
193
|
return scheduleReload();
|
|
@@ -190,7 +202,7 @@ function connect() {
|
|
|
190
202
|
for (const type of ["generation_chunk", "generation_retrying", "tool_call_started", "tool_call_completed",
|
|
191
203
|
"turn_started", "turn_completed", "turn_canceled", "turn_failed", "turn_enqueued", "turn_dequeued", "input_merged",
|
|
192
204
|
"question_requested", "question_answered", "question_cancelled", "continue_offered", "continue_resolved",
|
|
193
|
-
"snapshot", "reset"]) {
|
|
205
|
+
"snapshot", "reset", "verdict_recorded"]) {
|
|
194
206
|
source.addEventListener(type, onEvent);
|
|
195
207
|
}
|
|
196
208
|
source.onerror = () => {
|
|
@@ -202,9 +214,11 @@ function connect() {
|
|
|
202
214
|
function render() {
|
|
203
215
|
const viewer = data.viewer || {};
|
|
204
216
|
const session = data.session || {};
|
|
205
|
-
|
|
217
|
+
// A pair participant works in the session: their page says so, not "review".
|
|
218
|
+
const whose = viewer.mode === "pair" ? `${viewer.name} · pairing` : `${viewer.name}'s review`;
|
|
219
|
+
document.title = ownerView ? `chi · participant view · ${session.title}` : `chi · ${whose}`;
|
|
206
220
|
const title = $("title");
|
|
207
|
-
title.replaceChildren(ownerView ? "Participant view" :
|
|
221
|
+
title.replaceChildren(ownerView ? "Participant view" : whose, el("span", "p-sub", ` · ${session.title}`));
|
|
208
222
|
title.title = session.title || "";
|
|
209
223
|
const status = $("status");
|
|
210
224
|
const waiting = data.waiting_for_owner;
|
|
@@ -394,10 +408,42 @@ function renderThread() {
|
|
|
394
408
|
const main = $("main");
|
|
395
409
|
const atBottom = main.scrollHeight - main.scrollTop - main.clientHeight < 80;
|
|
396
410
|
syncChildren(thread, nodes);
|
|
411
|
+
for (const record of data.verdicts || []) {
|
|
412
|
+
const author = record.by || null;
|
|
413
|
+
const viewer = data.viewer || {};
|
|
414
|
+
let who = ownerView ? "You" : "Owner";
|
|
415
|
+
if (author && author !== "owner") {
|
|
416
|
+
if (!ownerView && author === participantAuthor(viewer.id)) who = "You";
|
|
417
|
+
else {
|
|
418
|
+
who = (data.participants || []).find((participant) => participantAuthor(participant.id) === author)?.name || "A participant";
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
placeVerdictWithFresh(thread, record, { who, author }, verifyFreshState());
|
|
422
|
+
}
|
|
397
423
|
if (atBottom || !thread.dataset.drawn) main.scrollTop = main.scrollHeight;
|
|
398
424
|
thread.dataset.drawn = "1";
|
|
399
425
|
}
|
|
400
426
|
|
|
427
|
+
// Verify fresh on an unclear verdict's card (verdict_fresh.js): a
|
|
428
|
+
// participant starts one while their grant could run a turn now
|
|
429
|
+
// (can_comment); the owner looking through the participant view never
|
|
430
|
+
// does, and no one here gets a link to the child's session.
|
|
431
|
+
function verifyFreshState() {
|
|
432
|
+
if (!Array.isArray(data.fresh_running)) data.fresh_running = [];
|
|
433
|
+
return {
|
|
434
|
+
verdicts: data.verdicts || [],
|
|
435
|
+
running: data.fresh_running,
|
|
436
|
+
canStart: !ownerView && !ended && !!data.viewer?.can_comment,
|
|
437
|
+
start: async (of) => {
|
|
438
|
+
const { ok, body } = await api(freshURL(sessionId, of), {
|
|
439
|
+
method: "POST", body: "{}", headers: { "Content-Type": "application/json" },
|
|
440
|
+
});
|
|
441
|
+
return ok ? { ok: true } : { ok: false, error: body?.detail || "Couldn't start a fresh check." };
|
|
442
|
+
},
|
|
443
|
+
childHref: () => null,
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
|
|
401
447
|
// +node+'s tool list open or closed as +old+'s was (the same place drawn
|
|
402
448
|
// again with new content).
|
|
403
449
|
function keepToolsOpen(node, old) {
|
|
@@ -516,13 +562,15 @@ async function sendComment() {
|
|
|
516
562
|
const comment = $("comment");
|
|
517
563
|
const prompt = comment.value.trim();
|
|
518
564
|
if (!prompt) return;
|
|
565
|
+
const verify = pendingVerifyAnchor;
|
|
519
566
|
sending = true;
|
|
520
567
|
$("send").disabled = true;
|
|
521
568
|
showError("");
|
|
522
569
|
let reply;
|
|
523
570
|
try {
|
|
524
571
|
reply = await api(`/api/sessions/${encodeURIComponent(sessionId)}/turn`, {
|
|
525
|
-
method: "POST", headers: { "Content-Type": "application/json" },
|
|
572
|
+
method: "POST", headers: { "Content-Type": "application/json" },
|
|
573
|
+
body: JSON.stringify({ prompt, ...(verify ? { verify } : {}) }),
|
|
526
574
|
});
|
|
527
575
|
} finally {
|
|
528
576
|
sending = false;
|
|
@@ -531,6 +579,7 @@ async function sendComment() {
|
|
|
531
579
|
const { ok, status, body: json } = reply;
|
|
532
580
|
if (ended) return;
|
|
533
581
|
if (ok) {
|
|
582
|
+
if (pendingVerifyAnchor === verify) pendingVerifyAnchor = null;
|
|
534
583
|
recordReviewComment(data?.viewer?.id, prompt);
|
|
535
584
|
// What was typed while the comment was in flight stays in the box.
|
|
536
585
|
if (comment.value.trim() === prompt) comment.value = "";
|
|
@@ -575,7 +624,11 @@ const composer = ownerView ? null : mountComposer({
|
|
|
575
624
|
});
|
|
576
625
|
if (composer) {
|
|
577
626
|
// An error under the box (a refusal, the images toast) goes at the next edit.
|
|
578
|
-
|
|
627
|
+
// An emptied box lets go of its Verify claim.
|
|
628
|
+
$("comment").addEventListener("input", (e) => {
|
|
629
|
+
showError("");
|
|
630
|
+
if (!e.target.value.trim()) pendingVerifyAnchor = null;
|
|
631
|
+
});
|
|
579
632
|
// The session composer's layout (composer.css), and the fold saved in this browser.
|
|
580
633
|
document.body.classList.add("has-session");
|
|
581
634
|
composer.newVisit();
|
|
@@ -600,10 +653,19 @@ const annotateBar = createAnnotateBar({
|
|
|
600
653
|
roots: () => [$("planDoc"), $("thread")],
|
|
601
654
|
isLive: (root) => !!root.closest?.(".p-msg.live"),
|
|
602
655
|
onQuote: quoteIntoComment,
|
|
656
|
+
onPreset: (preset, fields) => { pendingVerifyAnchor = preset === VERIFY_PRESET ? verifyAnchorFor(fields) : null; },
|
|
603
657
|
source: participantSource,
|
|
604
658
|
quote: participantQuote,
|
|
605
659
|
dock: () => $("dock"),
|
|
606
660
|
});
|
|
661
|
+
|
|
662
|
+
function verifyAnchorFor({ source, range }) {
|
|
663
|
+
const message = source?.root?.closest?.(".p-msg");
|
|
664
|
+
const turnId = message?.dataset?.turnId;
|
|
665
|
+
if (!turnId) return null;
|
|
666
|
+
const quote = selectionClaim(source.root, range).q;
|
|
667
|
+
return quote ? { turn_id: turnId, quote } : null;
|
|
668
|
+
}
|
|
607
669
|
$("main").addEventListener("scroll", annotateBar.schedule);
|
|
608
670
|
$("planScroll").addEventListener("scroll", annotateBar.schedule);
|
|
609
671
|
|
|
@@ -29,6 +29,7 @@ import { composerAfterAck, dropEarlyRestores, restoreOnAck } from "./restore.js"
|
|
|
29
29
|
// +alert+: the browser's.
|
|
30
30
|
export function createSendTurn({
|
|
31
31
|
session, state, running, clientId, sentIds, earlyRestores, api, dir, startPage, takeDelivery, composer,
|
|
32
|
+
verify = () => null, clearVerify = () => {},
|
|
32
33
|
historyEl, turnDom, makeUserBubble, bubbleById, addCommandBubble,
|
|
33
34
|
addCreatedSession, select, showNotice, updateInfoBar, updateComposerMode, followWokenWorker, refreshHistory,
|
|
34
35
|
leaveGoneSession, runCommand, toast, alert = (text) => globalThis.alert(text),
|
|
@@ -131,7 +132,10 @@ export function createSendTurn({
|
|
|
131
132
|
const sentTo = session();
|
|
132
133
|
try {
|
|
133
134
|
await uploadChips(sending, sentTo, { upload: api.uploadImage });
|
|
134
|
-
const
|
|
135
|
+
const verifyAnchor = verify();
|
|
136
|
+
const ack = await api.sendTurn(sentTo, prompt, {
|
|
137
|
+
clientId, images: turnRefs(sending), history: typed, delivery, ...(verifyAnchor ? { verify: verifyAnchor } : {}),
|
|
138
|
+
});
|
|
135
139
|
if (ack?.command_id) {
|
|
136
140
|
// The worker knew it as a command (its list was newer than ours):
|
|
137
141
|
// its command_ran shows it, not a prompt bubble.
|
|
@@ -140,6 +144,7 @@ export function createSendTurn({
|
|
|
140
144
|
if (sentTo === session()) followWokenWorker();
|
|
141
145
|
return;
|
|
142
146
|
}
|
|
147
|
+
if (verifyAnchor) clearVerify(verifyAnchor);
|
|
143
148
|
if (ack?.enqueued_id) sentIds.add(ack.enqueued_id);
|
|
144
149
|
// A cut the worker didn't take (no thinking-only step: cut off) goes in
|
|
145
150
|
// at the next step; a queue whose turn ended meanwhile is the next turn.
|