pendingyou 0.43.0 → 0.43.2
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 +51 -0
- package/dist/apps/codex-wake.js +33 -6
- package/dist/apps/opencode-plugin.js +11 -5
- package/dist/apps/pi-extension.js +8 -4
- package/dist/args.js +2 -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/handed.js +4 -1
- package/dist/io.js +6 -1
- package/dist/main.js +1 -0
- package/dist/permission.js +3 -1
- package/dist/pickup.js +9 -2
- package/dist/presence.js +18 -3
- package/dist/setup.js +8 -2
- 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 +208 -26
- package/mod/hooks/wake.js +159 -12
- package/package.json +1 -1
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
|
}
|
|
@@ -417,9 +428,71 @@ export function settle(book, now) {
|
|
|
417
428
|
export const isStale = (book, now) => now - book.updatedAt > KEEP_MS;
|
|
418
429
|
const titled = (card) => card.title ? `“${clip(card.title)}” (${card.requestId})` : card.requestId;
|
|
419
430
|
const named = (card) => (card.name ? `name “${card.name}”` : 'your name');
|
|
420
|
-
|
|
431
|
+
export const WORDS_CHARS = 600;
|
|
432
|
+
export function wordsOf(output) {
|
|
433
|
+
const state = stateOf(output);
|
|
434
|
+
if (state?.status !== 'answered' || state.turn !== 'agent' || state.approvedDraft)
|
|
435
|
+
return undefined;
|
|
436
|
+
const given = isObject(output.answer) ? output.answer.words : undefined;
|
|
437
|
+
if (typeof given !== 'string')
|
|
438
|
+
return undefined;
|
|
439
|
+
const flat = given.replace(/\s+/g, ' ').trim().replaceAll('“', '‘').replaceAll('”', '’');
|
|
440
|
+
if (!flat)
|
|
441
|
+
return undefined;
|
|
442
|
+
const chars = [...flat];
|
|
443
|
+
const cut = chars.length > WORDS_CHARS;
|
|
444
|
+
const text = cut
|
|
445
|
+
? `${chars
|
|
446
|
+
.slice(0, WORDS_CHARS - 1)
|
|
447
|
+
.join('')
|
|
448
|
+
.trimEnd()}…`
|
|
449
|
+
: flat;
|
|
450
|
+
return { moment: momentOf(state), text, cut };
|
|
451
|
+
}
|
|
452
|
+
export const checkArgs = (card, words) => ({
|
|
453
|
+
requestId: card.requestId,
|
|
454
|
+
...(card.name ? { name: card.name } : {}),
|
|
455
|
+
...(words ? { words: true } : {}),
|
|
456
|
+
});
|
|
457
|
+
function wordsFor(card, words) {
|
|
458
|
+
const state = card.state;
|
|
459
|
+
if (!words || !state || card.kind === 'answer')
|
|
460
|
+
return undefined;
|
|
461
|
+
if (state.status !== 'answered' || state.approvedDraft)
|
|
462
|
+
return undefined;
|
|
463
|
+
return words.moment === momentOf(state) ? words : undefined;
|
|
464
|
+
}
|
|
465
|
+
function line(card, given) {
|
|
421
466
|
const state = card.state;
|
|
422
467
|
const get = `get_request (requestId ${card.requestId}, ${named(card)})`;
|
|
468
|
+
const words = wordsFor(card, given);
|
|
469
|
+
if (words) {
|
|
470
|
+
const ack = `ack_answer (requestId ${card.requestId}, ${named(card)}, expectedVersion ${state.version})`;
|
|
471
|
+
const quoted = `: “${words.text}”`;
|
|
472
|
+
const after = words.cut ? `Cut short: ${get} has all of it.` : undefined;
|
|
473
|
+
const rest = { quoted: true, ...(after ? { after } : {}) };
|
|
474
|
+
if (state.handled === 'self')
|
|
475
|
+
return {
|
|
476
|
+
happened: `your person will handle ${titled(card)} themselves${quoted}`,
|
|
477
|
+
todo: `close it out: take no action on it, leave things as they are and don’t follow up; ${ack} with an outcome like “Left to you”`,
|
|
478
|
+
...rest,
|
|
479
|
+
};
|
|
480
|
+
if (state.handled === 'leave')
|
|
481
|
+
return {
|
|
482
|
+
happened: `your person won’t do ${titled(card)}${quoted}`,
|
|
483
|
+
todo: `close it out: don’t do it for them and don’t follow up; ${ack} with an outcome like “Skipped”`,
|
|
484
|
+
...rest,
|
|
485
|
+
};
|
|
486
|
+
return {
|
|
487
|
+
happened: `your person answered ${titled(card)}${quoted}`,
|
|
488
|
+
todo: `act on their words, then ${ack} with a one-line outcome`,
|
|
489
|
+
...rest,
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
const [happened, todo] = plainLine(card, get, state);
|
|
493
|
+
return { happened, todo };
|
|
494
|
+
}
|
|
495
|
+
function plainLine(card, get, state) {
|
|
423
496
|
if (card.kind === 'answer')
|
|
424
497
|
return [
|
|
425
498
|
`your person replied to your answer ${titled(card)}`,
|
|
@@ -461,7 +534,7 @@ function line(card) {
|
|
|
461
534
|
}
|
|
462
535
|
}
|
|
463
536
|
const capital = (sentence) => sentence.charAt(0).toUpperCase() + sentence.slice(1);
|
|
464
|
-
export function wakeText(cards) {
|
|
537
|
+
export function wakeText(cards, words) {
|
|
465
538
|
const asked = cards.some((card) => card.state?.turn === 'agent' &&
|
|
466
539
|
!isClosed(card.state.status) &&
|
|
467
540
|
card.state.status !== 'delegated' &&
|
|
@@ -469,15 +542,16 @@ export function wakeText(cards) {
|
|
|
469
542
|
const reopen = asked
|
|
470
543
|
? ' If you need more from them, or the next step, post a new card with follows: that card’s requestId; never reopen.'
|
|
471
544
|
: '';
|
|
545
|
+
const lineOf = (card) => line(card, words?.get(card.requestId));
|
|
472
546
|
if (cards.length === 1) {
|
|
473
|
-
const
|
|
474
|
-
return `Pending You: ${happened}. ${capital(todo)}.${reopen}`;
|
|
547
|
+
const { happened, todo, quoted, after } = lineOf(cards[0]);
|
|
548
|
+
return `Pending You: ${happened}${quoted ? '' : '.'} ${capital(todo)}.${after ? ` ${after}` : ''}${reopen}`;
|
|
475
549
|
}
|
|
476
550
|
return [
|
|
477
551
|
`Pending You: ${cards.length} of your cards need you.`,
|
|
478
552
|
...cards.map((card) => {
|
|
479
|
-
const
|
|
480
|
-
return `- ${capital(happened)}: ${todo}
|
|
553
|
+
const { happened, todo, after } = lineOf(card);
|
|
554
|
+
return `- ${capital(happened)}: ${todo}.${after ? ` ${after}` : ''}`;
|
|
481
555
|
}),
|
|
482
556
|
...(reopen ? [reopen.trim()] : []),
|
|
483
557
|
].join('\n');
|
|
@@ -628,6 +702,9 @@ export function claimLease(value, me, now) {
|
|
|
628
702
|
export const HANDED_FAST_MS = 60_000;
|
|
629
703
|
export const HANDED_SLOW_MS = 3 * 60_000;
|
|
630
704
|
export const HANDED_FOR_MS = 12 * 60 * 60_000;
|
|
705
|
+
export const HANDED_IDLE_MS = 10 * 60_000;
|
|
706
|
+
const USED_EVERY_MS = 60_000;
|
|
707
|
+
export const BOOK_TOUCH_MS = 24 * 60 * 60_000;
|
|
631
708
|
export const HANDED_GRACE_MS = 30_000;
|
|
632
709
|
export const CLAIM_PREFIX = 'handed:';
|
|
633
710
|
export const HANDED_PREFIX = 'Pending You: your person handed you';
|
|
@@ -653,8 +730,39 @@ export function readSince(known, updatedAt) {
|
|
|
653
730
|
const at = Number(known.slice(1));
|
|
654
731
|
return !Number.isFinite(at) || at === 0 || Date.parse(updatedAt) <= at;
|
|
655
732
|
}
|
|
656
|
-
export const handedDue = (seenAt, nextAt, now) => seenAt > 0 && now
|
|
657
|
-
export const handedNext = (seenAt, now) => now +
|
|
733
|
+
export const handedDue = (seenAt, nextAt, now) => seenAt > 0 && now >= nextAt;
|
|
734
|
+
export const handedNext = (seenAt, now) => now +
|
|
735
|
+
(now - seenAt < RECENT_MS
|
|
736
|
+
? HANDED_FAST_MS
|
|
737
|
+
: now - seenAt < HANDED_FOR_MS
|
|
738
|
+
? HANDED_SLOW_MS
|
|
739
|
+
: HANDED_IDLE_MS);
|
|
740
|
+
export const keepsBook = (book) => Object.keys(book.cards).length > 0 || Boolean(book.name && book.seenAt) || book.fork === true;
|
|
741
|
+
export function nameKept(book, before) {
|
|
742
|
+
if (book.name === before.name && book.server === before.server)
|
|
743
|
+
return book;
|
|
744
|
+
const { name: _name, server: _server, ...rest } = book;
|
|
745
|
+
return {
|
|
746
|
+
...rest,
|
|
747
|
+
...(before.name ? { name: before.name } : {}),
|
|
748
|
+
...(before.server ? { server: before.server } : {}),
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
const nameKeyOf = (name) => name.trim().toLowerCase().replace(/\s+/g, ' ');
|
|
752
|
+
export function newerElsewhere(handed, name, seenAt, books, home) {
|
|
753
|
+
const key = nameKeyOf(name);
|
|
754
|
+
return books.some((book) => book.name !== undefined &&
|
|
755
|
+
nameKeyOf(book.name) === key &&
|
|
756
|
+
(book.seenAt ?? 0) > seenAt &&
|
|
757
|
+
(handed.byName ||
|
|
758
|
+
!handed.cwd ||
|
|
759
|
+
!book.folders?.length ||
|
|
760
|
+
inTaskFolder(book.folders, handed.cwd, home)));
|
|
761
|
+
}
|
|
762
|
+
export const graceAfter = (handed) => Date.parse(handed.updatedAt) + HANDED_GRACE_MS;
|
|
763
|
+
export const used = (book, now) => book.seenAt !== undefined && now - book.seenAt < USED_EVERY_MS && now >= book.seenAt
|
|
764
|
+
? book
|
|
765
|
+
: { ...book, seenAt: now };
|
|
658
766
|
export function handedOf(output) {
|
|
659
767
|
const requests = output && Array.isArray(output.requests) ? output.requests : [];
|
|
660
768
|
return requests.flatMap((request) => {
|
|
@@ -737,20 +845,44 @@ export function handedView(output, handed, name) {
|
|
|
737
845
|
...(said ? { said } : {}),
|
|
738
846
|
};
|
|
739
847
|
}
|
|
848
|
+
export const CLAIM_RENEW_MS = 60_000;
|
|
849
|
+
export const CLAIM_LAPSE_MS = 3 * 60_000;
|
|
850
|
+
export const RETELL_AFTER_MS = 10 * 60_000;
|
|
740
851
|
export function readClaim(value) {
|
|
741
852
|
if (!isObject(value) || typeof value.moment !== 'string')
|
|
742
853
|
return null;
|
|
743
854
|
const by = text(value.by, 200);
|
|
744
|
-
return {
|
|
855
|
+
return {
|
|
856
|
+
moment: value.moment,
|
|
857
|
+
at: count(value.at) ?? 0,
|
|
858
|
+
...(by ? { by } : {}),
|
|
859
|
+
...(value.held === true ? { held: true } : {}),
|
|
860
|
+
...(value.retold === true ? { retold: true } : {}),
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
const lapsed = (claim, now) => claim.held === true && now - claim.at >= CLAIM_LAPSE_MS;
|
|
864
|
+
export function claimedElsewhere(value, moment, me, now) {
|
|
865
|
+
const claim = readClaim(value);
|
|
866
|
+
if (claim?.moment !== moment || claim.by === me)
|
|
867
|
+
return false;
|
|
868
|
+
return now === undefined || !lapsed(claim, now);
|
|
745
869
|
}
|
|
746
|
-
export function
|
|
870
|
+
export function claimLapsesAt(value) {
|
|
747
871
|
const claim = readClaim(value);
|
|
748
|
-
return claim?.
|
|
872
|
+
return claim?.held ? claim.at + CLAIM_LAPSE_MS : null;
|
|
749
873
|
}
|
|
750
874
|
export function claimHeld(value, moment, me) {
|
|
751
875
|
const claim = readClaim(value);
|
|
752
876
|
return claim?.moment === moment && claim.by === me;
|
|
753
877
|
}
|
|
878
|
+
export function retellDue(value, moment, me, now) {
|
|
879
|
+
const claim = readClaim(value);
|
|
880
|
+
return (claim?.moment === moment &&
|
|
881
|
+
claim.by === me &&
|
|
882
|
+
!claim.held &&
|
|
883
|
+
!claim.retold &&
|
|
884
|
+
now - claim.at >= RETELL_AFTER_MS);
|
|
885
|
+
}
|
|
754
886
|
export const LISTENER_KEY = 'handed-listener';
|
|
755
887
|
export const SIGNAL_KEY = 'handed-signal';
|
|
756
888
|
export const LISTEN_RUN_MS = 4 * 60_000;
|
|
@@ -772,7 +904,7 @@ export function readListener(value) {
|
|
|
772
904
|
return { by, until, ...(since ? { since } : {}), ...(quietUntil ? { quietUntil } : {}) };
|
|
773
905
|
}
|
|
774
906
|
export function mayListen(record, me, seenAt, now) {
|
|
775
|
-
if (seenAt <= 0
|
|
907
|
+
if (seenAt <= 0)
|
|
776
908
|
return false;
|
|
777
909
|
if (record?.quietUntil && now < record.quietUntil)
|
|
778
910
|
return false;
|
|
@@ -927,6 +1059,21 @@ export function originOf(manifest) {
|
|
|
927
1059
|
const origin = typeof parsed === 'object' && parsed !== null ? parsed.origin : null;
|
|
928
1060
|
return typeof origin === 'string' && /^https?:\/\/[^\s/]+$/.test(origin) ? origin : null;
|
|
929
1061
|
}
|
|
1062
|
+
export function presenceNameOf(record, sessionId) {
|
|
1063
|
+
let parsed = record;
|
|
1064
|
+
if (typeof record === 'string')
|
|
1065
|
+
try {
|
|
1066
|
+
parsed = JSON.parse(record);
|
|
1067
|
+
}
|
|
1068
|
+
catch {
|
|
1069
|
+
return undefined;
|
|
1070
|
+
}
|
|
1071
|
+
const sessions = isObject(parsed) && isObject(parsed.sessions) ? parsed.sessions : null;
|
|
1072
|
+
if (!sessions || !sessionId || !Object.hasOwn(sessions, sessionId))
|
|
1073
|
+
return undefined;
|
|
1074
|
+
const said = sessions[sessionId];
|
|
1075
|
+
return isObject(said) ? text(said.name, 120) : undefined;
|
|
1076
|
+
}
|
|
930
1077
|
export function presenceArgv(config, origin, session) {
|
|
931
1078
|
return [
|
|
932
1079
|
`${config}/bin/pendingyou-hook`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pendingyou",
|
|
3
|
-
"version": "0.43.
|
|
3
|
+
"version": "0.43.2",
|
|
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",
|