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/dist/setup.js
CHANGED
|
@@ -13,7 +13,7 @@ export function setupOf(heard) {
|
|
|
13
13
|
const setup = heard.setup;
|
|
14
14
|
if (typeof setup !== 'object' || setup === null)
|
|
15
15
|
return null;
|
|
16
|
-
const { reported, verified, test } = setup;
|
|
16
|
+
const { reported, verified, test, used } = setup;
|
|
17
17
|
if (typeof reported !== 'boolean' || typeof verified !== 'boolean')
|
|
18
18
|
return null;
|
|
19
19
|
const card = typeof test === 'object' && test !== null ? test : null;
|
|
@@ -24,6 +24,7 @@ export function setupOf(heard) {
|
|
|
24
24
|
return {
|
|
25
25
|
reported,
|
|
26
26
|
verified,
|
|
27
|
+
...(used === true ? { used: true } : {}),
|
|
27
28
|
...(ok
|
|
28
29
|
? {
|
|
29
30
|
test: {
|
|
@@ -51,7 +52,7 @@ export function setupLine(app, heard, setup) {
|
|
|
51
52
|
? `Pending You: your person answered setup’s test question (${requestId}), asked by “${name}”. If you’re ${name}, ${pickUp(`name “${name}”`)} If you aren’t, leave it to ${name}.`
|
|
52
53
|
: `Pending You: your person answered setup’s test question (${requestId}). C${pickUp('with your name').slice(1)}`;
|
|
53
54
|
}
|
|
54
|
-
if (setup.test)
|
|
55
|
+
if (setup.test || setup.used)
|
|
55
56
|
return null;
|
|
56
57
|
if (setup.reported)
|
|
57
58
|
return `Pending You: ${title} is connected, but setup’s test question isn’t sent yet. ${setupCalls(app, false)}`;
|
|
@@ -86,6 +87,7 @@ export async function setupReminder(io, options) {
|
|
|
86
87
|
return null;
|
|
87
88
|
}
|
|
88
89
|
}
|
|
90
|
+
export const SETUP_IN_USE = 'finished. It’s in use, so its unfinished test question no longer matters.';
|
|
89
91
|
export function setupStatus(appName, setup) {
|
|
90
92
|
if (!setup)
|
|
91
93
|
return null;
|
|
@@ -95,5 +97,9 @@ export function setupStatus(appName, setup) {
|
|
|
95
97
|
return 'its test card is waiting on you in Pending You';
|
|
96
98
|
if (setup.test?.turn === 'agent')
|
|
97
99
|
return `you answered its test card; ${appName} picks it up next`;
|
|
100
|
+
if (setup.used)
|
|
101
|
+
return SETUP_IN_USE;
|
|
102
|
+
if (setup.reported)
|
|
103
|
+
return `reported, but its test question isn’t sent yet. Start ${appName} (or restart it); if it doesn’t finish by itself, say “${FINISH_SAY}”`;
|
|
98
104
|
return `waiting for its first session. Start ${appName} (or restart it); if it doesn’t finish by itself, say “${FINISH_SAY}”`;
|
|
99
105
|
}
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.43.
|
|
1
|
+
export const VERSION = '0.43.2';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pendingyou-wake",
|
|
3
3
|
"displayName": "Pending You",
|
|
4
|
-
"version": "2.61.
|
|
4
|
+
"version": "2.61.2",
|
|
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.
|
|
7
|
+
Generated from recordplane/pendingyou (packages/claude-plugin/src/wake) with Pending You’s guide 2.61.2; send changes there.
|
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, 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, } 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, momentOf, nameKept, newerElsewhere, originOf, PRESENCE_EVERY_MS, PRESENCE_RUN_MS, presenceArgv, presenceNameOf, prompted, put, readBook, readClaim, readListener, readSetup, readSignal, readSince, readWait, resultObject, retellDue, SETUP_AFTER_MS, SETUP_RETRY_MS, SETUP_SERVER, SETUP_TRIES, SIGNAL_KEY, settle, setUpOf, setupNeeded, setupPrompt, stateOf, statusText, TICK_MS, takesHanded, told, toTell, untold, used, wakeText, wordsOf, } from "./wake.js";
|
|
5
5
|
const UNHEARD = { error: 'unavailable' };
|
|
6
6
|
const RETRY_MS = 60_000;
|
|
7
7
|
const live = {
|
|
@@ -22,6 +22,8 @@ const live = {
|
|
|
22
22
|
setupConnection: 'Claude Code',
|
|
23
23
|
seenAt: 0,
|
|
24
24
|
handedAt: 0,
|
|
25
|
+
held: [],
|
|
26
|
+
heldRenewedAt: 0,
|
|
25
27
|
handedTold: new Map(),
|
|
26
28
|
folders: [],
|
|
27
29
|
home: undefined,
|
|
@@ -32,6 +34,8 @@ const live = {
|
|
|
32
34
|
herdrTimer: null,
|
|
33
35
|
waiting: false,
|
|
34
36
|
signalSeen: 0,
|
|
37
|
+
words: new Map(),
|
|
38
|
+
wordless: new Set(),
|
|
35
39
|
};
|
|
36
40
|
const keyOf = (sessionId) => `session:${sessionId}`;
|
|
37
41
|
function blockedServer() {
|
|
@@ -41,8 +45,12 @@ function blockedServer() {
|
|
|
41
45
|
return undefined;
|
|
42
46
|
}
|
|
43
47
|
async function save($) {
|
|
44
|
-
live.book = {
|
|
45
|
-
|
|
48
|
+
live.book = {
|
|
49
|
+
...live.book,
|
|
50
|
+
updatedAt: await $.clock.now(),
|
|
51
|
+
...(live.folders.length ? { folders: live.folders } : {}),
|
|
52
|
+
};
|
|
53
|
+
if (keepsBook(live.book))
|
|
46
54
|
await $.store.set(keyOf(live.sessionId), live.book);
|
|
47
55
|
else
|
|
48
56
|
await $.store.delete(keyOf(live.sessionId));
|
|
@@ -107,23 +115,37 @@ async function allowed($, server, args, tool = 'get_request') {
|
|
|
107
115
|
return false;
|
|
108
116
|
}
|
|
109
117
|
}
|
|
118
|
+
async function readCard($, card, words) {
|
|
119
|
+
const args = checkArgs(card, words);
|
|
120
|
+
if (!(await allowed($, card.server, args)))
|
|
121
|
+
return { output: null, blocked: true };
|
|
122
|
+
try {
|
|
123
|
+
return {
|
|
124
|
+
output: resultObject(await $.mcp.call(card.server, 'get_request', args)),
|
|
125
|
+
blocked: false,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
return { output: null, blocked: isRefusal(error) };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
110
132
|
async function check($, requestId) {
|
|
111
133
|
const card = live.book.cards[requestId];
|
|
112
134
|
if (!card)
|
|
113
135
|
return 'error';
|
|
114
|
-
|
|
115
|
-
let
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
catch (error) {
|
|
122
|
-
blocked = isRefusal(error);
|
|
123
|
-
}
|
|
136
|
+
const words = !live.wordless.has(card.server);
|
|
137
|
+
let read = await readCard($, card, words);
|
|
138
|
+
if (words && !read.blocked && !(read.output && stateOf(read.output))) {
|
|
139
|
+
read = await readCard($, card, false);
|
|
140
|
+
if (read.output && stateOf(read.output))
|
|
141
|
+
live.wordless.add(card.server);
|
|
124
142
|
}
|
|
125
|
-
|
|
126
|
-
|
|
143
|
+
const { output, blocked } = read;
|
|
144
|
+
const said = output ? wordsOf(output) : undefined;
|
|
145
|
+
if (said)
|
|
146
|
+
live.words.set(requestId, said);
|
|
147
|
+
else if (output && stateOf(output))
|
|
148
|
+
live.words.delete(requestId);
|
|
127
149
|
const outcome = output && stateOf(output) ? 'ok' : blocked ? 'blocked' : 'error';
|
|
128
150
|
if (outcome === 'ok') {
|
|
129
151
|
live.verified.add(card.server);
|
|
@@ -160,17 +182,79 @@ async function deliver($) {
|
|
|
160
182
|
return false;
|
|
161
183
|
live.book = told(live.book, cards);
|
|
162
184
|
await save($);
|
|
163
|
-
$.prompt.submit({ text: wakeText(cards) }).catch(async () => {
|
|
185
|
+
$.prompt.submit({ text: wakeText(cards, live.words) }).catch(async () => {
|
|
164
186
|
live.book = untold(live.book, cards);
|
|
165
187
|
live.quietUntil = (await $.clock.now()) + RETRY_MS;
|
|
166
188
|
await save($).catch(() => { });
|
|
167
189
|
});
|
|
168
190
|
return true;
|
|
169
191
|
}
|
|
192
|
+
async function giveBack($, keys, by) {
|
|
193
|
+
if (keys.length === 0)
|
|
194
|
+
return;
|
|
195
|
+
for (const { key, moment } of keys)
|
|
196
|
+
if (claimHeld(await $.store.get(key), moment, by))
|
|
197
|
+
await $.store.delete(key).catch(() => { });
|
|
198
|
+
await $.store.set(SIGNAL_KEY, { at: await $.clock.now() }).catch(() => { });
|
|
199
|
+
}
|
|
200
|
+
async function heldHanded($, now) {
|
|
201
|
+
if (live.held.length === 0)
|
|
202
|
+
return;
|
|
203
|
+
const me = live.sessionId;
|
|
204
|
+
if (live.busy) {
|
|
205
|
+
if (now - live.heldRenewedAt < CLAIM_RENEW_MS)
|
|
206
|
+
return;
|
|
207
|
+
live.heldRenewedAt = now;
|
|
208
|
+
for (const held of live.held)
|
|
209
|
+
if (claimHeld(await $.store.get(held.key), held.moment, me))
|
|
210
|
+
await $.store.set(held.key, { moment: held.moment, at: now, by: me, held: true });
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const holding = live.held;
|
|
214
|
+
live.held = [];
|
|
215
|
+
const { name, server } = live.book;
|
|
216
|
+
const told = [];
|
|
217
|
+
for (const held of holding) {
|
|
218
|
+
if (!claimHeld(await $.store.get(held.key), held.moment, me))
|
|
219
|
+
continue;
|
|
220
|
+
let view = null;
|
|
221
|
+
if (name && server) {
|
|
222
|
+
const args = { requestId: held.handed.requestId, name };
|
|
223
|
+
if (await allowed($, server, args))
|
|
224
|
+
try {
|
|
225
|
+
view = handedView(resultObject(await $.mcp.call(server, 'get_request', args)), held.handed, name);
|
|
226
|
+
}
|
|
227
|
+
catch { }
|
|
228
|
+
}
|
|
229
|
+
if (live.sessionId !== me) {
|
|
230
|
+
await giveBack($, holding, me);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (!view) {
|
|
234
|
+
if (claimHeld(await $.store.get(held.key), held.moment, me))
|
|
235
|
+
await $.store.delete(held.key).catch(() => { });
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
await $.store.set(held.key, { moment: held.moment, at: now, by: me });
|
|
239
|
+
told.push({ view, key: held.key });
|
|
240
|
+
}
|
|
241
|
+
if (told.length === 0)
|
|
242
|
+
return;
|
|
243
|
+
$.prompt.submit({ text: handedText(told.map((each) => each.view)) }).catch(async () => {
|
|
244
|
+
for (const each of told) {
|
|
245
|
+
await $.store.delete(each.key).catch(() => { });
|
|
246
|
+
live.handedTold.delete(each.view.requestId);
|
|
247
|
+
}
|
|
248
|
+
live.handedAt = (await $.clock.now()) + RETRY_MS;
|
|
249
|
+
});
|
|
250
|
+
}
|
|
170
251
|
async function deliverHanded($) {
|
|
171
252
|
const { name, server } = live.book;
|
|
172
253
|
const now = await $.clock.now();
|
|
173
|
-
if (live.
|
|
254
|
+
if (live.book.seenAt && now - live.book.updatedAt > BOOK_TOUCH_MS)
|
|
255
|
+
await save($);
|
|
256
|
+
await heldHanded($, now);
|
|
257
|
+
if (!name || !server || !handedDue(live.seenAt, live.handedAt, now))
|
|
174
258
|
return;
|
|
175
259
|
live.handedAt = handedNext(live.seenAt, now);
|
|
176
260
|
if (!(await allowed($, server, { name }, 'list_pending')))
|
|
@@ -185,6 +269,7 @@ async function deliverHanded($) {
|
|
|
185
269
|
const cards = [];
|
|
186
270
|
const claims = [];
|
|
187
271
|
const me = live.sessionId;
|
|
272
|
+
let others;
|
|
188
273
|
for (const handed of listed) {
|
|
189
274
|
const known = live.handedTold.get(handed.requestId);
|
|
190
275
|
if (readSince(known, handed.updatedAt) || known === handed.updatedAt)
|
|
@@ -196,20 +281,61 @@ async function deliverHanded($) {
|
|
|
196
281
|
continue;
|
|
197
282
|
}
|
|
198
283
|
const key = `${CLAIM_PREFIX}${handed.requestId}`;
|
|
199
|
-
|
|
284
|
+
const before = await $.store.get(key);
|
|
285
|
+
if (claimedElsewhere(before, handed.updatedAt, me, now)) {
|
|
286
|
+
const lapse = claimLapsesAt(before);
|
|
287
|
+
if (lapse !== null)
|
|
288
|
+
live.handedAt = Math.min(live.handedAt, lapse);
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
const mine = claimHeld(before, handed.updatedAt, me);
|
|
292
|
+
const dropped = mine && readClaim(before)?.held === true && !live.held.some((held) => held.key === key);
|
|
293
|
+
const again = dropped || retellDue(before, handed.updatedAt, me, now);
|
|
294
|
+
if (mine && !again) {
|
|
200
295
|
live.handedTold.set(handed.requestId, handed.updatedAt);
|
|
201
296
|
continue;
|
|
202
297
|
}
|
|
298
|
+
const after = graceAfter(handed);
|
|
299
|
+
if (!again && after > now) {
|
|
300
|
+
others ??= await otherBooks($);
|
|
301
|
+
if (newerElsewhere(handed, name, live.seenAt, others, live.home)) {
|
|
302
|
+
live.handedAt = Math.min(live.handedAt, after);
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
203
306
|
const args = { requestId: handed.requestId, name };
|
|
204
307
|
if (!(await allowed($, server, args)))
|
|
205
308
|
continue;
|
|
206
|
-
await $.store.set(key, {
|
|
309
|
+
await $.store.set(key, {
|
|
310
|
+
moment: handed.updatedAt,
|
|
311
|
+
at: now,
|
|
312
|
+
by: me,
|
|
313
|
+
...(live.busy ? { held: true } : {}),
|
|
314
|
+
...(again && !dropped ? { retold: true } : {}),
|
|
315
|
+
});
|
|
316
|
+
if (live.busy) {
|
|
317
|
+
if (live.sessionId !== me) {
|
|
318
|
+
claims.push({ key, moment: handed.updatedAt });
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
live.handedTold.set(handed.requestId, handed.updatedAt);
|
|
322
|
+
if (!claimHeld(await $.store.get(key), handed.updatedAt, me))
|
|
323
|
+
continue;
|
|
324
|
+
if (live.held.length === 0)
|
|
325
|
+
live.heldRenewedAt = now;
|
|
326
|
+
live.held.push({ handed, key, moment: handed.updatedAt });
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
207
329
|
let view = null;
|
|
208
330
|
try {
|
|
209
331
|
view = handedView(resultObject(await $.mcp.call(server, 'get_request', args)), handed, name);
|
|
210
332
|
}
|
|
211
333
|
catch { }
|
|
212
334
|
const stored = await $.store.get(key);
|
|
335
|
+
if (live.sessionId !== me) {
|
|
336
|
+
claims.push({ key, moment: handed.updatedAt });
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
213
339
|
if (!view) {
|
|
214
340
|
if (claimHeld(stored, handed.updatedAt, me))
|
|
215
341
|
await $.store.delete(key);
|
|
@@ -220,13 +346,17 @@ async function deliverHanded($) {
|
|
|
220
346
|
continue;
|
|
221
347
|
}
|
|
222
348
|
live.handedTold.set(handed.requestId, handed.updatedAt);
|
|
223
|
-
claims.push(key);
|
|
349
|
+
claims.push({ key, moment: handed.updatedAt });
|
|
224
350
|
cards.push(view);
|
|
225
351
|
}
|
|
352
|
+
if (live.sessionId !== me) {
|
|
353
|
+
await giveBack($, claims, me);
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
226
356
|
if (cards.length === 0)
|
|
227
357
|
return;
|
|
228
358
|
$.prompt.submit({ text: handedText(cards) }).catch(async () => {
|
|
229
|
-
for (const key of claims)
|
|
359
|
+
for (const { key } of claims)
|
|
230
360
|
await $.store.delete(key).catch(() => { });
|
|
231
361
|
for (const card of cards)
|
|
232
362
|
live.handedTold.delete(card.requestId);
|
|
@@ -261,8 +391,9 @@ async function listenHanded($) {
|
|
|
261
391
|
.then(async (heard) => {
|
|
262
392
|
const at = await $.clock.now();
|
|
263
393
|
const current = readListener(await $.store.get(LISTENER_KEY));
|
|
264
|
-
|
|
265
|
-
|
|
394
|
+
const owner = live.sessionId;
|
|
395
|
+
if (!current || current.by === me || current.by === owner)
|
|
396
|
+
await $.store.set(LISTENER_KEY, listened({ ...lease, by: owner }, heard, at));
|
|
266
397
|
if ('handed' in heard && heard.handed.length) {
|
|
267
398
|
await $.store.set(SIGNAL_KEY, { at });
|
|
268
399
|
live.signalSeen = at;
|
|
@@ -282,6 +413,13 @@ async function heedSignal($) {
|
|
|
282
413
|
live.signalSeen = at;
|
|
283
414
|
live.handedAt = 0;
|
|
284
415
|
}
|
|
416
|
+
async function otherBooks($) {
|
|
417
|
+
const books = [];
|
|
418
|
+
for (const key of await $.store.keys())
|
|
419
|
+
if (key.startsWith('session:') && key !== keyOf(live.sessionId))
|
|
420
|
+
books.push(readBook(await $.store.get(key)));
|
|
421
|
+
return books;
|
|
422
|
+
}
|
|
285
423
|
async function prune($) {
|
|
286
424
|
const now = await $.clock.now();
|
|
287
425
|
for (const key of await $.store.keys()) {
|
|
@@ -382,7 +520,7 @@ function soon($) {
|
|
|
382
520
|
catch { }
|
|
383
521
|
}
|
|
384
522
|
function freshHanded() {
|
|
385
|
-
live.seenAt = Object.keys(live.book.cards).length ? live.book.updatedAt : 0;
|
|
523
|
+
live.seenAt = live.book.seenAt ?? (Object.keys(live.book.cards).length ? live.book.updatedAt : 0);
|
|
386
524
|
live.handedAt = 0;
|
|
387
525
|
live.handedTold = new Map();
|
|
388
526
|
}
|
|
@@ -409,6 +547,8 @@ async function sayLive($) {
|
|
|
409
547
|
const presence = live.presence;
|
|
410
548
|
if (!presence || !live.sessionId)
|
|
411
549
|
return;
|
|
550
|
+
if (!live.book.name)
|
|
551
|
+
await recallName($);
|
|
412
552
|
const argv = presenceArgv(presence.config, presence.origin, {
|
|
413
553
|
id: live.sessionId,
|
|
414
554
|
...(live.folders[0] ? { cwd: live.folders[0] } : {}),
|
|
@@ -438,12 +578,38 @@ async function startPresence($) {
|
|
|
438
578
|
await sayLive($);
|
|
439
579
|
live.presenceTimer = $.clock.every(PRESENCE_EVERY_MS, () => sayLive($));
|
|
440
580
|
}
|
|
581
|
+
async function recallName($) {
|
|
582
|
+
try {
|
|
583
|
+
const config = cliConfigOf($.plugin.root, $.plugin.name);
|
|
584
|
+
if (live.book.name || live.book.fork || !config || !live.sessionId)
|
|
585
|
+
return;
|
|
586
|
+
const name = presenceNameOf(await $.fs.read(`${config}/presence/claude-code.json`), live.sessionId);
|
|
587
|
+
if (!name)
|
|
588
|
+
return;
|
|
589
|
+
const now = await $.clock.now();
|
|
590
|
+
live.book = {
|
|
591
|
+
...live.book,
|
|
592
|
+
name,
|
|
593
|
+
server: live.book.server ?? SETUP_SERVER,
|
|
594
|
+
seenAt: live.book.seenAt ?? Math.max(1, now - HANDED_FOR_MS),
|
|
595
|
+
};
|
|
596
|
+
if (!live.seenAt) {
|
|
597
|
+
live.seenAt = live.book.seenAt ?? 0;
|
|
598
|
+
live.handedAt = 0;
|
|
599
|
+
}
|
|
600
|
+
await save($);
|
|
601
|
+
}
|
|
602
|
+
catch { }
|
|
603
|
+
}
|
|
441
604
|
async function start($, e) {
|
|
442
605
|
live.me = $.plugin.name;
|
|
443
606
|
live.sessionId = await $.session.id();
|
|
444
607
|
live.book = readBook(await $.store.get(keyOf(live.sessionId)));
|
|
608
|
+
await recallName($);
|
|
445
609
|
freshHanded();
|
|
446
610
|
await folderOfSession($, e.cwd);
|
|
611
|
+
if (live.book.name && live.book.seenAt)
|
|
612
|
+
await save($);
|
|
447
613
|
await noteLoaded($);
|
|
448
614
|
await claim($);
|
|
449
615
|
live.timer?.cancel();
|
|
@@ -458,10 +624,21 @@ async function switchSession($, e) {
|
|
|
458
624
|
const id = typeof e.session_id === 'string' && e.session_id ? e.session_id : await $.session.id();
|
|
459
625
|
if (!id || id === live.sessionId)
|
|
460
626
|
return;
|
|
461
|
-
const
|
|
627
|
+
const { seenAt: _seen, name: _name, ...forked } = live.book;
|
|
628
|
+
const carried = e.source === 'fork' ? { ...forked, fork: true } : null;
|
|
629
|
+
const was = live.sessionId;
|
|
462
630
|
live.sessionId = id;
|
|
631
|
+
const held = live.held;
|
|
632
|
+
live.held = [];
|
|
633
|
+
await giveBack($, held, was);
|
|
634
|
+
const listener = readListener(await $.store.get(LISTENER_KEY));
|
|
635
|
+
if (listener?.by === was)
|
|
636
|
+
await $.store.set(LISTENER_KEY, { ...listener, by: id });
|
|
463
637
|
live.book = carried ?? readBook(await $.store.get(keyOf(id)));
|
|
638
|
+
if (e.source === 'resume')
|
|
639
|
+
await recallName($);
|
|
464
640
|
live.noted.clear();
|
|
641
|
+
live.words.clear();
|
|
465
642
|
freshHanded();
|
|
466
643
|
await noteLoaded($);
|
|
467
644
|
if (typeof e.cwd === 'string' && e.cwd)
|
|
@@ -480,7 +657,8 @@ async function observe($, e, result) {
|
|
|
480
657
|
if ($.plugin.name === CLI_COPY && found.tool === 'whoami' && setUpOf(output) === true)
|
|
481
658
|
await setupDone($);
|
|
482
659
|
const now = await $.clock.now();
|
|
483
|
-
|
|
660
|
+
const subagent = typeof e.agentId === 'string' && e.agentId !== '';
|
|
661
|
+
if (output && !subagent) {
|
|
484
662
|
live.seenAt = now;
|
|
485
663
|
live.handedAt = Math.min(live.handedAt, now + HANDED_FAST_MS);
|
|
486
664
|
}
|
|
@@ -492,6 +670,10 @@ async function observe($, e, result) {
|
|
|
492
670
|
live.folders = [...live.folders, folder].slice(-5);
|
|
493
671
|
const before = live.book;
|
|
494
672
|
live.book = learn(live.book, { ...found, input: argumentsOf(e), output }, now);
|
|
673
|
+
if (subagent)
|
|
674
|
+
live.book = nameKept(live.book, before);
|
|
675
|
+
else if (output)
|
|
676
|
+
live.book = used(live.book, now);
|
|
495
677
|
if (live.book === before)
|
|
496
678
|
return result;
|
|
497
679
|
await save($);
|