pendingyou 0.44.1 → 0.45.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/README.md +51 -2
- package/dist/apps/antigravity-hooks.js +326 -0
- package/dist/apps/antigravity.js +704 -0
- package/dist/apps/codex-wake.js +2 -0
- package/dist/apps/ids.js +2 -1
- package/dist/apps/registry.js +2 -1
- package/dist/args.js +7 -4
- package/dist/asked.js +1 -1
- package/dist/environment.js +4 -1
- package/dist/herdr.js +1 -0
- package/dist/hold.js +25 -9
- package/dist/init.js +6 -4
- package/dist/main.js +6 -0
- package/dist/pickup.js +6 -5
- package/dist/presence.js +23 -16
- package/dist/setup.js +4 -1
- package/dist/shim.js +2 -0
- package/dist/stopcheck.js +13 -4
- package/dist/version.js +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,704 @@
|
|
|
1
|
+
import { rm, rmdir } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { bridgeOrigin, bridgePath, checkBridge, isOurBridge, probeBridge } from "../bridge.js";
|
|
4
|
+
import { readCredential } from "../credentials.js";
|
|
5
|
+
import { configDir, readJson, readText, writeWhole } from "../files.js";
|
|
6
|
+
import { holdCommand } from "../hold.js";
|
|
7
|
+
import { isOurHook, originArgs } from "../hooks.js";
|
|
8
|
+
import { editJson, isObject, readObject } from "../json.js";
|
|
9
|
+
import { removePresenceFiles } from "../presence.js";
|
|
10
|
+
import { foundBy, headlessReason } from "../remote.js";
|
|
11
|
+
import { connectionTitle, FINISH_SAY, setupCalls, setupOf, setupStatus } from "../setup.js";
|
|
12
|
+
import { VERSION } from "../version.js";
|
|
13
|
+
import { AGY_HOOK_EVENTS, AGY_POST_TOOL_MATCHER, agyHookFiles } from "./antigravity-hooks.js";
|
|
14
|
+
import { threadFiles } from "./codex-wake.js";
|
|
15
|
+
import { APP_NAMES } from "./ids.js";
|
|
16
|
+
import { switches } from "./switch.js";
|
|
17
|
+
const NAME = APP_NAMES.antigravity;
|
|
18
|
+
export const AGY_MIN = '1.5.12';
|
|
19
|
+
const PLUGIN = 'pendingyou';
|
|
20
|
+
const SERVER = 'pendingyou';
|
|
21
|
+
const HOMEPAGE = 'https://www.pendingyou.com';
|
|
22
|
+
const DESCRIPTION = 'Ask your person through Pending You when a decision, fact or step is theirs, and hear their answers.';
|
|
23
|
+
export const EAGER_TOOLS = [
|
|
24
|
+
'whoami',
|
|
25
|
+
'match_area',
|
|
26
|
+
'post_request',
|
|
27
|
+
'get_request',
|
|
28
|
+
'list_pending',
|
|
29
|
+
'ack_answer',
|
|
30
|
+
'update_request',
|
|
31
|
+
'cancel_request',
|
|
32
|
+
'reply_in_thread',
|
|
33
|
+
'post_answer',
|
|
34
|
+
'answer_delegated',
|
|
35
|
+
'hand_back',
|
|
36
|
+
'report_setup',
|
|
37
|
+
];
|
|
38
|
+
export const PERMISSION_RULES = [
|
|
39
|
+
'mcp(pendingyou_pendingyou/*)',
|
|
40
|
+
'command(npx -y pendingyou hold)',
|
|
41
|
+
];
|
|
42
|
+
const FILES = [
|
|
43
|
+
'plugin.json',
|
|
44
|
+
'mcp_config.json',
|
|
45
|
+
'hooks.json',
|
|
46
|
+
'rules/AGENTS.md',
|
|
47
|
+
'skills/pendingyou/SKILL.md',
|
|
48
|
+
];
|
|
49
|
+
const geminiConfig = (io) => join(io.home, '.gemini', 'config');
|
|
50
|
+
export const pluginDir = (io) => join(geminiConfig(io), 'plugins', PLUGIN);
|
|
51
|
+
const agyConfigPath = (io) => join(geminiConfig(io), 'config.json');
|
|
52
|
+
const globalMcpPath = (io) => join(geminiConfig(io), 'mcp_config.json');
|
|
53
|
+
export const agySettingsPath = (io) => join(io.home, '.gemini', 'antigravity-cli', 'settings.json');
|
|
54
|
+
const manifestPath = (io) => join(configDir(io), 'antigravity.json');
|
|
55
|
+
export const readAntigravityManifest = (io) => readJson(manifestPath(io)).catch(() => null);
|
|
56
|
+
const text = (value) => (typeof value === 'string' && value ? value : null);
|
|
57
|
+
async function readFile(path) {
|
|
58
|
+
const body = await readText(path).catch(() => null);
|
|
59
|
+
const read = readObject(body, path);
|
|
60
|
+
return 'invalid' in read ? { path, invalid: read.invalid } : { path, text: body, json: read.json };
|
|
61
|
+
}
|
|
62
|
+
function serverIn(json) {
|
|
63
|
+
const entry = isObject(json.mcpServers) ? json.mcpServers[SERVER] : undefined;
|
|
64
|
+
if (!isObject(entry))
|
|
65
|
+
return null;
|
|
66
|
+
const headers = isObject(entry.headers) ? entry.headers : {};
|
|
67
|
+
return {
|
|
68
|
+
entry,
|
|
69
|
+
url: text(entry.url) ?? text(entry.serverUrl),
|
|
70
|
+
command: text(entry.command)
|
|
71
|
+
? [
|
|
72
|
+
entry.command,
|
|
73
|
+
...(Array.isArray(entry.args)
|
|
74
|
+
? entry.args.filter((arg) => typeof arg === 'string')
|
|
75
|
+
: []),
|
|
76
|
+
]
|
|
77
|
+
: null,
|
|
78
|
+
ownAuth: Object.keys(headers).some((name) => name.toLowerCase() === 'authorization'),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function originOf(server) {
|
|
82
|
+
if (server.command && isOurBridge(server.command))
|
|
83
|
+
return bridgeOrigin(server.command);
|
|
84
|
+
try {
|
|
85
|
+
return server.url ? new URL(server.url).origin : null;
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const pluginServer = async (io) => {
|
|
92
|
+
const file = await readFile(join(pluginDir(io), 'mcp_config.json'));
|
|
93
|
+
return 'json' in file ? serverIn(file.json) : null;
|
|
94
|
+
};
|
|
95
|
+
export async function antigravityServerUrl(io) {
|
|
96
|
+
const global = await readFile(globalMcpPath(io));
|
|
97
|
+
for (const server of [await pluginServer(io), 'json' in global ? serverIn(global.json) : null]) {
|
|
98
|
+
const origin = server ? originOf(server) : null;
|
|
99
|
+
if (server && origin)
|
|
100
|
+
return server.url ?? `${origin}/mcp`;
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
const isOurPlugin = (json) => json !== null &&
|
|
105
|
+
json.name === PLUGIN &&
|
|
106
|
+
typeof json.homepage === 'string' &&
|
|
107
|
+
json.homepage.startsWith(HOMEPAGE);
|
|
108
|
+
async function pluginJson(io) {
|
|
109
|
+
const body = await readText(join(pluginDir(io), 'plugin.json')).catch(() => null);
|
|
110
|
+
if (body === null)
|
|
111
|
+
return null;
|
|
112
|
+
const read = readObject(body, 'plugin.json');
|
|
113
|
+
return 'invalid' in read ? 'invalid' : read.json;
|
|
114
|
+
}
|
|
115
|
+
async function turnedOff(io) {
|
|
116
|
+
const file = await readFile(agyConfigPath(io));
|
|
117
|
+
if (!('json' in file))
|
|
118
|
+
return false;
|
|
119
|
+
const plugins = isObject(file.json.plugins) ? file.json.plugins : {};
|
|
120
|
+
const ours = isObject(plugins[PLUGIN]) ? plugins[PLUGIN] : {};
|
|
121
|
+
return ours.enabled === false;
|
|
122
|
+
}
|
|
123
|
+
async function readSettings(io) {
|
|
124
|
+
const file = await readFile(agySettingsPath(io));
|
|
125
|
+
if ('invalid' in file)
|
|
126
|
+
return file;
|
|
127
|
+
const permissions = file.json.permissions;
|
|
128
|
+
if (permissions !== undefined && !isObject(permissions))
|
|
129
|
+
return {
|
|
130
|
+
path: file.path,
|
|
131
|
+
invalid: `${file.path} has a “permissions” that isn’t an object, so I left it alone.`,
|
|
132
|
+
};
|
|
133
|
+
if (isObject(permissions) && permissions.allow !== undefined && !Array.isArray(permissions.allow))
|
|
134
|
+
return {
|
|
135
|
+
path: file.path,
|
|
136
|
+
invalid: `${file.path} has a “permissions.allow” that isn’t a list, so I left it alone.`,
|
|
137
|
+
};
|
|
138
|
+
return file;
|
|
139
|
+
}
|
|
140
|
+
const allowedIn = (file) => {
|
|
141
|
+
if (!('json' in file) || !isObject(file.json.permissions))
|
|
142
|
+
return [];
|
|
143
|
+
const allow = file.json.permissions.allow;
|
|
144
|
+
return Array.isArray(allow)
|
|
145
|
+
? allow.filter((rule) => typeof rule === 'string')
|
|
146
|
+
: [];
|
|
147
|
+
};
|
|
148
|
+
const rulesText = (rules) => rules.length > 1 ? `${rules.slice(0, -1).join(', ')} and ${rules.at(-1)}` : (rules[0] ?? '');
|
|
149
|
+
async function writeBack(path, next) {
|
|
150
|
+
const json = JSON.parse(next.replace(/^/, ''));
|
|
151
|
+
if (Object.keys(json).length === 0)
|
|
152
|
+
await rm(path, { force: true });
|
|
153
|
+
else
|
|
154
|
+
await writeWhole(path, next);
|
|
155
|
+
}
|
|
156
|
+
export const stubBody = (stub) => stub.replace(/^---\n[\s\S]*?\n---\n?/, '').trim();
|
|
157
|
+
export function rulesFile(stub, origin) {
|
|
158
|
+
const body = stubBody(stub);
|
|
159
|
+
return `# Pending You
|
|
160
|
+
|
|
161
|
+
${body ? `${body}\n\n` : ''}## Answers in Antigravity
|
|
162
|
+
|
|
163
|
+
An idle Antigravity conversation hears your person’s answer only through a hold you start: right after you post a card (post_request) or an answer (post_answer), run \`${holdCommand('<requestId>', origin, undefined, 'antigravity')}\` as a background command (run_command with a short WaitMsBeforeAsync), then keep working or end your turn. When it finishes it says what came: act on it as it says. Answers waiting at your person’s next message come with it.
|
|
164
|
+
|
|
165
|
+
## Finishing setup
|
|
166
|
+
|
|
167
|
+
When your person says “${FINISH_SAY}”, or asks you to finish setting up Pending You, this is all of it: don’t ask whoami for the guide, and run no command to read anything. ${setupCalls('antigravity', true)}
|
|
168
|
+
`;
|
|
169
|
+
}
|
|
170
|
+
export function hooksFile(line) {
|
|
171
|
+
const handler = (sub) => ({ type: 'command', command: line(sub), timeout: 10 });
|
|
172
|
+
return {
|
|
173
|
+
[PLUGIN]: {
|
|
174
|
+
SessionStart: [handler('pickup')],
|
|
175
|
+
PreInvocation: [handler('handoff')],
|
|
176
|
+
PostToolUse: [{ matcher: AGY_POST_TOOL_MATCHER, hooks: [handler('posted')] }],
|
|
177
|
+
Stop: [handler('stopcheck')],
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
export const agyHookLine = (line) => line.replace(/ \|\| true$/, " || echo '{}'");
|
|
182
|
+
export function serverEntry(bridge, origin) {
|
|
183
|
+
const [command, ...args] = bridge ?? [];
|
|
184
|
+
return {
|
|
185
|
+
...(command ? { command, args } : { url: `${origin}/mcp` }),
|
|
186
|
+
tools: Object.fromEntries(EAGER_TOOLS.map((tool) => [tool, { eager: true }])),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
const json = (value) => `${JSON.stringify(value, null, 2)}\n`;
|
|
190
|
+
const switchesFor = (io, ctx) => switches(io, ctx, {
|
|
191
|
+
name: NAME,
|
|
192
|
+
what: `Antigravity signs in to Pending You by itself here (its pendingyou server in ${globalMcpPath(io)}).`,
|
|
193
|
+
uses: 'Pending You’s hooks for Antigravity use',
|
|
194
|
+
headless: false,
|
|
195
|
+
});
|
|
196
|
+
const RESTART = 'restart Antigravity (/exit, then agy; agy -c picks the conversation up again), or start agy in the folder you work in';
|
|
197
|
+
export const antigravity = {
|
|
198
|
+
id: 'antigravity',
|
|
199
|
+
name: NAME,
|
|
200
|
+
minVersion: AGY_MIN,
|
|
201
|
+
optIn: true,
|
|
202
|
+
async detect(io) {
|
|
203
|
+
const result = await io.run('agy', ['--version'], 20_000);
|
|
204
|
+
if (result.code !== 0)
|
|
205
|
+
return null;
|
|
206
|
+
return { version: /(\d+\.\d+\.\d+)/.exec(result.stdout)?.[1] ?? 'installed' };
|
|
207
|
+
},
|
|
208
|
+
async installed(io) {
|
|
209
|
+
return (await readAntigravityManifest(io)) !== null;
|
|
210
|
+
},
|
|
211
|
+
async usesHelper(io, origin) {
|
|
212
|
+
if (io.platform === 'win32')
|
|
213
|
+
return false;
|
|
214
|
+
const server = await pluginServer(io);
|
|
215
|
+
return Boolean(server?.command && isOurBridge(server.command) && originOf(server) === origin);
|
|
216
|
+
},
|
|
217
|
+
async prepare(io, ctx, detected) {
|
|
218
|
+
const url = `${ctx.origin}/mcp`;
|
|
219
|
+
const flag = originArgs(ctx.origin);
|
|
220
|
+
const skip = (step) => ({
|
|
221
|
+
app: antigravity,
|
|
222
|
+
detected,
|
|
223
|
+
signIn: null,
|
|
224
|
+
skipped: step,
|
|
225
|
+
install: async () => [],
|
|
226
|
+
next: () => null,
|
|
227
|
+
});
|
|
228
|
+
if (io.platform === 'win32')
|
|
229
|
+
return skip({
|
|
230
|
+
ok: true,
|
|
231
|
+
text: 'Antigravity on Windows isn’t set up by init yet: paste Pending You’s setup message for other MCP apps into it instead.',
|
|
232
|
+
});
|
|
233
|
+
const dir = pluginDir(io);
|
|
234
|
+
const before = await readAntigravityManifest(io);
|
|
235
|
+
const existing = await pluginJson(io);
|
|
236
|
+
if (existing !== null && !before && (existing === 'invalid' || !isOurPlugin(existing)))
|
|
237
|
+
return skip({
|
|
238
|
+
ok: false,
|
|
239
|
+
text: `${dir} holds a plugin that isn’t Pending You’s, so I left it alone. Move it elsewhere, then run init again${flag ? ` with${flag}` : ''}.`,
|
|
240
|
+
});
|
|
241
|
+
let how = ctx.oauth ? 'antigravity' : 'bridge';
|
|
242
|
+
let move = false;
|
|
243
|
+
let note = null;
|
|
244
|
+
const global = await readFile(globalMcpPath(io));
|
|
245
|
+
const theirs = 'json' in global ? serverIn(global.json) : null;
|
|
246
|
+
if ('invalid' in global)
|
|
247
|
+
note = {
|
|
248
|
+
ok: true,
|
|
249
|
+
text: `${global.invalid} If it has a pendingyou server, take it out: Pending You’s plugin brings its own.`,
|
|
250
|
+
};
|
|
251
|
+
else if (theirs) {
|
|
252
|
+
const reaches = originOf(theirs);
|
|
253
|
+
const ours = Boolean(theirs.command && isOurBridge(theirs.command));
|
|
254
|
+
if (theirs.command && !ours) {
|
|
255
|
+
how = 'kept';
|
|
256
|
+
note = {
|
|
257
|
+
ok: false,
|
|
258
|
+
text: `Kept the pendingyou MCP server in ${global.path}: it runs a command of its own (${theirs.command.join(' ')}). Pending You’s plugin brings no server beside it.`,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
else if (ours && reaches === ctx.origin && !ctx.oauth)
|
|
262
|
+
move = true;
|
|
263
|
+
else if (reaches !== ctx.origin) {
|
|
264
|
+
const was = theirs.url ?? `${reaches ?? 'another Pending You'}/mcp`;
|
|
265
|
+
ctx.progress(`Antigravity’s pendingyou MCP server in ${global.path} points at ${was}, not ${url}.\n`);
|
|
266
|
+
const replace = ctx.yes ||
|
|
267
|
+
(io.interactive &&
|
|
268
|
+
/^\s*y(es)?\s*$/i.test(await io.ask(`Take it out, so Antigravity uses Pending You’s plugin for ${url}? [y/N] `)));
|
|
269
|
+
if (!replace)
|
|
270
|
+
return skip({
|
|
271
|
+
ok: false,
|
|
272
|
+
text: `Kept Antigravity’s pendingyou MCP server at ${was}, so Antigravity isn’t set up for ${ctx.origin}. To use ${url}, run init again with --yes.`,
|
|
273
|
+
});
|
|
274
|
+
move = true;
|
|
275
|
+
}
|
|
276
|
+
else if (theirs.ownAuth) {
|
|
277
|
+
how = 'kept';
|
|
278
|
+
note = {
|
|
279
|
+
ok: false,
|
|
280
|
+
text: `Kept the pendingyou MCP server in ${global.path}: it signs in some way of its own (an Authorization header). Pending You’s plugin brings no server beside it.`,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
else if (ctx.oauth)
|
|
284
|
+
how = 'kept';
|
|
285
|
+
else if (await switchesFor(io, ctx))
|
|
286
|
+
move = true;
|
|
287
|
+
else {
|
|
288
|
+
how = 'kept';
|
|
289
|
+
note = {
|
|
290
|
+
ok: true,
|
|
291
|
+
text: `Kept Antigravity’s own sign-in to Pending You (${url}, in ${global.path}). To move it to this computer’s, run: npx -y pendingyou@latest init --app antigravity --yes${flag}`,
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
const settings = await readSettings(io);
|
|
296
|
+
const allowed = allowedIn(settings);
|
|
297
|
+
const missing = PERMISSION_RULES.filter((rule) => !allowed.includes(rule));
|
|
298
|
+
let allowing;
|
|
299
|
+
if ('invalid' in settings)
|
|
300
|
+
allowing = 'unreadable';
|
|
301
|
+
else if (missing.length === 0)
|
|
302
|
+
allowing = 'already';
|
|
303
|
+
else if (!io.interactive || ctx.yes)
|
|
304
|
+
allowing = 'nobody';
|
|
305
|
+
else {
|
|
306
|
+
io.out(`Antigravity asks you before each Pending You tool call and each hold (the command that waits for your answer in the background). init can allow both in ${settings.path}: ${rulesText(missing)}.\n`);
|
|
307
|
+
allowing = /^\s*y(es)?\s*$/i.test(await io.ask('Allow them in Antigravity? [y/N] '))
|
|
308
|
+
? 'added'
|
|
309
|
+
: 'declined';
|
|
310
|
+
}
|
|
311
|
+
return {
|
|
312
|
+
app: antigravity,
|
|
313
|
+
detected,
|
|
314
|
+
signIn: how === 'bridge' ? 'connection' : 'hear',
|
|
315
|
+
bridged: how === 'bridge',
|
|
316
|
+
install: async (ictx) => {
|
|
317
|
+
const steps = [];
|
|
318
|
+
const report = (step) => {
|
|
319
|
+
steps.push(step);
|
|
320
|
+
ictx.report(step);
|
|
321
|
+
};
|
|
322
|
+
const earlier = await readAntigravityManifest(io);
|
|
323
|
+
if (note)
|
|
324
|
+
report(note);
|
|
325
|
+
let moved = earlier?.moved;
|
|
326
|
+
if (move) {
|
|
327
|
+
const current = await readFile(globalMcpPath(io));
|
|
328
|
+
const server = 'json' in current ? serverIn(current.json) : null;
|
|
329
|
+
if ('json' in current && server) {
|
|
330
|
+
try {
|
|
331
|
+
await writeBack(current.path, editJson(current.text, { op: 'delete', path: ['mcpServers', SERVER] }, current.path));
|
|
332
|
+
moved = server.entry;
|
|
333
|
+
report({
|
|
334
|
+
ok: true,
|
|
335
|
+
text: `Took the pendingyou MCP server out of ${current.path} (it reached ${server.url ?? `${originOf(server)}/mcp`}): Pending You’s plugin brings its own. Uninstall puts it back.`,
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
catch (error) {
|
|
339
|
+
report({
|
|
340
|
+
ok: false,
|
|
341
|
+
text: `Couldn’t take the pendingyou MCP server out of ${current.path} (${error instanceof Error ? error.message : 'it went wrong'}): take it out yourself, then run init again.`,
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
let stub = null;
|
|
347
|
+
try {
|
|
348
|
+
const response = await io.fetch(`${ictx.origin}/skill-stub.md`, {
|
|
349
|
+
signal: AbortSignal.timeout(15_000),
|
|
350
|
+
});
|
|
351
|
+
if (response.ok)
|
|
352
|
+
stub = await response.text();
|
|
353
|
+
}
|
|
354
|
+
catch { }
|
|
355
|
+
const dir = pluginDir(io);
|
|
356
|
+
const read = (file) => readText(join(dir, file)).catch(() => null);
|
|
357
|
+
if (stub === null)
|
|
358
|
+
report({
|
|
359
|
+
ok: (await read('rules/AGENTS.md')) !== null,
|
|
360
|
+
text: `Couldn’t fetch the guide’s stub from ${ictx.origin}/skill-stub.md for the plugin’s rules and skill. Run init again later.`,
|
|
361
|
+
});
|
|
362
|
+
const server = how === 'kept' ? null : how === 'bridge' ? ictx.bridge : [];
|
|
363
|
+
if (how === 'bridge' && !ictx.bridge)
|
|
364
|
+
report({
|
|
365
|
+
ok: false,
|
|
366
|
+
text: 'Didn’t add Antigravity’s pendingyou MCP server: it runs pendingyou’s own copy through the bridge, which isn’t installed. Run init again.',
|
|
367
|
+
});
|
|
368
|
+
const wanted = {
|
|
369
|
+
'plugin.json': json({
|
|
370
|
+
name: PLUGIN,
|
|
371
|
+
displayName: 'Pending You',
|
|
372
|
+
version: VERSION,
|
|
373
|
+
description: DESCRIPTION,
|
|
374
|
+
homepage: HOMEPAGE,
|
|
375
|
+
}),
|
|
376
|
+
...(server && (how !== 'bridge' || ictx.bridge)
|
|
377
|
+
? {
|
|
378
|
+
'mcp_config.json': json({
|
|
379
|
+
mcpServers: { [SERVER]: serverEntry(server.length ? server : null, ictx.origin) },
|
|
380
|
+
}),
|
|
381
|
+
}
|
|
382
|
+
: {}),
|
|
383
|
+
'hooks.json': json(hooksFile((sub) => agyHookLine(ictx.hookLine(sub)))),
|
|
384
|
+
...(stub !== null
|
|
385
|
+
? {
|
|
386
|
+
'rules/AGENTS.md': rulesFile(stub, ictx.origin),
|
|
387
|
+
'skills/pendingyou/SKILL.md': stub,
|
|
388
|
+
}
|
|
389
|
+
: {}),
|
|
390
|
+
};
|
|
391
|
+
let changed = false;
|
|
392
|
+
let fresh = existing === null;
|
|
393
|
+
try {
|
|
394
|
+
for (const file of FILES) {
|
|
395
|
+
const want = wanted[file];
|
|
396
|
+
const path = join(dir, file);
|
|
397
|
+
const have = await readText(path).catch(() => null);
|
|
398
|
+
if (want === undefined) {
|
|
399
|
+
if (have !== null && file === 'mcp_config.json' && earlier?.files.includes(file)) {
|
|
400
|
+
await rm(path, { force: true });
|
|
401
|
+
changed = true;
|
|
402
|
+
}
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
if (have !== want) {
|
|
406
|
+
await writeWhole(path, want);
|
|
407
|
+
changed = true;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
catch (error) {
|
|
412
|
+
fresh = false;
|
|
413
|
+
report({
|
|
414
|
+
ok: false,
|
|
415
|
+
text: `Couldn’t write Pending You’s plugin in ${dir} (${error instanceof Error ? error.message : 'it went wrong'}). Run init again.`,
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
const serverWords = how === 'bridge'
|
|
419
|
+
? 'its pendingyou MCP server through Pending You’s bridge (this computer’s sign-in), its main tools loaded with each conversation'
|
|
420
|
+
: how === 'antigravity'
|
|
421
|
+
? `its pendingyou MCP server (${url}), which Antigravity signs in to by itself`
|
|
422
|
+
: 'no MCP server of its own (Antigravity keeps the one you have)';
|
|
423
|
+
report({
|
|
424
|
+
ok: true,
|
|
425
|
+
text: !changed
|
|
426
|
+
? `Pending You’s plugin for Antigravity was already in place (${dir}).`
|
|
427
|
+
: `${fresh ? 'Added' : 'Updated'} Pending You’s plugin for Antigravity in ${dir}: ${serverWords}; rules and a skill that say when to ask you; and hooks that hand it your answers as a conversation starts and with each message, and ask it to post what it leaves you only in chat.`,
|
|
428
|
+
});
|
|
429
|
+
if (await turnedOff(io))
|
|
430
|
+
report({
|
|
431
|
+
ok: false,
|
|
432
|
+
text: `Pending You’s plugin is turned off in Antigravity (${agyConfigPath(io)}). To turn it on: agy plugin enable ${PLUGIN}`,
|
|
433
|
+
});
|
|
434
|
+
const now = await readSettings(io);
|
|
435
|
+
const there = allowedIn(now);
|
|
436
|
+
const ours = (earlier?.permissions ?? []).filter((rule) => there.includes(rule));
|
|
437
|
+
const where = now.path;
|
|
438
|
+
const again = `To allow them, run npx pendingyou init --app antigravity${flag} again at a terminal.`;
|
|
439
|
+
if (allowing === 'added' && 'json' in now) {
|
|
440
|
+
const adding = PERMISSION_RULES.filter((rule) => !there.includes(rule));
|
|
441
|
+
try {
|
|
442
|
+
let next = now.text;
|
|
443
|
+
for (const rule of adding)
|
|
444
|
+
next = editJson(next, { op: 'append', path: ['permissions', 'allow'], value: rule }, where);
|
|
445
|
+
if (next !== now.text)
|
|
446
|
+
await writeWhole(where, next ?? '');
|
|
447
|
+
ours.push(...adding);
|
|
448
|
+
report({
|
|
449
|
+
ok: true,
|
|
450
|
+
text: `Allowed Pending You’s tools and its hold in Antigravity (${where}: ${rulesText(adding)}), so it runs them without asking each time.`,
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
catch (error) {
|
|
454
|
+
report({
|
|
455
|
+
ok: false,
|
|
456
|
+
text: `Couldn’t add Antigravity’s permission rules to ${where} (${error instanceof Error ? error.message : 'it went wrong'}), so it asks before each Pending You tool call and each hold. Add ${rulesText(adding)} to its “permissions.allow” yourself.`,
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
else if (allowing === 'already' ||
|
|
461
|
+
(allowing !== 'unreadable' && PERMISSION_RULES.every((rule) => there.includes(rule))))
|
|
462
|
+
report({
|
|
463
|
+
ok: true,
|
|
464
|
+
text: `Antigravity already runs Pending You’s tools and its hold without asking (${where}).`,
|
|
465
|
+
});
|
|
466
|
+
else if (allowing === 'declined')
|
|
467
|
+
report({
|
|
468
|
+
ok: true,
|
|
469
|
+
text: `Left Antigravity’s permissions as they were, as you said: it asks before each Pending You tool call and each hold. ${again}`,
|
|
470
|
+
});
|
|
471
|
+
else if (allowing === 'nobody')
|
|
472
|
+
report({
|
|
473
|
+
ok: true,
|
|
474
|
+
text: `Didn’t change Antigravity’s permissions (${ctx.yes ? '--yes never does' : 'nobody to ask here'}): it asks before each Pending You tool call and each hold. ${again}`,
|
|
475
|
+
});
|
|
476
|
+
else
|
|
477
|
+
report({
|
|
478
|
+
ok: true,
|
|
479
|
+
text: `${'invalid' in now ? now.invalid : `${where} can’t be read`} Antigravity asks before each Pending You tool call and each hold.`,
|
|
480
|
+
});
|
|
481
|
+
const manifest = {
|
|
482
|
+
version: 1,
|
|
483
|
+
origin: ictx.origin,
|
|
484
|
+
plugin: dir,
|
|
485
|
+
signsIn: how,
|
|
486
|
+
files: FILES.filter((file) => wanted[file] !== undefined ||
|
|
487
|
+
(file !== 'mcp_config.json' && earlier?.files.includes(file))),
|
|
488
|
+
...(moved ? { moved } : {}),
|
|
489
|
+
permissions: [...new Set(ours)],
|
|
490
|
+
setup: { since: new Date(io.now()).toISOString() },
|
|
491
|
+
};
|
|
492
|
+
await writeWhole(manifestPath(io), json(manifest), { secret: true });
|
|
493
|
+
return steps;
|
|
494
|
+
},
|
|
495
|
+
next: (ictx) => {
|
|
496
|
+
const login = how === 'antigravity' ? ', then type /mcp, choose pendingyou and sign in' : '';
|
|
497
|
+
const first = !ictx.signedIn && how === 'bridge'
|
|
498
|
+
? `run npx pendingyou login --app antigravity${flag}, then `
|
|
499
|
+
: '';
|
|
500
|
+
return {
|
|
501
|
+
lines: [`Next: ${first}${RESTART}${login}.`, 'Then say this to it:', '', FINISH_SAY],
|
|
502
|
+
together: `- Antigravity: ${first}${RESTART}${login}, then say the line below to it.`,
|
|
503
|
+
say: true,
|
|
504
|
+
};
|
|
505
|
+
},
|
|
506
|
+
};
|
|
507
|
+
},
|
|
508
|
+
async uninstall(io) {
|
|
509
|
+
const manifest = await readAntigravityManifest(io);
|
|
510
|
+
const steps = [];
|
|
511
|
+
const dir = manifest?.plugin ?? pluginDir(io);
|
|
512
|
+
const existing = await pluginJson(io);
|
|
513
|
+
if (manifest || (existing !== null && existing !== 'invalid' && isOurPlugin(existing))) {
|
|
514
|
+
let removed = false;
|
|
515
|
+
for (const file of FILES) {
|
|
516
|
+
const path = join(dir, file);
|
|
517
|
+
if ((await readText(path).catch(() => null)) === null)
|
|
518
|
+
continue;
|
|
519
|
+
await rm(path, { force: true });
|
|
520
|
+
removed = true;
|
|
521
|
+
}
|
|
522
|
+
for (const folder of ['skills/pendingyou', 'skills', 'rules', ''])
|
|
523
|
+
await rmdir(join(dir, folder)).catch(() => { });
|
|
524
|
+
if (removed)
|
|
525
|
+
steps.push({ ok: true, text: 'Removed Pending You’s plugin from Antigravity.' });
|
|
526
|
+
}
|
|
527
|
+
if (manifest?.moved) {
|
|
528
|
+
const global = await readFile(globalMcpPath(io));
|
|
529
|
+
if ('invalid' in global)
|
|
530
|
+
steps.push({
|
|
531
|
+
ok: false,
|
|
532
|
+
text: `${global.invalid} To put your pendingyou MCP server back, add it to its “mcpServers” yourself: ${JSON.stringify({ [SERVER]: manifest.moved })}`,
|
|
533
|
+
});
|
|
534
|
+
else if (!serverIn(global.json)) {
|
|
535
|
+
await writeWhole(global.path, editJson(global.text, { op: 'set', path: ['mcpServers', SERVER], value: manifest.moved }, global.path));
|
|
536
|
+
steps.push({ ok: true, text: `Put your pendingyou MCP server back in ${global.path}.` });
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
const added = manifest?.permissions ?? [];
|
|
540
|
+
if (added.length) {
|
|
541
|
+
const settings = await readSettings(io);
|
|
542
|
+
if ('invalid' in settings)
|
|
543
|
+
steps.push({
|
|
544
|
+
ok: false,
|
|
545
|
+
text: `${settings.invalid} Take ${rulesText(added)} out of its “permissions.allow” yourself.`,
|
|
546
|
+
});
|
|
547
|
+
else if (allowedIn(settings).some((rule) => added.includes(rule))) {
|
|
548
|
+
let next = editJson(settings.text, {
|
|
549
|
+
op: 'remove',
|
|
550
|
+
path: ['permissions', 'allow'],
|
|
551
|
+
match: (rule) => typeof rule === 'string' && added.includes(rule),
|
|
552
|
+
}, settings.path);
|
|
553
|
+
const after = JSON.parse(next.replace(/^/, ''));
|
|
554
|
+
const permissions = isObject(after.permissions) ? after.permissions : null;
|
|
555
|
+
if (permissions && Array.isArray(permissions.allow) && permissions.allow.length === 0)
|
|
556
|
+
next = editJson(next, { op: 'delete', path: ['permissions', 'allow'] }, settings.path);
|
|
557
|
+
const left = JSON.parse(next.replace(/^/, ''));
|
|
558
|
+
if (isObject(left.permissions) && Object.keys(left.permissions).length === 0)
|
|
559
|
+
next = editJson(next, { op: 'delete', path: ['permissions'] }, settings.path);
|
|
560
|
+
await writeBack(settings.path, next);
|
|
561
|
+
steps.push({
|
|
562
|
+
ok: true,
|
|
563
|
+
text: `Took Pending You’s rules out of Antigravity’s permissions (${settings.path}).`,
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
for (const path of [...threadFiles(io, 'antigravity'), ...agyHookFiles(io)])
|
|
568
|
+
await rm(path, { recursive: true, force: true });
|
|
569
|
+
await removePresenceFiles(io, 'antigravity');
|
|
570
|
+
await rm(manifestPath(io), { force: true });
|
|
571
|
+
return steps;
|
|
572
|
+
},
|
|
573
|
+
async status(io, ctx) {
|
|
574
|
+
const { origin, signIn } = ctx;
|
|
575
|
+
const flag = originArgs(origin);
|
|
576
|
+
const dir = pluginDir(io);
|
|
577
|
+
const [detected, manifest, plugin, off, settings, global] = await Promise.all([
|
|
578
|
+
antigravity.detect(io),
|
|
579
|
+
readAntigravityManifest(io),
|
|
580
|
+
pluginJson(io),
|
|
581
|
+
turnedOff(io),
|
|
582
|
+
readSettings(io),
|
|
583
|
+
readFile(globalMcpPath(io)),
|
|
584
|
+
]);
|
|
585
|
+
const credential = await readCredential(io, origin, 'antigravity');
|
|
586
|
+
const url = `${origin}/mcp`;
|
|
587
|
+
const why = headlessReason(io);
|
|
588
|
+
const mark = (ok) => (ok ? 'ok ' : 'missing');
|
|
589
|
+
const fix = `npx pendingyou init --app antigravity${flag}`;
|
|
590
|
+
const mcp = await readFile(join(dir, 'mcp_config.json'));
|
|
591
|
+
const server = 'json' in mcp ? serverIn(mcp.json) : null;
|
|
592
|
+
const theirs = 'json' in global ? serverIn(global.json) : null;
|
|
593
|
+
const bridged = Boolean(server?.command && isOurBridge(server.command) && originOf(server) === origin);
|
|
594
|
+
const bridge = bridged || manifest?.signsIn === 'bridge' || (!server && !manifest && !theirs);
|
|
595
|
+
const connected = credential?.kind === 'connection';
|
|
596
|
+
const signOk = signIn.state === 'ok' && (!bridge || connected);
|
|
597
|
+
const title = signIn.state === 'ok' && signIn.for ? connectionTitle(signIn.for) : `${NAME} on this computer`;
|
|
598
|
+
const signText = signIn.state === 'ok'
|
|
599
|
+
? bridge
|
|
600
|
+
? connected
|
|
601
|
+
? `this computer’s own connection, ${title}; Antigravity here asks and hears through it`
|
|
602
|
+
: `this computer’s sign-in for Antigravity only hears answers, so Antigravity here can’t use it; run npx pendingyou login --app antigravity${flag}`
|
|
603
|
+
: `hears for ${signIn.connections} Antigravity connection${signIn.connections === 1 ? '' : 's'}`
|
|
604
|
+
: signIn.state === 'ended'
|
|
605
|
+
? `ended; run npx pendingyou login --app antigravity${flag}`
|
|
606
|
+
: signIn.state === 'none'
|
|
607
|
+
? `not signed in; run ${bridged ? `npx pendingyou login --app antigravity${flag}` : fix}`
|
|
608
|
+
: 'Pending You couldn’t be reached';
|
|
609
|
+
const ours = plugin !== null && plugin !== 'invalid' && isOurPlugin(plugin);
|
|
610
|
+
const pluginOk = ours && !off;
|
|
611
|
+
const pluginText = !ours
|
|
612
|
+
? plugin === null
|
|
613
|
+
? `not installed; run ${fix}`
|
|
614
|
+
: `${dir} holds a plugin that isn’t Pending You’s`
|
|
615
|
+
: off
|
|
616
|
+
? `${dir}, turned off in Antigravity; run agy plugin enable ${PLUGIN}`
|
|
617
|
+
: `${dir}, on`;
|
|
618
|
+
const kept = !server && manifest?.signsIn === 'kept' && theirs !== null;
|
|
619
|
+
const reaches = server ? originOf(server) : theirs ? originOf(theirs) : null;
|
|
620
|
+
const mcpOk = kept
|
|
621
|
+
? reaches === origin
|
|
622
|
+
: Boolean(server) && reaches === origin && (!bridge || bridged);
|
|
623
|
+
const mcpText = (() => {
|
|
624
|
+
if ('invalid' in mcp)
|
|
625
|
+
return mcp.invalid;
|
|
626
|
+
if (kept && theirs)
|
|
627
|
+
return reaches === origin
|
|
628
|
+
? `pendingyou in ${globalMcpPath(io)}, your own (Antigravity signs in to it by itself)`
|
|
629
|
+
: `pendingyou in ${globalMcpPath(io)} points at ${theirs.url ?? `${reaches}/mcp`}, not ${url}; run ${fix} --yes`;
|
|
630
|
+
if (!server)
|
|
631
|
+
return `not added; run ${fix}`;
|
|
632
|
+
if (reaches !== origin)
|
|
633
|
+
return `points at ${server.url ?? `${reaches}/mcp`}, not ${url}; run ${fix}`;
|
|
634
|
+
if (bridged)
|
|
635
|
+
return `pendingyou in ${mcp.path}, through the bridge (${bridgePath(io)} --app antigravity); its main tools load with each conversation`;
|
|
636
|
+
return bridge
|
|
637
|
+
? `pendingyou (${server.url}) signs in by itself; run ${fix} to use this computer’s sign-in`
|
|
638
|
+
: `pendingyou (${server.url}), signed in by Antigravity itself (its /mcp)`;
|
|
639
|
+
})();
|
|
640
|
+
const check = bridge && bridged ? await checkBridge(io, origin, 'antigravity') : null;
|
|
641
|
+
const reached = check?.ok && signOk && signIn.state === 'ok'
|
|
642
|
+
? await probeBridge(io, origin, 'antigravity')
|
|
643
|
+
: null;
|
|
644
|
+
const bridgeLine = check
|
|
645
|
+
? check.ok
|
|
646
|
+
? reached === null
|
|
647
|
+
? `${check.node} (${foundBy(check.from)}) runs pendingyou ${check.version}, and Pending You takes Antigravity’s sign-in`
|
|
648
|
+
: `${check.node} runs pendingyou ${check.version}, but ${reached}`
|
|
649
|
+
: `${check.why}; run ${fix}`
|
|
650
|
+
: null;
|
|
651
|
+
const bridgeOk = !check || (check.ok && reached === null);
|
|
652
|
+
const rules = (await readText(join(dir, 'rules', 'AGENTS.md')).catch(() => null)) !== null;
|
|
653
|
+
const skill = (await readText(join(dir, 'skills', 'pendingyou', 'SKILL.md')).catch(() => null)) !== null;
|
|
654
|
+
const rulesOk = rules && skill;
|
|
655
|
+
const rulesText_ = rulesOk
|
|
656
|
+
? `${join(dir, 'rules', 'AGENTS.md')} (always on) and the pendingyou skill`
|
|
657
|
+
: `${rules ? 'the skill' : 'the rules'} ${rules || skill ? 'is' : 'are'} missing; run ${fix}`;
|
|
658
|
+
const hooks = await readFile(join(dir, 'hooks.json'));
|
|
659
|
+
const named = 'json' in hooks && isObject(hooks.json[PLUGIN]) ? hooks.json[PLUGIN] : {};
|
|
660
|
+
const has = (event, sub) => Array.isArray(named[event]) &&
|
|
661
|
+
named[event].some((entry) => isObject(entry) &&
|
|
662
|
+
(isOurHook(entry.command, sub) ||
|
|
663
|
+
(Array.isArray(entry.hooks) &&
|
|
664
|
+
entry.hooks.some((hook) => isObject(hook) && isOurHook(hook.command, sub)))));
|
|
665
|
+
const events = Object.entries(AGY_HOOK_EVENTS);
|
|
666
|
+
const hooksOk = events.every(([sub, event]) => has(event, sub));
|
|
667
|
+
const hooksText = hooksOk
|
|
668
|
+
? `${events.map(([, event]) => event).join(', ')}, in ${hooks.path}`
|
|
669
|
+
: `not installed; run ${fix}`;
|
|
670
|
+
const allowed = allowedIn(settings);
|
|
671
|
+
const permitted = PERMISSION_RULES.every((rule) => allowed.includes(rule));
|
|
672
|
+
const permissionText = 'invalid' in settings
|
|
673
|
+
? settings.invalid
|
|
674
|
+
: permitted
|
|
675
|
+
? `Antigravity runs Pending You’s tools and its hold without asking (${settings.path})`
|
|
676
|
+
: `Antigravity asks before each Pending You tool call and each hold; to allow them, run ${fix} at a terminal`;
|
|
677
|
+
const lines = [
|
|
678
|
+
`Pending You for Antigravity · ${origin}${why ? ` · no browser here (${why})` : ''}`,
|
|
679
|
+
` ${mark(signOk)} Sign-in: ${signText}`,
|
|
680
|
+
` ${mark(detected !== null)} Antigravity: ${detected?.version ?? 'agy not found on PATH'}`,
|
|
681
|
+
` ${mark(pluginOk)} Plugin: ${pluginText}`,
|
|
682
|
+
` ${mark(mcpOk)} MCP server: ${mcpText}`,
|
|
683
|
+
...(bridgeLine ? [` ${mark(bridgeOk)} Bridge: ${bridgeLine}`] : []),
|
|
684
|
+
` ${mark(rulesOk)} Rules and skill: ${rulesText_}`,
|
|
685
|
+
` ${mark(hooksOk)} Hooks: ${hooksText}`,
|
|
686
|
+
` ${permitted ? 'ok ' : ' '} Permissions: ${permissionText}`,
|
|
687
|
+
connected && hooksOk
|
|
688
|
+
? ' ok Presence: tells Pending You when a conversation is open (its keeper says so every 5 minutes while agy runs)'
|
|
689
|
+
: ` Presence: off: it needs ${connected ? 'the hooks' : 'Antigravity signed in through this computer’s own connection'}`,
|
|
690
|
+
` Wake: an idle conversation hears your answer through the hold it starts in the background (${holdCommand('<requestId>', origin, undefined, 'antigravity')}); otherwise with your next message`,
|
|
691
|
+
];
|
|
692
|
+
const setup = setupStatus(NAME, signIn.state === 'ok' ? setupOf(signIn.for) : null);
|
|
693
|
+
if (setup)
|
|
694
|
+
lines.push(` ${setup === 'finished' ? 'ok ' : ' '} Setup: ${setup}`);
|
|
695
|
+
const reachable = signOk && mcpOk && bridgeOk && pluginOk;
|
|
696
|
+
const ready = reachable && signIn.state === 'ok' && hooksOk && rulesOk;
|
|
697
|
+
lines.push(ready
|
|
698
|
+
? 'Ready: Antigravity hears answers with your next message, and while it waits on a hold it started.'
|
|
699
|
+
: reachable
|
|
700
|
+
? 'Not ready: Antigravity hears answers only while it’s working until the lines marked missing are fixed.'
|
|
701
|
+
: 'Not ready: Antigravity here can’t reach Pending You until the lines marked missing are fixed.');
|
|
702
|
+
return { lines, ready };
|
|
703
|
+
},
|
|
704
|
+
};
|