paseo-follow-up 2.2.0-beta.2 → 2.2.0-beta.4

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.
@@ -60,7 +60,9 @@ export type SessionStats = { done: number; skipped: number; later: number; gone:
60
60
  * A Catch up session. `order` is every card key seen this session (done ones stay, so Back works); `pos` is the card
61
61
  * on screen, `order.length` once nothing is left. `parked` maps a workstream waiting for More context to its request.
62
62
  */
63
- export type Session = { order: string[]; pos: number; outcomes: Record<string, Outcome>; parked: Record<string, string> };
63
+ export type Session = { order: string[]; pos: number; outcomes: Record<string, Outcome>; parked: Record<string, string>; lapped?: boolean;
64
+ /** Skip workspace jumped from `to` and landed on `from` (undefined: the finished screen): Back from there returns to `to`. */
65
+ back?: { to: string; from: string | undefined } };
64
66
 
65
67
  export const startSession = (cards: readonly Pick<DeckCard, "key">[]): Session => ({ order: cards.map(c => c.key), pos: 0, outcomes: {}, parked: {} });
66
68
 
@@ -70,23 +72,75 @@ const open = (s: Session, key: string) => { const o = s.outcomes[key]; return !o
70
72
  const landable = (s: Session, key: string) => open(s, key) && !s.parked[groupOf(key)];
71
73
 
72
74
  /**
73
- * The next card after `from`: the next landable one in order, else the first skipped one from the start (a second
74
- * pass), else `order.length` (finished). Never returns `from` itself unless it is the only one left.
75
+ * The next card after `from`: the next landable one in order, else the first skipped one from the start (one second
76
+ * pass, `lapped`), else `order.length` (finished). On the second pass a skip moves forward only, so skipping everything
77
+ * ends at the finished screen with "Catch up on N skipped" instead of going round for ever.
75
78
  */
76
- export function nextPos(s: Session, from: number): number {
77
- for (let i = from + 1; i < s.order.length; i++) if (landable(s, s.order[i]) && s.outcomes[s.order[i]] !== "skipped") return i;
78
- for (let i = 0; i < s.order.length; i++) if (i !== from && landable(s, s.order[i])) return i;
79
- return from < s.order.length && landable(s, s.order[from]) ? from : s.order.length;
79
+ export function advance(s: Session, from: number): Pick<Session, "pos" | "lapped"> {
80
+ for (let i = from + 1; i < s.order.length; i++) if (landable(s, s.order[i]) && (s.lapped || s.outcomes[s.order[i]] !== "skipped")) return { pos: i, lapped: s.lapped };
81
+ if (!s.lapped) for (let i = 0; i < s.order.length; i++) if (i !== from && landable(s, s.order[i])) return { pos: i, lapped: true };
82
+ return { pos: s.order.length, lapped: s.lapped };
80
83
  }
84
+ export const nextPos = (s: Session, from: number): number => advance(s, from).pos;
81
85
 
82
- /** Back: the card before, whatever happened to it (done cards show what was sent; a parked one shows it is asking). */
83
- export const prevPos = (s: Session): number => Math.max(0, Math.min(s.pos, s.order.length) - 1);
86
+ /**
87
+ * Back: the card before, whatever happened to it (done cards show what was sent; a parked one shows it is asking).
88
+ * Right after Skip workspace, Back returns to the card it was pressed on, not the last card of the skipped workspace.
89
+ */
90
+ export function prevPos(s: Session): number {
91
+ if (s.back && s.order[s.pos] === s.back.from) { const i = s.order.indexOf(s.back.to); if (i >= 0) return i; }
92
+ return Math.max(0, Math.min(s.pos, s.order.length) - 1);
93
+ }
94
+
95
+ /** The cards of the on-screen card's workspace still to act on, the current one included: Skip workspace shows only above one. */
96
+ export function openInWorkspace(s: Session, key = s.order[s.pos]): string[] {
97
+ if (key === undefined) return [];
98
+ const g = groupOf(key);
99
+ return s.order.filter(k => groupOf(k) === g && open(s, k));
100
+ }
101
+
102
+ /**
103
+ * Skip workspace: every card of this workspace still to act on is skipped at once (each counts as one skipped card) and
104
+ * the deck moves to the next workspace. They come back on the second pass like any skipped card; on the second pass
105
+ * itself it moves past the rest of them.
106
+ */
107
+ export function skipWorkspace(s: Session): Session {
108
+ const key = s.order[s.pos];
109
+ if (key === undefined) return s;
110
+ const g = groupOf(key);
111
+ const outcomes = { ...s.outcomes };
112
+ for (const k of openInWorkspace(s)) outcomes[k] = "skipped";
113
+ const next: Session = { ...s, outcomes };
114
+ let at = advance(next, s.pos);
115
+ while (at.pos < s.order.length && groupOf(s.order[at.pos]) === g) at = advance({ ...next, lapped: at.lapped }, at.pos);
116
+ return { ...next, ...at, back: { to: key, from: s.order[at.pos] } };
117
+ }
118
+
119
+ /** Phone drag: which way a touch is going, decided once it has moved this far, so a vertical scroll stays a scroll. */
120
+ export const SWIPE_LOCK_PX = 8;
121
+ export function swipeLock(dx: number, dy: number): "x" | "y" | null {
122
+ if (Math.max(Math.abs(dx), Math.abs(dy)) < SWIPE_LOCK_PX) return null;
123
+ return Math.abs(dx) > 1.5 * Math.abs(dy) ? "x" : "y";
124
+ }
125
+ /**
126
+ * A released drag: past `SWIPE_COMMIT` of the card's width, or flung faster than `SWIPE_FLING` px/ms the same way, left
127
+ * skips the card and right goes Back (when there is a card to go back to); anything else springs back.
128
+ */
129
+ export const SWIPE_COMMIT = 0.35;
130
+ export const SWIPE_FLING = 0.5;
131
+ export function swipeOutcome(g: { dx: number; vx: number; width: number; canBack: boolean }): "skip" | "back" | "stay" {
132
+ const far = Math.abs(g.dx) > SWIPE_COMMIT * g.width;
133
+ const fling = Math.abs(g.vx) > SWIPE_FLING && Math.sign(g.vx) === Math.sign(g.dx);
134
+ if (!far && !fling) return "stay";
135
+ if (g.dx < 0) return "skip";
136
+ return g.canBack && g.dx > 0 ? "back" : "stay";
137
+ }
84
138
 
85
139
  /** Records what happened to the card on screen and moves on. */
86
140
  export function settle(s: Session, outcome: Outcome, key = s.order[s.pos]): Session {
87
141
  if (key === undefined) return s;
88
142
  const next = { ...s, outcomes: { ...s.outcomes, [key]: outcome } };
89
- return s.order[s.pos] === key ? { ...next, pos: nextPos(next, s.pos) } : next;
143
+ return s.order[s.pos] === key ? { ...next, ...advance(next, s.pos) } : next;
90
144
  }
91
145
 
92
146
  /**
@@ -97,7 +151,7 @@ export function settle(s: Session, outcome: Outcome, key = s.order[s.pos]): Sess
97
151
  export function park(s: Session, requestId: string, key = s.order[s.pos]): Session {
98
152
  if (key === undefined) return s;
99
153
  const next = { ...s, parked: { ...s.parked, [groupOf(key)]: requestId } };
100
- return s.order[s.pos] !== undefined && groupOf(s.order[s.pos]) === groupOf(key) ? { ...next, pos: nextPos(next, s.pos) } : next;
154
+ return s.order[s.pos] !== undefined && groupOf(s.order[s.pos]) === groupOf(key) ? { ...next, ...advance(next, s.pos) } : next;
101
155
  }
102
156
 
103
157
  /**
@@ -125,7 +179,7 @@ export function sync(s: Session, live: readonly Pick<DeckCard, "key">[], settled
125
179
  order = [...rest.slice(0, at), ...back, ...rest.slice(at)];
126
180
  pos = current === undefined ? at : order.indexOf(current);
127
181
  }
128
- return { order, pos, outcomes, parked };
182
+ return { ...s, order, pos, outcomes, parked };
129
183
  }
130
184
 
131
185
  /** The progress line's numbers: the card on screen out of every card this session, and what is waiting for context. */
@@ -137,19 +191,78 @@ export function statsOf(s: Session): SessionStats {
137
191
  }
138
192
 
139
193
  /** The keys, one place, so the help line, the tooltips and the handler agree. Option letters pick; these never collide with A–H. */
140
- export const CATCH_UP_KEYS = [
141
- { key: "A–H", what: "Pick an option" },
142
- { key: "W", what: "Write your own answer" },
143
- { key: "⌘↵", what: "Send" },
144
- { key: "J / →", what: "Skip" },
145
- { key: "K / ←", what: "Back" },
146
- { key: "M", what: "More context" },
147
- { key: "N", what: "Add a note" },
148
- { key: "L", what: "Later" },
149
- { key: "O", what: "Open chat" },
150
- { key: "?", what: "Show the keys" },
151
- { key: "Esc", what: "Leave" },
152
- ] as const;
194
+ /**
195
+ * Catch up's keys (desktop web): one list that the handler (`catchUpKey`), the S sheet and the hint line read, so
196
+ * they never disagree. `combos` spell each key the way Paseo's bundle does (PASEO_BOUND, shared/search-key.ts):
197
+ * tests/catch-up-keys.test.ts fails if one is a combo Paseo binds, Home's search key, or one of the search-from-
198
+ * anywhere presets. Paseo takes Shift+? (its shortcuts dialog) and Escape (interrupt agent) when focus is outside a
199
+ * field, which is exactly when these fire, so the sheet is S and leaving is X.
200
+ */
201
+ export type CatchUpAction = "pick" | "own" | "send" | "skip" | "skip-workspace" | "back" | "more" | "chip" | "ask" | "note" | "later" | "chat" | "rail" | "rail-up" | "rail-down" | "keys" | "leave";
202
+ /**
203
+ * a-move-bar-action-opens-in-view: where each move-bar action opens what it opens, so its result is where the eye
204
+ * already is and never appended below the fold. `sheet`: drawn in the phone's dock, above the bar, kept above the
205
+ * keyboard. `popover`: anchored to its button on desktop. `focus`: a field or row takes focus, and DockedPane (phone)
206
+ * or the browser (desktop) scrolls it into view. `navigates`: leaves Catch up for the chat.
207
+ */
208
+ export type MovePlace = "sheet" | "popover" | "focus" | "navigates";
209
+ export const MOVE_OPENS: Readonly<Record<"more" | "later" | "note" | "chat" | "rail", { phone: MovePlace | null; desktop: MovePlace }>> = {
210
+ more: { phone: "sheet", desktop: "popover" },
211
+ later: { phone: "sheet", desktop: "popover" },
212
+ note: { phone: "focus", desktop: "focus" },
213
+ chat: { phone: "navigates", desktop: "navigates" },
214
+ // The queue rail is desktop only.
215
+ rail: { phone: null, desktop: "focus" },
216
+ };
217
+
218
+ /** A key as this platform spells it: ⌘ on a Mac, Ctrl elsewhere (as the Send button's own hint reads). */
219
+ export const keyLabel = (key: string, mac: boolean) => mac ? key : key.replace("⌘", "Ctrl ");
220
+
221
+ export const CATCH_UP_KEYS: readonly { key: string; what: string; action: CatchUpAction; combos: readonly string[]; when?: "more" | "rail" }[] = [
222
+ { key: "A–H", what: "Pick an option", action: "pick", combos: ["A", "B", "C", "D", "E", "F", "G", "H"] },
223
+ { key: "W", what: "Write your own answer", action: "own", combos: ["W"] },
224
+ { key: "⌘↵", what: "Send", action: "send", combos: ["Cmd+Enter", "Ctrl+Enter"] },
225
+ { key: "J / →", what: "Skip this card (it comes back after the rest)", action: "skip", combos: ["J", "ArrowRight"] },
226
+ { key: "⇧J", what: "Skip workspace (all its cards come back after the rest)", action: "skip-workspace", combos: ["Shift+J"] },
227
+ { key: "K / ←", what: "Back", action: "back", combos: ["K", "ArrowLeft"] },
228
+ { key: "M", what: "More context", action: "more", combos: ["M"] },
229
+ { key: "1–4", what: "Pick a More context ask", action: "chip", combos: ["Digit"], when: "more" },
230
+ { key: "⌘↵", what: "Ask the agent", action: "ask", combos: ["Cmd+Enter", "Ctrl+Enter"], when: "more" },
231
+ { key: "N", what: "Add a note", action: "note", combos: ["N"] },
232
+ { key: "L", what: "Later", action: "later", combos: ["L"] },
233
+ { key: "O", what: "Open chat", action: "chat", combos: ["O"] },
234
+ { key: "R", what: "Go to the queue, and back", action: "rail", combos: ["R"] },
235
+ { key: "↑ / ↓", what: "Move in the queue (Enter opens)", action: "rail-up", combos: ["ArrowUp", "ArrowDown"], when: "rail" },
236
+ { key: "S", what: "Show the keys", action: "keys", combos: ["S"] },
237
+ { key: "X", what: "Leave Catch up", action: "leave", combos: ["X"] },
238
+ ];
239
+
240
+ export type KeyPress = { key: string; meta: boolean; ctrl: boolean; alt: boolean; shift: boolean; composing?: boolean; mac: boolean };
241
+ /**
242
+ * What a key press does in Catch up, or null to leave it alone (Paseo's, the field's, the browser's). Pure, so the
243
+ * map is tested without a DOM. `typing`: focus is in a text field, where only the More context box's ⌘↵ and ⌘⇧↵ act
244
+ * (a card field's ⌘↵ is its own SubmitScope's). `inRail`: focus is in the queue.
245
+ */
246
+ export function catchUpKey(e: KeyPress, at: { typing: boolean; inMore: boolean; moreOpen: boolean; inRail: boolean }): { action: CatchUpAction; arg?: string } | null {
247
+ if (e.composing || e.alt) return null;
248
+ const mod = e.mac ? e.meta : e.ctrl;
249
+ if (e.key === "Enter" && mod && (e.mac ? !e.ctrl : !e.meta)) {
250
+ if (e.shift) return null;
251
+ if (at.moreOpen && (!at.typing || at.inMore)) return { action: "ask" };
252
+ return at.typing ? null : { action: "send" };
253
+ }
254
+ if (at.typing || e.meta || e.ctrl) return null;
255
+ if (at.inRail && (e.key === "ArrowUp" || e.key === "ArrowDown")) return { action: e.key === "ArrowUp" ? "rail-up" : "rail-down" };
256
+ if (e.key === "ArrowRight") return { action: "skip" };
257
+ if (e.key === "ArrowLeft") return { action: "back" };
258
+ if (at.moreOpen && /^[1-4]$/.test(e.key)) return { action: "chip", arg: e.key };
259
+ if (e.shift && e.key.toLowerCase() === "j") return { action: "skip-workspace" };
260
+ if (e.shift || e.key.length !== 1) return null;
261
+ const k = e.key.toLowerCase();
262
+ if (/^[a-h]$/.test(k)) return { action: "pick", arg: k.toUpperCase() };
263
+ const byLetter: Record<string, CatchUpAction> = { w: "own", j: "skip", k: "back", m: "more", n: "note", l: "later", o: "chat", r: "rail", s: "keys", x: "leave" };
264
+ return byLetter[k] ? { action: byLetter[k] } : null;
265
+ }
153
266
 
154
267
  /**
155
268
  * The mode's name in every place it shows, so renaming it is one edit. Tom picked Catch up (2026-11-17: "people know
@@ -164,12 +277,18 @@ export const MODE = {
164
277
  progress: (at: number, of: number) => `Catch up ${at} of ${of}`,
165
278
  waiting: (n: number) => `${n} getting context`,
166
279
  finished: "All caught up",
280
+ /** The end of a deck with cards still skipped or waiting: not caught up, so it does not say so. */
281
+ endOfDeck: "End of the deck",
167
282
  empty: "Nothing needs you",
168
283
  } as const;
169
284
 
170
285
  // More context ------------------------------------------------------------------------------------------------------
171
286
 
172
- /** Who answers: the Overseer from what it already knows (wakes no one), or the card's own agent (Tom asked, so it may wake). */
287
+ /**
288
+ * Who answered. Every ask goes to the card's workspace's main agent (`agent`; asking may wake it, because the developer
289
+ * asked). `overseer` is only read from files written by 2.2.0-beta.3, which could route an ask to the Overseer: it never
290
+ * had context_reply, so those settle as `chat` on load (an-ask-goes-only-to-an-agent-that-can-answer-it).
291
+ */
173
292
  export const CONTEXT_TARGETS = ["overseer", "agent"] as const;
174
293
  export type ContextTarget = typeof CONTEXT_TARGETS[number];
175
294
  /** asking → answered (the reply came with context_reply), chat (the agent ended its turn without it: read its chat), failed. */
@@ -200,13 +319,19 @@ export const contextRequestSchema = z.object({
200
319
  target: z.enum(CONTEXT_TARGETS),
201
320
  /** The developer's words, or a suggestion's text. */
202
321
  ask: z.string().min(1).max(2000),
203
- /** The agent that should reply (the card's agent, or the Overseer once it is known). */
322
+ /** The agent that should reply: the workspace's main agent (an Overseer's id on beta.3 files). */
204
323
  askedOf: z.string().nullable(),
205
324
  state: z.enum(CONTEXT_STATES),
206
325
  answer: z.string().max(CONTEXT_ANSWER_MAX).nullable(),
207
326
  error: z.string().max(500).nullable(),
208
327
  askedAt: iso,
209
328
  settledAt: iso.nullable(),
329
+ /**
330
+ * When the ask actually reached `askedOf` (the queue sent it, or the Overseer took it). The first turn end after this
331
+ * without a context_reply settles it as `chat`, so a prompt steered into a running turn counts too. Absent in files
332
+ * from before it existed.
333
+ */
334
+ deliveredAt: iso.nullable().default(null),
210
335
  /** Who asked: "developer" or "agent:<id>" (agent parity). */
211
336
  by: z.string().max(120),
212
337
  });
@@ -232,18 +357,26 @@ export function agentContextPrompt(r: Pick<ContextRequest, "id" | "card" | "ask"
232
357
  ].join("\n");
233
358
  }
234
359
 
235
- /** The Overseer's version: it answers from what it can read without waking anyone, and doesn't forward the ask. */
236
- export function overseerContextPrompt(r: Pick<ContextRequest, "id" | "card" | "ask">, workspace: string): string {
237
- return [
238
- `The developer is catching up on what needs them and is looking at a card from ${workspace}: ${r.card}`,
239
- `They want more context before they answer: "${r.ask}"`,
240
- `Answer from what you can read (workstreams, agent_digest) without waking agents and without forwarding this to the agent. Plain words, short (under ${CONTEXT_ANSWER_MAX} characters).`,
241
- `Reply with ${REPLY_TOOL} and requestId "${r.id}" so the answer shows on their card.`,
242
- ].join("\n");
243
- }
360
+ /**
361
+ * an-ask-goes-only-to-an-agent-that-can-answer-it: the role a More context ask is routed to. context_reply is a tool
362
+ * of this role only (server/mcp-source.ts toolList: contributors, recovery agents and untracked agents such as the
363
+ * Overseer don't get it), so an ask is only ever delivered where its answer can reach the card.
364
+ */
365
+ export const CONTEXT_REPLY_ROLE = "main" as const;
244
366
 
245
367
  /** A request older than CONTEXT_KEEP_MS goes, then the oldest past CONTEXT_MAX; an asking one is kept while it is young. */
246
368
  export function pruneContext(requests: readonly ContextRequest[], now: number): ContextRequest[] {
247
369
  const young = requests.filter(r => now - Date.parse(r.askedAt) < CONTEXT_KEEP_MS);
248
370
  return young.slice(Math.max(0, young.length - CONTEXT_MAX));
249
371
  }
372
+
373
+ /**
374
+ * A context answer as the card shows it: plain words. Agents often answer in Markdown, which the card would show as
375
+ * literal ** and # marks, so emphasis, heading and quote marks go; links and line breaks stay.
376
+ */
377
+ export function plainAnswer(text: string): string {
378
+ return text.replace(/\*\*(.+?)\*\*|__(.+?)__/g, (_m, a, b) => a ?? b).replace(/^\s{0,3}(#{1,6}|>)\s+/gm, "").trim();
379
+ }
380
+
381
+ /** The ask as the card's header quotes it: its first sentence ("I don't get it."), not the whole prompt. */
382
+ export const askHeadline = (ask: string): string => (ask.match(/^.+?[.?!](?=\s|$)/)?.[0] ?? ask).slice(0, 120);
@@ -210,8 +210,10 @@ export const overseerAskRpc = defineRpc({ name: "follow.overseer-ask", input: z.
210
210
  // asked agent's reply. The ask answers once it is recorded; the send to the agent goes through the message queue.
211
211
  export const contextAskRpc = defineRpc({ name: "follow.context-ask", input: z.strictObject({
212
212
  workspaceId: z.string().min(1).max(200).nullable(), agentId: z.string().min(1).max(200).nullable(), cardKey: z.string().min(1).max(400),
213
- card: z.string().trim().min(1).max(300), target: z.enum(CONTEXT_TARGETS), ask: z.string().trim().min(1).max(2000) }),
214
- output: z.object({ request: contextRequestSchema, fresh: z.boolean() }) });
213
+ card: z.string().trim().min(1).max(300),
214
+ /** Ignored: every ask goes to the card's workspace's main agent. Still accepted, so older callers don't break. */
215
+ target: z.enum(CONTEXT_TARGETS).optional(), ask: z.string().trim().min(1).max(2000) }),
216
+ output: z.object({ request: contextRequestSchema, fresh: z.boolean(), note: z.string().optional() }) });
215
217
  export const contextListRpc = defineRpc({ name: "follow.context-list", input: z.strictObject({ workspaceId: z.string().max(200).optional() }), output: z.object({ requests: z.array(contextRequestSchema) }) });
216
218
  /** Catch up's deck as the developer's Home would deal it (agent parity: an agent sees what the developer goes through). */
217
219
  export const catchUpDeckRpc = defineRpc({ name: "follow.catch-up-deck", input: z.strictObject({}), output: z.object({
package/shared/display.ts CHANGED
@@ -7,6 +7,10 @@ import { SEARCH_SHORTCUTS } from "./search-key";
7
7
  export const HOME_DETAIL_DEFAULT = 0.42;
8
8
  export const HOME_DETAIL_MIN = 0.2;
9
9
  export const HOME_DETAIL_MAX = 0.8;
10
+ /** Catch up's queue rail on desktop (side-panes-are-resizable): its share of the width. */
11
+ export const CATCH_UP_RAIL_DEFAULT = 0.28;
12
+ export const CATCH_UP_RAIL_MIN = 0.16;
13
+ export const CATCH_UP_RAIL_MAX = 0.5;
10
14
 
11
15
  export const displayPreferences = defineSettings({
12
16
  id: "display",
@@ -36,6 +40,9 @@ export const displayPreferences = defineSettings({
36
40
  // 2.1: the share of Home's width the right pane (the brief or the selected item) takes, set by dragging the divider
37
41
  // (client/split.tsx). A fraction, so it carries across window sizes; absent means HOME_DETAIL_DEFAULT.
38
42
  home_detail_fraction: z.number().min(HOME_DETAIL_MIN).max(HOME_DETAIL_MAX).optional(),
43
+ // 2.2: the share of Catch up's width its queue rail takes on desktop (client/catch-up.tsx, client/split.tsx).
44
+ // Absent means CATCH_UP_RAIL_DEFAULT.
45
+ catch_up_rail_fraction: z.number().min(CATCH_UP_RAIL_MIN).max(CATCH_UP_RAIL_MAX).optional(),
39
46
  // 2.1: the key that opens Home with the cursor in its search from anywhere in Paseo (shared/search-key.ts).
40
47
  // Absent means DEFAULT_SEARCH_SHORTCUT (⌘/ or Ctrl+/); "none" turns it off.
41
48
  search_shortcut: z.enum(SEARCH_SHORTCUTS).optional() }),