pendingyou 0.40.0 → 0.42.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,36 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.42.0 (2026-11-16)
4
+
5
+ - Fixed: a Codex thread that had only said its name to Pending You (`whoami`, then read its queue) was never woken for a
6
+ question you handed it from another assistant. Only a card call made a thread known on your computer, so the question
7
+ waited for the next session start or message in its folder. Now a thread that calls `whoami`, `list_pending` or
8
+ `get_request` with its name is known by that name and folder, as one that posted a card is, and a question handed to
9
+ it is queued into it for the next 12 hours. Such a call is never a card: the check at the end of the turn doesn't count
10
+ it as one posted, and it makes no card the thread's own.
11
+ - Codex: it comes from a new hook, PostToolUse on those three tools, added last so every hook you trusted stays trusted.
12
+ Codex skips it until you trust it in `/hooks`: `npx pendingyou@latest init` adds it, says "Codex has new Pending You
13
+ hooks (questions handed to a thread)" and waits for you there, and `status` has a "Handed questions" line saying how
14
+ it stands. The card hook is unchanged, so answers to a thread's own cards wake it as before meanwhile.
15
+ - OpenCode and Pi had the same gap: the plugin and the extension now hand those three calls to the command line too,
16
+ when they carry a name. Run `npx pendingyou@latest init` there, then restart OpenCode or `/reload` Pi.
17
+ - Claude Code never had it: its wake mod learns the session's name from any Pending You call, `whoami` included.
18
+
19
+ ## 0.41.0 (2026-11-03)
20
+
21
+ - 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
22
+ asks you something there, Pending You keeps its card out of sight while you stay: answer it in the pane and it never
23
+ 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
24
+ card. The watcher tells Pending You which pane you're in and your last sign of you there: moving between panes, tabs
25
+ and workspaces, keys in the popup, and each message you send the agent in that pane (its app's next-message hook
26
+ notes the moment, never the words). Herdr can't tell anyone about keys typed in a pane, so those don't count.
27
+ - A held card stays off the pane's badges, so off the sidebar's row, the popup, `next` and the toasts, and comes back
28
+ the moment it shows. Each badge write keeps its pane's cards (the titles the badges already carry) in
29
+ `~/.config/pendingyou/herdr/` so the watcher can write them again.
30
+ - It needs Herdr signed in again (`npx pendingyou app login herdr`, or setup's "Sign Herdr in again now?"): a sign-in
31
+ from before doesn't hold the new `presence:focus`. Setup and doctor say so. With a Pending You that doesn't hold cards
32
+ yet, the watcher is told no and asks again 10 minutes later; nothing else changes.
33
+
3
34
  ## 0.40.0 (2026-10-28)
4
35
 
5
36
  - Pending You for Herdr answers "Ask Maple again?": when one of your agents asks to send its card to another of your
package/README.md CHANGED
@@ -103,8 +103,10 @@ call that ran (a card when Codex waits for your OK, [below](#when-claude-code-wa
103
103
  `status` finds Pending You's hooks not trusted yet, it prints the one command that opens a Codex here (`codex`, or
104
104
  the one the ChatGPT app brings, by its full path) and says to type `/hooks` there and trust them; at a terminal it
105
105
  then waits (every 3 seconds, for up to 10 minutes; Ctrl-C stops it) until Codex trusts them, and says whether Codex is
106
- ready. It never trusts them for you. `status` says which are trusted. Upgrading from 0.14.0 adds three hooks, which Codex
107
- skips until you trust them once; `init` says so, and the ones you trusted stay trusted. A `pendingyou` server or
106
+ ready. It never trusts them for you. `status` says which are trusted. Upgrading from 0.14.0 adds three hooks, and
107
+ from 0.41.0 or earlier one more (0.42.0: whoami, list_pending and get_request, so a question you hand a thread that only
108
+ said its name wakes it), which Codex skips until you trust them once; `init` says so, and the ones you trusted stay
109
+ trusted. A `pendingyou` server or
108
110
  hooks Codex's `/import` copied from Claude Code (without its sign-in) are replaced.
109
111
 
110
112
  **The Codex app** (on a Mac, in the ChatGPT app) shares all of this with Codex CLI: the same `~/.codex`, server, hooks
@@ -427,6 +429,18 @@ Claude Code). Otherwise Pending You hears "not found", and nothing moves. It onl
427
429
  never types into one, runs or opens anything, and logs nothing. Setup starts this version's watcher in place of one
428
430
  from an older pendingyou, which doesn't listen.
429
431
 
432
+ ### Holding cards while you're in the agent's pane (0.41.0)
433
+
434
+ When the agent in the Herdr pane you're in also asks you something there, Pending You keeps its card out of sight while
435
+ 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
436
+ 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
437
+ there once Herdr's sign-in allows it (`presence:focus`, which only Pending You's own apps may hold; a sign-in from before
438
+ 0.41.0 doesn't hold it, and setup and doctor say to sign in again). The signs are moving between panes, tabs and
439
+ workspaces, keys in the popup, and each message you send the agent in that pane: its app's next-message hook notes the
440
+ moment in `~/.config/pendingyou/herdr/messages/`, never the words. A held card stays off the pane's badges (the sidebar's
441
+ row, the popup, `next`, the toasts) and comes back the moment it shows. Turn it off in Pending You: Settings ›
442
+ Notifications › In Herdr.
443
+
430
444
  ## How Claude Code hears your answer
431
445
 
432
446
  **Claude Code 2.1.287 or later: the wake mod.** There's nothing to run. In each session the mod learns the cards
@@ -495,9 +509,12 @@ answers, once the 5-second window to undo is over:
495
509
  know; if not, hand_back with what you checked.” Among sessions by one name, the one working in the task's folder
496
510
  takes it (as `list_pending` gives it, `~/…` or a full path), one in another folder never does, and one that can't
497
511
  tell its folder waits half a minute (5 minutes before 0.35.0).
498
- - **Codex**: one listener for the app queues it into the thread it's for (`codex queue`, the same words).
512
+ - **Codex**: one listener for the app queues it into the thread it's for (`codex queue`, the same words), for 12 hours
513
+ after the thread last used Pending You's card tools or (0.42.0) said its name with `whoami`, `list_pending` or
514
+ `get_request`. That last needs a hook of its own (PostToolUse on those three), which Codex runs once you trust it in
515
+ `/hooks`: `npx pendingyou@latest init` adds it and says so, and `status`'s "Handed questions" line says how it stands.
499
516
  - **OpenCode and Pi**: the session's listener starts the turn through the plugin or extension; a session that used
500
- Pending You's card tools keeps listening for 12 hours, while the app is open.
517
+ Pending You's card tools or (0.42.0) said its name keeps listening for 12 hours, while the app is open.
501
518
  - **Otherwise**: a session start or your next message in that folder brings it, with your note: at once in the
502
519
  session that goes by the task's name, after 5 minutes in any other.
503
520
 
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) {
@@ -34,10 +34,20 @@ const CARD_TOOLS = {
34
34
  pi: MCP_CARD_TOOL,
35
35
  };
36
36
  const HELPER_CALLS = new Set(['answer_delegated', 'hand_back']);
37
+ const MCP_NAMED_TOOL = /^mcp__([A-Za-z0-9_]*pendingyou[A-Za-z0-9_]*)__(whoami|list_pending|get_request)$/i;
38
+ const NAMED_TOOLS = {
39
+ codex: MCP_NAMED_TOOL,
40
+ opencode: /^([A-Za-z0-9_-]*pendingyou[A-Za-z0-9_-]*)_(whoami|list_pending|get_request)$/i,
41
+ pi: MCP_NAMED_TOOL,
42
+ };
37
43
  export function cardTool(app, name) {
38
44
  const pattern = CARD_TOOLS[app];
39
45
  return pattern && typeof name === 'string' ? (pattern.exec(name)?.[2] ?? null) : null;
40
46
  }
47
+ export function namedTool(app, name) {
48
+ const pattern = NAMED_TOOLS[app];
49
+ return pattern && typeof name === 'string' ? (pattern.exec(name)?.[2] ?? null) : null;
50
+ }
41
51
  const statePath = (io, app) => join(configDir(io), `${app}-threads.json`);
42
52
  const leasePath = (io, app, thread) => join(configDir(io), `${app}-listen`, `${thread}.lease`);
43
53
  export const threadFiles = (io, app) => [
@@ -151,10 +161,14 @@ export async function posted(io, options) {
151
161
  const input = JSON.parse(await io.readStdin(1000));
152
162
  if (!isObject(input))
153
163
  return 0;
154
- const call = cardTool(app, input.tool_name);
155
164
  const thread = typeof input.session_id === 'string' ? input.session_id : null;
165
+ if (!thread)
166
+ return 0;
167
+ if (namedTool(app, input.tool_name))
168
+ return await named(io, options, input, thread);
169
+ const call = cardTool(app, input.tool_name);
156
170
  const turn = typeof input.turn_id === 'string' ? input.turn_id : null;
157
- if (!call || !thread)
171
+ if (!call)
158
172
  return 0;
159
173
  const args = isObject(input.tool_input) ? input.tool_input : {};
160
174
  const output = resultOf(input.tool_response);
@@ -213,6 +227,34 @@ export async function posted(io, options) {
213
227
  return 0;
214
228
  }
215
229
  }
230
+ async function named(io, options, input, thread) {
231
+ const { app } = options;
232
+ if (!THREAD.test(thread))
233
+ return 0;
234
+ if (isObject(input.tool_response) && input.tool_response.isError === true)
235
+ return 0;
236
+ const name = nameOf(isObject(input.tool_input) ? input.tool_input : {});
237
+ if (!name)
238
+ return 0;
239
+ const cwd = text(input.cwd, 1000);
240
+ const now = io.now();
241
+ const pane = await herdrTarget(io);
242
+ await change(io, app, (state) => {
243
+ const known = withName(state.threads[thread] ?? { origin: options.origin, cards: {}, at: now }, name);
244
+ if (cwd)
245
+ known.cwd = cwd;
246
+ if (pane)
247
+ known.herdr = pane.pane;
248
+ known.origin = options.origin;
249
+ known.at = now;
250
+ state.threads[thread] = known;
251
+ });
252
+ if (pane)
253
+ io.background(reportCommand(app, { session: thread, at: now }));
254
+ if (app === 'codex')
255
+ await keepListening(io, options.origin, thread);
256
+ return 0;
257
+ }
216
258
  function askedIn(args) {
217
259
  let asked = args.askedFirst;
218
260
  if (typeof asked === 'string')
@@ -39,6 +39,7 @@ export function trustSteps(found) {
39
39
  const DONT_SAVE = 'In the Codex app, don’t press Save on pendingyou in Settings › MCP: that writes it again without this computer’s sign-in (if you did, run init again to put it back).';
40
40
  const CARD_TOOLS = '^mcp__pendingyou__(post_request|post_answer|update_request|reply_in_thread|cancel_request)$';
41
41
  const POST_ANSWER = 'mcp__pendingyou__post_answer';
42
+ const NAMED_TOOLS = '^mcp__pendingyou__(whoami|list_pending|get_request)$';
42
43
  export const CODEX_HOOKS = [
43
44
  { event: 'SessionStart', sub: 'pickup', matcher: 'startup|resume|clear' },
44
45
  { event: 'UserPromptSubmit', sub: 'handoff' },
@@ -53,10 +54,14 @@ export const codexPermissionHooks = (wait) => CODEX_PERMISSION_HOOKS.map((spec)
53
54
  export const CODEX_PRESENCE_HOOKS = [
54
55
  { event: 'SessionEnd', sub: 'presence', timeout: 3 },
55
56
  ];
57
+ export const CODEX_NAMED_HOOKS = [
58
+ { event: 'PostToolUse', sub: 'named', matcher: NAMED_TOOLS },
59
+ ];
56
60
  export const ALL_CODEX_HOOKS = [
57
61
  ...CODEX_HOOKS,
58
62
  ...CODEX_PERMISSION_HOOKS,
59
63
  ...CODEX_PRESENCE_HOOKS,
64
+ ...CODEX_NAMED_HOOKS,
60
65
  ];
61
66
  const EVENT_LABELS = {
62
67
  SessionStart: 'session_start',
@@ -283,6 +288,7 @@ function keepTheirTrust(config, file, before) {
283
288
  }
284
289
  return next;
285
290
  }
291
+ const listed = (words) => words.length > 1 ? `${words.slice(0, -1).join(', ')} and ${words.at(-1)}` : (words[0] ?? '');
286
292
  export function answerWaitWords(wait) {
287
293
  return wait > 0
288
294
  ? `Ask on your phone first: Codex’s permission prompts wait up to ${minutes(wait)} for Allow or Deny on their Pending You card, then Codex asks in its terminal (npx pendingyou codex-answers --wait 0 turns it off).`
@@ -487,6 +493,7 @@ export const codex = {
487
493
  ...CODEX_HOOKS,
488
494
  ...(extra && cards ? codexPermissionHooks(wait) : []),
489
495
  ...(extra ? CODEX_PRESENCE_HOOKS : []),
496
+ ...CODEX_NAMED_HOOKS,
490
497
  ];
491
498
  const wantedKeys = new Set(wanted.map(lineKey));
492
499
  const unwanted = ALL_CODEX_HOOKS.filter((spec) => !wantedKeys.has(lineKey(spec)));
@@ -505,16 +512,19 @@ export const codex = {
505
512
  await writeWhole(file.path, `${JSON.stringify({ ...file.json, hooks: removed.hooks }, null, 2)}\n`);
506
513
  const fresh = wanted.filter((spec) => !CODEX_HOOKS.includes(spec) && !(lineKey(spec) in (before?.hooks ?? {})));
507
514
  if (before && merged.changed && fresh.length)
508
- newHooks = [
515
+ newHooks = listed([
509
516
  ...(fresh.some((spec) => spec.sub === 'presence') ? ['session end'] : []),
510
517
  ...(fresh.some((spec) => spec.sub.startsWith('permission'))
511
518
  ? ['permission prompts']
512
519
  : []),
513
- ].join(' and ');
520
+ ...(fresh.some((spec) => spec.sub === 'named')
521
+ ? ['questions handed to a thread']
522
+ : []),
523
+ ]);
514
524
  report({
515
525
  ok: true,
516
526
  text: merged.changed
517
- ? `Installed or updated Codex’s session-start pickup, next-message hand-off, card and Stop check hooks${extra ? `, ${cards ? 'its permission-prompt hooks (a card when Codex waits for your OK; --no-permission-cards leaves them out) ' : ''}and its session-end hook (Pending You hears when a thread is open)` : ''} in ${file.path}. Codex runs them once you trust them (how: below).`
527
+ ? `Installed or updated Codex’s session-start pickup, next-message hand-off, card, name and Stop check hooks${extra ? `, ${cards ? 'its permission-prompt hooks (a card when Codex waits for your OK; --no-permission-cards leaves them out) ' : ''}and its session-end hook (Pending You hears when a thread is open)` : ''} in ${file.path}. Codex runs them once you trust them (how: below).`
518
528
  : removed.changed
519
529
  ? `Took out Codex’s permission-prompt hooks, as you asked: no card when Codex waits for your OK. To turn them on: npx pendingyou init --app codex --permission-cards${originArgs(ictx.origin)}`
520
530
  : 'Codex’s hooks were already installed.',
@@ -706,6 +716,7 @@ export const codex = {
706
716
  : 'off: Codex asks in its terminal at once (npx pendingyou codex-answers --wait 2 sends its prompts to your card first, for up to 2 minutes)'}`
707
717
  : null;
708
718
  const presenceText = extraLine('Presence:', 'tells Pending You when this session is open', CODEX_PRESENCE_HOOKS.map((spec) => spec.sub), ownConnection ? null : notOwn);
719
+ const namedText = extraLine('Handed questions:', 'a question you hand a thread that said its name to Pending You wakes it', CODEX_NAMED_HOOKS.map((spec) => spec.sub), null);
709
720
  const wakes = detected
710
721
  ? atLeast(detected.version, detected.command ? CODEX_APP_WAKE : CODEX_WAKE)
711
722
  : false;
@@ -726,6 +737,7 @@ export const codex = {
726
737
  permissionText,
727
738
  ...(askFirst ? [askFirst] : []),
728
739
  presenceText,
740
+ namedText,
729
741
  ` ${mark(wakes)} Wake: ${wakes
730
742
  ? detected?.command
731
743
  ? 'codex queue wakes a chat the Codex app has open when you answer, while the app runs (one it let go, idle 3 hours or behind 10 newer idle chats, hears it when you open it again)'
@@ -11,6 +11,7 @@ const HOOK_MS = 5000;
11
11
  const TURN_MESSAGES = 200;
12
12
  const TEXT_CHARS = 100_000;
13
13
  const CARD_TOOL = /^[A-Za-z0-9_-]*pendingyou[A-Za-z0-9_-]*_(post_request|post_answer|update_request|reply_in_thread|cancel_request|answer_delegated|hand_back)$/i;
14
+ const NAMED_TOOL = /^[A-Za-z0-9_-]*pendingyou[A-Za-z0-9_-]*_(whoami|list_pending|get_request)$/i;
14
15
  export const HANDED_FOR_MS = 12 * 60 * 60_000;
15
16
  const NUDGED = 'Asked OpenCode to put what it needs from you on a card.';
16
17
  const isObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
@@ -433,7 +434,10 @@ export async function pendingYou(input, deps) {
433
434
  },
434
435
  async 'tool.execute.after'(input, output) {
435
436
  try {
436
- if (!CARD_TOOL.test(input.tool))
437
+ const named = NAMED_TOOL.test(input.tool);
438
+ if (named && !(isObject(input.args) && typeof input.args.name === 'string'))
439
+ return;
440
+ if (!named && !CARD_TOOL.test(input.tool))
437
441
  return;
438
442
  const session = await known(input.sessionID);
439
443
  const id = session.parent ?? input.sessionID;
@@ -9,6 +9,7 @@ export const READY_FOR_MS = 30_000;
9
9
  const WHOAMI = /^mcp__[A-Za-z0-9_]*pendingyou[A-Za-z0-9_]*__whoami$/i;
10
10
  const STOP_MS = 2000;
11
11
  export const CARD_TOOL = /^mcp__[A-Za-z0-9_]*pendingyou[A-Za-z0-9_]*__(post_request|post_answer|update_request|reply_in_thread|cancel_request|answer_delegated|hand_back)$/i;
12
+ export const NAMED_TOOL = /^mcp__[A-Za-z0-9_]*pendingyou[A-Za-z0-9_]*__(whoami|list_pending|get_request)$/i;
12
13
  export const HANDED_FOR_MS = 12 * 60 * 60_000;
13
14
  export const HANDED_PREFIX = 'Pending You: your person handed you';
14
15
  const HANDED_REPLY = ' on the question handed to you, ';
@@ -336,14 +337,18 @@ export function pendingYou(setup, options = {}) {
336
337
  return said ? { message: { customType: TYPE, content: said, display: false } } : undefined;
337
338
  });
338
339
  pi.on('tool_result', (event) => {
339
- if (event.isError === true || typeof event.toolName !== 'string')
340
+ if (event.isError === true || typeof event.toolName !== 'string' || !session)
340
341
  return;
341
- if (!CARD_TOOL.test(event.toolName) || !session)
342
+ const named = NAMED_TOOL.test(event.toolName);
343
+ if (named && !(isObject(event.input) && typeof event.input.name === 'string'))
342
344
  return;
343
- turn ??= `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
345
+ if (!named && !CARD_TOOL.test(event.toolName))
346
+ return;
347
+ if (!named)
348
+ turn ??= `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
344
349
  const input = {
345
350
  session_id: session,
346
- turn_id: turn,
351
+ ...(named ? {} : { turn_id: turn }),
347
352
  cwd,
348
353
  tool_name: event.toolName,
349
354
  tool_input: clipped(event.input ?? {}),
package/dist/args.js CHANGED
@@ -76,6 +76,7 @@ const COMMANDS = new Set([
76
76
  'refresh',
77
77
  'mcp-headers',
78
78
  'posted',
79
+ 'named',
79
80
  'listen',
80
81
  'mcp',
81
82
  'permission',
@@ -109,6 +110,7 @@ const FLAGS = {
109
110
  handoff: { origin: true, app: true },
110
111
  stopcheck: { origin: true, app: true },
111
112
  posted: { origin: true, app: true },
113
+ named: { origin: true, app: true },
112
114
  listen: { origin: true, app: true, thread: true, handed: false, since: true },
113
115
  permission: { origin: true, app: true },
114
116
  'permission-done': { origin: true, app: true },
@@ -206,6 +208,7 @@ export const HOOK_COMMANDS = new Set([
206
208
  'handoff',
207
209
  'stopcheck',
208
210
  'posted',
211
+ 'named',
209
212
  'permission',
210
213
  'permission-done',
211
214
  'notify',
@@ -356,8 +359,9 @@ export function parseArgs(argv, env = {}) {
356
359
  none();
357
360
  return { name: 'stopcheck', origin, ...app() };
358
361
  case 'posted':
362
+ case 'named':
359
363
  none();
360
- return { name: 'posted', origin, ...app() };
364
+ return { name: first, origin, ...app() };
361
365
  case 'listen': {
362
366
  none();
363
367
  const thread = text('thread');
@@ -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
+ });
@@ -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/main.js CHANGED
@@ -50,6 +50,7 @@ async function run(io, command, hook = { fallback: '' }) {
50
50
  case 'stopcheck':
51
51
  return stopcheck(io, { origin: command.origin, app: command.app ?? DEFAULT_APP });
52
52
  case 'posted':
53
+ case 'named':
53
54
  return posted(io, { origin: command.origin, app: command.app ?? DEFAULT_APP });
54
55
  case 'permission':
55
56
  case 'permission-done':
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.40.0';
1
+ export const VERSION = '0.42.0';
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pendingyou-wake",
3
3
  "displayName": "Pending You",
4
- "version": "2.58.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.58.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.40.0",
3
+ "version": "0.42.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",