@penguinharness/penguin-support 0.2.16 → 0.2.18

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.
package/README.md CHANGED
@@ -4,4 +4,6 @@ The default Project installs this plugin on its PenguinHarness Support agent. Yo
4
4
 
5
5
  The workbench shows a centered question list. New question and conversation details open in dialogs; follow-ups stay on the same ticket. The `penguin-support` Skill reads the official docs and repository before answering. The selected Project model handles each question.
6
6
 
7
+ While a question is being researched, its dialog shows the answer as it is written and what the agent is doing, with a Stop button. The handler saves the answer as soon as the task ends, whether or not the page is open. On a server without live following (the workbench host's `subscribe` and the page SDK `../sdk/workbench.js`), the answer is saved when the question list is next loaded, and the dialog falls back to polling and shows only the waiting time.
8
+
7
9
  `workbenches/support/` contains plain HTML, CSS, JavaScript and a TypeScript backend. Installing or updating replaces its code while preserving `state.json` and workbench history. Uninstalling the workbench removes its records, just like removing a workbench from the agent.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@penguinharness/penguin-support",
3
- "version": "0.2.16",
3
+ "version": "0.2.18",
4
4
  "description": "PenguinHarness product support with a question list, conversation dialogs and answers grounded in documentation and source code.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -8,11 +8,39 @@ type Ticket = {
8
8
  sessionId: string;
9
9
  messages: Message[];
10
10
  error: string | null;
11
+ /** A person stopped its last task (the main Session's abort record said so); absent otherwise. */
12
+ stopped?: boolean;
11
13
  createdAt: string;
12
14
  updatedAt: string;
13
15
  };
14
16
  type State = { tickets: Ticket[] };
15
17
 
18
+ /**
19
+ * `host.subscribe` as this handler uses it. A server from before it has no such method and its
20
+ * `.harness/` types do not name it, so the handler reads it through this shape and, without
21
+ * it, leaves every answer to GET /tickets.
22
+ */
23
+ type Subscribe = (
24
+ sessionId: string,
25
+ listener: (record: {
26
+ origin?: string[];
27
+ payload: { type?: unknown; error_code?: unknown };
28
+ }) => void,
29
+ ) => () => void;
30
+
31
+ /** The abort codes of a person interrupting a task; the turn cap's `max_turns` is not one. */
32
+ const STOP_CODES: ReadonlySet<unknown> = new Set([
33
+ "user_abort",
34
+ "backoff_interrupted",
35
+ "compaction_interrupted",
36
+ ]);
37
+
38
+ /** How often, and how many times, a Session that sent its task_end is checked for idle. */
39
+ const IDLE_CHECK_MS = 50;
40
+ const IDLE_CHECKS = 40;
41
+
42
+ const sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));
43
+
16
44
  export default {
17
45
  modules: {
18
46
  Workbench: {
@@ -29,16 +57,96 @@ export default {
29
57
  return state && Array.isArray(state.tickets) ? structuredClone(state) : { tickets: [] };
30
58
  };
31
59
  const save = (state: State) => host.setState(state);
60
+
61
+ // The Sessions of running tickets, followed live so an answer is saved the moment its
62
+ // task ends, whether or not the page is open. GET /tickets still reconciles: nothing is
63
+ // followed across a server restart until the workbench loads again.
64
+ const subscribe = (host as unknown as { subscribe?: unknown }).subscribe;
65
+ const live = typeof subscribe === "function" ? (subscribe as Subscribe).bind(host) : null;
66
+ const following = new Map<string, () => void>();
67
+ /** Sessions whose current task a person stopped, until that task is reconciled. */
68
+ const stopped = new Set<string>();
69
+ const unfollow = (sessionId: string) => {
70
+ following.get(sessionId)?.();
71
+ following.delete(sessionId);
72
+ };
73
+ const idle = (sessionId: string) => {
74
+ try {
75
+ return host.sessionStatus(sessionId) === "idle";
76
+ } catch {
77
+ return true; // The Session is gone: reconciling marks the ticket failed.
78
+ }
79
+ };
80
+ /** Moves a running ticket to its answer or failure; false while its Session still runs. */
81
+ const reconcile = async (ticket: Ticket): Promise<boolean> => {
82
+ try {
83
+ const result = await host.sessionResult(ticket.sessionId);
84
+ if (result.status === "running") return false;
85
+ ticket.status = result.status === "completed" ? "answered" : "failed";
86
+ ticket.error = result.error;
87
+ if (result.status === "failed" && stopped.has(ticket.sessionId)) ticket.stopped = true;
88
+ ticket.updatedAt = new Date().toISOString();
89
+ if (result.status === "completed")
90
+ ticket.messages.push({ role: "assistant", text: result.text, at: ticket.updatedAt });
91
+ } catch (e) {
92
+ ticket.status = "failed";
93
+ ticket.error = e instanceof Error ? e.message : String(e);
94
+ }
95
+ stopped.delete(ticket.sessionId);
96
+ unfollow(ticket.sessionId);
97
+ return true;
98
+ };
99
+ // A task_end arrives before its Session reads idle, and sessionResult answers `running`
100
+ // until it does: wait for idle first. A Session still busy after that (a queued
101
+ // follow-up started) stays followed for its next task_end.
102
+ const settle = async (sessionId: string) => {
103
+ for (let i = 0; i < IDLE_CHECKS && !idle(sessionId); i++) await sleep(IDLE_CHECK_MS);
104
+ await locked(async () => {
105
+ const state = read();
106
+ const ticket = state.tickets.find(
107
+ (t) => t.sessionId === sessionId && t.status === "running",
108
+ );
109
+ if (!ticket) unfollow(sessionId);
110
+ else if (await reconcile(ticket)) await save(state);
111
+ });
112
+ };
113
+ const follow = (sessionId: string) => {
114
+ if (!live || following.has(sessionId)) return;
115
+ try {
116
+ const stop = live(sessionId, (record) => {
117
+ // Only the main Session's own records decide; a subagent's carry `origin`.
118
+ if (record.origin?.length) return;
119
+ const { type, error_code } = record.payload;
120
+ if (type === "abort" && STOP_CODES.has(error_code)) stopped.add(sessionId);
121
+ if (type !== "task_end") return;
122
+ settle(sessionId).catch((e) =>
123
+ host.log(`Could not save the answer of ${sessionId}: ${String(e)}`),
124
+ );
125
+ });
126
+ following.set(sessionId, stop);
127
+ } catch {
128
+ // A Session outside this Project: GET /tickets records the failure on the ticket.
129
+ }
130
+ };
131
+ // Reloads and restarts end every subscription; take up the questions still running.
132
+ for (const ticket of read().tickets)
133
+ if (ticket.status === "running") follow(ticket.sessionId);
134
+
32
135
  const start = async (ticket: Ticket, text: string, state: State) => {
33
136
  ticket.status = "running";
34
137
  ticket.error = null;
138
+ delete ticket.stopped;
139
+ stopped.delete(ticket.sessionId);
35
140
  ticket.updatedAt = new Date().toISOString();
36
141
  await save(state);
142
+ // Before run: a subscription replays nothing, and a short task could end first.
143
+ follow(ticket.sessionId);
37
144
  try {
38
145
  await host.run(ticket.sessionId, [{ text }]);
39
146
  ticket.title = host.sessionTitle(ticket.sessionId) ?? ticket.title;
40
147
  await save(state);
41
148
  } catch (e) {
149
+ unfollow(ticket.sessionId);
42
150
  ticket.status = "failed";
43
151
  ticket.error = e instanceof Error ? e.message : String(e);
44
152
  await save(state);
@@ -63,25 +171,10 @@ export default {
63
171
  }
64
172
  } catch {}
65
173
  }
66
- for (const ticket of state.tickets.filter((t) => t.status === "running")) {
67
- try {
68
- const result = await host.sessionResult(ticket.sessionId);
69
- if (result.status === "running") continue;
70
- ticket.status = result.status === "completed" ? "answered" : "failed";
71
- ticket.error = result.error;
72
- ticket.updatedAt = new Date().toISOString();
73
- if (result.status === "completed")
74
- ticket.messages.push({
75
- role: "assistant",
76
- text: result.text,
77
- at: ticket.updatedAt,
78
- });
79
- } catch (e) {
80
- ticket.status = "failed";
81
- ticket.error = e instanceof Error ? e.message : String(e);
82
- }
83
- changed = true;
84
- }
174
+ // The fallback for a task_end nobody heard: one that ended while the
175
+ // server restarted or the workbench reloaded.
176
+ for (const ticket of state.tickets.filter((t) => t.status === "running"))
177
+ if (await reconcile(ticket)) changed = true;
85
178
  if (changed) await save(state);
86
179
  return { body: state };
87
180
  }
@@ -3,7 +3,7 @@
3
3
  "version": "1.0.0",
4
4
  "type": "module",
5
5
  "penguin": {
6
- "version": "2026.10.14.3",
6
+ "version": "2026.10.26.1",
7
7
  "modules": [
8
8
  {
9
9
  "name": "Workbench",
@@ -1,8 +1,27 @@
1
1
  import dictionaries from "./strings.js";
2
+ import { draftOf, emptyLive, foldLive } from "./live.js";
2
3
 
3
4
  const $ = (id) => document.getElementById(id);
4
5
  const dialog = $("dialog");
5
6
  const drafts = new Map();
7
+ // The page SDK the server serves beside this workbench; an older server has none, and then the
8
+ // page polls. Imported only when a question is followed, by a name in a variable so that no
9
+ // tool tries to resolve the file ahead of time.
10
+ const SDK = "../sdk/workbench.js";
11
+ // The open question is followed live and refreshes the page the moment its task ends, so the
12
+ // list can be polled slowly; without the page SDK it is polled at the old pace.
13
+ const POLL_MS = 5000;
14
+ const FALLBACK_POLL_MS = 2500;
15
+ // The answer is saved a moment after the task ends: look again a few times before giving up.
16
+ const SETTLE_RETRY_MS = [0, 400, 1200, 2500];
17
+ // A status's colour: running shares success with answered, its word tells them apart.
18
+ const TONES = {
19
+ open: "attention",
20
+ running: "success",
21
+ answered: "success",
22
+ resolved: "done",
23
+ failed: "danger",
24
+ };
6
25
  let preferred;
7
26
  try {
8
27
  preferred = localStorage.getItem("penguin.support.lang") || localStorage.getItem("penguin.lang");
@@ -21,6 +40,13 @@ let loaded = false;
21
40
  let requestVersion = 0;
22
41
  let listSignature = "";
23
42
  let detailSignature = "";
43
+ let sdk; // undefined until tried, null when it cannot be loaded
44
+ let sdkLoad = null;
45
+ let live = null; // the open question's reader: { id, sessionId, reader, view, settling }
46
+ let stopping = null; // null, "ask" or "stopping"
47
+ let liveQueued = false;
48
+ let shownDraft = "";
49
+ let pollTimer;
24
50
 
25
51
  async function api(route, body) {
26
52
  const response = await fetch(
@@ -48,6 +74,14 @@ function report(id, error) {
48
74
  $(id).hidden = false;
49
75
  }
50
76
 
77
+ // A question someone stopped says so in plain words rather than in the server's error.
78
+ const errorText = (ticket) => (ticket.stopped ? copy.stopped : ticket.error);
79
+
80
+ function badge(element, status) {
81
+ element.textContent = copy[status] || status;
82
+ element.dataset.tone = TONES[status] || "neutral";
83
+ }
84
+
51
85
  function translate() {
52
86
  copy = dictionaries[language];
53
87
  document.documentElement.lang = language;
@@ -93,23 +127,31 @@ function renderList() {
93
127
  const button = document.createElement("button");
94
128
  const summary = document.createElement("span");
95
129
  const title = document.createElement("strong");
96
- const status = document.createElement("small");
130
+ const meta = document.createElement("span");
131
+ const status = document.createElement("span");
97
132
  const time = document.createElement("time");
98
133
  title.textContent = ticket.title || copy.newTicket;
99
- status.textContent = copy[ticket.status] || ticket.status;
100
- if (ticket.status === "running") status.dataset.waiting = ticket.id;
134
+ meta.className = "meta";
135
+ status.className = "wb-badge";
136
+ badge(status, ticket.status);
137
+ meta.append(status);
138
+ if (ticket.status === "running") {
139
+ const estimate = document.createElement("small");
140
+ estimate.dataset.waiting = ticket.id;
141
+ meta.append(estimate);
142
+ }
101
143
  time.dateTime = ticket.updatedAt;
102
144
  time.textContent = new Date(ticket.updatedAt).toLocaleDateString(language);
103
145
  button.dataset.ticket = ticket.id;
104
146
  button.onclick = () => showTicket(ticket.id);
105
- summary.append(title, status);
147
+ summary.append(title, meta);
106
148
  button.append(summary, time);
107
149
  row.append(button);
108
150
  return row;
109
151
  });
110
152
  if (!rows.length) {
111
153
  const empty = document.createElement("li");
112
- empty.className = "empty muted";
154
+ empty.className = "empty wb-muted";
113
155
  empty.textContent = !loaded
114
156
  ? copy.loading
115
157
  : query || filter !== "all"
@@ -201,7 +243,7 @@ function renderTicket() {
201
243
  if (signature !== detailSignature) {
202
244
  detailSignature = signature;
203
245
  $("dialog-title").textContent = ticket.title || copy.newTicket;
204
- $("status").textContent = ticket.status === "running" ? copy.working : copy[ticket.status];
246
+ badge($("status"), ticket.status);
205
247
  const messages = ticket.messages.map((message) => {
206
248
  const article = document.createElement("article");
207
249
  const heading = document.createElement("h3");
@@ -214,8 +256,9 @@ function renderTicket() {
214
256
  return article;
215
257
  });
216
258
  $("messages").replaceChildren(...messages);
217
- $("dialog-error").hidden = !ticket.error;
218
- if (ticket.error) report("dialog-error", new Error(ticket.error));
259
+ const error = errorText(ticket);
260
+ $("dialog-error").hidden = !error;
261
+ if (error) report("dialog-error", new Error(error));
219
262
  }
220
263
  const disabled = busy || ticket.status === "running";
221
264
  $("resolve").textContent = ticket.status === "resolved" ? copy.reopen : copy.resolve;
@@ -247,7 +290,7 @@ function updateWaiting() {
247
290
  .forEach((element) => {
248
291
  const ticket = tickets.find((item) => item.id === element.dataset.waiting);
249
292
  if (!ticket) return;
250
- const text = `${copy.running} · ${waitingText(ticket).estimate}`;
293
+ const text = waitingText(ticket).estimate;
251
294
  if (element.textContent !== text) element.textContent = text;
252
295
  });
253
296
  const ticket = tickets.find((item) => item.id === selected);
@@ -258,11 +301,122 @@ function updateWaiting() {
258
301
  }
259
302
  }
260
303
 
304
+ // Following the open question live: one reader, only while its dialog is open on a question
305
+ // being researched and the page is shown. Everything else, and every server without the page
306
+ // SDK, is polling.
307
+ function loadSdk() {
308
+ sdkLoad ??= import(SDK).then(
309
+ (module) => (sdk = module),
310
+ () => {
311
+ sdk = null;
312
+ schedulePoll();
313
+ },
314
+ );
315
+ return sdkLoad;
316
+ }
317
+
318
+ function syncLive() {
319
+ const ticket = tickets.find((item) => item.id === selected);
320
+ const wanted =
321
+ dialog.open && !document.hidden && ticket?.status === "running" && sdk !== null ? ticket : null;
322
+ if (live && live.id === wanted?.id && live.sessionId === wanted.sessionId) return;
323
+ if (live) {
324
+ live.reader?.close();
325
+ live = null;
326
+ stopping = null;
327
+ }
328
+ if (!wanted) return;
329
+ const current = {
330
+ id: wanted.id,
331
+ sessionId: wanted.sessionId,
332
+ reader: null,
333
+ view: emptyLive(),
334
+ settling: false,
335
+ };
336
+ live = current;
337
+ loadSdk().then(() => {
338
+ if (live !== current) return;
339
+ if (sdk) {
340
+ try {
341
+ // The latest task is enough: it holds the Request being written.
342
+ current.reader = sdk.followSession(current.sessionId, { tailLimit: 1 });
343
+ current.reader.on("event", ({ record }) => onRecord(current, record));
344
+ current.reader.on("reset", () => {
345
+ current.view = emptyLive();
346
+ queueLive();
347
+ });
348
+ // Refused for good (the conversation is gone): polling carries on.
349
+ current.reader.on("error", () => (current.reader = null));
350
+ } catch {
351
+ current.reader = null;
352
+ }
353
+ }
354
+ renderLive();
355
+ });
356
+ }
357
+
358
+ function onRecord(current, record) {
359
+ if (live !== current) return;
360
+ current.view = foldLive(current.view, record);
361
+ if (!record.origin?.length && record.payload?.type === "task_end") settle(current);
362
+ queueLive();
363
+ }
364
+
365
+ // The task ended: show the answer now instead of at the next poll.
366
+ async function settle(current) {
367
+ if (current.settling) return;
368
+ current.settling = true;
369
+ try {
370
+ for (const wait of SETTLE_RETRY_MS) {
371
+ if (wait) await new Promise((resolve) => setTimeout(resolve, wait));
372
+ if (live !== current || current.view.running) return;
373
+ await refresh();
374
+ if (tickets.find((item) => item.id === current.id)?.status !== "running") return;
375
+ }
376
+ } finally {
377
+ current.settling = false;
378
+ }
379
+ }
380
+
381
+ function queueLive() {
382
+ if (liveQueued) return;
383
+ liveQueued = true;
384
+ queueMicrotask(() => {
385
+ liveQueued = false;
386
+ renderLive();
387
+ });
388
+ }
389
+
390
+ function setText(element, text) {
391
+ if (element.textContent !== text) element.textContent = text;
392
+ }
393
+
394
+ function renderLive() {
395
+ const ticket = tickets.find((item) => item.id === selected);
396
+ const running = ticket?.status === "running";
397
+ $("live").hidden = !running;
398
+ $("stop").hidden = !running || !sdk || stopping !== null;
399
+ $("stop-confirm").hidden = !running || stopping === null;
400
+ $("stop-yes").disabled = $("stop-no").disabled = stopping === "stopping";
401
+ setText($("stop-ask"), stopping === "stopping" ? copy.stopping : copy.stopAsk);
402
+ setText($("live-heading"), `${copy.title} · ${copy.draft}`);
403
+ const view = running && live?.reader ? live.view : emptyLive();
404
+ const activity = view.running === false ? null : copy.activity[view.activity];
405
+ setText($("activity"), activity || copy.working);
406
+ const draft = draftOf(view);
407
+ if (draft !== shownDraft) {
408
+ shownDraft = draft;
409
+ $("draft").replaceChildren(...(draft ? [answerNode(draft)] : []));
410
+ }
411
+ }
412
+
261
413
  function render() {
262
414
  renderList();
263
415
  $("new").disabled = busy;
264
416
  $("submit").disabled = busy;
265
417
  renderTicket();
418
+ syncLive();
419
+ renderLive();
266
420
  updateWaiting();
267
421
  }
268
422
 
@@ -279,6 +433,8 @@ function showTicket(id) {
279
433
  $("followup").elements.text.value = drafts.get(id) || "";
280
434
  openDialog();
281
435
  renderTicket();
436
+ syncLive();
437
+ renderLive();
282
438
  updateWaiting();
283
439
  $("dialog-title").focus();
284
440
  }
@@ -297,6 +453,16 @@ async function refresh() {
297
453
  }
298
454
  }
299
455
 
456
+ function schedulePoll() {
457
+ clearTimeout(pollTimer);
458
+ pollTimer = setTimeout(poll, sdk === null ? FALLBACK_POLL_MS : POLL_MS);
459
+ }
460
+
461
+ async function poll() {
462
+ if (!document.hidden && !busy) await refresh();
463
+ schedulePoll();
464
+ }
465
+
300
466
  async function mutate(action) {
301
467
  if (busy) return null;
302
468
  busy = true;
@@ -351,11 +517,13 @@ dialog.addEventListener("keydown", (event) => {
351
517
  dialog.close();
352
518
  });
353
519
  dialog.addEventListener("close", () => {
520
+ syncLive();
354
521
  const row = [...$("list").querySelectorAll("button")].find(
355
522
  (button) => button.dataset.ticket === selected,
356
523
  );
357
524
  (row || $("new")).focus();
358
525
  });
526
+ document.addEventListener("visibilitychange", render);
359
527
  $("create").onsubmit = async (event) => {
360
528
  event.preventDefault();
361
529
  const form = event.currentTarget;
@@ -386,7 +554,34 @@ $("resolve").onclick = () => {
386
554
  );
387
555
  };
388
556
  $("retry").onclick = () => mutate(() => api("/tickets/" + selected, { action: "retry" }));
389
- $("search").oninput = $("filter").onchange = renderList;
557
+ $("stop").onclick = () => {
558
+ stopping = "ask";
559
+ renderLive();
560
+ $("stop-no").focus();
561
+ };
562
+ $("stop-no").onclick = () => {
563
+ stopping = null;
564
+ renderLive();
565
+ $("stop").focus();
566
+ };
567
+ $("stop-yes").onclick = async () => {
568
+ const ticket = tickets.find((item) => item.id === selected);
569
+ if (!sdk || ticket?.status !== "running") return;
570
+ stopping = "stopping";
571
+ renderLive();
572
+ try {
573
+ // Still "Stopping…" until the question shows as stopped; nothing to wait for when idle.
574
+ if (!(await sdk.abortSession(ticket.sessionId))) stopping = null;
575
+ } catch {
576
+ stopping = null;
577
+ report("dialog-error", new Error(copy.error));
578
+ }
579
+ await refresh();
580
+ };
581
+ $("search").oninput = $("filter").onchange = () => {
582
+ renderList();
583
+ updateWaiting();
584
+ };
390
585
  $("locale").onchange = () => {
391
586
  language = $("locale").value;
392
587
  try {
@@ -396,16 +591,7 @@ $("locale").onchange = () => {
396
591
  };
397
592
  translate();
398
593
  refresh();
594
+ schedulePoll();
399
595
  setInterval(() => {
400
596
  if (!document.hidden) updateWaiting();
401
597
  }, 1000);
402
- let refreshing = false;
403
- setInterval(async () => {
404
- if (document.hidden || refreshing || busy) return;
405
- refreshing = true;
406
- try {
407
- await refresh();
408
- } finally {
409
- refreshing = false;
410
- }
411
- }, 2500);
@@ -53,9 +53,30 @@
53
53
  </div>
54
54
  </form>
55
55
  <section id="ticket" hidden>
56
- <p id="status" role="status" class="muted"></p>
57
- <p id="waiting" class="muted" hidden></p>
56
+ <div class="ticket-state">
57
+ <span id="status" class="wb-badge" role="status"></span>
58
+ <span id="waiting" class="wb-muted" hidden></span>
59
+ <button id="stop" type="button" data-copy="stop" hidden></button>
60
+ </div>
61
+ <div
62
+ id="stop-confirm"
63
+ class="stop-confirm"
64
+ role="group"
65
+ aria-labelledby="stop-ask"
66
+ hidden
67
+ >
68
+ <span id="stop-ask"></span>
69
+ <div class="actions">
70
+ <button id="stop-no" type="button" data-copy="stopNo"></button>
71
+ <button id="stop-yes" type="button" class="danger" data-copy="stopYes"></button>
72
+ </div>
73
+ </div>
58
74
  <div id="messages"></div>
75
+ <article id="live" class="answer" hidden>
76
+ <h3 id="live-heading"></h3>
77
+ <p id="activity" class="wb-muted" role="status"></p>
78
+ <div id="draft"></div>
79
+ </article>
59
80
  <div class="actions">
60
81
  <button id="resolve" type="button"></button>
61
82
  <button id="retry" type="button" data-copy="retry" hidden></button>
@@ -0,0 +1,66 @@
1
+ // What the open question's dialog shows while its answer is written: folded from the Session's
2
+ // records as the page SDK's reader delivers them (the latest task's history, then live).
3
+
4
+ /** The view before any record: nothing known yet. */
5
+ export function emptyLive() {
6
+ // running: null until a task_begin or task_end says. text: the current Request's finished
7
+ // texts; streaming: the one still arriving. activity: a key of the strings' `activity`.
8
+ return { running: null, compacting: false, text: "", streaming: "", activity: null };
9
+ }
10
+
11
+ // Plain words for what a tool call is doing (keys of `activity` in strings.js).
12
+ const TOOL_ACTIVITY = {
13
+ read_file: "reading",
14
+ exec_command: "searching",
15
+ input_command: "searching",
16
+ run_subagent: "helper",
17
+ input_subagent: "helper",
18
+ write_file: "notes",
19
+ edit_file: "notes",
20
+ };
21
+
22
+ export const toolActivity = (name) =>
23
+ Object.hasOwn(TOOL_ACTIVITY, name) ? TOOL_ACTIVITY[name] : "other";
24
+
25
+ /** The view after one more record. A subagent's record (it carries `origin`) changes nothing. */
26
+ export function foldLive(view, record) {
27
+ if (record.origin?.length) return view;
28
+ const p = record.payload || {};
29
+ switch (p.type) {
30
+ case "task_begin":
31
+ return { ...emptyLive(), running: true };
32
+ case "task_end":
33
+ return { ...view, running: false, streaming: "" };
34
+ case "request_begin":
35
+ // Each Request drafts afresh: what one wrote before its tool calls is not the answer.
36
+ return { ...view, text: "", streaming: "" };
37
+ case "compaction_begin":
38
+ return { ...view, compacting: true, activity: "summarizing" };
39
+ case "compaction_end":
40
+ return { ...view, compacting: false };
41
+ case "partial_thinking":
42
+ return { ...view, activity: "thinking" };
43
+ case "partial_tool_call":
44
+ case "tool_call":
45
+ return { ...view, activity: toolActivity(p.name) };
46
+ case "partial_text":
47
+ // The summary a compaction writes streams as text too, and is no answer.
48
+ if (view.compacting || p.role !== "assistant") return view;
49
+ if (p.event_type === "start")
50
+ return { ...view, activity: "writing", streaming: p.text || "" };
51
+ if (p.event_type === "delta") return { ...view, streaming: view.streaming + (p.text || "") };
52
+ return view;
53
+ case "text":
54
+ if (view.compacting || p.role !== "assistant") return view;
55
+ return { ...view, text: joinText(view.text, p.text), streaming: "" };
56
+ default:
57
+ return view;
58
+ }
59
+ }
60
+
61
+ /** The draft to show: the current Request's text so far, or "" when none is being written. */
62
+ export function draftOf(view) {
63
+ return view.running === false ? "" : joinText(view.text, view.streaming);
64
+ }
65
+
66
+ const joinText = (a, b) => (a && b ? a + "\n\n" + b : a || b);
@@ -17,6 +17,13 @@ export default {
17
17
  resolve: "Mark resolved",
18
18
  reopen: "Reopen",
19
19
  retry: "Retry",
20
+ stop: "Stop",
21
+ stopAsk: "Stop researching this question? You can retry it later.",
22
+ stopYes: "Yes, stop",
23
+ stopNo: "Keep going",
24
+ stopping: "Stopping…",
25
+ stopped: "This question was stopped before the answer was ready. Click Retry to ask again.",
26
+ draft: "Answer in progress",
20
27
  empty: "No questions yet.",
21
28
  noMatches: "No matching questions.",
22
29
  questions: "Questions",
@@ -24,6 +31,16 @@ export default {
24
31
  close: "Close",
25
32
  cancel: "Cancel",
26
33
  working: "Checking the documentation and source code…",
34
+ activity: {
35
+ thinking: "Thinking it over…",
36
+ writing: "Writing the answer…",
37
+ reading: "Reading the documentation and code…",
38
+ searching: "Searching the documentation and code…",
39
+ helper: "Asking a helper to look into part of it…",
40
+ notes: "Taking notes…",
41
+ summarizing: "Summarizing what it has found so far…",
42
+ other: "Looking something up…",
43
+ },
27
44
  estimate: (minutes) => `Reply expected in about ${minutes} min`,
28
45
  elapsed: (time) => `Waiting ${time}`,
29
46
  takingLonger: "Taking longer than estimated; still checking…",
@@ -50,6 +67,13 @@ export default {
50
67
  resolve: "标记已解决",
51
68
  reopen: "重新打开",
52
69
  retry: "重试",
70
+ stop: "停止",
71
+ stopAsk: "停止查阅这个问题?之后可以重试。",
72
+ stopYes: "确定停止",
73
+ stopNo: "继续查阅",
74
+ stopping: "正在停止…",
75
+ stopped: "这个问题在回答完成前已停止。点击「重试」可以重新提问。",
76
+ draft: "回答撰写中",
53
77
  empty: "还没有问题。",
54
78
  noMatches: "没有匹配的问题。",
55
79
  questions: "问题列表",
@@ -57,6 +81,16 @@ export default {
57
81
  close: "关闭",
58
82
  cancel: "取消",
59
83
  working: "正在查阅文档和源代码…",
84
+ activity: {
85
+ thinking: "正在思考…",
86
+ writing: "正在撰写回答…",
87
+ reading: "正在阅读文档和代码…",
88
+ searching: "正在搜索文档和代码…",
89
+ helper: "正在请助手查阅其中一部分…",
90
+ notes: "正在记笔记…",
91
+ summarizing: "正在整理已查到的内容…",
92
+ other: "正在查找资料…",
93
+ },
60
94
  estimate: (minutes) => `预计约 ${minutes} 分钟后回复`,
61
95
  elapsed: (time) => `已等待 ${time}`,
62
96
  takingLonger: "查阅时间超过预估,仍在处理中…",
@@ -12,6 +12,7 @@ body {
12
12
  .dialog-header,
13
13
  .filters,
14
14
  .actions,
15
+ .ticket-state,
15
16
  footer {
16
17
  display: flex;
17
18
  align-items: center;
@@ -37,7 +38,6 @@ button {
37
38
  button:disabled {
38
39
  cursor: default;
39
40
  }
40
- .muted,
41
41
  small,
42
42
  time,
43
43
  footer {
@@ -83,9 +83,12 @@ a {
83
83
  font-weight: 500;
84
84
  overflow-wrap: anywhere;
85
85
  }
86
- #list small {
87
- display: block;
88
- margin-top: 4px;
86
+ #list .meta {
87
+ display: flex;
88
+ flex-wrap: wrap;
89
+ align-items: center;
90
+ gap: 8px;
91
+ margin-top: 6px;
89
92
  }
90
93
  #list time {
91
94
  flex: none;
@@ -115,13 +118,14 @@ dialog {
115
118
  background: var(--wb-bg);
116
119
  border: 1px solid var(--wb-border);
117
120
  border-radius: var(--wb-radius);
121
+ box-shadow: var(--ui-shadow-modal, none);
118
122
  }
119
123
  dialog[open] {
120
124
  display: flex;
121
125
  flex-direction: column;
122
126
  }
123
127
  dialog::backdrop {
124
- background: rgb(0 0 0 / 35%);
128
+ background: var(--ui-overlay-backdrop, rgb(0 0 0 / 35%));
125
129
  }
126
130
  .dialog-header {
127
131
  padding: 20px 24px;
@@ -160,9 +164,29 @@ textarea {
160
164
  justify-content: flex-end;
161
165
  flex-wrap: wrap;
162
166
  }
163
- #status {
167
+ .ticket-state {
168
+ flex-wrap: wrap;
164
169
  margin: 0 0 20px;
165
170
  }
171
+ #stop {
172
+ margin-left: auto;
173
+ }
174
+ .stop-confirm {
175
+ display: flex;
176
+ flex-wrap: wrap;
177
+ align-items: center;
178
+ justify-content: space-between;
179
+ gap: 12px;
180
+ margin: -8px 0 20px;
181
+ padding: 10px 12px;
182
+ background: var(--wb-tone-danger-bg);
183
+ border: 1px solid var(--wb-tone-danger-line);
184
+ border-radius: var(--wb-radius);
185
+ }
186
+ button.danger {
187
+ color: var(--wb-tone-danger-fg);
188
+ border-color: var(--wb-tone-danger-line);
189
+ }
166
190
  .answer {
167
191
  border-top: 1px solid var(--wb-border);
168
192
  padding: 18px 0;
@@ -181,6 +205,30 @@ textarea {
181
205
  .answer pre {
182
206
  overflow-x: auto;
183
207
  }
208
+ #activity {
209
+ display: flex;
210
+ align-items: center;
211
+ gap: 8px;
212
+ margin: 0 0 8px;
213
+ }
214
+ /* A live answer: the dot beats while the agent works. */
215
+ #activity::before {
216
+ content: "";
217
+ flex: none;
218
+ width: 6px;
219
+ height: 6px;
220
+ border-radius: 50%;
221
+ background: var(--wb-tone-success-fg);
222
+ animation: beat 1.6s ease-in-out infinite;
223
+ }
224
+ @keyframes beat {
225
+ 50% {
226
+ opacity: 0.3;
227
+ }
228
+ }
229
+ #draft {
230
+ color: var(--wb-muted);
231
+ }
184
232
  #followup {
185
233
  margin-top: 24px;
186
234
  }