pendingyou 0.9.0 → 0.10.0
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 +49 -0
- package/README.md +80 -22
- package/dist/api.js +33 -0
- package/dist/args.js +78 -14
- package/dist/claude.js +268 -23
- package/dist/credentials.js +39 -1
- package/dist/files.js +3 -3
- package/dist/hold.js +35 -17
- package/dist/index.js +1 -0
- package/dist/install.js +4 -2
- package/dist/io.js +3 -1
- package/dist/main.js +195 -35
- package/dist/mod.js +87 -0
- package/dist/oauth.js +27 -6
- package/dist/pickup.js +16 -18
- package/dist/qr.js +365 -0
- package/dist/remote.js +306 -0
- package/dist/state.js +5 -32
- package/dist/stopcheck.js +2 -1
- package/dist/version.js +1 -1
- package/dist/watch.js +3 -5
- package/mod/.claude-plugin/plugin.json +12 -0
- package/mod/README.md +7 -0
- package/mod/hooks/hooks.json +7 -0
- package/mod/hooks/register.js +314 -0
- package/mod/hooks/wake.js +599 -0
- package/mod/tests/wake.test.ts +198 -0
- package/package.json +3 -2
package/dist/state.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
// What the command line remembers between runs, in ~/.config/pendingyou/state.json (0600): which answers it already
|
|
2
|
-
// handed to Claude Code
|
|
3
|
-
//
|
|
4
|
-
//
|
|
2
|
+
// handed to Claude Code, so a hook never repeats one. Ids only: never a title or an answer. Until 0.10.0 it also kept
|
|
3
|
+
// which requests a hold was waiting on, because the next-message hook only looked for answers then; it looks every
|
|
4
|
+
// time now, and a file from before is rewritten without them.
|
|
5
5
|
import { join } from 'node:path';
|
|
6
6
|
import { configDir, readJson, withLock, writeWhole } from "./files.js";
|
|
7
7
|
const KEEP_HANDED = 300;
|
|
8
|
-
/** A wait this old is dropped: its request has long been answered, or forgotten. */
|
|
9
|
-
const WAITING_DAYS = 7;
|
|
10
8
|
const statePath = (io) => join(configDir(io), 'state.json');
|
|
11
9
|
const key = (origin, requestId) => `${origin} ${requestId}`;
|
|
12
10
|
/** The moment of a heard request: a new answer version or a new message is a new moment. */
|
|
@@ -16,7 +14,6 @@ async function load(io) {
|
|
|
16
14
|
return {
|
|
17
15
|
version: 1,
|
|
18
16
|
handed: file?.handed && typeof file.handed === 'object' ? file.handed : {},
|
|
19
|
-
waiting: file?.waiting && typeof file.waiting === 'object' ? file.waiting : {},
|
|
20
17
|
};
|
|
21
18
|
}
|
|
22
19
|
async function change(io, edit) {
|
|
@@ -27,43 +24,19 @@ async function change(io, edit) {
|
|
|
27
24
|
const handed = Object.entries(state.handed);
|
|
28
25
|
if (handed.length > KEEP_HANDED)
|
|
29
26
|
state.handed = Object.fromEntries(handed.slice(-KEEP_HANDED));
|
|
30
|
-
const oldest = io.now() - WAITING_DAYS * 86_400_000;
|
|
31
|
-
for (const [name, wait] of Object.entries(state.waiting))
|
|
32
|
-
if (wait.since < oldest)
|
|
33
|
-
delete state.waiting[name];
|
|
34
27
|
await writeWhole(path, `${JSON.stringify(state, null, 2)}\n`, { secret: true });
|
|
35
28
|
});
|
|
36
29
|
}
|
|
37
30
|
export async function wasHanded(io, origin, requestId, moment) {
|
|
38
31
|
return (await load(io)).handed[key(origin, requestId)] === moment;
|
|
39
32
|
}
|
|
40
|
-
/** Records answers as handed over
|
|
33
|
+
/** Records answers as handed over. */
|
|
41
34
|
export function markHanded(io, origin, heard) {
|
|
42
35
|
return change(io, (state) => {
|
|
43
|
-
for (const { requestId, moment
|
|
36
|
+
for (const { requestId, moment } of heard) {
|
|
44
37
|
const name = key(origin, requestId);
|
|
45
38
|
delete state.handed[name];
|
|
46
39
|
state.handed[name] = moment;
|
|
47
|
-
if (closed)
|
|
48
|
-
delete state.waiting[name];
|
|
49
40
|
}
|
|
50
41
|
});
|
|
51
42
|
}
|
|
52
|
-
export function startWaiting(io, origin, requestId, cwd) {
|
|
53
|
-
return change(io, (state) => {
|
|
54
|
-
state.waiting[key(origin, requestId)] = { cwd, since: io.now() };
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
export function stopWaiting(io, origin, requestIds) {
|
|
58
|
-
return change(io, (state) => {
|
|
59
|
-
for (const requestId of requestIds)
|
|
60
|
-
delete state.waiting[key(origin, requestId)];
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
/** The requests a hold was started for on this origin, and the folders they were started in. */
|
|
64
|
-
export async function waitingOn(io, origin) {
|
|
65
|
-
const state = await load(io);
|
|
66
|
-
return Object.entries(state.waiting)
|
|
67
|
-
.filter(([name]) => name.startsWith(`${origin} `))
|
|
68
|
-
.map(([name, wait]) => ({ requestId: name.slice(origin.length + 1), cwd: wait.cwd }));
|
|
69
|
-
}
|
package/dist/stopcheck.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// open cards, as the next-message hook asks for them, given up after 1.5 seconds). It never loops (stop_hook_active),
|
|
13
13
|
// stays quiet for anyone not signed in to this origin, and exits 0 silently on any error.
|
|
14
14
|
import { open } from 'node:fs/promises';
|
|
15
|
-
import { getJson } from "./api.js";
|
|
15
|
+
import { getJson, SESSION_APP } from "./api.js";
|
|
16
16
|
import { asksToTypeHere, cardFits, confirmReason, sessionLink } from "./confirm.js";
|
|
17
17
|
import { readCredential } from "./credentials.js";
|
|
18
18
|
import { folderForms } from "./pickup.js";
|
|
@@ -216,6 +216,7 @@ async function openTitles(io, origin, cwd) {
|
|
|
216
216
|
...folderForms(cwd, io.home).map((form) => ['cwd', form]),
|
|
217
217
|
['limit', '0'],
|
|
218
218
|
['open', String(OPEN_CARDS)],
|
|
219
|
+
['source', SESSION_APP],
|
|
219
220
|
]);
|
|
220
221
|
const { status, body } = await getJson(io, origin, `/mcp/cli/answers?${query}`, OPEN_TIME_BOX_MS, io.signal, { hook: true });
|
|
221
222
|
const requests = status === 200 ? body.open?.requests : undefined;
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// The command line's version, as published (package.json). A test keeps them the same.
|
|
2
|
-
export const VERSION = '0.
|
|
2
|
+
export const VERSION = '0.10.0';
|
package/dist/watch.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// `pendingyou watch -- <command> [args…]`: for an always-on script on an assistant's own machine (a Muse job, a cron
|
|
2
2
|
// box, a home server). It waits on Pending You for any of the sign-in's requests to become the assistant's move, and
|
|
3
3
|
// runs the command once for each: the answer after its 5-second hold, a message from the person, or a fallback that
|
|
4
|
-
// came due.
|
|
5
|
-
//
|
|
4
|
+
// came due. It watches the person's Claude Code assistants: signing in offers no choice of assistant since 2026-10-04,
|
|
5
|
+
// and a sign-in pointed at one assistant before then ("Hear answers for: Only Muse") keeps watching that one.
|
|
6
6
|
//
|
|
7
7
|
// The command runs without a shell, one at a time, with its output passed through. It gets the request on stdin as
|
|
8
8
|
// JSON (the same fields as /mcp/cli/answers: id, title, status, the answer in words, new messages, fallback) and, in
|
|
@@ -92,9 +92,7 @@ export async function watch(io, options) {
|
|
|
92
92
|
// A command that can't even start is a mistake in the command line: stop, and hand nothing over.
|
|
93
93
|
if (code === 127)
|
|
94
94
|
return 127;
|
|
95
|
-
await markHanded(io, origin, [
|
|
96
|
-
{ requestId: request.requestId, moment: momentOf(request), closed: true },
|
|
97
|
-
]);
|
|
95
|
+
await markHanded(io, origin, [{ requestId: request.requestId, moment: momentOf(request) }]);
|
|
98
96
|
if (options.once)
|
|
99
97
|
return code;
|
|
100
98
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pendingyou-wake",
|
|
3
|
+
"displayName": "Pending You",
|
|
4
|
+
"version": "2.25.0",
|
|
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
|
+
"author": {
|
|
7
|
+
"name": "RecordPlane",
|
|
8
|
+
"url": "https://www.pendingyou.com"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://www.pendingyou.com",
|
|
11
|
+
"repository": "https://github.com/recordplane/pendingyou"
|
|
12
|
+
}
|
package/mod/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Pending You wake mod
|
|
2
|
+
|
|
3
|
+
The pendingyou command line’s copy of the Pending You plugin’s wake mod, for Claude Code 2.1.287 and later. `npx pendingyou init` adds this folder to `CLAUDE_CODE_PLUGIN_DIRS` in `~/.claude/settings.json`, so every Claude Code session loads it; `npx pendingyou uninstall` takes it out.
|
|
4
|
+
|
|
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, even while the session 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
|
+
|
|
7
|
+
Generated from recordplane/pendingyou (packages/claude-plugin/src/wake) with Pending You’s guide 2.25.0; send changes there.
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
// Generated from packages/claude-plugin/src/wake/register.ts in recordplane/pendingyou: edit that, then run
|
|
2
|
+
// `pnpm --filter @pendingyou/claude-plugin generate`.
|
|
3
|
+
|
|
4
|
+
// The Pending You wake mod's hooks module, for Claude Code 2.1.287 and later: the thin part that calls Claude Code.
|
|
5
|
+
// What the mod does, and every rule it follows, is in wake.ts; src/plugin.ts ships both as JavaScript.
|
|
6
|
+
//
|
|
7
|
+
// It never gets in the way. Every hook passes its event on; a failure in the mod's own work is swallowed; and a hold it
|
|
8
|
+
// can't stand behind (another copy of the mod acts for this session, or Claude Code won't let it check the card) runs
|
|
9
|
+
// as it is. Its checks are get_request calls over the session's own connection, so they need what the agent's own
|
|
10
|
+
// calls need: Pending You's tools allowed (`npx pendingyou init` allows mcp__pendingyou; the plugin's setup asks the
|
|
11
|
+
// person to allow its server). It asks Claude Code first ($.tool.check, a question that runs nothing): a check that
|
|
12
|
+
// isn't allowed would open a permission dialog in an interactive session and hold up the call it runs in (seen
|
|
13
|
+
// 2026-10-04). Until it's allowed, the mod says so, under the prompt and once to the agent.
|
|
14
|
+
//
|
|
15
|
+
// One copy acts per session: the plugin's and the command line's copy can both load, and they keep separate stores, so
|
|
16
|
+
// the lease is a variable in the session's own environment, which every mod in the process shares.
|
|
17
|
+
import { argumentsOf, blockedNote, cardTool, checked, claimLease, dueCards, emptyBook, failed, holdOf, holdReply, isRefusal, isStale, isWaitingOnYou, learn, leaseHolder, momentOf, put, readBook, resultObject, settle, stateOf, statusText, TICK_MS, told, toTell, untold, wakeText, } from "./wake.js";
|
|
18
|
+
/** After a prompt that didn't go, how long before the mod tries again. */
|
|
19
|
+
const RETRY_MS = 60_000;
|
|
20
|
+
/** What the mod holds while its module is loaded. The cards themselves are kept in the store. */
|
|
21
|
+
const live = {
|
|
22
|
+
/** This copy's name in the lease: its plugin's. */
|
|
23
|
+
me: '',
|
|
24
|
+
sessionId: '',
|
|
25
|
+
book: emptyBook(),
|
|
26
|
+
owner: false,
|
|
27
|
+
/** A turn of the main conversation is running: a prompt now would only queue behind it. */
|
|
28
|
+
busy: false,
|
|
29
|
+
ticking: false,
|
|
30
|
+
pruned: false,
|
|
31
|
+
quietUntil: 0,
|
|
32
|
+
timer: null,
|
|
33
|
+
shown: undefined,
|
|
34
|
+
/** Servers Claude Code refused a check on. */
|
|
35
|
+
blocked: new Set(),
|
|
36
|
+
/** Servers a check worked on this session. */
|
|
37
|
+
verified: new Set(),
|
|
38
|
+
/** Servers the agent was told it can't be woken through. */
|
|
39
|
+
noted: new Set(),
|
|
40
|
+
};
|
|
41
|
+
const keyOf = (sessionId) => `session:${sessionId}`;
|
|
42
|
+
/** A server Claude Code refuses checks on, while the session has a card there. */
|
|
43
|
+
function blockedServer() {
|
|
44
|
+
for (const server of live.blocked)
|
|
45
|
+
if (Object.values(live.book.cards).some((card) => card.server === server))
|
|
46
|
+
return server;
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
/** Keeps the session's cards in the store; a session with none left keeps nothing there. */
|
|
50
|
+
async function save($) {
|
|
51
|
+
live.book = { ...live.book, updatedAt: await $.clock.now() };
|
|
52
|
+
if (Object.keys(live.book.cards).length)
|
|
53
|
+
await $.store.set(keyOf(live.sessionId), live.book);
|
|
54
|
+
else
|
|
55
|
+
await $.store.delete(keyOf(live.sessionId));
|
|
56
|
+
}
|
|
57
|
+
/** Takes or renews the lease; true while this copy holds it. */
|
|
58
|
+
async function claim($) {
|
|
59
|
+
const now = await $.clock.now();
|
|
60
|
+
const value = claimLease(await $.env.get('PENDINGYOU_WAKE_OWNER'), live.me, now);
|
|
61
|
+
if (value)
|
|
62
|
+
await $.env.set('PENDINGYOU_WAKE_OWNER', value);
|
|
63
|
+
live.owner = leaseHolder(await $.env.get('PENDINGYOU_WAKE_OWNER'), now) === live.me;
|
|
64
|
+
return live.owner;
|
|
65
|
+
}
|
|
66
|
+
function show($, text) {
|
|
67
|
+
if (text === live.shown)
|
|
68
|
+
return;
|
|
69
|
+
live.shown = text;
|
|
70
|
+
try {
|
|
71
|
+
const shown = $.ui.status(text);
|
|
72
|
+
if (shown instanceof Promise)
|
|
73
|
+
shown.catch(() => { });
|
|
74
|
+
}
|
|
75
|
+
catch { }
|
|
76
|
+
}
|
|
77
|
+
const showCards = ($) => show($, live.owner ? statusText(live.book, blockedServer()) : undefined);
|
|
78
|
+
/** Whether Claude Code lets the mod make this call now, without asking anyone: never opens a dialog. */
|
|
79
|
+
async function allowed($, server, args) {
|
|
80
|
+
try {
|
|
81
|
+
const decided = await $.tool.check({ tool: `mcp__${server}__get_request`, input: args });
|
|
82
|
+
return decided.decision === 'allow';
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/** Checks one card now through the session's connection: ok, blocked (Claude Code won't allow it), or error. */
|
|
89
|
+
async function check($, requestId) {
|
|
90
|
+
const card = live.book.cards[requestId];
|
|
91
|
+
if (!card)
|
|
92
|
+
return 'error';
|
|
93
|
+
let output = null;
|
|
94
|
+
let blocked = false;
|
|
95
|
+
const args = { requestId, ...(card.name ? { name: card.name } : {}) };
|
|
96
|
+
if (await allowed($, card.server, args)) {
|
|
97
|
+
try {
|
|
98
|
+
output = resultObject(await $.mcp.call(card.server, 'get_request', args));
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
blocked = isRefusal(error);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else
|
|
105
|
+
blocked = true;
|
|
106
|
+
const outcome = output && stateOf(output) ? 'ok' : blocked ? 'blocked' : 'error';
|
|
107
|
+
if (outcome === 'ok') {
|
|
108
|
+
live.verified.add(card.server);
|
|
109
|
+
live.blocked.delete(card.server);
|
|
110
|
+
}
|
|
111
|
+
else if (outcome === 'blocked')
|
|
112
|
+
live.blocked.add(card.server);
|
|
113
|
+
// The card as it is now: the agent may have acked or changed it while the check ran.
|
|
114
|
+
const current = live.book.cards[requestId];
|
|
115
|
+
if (!current)
|
|
116
|
+
return outcome;
|
|
117
|
+
const now = await $.clock.now();
|
|
118
|
+
const next = output && outcome === 'ok' ? checked(current, output, now) : failed(current, now, blocked);
|
|
119
|
+
live.book = put(live.book, next);
|
|
120
|
+
if (!current.state || (next.state && momentOf(current.state) !== momentOf(next.state)))
|
|
121
|
+
await save($);
|
|
122
|
+
return outcome;
|
|
123
|
+
}
|
|
124
|
+
/** Starts one turn for every card whose moment the agent hasn't heard, while the session is idle. */
|
|
125
|
+
async function deliver($) {
|
|
126
|
+
if (live.busy)
|
|
127
|
+
return;
|
|
128
|
+
const cards = toTell(live.book);
|
|
129
|
+
if (cards.length === 0 || (await $.clock.now()) < live.quietUntil)
|
|
130
|
+
return;
|
|
131
|
+
if (!(await claim($)))
|
|
132
|
+
return;
|
|
133
|
+
live.book = told(live.book, cards);
|
|
134
|
+
await save($);
|
|
135
|
+
$.prompt.submit({ text: wakeText(cards) }).catch(async () => {
|
|
136
|
+
live.book = untold(live.book, cards);
|
|
137
|
+
live.quietUntil = (await $.clock.now()) + RETRY_MS;
|
|
138
|
+
await save($).catch(() => { });
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/** Forgets other sessions' lists that nobody has touched for 7 days. */
|
|
142
|
+
async function prune($) {
|
|
143
|
+
const now = await $.clock.now();
|
|
144
|
+
for (const key of await $.store.keys()) {
|
|
145
|
+
if (!key.startsWith('session:') || key === keyOf(live.sessionId))
|
|
146
|
+
continue;
|
|
147
|
+
if (isStale(readBook(await $.store.get(key)), now))
|
|
148
|
+
await $.store.delete(key);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async function tick($) {
|
|
152
|
+
if (live.ticking || !live.sessionId)
|
|
153
|
+
return;
|
|
154
|
+
live.ticking = true;
|
|
155
|
+
try {
|
|
156
|
+
if (!live.pruned) {
|
|
157
|
+
live.pruned = true;
|
|
158
|
+
await prune($);
|
|
159
|
+
}
|
|
160
|
+
if (!(await claim($))) {
|
|
161
|
+
show($, undefined);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const now = await $.clock.now();
|
|
165
|
+
const settled = settle(live.book, now);
|
|
166
|
+
if (settled !== live.book) {
|
|
167
|
+
live.book = settled;
|
|
168
|
+
await save($);
|
|
169
|
+
}
|
|
170
|
+
for (const card of dueCards(live.book, now))
|
|
171
|
+
await check($, card.requestId);
|
|
172
|
+
await deliver($);
|
|
173
|
+
showCards($);
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
// The next tick tries again.
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
live.ticking = false;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function soon($) {
|
|
183
|
+
try {
|
|
184
|
+
$.clock.after(1500, () => tick($));
|
|
185
|
+
}
|
|
186
|
+
catch { }
|
|
187
|
+
}
|
|
188
|
+
async function start($) {
|
|
189
|
+
live.me = $.plugin.name;
|
|
190
|
+
live.sessionId = await $.session.id();
|
|
191
|
+
live.book = readBook(await $.store.get(keyOf(live.sessionId)));
|
|
192
|
+
await claim($);
|
|
193
|
+
live.timer?.cancel();
|
|
194
|
+
live.timer = $.clock.every(TICK_MS, () => tick($));
|
|
195
|
+
soon($);
|
|
196
|
+
}
|
|
197
|
+
/** After /clear, /resume or /branch: the session's id changed, and its cards with it (a branch keeps them). */
|
|
198
|
+
async function switchSession($, e) {
|
|
199
|
+
const id = typeof e.session_id === 'string' && e.session_id ? e.session_id : await $.session.id();
|
|
200
|
+
if (!id || id === live.sessionId)
|
|
201
|
+
return;
|
|
202
|
+
const carried = e.source === 'fork' ? live.book : null;
|
|
203
|
+
live.sessionId = id;
|
|
204
|
+
live.book = carried ?? readBook(await $.store.get(keyOf(id)));
|
|
205
|
+
live.noted.clear();
|
|
206
|
+
if (carried)
|
|
207
|
+
await save($);
|
|
208
|
+
showCards($);
|
|
209
|
+
}
|
|
210
|
+
/** Learns from one of the session's own Pending You calls, and says once when Claude Code won't let it check. */
|
|
211
|
+
async function observe($, e, result) {
|
|
212
|
+
const found = cardTool(e.tool);
|
|
213
|
+
if (!found || !live.sessionId)
|
|
214
|
+
return result;
|
|
215
|
+
const output = resultObject(result);
|
|
216
|
+
const before = live.book;
|
|
217
|
+
live.book = learn(live.book, { ...found, input: argumentsOf(e), output }, await $.clock.now());
|
|
218
|
+
if (live.book === before)
|
|
219
|
+
return result;
|
|
220
|
+
await save($);
|
|
221
|
+
const id = output?.requestId ?? e.requestId;
|
|
222
|
+
const card = typeof id === 'string' ? live.book.cards[id] : undefined;
|
|
223
|
+
// A card just put in front of the person, on a server not checked yet this session: check it now, so a refusal is
|
|
224
|
+
// known while the agent can still tell its person.
|
|
225
|
+
if (live.owner && card?.state && isWaitingOnYou(card.state) && !live.verified.has(card.server)) {
|
|
226
|
+
const outcome = await check($, card.requestId);
|
|
227
|
+
if (outcome === 'blocked' && !live.noted.has(card.server)) {
|
|
228
|
+
live.noted.add(card.server);
|
|
229
|
+
showCards($);
|
|
230
|
+
return { ...result, context: [...(result.context ?? []), blockedNote(card.server)] };
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
showCards($);
|
|
234
|
+
return result;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Answers `npx pendingyou hold <id>` for this session: nothing runs, and the mod wakes it instead. Null when the hold
|
|
238
|
+
* should run as it is: another copy acts here (it answers), the card's server isn't known, or a check didn't work.
|
|
239
|
+
*/
|
|
240
|
+
async function answerHold($, e) {
|
|
241
|
+
const requestId = typeof e.command === 'string' ? holdOf(e.command) : null;
|
|
242
|
+
if (!requestId || !live.sessionId)
|
|
243
|
+
return null;
|
|
244
|
+
const known = live.book.cards[requestId];
|
|
245
|
+
const server = known?.server ?? live.book.server;
|
|
246
|
+
if (!server)
|
|
247
|
+
return null;
|
|
248
|
+
if (!known) {
|
|
249
|
+
const now = await $.clock.now();
|
|
250
|
+
const name = live.book.name;
|
|
251
|
+
live.book = put(live.book, {
|
|
252
|
+
requestId,
|
|
253
|
+
server,
|
|
254
|
+
...(name ? { name } : {}),
|
|
255
|
+
learnedAt: now,
|
|
256
|
+
changedAt: now,
|
|
257
|
+
nextAt: now,
|
|
258
|
+
});
|
|
259
|
+
await save($);
|
|
260
|
+
}
|
|
261
|
+
if (!(await claim($)))
|
|
262
|
+
return null;
|
|
263
|
+
if ((await check($, requestId)) !== 'ok')
|
|
264
|
+
return null;
|
|
265
|
+
showCards($);
|
|
266
|
+
return { result: { stdout: holdReply(requestId), stderr: '', interrupted: false } };
|
|
267
|
+
}
|
|
268
|
+
export function register(on) {
|
|
269
|
+
on('session.start', async ($, e, next) => {
|
|
270
|
+
try {
|
|
271
|
+
await start($);
|
|
272
|
+
}
|
|
273
|
+
catch { }
|
|
274
|
+
return next(e);
|
|
275
|
+
});
|
|
276
|
+
on('classic.SessionStart', { source: ['clear', 'resume', 'fork'] }, async ($, e, next) => {
|
|
277
|
+
try {
|
|
278
|
+
await switchSession($, e);
|
|
279
|
+
}
|
|
280
|
+
catch { }
|
|
281
|
+
return next(e);
|
|
282
|
+
});
|
|
283
|
+
on('turn.start', async (_, e, next) => {
|
|
284
|
+
if (!e.agentId)
|
|
285
|
+
live.busy = true;
|
|
286
|
+
return next(e);
|
|
287
|
+
});
|
|
288
|
+
on('turn.complete', async ($, e, next) => {
|
|
289
|
+
if (!e.agentId) {
|
|
290
|
+
live.busy = false;
|
|
291
|
+
soon($);
|
|
292
|
+
}
|
|
293
|
+
return next(e);
|
|
294
|
+
});
|
|
295
|
+
on('tool.call', {
|
|
296
|
+
tool: /^mcp__.+__(post_request|get_request|update_request|reply_in_thread|ack_answer|cancel_request|whoami|list_pending)$/,
|
|
297
|
+
}, async ($, e, next) => {
|
|
298
|
+
const result = await next(e);
|
|
299
|
+
try {
|
|
300
|
+
return await observe($, e, result);
|
|
301
|
+
}
|
|
302
|
+
catch {
|
|
303
|
+
return result;
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
on('tool.call', { tool: 'Bash' }, async ($, e, next) => {
|
|
307
|
+
let answer = null;
|
|
308
|
+
try {
|
|
309
|
+
answer = await answerHold($, e);
|
|
310
|
+
}
|
|
311
|
+
catch { }
|
|
312
|
+
return answer ?? next(e);
|
|
313
|
+
});
|
|
314
|
+
}
|