pi-pocket 0.28.0 → 0.28.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.
@@ -59,6 +59,44 @@ export const SessionsDoc = defineDoc<{ items: Record<string, SessionMeta> }>({
59
59
  initial: () => ({ items: {} }),
60
60
  });
61
61
 
62
+ /** Interrupt handoffs not yet admitted as messages: retries find the same durable task, even after a restart. */
63
+ export const InterruptsDoc = defineDoc<{ pending: Record<string, number> }>({
64
+ kind: "pocket.interrupts",
65
+ version: 1,
66
+ ...rebased,
67
+ scope: "conversation",
68
+ history: "latest",
69
+ fork: "initial",
70
+ initial: () => ({ pending: {} }),
71
+ });
72
+
73
+ /** A message that Stop took out of the queue: it waits, and goes to Pi only when someone sends it. */
74
+ export type HeldMessage = {
75
+ /** The id of the queued message it was. */
76
+ key: string;
77
+ /** Pi Durable's `UserInput`, as it was queued. */
78
+ content: JsonValue;
79
+ mode: "steer" | "followUp";
80
+ /** The request id it goes out with: its sender's, so it stays theirs, and a retry never sends it twice. */
81
+ requestId: string;
82
+ /** Pi Durable's `InputEntry`, when it had one. */
83
+ entry?: JsonValue;
84
+ /** Who wrote it, when a person did. */
85
+ by?: string;
86
+ heldAt: number;
87
+ };
88
+
89
+ /** The messages a Stop kept from the queue, in their order (`Commands.abort`, `Commands.sendHeld`). */
90
+ export const HeldDoc = defineDoc<{ items: HeldMessage[] }>({
91
+ kind: "pocket.held",
92
+ version: 1,
93
+ ...rebased,
94
+ scope: "conversation",
95
+ history: "latest",
96
+ fork: "initial",
97
+ initial: () => ({ items: [] }),
98
+ });
99
+
62
100
  /** Favorite working folders in shortcut order, private to each person and shared by their devices. */
63
101
  export const FolderFavoritesDoc = defineDoc<{ users: Record<string, string[]> }>({
64
102
  kind: "pocket.folder-favorites",
@@ -498,6 +536,10 @@ export type Schedule = {
498
536
  createdAt: number;
499
537
  /** How many times it went out: each time sends with its own request id, so a restart never sends one twice. */
500
538
  runs: number;
539
+ /** How many of a repeat's times sent nothing because its last message still waited in the queue (`schedules.ts`). */
540
+ skipped?: number;
541
+ /** When the newest of those was. */
542
+ skippedAt?: number;
501
543
  /** The durable task that sends it. */
502
544
  taskId: TaskId;
503
545
  /** Set by the same call already, when a tool call is replayed: its `taskId:callId`. */
@@ -110,7 +110,7 @@ export default function createSchedules(host: PocketHost, web: ExtensionWeb) {
110
110
  execute: async (args, api) => {
111
111
  const reply = (text: string) => ({ output: [{ type: "text" as const, text }] });
112
112
  const line = (item: Schedule) =>
113
- `${item.id}: ${item.every === undefined ? describeMoment(item.next, item.zone) : `${describeRepeat(item.every)}, next ${describeMoment(item.next, item.zone)}`} · ${item.text}`;
113
+ `${item.id}: ${item.every === undefined ? describeMoment(item.next, item.zone) : `${describeRepeat(item.every)}, next ${describeMoment(item.next, item.zone)}`}${(item.skipped ?? 0) > 0 ? `, skipped ${String(item.skipped)}× (last ${describeMoment(item.skippedAt ?? item.next, item.zone)}): its last message still waits in the queue` : ""} · ${item.text}`;
114
114
 
115
115
  if (args.action === "list") {
116
116
  const items = await host.schedules.list(api.conversationId);
@@ -196,6 +196,28 @@ export async function conversationRoutes(
196
196
  );
197
197
  }
198
198
 
199
+ // What a Stop held: `send` them all, or `drop` or `edit` one, by its `key`.
200
+ if (third === "held" && method === "POST") {
201
+ const body = await readJson<{ action?: unknown; key?: unknown }>(request);
202
+ const key = String(body.key ?? "");
203
+
204
+ if (body.action === "send") {
205
+ return json(response, 200, { sent: await app.commands.sendHeld(id, user) });
206
+ }
207
+
208
+ if (body.action === "drop") {
209
+ await app.commands.dropHeld(id, user, key);
210
+
211
+ return json(response, 200, { ok: true });
212
+ }
213
+
214
+ if (body.action === "edit") {
215
+ return json(response, 200, await app.commands.editHeld(id, user, key));
216
+ }
217
+
218
+ throw new HttpError(400, "Say send, drop, or edit.");
219
+ }
220
+
199
221
  if (third === "move" && method === "POST") {
200
222
  const body = await readJson<{ submissionId?: number; mode?: string }>(request);
201
223
 
package/src/server/pip.ts CHANGED
@@ -1581,6 +1581,14 @@ export class Pip {
1581
1581
  /** A session's last words, for PiP: how its run ended, and Pi's last answer, fenced. */
1582
1582
  async #lastWords(id: ConversationId, title: string, state: string): Promise<string> {
1583
1583
  const name = `${quoted(title, 80)} (/s/${String(id)})`;
1584
+ // A run that failed with no answer of its own (its compaction failed) left the answer before it as the last:
1585
+ // the failure is what came of the run, not that answer.
1586
+ const failure = this.#app.runFailure(id);
1587
+
1588
+ if (failure !== undefined) {
1589
+ return `${name} stopped with an error: ${snippet(failure, 300)}`;
1590
+ }
1591
+
1584
1592
  const page = await (await this.#app.conversation(id)).entries({}, 16, undefined, context);
1585
1593
  const last = page.items
1586
1594
  .map((entry) => projectEntry(entry))
@@ -11,6 +11,7 @@ import {
11
11
  type InputEntry,
12
12
  type UserInput,
13
13
  } from "@earendil-works/pi-durable";
14
+ import { InterruptsDoc } from "./docs.ts";
14
15
  import { CONTEXT_BLOCK, FILE_BLOCK } from "./entry-format.ts";
15
16
  import { describe } from "./errors.ts";
16
17
  import { ownRequest } from "./requests.ts";
@@ -100,13 +101,14 @@ export type Requeue = {
100
101
  };
101
102
 
102
103
  /**
103
- * A queued message moved to Interrupt: what it says, the request id it goes out with, the run it stops, and the other
104
- * queued messages, in their order, which the stop would withdraw and which are queued again after it.
104
+ * An Interrupt: what it says, the request id it goes out with, the run it stops, and the other queued messages, in
105
+ * their order, which the stop would withdraw and which are queued again after it.
105
106
  */
106
107
  export type Interrupt = {
107
108
  content: UserInput;
108
109
  requestId: string;
109
- /** The run that was going when the message was moved: only that run is stopped, never one that came after. */
110
+ entry?: InputEntry;
111
+ /** The run going at admission: only that run is stopped, never one that came after. */
110
112
  run?: number;
111
113
  others?: Requeue[];
112
114
  };
@@ -115,8 +117,8 @@ export type Interrupt = {
115
117
  export type StopRun = (run: number, context: Context) => Promise<void>;
116
118
 
117
119
  /**
118
- * Stops the run, then sends a queued message that the commit making this task took out of the queue, so a restart
119
- * in between cannot lose it, and puts the other messages that were queued back. Every message has a request id, so a
120
+ * Stops the run, then sends the message stored by the commit making this task, so a restart in between cannot lose
121
+ * it, and puts the other messages that were queued back. Every message has a request id, so a
120
122
  * restart at any point sends each once. Background, so the stop does not stop this task too. It stops the run it was
121
123
  * made for by its id (`stopRun`, from the app's harness), never whichever run is going: one that started after it ended
122
124
  * goes on.
@@ -128,7 +130,7 @@ export const interruptTask = (stopRun: StopRun) =>
128
130
  initial: () => ({ phase: "send" }),
129
131
  phases: {
130
132
  send: async (task, runtime, context) => {
131
- const { content, requestId, run, others } = task.input;
133
+ const { content, requestId, entry, run, others } = task.input;
132
134
  const id = runtime.conversationId;
133
135
  let sent = false;
134
136
 
@@ -148,7 +150,17 @@ export const interruptTask = (stopRun: StopRun) =>
148
150
  await stopRun(run, context);
149
151
  }
150
152
 
151
- await conversation?.submit({ type: "input", content, requestId }, context);
153
+ await runtime.commit(async (tx) => {
154
+ await conversation?.submit(tx, {
155
+ type: "input",
156
+ content,
157
+ requestId,
158
+ ...(entry === undefined ? {} : { entry }),
159
+ });
160
+ const interrupts = await tx.doc(InterruptsDoc, id);
161
+
162
+ delete interrupts.pending[requestId];
163
+ }, context);
152
164
  } catch (error) {
153
165
  if (context.abortSignal?.aborted === true) {
154
166
  throw error;
@@ -186,7 +198,12 @@ export const interruptTask = (stopRun: StopRun) =>
186
198
  }
187
199
  }
188
200
 
189
- await runtime.commit(() => finished, context);
201
+ // A message that was not sent leaves no receipt: a retry of its request makes a new handoff.
202
+ await runtime.commit(async (tx) => {
203
+ delete (await tx.doc(InterruptsDoc, id)).pending[requestId];
204
+
205
+ return finished;
206
+ }, context);
190
207
  },
191
208
  },
192
209
  abort: (_task, runtime, context) =>
@@ -28,6 +28,8 @@ import {
28
28
  DecisionsDoc,
29
29
  type Goal,
30
30
  GoalDoc,
31
+ HeldDoc,
32
+ type HeldMessage,
31
33
  LinkedSessionPeersDoc,
32
34
  type Notes,
33
35
  NotesDoc,
@@ -88,6 +90,7 @@ export const ROOM_DOCS = new Set(
88
90
  GoalDoc,
89
91
  WatchDoc,
90
92
  LinkedSessionPeersDoc,
93
+ HeldDoc,
91
94
  ].map((doc) => doc.definition.kind),
92
95
  );
93
96
  /** A typing indicator lasts this long unless the browser renews it. */
@@ -380,6 +383,8 @@ export class Room {
380
383
  decisions: Record<string, Decision> = {};
381
384
  plan: { on: boolean; by?: string; at?: number } = { on: false };
382
385
  schedules: Record<string, Schedule> = {};
386
+ /** The messages a Stop held out of the queue, in their order. */
387
+ held: HeldMessage[] = [];
383
388
  goal: Goal | undefined;
384
389
  watch: PrWatch | undefined;
385
390
  /** The sessions this one knows by an address (`linked-sessions.ts`): whom each linked session's message is from. */
@@ -460,6 +465,7 @@ export class Room {
460
465
  this.schedules = {
461
466
  ...((await harness.snapshot(ScheduleDoc, this.id, context))?.items ?? {}),
462
467
  };
468
+ this.held = [...((await harness.snapshot(HeldDoc, this.id, context))?.items ?? [])];
463
469
  this.goal = (await harness.snapshot(GoalDoc, this.id, context))?.goal;
464
470
  this.watch = (await harness.snapshot(WatchDoc, this.id, context))?.watch;
465
471
  this.peers = {
@@ -532,6 +538,8 @@ export class Room {
532
538
  this.plan = { on: false, ...((value as Room["plan"] | null) ?? {}) };
533
539
  } else if (kind === ScheduleDoc.definition.kind) {
534
540
  this.schedules = { ...((value?.items as Record<string, Schedule>) ?? {}) };
541
+ } else if (kind === HeldDoc.definition.kind) {
542
+ this.held = [...((value?.items as HeldMessage[] | undefined) ?? [])];
535
543
  } else if (kind === GoalDoc.definition.kind) {
536
544
  this.goal = (value?.goal as Goal | undefined) ?? undefined;
537
545
  } else if (kind === WatchDoc.definition.kind) {
@@ -846,14 +854,22 @@ export class Room {
846
854
  plan: this.plan,
847
855
  schedules: Object.values(this.schedules)
848
856
  .sort((a, b) => a.next - b.next)
849
- .map(({ id, text, next, every, by, runs }) => ({
857
+ .map(({ id, text, next, every, by, runs, skipped, skippedAt }) => ({
850
858
  id,
851
859
  text,
852
860
  next,
853
861
  ...(every === undefined ? {} : { repeat: describeRepeat(every) }),
854
862
  ...(by === undefined ? {} : { by }),
855
863
  runs,
864
+ ...(skipped === undefined ? {} : { skipped, skippedAt }),
856
865
  })),
866
+ // What a Stop held: each message's start and who wrote it, as the queue shows them.
867
+ held: this.held.map((item) => ({
868
+ key: item.key,
869
+ mode: item.mode,
870
+ ...(item.by === undefined ? {} : { by: item.by }),
871
+ text: cutQueued(queuedText(item.content)),
872
+ })),
857
873
  // The branch is read from the repository each time, so one Pi or a person switched to shows on the next update.
858
874
  branch: this.#readHead(),
859
875
  goal:
@@ -78,6 +78,8 @@ export type BoardSchedule = {
78
78
  requestedBy?: string;
79
79
  createdAt: number;
80
80
  runs: number;
81
+ /** How many times it sent nothing because its last message still waited in the queue (`schedules.ts`). */
82
+ skipped?: number;
81
83
  /** The next times it goes out, the first being `next`: up to `UPCOMING`, within `UPCOMING_MS`. */
82
84
  upcoming: number[];
83
85
  /** Why it would not go out now (a spend limit, or nobody left to steer), when it would not. */
@@ -525,6 +527,7 @@ export async function runningBoard(app: PocketApp, user: User): Promise<RunningB
525
527
  : { requestedBy: schedule.requestedBy }),
526
528
  createdAt: schedule.createdAt,
527
529
  runs: schedule.runs,
530
+ ...(schedule.skipped === undefined ? {} : { skipped: schedule.skipped }),
528
531
  upcoming: upcomingOf(schedule.id, schedule.next, schedule.every, schedule.zone),
529
532
  ...(held === undefined ? {} : { held }),
530
533
  });
@@ -3,7 +3,9 @@
3
3
  * its message, and for a repeat goes back to sleep until the next time. A restart while it sleeps continues the
4
4
  * sleep, and one that comes after the time sends at once. Each sending has its own request id, so a restart in the
5
5
  * middle of one never sends twice. A schedule goes out only while its person may still steer the session and no
6
- * spend limit is reached; otherwise it is cancelled, with a line in the chat saying why. One in PiP's conversation
6
+ * spend limit is reached; otherwise it is cancelled, with a line in the chat saying why. A repeat whose last message
7
+ * still waits in the session's queue sends no other: that time is skipped, counted on the schedule, and said in the
8
+ * chat, so messages do not pile up behind a session that cannot answer. One in PiP's conversation
7
9
  * waits while PiP is turned off, and goes out once it is back. The schedules extension
8
10
  * (`extensions/schedules.ts`) installs the task and gives Pi a tool to schedule its own follow-ups; while it is off,
9
11
  * nothing goes out.
@@ -19,7 +21,7 @@ import {
19
21
  } from "@earendil-works/pi-durable";
20
22
  import type { PocketApp } from "./app.ts";
21
23
  import { addActivity } from "./collab.ts";
22
- import { ChatDoc, type Schedule, ScheduleDoc } from "./docs.ts";
24
+ import { ChatDoc, type ChatMessage, type Schedule, ScheduleDoc } from "./docs.ts";
23
25
  import { describe, HttpError } from "./errors.ts";
24
26
  import { FROM_PREFIX } from "./entry-format.ts";
25
27
  import { snippet } from "./projection.ts";
@@ -69,6 +71,51 @@ async function stored(
69
71
 
70
72
  const finished = { status: "terminal", outcome: { status: "completed", result: null } } as const;
71
73
 
74
+ /** Who the chat names for a skipped time: no person did it. */
75
+ const SCHEDULER = { id: "pi", name: "Schedules" };
76
+
77
+ /**
78
+ * Say in the chat that a schedule skipped a time. Times are 10 minutes apart at least, so a session that cannot take
79
+ * its messages for hours would get a line for each: while nothing else is said, the last line counts them instead.
80
+ */
81
+ function sayWhatWasSkipped(chat: { messages: ChatMessage[] }, text: string, now: number): void {
82
+ const what = `skipped “${snippet(text, 60)}”`;
83
+ const why = "its last message still waits in the queue.";
84
+ const last = chat.messages.at(-1);
85
+ const times = /^skipped “.*” (\d+) times:/s.exec(last?.text ?? "");
86
+
87
+ if (
88
+ last?.kind === "event" &&
89
+ last.userId === SCHEDULER.id &&
90
+ last.name === SCHEDULER.name &&
91
+ last.text.startsWith(`${what}`) &&
92
+ last.text.endsWith(why)
93
+ ) {
94
+ const count = (times === null ? 1 : Number(times[1])) + 1;
95
+
96
+ last.text = `${what} ${count} times: ${why}`;
97
+ last.at = now;
98
+
99
+ return;
100
+ }
101
+
102
+ addActivity(chat, SCHEDULER, `${what}: ${why}`, now);
103
+ }
104
+
105
+ /**
106
+ * The request id of a schedule's sending number `run`. Sent as the person who set it up, so it shows as theirs. Pi's own
107
+ * are sent as Pi's, but as the work of whom Pi worked for when it set them up.
108
+ */
109
+ function sendingRequest(schedule: Schedule, run: number): string {
110
+ const sending = `${String(schedule.taskId)}-${run}`;
111
+
112
+ return schedule.by !== undefined
113
+ ? ownRequest(schedule.by, `schedule-${sending}`)
114
+ : schedule.requestedBy !== undefined
115
+ ? requestFor(schedule.requestedBy, `schedule-${sending}`)
116
+ : `schedule:${sending}`;
117
+ }
118
+
72
119
  export type ScheduleRequest = {
73
120
  /** When it goes out (`in 30m`, `every weekday 8:00`, …), followed by the message unless `text` is given. */
74
121
  when: string;
@@ -148,16 +195,19 @@ export class Schedules {
148
195
  }, context);
149
196
  }
150
197
 
151
- // Sent as the person who set it up, so it shows as theirs. Pi's own are sent as Pi's, but as the work of whom Pi
152
- // worked for when it set them up.
153
- const sending = `${String(schedule.taskId)}-${schedule.runs}`;
154
- const requestId =
155
- schedule.by !== undefined
156
- ? ownRequest(schedule.by, `schedule-${sending}`)
157
- : schedule.requestedBy !== undefined
158
- ? requestFor(schedule.requestedBy, `schedule-${sending}`)
159
- : `schedule:${sending}`;
198
+ const requestId = sendingRequest(schedule, schedule.runs);
160
199
  const stopped = this.#stopped(conversationId, schedule);
200
+ // Its last message, not yet in the transcript: the session has not taken it, so another would only wait too.
201
+ const waiting =
202
+ stopped === undefined &&
203
+ schedule.runs > 0 &&
204
+ (await this.#queued(runtime, sendingRequest(schedule, schedule.runs - 1), context)) &&
205
+ // Run again after a crash, this phase may find its own message sent already: that one counts as sent.
206
+ !(await this.#queued(runtime, requestId, context, true));
207
+
208
+ if (waiting) {
209
+ return this.#skip(id, runtime, context);
210
+ }
161
211
 
162
212
  if (stopped === undefined) {
163
213
  await conversation.submit(
@@ -204,6 +254,56 @@ export class Schedules {
204
254
  }, context);
205
255
  }
206
256
 
257
+ /**
258
+ * Whether the message sent with `requestId` waits in the conversation's queue, not yet taken into a run. `any`: whether
259
+ * it was sent at all, in any state.
260
+ */
261
+ async #queued(
262
+ runtime: Runtime,
263
+ requestId: string,
264
+ context: Context,
265
+ any = false,
266
+ ): Promise<boolean> {
267
+ const conversationId = runtime.conversationId;
268
+ const record = await this.#app.harness.commit(
269
+ (tx) => tx.submissionByRequest(conversationId, requestId),
270
+ context,
271
+ );
272
+
273
+ return record !== undefined && (any || record.status === "queued");
274
+ }
275
+
276
+ /**
277
+ * Skip this time of a repeat whose last message still waits in the queue: count it on the schedule, say so in the
278
+ * chat (one line, updated while the skips go on), and wait for the next time. `runs` stays, so the message that
279
+ * waits keeps its request id and the next check finds it.
280
+ */
281
+ async #skip(id: string, runtime: Runtime, context: Context): Promise<void> {
282
+ const conversationId = runtime.conversationId;
283
+
284
+ await runtime.commit(async (tx) => {
285
+ const doc = await tx.doc(ScheduleDoc, conversationId);
286
+ const item = doc.items[id];
287
+
288
+ if (item === undefined) {
289
+ return finished;
290
+ }
291
+
292
+ const now = runtime.now();
293
+
294
+ item.skipped = (item.skipped ?? 0) + 1;
295
+ item.skippedAt = now;
296
+ // A one-time message has no next time; it never has a message of its own waiting either.
297
+ item.next = item.every === undefined ? now : nextRepeat(item.every, now, item.zone);
298
+ sayWhatWasSkipped(await tx.doc(ChatDoc, conversationId), item.text, now);
299
+
300
+ return { status: "running", checkpoint: { phase: "wait" } };
301
+ }, context);
302
+ this.#app.log(
303
+ `Schedule ${id} in session ${String(conversationId)} skipped a time: its last message still waits in the queue.`,
304
+ );
305
+ }
306
+
207
307
  /** Whether a conversation is a PiP whose person cannot have it now (its extension is off). */
208
308
  #waitsForPip(conversationId: ConversationId): boolean {
209
309
  const app = this.#app;
package/web/composer.js CHANGED
@@ -307,14 +307,14 @@ const SEND_MODES = [
307
307
  [
308
308
  "interrupt",
309
309
  "Interrupt",
310
- "Stops the run right now (also its tool call) and clears the queue, then sends it",
310
+ "Stops the run right now (also its tool call), then sends it. The queued messages stay queued",
311
311
  ],
312
312
  ];
313
313
 
314
314
  /** What a send mode does, for a queued message's buttons. */
315
315
  const modeHint = (mode) => SEND_MODES.find(([value]) => value === mode)[2];
316
316
 
317
- /** What Interrupt does to a message waiting in the queue: the others there stay, unlike the composer's Interrupt. */
317
+ /** What Interrupt does to a message waiting in the queue: the others there stay queued. */
318
318
  const QUEUED_INTERRUPT_HINT =
319
319
  "Stops the run right now (also its tool call), then sends this one. The other queued messages stay queued";
320
320
 
@@ -437,6 +437,87 @@ function DriverBar() {
437
437
  }
438
438
 
439
439
  /** Plan mode: Pi proposes and changes nothing until someone here approves its plan. */
440
+ /**
441
+ * What a Stop held out of the queue: it waits until someone sends it. Send sends them all, in their order; Show lists
442
+ * them, each with Edit (its sender's) and a × to withdraw it.
443
+ */
444
+ function HeldBar({ blocked, onEdit }) {
445
+ const { view, me, users } = store.state;
446
+ const held = view.held ?? [];
447
+ const [open, setOpen] = useState(false);
448
+
449
+ if (held.length === 0) {
450
+ return null;
451
+ }
452
+
453
+ const steer = canSteer();
454
+ const heldBy = (item) =>
455
+ item.by === undefined
456
+ ? ""
457
+ : item.by === me?.id
458
+ ? " · you"
459
+ : ` · ${users.find((user) => user.id === item.by)?.name ?? "someone"}`;
460
+
461
+ return html`<div class="held-bar" data-part="held">
462
+ <span class="grow">
463
+ <strong>${held.length === 1 ? "1 message held." : `${held.length} messages held.`}</strong> Stop kept ${held.length === 1 ? "it" : "them"} from Pi until sent.
464
+ </span>
465
+ <button class="link small" aria-expanded=${open} onClick=${() => setOpen(!open)}>
466
+ ${open ? "Hide" : "Show"}
467
+ </button>
468
+ ${
469
+ steer &&
470
+ !blocked &&
471
+ html`<button
472
+ class="button small primary"
473
+ title="Send them to Pi, in their order"
474
+ onClick=${() => attempt(actions.sendHeld)}
475
+ >
476
+ Send
477
+ </button>`
478
+ }
479
+ ${
480
+ open &&
481
+ html`<div class="held-list">
482
+ ${held.map(
483
+ (item) => html`<div class="queued" key=${item.key}>
484
+ <span class="queued-mode">
485
+ ${item.mode === "steer" ? "Steer" : "Queue"}
486
+ <span class="muted">${heldBy(item)}</span>
487
+ </span>
488
+ <span class="queued-text">${(item.text ?? "").replace(FROM, "")}</span>
489
+ ${
490
+ steer &&
491
+ !blocked &&
492
+ item.by !== undefined &&
493
+ item.by === me?.id &&
494
+ html`<button
495
+ class="link small"
496
+ title="Take it back into the message box to change it"
497
+ onClick=${() => onEdit(item)}
498
+ >
499
+ Edit
500
+ </button>`
501
+ }
502
+ ${
503
+ steer &&
504
+ (!blocked || item.by === me?.id) &&
505
+ html`<button
506
+ class="icon-button small queued-remove"
507
+ aria-label="Withdraw"
508
+ title="Withdraw: Pi will not get it"
509
+ onClick=${() => attempt(() => actions.dropHeld(item.key))}
510
+ >
511
+ <${Icon} name="close" size=${13} />
512
+ </button>`
513
+ }
514
+ </div>`,
515
+ )}
516
+ </div>`
517
+ }
518
+ </div>`;
519
+ }
520
+
440
521
  function PlanBar({ blocked }) {
441
522
  const { view } = store.state;
442
523
 
@@ -1090,6 +1171,22 @@ export function Composer() {
1090
1171
  }
1091
1172
  };
1092
1173
 
1174
+ // Edit on a held message: the same, for one a Stop held.
1175
+ const editHeld = async (item) => {
1176
+ if (takingBack.has(item.key)) {
1177
+ return;
1178
+ }
1179
+
1180
+ takingBack.add(item.key);
1181
+ const back = await attempt(() => actions.editHeld(item.key, conversationId));
1182
+
1183
+ takingBack.delete(item.key);
1184
+
1185
+ if (back) {
1186
+ keepBack(conversationId, back);
1187
+ }
1188
+ };
1189
+
1093
1190
  /** Put a message sent before into the box, to send again or change. */
1094
1191
  const recall = (value, at = value.length) => {
1095
1192
  edit(value, at);
@@ -1429,6 +1526,7 @@ export function Composer() {
1429
1526
  return html`<footer class="composer-wrap" data-part="composer">
1430
1527
  <div class="dock" data-part="dock" ref=${dock}>
1431
1528
  <${TypingLine} where="pi" />
1529
+ <${HeldBar} blocked=${blocked} onEdit=${editHeld} />
1432
1530
  ${
1433
1531
  // How many wait: shown when the queue does not show them all (`dock.js`).
1434
1532
  inbox.length > 0 &&
@@ -1961,7 +2059,7 @@ function StopButton() {
1961
2059
  class="stop-button"
1962
2060
  data-part="composer-button stop-button"
1963
2061
  aria-label="Stop"
1964
- title="Stop (Esc twice)"
2062
+ title="Stop (Esc twice). Queued messages are held until someone sends them"
1965
2063
  onClick=${() => attempt(actions.abort)}
1966
2064
  >
1967
2065
  <span class="stop-square" aria-hidden="true"></span>
@@ -1142,6 +1142,7 @@ function Row({
1142
1142
  <span class="rb-sched-rel">
1143
1143
  ${relative(schedule.next, now)}
1144
1144
  ${schedule.every ? ` · ${schedule.runs}×` : ""}
1145
+ ${schedule.skipped > 0 ? ` · skipped ${schedule.skipped}×` : ""}
1145
1146
  </span>
1146
1147
  </button>`,
1147
1148
  )
@@ -56,6 +56,12 @@ export function SchedulesSheet() {
56
56
  <div class="muted small">
57
57
  ${schedule.repeat ? `${schedule.repeat} · next ${formatWhen(schedule.next)}` : formatWhen(schedule.next)} · set by ${setBy(schedule.by)}${archived ? " · session archived" : ""}
58
58
  </div>
59
+ ${
60
+ schedule.skipped > 0 &&
61
+ html`<div class="muted small" data-part="schedule-skipped">
62
+ Skipped ${schedule.skipped === 1 ? "once" : `${schedule.skipped} times`}, last ${formatWhen(schedule.skippedAt)}: its last message still waits in the queue
63
+ </div>`
64
+ }
59
65
  </div>
60
66
  ${
61
67
  steer &&
package/web/store.js CHANGED
@@ -105,6 +105,7 @@ const emptyView = () => ({
105
105
  watch: null,
106
106
  branch: null,
107
107
  subagentsHeld: null,
108
+ held: [],
108
109
  });
109
110
 
110
111
  // ─── Each session's panel ──────────────────────────────────────────────────────────
@@ -1682,6 +1683,8 @@ function mergeView(current, data) {
1682
1683
  decisions: data.decisions ?? base.decisions,
1683
1684
  plan: data.plan ?? base.plan,
1684
1685
  schedules: data.schedules ?? base.schedules,
1686
+ // What a Stop held out of the queue: it waits until someone sends it.
1687
+ held: data.held ?? base.held,
1685
1688
  // No goal is null, which the server sends too: only a missing field keeps the last value.
1686
1689
  goal: data.goal === undefined ? base.goal : data.goal,
1687
1690
  // The session's PR watch, or null: the same.
@@ -2707,6 +2710,10 @@ export const actions = {
2707
2710
  /** Move one's own queued message to "steer" or "followUp", or send it now with "interrupt". */
2708
2711
  move: (submissionId, mode) => api(`c/${current()}/move`, { submissionId, mode }),
2709
2712
  editQueued: (submissionId, id = current()) => api(`c/${id}/edit-queued`, { submissionId }),
2713
+ /** What a Stop held: send them all, or drop one or take it back into the box, by its key. */
2714
+ sendHeld: () => api(`c/${current()}/held`, { action: "send" }),
2715
+ dropHeld: (key) => api(`c/${current()}/held`, { action: "drop", key }),
2716
+ editHeld: (key, id = current()) => api(`c/${id}/held`, { action: "edit", key }),
2710
2717
  configure: (change) => api(`c/${current()}/configure`, change),
2711
2718
  /** The owner's model and thinking level for new sessions, `{ provider, modelId, thinkingLevel }`; null clears it. */
2712
2719
  setDefaultModel: (choice) => api("settings", { defaultModel: choice }),