pendingyou 0.43.3 → 0.44.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,55 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.44.1 (2026-11-19)
4
+
5
+ Found by the first live tests of Codex 0.170.0, OpenCode 2.3.2 and Pi 1.5.2.
6
+
7
+ - **A reply on an open card wakes Pi and OpenCode.** When you wrote back on a card (“Before I answer: how long can it
8
+ be?”) while a Pi or OpenCode session sat idle, nothing woke it: it heard your words only with your next message. The
9
+ session's listener read its cards before each wait for news, so a card posted during that wait, and written on
10
+ before it ended, was missed for good. The same could happen to an answer, less often, and to Codex on a second card
11
+ posted while the first one's listener ran. A question you hand a session was never affected.
12
+ - **A reply that ends on a question reaches you as a card.** An assistant that ended on “Should the next file be
13
+ called alpha.txt or beta.txt?” settled with the question only in chat: the check that puts what an assistant leaves
14
+ you in chat on a card counted a question only when it said “you”. Now a reply whose last sentence is a question
15
+ counts, in every app (Claude Code, Codex, OpenCode and Pi), outside code, quotes and a closing aside in parentheses,
16
+ and not a question it goes on to answer itself.
17
+ - **A question already on one of the session's open cards no longer nags.** When all a reply leaves you is questions
18
+ and each is one of the session's open cards (“Still waiting: which DNS host for the new domain?”), the assistant
19
+ isn't asked to post it again. It asks Pending You for those cards (1.5 seconds at most); when Pending You can't say
20
+ in time, it lets the reply stand. The words an assistant is asked with are unchanged.
21
+ - **An assistant shows as running as soon as it has a name.** A session said it was open before it had said its name,
22
+ and Pending You knows a session's agent by its name, so a new Pi, OpenCode or Codex session wasn't shown running for
23
+ up to 5 minutes after it introduced itself. Now it says so again, with its name, the moment it gives one.
24
+ - After `npx -y pendingyou@latest init`: restart Pi (or `/reload` in it) and OpenCode 1.x so their listeners run the
25
+ new version; OpenCode 2.x reloads the plugin by itself. A Codex thread's listener runs the new version the next
26
+ time one starts (when it has no card left, or after 8 hours, it stops). Nothing to restart for the rest: the check
27
+ on a reply's last words and the name sent with a session's presence run the new version at once.
28
+
29
+ ## 0.44.0 (2026-11-18)
30
+
31
+ - **OpenCode 2.x: Pending You's plugin loads again.** OpenCode 2.0.0 and later refused the plugin that `init` wrote
32
+ ("failed to load plugin" in OpenCode's log), so an OpenCode 2.x session was never woken when you answered, its next
33
+ message didn't carry your answers, and nothing asked it to put what it left you in chat on a card. Its MCP server
34
+ worked, so setup looked fine, and `status` wrongly said "OpenCode hears answers right away". If you use OpenCode 2.x,
35
+ run `npx -y pendingyou@latest init` (all your agents, or `--app opencode`); an open OpenCode loads the new plugin by
36
+ itself, or restart it. What each OpenCode runs:
37
+ - OpenCode 1.x (1.17.0 and later) and **2.3.0 and later**: all of it.
38
+ - 2.2.1 to 2.2.x: it's woken when you answer and asked to put what it leaves you in chat on a card, but your next
39
+ message doesn't carry your answers and the setup line (that takes 2.3.0).
40
+ - 2.0.0 to 2.2.0: it's woken when you answer, and nothing more.
41
+ - On 2.0.0 to 2.2.x, `init` and `status` say so; update OpenCode to 2.3.0 or later for the rest.
42
+ - In OpenCode 2.x the hand-off goes to the model only: your message shows your own words, and the session's title
43
+ isn't made from it.
44
+ - `status` says OpenCode hears answers right away only when OpenCode's own log shows it loaded the plugin. It says
45
+ when OpenCode refused it and why, when an open OpenCode needs a restart for the plugin `init` just wrote, and that it
46
+ couldn't confirm when the log doesn't mention it.
47
+ - When `init` rewrites the plugin with OpenCode 2.x open, the sessions it had open stay open in Pending You and keep
48
+ listening; and as OpenCode starts, its sessions with cards waiting listen again.
49
+ - A card an OpenCode 2.x turn posts while you type another message counts for that turn, so it isn't asked to put the
50
+ same thing on a card again.
51
+ - `init` never removes the copy of pendingyou OpenCode's plugin runs from.
52
+
3
53
  ## 0.43.3 (2026-11-17)
4
54
 
5
55
  - An assistant in the middle of a long task when you answer is told at its next tool call, once, in one line, instead
@@ -9,6 +9,7 @@ import { APPROVED_DRAFT_NOTICE, approvesDraft, clip, delegatedOf, handledOf, isC
9
9
  import { chooseThread, goesBy, HANDED_FOR_MS, handedCard, handedMessage, namesAnotherComputer, OPEN_FOR_MS, } from "../handed.js";
10
10
  import { clearHerdr, herdrTarget, isUrgency, PANE_ID, reportCommand, writeHerdr, } from "../herdr.js";
11
11
  import { linkSoon } from "../link.js";
12
+ import { presenceArgs, readSaid } from "../presence.js";
12
13
  import { macName, tailscaleName } from "../remote.js";
13
14
  import { claimHanded, markHanded, momentOf, releaseHanded, wasHanded } from "../state.js";
14
15
  import { findCodex } from "./codex-app.js";
@@ -183,7 +184,9 @@ export async function posted(io, options) {
183
184
  const cwd = text(input.cwd, 1000);
184
185
  const now = io.now();
185
186
  const pane = await herdrTarget(io);
187
+ let renamed = null;
186
188
  await change(io, app, (state) => {
189
+ renamed = newName(state.threads[thread], nameOf(args));
187
190
  if (turn && call !== 'cancel_request') {
188
191
  const record = state.turns[turn] ?? { at: now, cards: [] };
189
192
  record.cards = [...record.cards, wordsIn(args)].slice(-10);
@@ -226,6 +229,8 @@ export async function posted(io, options) {
226
229
  });
227
230
  if (pane)
228
231
  io.background(reportCommand(app, { session: thread, at: now }));
232
+ if (renamed)
233
+ await liveByName(io, options, thread, renamed, cwd, now);
229
234
  if (app === 'codex')
230
235
  await keepListening(io, options.origin, thread);
231
236
  return 0;
@@ -250,7 +255,9 @@ async function named(io, options, input, thread) {
250
255
  const cwd = text(input.cwd, 1000);
251
256
  const now = io.now();
252
257
  const pane = await herdrTarget(io);
258
+ let renamed = null;
253
259
  await change(io, app, (state) => {
260
+ renamed = newName(state.threads[thread], name);
254
261
  const known = withName(state.threads[thread] ?? { origin: options.origin, cards: {}, at: now }, name);
255
262
  if (cwd)
256
263
  known.cwd = cwd;
@@ -262,10 +269,34 @@ async function named(io, options, input, thread) {
262
269
  });
263
270
  if (pane)
264
271
  io.background(reportCommand(app, { session: thread, at: now }));
272
+ if (renamed)
273
+ await liveByName(io, options, thread, renamed, cwd, now);
265
274
  if (app === 'codex')
266
275
  await keepListening(io, options.origin, thread);
267
276
  return 0;
268
277
  }
278
+ function newName(thread, name) {
279
+ if (!name)
280
+ return null;
281
+ const now = thread?.names?.at(-1);
282
+ return now && goesBy([now], name) ? null : name;
283
+ }
284
+ async function liveByName(io, options, thread, name, cwd, at) {
285
+ try {
286
+ if (io.platform === 'win32')
287
+ return;
288
+ if ((await readSaid(io, options.app))[thread]?.state !== 'live')
289
+ return;
290
+ io.background(presenceArgs(options.origin, options.app, {
291
+ state: 'live',
292
+ session: thread,
293
+ name,
294
+ ...(cwd ? { cwd } : {}),
295
+ at,
296
+ }));
297
+ }
298
+ catch { }
299
+ }
269
300
  function askedIn(args) {
270
301
  let asked = args.askedFirst;
271
302
  if (typeof asked === 'string')
@@ -711,9 +742,9 @@ export async function listen(io, options) {
711
742
  }
712
743
  const waiting = app === 'codex' && (await hasHeard(io, thread));
713
744
  const record = (await load(io, app)).threads[thread];
714
- const cards = record?.cards ?? {};
715
745
  if (!waiting &&
716
- (!record || (Object.keys(cards).length === 0 && !(takes && mayBeHanded(record, io.now())))))
746
+ (!record ||
747
+ (Object.keys(record.cards).length === 0 && !(takes && mayBeHanded(record, io.now())))))
717
748
  return 0;
718
749
  if (!(await renew(io, app, thread, lease)))
719
750
  return 0;
@@ -743,6 +774,7 @@ export async function listen(io, options) {
743
774
  for (const heard of requests)
744
775
  if (!since || heard.changedAt > since)
745
776
  since = heard.changedAt;
777
+ const cards = (await load(io, app)).threads[thread]?.cards ?? {};
746
778
  const ready = [];
747
779
  const done = [];
748
780
  for (const heard of requests) {
@@ -149,21 +149,34 @@ function viaShim(config, origin, directory) {
149
149
  },
150
150
  };
151
151
  }
152
+ function setUp(directory) {
153
+ const config = configFolder();
154
+ const manifest = JSON.parse(readFileSync(join(config, 'opencode.json'), 'utf8'));
155
+ const origin = isObject(manifest) && typeof manifest.origin === 'string' ? manifest.origin : null;
156
+ return origin ? viaShim(config, origin, directory) : null;
157
+ }
152
158
  export const PendingYou = async (input) => {
153
159
  try {
154
- const config = configFolder();
155
- const manifest = JSON.parse(readFileSync(join(config, 'opencode.json'), 'utf8'));
156
- const origin = isObject(manifest) && typeof manifest.origin === 'string' ? manifest.origin : null;
157
- if (!origin)
158
- return {};
159
- return pendingYou(input, viaShim(config, origin, input.directory));
160
+ const deps = setUp(input.directory);
161
+ return deps ? pendingYou(input, deps) : {};
160
162
  }
161
163
  catch {
162
164
  return {};
163
165
  }
164
166
  };
165
- export async function pendingYou(input, deps) {
166
- const { client, directory } = input;
167
+ export const setupV2 = async (ctx) => {
168
+ try {
169
+ const directory = ctx.location?.directory ?? process.cwd();
170
+ const deps = setUp(directory);
171
+ return deps ? await pendingYouV2(ctx, deps, directory) : undefined;
172
+ }
173
+ catch {
174
+ return undefined;
175
+ }
176
+ };
177
+ const plugin = { id: 'pendingyou', server: PendingYou, setup: setupV2 };
178
+ export default plugin;
179
+ function core(surface, deps, directory) {
167
180
  const sessions = new Map();
168
181
  const present = new Set();
169
182
  let stopBeat = null;
@@ -194,15 +207,174 @@ export async function pendingYou(input, deps) {
194
207
  const session = found ?? {};
195
208
  sessions.set(id, session);
196
209
  try {
197
- const { data } = await client.session.get({ path: { id } });
198
- session.parent =
199
- isObject(data) && typeof data.parentID === 'string' && data.parentID ? data.parentID : null;
210
+ session.parent = await surface.parentOf(id);
200
211
  }
201
212
  catch {
202
213
  session.parent = null;
203
214
  }
204
215
  return session;
205
216
  };
217
+ const listenFor = (id, session) => {
218
+ if (session.gone)
219
+ return;
220
+ if (session.listener) {
221
+ session.again = true;
222
+ return;
223
+ }
224
+ session.again = false;
225
+ const listener = deps.listen(id);
226
+ if (!listener)
227
+ return;
228
+ session.listener = listener;
229
+ void (async () => {
230
+ try {
231
+ for await (const line of listener.lines) {
232
+ let wake;
233
+ try {
234
+ wake = JSON.parse(line);
235
+ }
236
+ catch {
237
+ continue;
238
+ }
239
+ if (!isObject(wake) || typeof wake.wake !== 'string')
240
+ continue;
241
+ const delivered = await surface.send(id, session, 'wake', wake.wake).catch(() => false);
242
+ listener.reply(JSON.stringify({ delivered }));
243
+ }
244
+ }
245
+ catch { }
246
+ if (session.listener === listener)
247
+ session.listener = undefined;
248
+ if (session.again)
249
+ listenFor(id, session);
250
+ })();
251
+ };
252
+ return {
253
+ created(id, parent) {
254
+ const session = sessions.get(id) ?? {};
255
+ session.fresh = true;
256
+ session.parent = parent;
257
+ sessions.set(id, session);
258
+ if (!session.parent)
259
+ live(id);
260
+ },
261
+ deleted(id) {
262
+ const session = sessions.get(id);
263
+ if (session)
264
+ session.gone = true;
265
+ session?.listener?.stop();
266
+ sessions.delete(id);
267
+ closed(id);
268
+ },
269
+ async message(id, turn, using) {
270
+ const session = await known(id);
271
+ if (session.parent)
272
+ return '';
273
+ live(id);
274
+ if (turn)
275
+ session.turn = turn;
276
+ if (using)
277
+ session.using = using;
278
+ const first = !session.spoken;
279
+ session.spoken = true;
280
+ const said = (await deps.run('handoff', {
281
+ cwd: directory,
282
+ session_id: id,
283
+ ...(first ? { source: session.fresh ? 'startup' : 'resume' } : {}),
284
+ })).trim();
285
+ if (first || deps.wanted?.(id))
286
+ listenFor(id, session);
287
+ return said;
288
+ },
289
+ async reopen(id, isLive) {
290
+ const session = await known(id);
291
+ if (session.parent || session.gone)
292
+ return;
293
+ if (isLive)
294
+ live(id);
295
+ if (!session.listener && deps.wanted?.(id))
296
+ listenFor(id, session);
297
+ },
298
+ present: () => [...present],
299
+ async ours(id, turn) {
300
+ const session = await known(id);
301
+ if (session.parent)
302
+ return;
303
+ live(id);
304
+ session.turn = turn;
305
+ },
306
+ async tool(tool, sessionID, args, response) {
307
+ const named = NAMED_TOOL.test(tool);
308
+ if (named && !(isObject(args) && typeof args.name === 'string'))
309
+ return;
310
+ if (!named && !CARD_TOOL.test(tool))
311
+ return;
312
+ const session = await known(sessionID);
313
+ const id = session.parent ?? sessionID;
314
+ const owner = session.parent ? await known(id) : session;
315
+ const turn = (await surface.turnNow?.(id).catch(() => null)) ?? owner.turn;
316
+ await deps.run('posted', {
317
+ session_id: id,
318
+ ...(turn ? { turn_id: turn } : {}),
319
+ cwd: directory,
320
+ tool_name: tool,
321
+ tool_input: args ?? {},
322
+ tool_response: response,
323
+ });
324
+ listenFor(id, owner);
325
+ },
326
+ async idle(id) {
327
+ const session = await known(id);
328
+ if (session.parent || session.checking)
329
+ return;
330
+ session.checking = true;
331
+ try {
332
+ const turn = await surface.turnOf(id);
333
+ if (!turn)
334
+ return;
335
+ const said = await deps.run('stopcheck', {
336
+ session_id: id,
337
+ turn_id: turn.id,
338
+ cwd: directory,
339
+ messages: turn.messages,
340
+ });
341
+ let decision;
342
+ try {
343
+ decision = JSON.parse(said);
344
+ }
345
+ catch {
346
+ return;
347
+ }
348
+ if (!isObject(decision) || decision.decision !== 'block')
349
+ return;
350
+ if (typeof decision.reason !== 'string')
351
+ return;
352
+ await surface.send(id, session, 'stopcheck', decision.reason);
353
+ }
354
+ finally {
355
+ session.checking = false;
356
+ }
357
+ },
358
+ dispose() {
359
+ for (const session of sessions.values()) {
360
+ session.gone = true;
361
+ session.listener?.stop();
362
+ }
363
+ stopBeat?.();
364
+ stopBeat = null;
365
+ for (const id of [...present])
366
+ closed(id);
367
+ },
368
+ };
369
+ }
370
+ function textPart(text, extra = {}) {
371
+ return { type: 'text', text: text.slice(0, TEXT_CHARS), ...extra };
372
+ }
373
+ function toolPart(tool, status, input) {
374
+ return { type: 'tool', tool, status, ...(CARD_TOOL.test(tool) ? { input } : {}) };
375
+ }
376
+ export async function pendingYou(input, deps) {
377
+ const { client, directory } = input;
206
378
  const usingOf = (info) => {
207
379
  if (!isObject(info))
208
380
  return undefined;
@@ -241,45 +413,30 @@ export async function pendingYou(input, deps) {
241
413
  return false;
242
414
  }
243
415
  };
244
- const listenFor = (id, session) => {
245
- if (session.gone)
246
- return;
247
- if (session.listener) {
248
- session.again = true;
249
- return;
250
- }
251
- session.again = false;
252
- const listener = deps.listen(id);
253
- if (!listener)
254
- return;
255
- session.listener = listener;
256
- void (async () => {
257
- try {
258
- for await (const line of listener.lines) {
259
- let wake;
260
- try {
261
- wake = JSON.parse(line);
262
- }
263
- catch {
264
- continue;
265
- }
266
- if (!isObject(wake) || typeof wake.wake !== 'string')
267
- continue;
268
- const delivered = await prompt(id, session, {
269
- type: 'text',
270
- text: wake.wake,
271
- metadata: { pendingyou: 'wake' },
272
- });
273
- listener.reply(JSON.stringify({ delivered }));
274
- }
275
- }
276
- catch { }
277
- if (session.listener === listener)
278
- session.listener = undefined;
279
- if (session.again)
280
- listenFor(id, session);
281
- })();
282
- };
416
+ const plugin = core({
417
+ parentOf: async (id) => {
418
+ const { data } = await client.session.get({ path: { id } });
419
+ return isObject(data) && typeof data.parentID === 'string' && data.parentID
420
+ ? data.parentID
421
+ : null;
422
+ },
423
+ turnOf: async (id) => turnOf(await messagesOf(id, TURN_MESSAGES)),
424
+ send: async (id, session, kind, text) => {
425
+ if (kind === 'wake')
426
+ return prompt(id, session, { type: 'text', text, metadata: { pendingyou: 'wake' } });
427
+ const went = await prompt(id, session, {
428
+ type: 'text',
429
+ text,
430
+ synthetic: true,
431
+ metadata: { pendingyou: 'stopcheck' },
432
+ });
433
+ if (went)
434
+ await client.tui
435
+ .showToast({ body: { title: 'Pending You', message: NUDGED, variant: 'info' } })
436
+ .catch(() => { });
437
+ return went;
438
+ },
439
+ }, deps, directory);
283
440
  const turnOf = (messages) => {
284
441
  const start = messages.findLastIndex((message) => isObject(message.info) && message.info.role === 'user');
285
442
  const first = messages[start];
@@ -299,24 +456,15 @@ export async function pendingYou(input, deps) {
299
456
  if (part.type === 'text' && typeof part.text === 'string') {
300
457
  const mark = ourMark(part);
301
458
  return [
302
- {
303
- type: 'text',
304
- text: part.text.slice(0, TEXT_CHARS),
459
+ textPart(part.text, {
305
460
  ...(part.synthetic === true ? { synthetic: true } : {}),
306
461
  ...(mark ? { pendingyou: mark } : {}),
307
- },
462
+ }),
308
463
  ];
309
464
  }
310
465
  if (part.type === 'tool' && typeof part.tool === 'string') {
311
466
  const state = isObject(part.state) ? part.state : {};
312
- return [
313
- {
314
- type: 'tool',
315
- tool: part.tool,
316
- status: state.status,
317
- ...(CARD_TOOL.test(part.tool) ? { input: state.input } : {}),
318
- },
319
- ];
467
+ return [toolPart(part.tool, state.status, state.input)];
320
468
  }
321
469
  return [];
322
470
  }),
@@ -324,47 +472,6 @@ export async function pendingYou(input, deps) {
324
472
  }),
325
473
  };
326
474
  };
327
- const idle = async (id) => {
328
- const session = await known(id);
329
- if (session.parent || session.checking)
330
- return;
331
- session.checking = true;
332
- try {
333
- const turn = turnOf(await messagesOf(id, TURN_MESSAGES));
334
- if (!turn)
335
- return;
336
- const said = await deps.run('stopcheck', {
337
- session_id: id,
338
- turn_id: turn.id,
339
- cwd: directory,
340
- messages: turn.messages,
341
- });
342
- let decision;
343
- try {
344
- decision = JSON.parse(said);
345
- }
346
- catch {
347
- return;
348
- }
349
- if (!isObject(decision) || decision.decision !== 'block')
350
- return;
351
- if (typeof decision.reason !== 'string')
352
- return;
353
- const went = await prompt(id, session, {
354
- type: 'text',
355
- text: decision.reason,
356
- synthetic: true,
357
- metadata: { pendingyou: 'stopcheck' },
358
- });
359
- if (went)
360
- await client.tui
361
- .showToast({ body: { title: 'Pending You', message: NUDGED, variant: 'info' } })
362
- .catch(() => { });
363
- }
364
- finally {
365
- session.checking = false;
366
- }
367
- };
368
475
  return {
369
476
  async event({ event }) {
370
477
  try {
@@ -373,56 +480,36 @@ export async function pendingYou(input, deps) {
373
480
  const info = properties.info;
374
481
  if (typeof info.id !== 'string')
375
482
  return;
376
- const session = sessions.get(info.id) ?? {};
377
- session.fresh = true;
378
- session.parent = typeof info.parentID === 'string' && info.parentID ? info.parentID : null;
379
- sessions.set(info.id, session);
380
- if (!session.parent)
381
- live(info.id);
483
+ plugin.created(info.id, typeof info.parentID === 'string' && info.parentID ? info.parentID : null);
382
484
  }
383
485
  else if (event.type === 'session.deleted' && isObject(properties.info)) {
384
486
  const id = properties.info.id;
385
487
  if (typeof id !== 'string')
386
488
  return;
387
- const deleted = sessions.get(id);
388
- if (deleted)
389
- deleted.gone = true;
390
- deleted?.listener?.stop();
391
- sessions.delete(id);
392
- closed(id);
489
+ plugin.deleted(id);
393
490
  }
394
491
  else if (event.type === 'session.status' &&
395
492
  typeof properties.sessionID === 'string' &&
396
493
  isObject(properties.status) &&
397
494
  properties.status.type === 'idle')
398
- await idle(properties.sessionID);
495
+ await plugin.idle(properties.sessionID);
399
496
  }
400
497
  catch { }
401
498
  },
402
499
  async 'chat.message'(input, output) {
403
500
  try {
404
501
  const id = input.sessionID;
405
- const session = await known(id);
406
- if (session.parent)
407
- return;
408
- live(id);
409
- if (typeof output.message.id === 'string')
410
- session.turn = output.message.id;
411
- if (output.parts.some((part) => ourMark(part) !== null))
502
+ if (output.parts.some((part) => ourMark(part) !== null)) {
503
+ if (typeof output.message.id === 'string')
504
+ await plugin.ours(id, output.message.id);
412
505
  return;
413
- session.using = {
506
+ }
507
+ const said = await plugin.message(id, typeof output.message.id === 'string' ? output.message.id : undefined, {
414
508
  ...usingOf(output.message),
415
509
  ...(typeof input.agent === 'string' ? { agent: input.agent } : {}),
416
510
  ...(isObject(input.model) ? { model: input.model } : {}),
417
511
  ...(typeof input.variant === 'string' ? { variant: input.variant } : {}),
418
- };
419
- const first = !session.spoken;
420
- session.spoken = true;
421
- const said = (await deps.run('handoff', {
422
- cwd: directory,
423
- session_id: id,
424
- ...(first ? { source: session.fresh ? 'startup' : 'resume' } : {}),
425
- })).trim();
512
+ });
426
513
  if (said)
427
514
  output.parts.push({
428
515
  id: deps.partId(),
@@ -433,42 +520,239 @@ export async function pendingYou(input, deps) {
433
520
  synthetic: true,
434
521
  metadata: { pendingyou: 'handoff' },
435
522
  });
436
- if (first || deps.wanted?.(id))
437
- listenFor(id, session);
438
523
  }
439
524
  catch { }
440
525
  },
441
526
  async 'tool.execute.after'(input, output) {
442
527
  try {
443
- const named = NAMED_TOOL.test(input.tool);
444
- if (named && !(isObject(input.args) && typeof input.args.name === 'string'))
445
- return;
446
- if (!named && !CARD_TOOL.test(input.tool))
447
- return;
448
- const session = await known(input.sessionID);
449
- const id = session.parent ?? input.sessionID;
450
- const owner = session.parent ? await known(id) : session;
451
- await deps.run('posted', {
452
- session_id: id,
453
- ...(owner.turn ? { turn_id: owner.turn } : {}),
454
- cwd: directory,
455
- tool_name: input.tool,
456
- tool_input: input.args ?? {},
457
- tool_response: output,
458
- });
459
- listenFor(id, owner);
528
+ await plugin.tool(input.tool, input.sessionID, input.args, output);
460
529
  }
461
530
  catch { }
462
531
  },
463
532
  async dispose() {
464
- for (const session of sessions.values()) {
465
- session.gone = true;
466
- session.listener?.stop();
533
+ plugin.dispose();
534
+ },
535
+ };
536
+ }
537
+ const HANDOFF_KEY = 'pendingyouHandoff';
538
+ const markOf = (message) => isObject(message.metadata) && typeof message.metadata.pendingyou === 'string'
539
+ ? message.metadata.pendingyou
540
+ : null;
541
+ function descriptionOf(kind, text) {
542
+ if (kind === 'stopcheck')
543
+ return NUDGED;
544
+ const line = text.split('\n')[0] ?? '';
545
+ const at = line.indexOf('). ');
546
+ return (at > 0 ? line.slice(0, at + 2) : line).slice(0, 300);
547
+ }
548
+ export function turnOfV2(messages) {
549
+ const list = (Array.isArray(messages) ? messages : []).filter(isObject).slice(-TURN_MESSAGES);
550
+ const start = list.findLastIndex((message) => message.type === 'user' ||
551
+ (message.type === 'synthetic' && ['wake', 'stopcheck'].includes(markOf(message) ?? '')));
552
+ const first = list[start];
553
+ if (!first || typeof first.id !== 'string')
554
+ return null;
555
+ return {
556
+ id: first.id,
557
+ messages: list.slice(start).flatMap((message) => {
558
+ const text = typeof message.text === 'string' ? message.text : '';
559
+ if (message === first && message.type === 'user') {
560
+ const handoff = isObject(message.metadata) ? message.metadata[HANDOFF_KEY] : null;
561
+ return [
562
+ {
563
+ id: message.id,
564
+ role: 'user',
565
+ parts: [
566
+ textPart(text),
567
+ ...(typeof handoff === 'string' && handoff
568
+ ? [textPart(handoff, { synthetic: true, pendingyou: 'handoff' })]
569
+ : []),
570
+ ],
571
+ },
572
+ ];
467
573
  }
468
- stopBeat?.();
469
- stopBeat = null;
470
- for (const id of [...present])
471
- closed(id);
574
+ if (message === first) {
575
+ const mark = markOf(message);
576
+ return [
577
+ {
578
+ id: message.id,
579
+ role: 'user',
580
+ parts: [
581
+ textPart(text, {
582
+ ...(mark === 'stopcheck' ? { synthetic: true } : {}),
583
+ pendingyou: mark,
584
+ }),
585
+ ],
586
+ },
587
+ ];
588
+ }
589
+ if (message.type !== 'assistant')
590
+ return [];
591
+ const error = isObject(message.error) && typeof message.error.type === 'string'
592
+ ? message.error.type
593
+ : null;
594
+ const content = (Array.isArray(message.content) ? message.content : []).filter(isObject);
595
+ return [
596
+ {
597
+ id: message.id,
598
+ role: 'assistant',
599
+ ...(error ? { error } : {}),
600
+ parts: content.flatMap((part) => {
601
+ if (part.type === 'text' && typeof part.text === 'string')
602
+ return [textPart(part.text)];
603
+ if (part.type === 'tool' && typeof part.name === 'string') {
604
+ const state = isObject(part.state) ? part.state : {};
605
+ return [toolPart(part.name, state.status, state.input)];
606
+ }
607
+ return [];
608
+ }),
609
+ },
610
+ ];
611
+ }),
612
+ };
613
+ }
614
+ export function toolResponseV2(result) {
615
+ const value = isObject(result) ? result : {};
616
+ const content = typeof value.content === 'string'
617
+ ? [{ type: 'text', text: value.content }]
618
+ : Array.isArray(value.content)
619
+ ? value.content
620
+ : [];
621
+ return { ...(isObject(value.output) ? { structuredContent: value.output } : {}), content };
622
+ }
623
+ export async function pendingYouV2(ctx, deps, directory) {
624
+ const plugin = core({
625
+ parentOf: async (id) => {
626
+ const info = await ctx.session.get({ sessionID: id });
627
+ return isObject(info) && typeof info.parentID === 'string' && info.parentID
628
+ ? info.parentID
629
+ : null;
472
630
  },
631
+ turnOf: async (id) => turnOfV2(await ctx.session.context({ sessionID: id })),
632
+ turnNow: async (id) => turnOfV2(await ctx.session.context({ sessionID: id }))?.id ?? null,
633
+ send: async (id, _session, kind, text) => {
634
+ try {
635
+ const admitted = await ctx.session.synthetic({
636
+ sessionID: id,
637
+ text,
638
+ description: descriptionOf(kind, text),
639
+ metadata: { pendingyou: kind },
640
+ });
641
+ if (isObject(admitted) && typeof admitted.id === 'string')
642
+ await plugin.ours(id, admitted.id);
643
+ return true;
644
+ }
645
+ catch {
646
+ return false;
647
+ }
648
+ },
649
+ }, deps, directory);
650
+ const register = async (run) => {
651
+ try {
652
+ await run();
653
+ }
654
+ catch { }
473
655
  };
656
+ await register(() => ctx.session.hook('prompt', async (event) => {
657
+ try {
658
+ if (isObject(event.metadata) && typeof event.metadata.pendingyou === 'string')
659
+ return;
660
+ const said = await plugin.message(event.sessionID, event.messageID);
661
+ if (said)
662
+ event.metadata = { ...(event.metadata ?? {}), [HANDOFF_KEY]: said };
663
+ }
664
+ catch { }
665
+ }));
666
+ await register(() => ctx.session.hook('context', (event) => {
667
+ try {
668
+ event.messages.forEach((message, index) => {
669
+ const said = isObject(message.metadata) ? message.metadata[HANDOFF_KEY] : null;
670
+ if (message.role !== 'user' || typeof said !== 'string' || !said)
671
+ return;
672
+ const content = Array.isArray(message.content) ? message.content : [];
673
+ const last = content.at(-1);
674
+ if (isObject(last) && last.text === said)
675
+ return;
676
+ event.messages[index] = {
677
+ ...message,
678
+ content: [...content, { type: 'text', text: said }],
679
+ };
680
+ });
681
+ }
682
+ catch { }
683
+ }));
684
+ await register(() => ctx.session.hook('experimental.idle', async (event) => {
685
+ try {
686
+ if (event.background.some((work) => isObject(work) && work.sessionID === event.sessionID))
687
+ return;
688
+ await plugin.idle(event.sessionID);
689
+ }
690
+ catch { }
691
+ }));
692
+ await register(() => ctx.tool.hook('execute.after', async (event) => {
693
+ try {
694
+ if (event.status !== 'completed')
695
+ return;
696
+ await plugin.tool(event.tool, event.sessionID, event.input, toolResponseV2(event.result));
697
+ }
698
+ catch { }
699
+ }));
700
+ const stop = new AbortController();
701
+ void (async () => {
702
+ try {
703
+ for await (const event of ctx.event.subscribe({
704
+ types: ['session.created', 'session.deleted'],
705
+ signal: stop.signal,
706
+ })) {
707
+ if (!isObject(event) || !isObject(event.data))
708
+ continue;
709
+ const id = event.data.sessionID;
710
+ if (typeof id !== 'string')
711
+ continue;
712
+ const parent = event.data.parentID;
713
+ if (event.type === 'session.created')
714
+ plugin.created(id, typeof parent === 'string' && parent ? parent : null);
715
+ else if (event.type === 'session.deleted')
716
+ plugin.deleted(id);
717
+ }
718
+ }
719
+ catch { }
720
+ })();
721
+ const handovers = handoverOf();
722
+ const handed = handovers.get(directory);
723
+ handovers.delete(directory);
724
+ const wasLive = handed && Date.now() - handed.at < HANDOVER_MS
725
+ ? handed.ids.filter((id) => typeof id === 'string')
726
+ : [];
727
+ void (async () => {
728
+ try {
729
+ for (const id of wasLive)
730
+ await plugin.reopen(id, true);
731
+ if (!ctx.session.list)
732
+ return;
733
+ const listed = await ctx.session.list({ directory, limit: RECENT_SESSIONS, order: 'desc' });
734
+ const infos = Array.isArray(listed) ? listed : isObject(listed) ? listed.data : null;
735
+ for (const info of Array.isArray(infos) ? infos.filter(isObject) : [])
736
+ if (typeof info.id === 'string' && !info.parentID && !wasLive.includes(info.id))
737
+ await plugin.reopen(info.id, false);
738
+ }
739
+ catch { }
740
+ })();
741
+ return async () => {
742
+ stop.abort();
743
+ handoverOf().set(directory, { at: Date.now(), ids: plugin.present() });
744
+ plugin.dispose();
745
+ };
746
+ }
747
+ const HANDOVER = Symbol.for('pendingyou.opencode.live');
748
+ const HANDOVER_MS = 60_000;
749
+ function handoverOf() {
750
+ const store = globalThis;
751
+ const found = store[HANDOVER];
752
+ if (found instanceof Map)
753
+ return found;
754
+ const made = new Map();
755
+ store[HANDOVER] = made;
756
+ return made;
474
757
  }
758
+ const RECENT_SESSIONS = 20;
@@ -1,4 +1,4 @@
1
- import { mkdir, rm, rmdir, stat } from 'node:fs/promises';
1
+ import { mkdir, open, rm, rmdir, stat } from 'node:fs/promises';
2
2
  import { basename, dirname, join } from 'node:path';
3
3
  import { fileURLToPath, pathToFileURL } from 'node:url';
4
4
  import { bridgeCommand, bridgeOrigin, bridgePath, checkBridge, isOurBridge, probeBridge, } from "../bridge.js";
@@ -140,20 +140,99 @@ export function toolPermission(value) {
140
140
  export function pluginFile(module) {
141
141
  return `// Pending You for OpenCode: hands it your answers, wakes a session when you answer, and asks it to put what it
142
142
  // leaves you in chat on a card. Written by npx pendingyou init (pendingyou ${VERSION}); run that again to repair it.
143
- export { PendingYou } from ${JSON.stringify(pathToFileURL(module).href)}
143
+ export { default } from ${JSON.stringify(pathToFileURL(module).href)}
144
144
  `;
145
145
  }
146
+ const PLUGIN_LINE = /^export \{ (default|PendingYou) \} from "(file:\/\/[^"]+\/node_modules\/pendingyou\/dist\/apps\/opencode-plugin\.js)"$/m;
146
147
  export function pluginTarget(text) {
147
- const found = /^export \{ PendingYou \} from "(file:\/\/[^"]+\/node_modules\/pendingyou\/dist\/apps\/opencode-plugin\.js)"$/m.exec(text);
148
+ const found = PLUGIN_LINE.exec(text);
148
149
  if (!found)
149
150
  return null;
150
151
  try {
151
- return fileURLToPath(found[1]);
152
+ return fileURLToPath(found[2]);
152
153
  }
153
154
  catch {
154
155
  return null;
155
156
  }
156
157
  }
158
+ export function pluginLineIsOld(text) {
159
+ return PLUGIN_LINE.exec(text)?.[1] === 'PendingYou';
160
+ }
161
+ export const opencodeLogPath = (io) => join(io.env.XDG_DATA_HOME || join(io.home, '.local', 'share'), 'opencode', 'log', 'opencode.log');
162
+ const LOG_TAIL = 2_000_000;
163
+ export function opencodeTier(version) {
164
+ const found = /^(\d+)\.(\d+)\.(\d+)/.exec(version ?? '');
165
+ if (!found)
166
+ return 'all';
167
+ const [major, minor, patch] = found.slice(1).map(Number);
168
+ if (major < 2)
169
+ return 'v1';
170
+ if (major > 2 || minor >= 3)
171
+ return 'all';
172
+ return minor === 2 && patch >= 1 ? 'stopcheck' : 'wake';
173
+ }
174
+ export function tierMisses(tier) {
175
+ if (tier === 'wake')
176
+ return 'it doesn’t hand OpenCode your answers and the setup line with your next message (that takes OpenCode 2.3.0), and doesn’t ask it to put what it leaves you in chat on a card (2.2.1)';
177
+ if (tier === 'stopcheck')
178
+ return 'it doesn’t hand OpenCode your answers and the setup line with your next message (that takes OpenCode 2.3.0)';
179
+ return null;
180
+ }
181
+ export function pluginLoadIn(log, path) {
182
+ const forms = [path, `"${path.replaceAll('\\', '\\\\').replaceAll('"', '\\"')}"`];
183
+ const names = (line, key) => forms.some((form) => line.includes(` ${key}=${form} `) || line.endsWith(` ${key}=${form}`));
184
+ const timeOf = (line) => {
185
+ const at = Date.parse(/^timestamp=(\S+)/.exec(line)?.[1] ?? '');
186
+ return Number.isFinite(at) ? at : null;
187
+ };
188
+ const lines = log.split('\n');
189
+ let loaded = -1;
190
+ let failed = -1;
191
+ lines.forEach((line, index) => {
192
+ if (line.includes('"loading plugin"') && names(line, 'id'))
193
+ loaded = index;
194
+ else if (line.includes('"failed to load plugin"') && names(line, 'target'))
195
+ failed = index;
196
+ });
197
+ if (loaded === -1 && failed === -1)
198
+ return { state: 'unknown' };
199
+ const loadAt = loaded === -1 ? null : timeOf(lines[loaded]);
200
+ const failAt = failed === -1 ? null : timeOf(lines[failed]);
201
+ const refused = failed !== -1 &&
202
+ (loaded === -1 || failed > loaded || (loadAt !== null && failAt !== null && failAt >= loadAt));
203
+ if (!refused)
204
+ return { state: 'loaded' };
205
+ const line = lines[failed];
206
+ const after = line.slice(line.indexOf('cause='));
207
+ const cause = (/Error: ([^"\\(]{1,200})/.exec(after) ??
208
+ /cause="([^"\\(]{1,200})/.exec(after))?.[1];
209
+ return {
210
+ state: 'refused',
211
+ cause: (cause ?? 'it gave no reason').trim().replace(/\.$/, ''),
212
+ at: failAt,
213
+ };
214
+ }
215
+ export function pluginCopyVersion(text) {
216
+ const target = pluginTarget(text);
217
+ return target ? (/\/cli\/([^/]+)\/node_modules\/pendingyou\//.exec(target)?.[1] ?? null) : null;
218
+ }
219
+ async function logTail(path) {
220
+ let file;
221
+ try {
222
+ file = await open(path, 'r');
223
+ const { size } = await file.stat();
224
+ const length = Math.min(size, LOG_TAIL);
225
+ const buffer = Buffer.alloc(length);
226
+ await file.read(buffer, 0, length, size - length);
227
+ return buffer.toString('utf8');
228
+ }
229
+ catch {
230
+ return null;
231
+ }
232
+ finally {
233
+ await file?.close().catch(() => { });
234
+ }
235
+ }
157
236
  const exists = (path) => stat(path).then(() => true, () => false);
158
237
  async function sharedSkill(io) {
159
238
  const on = (name) => !['1', 'true'].includes((io.env[name] ?? '').toLowerCase());
@@ -436,6 +515,12 @@ export const opencode = {
436
515
  report(saved.step);
437
516
  }
438
517
  const plugin = await addPlugin(io, ictx, report);
518
+ const misses = plugin ? tierMisses(opencodeTier(detected.version)) : null;
519
+ if (misses)
520
+ report({
521
+ ok: true,
522
+ text: `OpenCode ${detected.version} runs the plugin only in part: it wakes a session when you answer, but ${misses}. Update OpenCode to 2.3.0 or later, then restart it.`,
523
+ });
439
524
  const manifest = {
440
525
  version: 1,
441
526
  origin: ictx.origin,
@@ -628,16 +713,38 @@ export const opencode = {
628
713
  : `${check.why}; run ${init}`
629
714
  : null;
630
715
  const bridgeOk = !check || (check.ok && reached === null);
631
- const pluginText = await readText(opencodePluginPath(io)).catch(() => null);
716
+ const pluginPath = opencodePluginPath(io);
717
+ const pluginText = await readText(pluginPath).catch(() => null);
632
718
  const target = pluginText === null ? null : pluginTarget(pluginText);
633
- const pluginOk = target !== null && (await exists(target));
719
+ const copied = target !== null && (await exists(target));
720
+ const tier = opencodeTier(detected?.version);
721
+ const v2 = detected !== null && tier !== 'v1';
722
+ const oldLine = pluginText !== null && pluginLineIsOld(pluginText) && v2;
723
+ const logPath = opencodeLogPath(io);
724
+ const load = copied && !oldLine && v2 ? pluginLoadIn((await logTail(logPath)) ?? '', pluginPath) : null;
725
+ const written = load?.state === 'refused'
726
+ ? await stat(pluginPath).then((info) => info.mtimeMs, () => 0)
727
+ : 0;
728
+ const unsure = load?.state === 'unknown';
729
+ const pluginOk = copied && !oldLine && (load === null || load.state === 'loaded');
730
+ const misses = pluginOk ? tierMisses(tier) : null;
634
731
  const pluginLine = pluginText === null
635
732
  ? `not added; run ${init}`
636
733
  : target === null
637
- ? `${opencodePluginPath(io)} isn’t the one init writes; move it, then run ${init}`
638
- : pluginOk
639
- ? `${opencodePluginPath(io)}: hands OpenCode your answers, wakes a session when you answer, and asks it to put what it leaves you in chat on a card`
640
- : `points at a copy of pendingyou that’s gone (${target}); run ${init}`;
734
+ ? `${pluginPath} isn’t the one init writes; move it, then run ${init}`
735
+ : !copied
736
+ ? `points at a copy of pendingyou that’s gone (${target}); run ${init}`
737
+ : oldLine
738
+ ? `${pluginPath} is from a pendingyou before 0.44.0, which OpenCode ${detected?.version} doesn’t load, so it isn’t woken when you answer; run ${init}, then restart OpenCode`
739
+ : load?.state === 'refused'
740
+ ? load.at !== null && written > load.at
741
+ ? `OpenCode couldn’t load it when it last started (${load.cause}); restart OpenCode to load the one init wrote since`
742
+ : `OpenCode couldn’t load it (${load.cause}); run ${init}, then restart OpenCode`
743
+ : unsure
744
+ ? `${pluginPath}, but OpenCode’s log (${logPath}) doesn’t show it loaded it, so that couldn’t be confirmed; start or restart OpenCode, then run status again`
745
+ : misses
746
+ ? `${pluginPath}: wakes a session when you answer, but OpenCode ${detected?.version} runs it only in part: ${misses}; update OpenCode to 2.3.0 or later, then restart it`
747
+ : `${pluginPath}: hands OpenCode your answers, wakes a session when you answer, and asks it to put what it leaves you in chat on a card`;
641
748
  const shared = await sharedSkill(io);
642
749
  const own = (await readText(opencodeSkillPath(io)).catch(() => null)) !== null;
643
750
  const lines = [
@@ -646,7 +753,7 @@ export const opencode = {
646
753
  ` ${mark(detected !== null)} OpenCode: ${detected?.version ?? 'not found on PATH'}`,
647
754
  ` ${mark(mcpOk)} MCP server: ${mcpText}`,
648
755
  ...(bridgeLine ? [` ${mark(bridgeOk)} Bridge: ${bridgeLine}`] : []),
649
- ` ${mark(pluginOk)} Plugin: ${pluginLine}`,
756
+ ` ${unsure ? 'unsure ' : misses ? 'partly ' : mark(pluginOk)} Plugin: ${pluginLine}`,
650
757
  ` ${mark(own || shared !== null)} Skill: ${own ? `saved (${opencodeSkillPath(io)})` : shared ? `OpenCode reads the one at ${shared}` : `not saved; run ${init}`}`,
651
758
  connected && pluginOk
652
759
  ? ' ok Presence: tells Pending You when this session is open (the plugin says so every 5 minutes while OpenCode runs)'
@@ -658,10 +765,14 @@ export const opencode = {
658
765
  const reaches = !bridgeMode || (signOk && mcpOk && bridgeOk);
659
766
  const ready = reaches && signIn.state === 'ok' && mcpOk && pluginOk;
660
767
  lines.push(ready
661
- ? 'Ready: OpenCode hears answers right away (report_setup hears "instant").'
662
- : reaches && mcpOk
663
- ? 'Not ready: OpenCode hears answers only while it’s working until the lines marked missing are fixed.'
664
- : 'Not ready: OpenCode here can’t reach Pending You until the lines marked missing are fixed.');
768
+ ? misses
769
+ ? `Ready in part: OpenCode ${detected?.version} is woken when you answer (report_setup hears "instant"), but not all of Pending You works on it; update OpenCode to 2.3.0 or later.`
770
+ : 'Ready: OpenCode hears answers right away (report_setup hears "instant").'
771
+ : unsure && reaches && mcpOk && signIn.state === 'ok'
772
+ ? 'Not confirmed: OpenCode’s log doesn’t show it loaded the plugin, so whether it’s woken when you answer isn’t known; start or restart OpenCode, then run status again.'
773
+ : reaches && mcpOk
774
+ ? 'Not ready: OpenCode hears answers only while it’s working until the lines marked missing are fixed.'
775
+ : 'Not ready: OpenCode here can’t reach Pending You until the lines marked missing are fixed.');
665
776
  return { lines, ready };
666
777
  },
667
778
  };
package/dist/init.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import { APP_IDS, DEFAULT_APP, namesOf } from "./apps/ids.js";
2
+ import { opencodePluginPath, pluginCopyVersion } from "./apps/opencode.js";
2
3
  import { APPS, appModule, atLeast } from "./apps/registry.js";
3
4
  import { bridgeCommand, removeBridge, writeBridge } from "./bridge.js";
4
5
  import { hookCommand } from "./claude.js";
5
6
  import { readCredential, saveConnectionClient } from "./credentials.js";
7
+ import { readText } from "./files.js";
6
8
  import { hookLine, originArgs } from "./hooks.js";
7
9
  import { installCli, pruneCli, removeCli } from "./install.js";
8
10
  import { linkClients } from "./link.js";
@@ -202,8 +204,11 @@ export async function init(io, options) {
202
204
  installed.push({ each, ictx, done: await each.install(ictx) });
203
205
  }
204
206
  const others = await Promise.all(APPS.filter((app) => !setUp.some((each) => each.app.id === app.id)).map((app) => app.installed(io)));
205
- if (!io.env.PENDINGYOU_SELF && !others.some(Boolean))
206
- await pruneCli(io, shared.copy?.version ?? null);
207
+ if (!io.env.PENDINGYOU_SELF && !others.some(Boolean)) {
208
+ const line = await readText(opencodePluginPath(io)).catch(() => null);
209
+ const pinned = line === null ? null : pluginCopyVersion(line);
210
+ await pruneCli(io, shared.copy?.version ?? null, pinned ? [pinned] : []);
211
+ }
207
212
  for (const { each } of installed)
208
213
  await trustHooks(io, each.app, options.origin);
209
214
  const nexts = [];
package/dist/install.js CHANGED
@@ -108,7 +108,7 @@ function byVersion(a, b) {
108
108
  return 0;
109
109
  }
110
110
  const VERSION_NAME = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/;
111
- export async function pruneCli(io, keep) {
111
+ export async function pruneCli(io, keep, pinned = []) {
112
112
  const root = cliRoot(io);
113
113
  const entries = await readdir(root).catch(() => []);
114
114
  const previous = entries
@@ -116,7 +116,7 @@ export async function pruneCli(io, keep) {
116
116
  .sort(byVersion)
117
117
  .at(-1);
118
118
  for (const entry of entries)
119
- if (entry !== keep && entry !== previous)
119
+ if (entry !== keep && entry !== previous && !pinned.includes(entry))
120
120
  await rm(join(root, entry), { recursive: true, force: true }).catch(() => { });
121
121
  }
122
122
  async function filesUnder(root, at = root) {
package/dist/pickup.js CHANGED
@@ -251,6 +251,8 @@ export async function pickup(io, options, hook = { fallback: '' }) {
251
251
  ['source', app],
252
252
  ...asker.params,
253
253
  ]);
254
+ if (mode === 'handoff' || (await readCredential(io, origin, app)) !== null)
255
+ hook.fallback = `${[line, UNCHECKED, warning].filter(Boolean).join('\n')}\n`;
254
256
  const { status, body } = await getJson(io, origin, `/mcp/cli/answers?${query}`, TIME_BOX_MS[mode], io.signal, {
255
257
  hook: true,
256
258
  patient: true,
package/dist/stopcheck.js CHANGED
@@ -6,7 +6,7 @@ import { markNudged, turnRecord } from "./apps/codex-wake.js";
6
6
  import { APP_NAMES, DEFAULT_APP } from "./apps/ids.js";
7
7
  import { DEFAULT_ORIGIN } from "./args.js";
8
8
  import { asksQuestion, wordsOf } from "./asked.js";
9
- import { asksToTypeHere, cardFits, confirmReason, sessionLink } from "./confirm.js";
9
+ import { asksToTypeHere, cardFits, confirmReason, sessionLink, telling } from "./confirm.js";
10
10
  import { readCredential } from "./credentials.js";
11
11
  import { isHandedWake } from "./format.js";
12
12
  import { isPermissionCard, isPromptApp, sessionName, settlePrompts, subagentsRunning, } from "./permission.js";
@@ -84,11 +84,57 @@ function itemsIn(plain) {
84
84
  }
85
85
  if (STEPS_FOR_THEM.test(plain))
86
86
  return 'steps';
87
- for (const sentence of plain.split(/(?<=[.!?])\s+|\n/))
88
- if (sentence.trim().endsWith('?') && YOU.test(sentence))
89
- return 'question';
90
- return null;
87
+ return questionsIn(plain).length ? 'question' : null;
91
88
  }
89
+ const sentenceEnd = (sentence) => sentence.trim().replace(/[*_\s]+$/, '');
90
+ function lastSentence(plain) {
91
+ let text = plain.trim();
92
+ for (let aside = /\s*\([^()]*\)[\s*_]*$/.exec(text); aside; aside = /\s*\([^()]*\)[\s*_]*$/.exec(text)) {
93
+ const before = text.slice(0, aside.index).trim();
94
+ if (!before)
95
+ break;
96
+ text = before;
97
+ }
98
+ const line = text
99
+ .split('\n')
100
+ .filter((each) => each.trim())
101
+ .at(-1) ?? '';
102
+ return sentenceEnd(line.split(SENTENCE_END).at(-1) ?? '');
103
+ }
104
+ export const endsOnQuestion = (text) => lastSentence(plainText(text)).endsWith('?');
105
+ function questionsIn(plain) {
106
+ const found = plain
107
+ .split(/(?<=[.!?])\s+|\n/)
108
+ .map(sentenceEnd)
109
+ .filter((sentence) => sentence.endsWith('?') && YOU.test(sentence));
110
+ const last = lastSentence(plain);
111
+ return last.endsWith('?') && !found.includes(last) ? [...found, last] : found;
112
+ }
113
+ const ASKING = new Set([
114
+ 'you',
115
+ 'your',
116
+ 'want',
117
+ 'do',
118
+ 'does',
119
+ 'i',
120
+ 'me',
121
+ 'we',
122
+ 'us',
123
+ 'should',
124
+ 'shall',
125
+ 'would',
126
+ 'like',
127
+ 'to',
128
+ 'use',
129
+ ]);
130
+ const tellingOf = (text) => telling(text).filter((word) => !ASKING.has(word));
131
+ export function onCard(question, title) {
132
+ const asked = tellingOf(question);
133
+ const titled = tellingOf(title);
134
+ const within = (part, whole) => part.length >= 2 && part.every((word) => whole.includes(word));
135
+ return within(titled, asked) || within(asked, titled);
136
+ }
137
+ export const questionsOutsideRecaps = (text) => questionsIn(withoutRecaps(plainText(text)));
92
138
  export function itemsForPerson(text) {
93
139
  return itemsIn(plainText(text));
94
140
  }
@@ -334,7 +380,7 @@ function opencodeTurn(input) {
334
380
  const text = final.join('\n').trim();
335
381
  return text ? { text, posted, cards, handed, asked } : null;
336
382
  }
337
- async function openTitles(io, origin, cwd, app, session) {
383
+ async function openTitles(io, origin, cwd, app, session, unlisted = 'unknown') {
338
384
  try {
339
385
  const name = app === 'claude-code' ? await sessionName(session.transcript ?? undefined) : undefined;
340
386
  const query = new URLSearchParams([
@@ -345,9 +391,11 @@ async function openTitles(io, origin, cwd, app, session) {
345
391
  ...(await askerParams(io, origin, app, { ...session, name: name ?? null })),
346
392
  ]);
347
393
  const { status, body } = await getJson(io, origin, `/mcp/cli/answers?${query}`, OPEN_TIME_BOX_MS, io.signal, { hook: true, app });
348
- const requests = status === 200 ? body.open?.requests : undefined;
349
- if (!Array.isArray(requests))
394
+ if (status !== 200)
350
395
  return null;
396
+ const requests = body.open?.requests;
397
+ if (!Array.isArray(requests))
398
+ return unlisted === 'none' ? [] : null;
351
399
  return requests.flatMap((card) => typeof card?.title === 'string' ? [card.title] : []);
352
400
  }
353
401
  catch {
@@ -472,13 +520,25 @@ export async function stopcheck(io, options) {
472
520
  return 0;
473
521
  if (turn.asked && isAnswer(text) && (await seesAnswers(io, app)))
474
522
  return block(ANSWER_REASON);
475
- if (!itemsOutsideRecaps(text))
523
+ const items = itemsOutsideRecaps(text);
524
+ if (!items)
476
525
  return 0;
526
+ let open;
477
527
  if (mentionsCards(text)) {
478
- const open = await openTitles(io, options.origin, cwd, app, session);
528
+ open = await openTitles(io, options.origin, cwd, app, session);
479
529
  if (open === null || open.some((title) => !isPermissionCard(title)))
480
530
  return 0;
481
531
  }
532
+ if (items === 'question') {
533
+ open ??= await openTitles(io, options.origin, cwd, app, session, 'none');
534
+ if (open === null)
535
+ return 0;
536
+ const titles = open;
537
+ const asked = questionsOutsideRecaps(text);
538
+ if (asked.length &&
539
+ asked.every((question) => titles.some((title) => onCard(question, title))))
540
+ return 0;
541
+ }
482
542
  return block(STOP_REASON);
483
543
  }
484
544
  catch {
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.43.3';
1
+ export const VERSION = '0.44.1';
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pendingyou-wake",
3
3
  "displayName": "Pending You",
4
- "version": "2.61.3",
4
+ "version": "2.63.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.61.3; send changes there.
7
+ Generated from recordplane/pendingyou (packages/claude-plugin/src/wake) with Pending You’s guide 2.63.0; send changes there.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pendingyou",
3
- "version": "0.43.3",
3
+ "version": "0.44.1",
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",