pendingyou 0.43.1 → 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 +68 -0
- package/dist/apps/codex-midturn.js +164 -0
- package/dist/apps/codex-wake.js +106 -13
- package/dist/apps/codex.js +9 -1
- package/dist/apps/opencode-plugin.js +11 -5
- package/dist/apps/pi-extension.js +9 -5
- package/dist/args.js +6 -0
- package/dist/drafter/claude-code.js +119 -0
- package/dist/drafter/config.js +35 -0
- package/dist/drafter/eval.js +188 -0
- package/dist/drafter/own-messages.js +18 -0
- package/dist/drafter/prompt.js +124 -0
- package/dist/drafter/tiers.js +106 -0
- package/dist/drafter/types.js +10 -0
- package/dist/drafter/validate.js +240 -0
- package/dist/format.js +1 -1
- package/dist/handed.js +4 -1
- package/dist/io.js +6 -1
- package/dist/main.js +4 -0
- package/dist/midturn.js +54 -0
- package/dist/permission.js +11 -2
- package/dist/pickup.js +12 -2
- package/dist/presence.js +18 -3
- package/dist/setup.js +8 -2
- package/dist/stopcheck.js +16 -0
- package/dist/version.js +1 -1
- package/mod/.claude-plugin/plugin.json +1 -1
- package/mod/README.md +1 -1
- package/mod/hooks/register.js +254 -15
- package/mod/hooks/wake.js +167 -7
- package/package.json +1 -1
package/mod/hooks/register.js
CHANGED
|
@@ -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, blockedNote, CLAIM_PREFIX, CLI_COPY, cardTool, checkArgs, checked, claimedElsewhere, claimHeld, claimLease, cliConfigOf, connectionOf, dueCards, emptyBook, failed, folderOf, graceEnds, HANDED_FAST_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, LISTEN_RUN_MS, LISTENER_KEY, learn, leaseFor, leaseHolder, listenArgv, listened, loadedNote, loadedPath, mayListen, momentOf, originOf, PRESENCE_EVERY_MS, PRESENCE_RUN_MS, presenceArgv, prompted, put, readBook, readClaim, readListener, readSetup, readSignal, readSince, readWait, resultObject, SETUP_AFTER_MS, SETUP_RETRY_MS, SETUP_SERVER, SETUP_TRIES, SIGNAL_KEY, settle, setUpOf, setupNeeded, setupPrompt, stateOf, statusText, TICK_MS, takesHanded, told, toTell, untold, 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,9 @@ const live = {
|
|
|
22
22
|
setupConnection: 'Claude Code',
|
|
23
23
|
seenAt: 0,
|
|
24
24
|
handedAt: 0,
|
|
25
|
+
hinted: new Set(),
|
|
26
|
+
held: [],
|
|
27
|
+
heldRenewedAt: 0,
|
|
25
28
|
handedTold: new Map(),
|
|
26
29
|
folders: [],
|
|
27
30
|
home: undefined,
|
|
@@ -43,8 +46,12 @@ function blockedServer() {
|
|
|
43
46
|
return undefined;
|
|
44
47
|
}
|
|
45
48
|
async function save($) {
|
|
46
|
-
live.book = {
|
|
47
|
-
|
|
49
|
+
live.book = {
|
|
50
|
+
...live.book,
|
|
51
|
+
updatedAt: await $.clock.now(),
|
|
52
|
+
...(live.folders.length ? { folders: live.folders } : {}),
|
|
53
|
+
};
|
|
54
|
+
if (keepsBook(live.book))
|
|
48
55
|
await $.store.set(keyOf(live.sessionId), live.book);
|
|
49
56
|
else
|
|
50
57
|
await $.store.delete(keyOf(live.sessionId));
|
|
@@ -176,17 +183,97 @@ async function deliver($) {
|
|
|
176
183
|
return false;
|
|
177
184
|
live.book = told(live.book, cards);
|
|
178
185
|
await save($);
|
|
179
|
-
|
|
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 () => {
|
|
180
190
|
live.book = untold(live.book, cards);
|
|
181
191
|
live.quietUntil = (await $.clock.now()) + RETRY_MS;
|
|
182
192
|
await save($).catch(() => { });
|
|
183
193
|
});
|
|
184
194
|
return true;
|
|
185
195
|
}
|
|
196
|
+
async function giveBack($, keys, by) {
|
|
197
|
+
if (keys.length === 0)
|
|
198
|
+
return;
|
|
199
|
+
for (const { key, moment } of keys)
|
|
200
|
+
if (claimHeld(await $.store.get(key), moment, by))
|
|
201
|
+
await $.store.delete(key).catch(() => { });
|
|
202
|
+
await $.store.set(SIGNAL_KEY, { at: await $.clock.now() }).catch(() => { });
|
|
203
|
+
}
|
|
204
|
+
async function heldHanded($, now) {
|
|
205
|
+
if (live.held.length === 0)
|
|
206
|
+
return;
|
|
207
|
+
const me = live.sessionId;
|
|
208
|
+
if (live.busy) {
|
|
209
|
+
if (now - live.heldRenewedAt < CLAIM_RENEW_MS)
|
|
210
|
+
return;
|
|
211
|
+
live.heldRenewedAt = now;
|
|
212
|
+
for (const held of live.held)
|
|
213
|
+
if (claimHeld(await $.store.get(held.key), held.moment, me))
|
|
214
|
+
await $.store.set(held.key, { moment: held.moment, at: now, by: me, held: true });
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const holding = live.held;
|
|
218
|
+
live.held = [];
|
|
219
|
+
const { name, server } = live.book;
|
|
220
|
+
const told = [];
|
|
221
|
+
for (const held of holding) {
|
|
222
|
+
if (!claimHeld(await $.store.get(held.key), held.moment, me))
|
|
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
|
+
}
|
|
228
|
+
let view = null;
|
|
229
|
+
let unread = true;
|
|
230
|
+
if (name && server) {
|
|
231
|
+
const args = { requestId: held.handed.requestId, name };
|
|
232
|
+
if (await allowed($, server, args))
|
|
233
|
+
try {
|
|
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
|
+
}
|
|
239
|
+
}
|
|
240
|
+
catch { }
|
|
241
|
+
}
|
|
242
|
+
if (live.sessionId !== me) {
|
|
243
|
+
await giveBack($, holding, me);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (unread) {
|
|
247
|
+
live.handedTold.delete(held.handed.requestId);
|
|
248
|
+
live.handedAt = Math.min(live.handedAt, now + RETRY_MS);
|
|
249
|
+
}
|
|
250
|
+
if (!view) {
|
|
251
|
+
if (claimHeld(await $.store.get(held.key), held.moment, me))
|
|
252
|
+
await $.store.delete(held.key).catch(() => { });
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
await $.store.set(held.key, { moment: held.moment, at: now, by: me });
|
|
256
|
+
told.push({ view, key: held.key });
|
|
257
|
+
}
|
|
258
|
+
if (told.length === 0)
|
|
259
|
+
return;
|
|
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 () => {
|
|
263
|
+
for (const each of told) {
|
|
264
|
+
await $.store.delete(each.key).catch(() => { });
|
|
265
|
+
live.handedTold.delete(each.view.requestId);
|
|
266
|
+
}
|
|
267
|
+
live.handedAt = (await $.clock.now()) + RETRY_MS;
|
|
268
|
+
});
|
|
269
|
+
}
|
|
186
270
|
async function deliverHanded($) {
|
|
187
271
|
const { name, server } = live.book;
|
|
188
272
|
const now = await $.clock.now();
|
|
189
|
-
if (live.
|
|
273
|
+
if (live.book.seenAt && now - live.book.updatedAt > BOOK_TOUCH_MS)
|
|
274
|
+
await save($);
|
|
275
|
+
await heldHanded($, now);
|
|
276
|
+
if (!name || !server || !handedDue(live.seenAt, live.handedAt, now))
|
|
190
277
|
return;
|
|
191
278
|
live.handedAt = handedNext(live.seenAt, now);
|
|
192
279
|
if (!(await allowed($, server, { name }, 'list_pending')))
|
|
@@ -201,6 +288,7 @@ async function deliverHanded($) {
|
|
|
201
288
|
const cards = [];
|
|
202
289
|
const claims = [];
|
|
203
290
|
const me = live.sessionId;
|
|
291
|
+
let others;
|
|
204
292
|
for (const handed of listed) {
|
|
205
293
|
const known = live.handedTold.get(handed.requestId);
|
|
206
294
|
if (readSince(known, handed.updatedAt) || known === handed.updatedAt)
|
|
@@ -212,20 +300,61 @@ async function deliverHanded($) {
|
|
|
212
300
|
continue;
|
|
213
301
|
}
|
|
214
302
|
const key = `${CLAIM_PREFIX}${handed.requestId}`;
|
|
215
|
-
|
|
303
|
+
const before = await $.store.get(key);
|
|
304
|
+
if (claimedElsewhere(before, handed.updatedAt, me, now)) {
|
|
305
|
+
const lapse = claimLapsesAt(before);
|
|
306
|
+
if (lapse !== null)
|
|
307
|
+
live.handedAt = Math.min(live.handedAt, lapse);
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
const mine = claimHeld(before, handed.updatedAt, me);
|
|
311
|
+
const dropped = mine && readClaim(before)?.held === true && !live.held.some((held) => held.key === key);
|
|
312
|
+
const again = dropped || retellDue(before, handed.updatedAt, me, now);
|
|
313
|
+
if (mine && !again) {
|
|
216
314
|
live.handedTold.set(handed.requestId, handed.updatedAt);
|
|
217
315
|
continue;
|
|
218
316
|
}
|
|
317
|
+
const after = graceAfter(handed);
|
|
318
|
+
if (!again && after > now) {
|
|
319
|
+
others ??= await otherBooks($);
|
|
320
|
+
if (newerElsewhere(handed, name, live.seenAt, others, live.home)) {
|
|
321
|
+
live.handedAt = Math.min(live.handedAt, after);
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
219
325
|
const args = { requestId: handed.requestId, name };
|
|
220
326
|
if (!(await allowed($, server, args)))
|
|
221
327
|
continue;
|
|
222
|
-
await $.store.set(key, {
|
|
328
|
+
await $.store.set(key, {
|
|
329
|
+
moment: handed.updatedAt,
|
|
330
|
+
at: now,
|
|
331
|
+
by: me,
|
|
332
|
+
...(live.busy ? { held: true } : {}),
|
|
333
|
+
...(again && !dropped ? { retold: true } : {}),
|
|
334
|
+
});
|
|
335
|
+
if (live.busy) {
|
|
336
|
+
if (live.sessionId !== me) {
|
|
337
|
+
claims.push({ key, moment: handed.updatedAt });
|
|
338
|
+
break;
|
|
339
|
+
}
|
|
340
|
+
live.handedTold.set(handed.requestId, handed.updatedAt);
|
|
341
|
+
if (!claimHeld(await $.store.get(key), handed.updatedAt, me))
|
|
342
|
+
continue;
|
|
343
|
+
if (live.held.length === 0)
|
|
344
|
+
live.heldRenewedAt = now;
|
|
345
|
+
live.held.push({ handed, key, moment: handed.updatedAt });
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
223
348
|
let view = null;
|
|
224
349
|
try {
|
|
225
350
|
view = handedView(resultObject(await $.mcp.call(server, 'get_request', args)), handed, name);
|
|
226
351
|
}
|
|
227
352
|
catch { }
|
|
228
353
|
const stored = await $.store.get(key);
|
|
354
|
+
if (live.sessionId !== me) {
|
|
355
|
+
claims.push({ key, moment: handed.updatedAt });
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
229
358
|
if (!view) {
|
|
230
359
|
if (claimHeld(stored, handed.updatedAt, me))
|
|
231
360
|
await $.store.delete(key);
|
|
@@ -236,13 +365,17 @@ async function deliverHanded($) {
|
|
|
236
365
|
continue;
|
|
237
366
|
}
|
|
238
367
|
live.handedTold.set(handed.requestId, handed.updatedAt);
|
|
239
|
-
claims.push(key);
|
|
368
|
+
claims.push({ key, moment: handed.updatedAt });
|
|
240
369
|
cards.push(view);
|
|
241
370
|
}
|
|
371
|
+
if (live.sessionId !== me) {
|
|
372
|
+
await giveBack($, claims, me);
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
242
375
|
if (cards.length === 0)
|
|
243
376
|
return;
|
|
244
377
|
$.prompt.submit({ text: handedText(cards) }).catch(async () => {
|
|
245
|
-
for (const key of claims)
|
|
378
|
+
for (const { key } of claims)
|
|
246
379
|
await $.store.delete(key).catch(() => { });
|
|
247
380
|
for (const card of cards)
|
|
248
381
|
live.handedTold.delete(card.requestId);
|
|
@@ -277,8 +410,9 @@ async function listenHanded($) {
|
|
|
277
410
|
.then(async (heard) => {
|
|
278
411
|
const at = await $.clock.now();
|
|
279
412
|
const current = readListener(await $.store.get(LISTENER_KEY));
|
|
280
|
-
|
|
281
|
-
|
|
413
|
+
const owner = live.sessionId;
|
|
414
|
+
if (!current || current.by === me || current.by === owner)
|
|
415
|
+
await $.store.set(LISTENER_KEY, listened({ ...lease, by: owner }, heard, at));
|
|
282
416
|
if ('handed' in heard && heard.handed.length) {
|
|
283
417
|
await $.store.set(SIGNAL_KEY, { at });
|
|
284
418
|
live.signalSeen = at;
|
|
@@ -298,6 +432,13 @@ async function heedSignal($) {
|
|
|
298
432
|
live.signalSeen = at;
|
|
299
433
|
live.handedAt = 0;
|
|
300
434
|
}
|
|
435
|
+
async function otherBooks($) {
|
|
436
|
+
const books = [];
|
|
437
|
+
for (const key of await $.store.keys())
|
|
438
|
+
if (key.startsWith('session:') && key !== keyOf(live.sessionId))
|
|
439
|
+
books.push(readBook(await $.store.get(key)));
|
|
440
|
+
return books;
|
|
441
|
+
}
|
|
301
442
|
async function prune($) {
|
|
302
443
|
const now = await $.clock.now();
|
|
303
444
|
for (const key of await $.store.keys()) {
|
|
@@ -398,7 +539,7 @@ function soon($) {
|
|
|
398
539
|
catch { }
|
|
399
540
|
}
|
|
400
541
|
function freshHanded() {
|
|
401
|
-
live.seenAt = Object.keys(live.book.cards).length ? live.book.updatedAt : 0;
|
|
542
|
+
live.seenAt = live.book.seenAt ?? (Object.keys(live.book.cards).length ? live.book.updatedAt : 0);
|
|
402
543
|
live.handedAt = 0;
|
|
403
544
|
live.handedTold = new Map();
|
|
404
545
|
}
|
|
@@ -425,6 +566,8 @@ async function sayLive($) {
|
|
|
425
566
|
const presence = live.presence;
|
|
426
567
|
if (!presence || !live.sessionId)
|
|
427
568
|
return;
|
|
569
|
+
if (!live.book.name)
|
|
570
|
+
await recallName($);
|
|
428
571
|
const argv = presenceArgv(presence.config, presence.origin, {
|
|
429
572
|
id: live.sessionId,
|
|
430
573
|
...(live.folders[0] ? { cwd: live.folders[0] } : {}),
|
|
@@ -454,12 +597,38 @@ async function startPresence($) {
|
|
|
454
597
|
await sayLive($);
|
|
455
598
|
live.presenceTimer = $.clock.every(PRESENCE_EVERY_MS, () => sayLive($));
|
|
456
599
|
}
|
|
600
|
+
async function recallName($) {
|
|
601
|
+
try {
|
|
602
|
+
const config = cliConfigOf($.plugin.root, $.plugin.name);
|
|
603
|
+
if (live.book.name || live.book.fork || !config || !live.sessionId)
|
|
604
|
+
return;
|
|
605
|
+
const name = presenceNameOf(await $.fs.read(`${config}/presence/claude-code.json`), live.sessionId);
|
|
606
|
+
if (!name)
|
|
607
|
+
return;
|
|
608
|
+
const now = await $.clock.now();
|
|
609
|
+
live.book = {
|
|
610
|
+
...live.book,
|
|
611
|
+
name,
|
|
612
|
+
server: live.book.server ?? SETUP_SERVER,
|
|
613
|
+
seenAt: live.book.seenAt ?? Math.max(1, now - HANDED_FOR_MS),
|
|
614
|
+
};
|
|
615
|
+
if (!live.seenAt) {
|
|
616
|
+
live.seenAt = live.book.seenAt ?? 0;
|
|
617
|
+
live.handedAt = 0;
|
|
618
|
+
}
|
|
619
|
+
await save($);
|
|
620
|
+
}
|
|
621
|
+
catch { }
|
|
622
|
+
}
|
|
457
623
|
async function start($, e) {
|
|
458
624
|
live.me = $.plugin.name;
|
|
459
625
|
live.sessionId = await $.session.id();
|
|
460
626
|
live.book = readBook(await $.store.get(keyOf(live.sessionId)));
|
|
627
|
+
await recallName($);
|
|
461
628
|
freshHanded();
|
|
462
629
|
await folderOfSession($, e.cwd);
|
|
630
|
+
if (live.book.name && live.book.seenAt)
|
|
631
|
+
await save($);
|
|
463
632
|
await noteLoaded($);
|
|
464
633
|
await claim($);
|
|
465
634
|
live.timer?.cancel();
|
|
@@ -474,9 +643,19 @@ async function switchSession($, e) {
|
|
|
474
643
|
const id = typeof e.session_id === 'string' && e.session_id ? e.session_id : await $.session.id();
|
|
475
644
|
if (!id || id === live.sessionId)
|
|
476
645
|
return;
|
|
477
|
-
const
|
|
646
|
+
const { seenAt: _seen, name: _name, ...forked } = live.book;
|
|
647
|
+
const carried = e.source === 'fork' ? { ...forked, fork: true } : null;
|
|
648
|
+
const was = live.sessionId;
|
|
478
649
|
live.sessionId = id;
|
|
650
|
+
const held = live.held;
|
|
651
|
+
live.held = [];
|
|
652
|
+
await giveBack($, held, was);
|
|
653
|
+
const listener = readListener(await $.store.get(LISTENER_KEY));
|
|
654
|
+
if (listener?.by === was)
|
|
655
|
+
await $.store.set(LISTENER_KEY, { ...listener, by: id });
|
|
479
656
|
live.book = carried ?? readBook(await $.store.get(keyOf(id)));
|
|
657
|
+
if (e.source === 'resume')
|
|
658
|
+
await recallName($);
|
|
480
659
|
live.noted.clear();
|
|
481
660
|
live.words.clear();
|
|
482
661
|
freshHanded();
|
|
@@ -497,7 +676,8 @@ async function observe($, e, result) {
|
|
|
497
676
|
if ($.plugin.name === CLI_COPY && found.tool === 'whoami' && setUpOf(output) === true)
|
|
498
677
|
await setupDone($);
|
|
499
678
|
const now = await $.clock.now();
|
|
500
|
-
|
|
679
|
+
const subagent = typeof e.agentId === 'string' && e.agentId !== '';
|
|
680
|
+
if (output && !subagent) {
|
|
501
681
|
live.seenAt = now;
|
|
502
682
|
live.handedAt = Math.min(live.handedAt, now + HANDED_FAST_MS);
|
|
503
683
|
}
|
|
@@ -509,6 +689,10 @@ async function observe($, e, result) {
|
|
|
509
689
|
live.folders = [...live.folders, folder].slice(-5);
|
|
510
690
|
const before = live.book;
|
|
511
691
|
live.book = learn(live.book, { ...found, input: argumentsOf(e), output }, now);
|
|
692
|
+
if (subagent)
|
|
693
|
+
live.book = nameKept(live.book, before);
|
|
694
|
+
else if (output)
|
|
695
|
+
live.book = used(live.book, now);
|
|
512
696
|
if (live.book === before)
|
|
513
697
|
return result;
|
|
514
698
|
await save($);
|
|
@@ -554,7 +738,60 @@ async function answerHold($, e) {
|
|
|
554
738
|
const answer = live.book.cards[requestId]?.kind === 'answer';
|
|
555
739
|
return { result: { stdout: holdReply(requestId, answer), stderr: '', interrupted: false } };
|
|
556
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
|
+
}
|
|
557
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
|
+
});
|
|
558
795
|
on('session.start', async ($, e, next) => {
|
|
559
796
|
try {
|
|
560
797
|
await start($, e);
|
|
@@ -570,8 +807,10 @@ export function register(on) {
|
|
|
570
807
|
return next(e);
|
|
571
808
|
});
|
|
572
809
|
on('turn.start', async (_, e, next) => {
|
|
573
|
-
if (!e.agentId)
|
|
810
|
+
if (!e.agentId) {
|
|
574
811
|
live.busy = true;
|
|
812
|
+
live.hinted.clear();
|
|
813
|
+
}
|
|
575
814
|
return next(e);
|
|
576
815
|
});
|
|
577
816
|
on('turn.complete', async ($, e, next) => {
|
package/mod/hooks/wake.js
CHANGED
|
@@ -175,6 +175,17 @@ export function readBook(value) {
|
|
|
175
175
|
...(typeof value.server === 'string' && isPendingYou(value.server)
|
|
176
176
|
? { server: value.server }
|
|
177
177
|
: {}),
|
|
178
|
+
...(count(value.seenAt) ? { seenAt: count(value.seenAt) } : {}),
|
|
179
|
+
...(Array.isArray(value.folders)
|
|
180
|
+
? (() => {
|
|
181
|
+
const folders = value.folders
|
|
182
|
+
.map((folder) => text(folder, 1000))
|
|
183
|
+
.filter((folder) => folder !== undefined)
|
|
184
|
+
.slice(-5);
|
|
185
|
+
return folders.length ? { folders } : {};
|
|
186
|
+
})()
|
|
187
|
+
: {}),
|
|
188
|
+
...(value.fork === true ? { fork: true } : {}),
|
|
178
189
|
cards,
|
|
179
190
|
};
|
|
180
191
|
}
|
|
@@ -523,7 +534,15 @@ function plainLine(card, get, state) {
|
|
|
523
534
|
}
|
|
524
535
|
}
|
|
525
536
|
const capital = (sentence) => sentence.charAt(0).toUpperCase() + sentence.slice(1);
|
|
526
|
-
export
|
|
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) {
|
|
527
546
|
const asked = cards.some((card) => card.state?.turn === 'agent' &&
|
|
528
547
|
!isClosed(card.state.status) &&
|
|
529
548
|
card.state.status !== 'delegated' &&
|
|
@@ -691,6 +710,9 @@ export function claimLease(value, me, now) {
|
|
|
691
710
|
export const HANDED_FAST_MS = 60_000;
|
|
692
711
|
export const HANDED_SLOW_MS = 3 * 60_000;
|
|
693
712
|
export const HANDED_FOR_MS = 12 * 60 * 60_000;
|
|
713
|
+
export const HANDED_IDLE_MS = 10 * 60_000;
|
|
714
|
+
const USED_EVERY_MS = 60_000;
|
|
715
|
+
export const BOOK_TOUCH_MS = 24 * 60 * 60_000;
|
|
694
716
|
export const HANDED_GRACE_MS = 30_000;
|
|
695
717
|
export const CLAIM_PREFIX = 'handed:';
|
|
696
718
|
export const HANDED_PREFIX = 'Pending You: your person handed you';
|
|
@@ -716,8 +738,39 @@ export function readSince(known, updatedAt) {
|
|
|
716
738
|
const at = Number(known.slice(1));
|
|
717
739
|
return !Number.isFinite(at) || at === 0 || Date.parse(updatedAt) <= at;
|
|
718
740
|
}
|
|
719
|
-
export const handedDue = (seenAt, nextAt, now) => seenAt > 0 && now
|
|
720
|
-
export const handedNext = (seenAt, now) => now +
|
|
741
|
+
export const handedDue = (seenAt, nextAt, now) => seenAt > 0 && now >= nextAt;
|
|
742
|
+
export const handedNext = (seenAt, now) => now +
|
|
743
|
+
(now - seenAt < RECENT_MS
|
|
744
|
+
? HANDED_FAST_MS
|
|
745
|
+
: now - seenAt < HANDED_FOR_MS
|
|
746
|
+
? HANDED_SLOW_MS
|
|
747
|
+
: HANDED_IDLE_MS);
|
|
748
|
+
export const keepsBook = (book) => Object.keys(book.cards).length > 0 || Boolean(book.name && book.seenAt) || book.fork === true;
|
|
749
|
+
export function nameKept(book, before) {
|
|
750
|
+
if (book.name === before.name && book.server === before.server)
|
|
751
|
+
return book;
|
|
752
|
+
const { name: _name, server: _server, ...rest } = book;
|
|
753
|
+
return {
|
|
754
|
+
...rest,
|
|
755
|
+
...(before.name ? { name: before.name } : {}),
|
|
756
|
+
...(before.server ? { server: before.server } : {}),
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
const nameKeyOf = (name) => name.trim().toLowerCase().replace(/\s+/g, ' ');
|
|
760
|
+
export function newerElsewhere(handed, name, seenAt, books, home) {
|
|
761
|
+
const key = nameKeyOf(name);
|
|
762
|
+
return books.some((book) => book.name !== undefined &&
|
|
763
|
+
nameKeyOf(book.name) === key &&
|
|
764
|
+
(book.seenAt ?? 0) > seenAt &&
|
|
765
|
+
(handed.byName ||
|
|
766
|
+
!handed.cwd ||
|
|
767
|
+
!book.folders?.length ||
|
|
768
|
+
inTaskFolder(book.folders, handed.cwd, home)));
|
|
769
|
+
}
|
|
770
|
+
export const graceAfter = (handed) => Date.parse(handed.updatedAt) + HANDED_GRACE_MS;
|
|
771
|
+
export const used = (book, now) => book.seenAt !== undefined && now - book.seenAt < USED_EVERY_MS && now >= book.seenAt
|
|
772
|
+
? book
|
|
773
|
+
: { ...book, seenAt: now };
|
|
721
774
|
export function handedOf(output) {
|
|
722
775
|
const requests = output && Array.isArray(output.requests) ? output.requests : [];
|
|
723
776
|
return requests.flatMap((request) => {
|
|
@@ -800,20 +853,44 @@ export function handedView(output, handed, name) {
|
|
|
800
853
|
...(said ? { said } : {}),
|
|
801
854
|
};
|
|
802
855
|
}
|
|
856
|
+
export const CLAIM_RENEW_MS = 60_000;
|
|
857
|
+
export const CLAIM_LAPSE_MS = 3 * 60_000;
|
|
858
|
+
export const RETELL_AFTER_MS = 10 * 60_000;
|
|
803
859
|
export function readClaim(value) {
|
|
804
860
|
if (!isObject(value) || typeof value.moment !== 'string')
|
|
805
861
|
return null;
|
|
806
862
|
const by = text(value.by, 200);
|
|
807
|
-
return {
|
|
863
|
+
return {
|
|
864
|
+
moment: value.moment,
|
|
865
|
+
at: count(value.at) ?? 0,
|
|
866
|
+
...(by ? { by } : {}),
|
|
867
|
+
...(value.held === true ? { held: true } : {}),
|
|
868
|
+
...(value.retold === true ? { retold: true } : {}),
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
const lapsed = (claim, now) => claim.held === true && now - claim.at >= CLAIM_LAPSE_MS;
|
|
872
|
+
export function claimedElsewhere(value, moment, me, now) {
|
|
873
|
+
const claim = readClaim(value);
|
|
874
|
+
if (claim?.moment !== moment || claim.by === me)
|
|
875
|
+
return false;
|
|
876
|
+
return now === undefined || !lapsed(claim, now);
|
|
808
877
|
}
|
|
809
|
-
export function
|
|
878
|
+
export function claimLapsesAt(value) {
|
|
810
879
|
const claim = readClaim(value);
|
|
811
|
-
return claim?.
|
|
880
|
+
return claim?.held ? claim.at + CLAIM_LAPSE_MS : null;
|
|
812
881
|
}
|
|
813
882
|
export function claimHeld(value, moment, me) {
|
|
814
883
|
const claim = readClaim(value);
|
|
815
884
|
return claim?.moment === moment && claim.by === me;
|
|
816
885
|
}
|
|
886
|
+
export function retellDue(value, moment, me, now) {
|
|
887
|
+
const claim = readClaim(value);
|
|
888
|
+
return (claim?.moment === moment &&
|
|
889
|
+
claim.by === me &&
|
|
890
|
+
!claim.held &&
|
|
891
|
+
!claim.retold &&
|
|
892
|
+
now - claim.at >= RETELL_AFTER_MS);
|
|
893
|
+
}
|
|
817
894
|
export const LISTENER_KEY = 'handed-listener';
|
|
818
895
|
export const SIGNAL_KEY = 'handed-signal';
|
|
819
896
|
export const LISTEN_RUN_MS = 4 * 60_000;
|
|
@@ -835,7 +912,7 @@ export function readListener(value) {
|
|
|
835
912
|
return { by, until, ...(since ? { since } : {}), ...(quietUntil ? { quietUntil } : {}) };
|
|
836
913
|
}
|
|
837
914
|
export function mayListen(record, me, seenAt, now) {
|
|
838
|
-
if (seenAt <= 0
|
|
915
|
+
if (seenAt <= 0)
|
|
839
916
|
return false;
|
|
840
917
|
if (record?.quietUntil && now < record.quietUntil)
|
|
841
918
|
return false;
|
|
@@ -990,6 +1067,21 @@ export function originOf(manifest) {
|
|
|
990
1067
|
const origin = typeof parsed === 'object' && parsed !== null ? parsed.origin : null;
|
|
991
1068
|
return typeof origin === 'string' && /^https?:\/\/[^\s/]+$/.test(origin) ? origin : null;
|
|
992
1069
|
}
|
|
1070
|
+
export function presenceNameOf(record, sessionId) {
|
|
1071
|
+
let parsed = record;
|
|
1072
|
+
if (typeof record === 'string')
|
|
1073
|
+
try {
|
|
1074
|
+
parsed = JSON.parse(record);
|
|
1075
|
+
}
|
|
1076
|
+
catch {
|
|
1077
|
+
return undefined;
|
|
1078
|
+
}
|
|
1079
|
+
const sessions = isObject(parsed) && isObject(parsed.sessions) ? parsed.sessions : null;
|
|
1080
|
+
if (!sessions || !sessionId || !Object.hasOwn(sessions, sessionId))
|
|
1081
|
+
return undefined;
|
|
1082
|
+
const said = sessions[sessionId];
|
|
1083
|
+
return isObject(said) ? text(said.name, 120) : undefined;
|
|
1084
|
+
}
|
|
993
1085
|
export function presenceArgv(config, origin, session) {
|
|
994
1086
|
return [
|
|
995
1087
|
`${config}/bin/pendingyou-hook`,
|
|
@@ -1041,3 +1133,71 @@ export function herdrArgv(config, session) {
|
|
|
1041
1133
|
String(Math.floor(session.at)),
|
|
1042
1134
|
];
|
|
1043
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.
|
|
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",
|