pendingyou 0.43.2 → 0.43.3

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.43.3 (2026-11-17)
4
+
5
+ - An assistant in the middle of a long task when you answer is told at its next tool call, once, in one line, instead
6
+ of when the task is done: "Pending You, while you were working: your person answered “Ship the webhook retries
7
+ tonight?” (req_…). Read it now with get_request (name “infra”), and act on it at the next sensible point in this
8
+ task." The same for a message on one of its cards, a reply on one of its answers, and a question you hand it. Never
9
+ your answer's own words: it reads it with `get_request`. The line is a hint, said once a turn: only the assistant's
10
+ own read counts, so one that doesn't read it is woken when its turn ends, as before, the wake ending "You were told
11
+ of this while working and haven’t read it." (Codex: "You may have been told of this while working, and haven’t read
12
+ it.", since nothing says Codex showed the line to the model). An idle assistant is woken as before. With nothing waiting, a tool call costs
13
+ nothing more.
14
+ - Claude Code: the wake mod adds the line after the next tool result of the session's main conversation (never a
15
+ subagent's). Nothing to restart: open sessions reload the mod by themselves.
16
+ - Codex: the hooks keep each thread's turn on disk (begun by your message or its first tool call, kept fresh by each
17
+ tool call, ended by the Stop hook, and over by itself after 5 minutes with no tool call), and while a turn runs the
18
+ listener leaves the wake for the next tool call's PostToolUse, which Codex 0.169 runs for calls made inside its code
19
+ mode too. Whatever it hasn't read when the turn ends is queued at once, from the Stop hook. Where Codex's
20
+ permission-prompt hooks are installed (the default with this computer's own connection), their every-call hook
21
+ carries the line, so nothing needs trusting again and no tool call costs more; elsewhere (`--no-permission-cards`,
22
+ or a sign-in that only hears) `init` adds one hook on every call, a process of its own each time (about a tenth of a
23
+ second), and says "Codex has new Pending You hooks (answers while it works)": trust it once in `/hooks`. `status`
24
+ has a "Mid-task" line. Every wake `codex queue` carries now ends "If you already read it with get_request and acted
25
+ on it, end this turn with no message.", since a queued wake can't be taken back.
26
+ - Pi: unchanged: a wake still waits for the run under way to end.
27
+ - OpenCode already took a wake into the turn under way.
28
+ - Fixed: a question Claude Code held through a turn whose read failed as the turn ended is read again shortly, not
29
+ dropped.
30
+ - Guide 2.61.3 (a wording patch) says that an answer that didn’t work also has `failed` true, and that a to-do answered with `failed` and no step goes back with its fix as one with `failedStep` does; it carries the same mod in the Pending You plugin for Claude.
31
+ - Run `npx pendingyou@latest init`. Restart Codex: its hooks take the new command line at once, but a listener already
32
+ running keeps the old one.
33
+
3
34
  ## 0.43.2 (2026-11-17)
4
35
 
5
36
  - Fixed: a Claude Code session Pending You showed as running didn't hear a question you handed its agent. The wake mod
@@ -0,0 +1,164 @@
1
+ import { readFile, rm, stat, utimes } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { configDir, readJson, withLock, writeWhole } from "../files.js";
4
+ import { isHandedWake } from "../format.js";
5
+ import { midTurnText } from "../midturn.js";
6
+ export const STALE_WAKE = ' If you already read it with get_request and acted on it, end this turn with no message.';
7
+ export const TURN_FOR_MS = 5 * 60_000;
8
+ const THREAD = /^[A-Za-z0-9][A-Za-z0-9_-]{0,99}$/;
9
+ export const UNREAD_NOTE = 'You may have been told of this while working, and haven’t read it.';
10
+ export const unreadWake = (text) => text.includes('\n') ? `${text}\n${UNREAD_NOTE}` : `${text} ${UNREAD_NOTE}`;
11
+ const turnPath = (io, thread) => join(configDir(io), 'codex-turns', `${thread}.json`);
12
+ const heardPath = (io, thread) => join(configDir(io), 'codex-heard', `${thread}.json`);
13
+ const isObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
14
+ async function turnOf(io, thread) {
15
+ try {
16
+ const path = turnPath(io, thread);
17
+ const at = (await stat(path)).mtimeMs;
18
+ const parsed = JSON.parse(await readFile(path, 'utf8'));
19
+ const turn = isObject(parsed) && typeof parsed.turn === 'string' ? parsed.turn : null;
20
+ return { turn, at };
21
+ }
22
+ catch {
23
+ return null;
24
+ }
25
+ }
26
+ export async function turnBegan(io, thread, turn) {
27
+ try {
28
+ if (!THREAD.test(thread))
29
+ return;
30
+ await writeWhole(turnPath(io, thread), `${JSON.stringify({ turn })}\n`, { secret: true });
31
+ }
32
+ catch { }
33
+ }
34
+ export async function turnEnded(io, thread, turn) {
35
+ try {
36
+ if (!THREAD.test(thread))
37
+ return;
38
+ const on = await turnOf(io, thread);
39
+ if (on && turn && on.turn && on.turn !== turn)
40
+ return;
41
+ await rm(turnPath(io, thread), { force: true });
42
+ }
43
+ catch { }
44
+ }
45
+ export async function midTurn(io, thread) {
46
+ if (!THREAD.test(thread))
47
+ return false;
48
+ try {
49
+ return io.now() - (await stat(turnPath(io, thread))).mtimeMs < TURN_FOR_MS;
50
+ }
51
+ catch {
52
+ return false;
53
+ }
54
+ }
55
+ async function readHeard(io, thread) {
56
+ const file = await readJson(heardPath(io, thread)).catch(() => null);
57
+ const items = isObject(file?.items) ? Object.values(file.items) : [];
58
+ return items.filter((each) => isObject(each) &&
59
+ typeof each.requestId === 'string' &&
60
+ typeof each.moment === 'string' &&
61
+ typeof each.wake === 'string' &&
62
+ isObject(each.item));
63
+ }
64
+ async function writeHeard(io, thread, list) {
65
+ const path = heardPath(io, thread);
66
+ if (list.length === 0)
67
+ await rm(path, { force: true });
68
+ else
69
+ await writeWhole(path, `${JSON.stringify({ version: 1, items: Object.fromEntries(list.map((each) => [each.requestId, each])) })}\n`, { secret: true });
70
+ }
71
+ export async function holdHeard(io, thread, list) {
72
+ if (!THREAD.test(thread) || list.length === 0)
73
+ return;
74
+ await withLock(heardPath(io, thread), io, async () => {
75
+ const kept = (await readHeard(io, thread)).filter((each) => !list.some((added) => added.requestId === each.requestId));
76
+ await writeHeard(io, thread, [...kept, ...list]);
77
+ });
78
+ }
79
+ export async function hasHeard(io, thread) {
80
+ if (!THREAD.test(thread))
81
+ return false;
82
+ try {
83
+ await stat(heardPath(io, thread));
84
+ return true;
85
+ }
86
+ catch {
87
+ return false;
88
+ }
89
+ }
90
+ export async function takeHeard(io, thread) {
91
+ if (!(await hasHeard(io, thread)))
92
+ return [];
93
+ return withLock(heardPath(io, thread), io, async () => {
94
+ const list = await readHeard(io, thread);
95
+ await writeHeard(io, thread, []);
96
+ return list.map((each) => (each.told ? unreadWake(each.wake) : each.wake));
97
+ });
98
+ }
99
+ export function queuedWakes(wakes) {
100
+ const own = wakes.filter((wake) => !isHandedWake(wake));
101
+ return [...(own.length ? [own.join('\n\n')] : []), ...wakes.filter(isHandedWake)];
102
+ }
103
+ export async function heardRead(io, thread, requestId) {
104
+ try {
105
+ if (!(await hasHeard(io, thread)))
106
+ return;
107
+ await withLock(heardPath(io, thread), io, async () => {
108
+ const list = await readHeard(io, thread);
109
+ const kept = list.filter((each) => each.requestId !== requestId);
110
+ if (kept.length !== list.length)
111
+ await writeHeard(io, thread, kept);
112
+ });
113
+ }
114
+ catch { }
115
+ }
116
+ export async function tellHeard(io, input) {
117
+ try {
118
+ const thread = typeof input.session_id === 'string' ? input.session_id : '';
119
+ const turn = typeof input.turn_id === 'string' && input.turn_id ? input.turn_id : null;
120
+ if (!THREAD.test(thread))
121
+ return null;
122
+ const now = io.now();
123
+ const on = await turnOf(io, thread);
124
+ const ours = !on || !turn || !on.turn || on.turn === turn;
125
+ if (ours && on) {
126
+ const at = new Date(now);
127
+ await utimes(turnPath(io, thread), at, at);
128
+ }
129
+ else if (!on || now - on.at >= TURN_FOR_MS)
130
+ await turnBegan(io, thread, turn);
131
+ else
132
+ return null;
133
+ if (!(await hasHeard(io, thread)))
134
+ return null;
135
+ const list = await withLock(heardPath(io, thread), io, async () => {
136
+ const all = await readHeard(io, thread);
137
+ const fresh = all.filter((each) => !each.told);
138
+ if (fresh.length)
139
+ await writeHeard(io, thread, all.map((each) => ({ ...each, told: true })));
140
+ return fresh;
141
+ });
142
+ if (list.length === 0)
143
+ return null;
144
+ const text = midTurnText(list.map((each) => each.item));
145
+ return text
146
+ ? `${JSON.stringify({ hookSpecificOutput: { hookEventName: 'PostToolUse', additionalContext: text } })}\n`
147
+ : null;
148
+ }
149
+ catch {
150
+ return null;
151
+ }
152
+ }
153
+ export async function heardHook(io) {
154
+ try {
155
+ const input = JSON.parse(await io.readStdin(1000, 8_000_000));
156
+ if (!isObject(input) || input.hook_event_name !== 'PostToolUse')
157
+ return 0;
158
+ const told = await tellHeard(io, input);
159
+ if (told)
160
+ io.out(told);
161
+ }
162
+ catch { }
163
+ return 0;
164
+ }
@@ -12,6 +12,7 @@ import { linkSoon } from "../link.js";
12
12
  import { macName, tailscaleName } from "../remote.js";
13
13
  import { claimHanded, markHanded, momentOf, releaseHanded, wasHanded } from "../state.js";
14
14
  import { findCodex } from "./codex-app.js";
15
+ import { hasHeard, heardRead, holdHeard, midTurn, queuedWakes, STALE_WAKE, takeHeard, } from "./codex-midturn.js";
15
16
  import { APP_IDS } from "./ids.js";
16
17
  const KEEP_TURN_MS = 24 * 60 * 60_000;
17
18
  const KEEP_THREAD_MS = 7 * 24 * 60 * 60_000;
@@ -239,7 +240,11 @@ async function named(io, options, input, thread) {
239
240
  return 0;
240
241
  if (isObject(input.tool_response) && input.tool_response.isError === true)
241
242
  return 0;
242
- const name = nameOf(isObject(input.tool_input) ? input.tool_input : {});
243
+ const args = isObject(input.tool_input) ? input.tool_input : {};
244
+ if (app === 'codex' && namedTool(app, input.tool_name) === 'get_request')
245
+ if (typeof args.requestId === 'string')
246
+ await heardRead(io, thread, args.requestId);
247
+ const name = nameOf(args);
243
248
  if (!name)
244
249
  return 0;
245
250
  const cwd = text(input.cwd, 1000);
@@ -450,7 +455,7 @@ export async function keepListening(io, origin, thread) {
450
455
  return;
451
456
  const { threads } = await load(io, 'codex');
452
457
  const now = io.now();
453
- const own = Object.keys(threads[thread]?.cards ?? {}).length > 0;
458
+ const own = Object.keys(threads[thread]?.cards ?? {}).length > 0 || (await hasHeard(io, thread));
454
459
  const handed = Object.values(threads).some((each) => mayBeHanded(each, now));
455
460
  if (!own && !handed)
456
461
  return;
@@ -574,10 +579,30 @@ function byCodexQueue(io, thread) {
574
579
  let program = null;
575
580
  return async (message) => {
576
581
  program ??= findCodex(io).then((found) => found?.command ?? 'codex');
577
- const queued = await io.run(await program, ['queue', '--thread', thread, '--message', message], 30_000);
582
+ const queued = await io.run(await program, ['queue', '--thread', thread, '--message', `${message}${STALE_WAKE}`], 30_000);
578
583
  return queued.code === 0;
579
584
  };
580
585
  }
586
+ function midItemOf(heard, card) {
587
+ const kind = noticeOf(heard)
588
+ ? 'word'
589
+ : card.kind === 'answer'
590
+ ? 'replied'
591
+ : heard.status === 'expired'
592
+ ? 'fallback'
593
+ : heard.status === 'cancelled'
594
+ ? 'withdrawn'
595
+ : heard.status === 'answered'
596
+ ? 'answered'
597
+ : 'wrote';
598
+ const name = card.name ?? heard.sessionLabel;
599
+ return {
600
+ kind,
601
+ title: card.title ?? heard.title,
602
+ requestId: heard.requestId,
603
+ ...(name ? { name } : {}),
604
+ };
605
+ }
581
606
  function byPlugin(io, gone) {
582
607
  const queue = [];
583
608
  let waiting = null;
@@ -655,6 +680,12 @@ async function giveBack(io, origin, list) {
655
680
  }
656
681
  export async function listen(io, options) {
657
682
  const { origin, app, thread } = options;
683
+ if (app === 'codex' && !(await midTurn(io, thread))) {
684
+ const wakes = await takeHeard(io, thread);
685
+ const send = byCodexQueue(io, thread);
686
+ for (const message of queuedWakes(wakes))
687
+ await send(message, []);
688
+ }
658
689
  const lease = await takeLease(io, app, thread);
659
690
  if (!lease)
660
691
  return 0;
@@ -673,9 +704,16 @@ export async function listen(io, options) {
673
704
  let since;
674
705
  let failures = 0;
675
706
  while (io.now() - started < LISTEN_MS && !signal.aborted) {
707
+ if (app === 'codex' && !(await midTurn(io, thread))) {
708
+ const wakes = await takeHeard(io, thread);
709
+ for (const message of queuedWakes(wakes))
710
+ await deliver(message, []);
711
+ }
712
+ const waiting = app === 'codex' && (await hasHeard(io, thread));
676
713
  const record = (await load(io, app)).threads[thread];
677
714
  const cards = record?.cards ?? {};
678
- if (!record || (Object.keys(cards).length === 0 && !(takes && mayBeHanded(record, io.now()))))
715
+ if (!waiting &&
716
+ (!record || (Object.keys(cards).length === 0 && !(takes && mayBeHanded(record, io.now())))))
679
717
  return 0;
680
718
  if (!(await renew(io, app, thread, lease)))
681
719
  return 0;
@@ -726,7 +764,14 @@ export async function listen(io, options) {
726
764
  };
727
765
  const message = wakeMessage(ready);
728
766
  if (message) {
729
- if (!(await deliver(message, ready.map(({ heard }) => heard.requestId)))) {
767
+ if (app === 'codex' && (await midTurn(io, thread)))
768
+ await holdHeard(io, thread, ready.map((each) => ({
769
+ requestId: each.heard.requestId,
770
+ moment: momentOf(each.heard),
771
+ item: midItemOf(each.heard, each.card),
772
+ wake: wakeMessage([each]) ?? message,
773
+ })));
774
+ else if (!(await deliver(message, ready.map(({ heard }) => heard.requestId)))) {
730
775
  await gone();
731
776
  return 0;
732
777
  }
@@ -782,7 +827,7 @@ export async function listenHanded(io, options) {
782
827
  let program = null;
783
828
  const queue = async (thread, message) => {
784
829
  program ??= findCodex(io).then((found) => found?.command ?? 'codex');
785
- const queued = await io.run(await program, ['queue', '--thread', thread, '--message', message], 30_000);
830
+ const queued = await io.run(await program, ['queue', '--thread', thread, '--message', `${message}${STALE_WAKE}`], 30_000);
786
831
  return queued.code === 0;
787
832
  };
788
833
  const elsewhere = await elsewhereFor(io, origin, app);
@@ -792,7 +837,14 @@ export async function listenHanded(io, options) {
792
837
  let failures = 0;
793
838
  while (io.now() - started < LISTEN_MS && !signal.aborted) {
794
839
  const now = io.now();
795
- if (!Object.values((await load(io, app)).threads).some((each) => mayBeHanded(each, now)))
840
+ const { threads } = await load(io, app);
841
+ for (const thread of Object.keys(threads))
842
+ if (!(await midTurn(io, thread))) {
843
+ const wakes = await takeHeard(io, thread);
844
+ for (const message of queuedWakes(wakes))
845
+ await queue(thread, message);
846
+ }
847
+ if (!Object.values(threads).some((each) => mayBeHanded(each, now)))
796
848
  return 0;
797
849
  if (!(await renew(io, app, HANDED, lease)))
798
850
  return 0;
@@ -841,6 +893,20 @@ export async function listenHanded(io, options) {
841
893
  }
842
894
  for (const [thread, list] of byThread) {
843
895
  const message = handedMessage(list.map(({ card }) => card), { words: false });
896
+ if (message && (await midTurn(io, thread))) {
897
+ await holdHeard(io, thread, list.map(({ heard, card }) => ({
898
+ requestId: heard.requestId,
899
+ moment: momentOf(heard),
900
+ item: {
901
+ kind: card.said ? 'handed-reply' : 'handed',
902
+ title: card.title,
903
+ requestId: card.requestId,
904
+ name: card.name,
905
+ },
906
+ wake: handedMessage([card], { words: false }) ?? message,
907
+ })));
908
+ continue;
909
+ }
844
910
  if (message && (await queue(thread, message)))
845
911
  continue;
846
912
  await giveBack(io, origin, list);
@@ -57,11 +57,13 @@ export const CODEX_PRESENCE_HOOKS = [
57
57
  export const CODEX_NAMED_HOOKS = [
58
58
  { event: 'PostToolUse', sub: 'named', matcher: NAMED_TOOLS },
59
59
  ];
60
+ export const CODEX_HEARD_HOOKS = [{ event: 'PostToolUse', sub: 'heard' }];
60
61
  export const ALL_CODEX_HOOKS = [
61
62
  ...CODEX_HOOKS,
62
63
  ...CODEX_PERMISSION_HOOKS,
63
64
  ...CODEX_PRESENCE_HOOKS,
64
65
  ...CODEX_NAMED_HOOKS,
66
+ ...CODEX_HEARD_HOOKS,
65
67
  ];
66
68
  const EVENT_LABELS = {
67
69
  SessionStart: 'session_start',
@@ -494,6 +496,7 @@ export const codex = {
494
496
  ...(extra && cards ? codexPermissionHooks(wait) : []),
495
497
  ...(extra ? CODEX_PRESENCE_HOOKS : []),
496
498
  ...CODEX_NAMED_HOOKS,
499
+ ...(extra && cards ? [] : CODEX_HEARD_HOOKS),
497
500
  ];
498
501
  const wantedKeys = new Set(wanted.map(lineKey));
499
502
  const unwanted = ALL_CODEX_HOOKS.filter((spec) => !wantedKeys.has(lineKey(spec)));
@@ -520,10 +523,11 @@ export const codex = {
520
523
  ...(fresh.some((spec) => spec.sub === 'named')
521
524
  ? ['questions handed to a thread']
522
525
  : []),
526
+ ...(fresh.some((spec) => spec.sub === 'heard') ? ['answers while it works'] : []),
523
527
  ]);
524
528
  report({
525
529
  ok: true,
526
- text: merged.changed
530
+ text: merged.changed && !(removed.changed && !cards)
527
531
  ? `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).`
528
532
  : removed.changed
529
533
  ? `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)}`
@@ -717,6 +721,9 @@ export const codex = {
717
721
  : null;
718
722
  const presenceText = extraLine('Presence:', 'tells Pending You when this session is open', CODEX_PRESENCE_HOOKS.map((spec) => spec.sub), ownConnection ? null : notOwn);
719
723
  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);
724
+ const midTaskText = extraLine('Mid-task:', 'an answer that comes while a thread works is told at its next tool call', ownConnection && manifest?.permissionCards !== false
725
+ ? ['permission-done']
726
+ : CODEX_HEARD_HOOKS.map((spec) => spec.sub), null);
720
727
  const wakes = detected
721
728
  ? atLeast(detected.version, detected.command ? CODEX_APP_WAKE : CODEX_WAKE)
722
729
  : false;
@@ -738,6 +745,7 @@ export const codex = {
738
745
  ...(askFirst ? [askFirst] : []),
739
746
  presenceText,
740
747
  namedText,
748
+ midTaskText,
741
749
  ` ${mark(wakes)} Wake: ${wakes
742
750
  ? detected?.command
743
751
  ? '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)'
@@ -16,7 +16,7 @@ export const HANDED_PREFIX = 'Pending You: your person handed you';
16
16
  const HANDED_REPLY = ' on the question handed to you, ';
17
17
  const isHandedWake = (text) => {
18
18
  const first = text.trimStart().split('\n')[0] ?? '';
19
- return (first.startsWith(HANDED_PREFIX) ||
19
+ return (first.startsWith(`${HANDED_PREFIX} `) ||
20
20
  (first.startsWith('Pending You: ') && first.includes(HANDED_REPLY)));
21
21
  };
22
22
  const SOURCES = {
package/dist/args.js CHANGED
@@ -77,6 +77,7 @@ const COMMANDS = new Set([
77
77
  'mcp-headers',
78
78
  'posted',
79
79
  'named',
80
+ 'heard',
80
81
  'listen',
81
82
  'mcp',
82
83
  'permission',
@@ -111,6 +112,7 @@ const FLAGS = {
111
112
  stopcheck: { origin: true, app: true },
112
113
  posted: { origin: true, app: true },
113
114
  named: { origin: true, app: true },
115
+ heard: { origin: true, app: true },
114
116
  listen: { origin: true, app: true, thread: true, handed: false, since: true },
115
117
  permission: { origin: true, app: true },
116
118
  'permission-done': { origin: true, app: true },
@@ -210,6 +212,7 @@ export const HOOK_COMMANDS = new Set([
210
212
  'stopcheck',
211
213
  'posted',
212
214
  'named',
215
+ 'heard',
213
216
  'permission',
214
217
  'permission-done',
215
218
  'notify',
@@ -361,6 +364,7 @@ export function parseArgs(argv, env = {}) {
361
364
  return { name: 'stopcheck', origin, ...app() };
362
365
  case 'posted':
363
366
  case 'named':
367
+ case 'heard':
364
368
  none();
365
369
  return { name: first, origin, ...app() };
366
370
  case 'listen': {
package/dist/format.js CHANGED
@@ -25,7 +25,7 @@ export const HANDED_REPLY = 'on the question handed to you';
25
25
  export const HANDED_TALK_TODO = 'If you know now, answer_delegated with your answer and how you know; if you need more, reply_in_thread to “asker”; if it’s your person’s to decide, reply_in_thread with escalate true; if not, hand_back with what you checked.';
26
26
  export function isHandedWake(text) {
27
27
  const first = text.trimStart().split('\n')[0] ?? '';
28
- return (first.startsWith(HANDED_PREFIX) ||
28
+ return (first.startsWith(`${HANDED_PREFIX} `) ||
29
29
  (first.startsWith('Pending You: ') && first.includes(` ${HANDED_REPLY}, `)));
30
30
  }
31
31
  export function latestTalk(heard, from) {
package/dist/main.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { HOOK_DEADLINE_MS, refreshInBackground, SignInNeeded, Unavailable } from "./api.js";
2
2
  import { setAnswerWait } from "./apps/codex.js";
3
+ import { heardHook } from "./apps/codex-midturn.js";
3
4
  import { listen, listenHanded, posted } from "./apps/codex-wake.js";
4
5
  import { DEFAULT_APP } from "./apps/ids.js";
5
6
  import { appModule } from "./apps/registry.js";
@@ -52,6 +53,8 @@ async function run(io, command, hook = { fallback: '' }) {
52
53
  case 'posted':
53
54
  case 'named':
54
55
  return posted(io, { origin: command.origin, app: command.app ?? DEFAULT_APP });
56
+ case 'heard':
57
+ return heardHook(io);
55
58
  case 'permission':
56
59
  case 'permission-done':
57
60
  case 'notify': {
@@ -0,0 +1,54 @@
1
+ export const MID_TURN_TITLE_CHARS = 60;
2
+ export const MID_TURN_SHOWN = 3;
3
+ function midTitle(title) {
4
+ const flat = title.replace(/\s+/g, ' ').trim().replaceAll('“', '‘').replaceAll('”', '’');
5
+ const chars = [...flat];
6
+ return chars.length <= MID_TURN_TITLE_CHARS
7
+ ? flat
8
+ : `${chars
9
+ .slice(0, MID_TURN_TITLE_CHARS - 1)
10
+ .join('')
11
+ .trimEnd()}…`;
12
+ }
13
+ function midPhrase(item) {
14
+ const titled = `“${midTitle(item.title)}” (${item.requestId})`;
15
+ switch (item.kind) {
16
+ case 'answered':
17
+ return `your person answered ${titled}`;
18
+ case 'wrote':
19
+ return `your person wrote to you on ${titled}`;
20
+ case 'replied':
21
+ return `your person replied to your answer ${titled}`;
22
+ case 'word':
23
+ return `there’s word on ${titled}`;
24
+ case 'fallback':
25
+ return `nobody answered ${titled} in time, so its fallback is due`;
26
+ case 'withdrawn':
27
+ return `${titled} was withdrawn`;
28
+ case 'handed':
29
+ return `your person handed you ${titled}`;
30
+ case 'handed-reply':
31
+ return `there’s a reply on the question handed to you, ${titled}`;
32
+ }
33
+ }
34
+ const midRead = (item) => `get_request${item.name ? ` (name “${item.name}”)` : ''}`;
35
+ export function midTurnText(items) {
36
+ if (items.length === 0)
37
+ return null;
38
+ if (items.length === 1) {
39
+ const item = items[0];
40
+ if (item.kind === 'withdrawn')
41
+ return `Pending You, while you were working: ${midPhrase(item)}. Nothing to do.`;
42
+ return `Pending You, while you were working: ${midPhrase(item)}. Read it now with ${midRead(item)}, and act on it at the next sensible point in this task.`;
43
+ }
44
+ const shown = items.slice(0, MID_TURN_SHOWN);
45
+ const more = items.length - shown.length;
46
+ return [
47
+ 'Pending You, while you were working:',
48
+ ...shown.map((item) => item.kind === 'withdrawn'
49
+ ? `- ${midPhrase(item)}: nothing to do.`
50
+ : `- ${midPhrase(item)}: ${midRead(item)}.`),
51
+ ...(more > 0 ? [`- and ${more} more: list_pending with your name.`] : []),
52
+ 'Read each now, and act on them at the next sensible point in this task.',
53
+ ].join('\n');
54
+ }
@@ -1,6 +1,7 @@
1
1
  import { createHash, randomBytes } from 'node:crypto';
2
2
  import { open, readdir, rm, stat } from 'node:fs/promises';
3
3
  import { basename, dirname, join } from 'node:path';
4
+ import { tellHeard } from "./apps/codex-midturn.js";
4
5
  import { threadNames } from "./apps/codex-wake.js";
5
6
  import { APP_NAMES } from "./apps/ids.js";
6
7
  import { DEFAULT_ORIGIN } from "./args.js";
@@ -477,9 +478,15 @@ export async function permissionHook(io, options) {
477
478
  await asked(io, options.origin, input, app);
478
479
  break;
479
480
  case 'PostToolUse':
480
- case 'PostToolUseFailure':
481
+ case 'PostToolUseFailure': {
481
482
  await ran(io, input, app);
483
+ if (app === 'codex' && input.hook_event_name === 'PostToolUse') {
484
+ const told = await tellHeard(io, input);
485
+ if (told)
486
+ io.out(told);
487
+ }
482
488
  break;
489
+ }
483
490
  case 'Notification':
484
491
  if (app === CLAUDE)
485
492
  await notified(io, options.origin, input);
package/dist/pickup.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { getJson, postJson, SignInNeeded, Unavailable } from "./api.js";
2
+ import { turnBegan } from "./apps/codex-midturn.js";
2
3
  import { computerNames, hearsOnly, keepListening, markAskedTurn, markHandedTurn, sessionFor, threadAnsweredAt, threadCards, threadNames, touchThread, } from "./apps/codex-wake.js";
3
4
  import { APP_NAMES, DEFAULT_APP } from "./apps/ids.js";
4
5
  import { asksQuestion, ownWords } from "./asked.js";
@@ -228,6 +229,8 @@ export async function pickup(io, options, hook = { fallback: '' }) {
228
229
  else if (app === 'codex' && mode === 'handoff' && input.turn && asksQuestion(input.prompt))
229
230
  await markAskedTurn(io, input.turn, app).catch(() => { });
230
231
  }
232
+ if (app === 'codex' && mode === 'handoff' && input.session)
233
+ await turnBegan(io, input.session, input.turn ?? null);
231
234
  if (app === 'codex' && input.session)
232
235
  await keepListening(io, origin, input.session);
233
236
  const claudeNames = app === DEFAULT_APP
package/dist/stopcheck.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import { open } from 'node:fs/promises';
2
2
  import { getJson } from "./api.js";
3
3
  import { codexSeesAnswers } from "./apps/codex.js";
4
+ import { hasHeard, turnEnded } from "./apps/codex-midturn.js";
4
5
  import { markNudged, turnRecord } from "./apps/codex-wake.js";
5
6
  import { APP_NAMES, DEFAULT_APP } from "./apps/ids.js";
7
+ import { DEFAULT_ORIGIN } from "./args.js";
6
8
  import { asksQuestion, wordsOf } from "./asked.js";
7
9
  import { asksToTypeHere, cardFits, confirmReason, sessionLink } from "./confirm.js";
8
10
  import { readCredential } from "./credentials.js";
@@ -414,6 +416,20 @@ export async function stopcheck(io, options) {
414
416
  event: 'stop',
415
417
  subagents: subagentsRunning(input),
416
418
  });
419
+ if (app === 'codex' &&
420
+ typeof input.session_id === 'string' &&
421
+ input.stop_hook_active !== true) {
422
+ await turnEnded(io, input.session_id, typeof input.turn_id === 'string' ? input.turn_id : null);
423
+ if (await hasHeard(io, input.session_id))
424
+ io.background([
425
+ 'listen',
426
+ '--app',
427
+ 'codex',
428
+ '--thread',
429
+ input.session_id,
430
+ ...(options.origin === DEFAULT_ORIGIN ? [] : ['--origin', options.origin]),
431
+ ]);
432
+ }
417
433
  if (input.stop_hook_active === true)
418
434
  return 0;
419
435
  if (!(await readCredential(io, options.origin, app)))
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.43.2';
1
+ export const VERSION = '0.43.3';
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pendingyou-wake",
3
3
  "displayName": "Pending You",
4
- "version": "2.61.2",
4
+ "version": "2.61.3",
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.61.2; send changes there.
7
+ Generated from recordplane/pendingyou (packages/claude-plugin/src/wake) with Pending You’s guide 2.61.3; send changes there.
@@ -1,7 +1,7 @@
1
1
  // Generated from packages/claude-plugin/src/wake/register.ts in recordplane/pendingyou: edit that, then run
2
2
  // `pnpm --filter @pendingyou/claude-plugin generate`.
3
3
 
4
- import { argumentsOf, BOOK_TOUCH_MS, blockedNote, CLAIM_PREFIX, CLAIM_RENEW_MS, CLI_COPY, cardTool, checkArgs, checked, claimedElsewhere, claimHeld, claimLapsesAt, claimLease, cliConfigOf, connectionOf, dueCards, emptyBook, failed, folderOf, graceAfter, graceEnds, HANDED_FAST_MS, HANDED_FOR_MS, HANDED_READS, HERDR_EVERY_MS, HERDR_RUN_MS, handedDue, handedNext, handedOf, handedText, handedView, herdrArgv, herdrPayload, holdOf, holdReply, inHerdr, isFresh, isRefusal, isStale, isWaitingOnYou, KEEP_MS, keepsBook, LISTEN_RUN_MS, LISTENER_KEY, learn, leaseFor, leaseHolder, listenArgv, listened, loadedNote, loadedPath, mayListen, momentOf, nameKept, newerElsewhere, originOf, PRESENCE_EVERY_MS, PRESENCE_RUN_MS, presenceArgv, presenceNameOf, prompted, put, readBook, readClaim, readListener, readSetup, readSignal, readSince, readWait, resultObject, retellDue, SETUP_AFTER_MS, SETUP_RETRY_MS, SETUP_SERVER, SETUP_TRIES, SIGNAL_KEY, settle, setUpOf, setupNeeded, setupPrompt, stateOf, statusText, TICK_MS, takesHanded, told, toTell, untold, used, wakeText, wordsOf, } from "./wake.js";
4
+ import { argumentsOf, BOOK_TOUCH_MS, blockedNote, CLAIM_PREFIX, CLAIM_RENEW_MS, CLI_COPY, cardTool, checkArgs, checked, claimedElsewhere, claimHeld, claimLapsesAt, claimLease, cliConfigOf, connectionOf, dueCards, emptyBook, failed, folderOf, graceAfter, graceEnds, HANDED_FAST_MS, HANDED_FOR_MS, HANDED_READS, HERDR_EVERY_MS, HERDR_RUN_MS, handedDue, handedNext, handedOf, handedText, handedView, herdrArgv, herdrPayload, holdOf, holdReply, inHerdr, isFresh, isRefusal, isStale, isWaitingOnYou, KEEP_MS, keepsBook, LISTEN_RUN_MS, LISTENER_KEY, learn, leaseFor, leaseHolder, listenArgv, listened, loadedNote, loadedPath, mayListen, midTurnKindOf, midTurnText, momentOf, nameKept, newerElsewhere, originOf, PRESENCE_EVERY_MS, PRESENCE_RUN_MS, presenceArgv, presenceNameOf, prompted, put, readBook, readClaim, readListener, readSetup, readSignal, readSince, readWait, resultObject, retellDue, SETUP_AFTER_MS, SETUP_RETRY_MS, SETUP_SERVER, SETUP_TRIES, SIGNAL_KEY, settle, setUpOf, setupNeeded, setupPrompt, stateOf, statusText, TICK_MS, takesHanded, told, toTell, unreadWake, untold, used, wakeText, wordsOf, } from "./wake.js";
5
5
  const UNHEARD = { error: 'unavailable' };
6
6
  const RETRY_MS = 60_000;
7
7
  const live = {
@@ -22,6 +22,7 @@ const live = {
22
22
  setupConnection: 'Claude Code',
23
23
  seenAt: 0,
24
24
  handedAt: 0,
25
+ hinted: new Set(),
25
26
  held: [],
26
27
  heldRenewedAt: 0,
27
28
  handedTold: new Map(),
@@ -182,7 +183,10 @@ async function deliver($) {
182
183
  return false;
183
184
  live.book = told(live.book, cards);
184
185
  await save($);
185
- $.prompt.submit({ text: wakeText(cards, live.words) }).catch(async () => {
186
+ const hinted = new Set(cards
187
+ .filter((card) => card.state && live.hinted.has(`${card.requestId} ${momentOf(card.state)}`))
188
+ .map((card) => card.requestId));
189
+ $.prompt.submit({ text: wakeText(cards, live.words, hinted) }).catch(async () => {
186
190
  live.book = untold(live.book, cards);
187
191
  live.quietUntil = (await $.clock.now()) + RETRY_MS;
188
192
  await save($).catch(() => { });
@@ -217,12 +221,21 @@ async function heldHanded($, now) {
217
221
  for (const held of holding) {
218
222
  if (!claimHeld(await $.store.get(held.key), held.moment, me))
219
223
  continue;
224
+ if (readSince(live.handedTold.get(held.handed.requestId), held.handed.updatedAt)) {
225
+ await $.store.set(held.key, { moment: held.moment, at: now, by: me });
226
+ continue;
227
+ }
220
228
  let view = null;
229
+ let unread = true;
221
230
  if (name && server) {
222
231
  const args = { requestId: held.handed.requestId, name };
223
232
  if (await allowed($, server, args))
224
233
  try {
225
- view = handedView(resultObject(await $.mcp.call(server, 'get_request', args)), held.handed, name);
234
+ const output = resultObject(await $.mcp.call(server, 'get_request', args));
235
+ if (output) {
236
+ unread = false;
237
+ view = handedView(output, held.handed, name);
238
+ }
226
239
  }
227
240
  catch { }
228
241
  }
@@ -230,6 +243,10 @@ async function heldHanded($, now) {
230
243
  await giveBack($, holding, me);
231
244
  return;
232
245
  }
246
+ if (unread) {
247
+ live.handedTold.delete(held.handed.requestId);
248
+ live.handedAt = Math.min(live.handedAt, now + RETRY_MS);
249
+ }
233
250
  if (!view) {
234
251
  if (claimHeld(await $.store.get(held.key), held.moment, me))
235
252
  await $.store.delete(held.key).catch(() => { });
@@ -240,7 +257,9 @@ async function heldHanded($, now) {
240
257
  }
241
258
  if (told.length === 0)
242
259
  return;
243
- $.prompt.submit({ text: handedText(told.map((each) => each.view)) }).catch(async () => {
260
+ const words = handedText(told.map((each) => each.view));
261
+ const unread = told.every((each) => holding.some((held) => held.key === each.key && live.hinted.has(`${held.handed.requestId} ${held.moment}`)));
262
+ $.prompt.submit({ text: unread ? unreadWake(words) : words }).catch(async () => {
244
263
  for (const each of told) {
245
264
  await $.store.delete(each.key).catch(() => { });
246
265
  live.handedTold.delete(each.view.requestId);
@@ -719,7 +738,60 @@ async function answerHold($, e) {
719
738
  const answer = live.book.cards[requestId]?.kind === 'answer';
720
739
  return { result: { stdout: holdReply(requestId, answer), stderr: '', interrupted: false } };
721
740
  }
741
+ async function tellMidTurn($, e, result) {
742
+ if (!live.busy || !live.owner || !live.sessionId || e.agentId || result.deny !== undefined)
743
+ return result;
744
+ const own = typeof e.requestId === 'string' ? e.requestId : undefined;
745
+ const said = (requestId, moment) => live.hinted.has(`${requestId} ${moment}`);
746
+ const cards = toTell(live.book).filter((card) => card.requestId !== own && card.state && !said(card.requestId, momentOf(card.state)));
747
+ const waiting = live.held.filter((each) => each.handed.requestId !== own &&
748
+ !said(each.handed.requestId, each.moment) &&
749
+ !readSince(live.handedTold.get(each.handed.requestId), each.handed.updatedAt));
750
+ if (cards.length === 0 && waiting.length === 0)
751
+ return result;
752
+ const me = live.sessionId;
753
+ const name = live.book.name;
754
+ const held = [];
755
+ for (const each of waiting)
756
+ if (claimHeld(await $.store.get(each.key), each.moment, me))
757
+ held.push(each);
758
+ const items = [
759
+ ...cards.map((card) => {
760
+ const named = card.name ?? name;
761
+ return {
762
+ kind: midTurnKindOf(card),
763
+ title: card.title ?? card.requestId,
764
+ requestId: card.requestId,
765
+ ...(named ? { name: named } : {}),
766
+ };
767
+ }),
768
+ ...held.map((each) => ({
769
+ kind: 'handed',
770
+ title: each.handed.title,
771
+ requestId: each.handed.requestId,
772
+ ...(name ? { name } : {}),
773
+ })),
774
+ ];
775
+ const text = midTurnText(items);
776
+ if (!text)
777
+ return result;
778
+ for (const card of cards)
779
+ if (card.state)
780
+ live.hinted.add(`${card.requestId} ${momentOf(card.state)}`);
781
+ for (const each of held)
782
+ live.hinted.add(`${each.handed.requestId} ${each.moment}`);
783
+ return { ...result, context: [...(result.context ?? []), text] };
784
+ }
722
785
  export function register(on) {
786
+ on('tool.call', async ($, e, next) => {
787
+ const result = await next(e);
788
+ try {
789
+ return await tellMidTurn($, e, result);
790
+ }
791
+ catch {
792
+ return result;
793
+ }
794
+ });
723
795
  on('session.start', async ($, e, next) => {
724
796
  try {
725
797
  await start($, e);
@@ -735,8 +807,10 @@ export function register(on) {
735
807
  return next(e);
736
808
  });
737
809
  on('turn.start', async (_, e, next) => {
738
- if (!e.agentId)
810
+ if (!e.agentId) {
739
811
  live.busy = true;
812
+ live.hinted.clear();
813
+ }
740
814
  return next(e);
741
815
  });
742
816
  on('turn.complete', async ($, e, next) => {
package/mod/hooks/wake.js CHANGED
@@ -534,7 +534,15 @@ function plainLine(card, get, state) {
534
534
  }
535
535
  }
536
536
  const capital = (sentence) => sentence.charAt(0).toUpperCase() + sentence.slice(1);
537
- export function wakeText(cards, words) {
537
+ export const UNREAD_NOTE = 'You were told of this while working and haven’t read it.';
538
+ export const unreadWake = (text) => text.includes('\n') ? `${text}\n${UNREAD_NOTE}` : `${text} ${UNREAD_NOTE}`;
539
+ export function wakeText(cards, words, hinted) {
540
+ const text = wakeWords(cards, words);
541
+ return hinted && cards.length > 0 && cards.every((card) => hinted.has(card.requestId))
542
+ ? unreadWake(text)
543
+ : text;
544
+ }
545
+ function wakeWords(cards, words) {
538
546
  const asked = cards.some((card) => card.state?.turn === 'agent' &&
539
547
  !isClosed(card.state.status) &&
540
548
  card.state.status !== 'delegated' &&
@@ -1125,3 +1133,71 @@ export function herdrArgv(config, session) {
1125
1133
  String(Math.floor(session.at)),
1126
1134
  ];
1127
1135
  }
1136
+ export const MID_TURN_TITLE_CHARS = 60;
1137
+ export const MID_TURN_SHOWN = 3;
1138
+ function midTitle(title) {
1139
+ const flat = title.replace(/\s+/g, ' ').trim().replaceAll('“', '‘').replaceAll('”', '’');
1140
+ const chars = [...flat];
1141
+ return chars.length <= MID_TURN_TITLE_CHARS
1142
+ ? flat
1143
+ : `${chars
1144
+ .slice(0, MID_TURN_TITLE_CHARS - 1)
1145
+ .join('')
1146
+ .trimEnd()}…`;
1147
+ }
1148
+ function midPhrase(item) {
1149
+ const titled = `“${midTitle(item.title)}” (${item.requestId})`;
1150
+ switch (item.kind) {
1151
+ case 'answered':
1152
+ return `your person answered ${titled}`;
1153
+ case 'wrote':
1154
+ return `your person wrote to you on ${titled}`;
1155
+ case 'replied':
1156
+ return `your person replied to your answer ${titled}`;
1157
+ case 'word':
1158
+ return `there’s word on ${titled}`;
1159
+ case 'fallback':
1160
+ return `nobody answered ${titled} in time, so its fallback is due`;
1161
+ case 'withdrawn':
1162
+ return `${titled} was withdrawn`;
1163
+ case 'handed':
1164
+ return `your person handed you ${titled}`;
1165
+ case 'handed-reply':
1166
+ return `there’s a reply on the question handed to you, ${titled}`;
1167
+ }
1168
+ }
1169
+ const midRead = (item) => `get_request${item.name ? ` (name “${item.name}”)` : ''}`;
1170
+ export function midTurnText(items) {
1171
+ if (items.length === 0)
1172
+ return null;
1173
+ if (items.length === 1) {
1174
+ const item = items[0];
1175
+ if (item.kind === 'withdrawn')
1176
+ return `Pending You, while you were working: ${midPhrase(item)}. Nothing to do.`;
1177
+ return `Pending You, while you were working: ${midPhrase(item)}. Read it now with ${midRead(item)}, and act on it at the next sensible point in this task.`;
1178
+ }
1179
+ const shown = items.slice(0, MID_TURN_SHOWN);
1180
+ const more = items.length - shown.length;
1181
+ return [
1182
+ 'Pending You, while you were working:',
1183
+ ...shown.map((item) => item.kind === 'withdrawn'
1184
+ ? `- ${midPhrase(item)}: nothing to do.`
1185
+ : `- ${midPhrase(item)}: ${midRead(item)}.`),
1186
+ ...(more > 0 ? [`- and ${more} more: list_pending with your name.`] : []),
1187
+ 'Read each now, and act on them at the next sensible point in this task.',
1188
+ ].join('\n');
1189
+ }
1190
+ export function midTurnKindOf(card) {
1191
+ const status = card.state?.status;
1192
+ if (card.kind === 'answer')
1193
+ return 'replied';
1194
+ if (status === 'expired')
1195
+ return 'fallback';
1196
+ if (status === 'cancelled')
1197
+ return 'withdrawn';
1198
+ if (status === 'answered')
1199
+ return 'answered';
1200
+ if (status === 'delegated')
1201
+ return 'word';
1202
+ return 'wrote';
1203
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pendingyou",
3
- "version": "0.43.2",
3
+ "version": "0.43.3",
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",