pendingyou 0.39.0 → 0.41.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.41.0 (2026-11-03)
4
+
5
+ - Pending You for Herdr holds a card while you're in its agent's pane. When the agent in the Herdr pane you're in also
6
+ asks you something there, Pending You keeps its card out of sight while you stay: answer it in the pane and it never
7
+ shows; leave the pane, go 5 minutes without a sign of you in Herdr, or let 30 minutes pass, and it shows as a new
8
+ card. The watcher tells Pending You which pane you're in and your last sign of you there: moving between panes, tabs
9
+ and workspaces, keys in the popup, and each message you send the agent in that pane (its app's next-message hook
10
+ notes the moment, never the words). Herdr can't tell anyone about keys typed in a pane, so those don't count.
11
+ - A held card stays off the pane's badges, so off the sidebar's row, the popup, `next` and the toasts, and comes back
12
+ the moment it shows. Each badge write keeps its pane's cards (the titles the badges already carry) in
13
+ `~/.config/pendingyou/herdr/` so the watcher can write them again.
14
+ - It needs Herdr signed in again (`npx pendingyou app login herdr`, or setup's "Sign Herdr in again now?"): a sign-in
15
+ from before doesn't hold the new `presence:focus`. Setup and doctor say so. With a Pending You that doesn't hold cards
16
+ yet, the watcher is told no and asks again 10 minutes later; nothing else changes.
17
+
18
+ ## 0.40.0 (2026-10-28)
19
+
20
+ - Pending You for Herdr answers "Ask Maple again?": when one of your agents asks to send its card to another of your
21
+ assistants, one you handed one of its cards to before, the popup shows the card as Maple will see it, what Maple
22
+ helped with before and where its answer would go, and `y` says yes this time (the card goes to Maple, as handing it
23
+ over does, and `u` takes it back for 5 seconds) while `n` says no (the agent hears "Don’t send it to Maple"). Saying
24
+ "from now on" stays in Pending You. When Maple isn't one Herdr may hand the card to (it runs on another computer, or
25
+ it's gone), the card says to say yes in Pending You, and `n` still says no.
26
+ - A card your agent asked to send a teammate ("Send this to Doug?") says to answer it in Pending You, and `o` opens it:
27
+ no key answers it from Herdr. Before, the popup showed it as a plain card, and Pending You refused the answer.
28
+ - Both need a Pending You that says whom a card is to go to (2026-10-28); with an older one the popup is as before.
29
+
3
30
  ## 0.39.0 (2026-10-25)
4
31
 
5
32
  - In tmux, your agents' sessions now say which pane they run in, as they have in Herdr since 0.18.0: each presence
package/README.md CHANGED
@@ -407,7 +407,8 @@ with a key: 1–9 for a choice (Enter sends several), y or n to approve or decli
407
407
  a step done or not, Tab between a grouped card's questions; r writes to the agent, l puts it in Later, d hands it to
408
408
  another of your agents, u undoes for 5 seconds, t goes to the agent's pane, o opens the card in Pending You. A
409
409
  high-stakes card (it spends money, can't be undone or goes public) is never answered from Herdr: o opens it where you
410
- hold to approve. Pending You says on the card and to the agent "Answered in Herdr on build-01". While you're active in
410
+ hold to approve. Since 0.40.0, when an agent asks to send its card to another of your assistants ("Ask Maple
411
+ again?"), y says yes this time and n says no; one it asks to send a teammate is answered in Pending You, and o opens it. Pending You says on the card and to the agent "Answered in Herdr on build-01". While you're active in
411
412
  Herdr (moving between panes, tabs and workspaces, or pressing keys in the popup) your phone stays quiet for those cards,
412
413
  as it does while Pending You is open on your desk.
413
414
 
@@ -426,6 +427,18 @@ Claude Code). Otherwise Pending You hears "not found", and nothing moves. It onl
426
427
  never types into one, runs or opens anything, and logs nothing. Setup starts this version's watcher in place of one
427
428
  from an older pendingyou, which doesn't listen.
428
429
 
430
+ ### Holding cards while you're in the agent's pane (0.41.0)
431
+
432
+ When the agent in the Herdr pane you're in also asks you something there, Pending You keeps its card out of sight while
433
+ you stay: answer it in the pane and it never shows; leave the pane, go 5 minutes without a sign of you in Herdr, or let
434
+ 30 minutes pass, and it shows as a new card. The watcher tells Pending You which pane you're in and your last sign of you
435
+ there once Herdr's sign-in allows it (`presence:focus`, which only Pending You's own apps may hold; a sign-in from before
436
+ 0.41.0 doesn't hold it, and setup and doctor say to sign in again). The signs are moving between panes, tabs and
437
+ workspaces, keys in the popup, and each message you send the agent in that pane: its app's next-message hook notes the
438
+ moment in `~/.config/pendingyou/herdr/messages/`, never the words. A held card stays off the pane's badges (the sidebar's
439
+ row, the popup, `next`, the toasts) and comes back the moment it shows. Turn it off in Pending You: Settings ›
440
+ Notifications › In Herdr.
441
+
429
442
  ## How Claude Code hears your answer
430
443
 
431
444
  **Claude Code 2.1.287 or later: the wake mod.** There's nothing to run. In each session the mod learns the cards
package/dist/app-login.js CHANGED
@@ -21,8 +21,9 @@ export const APP_SCOPES = [
21
21
  'assistants:show',
22
22
  'presence:desk',
23
23
  ];
24
+ export const HERDR_SCOPES = [...APP_SCOPES, 'presence:focus'];
24
25
  export const FIRST_PARTY_APPS = {
25
- herdr: { name: 'Herdr', scopes: APP_SCOPES },
26
+ herdr: { name: 'Herdr', scopes: HERDR_SCOPES },
26
27
  };
27
28
  export const DEFAULT_SCOPES = ['cards:read'];
28
29
  export const APP_NAME = /^[a-z0-9][a-z0-9-]{0,39}$/;
@@ -57,6 +58,7 @@ const MAY = {
57
58
  'assistants:read': 'see your assistants',
58
59
  'assistants:show': 'bring the assistant that asked to the front when you press Show',
59
60
  'presence:desk': 'keep your phone quiet while you use it',
61
+ 'presence:focus': 'hold cards from the agent whose pane you’re in until you leave it',
60
62
  };
61
63
  const listed = (items) => items.length <= 1 ? (items[0] ?? '') : `${items.slice(0, -1).join(', ')} and ${items.at(-1)}`;
62
64
  export function reachWords(me) {
@@ -22,6 +22,17 @@ export const askerOf = (card) => `${card.asker.agent?.name ?? card.asker.assista
22
22
  const askerName = (card) => card.asker.agent?.name ?? card.asker.assistant.name;
23
23
  export const HIGH_STAKES = 'High stakes: answer it in Pending You, where you hold to approve. o opens it.';
24
24
  export const NOT_HERE = 'Answer this one in Pending You: o opens it.';
25
+ export const SAY_YES_THERE = 'Say yes in Pending You: o opens it.';
26
+ const ASK_AGAIN_KEYS = 'y: yes, this time; n: no.';
27
+ export const sendToOf = (card) => card.sendTo && (card.status === 'pending' || card.status === 'snoozed') ? card.sendTo : null;
28
+ const asksAgain = (sendTo) => sendTo.kind === 'assistant';
29
+ export const toTeammate = (card) => `Send this to ${card.sendTo?.name ?? 'them'}? Answer it in Pending You: o opens it.`;
30
+ const dayOf = (at) => {
31
+ const when = new Date(at);
32
+ return Number.isNaN(when.getTime())
33
+ ? ''
34
+ : when.toLocaleDateString('en-US', { month: 'short', day: 'numeric' });
35
+ };
25
36
  const KINDS = [
26
37
  'choice',
27
38
  'multi',
@@ -38,7 +49,8 @@ const QUESTION_KINDS = [
38
49
  'approve',
39
50
  'text',
40
51
  ];
41
- const answersHere = (card) => card.actions.includes('answer') &&
52
+ const answersHere = (card) => !sendToOf(card) &&
53
+ card.actions.includes('answer') &&
42
54
  KINDS.includes(card.kind) &&
43
55
  (card.questions ?? []).every((question) => QUESTION_KINDS.includes(question.kind));
44
56
  const NO_WORDS = 'Pending You takes no words on this card from Herdr: o opens it.';
@@ -145,10 +157,51 @@ function listKey(state, key, now) {
145
157
  { kind: 'targets', card },
146
158
  ];
147
159
  }
160
+ const sendTo = sendToOf(card);
161
+ if (sendTo)
162
+ return sendToKey(state, card, sendTo, key);
148
163
  if (!answersHere(card))
149
164
  return [{ ...state, note: NOT_HERE }, NONE];
150
165
  return answerKey(state, card, key);
151
166
  }
167
+ function sendToKey(state, card, sendTo, key) {
168
+ if (!asksAgain(sendTo))
169
+ return [{ ...state, note: toTeammate(card) }, NONE];
170
+ if (key === 'y') {
171
+ const to = sendTo.to;
172
+ if (!to || !card.actions.includes('delegate'))
173
+ return [{ ...state, note: SAY_YES_THERE }, NONE];
174
+ return [
175
+ { ...state, note: '' },
176
+ {
177
+ kind: 'delegate',
178
+ card,
179
+ target: {
180
+ assistantId: to.assistantId,
181
+ agentId: to.agentId,
182
+ name: sendTo.name,
183
+ label: sendTo.name,
184
+ detail: '',
185
+ },
186
+ mode: sendTo.mode === 'freely' ? 'freely' : 'loop',
187
+ },
188
+ ];
189
+ }
190
+ if (key === 'n') {
191
+ if (!card.actions.includes('answer'))
192
+ return [{ ...state, note: NOT_HERE }, NONE];
193
+ return [
194
+ { ...state, note: '' },
195
+ {
196
+ kind: 'answer',
197
+ card,
198
+ answer: { version: card.version, notSent: true },
199
+ words: sendTo.name,
200
+ },
201
+ ];
202
+ }
203
+ return [{ ...state, note: ASK_AGAIN_KEYS }, NONE];
204
+ }
152
205
  function answerKey(state, card, key) {
153
206
  const send = (answer, words) => [
154
207
  { ...state, note: '' },
@@ -423,6 +476,7 @@ export function targetsFor(card, assistants) {
423
476
  continue;
424
477
  targets.push({
425
478
  assistantId: assistant.id,
479
+ name: assistant.name,
426
480
  label: `${assistant.name} (${assistant.appName})`,
427
481
  detail: [...where].join(' · ') || 'in the cloud',
428
482
  });
@@ -435,6 +489,7 @@ export function targetsFor(card, assistants) {
435
489
  targets.push({
436
490
  assistantId: assistant.id,
437
491
  agentId: agent.id,
492
+ name: agent.name,
438
493
  label: `${agent.name} (${assistant.appName})`,
439
494
  detail: [agent.state, ...where, ...(pane ? [`pane ${pane}`] : [])].join(' · '),
440
495
  });
@@ -516,10 +571,12 @@ export function headingOf(state) {
516
571
  function askLines(card, state, room, now) {
517
572
  const fit = (text) => cleanValue(text, room);
518
573
  const lines = [];
574
+ const sendTo = sendToOf(card);
575
+ const keyOf = (index) => (sendTo ? '·' : `${index + 1}`);
519
576
  const options = (list, recommended = [], chosen) => (list ?? []).slice(0, KEYS_MAX).map((option, index) => {
520
- const box = chosen ? (chosen.includes(option.id) ? '[x] ' : '[ ] ') : '';
577
+ const box = chosen && !sendTo ? (chosen.includes(option.id) ? '[x] ' : '[ ] ') : '';
521
578
  const star = recommended.includes(option.id) ? '★ ' : '';
522
- return fit(`${box}${index + 1} ${star}${option.label}${option.detail ? ` · ${option.detail}` : ''}`);
579
+ return fit(`${box}${keyOf(index)} ${star}${option.label}${option.detail ? ` · ${option.detail}` : ''}`);
523
580
  });
524
581
  const more = (list) => (list?.length ?? 0) > KEYS_MAX
525
582
  ? [fit(`… and ${(list?.length ?? 0) - KEYS_MAX} more: o opens the card`)]
@@ -544,7 +601,7 @@ function askLines(card, state, room, now) {
544
601
  if (card.text?.placeholder)
545
602
  lines.push(DIM(fit(card.text.placeholder)));
546
603
  for (const [index, suggestion] of (card.text?.suggestions ?? []).slice(0, KEYS_MAX).entries())
547
- lines.push(fit(`${index + 1} ${suggestion}`));
604
+ lines.push(fit(`${keyOf(index)} ${suggestion}`));
548
605
  break;
549
606
  case 'action':
550
607
  for (const [index, step] of steps(card).entries()) {
@@ -561,6 +618,11 @@ function askLines(card, state, room, now) {
561
618
  break;
562
619
  case 'group': {
563
620
  const questions = card.questions ?? [];
621
+ if (sendTo) {
622
+ for (const question of questions)
623
+ lines.push(fit(`· ${question.title}`));
624
+ break;
625
+ }
564
626
  for (const [index, question] of questions.entries()) {
565
627
  const answer = state.answers[question.id];
566
628
  const mark = index === state.question ? '▸' : answer ? '✓' : '·';
@@ -585,12 +647,44 @@ function askLines(card, state, room, now) {
585
647
  }
586
648
  if (card.fallback)
587
649
  lines.push(DIM(fit(`If you don’t answer ${fromNow(card.fallback.at, now)}: ${card.fallback.text}`)));
650
+ if (sendTo)
651
+ lines.push(...sendToLines(card, sendTo, room));
588
652
  if (card.highStakes)
589
653
  lines.push(...wrap(HIGH_STAKES, room, 2));
590
- else if (!answersHere(card))
654
+ else if (!sendTo && !answersHere(card))
591
655
  lines.push(...wrap(NOT_HERE, room, 2));
592
656
  return lines;
593
657
  }
658
+ function sendToLines(card, sendTo, room) {
659
+ if (!asksAgain(sendTo))
660
+ return wrap(toTeammate(card), room, 2);
661
+ const name = sendTo.name;
662
+ const helped = sendTo.helped;
663
+ const on = helped && dayOf(helped.at) ? ` on ${dayOf(helped.at)}` : '';
664
+ const before = helped
665
+ ? helped.answered
666
+ ? `${name} helped with “${helped.title}”${on}.`
667
+ : `You handed ${name} “${helped.title}”${on}.`
668
+ : null;
669
+ const goes = sendTo.mode === 'freely'
670
+ ? `${name}’s answer goes straight to ${askerName(card)}.`
671
+ : `${name}’s answer comes back to you first.`;
672
+ const yesHere = Boolean(sendTo.to) && card.actions.includes('delegate');
673
+ return [
674
+ BOLD(cleanValue(`Ask ${name} again?`, room)),
675
+ ...(before ? wrap(before, room, 2) : []),
676
+ ...wrap(goes, room, 2),
677
+ ...(yesHere || card.highStakes ? [] : wrap(SAY_YES_THERE, room, 2)),
678
+ ];
679
+ }
680
+ function sendToKeys(card, sendTo) {
681
+ if (!asksAgain(sendTo))
682
+ return [];
683
+ return [
684
+ ...(sendTo.to && card.actions.includes('delegate') ? ['y yes, this time'] : []),
685
+ ...(card.actions.includes('answer') ? ['n no'] : []),
686
+ ];
687
+ }
594
688
  function answerWords(question, answer) {
595
689
  if (answer.text)
596
690
  return answer.text;
@@ -657,7 +751,10 @@ export function keysLine(state, now) {
657
751
  if (card) {
658
752
  const busy = state.sent?.cardId === card.id && now < state.sent.until;
659
753
  if (!card.highStakes && !busy) {
660
- if (answersHere(card))
754
+ const sendTo = sendToOf(card);
755
+ if (sendTo)
756
+ keys.push(...sendToKeys(card, sendTo));
757
+ else if (answersHere(card))
661
758
  keys.push(...answerKeys(card, state));
662
759
  if (card.actions.includes('reply'))
663
760
  keys.push('r reply');
@@ -680,6 +777,8 @@ export function sentLine(state, now) {
680
777
  switch (sent.what) {
681
778
  case 'answer':
682
779
  return `Sent: ${sent.words} · ${undo}`;
780
+ case 'not_sent':
781
+ return `Not sent to ${sent.words} · ${undo}`;
683
782
  case 'later':
684
783
  return `In Later: ${sent.words.toLowerCase()} · ${undo}`;
685
784
  case 'delegate':
@@ -160,6 +160,9 @@ async function originHere(io, fallback) {
160
160
  const line = (mark, text) => `${mark} ${text}\n`;
161
161
  const showsHere = (stored) => stored.scopes.includes('assistants:show');
162
162
  const signInAgainForShow = (origin) => `Sign Herdr in again to use Show in Herdr: npx pendingyou app login herdr${originArgs(origin)}`;
163
+ const holdsHere = (stored) => stored.scopes.includes('presence:focus');
164
+ const signInAgainForHold = (origin) => `Sign Herdr in again to hold cards while you’re in an agent’s pane: npx pendingyou app login herdr${originArgs(origin)}`;
165
+ export const HOLDING_LINE = 'Holding cards: a card the agent in the pane you’re in also asks you there waits in Pending You until you leave the pane, go 5 minutes without a sign of you in Herdr, or 30 minutes pass (Settings › Notifications › In Herdr).';
163
166
  async function startWatcher(io, place) {
164
167
  if (!place.socket)
165
168
  return;
@@ -222,9 +225,12 @@ async function signInStep(io, options, ask) {
222
225
  const stored = await readAppSignIn(io, 'herdr').catch(() => null);
223
226
  if (stored) {
224
227
  io.out(`${line('✓', `Herdr is signed in to Pending You at ${stored.origin}: its popup (prefix+y) answers your cards with a key.`)} npx pendingyou app status herdr says what it may do and for how long.\n\n`);
225
- if (showsHere(stored))
228
+ if (showsHere(stored) && holdsHere(stored))
226
229
  return;
227
- io.out(line('!', signInAgainForShow(stored.origin)));
230
+ if (!showsHere(stored))
231
+ io.out(line('!', signInAgainForShow(stored.origin)));
232
+ if (!holdsHere(stored))
233
+ io.out(line('!', signInAgainForHold(stored.origin)));
228
234
  if (options.yes || !io.interactive || !(await ask('Sign Herdr in again now?'))) {
229
235
  io.out('\n');
230
236
  return;
@@ -299,6 +305,8 @@ async function doctor(io, place, options) {
299
305
  io.out(showsHere(stored)
300
306
  ? line('✓', 'Show in Herdr: press it on a card in Pending You, and Herdr goes to the pane of the agent that asked.')
301
307
  : line('!', signInAgainForShow(stored.origin)));
308
+ if (stored && status.ok)
309
+ io.out(holdsHere(stored) ? line('✓', HOLDING_LINE) : line('!', signInAgainForHold(stored.origin)));
302
310
  }
303
311
  else
304
312
  io.out(line('·', 'Herdr isn’t signed in to Pending You: its popup lists what’s waiting. Setup signs it in.'));
@@ -0,0 +1,157 @@
1
+ import { readdir, rm } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { APP_IDS } from "../apps/ids.js";
4
+ import { configDir, readJson, readText, writeWhole } from "../files.js";
5
+ import { herdrBin, herdrPane, herdrServer, isUrgency, reportArgs, runHerdr, } from "../herdr.js";
6
+ export const IDLE_MS = 5 * 60_000;
7
+ export const EVERY_MS = 30_000;
8
+ export const GAP_MS = 2000;
9
+ export const REFUSED_MS = 10 * 60_000;
10
+ export const HELD_FRESH_MS = 2 * 60_000;
11
+ const herdrDir = (io) => join(configDir(io), 'herdr');
12
+ const heldPath = (io) => join(herdrDir(io), 'held.json');
13
+ const messagesDir = (io) => join(herdrDir(io), 'messages');
14
+ const panesDir = (io) => join(herdrDir(io), 'panes');
15
+ const paneFile = (server, pane) => `${server ?? 'local'}-${pane.replace(/[^A-Za-z0-9]/g, '_')}`;
16
+ export async function readHeld(io, now) {
17
+ const held = await readJson(heldPath(io)).catch(() => null);
18
+ if (!held || typeof held.at !== 'number' || now - held.at > HELD_FRESH_MS)
19
+ return new Set();
20
+ const ids = Array.isArray(held.ids) ? held.ids : [];
21
+ return new Set(ids.filter((id) => typeof id === 'string' && /^req_[A-Za-z0-9-]{1,40}$/.test(id)));
22
+ }
23
+ export async function writeHeld(io, ids, now) {
24
+ await writeWhole(heldPath(io), `${JSON.stringify({ version: 1, at: now, ids: [...ids] })}\n`, {
25
+ secret: true,
26
+ }).catch(() => { });
27
+ }
28
+ export const notHeld = (cards, held) => cards.filter((card) => !held.has(card.requestId));
29
+ export async function noteMessage(io) {
30
+ const pane = herdrPane(io.env);
31
+ if (!pane)
32
+ return;
33
+ const server = herdrServer(io.env, io.host);
34
+ await writeWhole(join(messagesDir(io), paneFile(server, pane.pane)), `${Math.floor(io.now())}\n`, { secret: true }).catch(() => { });
35
+ }
36
+ export async function lastMessage(io, server, pane) {
37
+ const text = await readText(join(messagesDir(io), paneFile(server, pane))).catch(() => null);
38
+ const at = Number(text?.trim());
39
+ return text && Number.isFinite(at) && at > 0 ? at : null;
40
+ }
41
+ export async function savePane(io, pane, report) {
42
+ if (report.cards === undefined)
43
+ return;
44
+ const saved = {
45
+ version: 1,
46
+ pane,
47
+ app: report.app,
48
+ ...(report.agent !== undefined ? { agent: report.agent } : {}),
49
+ cards: report.cards.map((card) => ({
50
+ requestId: card.requestId,
51
+ ...(card.title ? { title: card.title.slice(0, 200) } : {}),
52
+ ...(card.urgency ? { urgency: card.urgency } : {}),
53
+ ...(card.blocking ? { blocking: true } : {}),
54
+ ...(card.askedFirst ? { askedFirst: true } : {}),
55
+ at: card.at,
56
+ })),
57
+ };
58
+ await writeWhole(join(panesDir(io), paneFile(herdrServer(io.env, io.host), pane)), `${JSON.stringify(saved)}\n`, { secret: true }).catch(() => { });
59
+ }
60
+ export async function forgetPane(io, pane) {
61
+ await rm(join(panesDir(io), paneFile(herdrServer(io.env, io.host), pane)), {
62
+ force: true,
63
+ }).catch(() => { });
64
+ }
65
+ async function savedPanes(io, server) {
66
+ const prefix = `${server ?? 'local'}-`;
67
+ const names = await readdir(panesDir(io)).catch(() => []);
68
+ const panes = [];
69
+ for (const name of names.filter((each) => each.startsWith(prefix))) {
70
+ const saved = await readJson(join(panesDir(io), name)).catch(() => null);
71
+ if (!saved ||
72
+ typeof saved.pane !== 'string' ||
73
+ !APP_IDS.includes(String(saved.app)) ||
74
+ !Array.isArray(saved.cards))
75
+ continue;
76
+ panes.push({
77
+ version: 1,
78
+ pane: saved.pane,
79
+ app: saved.app,
80
+ ...(saved.agent !== undefined ? { agent: saved.agent } : {}),
81
+ cards: saved.cards.flatMap((card) => typeof card?.requestId === 'string'
82
+ ? [
83
+ {
84
+ requestId: card.requestId,
85
+ ...(typeof card.title === 'string' ? { title: card.title } : {}),
86
+ ...(isUrgency(card.urgency) ? { urgency: card.urgency } : {}),
87
+ ...(card.blocking === true ? { blocking: true } : {}),
88
+ ...(card.askedFirst === true ? { askedFirst: true } : {}),
89
+ at: typeof card.at === 'number' ? card.at : 0,
90
+ },
91
+ ]
92
+ : []),
93
+ });
94
+ }
95
+ return panes;
96
+ }
97
+ export async function applyHeld(io, server, before, after, now) {
98
+ await writeHeld(io, [...after], now);
99
+ const bin = herdrBin(io.env);
100
+ if (!bin)
101
+ return 0;
102
+ const changed = (id) => before.has(id) !== after.has(id);
103
+ let written = 0;
104
+ for (const saved of await savedPanes(io, server).catch(() => [])) {
105
+ if (!saved.cards.some((card) => changed(card.requestId)))
106
+ continue;
107
+ await runHerdr(io, { bin, pane: saved.pane }, reportArgs(saved.pane, {
108
+ app: saved.app,
109
+ ...(saved.agent !== undefined ? { agent: saved.agent } : {}),
110
+ cards: notHeld(saved.cards, after),
111
+ at: now,
112
+ }));
113
+ written++;
114
+ }
115
+ return written;
116
+ }
117
+ export const freshFocus = () => ({
118
+ sentAt: Number.NEGATIVE_INFINITY,
119
+ place: null,
120
+ active: false,
121
+ held: [],
122
+ every: EVERY_MS,
123
+ quietUntil: 0,
124
+ });
125
+ const placeKey = (spot) => (spot ? `${spot.server} ${spot.paneId}` : null);
126
+ export function focusDue(state, look) {
127
+ const { now } = look;
128
+ if (now < state.quietUntil || now - state.sentAt < GAP_MS)
129
+ return false;
130
+ if (state.sentAt === Number.NEGATIVE_INFINITY)
131
+ return true;
132
+ const active = look.activeAt !== null && now - look.activeAt < IDLE_MS;
133
+ if (placeKey(look.spot) !== state.place || look.nudge)
134
+ return true;
135
+ if ((active || state.held.length > 0) && now - state.sentAt >= state.every)
136
+ return true;
137
+ return state.active && !active;
138
+ }
139
+ export function focusSent(state, look, answer) {
140
+ return {
141
+ ...state,
142
+ sentAt: look.now,
143
+ place: placeKey(look.spot),
144
+ active: look.activeAt !== null && look.now - look.activeAt < IDLE_MS,
145
+ held: [...answer.held],
146
+ every: typeof answer.everySeconds === 'number' && answer.everySeconds >= 5
147
+ ? answer.everySeconds * 1000
148
+ : EVERY_MS,
149
+ quietUntil: 0,
150
+ };
151
+ }
152
+ export const focusRefused = (state, now) => ({
153
+ ...state,
154
+ sentAt: now,
155
+ held: [],
156
+ quietUntil: now + REFUSED_MS,
157
+ });
@@ -344,20 +344,22 @@ export async function queuePopup(io, place, options) {
344
344
  return false;
345
345
  }
346
346
  }
347
- case 'answer':
347
+ case 'answer': {
348
+ const what = effect.answer.notSent ? 'not_sent' : 'answer';
348
349
  if (!client) {
349
- state = sentState(state, { cardId: effect.card.id, what: 'answer', words: effect.words }, now);
350
+ state = sentState(state, { cardId: effect.card.id, what, words: effect.words }, now);
350
351
  return false;
351
352
  }
352
353
  try {
353
354
  const done = await client.cards.answer(effect.card.id, effect.answer);
354
- state = sentState(state, { cardId: effect.card.id, what: 'answer', words: effect.words, until: done.undoUntil }, io.now());
355
+ state = sentState(state, { cardId: effect.card.id, what, words: effect.words, until: done.undoUntil }, io.now());
355
356
  }
356
357
  catch (error) {
357
358
  fail(error);
358
359
  stale = true;
359
360
  }
360
361
  return false;
362
+ }
361
363
  case 'undo': {
362
364
  if (!client) {
363
365
  state = { ...state, sent: null, note: 'Undone: it’s waiting on you again.' };
@@ -365,7 +367,7 @@ export async function queuePopup(io, place, options) {
365
367
  }
366
368
  try {
367
369
  const { cardId, what } = effect.sent;
368
- if (what === 'answer')
370
+ if (what === 'answer' || what === 'not_sent')
369
371
  await client.cards.undo(cardId);
370
372
  else if (what === 'later')
371
373
  await client.cards.back(cardId);
@@ -412,7 +414,7 @@ export async function queuePopup(io, place, options) {
412
414
  return false;
413
415
  }
414
416
  case 'delegate': {
415
- const name = effect.target.label.replace(/ \(.*\)$/, '');
417
+ const name = effect.target.name ?? effect.target.label.replace(/ \(.*\)$/, '');
416
418
  if (!client) {
417
419
  state = sentState(state, { cardId: effect.card.id, what: 'delegate', words: name }, now);
418
420
  return false;
@@ -2,10 +2,11 @@ import { randomBytes } from 'node:crypto';
2
2
  import { mkdir, readFile, rm, stat, utimes, writeFile } from 'node:fs/promises';
3
3
  import { join } from 'node:path';
4
4
  import { appClient, RENEW_WITHIN_MS, readAppSignIn } from "../app-login.js";
5
- import { herdrServer } from "../herdr.js";
5
+ import { herdrServer, TOKENS } from "../herdr.js";
6
6
  import { atLeast } from "../mod.js";
7
- import { SignedOutError } from "../sdk/index.js";
7
+ import { ApiError, SignedOutError } from "../sdk/index.js";
8
8
  import { VERSION } from "../version.js";
9
+ import { applyHeld, focusDue, focusRefused, focusSent, freshFocus, lastMessage, } from "./focus.js";
9
10
  import { due, emptyNotices, look } from "./notice.js";
10
11
  import { readWaiting } from "./panes.js";
11
12
  import { agentView, pluginOff, viewOn } from "./plugin.js";
@@ -121,7 +122,13 @@ export async function watchStep(io, socket, state, options) {
121
122
  let next = state;
122
123
  if (options.read) {
123
124
  const { snapshot, waiting } = await readWaiting(socket);
124
- last = { waiting, viewing: snapshot.focusedTab };
125
+ const focused = snapshot.panes.find((pane) => pane.paneId === snapshot.focusedPane);
126
+ last = {
127
+ waiting,
128
+ viewing: snapshot.focusedTab,
129
+ focusedPane: snapshot.focusedPane,
130
+ focusedCards: focused?.tokens[TOKENS.cards] ?? '',
131
+ };
125
132
  next = look(next, last.waiting, io.now());
126
133
  }
127
134
  const decided = due(next, last.waiting, io.now(), last.viewing);
@@ -129,6 +136,7 @@ export async function watchStep(io, socket, state, options) {
129
136
  const toast = decided.toast ? await showToast(socket, decided.toast) : null;
130
137
  return { state: next, last, toast };
131
138
  }
139
+ export const nothingSeen = () => ({ waiting: [], viewing: null });
132
140
  const FOCUS_EVENTS = new Set([
133
141
  'pane.focused',
134
142
  'tab.focused',
@@ -161,6 +169,18 @@ export function signInKeeper(io, socket, place) {
161
169
  const server = herdrServer(io.env, io.host);
162
170
  let following = null;
163
171
  let refused = null;
172
+ let focusing = false;
173
+ let focus = freshFocus();
174
+ let held = new Set();
175
+ let cardsSeen = null;
176
+ const unhold = async () => {
177
+ if (!held.size)
178
+ return;
179
+ const before = held;
180
+ held = new Set();
181
+ focus = freshFocus();
182
+ await applyHeld(io, server, before, held, io.now()).catch(() => 0);
183
+ };
164
184
  const stopShows = () => {
165
185
  following?.stop.abort();
166
186
  following = null;
@@ -170,6 +190,7 @@ export function signInKeeper(io, socket, place) {
170
190
  return;
171
191
  client = null;
172
192
  stopShows();
193
+ await unhold();
173
194
  if (endedSignIn !== which) {
174
195
  endedSignIn = which;
175
196
  await showToast(socket, SIGNED_OUT_TOAST);
@@ -207,6 +228,7 @@ export function signInKeeper(io, socket, place) {
207
228
  client = null;
208
229
  current = signIn;
209
230
  stopShows();
231
+ await unhold();
210
232
  return;
211
233
  }
212
234
  if (signIn !== current || !client) {
@@ -216,20 +238,55 @@ export function signInKeeper(io, socket, place) {
216
238
  }
217
239
  presence = stored.scopes.includes('presence:desk');
218
240
  shows = stored.scopes.includes('assistants:show');
241
+ focusing = stored.scopes.includes('presence:focus');
242
+ if (!focusing)
243
+ await unhold();
219
244
  if (shows)
220
245
  followShows();
221
246
  else
222
247
  stopShows();
223
248
  },
224
- stop() {
249
+ async stop() {
225
250
  stopShows();
251
+ await unhold();
226
252
  },
227
- async tick() {
253
+ async tick(seen = nothingSeen()) {
228
254
  if (!client)
229
255
  return;
230
256
  const now = io.now();
257
+ const popup = await lastActive(place);
258
+ if (focusing && server) {
259
+ const pane = seen.focusedPane ?? null;
260
+ const said = pane ? await lastMessage(io, server, pane) : null;
261
+ const latest = Math.max(focusAt ?? -1, popup ?? -1, said ?? -1);
262
+ const spot = pane ? { server, paneId: pane } : null;
263
+ const cards = seen.focusedCards ?? '';
264
+ const nudge = cardsSeen !== null && cards !== '' && cards !== cardsSeen;
265
+ cardsSeen = cards;
266
+ const look = { now, spot, activeAt: latest >= 0 ? latest : null, nudge };
267
+ if (focusDue(focus, look))
268
+ try {
269
+ const answer = await client.focus({
270
+ place: spot ? { app: 'herdr', paneId: spot.paneId, server: spot.server } : null,
271
+ activeAt: new Date(Math.max(0, latest)).toISOString(),
272
+ });
273
+ focus = focusSent(focus, look, answer);
274
+ const before = held;
275
+ held = new Set(answer.held);
276
+ await applyHeld(io, server, before, held, now);
277
+ }
278
+ catch (error) {
279
+ if (error instanceof SignedOutError)
280
+ return ended();
281
+ if (error instanceof ApiError && error.status >= 400 && error.status < 500) {
282
+ focus = focusRefused(focus, now);
283
+ await unhold();
284
+ }
285
+ else
286
+ focus = { ...focus, sentAt: now };
287
+ }
288
+ }
231
289
  if (presence) {
232
- const popup = await lastActive(place);
233
290
  const activeAt = Math.max(focusAt ?? -1, popup ?? -1);
234
291
  const step = deskStep(desk, activeAt >= 0 ? activeAt : null, now);
235
292
  if (step.send !== null)
@@ -274,7 +331,7 @@ export async function watch(io, place, options) {
274
331
  return 0;
275
332
  const socket = place.socket;
276
333
  let state = emptyNotices();
277
- let last = { waiting: [], viewing: null };
334
+ let last = nothingSeen();
278
335
  const signIn = signInKeeper(io, socket, place);
279
336
  try {
280
337
  while (!io.signal.aborted) {
@@ -305,7 +362,7 @@ export async function watch(io, place, options) {
305
362
  catch {
306
363
  live.changed = true;
307
364
  }
308
- await signIn.tick().catch(() => { });
365
+ await signIn.tick(last).catch(() => { });
309
366
  if (io.now() - checked >= RENEW_MS) {
310
367
  checked = io.now();
311
368
  await signIn.renew();
@@ -329,7 +386,7 @@ export async function watch(io, place, options) {
329
386
  return 0;
330
387
  }
331
388
  finally {
332
- signIn.stop();
389
+ await signIn.stop().catch(() => { });
333
390
  if ((await holder(place))?.id === lease)
334
391
  await rm(leasePath(place), { force: true }).catch(() => { });
335
392
  }
package/dist/herdr.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { isAbsolute, join } from 'node:path';
3
3
  import { configDir, readJson, writeWhole } from "./files.js";
4
+ import { forgetPane, notHeld, readHeld, savePane } from "./herdr/focus.js";
4
5
  import { cut, redactText } from "./redact.js";
5
6
  export const HERDR_SOURCE = 'pendingyou';
6
7
  export const HERDR_TIMEOUT_MS = 1000;
@@ -186,12 +187,17 @@ export async function writeHerdr(io, report, pane) {
186
187
  const target = pane === undefined ? await herdrTarget(io) : pane;
187
188
  if (!target)
188
189
  return 'off';
189
- return runHerdr(io, target, reportArgs(target.pane, report));
190
+ if (report.cards === undefined)
191
+ return runHerdr(io, target, reportArgs(target.pane, report));
192
+ await savePane(io, target.pane, report);
193
+ const held = await readHeld(io, io.now()).catch(() => new Set());
194
+ return runHerdr(io, target, reportArgs(target.pane, { ...report, cards: notHeld(report.cards, held) }));
190
195
  }
191
196
  export async function clearHerdr(io, at, pane) {
192
197
  const target = pane === undefined ? await herdrTarget(io) : pane;
193
198
  if (!target)
194
199
  return 'off';
200
+ await forgetPane(io, target.pane);
195
201
  return runHerdr(io, target, clearArgs(target.pane, at));
196
202
  }
197
203
  export function reportCommand(app, fields) {
package/dist/pickup.js CHANGED
@@ -7,6 +7,7 @@ import { environmentWarning } from "./environment.js";
7
7
  import { configDir, readJson } from "./files.js";
8
8
  import { clip, delegatedOf, describe, HANDED_PREFIX, isHandedWake, } from "./format.js";
9
9
  import { goesBy, HANDED_GRACE_MS, namesAnotherComputer } from "./handed.js";
10
+ import { noteMessage } from "./herdr/focus.js";
10
11
  import { herdrTarget, reportCommand } from "./herdr.js";
11
12
  import { holdCommand } from "./hold.js";
12
13
  import { linkSoon } from "./link.js";
@@ -177,6 +178,8 @@ export async function pickup(io, options, hook = { fallback: '' }) {
177
178
  try {
178
179
  const input = await hookInput(io);
179
180
  const { cwd } = input;
181
+ if (mode === 'handoff' && (await herdrTarget(io)))
182
+ await noteMessage(io);
180
183
  await linkSoon(io, origin);
181
184
  if (mode === 'handoff' && isPromptApp(app))
182
185
  await settlePrompts(io, { session: input.session, event: 'prompt' });
@@ -215,6 +215,7 @@ export function createClient(options) {
215
215
  presence: async (here) => {
216
216
  await request('POST', '/v1/presence', { body: { here } });
217
217
  },
218
+ focus: (report) => request('POST', '/v1/focus', { body: report }),
218
219
  changesPage: (query, opts) => request('GET', '/v1/changes', {
219
220
  ...opts,
220
221
  ...(query ? { query: query } : {}),
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.39.0';
1
+ export const VERSION = '0.41.0';
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pendingyou-wake",
3
3
  "displayName": "Pending You",
4
- "version": "2.56.0",
4
+ "version": "2.60.0",
5
5
  "description": "Wakes Claude Code when your person answers a Pending You card it posted, even while it sits idle. Installed by `npx pendingyou init`.",
6
6
  "author": {
7
7
  "name": "RecordPlane",
package/mod/README.md CHANGED
@@ -4,4 +4,4 @@ The pendingyou command line’s copy of the Pending You plugin’s wake mod, for
4
4
 
5
5
  In each session it learns the cards the session posts to Pending You, checks them through the session’s own Pending You connection, and starts a turn when your person answers, writes back or a fallback comes due, or hands the session a question from another of their assistants (CLI 0.14.0), even while it sits idle. It answers `npx pendingyou hold` itself, so nothing waits in the background, and shows “2 waiting on you” under the prompt, after the plugin’s name. With the Pending You plugin installed too, only one copy acts.
6
6
 
7
- Generated from recordplane/pendingyou (packages/claude-plugin/src/wake) with Pending You’s guide 2.56.0; send changes there.
7
+ Generated from recordplane/pendingyou (packages/claude-plugin/src/wake) with Pending You’s guide 2.60.0; send changes there.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pendingyou",
3
- "version": "0.39.0",
3
+ "version": "0.41.0",
4
4
  "description": "Pending You for your coding agents: one command sets up Claude Code, Codex, OpenCode and Pi to ask you through Pending You and hear your answers, even while they sit idle.",
5
5
  "keywords": [
6
6
  "pendingyou",