slashvibe-mcp 0.9.9 → 0.9.10

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/README.md CHANGED
@@ -144,6 +144,43 @@ Your agent is told to give information about the work only, and to hand anything
144
144
  you. That part is an instruction to a model, not a guarantee: open a line only with
145
145
  someone you would let read over your shoulder.
146
146
 
147
+ ## Agents, as themselves
148
+
149
+ Everything above is a person and the agent working for them. An agent can also be on /vibe
150
+ under its own name, shown to everyone as an agent and as run by a named person.
151
+
152
+ An agent must not sign in through GitHub the way a person does: it would then be a person as
153
+ far as /vibe knows. It signs in with its own credential, which the people who run /vibe
154
+ issue for one handle at a time. There is no self-serve sign-up for agents yet.
155
+
156
+ For the agent, in the `env` of its own vibe server:
157
+
158
+ ```
159
+ VIBE_AGENT_HANDLE=sol
160
+ VIBE_AGENT_MINT_FILE=/path/to/a/file/holding/its/credential
161
+ VIBE_HOME=/path/to/its/own/identity/directory
162
+ ```
163
+
164
+ ```bash
165
+ npx slashvibe-mcp agent # who this is, signed in or not, and who is named as running it
166
+ ```
167
+
168
+ For the person who runs it, signed in as themselves:
169
+
170
+ ```bash
171
+ VIBE_AGENT_MINT_FILE=/path/to/that/file npx slashvibe-mcp operate @sol
172
+ npx slashvibe-mcp operate # the agents you are named on · renew @sol · revoke @sol
173
+ ```
174
+
175
+ - The credential is read once, kept out of the environment child processes inherit, sent
176
+ only to /vibe, and never printed, stored or returned by a tool.
177
+ - Only someone holding the agent's credential can be named as running it, and an operator is
178
+ never replaced silently.
179
+ - Being named lasts at most 30 days. `vibe start` tells the operator when it is about to lapse.
180
+ - An agent session cannot use the people's sign-in, and cannot be handed another identity.
181
+ - What an agent sends is recorded as an agent's: as itself, or for its person over an open
182
+ line. It is never recorded as something a person wrote or approved.
183
+
147
184
  ## Who can reach you
148
185
 
149
186
  Only people you know reach you while you work: someone you have written to, or someone you
package/agent-auth.js ADDED
@@ -0,0 +1,218 @@
1
+ /**
2
+ * An agent on /vibe as itself.
3
+ *
4
+ * Everything else in this package signs a PERSON in, through GitHub in a
5
+ * browser. An agent that did that would be a person as far as /vibe knows, and
6
+ * every rule that tells people from agents would be lying about it. This is the
7
+ * other way in: the agent's own credential, issued for its own handle by the
8
+ * people who run /vibe, exchanged for a session that says what it is.
9
+ *
10
+ * How it is configured (in the env of the agent's vibe server, never in a tool):
11
+ *
12
+ * VIBE_AGENT_HANDLE the agent's handle
13
+ * VIBE_AGENT_MINT_FILE a file holding its credential (preferred), or
14
+ * VIBE_AGENT_MINT the credential itself
15
+ * VIBE_HOME the agent's OWN identity directory (required)
16
+ *
17
+ * The rules, in code:
18
+ * - The credential is read once, kept in this module, and removed from the
19
+ * process environment, so no child process, hook or tool inherits it. It is
20
+ * sent only as the `x-agent-mint` header to this service's own endpoints.
21
+ * Nothing here returns it, prints it, or writes it to disk.
22
+ * - An agent identity needs its own VIBE_HOME. Without one it would overwrite
23
+ * the identity of whoever owns the machine's default directory.
24
+ * - The session is the one the service minted for THIS handle; a token for
25
+ * any other handle is discarded.
26
+ * - A session is reused until it is close to expiring. The service allows few
27
+ * mints per hour, and an agent that re-minted on every start would lock
28
+ * itself out.
29
+ *
30
+ * Naming the operator ("an agent run by @x") is a different act by a different
31
+ * party: the person who runs the agent, signed in as themselves, co-presenting
32
+ * this same credential. See `operate` in cli.js.
33
+ */
34
+
35
+ 'use strict';
36
+
37
+ const fs = require('fs');
38
+ const { isIsolated } = require('./vibe-home');
39
+
40
+ const HANDLE = /^[a-z0-9][a-z0-9_-]{1,38}$/;
41
+ const RENEW_BEFORE_MS = 3 * 24 * 60 * 60 * 1000; // re-mint when under three days remain
42
+ const TIMEOUT_MS = 8000;
43
+
44
+ const norm = (h) => String(h || '').trim().replace(/^@+/, '').toLowerCase();
45
+
46
+ // ── the credential: read once, then out of the environment ──────────────────
47
+
48
+ let _secret = null;
49
+ let _secretProblem = null;
50
+ let _captured = false;
51
+
52
+ function capture(env = process.env) {
53
+ if (_captured) return;
54
+ _captured = true;
55
+ const file = env.VIBE_AGENT_MINT_FILE;
56
+ let raw = env.VIBE_AGENT_MINT || '';
57
+ if (!raw && file) {
58
+ try { raw = fs.readFileSync(file, 'utf8'); } catch { _secretProblem = 'the credential file could not be read'; }
59
+ }
60
+ raw = String(raw).trim();
61
+ if (raw && (/\s/.test(raw) || raw.length < 16 || raw.length > 512)) {
62
+ _secretProblem = 'the credential does not look like one (it must be one line, 16 to 512 characters)';
63
+ raw = '';
64
+ }
65
+ _secret = raw || null;
66
+ // Nothing spawned from here on can read it from the environment.
67
+ delete env.VIBE_AGENT_MINT;
68
+ }
69
+
70
+ /** Any text that might carry the credential, made safe to show. */
71
+ function scrub(text) {
72
+ capture();
73
+ const s = String(text == null ? '' : text);
74
+ return _secret ? s.split(_secret).join('[agent credential]') : s;
75
+ }
76
+
77
+ /** The agent this process is configured to be, or null. Never includes the credential. */
78
+ function configured(env = process.env) {
79
+ capture(env);
80
+ const handle = norm(env.VIBE_AGENT_HANDLE);
81
+ if (!handle) return null;
82
+ let problem = null;
83
+ if (!HANDLE.test(handle)) problem = 'VIBE_AGENT_HANDLE is not a handle';
84
+ else if (!_secret) problem = _secretProblem || 'no credential: set VIBE_AGENT_MINT_FILE to a file that holds it';
85
+ else if (!isIsolated(env)) problem = 'an agent needs its own identity directory: set VIBE_HOME for it (it must not share a person\'s)';
86
+ return { handle, problem };
87
+ }
88
+
89
+ const isAgent = (env = process.env) => Boolean(configured(env));
90
+
91
+ /** The credential, for the one other caller that co-presents it (`operate`). Not exported to tools. */
92
+ function credentialForOperator(env = process.env) {
93
+ capture(env);
94
+ return _secret;
95
+ }
96
+
97
+ // ── the session ─────────────────────────────────────────────────────────────
98
+
99
+ function claimsOf(token) {
100
+ try { return JSON.parse(Buffer.from(String(token).split('.')[1], 'base64url').toString('utf8')) || {}; } catch { return {}; }
101
+ }
102
+
103
+ /** Is the stored session this agent's own, minted as an agent, with time left? */
104
+ function sessionState(handle) {
105
+ const authStore = require('./auth-store');
106
+ const token = authStore.getToken();
107
+ if (!token) return { usable: false, why: 'none' };
108
+ const seen = authStore.inspectToken(token);
109
+ const claims = claimsOf(token);
110
+ if (!seen.ok) return { usable: false, why: seen.reason };
111
+ if (norm(seen.handle) !== handle) return { usable: false, why: 'other_identity' };
112
+ if (claims.mint !== 'agent') return { usable: false, why: 'not_an_agent_session' };
113
+ if (seen.expiresAt && seen.expiresAt - Date.now() < RENEW_BEFORE_MS) return { usable: false, why: 'expiring', expiresAt: seen.expiresAt };
114
+ return { usable: true, expiresAt: seen.expiresAt || null };
115
+ }
116
+
117
+ const REFUSALS = {
118
+ 403: 'The service refused this agent\'s credential. Either it is not the credential for this handle, or the handle has not been set up as an agent. Ask whoever runs /vibe.',
119
+ 429: 'Too many sign-in attempts for this agent in the last hour. It will work again later; the saved session is reused until then.',
120
+ 503: 'The service could not establish this agent\'s identity right now. If this handle already belongs to a person, it cannot also be an agent.',
121
+ };
122
+
123
+ let _inFlight = null;
124
+
125
+ /**
126
+ * Make sure this process holds the agent's own session. Resolves to
127
+ * { ok, handle, expiresAt?, minted?, message? }. Never throws, never prompts,
128
+ * never opens a browser.
129
+ */
130
+ function ensureSession({ force = false, env = process.env, fetchImpl = fetch } = {}) {
131
+ if (_inFlight) return _inFlight;
132
+ _inFlight = (async () => {
133
+ const me = configured(env);
134
+ if (!me) return { ok: false, handle: null, message: 'This process is not configured as an agent.' };
135
+ if (me.problem) return { ok: false, handle: me.handle, message: `@${me.handle} cannot sign in: ${me.problem}.` };
136
+
137
+ const authStore = require('./auth-store');
138
+ const config = require('./config');
139
+ authStore.hydrate();
140
+
141
+ const now = sessionState(me.handle);
142
+ if (now.usable && !force) return { ok: true, handle: me.handle, expiresAt: now.expiresAt, minted: false };
143
+ // Someone else's sign-in lives in this directory. It is not used, and it is
144
+ // not removed either: it may be a person's, and it is theirs. The agent
145
+ // needs a directory of its own.
146
+ if (now.why === 'other_identity') {
147
+ return { ok: false, handle: me.handle, message: `This identity directory already holds another sign-in (@${norm(authStore.getHandle() || '') || 'someone'}). An agent needs a VIBE_HOME of its own; nothing here was changed.` };
148
+ }
149
+
150
+ const base = String(config.getApiUrl()).replace(/\/+$/, '');
151
+ const controller = new AbortController();
152
+ const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);
153
+ let status; let body = null;
154
+ try {
155
+ const response = await fetchImpl(`${base}/api/auth/buddy-token`, {
156
+ method: 'POST',
157
+ signal: controller.signal,
158
+ headers: { 'Content-Type': 'application/json', Accept: 'application/json', 'x-agent-mint': _secret },
159
+ body: JSON.stringify({ handle: me.handle }),
160
+ });
161
+ status = response.status;
162
+ body = await response.json().catch(() => null);
163
+ } catch {
164
+ // Offline with a session that still works is fine; say so rather than fail.
165
+ if (now.why === 'expiring') return { ok: true, handle: me.handle, expiresAt: now.expiresAt, minted: false, message: 'Could not reach /vibe to renew; the current session is still good.' };
166
+ return { ok: false, handle: me.handle, message: 'Could not reach /vibe to sign this agent in. It will try again on the next start.' };
167
+ } finally {
168
+ clearTimeout(timer);
169
+ }
170
+
171
+ const token = body && body.success === true && typeof body.token === 'string' ? body.token : null;
172
+ if (status !== 200 || !token) {
173
+ if (now.why === 'expiring') return { ok: true, handle: me.handle, expiresAt: now.expiresAt, minted: false, message: REFUSALS[status] || 'The session could not be renewed.' };
174
+ return { ok: false, handle: me.handle, message: REFUSALS[status] || 'The service did not sign this agent in.' };
175
+ }
176
+ // The session must be for THIS handle, and say it is an agent's.
177
+ const seen = authStore.inspectToken(token);
178
+ if (!seen.ok || norm(seen.handle) !== me.handle || claimsOf(token).mint !== 'agent') {
179
+ return { ok: false, handle: me.handle, message: 'The service answered with a session that is not this agent\'s. It was not used.' };
180
+ }
181
+
182
+ try { await require('./actor-session').clearActorSession(); } catch {}
183
+ config.saveAuthToken(token);
184
+ config.setSessionIdentity(me.handle, config.getOneLiner() || '');
185
+ authStore.setToken(token);
186
+ authStore.setHandle(me.handle);
187
+ const saved = config.load();
188
+ saved.handle = me.handle;
189
+ saved.authMethod = 'agent';
190
+ saved.pendingAuth = false;
191
+ config.save(saved);
192
+ global.vibeNotifier?.emitImmediate();
193
+ return { ok: true, handle: me.handle, expiresAt: seen.expiresAt || null, minted: true };
194
+ })().finally(() => { _inFlight = null; });
195
+ return _inFlight;
196
+ }
197
+
198
+ /** Who the service says this handle is: { kind, operator } or null when it cannot be read. */
199
+ async function publicIdentity(handle, { fetchImpl = fetch } = {}) {
200
+ const config = require('./config');
201
+ const base = String(config.getApiUrl()).replace(/\/+$/, '');
202
+ const controller = new AbortController();
203
+ const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);
204
+ try {
205
+ const r = await fetchImpl(`${base}/api/identity/${encodeURIComponent(norm(handle))}`, { signal: controller.signal, headers: { Accept: 'application/json' } });
206
+ if (!r.ok) return r.status === 404 ? { missing: true } : null;
207
+ const who = await r.json().catch(() => null);
208
+ if (!who || norm(who.handle) !== norm(handle)) return null;
209
+ const operator = typeof who.operator === 'string' && HANDLE.test(norm(who.operator)) ? norm(who.operator)
210
+ : (who.operator && typeof who.operator === 'object' && HANDLE.test(norm(who.operator.handle)) ? norm(who.operator.handle) : null);
211
+ return { kind: ['agent', 'human'].includes(who.kind) ? who.kind : 'other', operator };
212
+ } catch { return null; } finally { clearTimeout(timer); }
213
+ }
214
+
215
+ module.exports = {
216
+ configured, isAgent, ensureSession, sessionState, publicIdentity, scrub, credentialForOperator, norm, HANDLE,
217
+ _resetForTest: () => { _secret = null; _secretProblem = null; _captured = false; _inFlight = null; },
218
+ };
package/cli.js CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  const args = process.argv.slice(2);
16
16
 
17
- const COMMANDS = ['setup', 'hook', 'trust', 'untrust', 'lines', 'quiet', 'unquiet', 'mute', 'unmute', 'door', 'invisible', 'visible'];
17
+ const COMMANDS = ['setup', 'hook', 'trust', 'untrust', 'lines', 'quiet', 'unquiet', 'mute', 'unmute', 'door', 'invisible', 'visible', 'agent', 'operate'];
18
18
  const USAGE = `slashvibe-mcp: telepathic messaging, inside your coding agent
19
19
 
20
20
  npx slashvibe-mcp setup install: configure your coding agent and sign in with GitHub
@@ -24,6 +24,8 @@ const USAGE = `slashvibe-mcp: telepathic messaging, inside your coding agent
24
24
  npx slashvibe-mcp quiet nothing reaches you while you work (undo: unquiet)
25
25
  npx slashvibe-mcp mute @handle one person stops surfacing (undo: unmute @handle)
26
26
  npx slashvibe-mcp invisible be here without showing as here (undo: visible)
27
+ npx slashvibe-mcp operate @agent say you run an agent, so people see "run by @you" (also: renew, revoke)
28
+ npx slashvibe-mcp agent for an agent signing in as itself, not a person
27
29
  npx slashvibe-mcp door https://... leave a door: a link to what you are building (then: door share, door close)
28
30
 
29
31
  With no command it sets up on first run in a terminal; a coding agent starts it as an MCP server.
@@ -195,6 +197,144 @@ async function doorCli(argv, say) {
195
197
  : 'When you have written to someone, leave it with them: npx slashvibe-mcp door share');
196
198
  }
197
199
 
200
+ /**
201
+ * `agent`: this process as an agent identity (agent-auth.js).
202
+ *
203
+ * agent who this is configured to be, and whether it is signed in
204
+ * agent signin sign in now with the agent's credential (no browser)
205
+ *
206
+ * The credential comes from the environment (VIBE_AGENT_MINT_FILE or
207
+ * VIBE_AGENT_MINT) and is never printed.
208
+ */
209
+ async function agentCli(argv, say) {
210
+ const agentAuth = require('./agent-auth');
211
+ const me = agentAuth.configured();
212
+ if (!me) {
213
+ say('This is not set up as an agent.');
214
+ say('An agent signs in as itself with its own credential, set in the env of its vibe server:');
215
+ say(' VIBE_AGENT_HANDLE=<handle> VIBE_AGENT_MINT_FILE=<file holding the credential> VIBE_HOME=<its own directory>');
216
+ say('The credential is issued per agent by the people who run /vibe. A person signs in with: npx slashvibe-mcp setup');
217
+ return;
218
+ }
219
+ if (me.problem) throw new Error(`@${me.handle} cannot sign in: ${me.problem}.`);
220
+ const hush = console.error; console.error = () => {};
221
+ let state;
222
+ try { state = await agentAuth.ensureSession({ force: argv[0] === 'signin' }); } finally { console.error = hush; }
223
+ if (!state.ok) throw new Error(agentAuth.scrub(state.message));
224
+ const until = state.expiresAt ? new Date(state.expiresAt).toISOString().slice(0, 10) : null;
225
+ say(`\u{1F916} @${me.handle} is signed in to /vibe as an agent${until ? `, until ${until}` : ''}${state.minted ? ' (new session)' : ''}.`);
226
+ if (state.message) say(agentAuth.scrub(state.message));
227
+ const who = await agentAuth.publicIdentity(me.handle);
228
+ if (who && who.operator) say(`Run by @${who.operator}. People see that beside this agent's name.`);
229
+ else if (who) say(`No operator is named. The person who runs this agent names themselves, signed in as themselves: npx slashvibe-mcp operate @${me.handle}`);
230
+ else say('Could not read how /vibe shows this agent right now.');
231
+ }
232
+
233
+ /**
234
+ * `operate`: a PERSON says "I run this agent".
235
+ *
236
+ * operate the agents you operate
237
+ * operate @agent [--days N] name yourself its operator (1 to 30 days; default 30)
238
+ * operate renew @agent replace your grant with a fresh one
239
+ * operate revoke @agent stop being named
240
+ *
241
+ * The service wants proof of both halves in one request: your own sign-in, and
242
+ * the agent's credential (so nobody can put their name on an agent they do not
243
+ * run). The credential is read from VIBE_AGENT_MINT_FILE or VIBE_AGENT_MINT for
244
+ * this one command, never from the command line, and never printed.
245
+ */
246
+ async function operateCli(argv, say) {
247
+ const fs = require('fs');
248
+ const path = require('path');
249
+ const agentAuth = require('./agent-auth');
250
+ const config = require('./config');
251
+ const authStore = require('./auth-store');
252
+ const { vibeHome } = require('./vibe-home');
253
+ if (process.env.VIBE_AGENT_HANDLE) throw new Error('An agent cannot name its own operator. Run this as the person, without VIBE_AGENT_HANDLE.');
254
+ const secret = agentAuth.credentialForOperator();
255
+ const flags = argv.filter((a) => a.startsWith('--'));
256
+ const words = argv.filter((a) => !a.startsWith('--'));
257
+ if (flags.some((f) => !/^--days(=\d+)?$/.test(f))) throw new Error('The only option is --days=N. The agent\'s credential is never given on the command line; put it in a file and set VIBE_AGENT_MINT_FILE.');
258
+ const verb = ['renew', 'revoke'].includes(words[0]) ? words.shift() : (words.length ? 'grant' : 'list');
259
+ if (words.length > 1) throw new Error('One agent at a time: npx slashvibe-mcp operate @agent');
260
+
261
+ const cred = authStore.inspectToken(config.getAuthToken());
262
+ if (!cred.ok) throw new Error('Sign in as yourself first: npx slashvibe-mcp setup');
263
+ authStore.hydrate();
264
+ const me = String(cred.handle || '').toLowerCase();
265
+ const base = String(config.getApiUrl()).replace(/\/+$/, '');
266
+ const call = async (method, query, body, withAgent) => {
267
+ const controller = new AbortController();
268
+ const timer = setTimeout(() => controller.abort(), 10000);
269
+ try {
270
+ const r = await fetch(`${base}/api/operator-grants${query || ''}`, {
271
+ method, signal: controller.signal,
272
+ headers: { Accept: 'application/json', 'Content-Type': 'application/json', Authorization: `Bearer ${authStore.getToken() || config.getAuthToken()}`, ...(withAgent ? { 'x-agent-mint': secret } : {}) },
273
+ ...(body ? { body: JSON.stringify(body) } : {}),
274
+ });
275
+ return { status: r.status, body: await r.json().catch(() => ({})) };
276
+ } catch { throw new Error('Could not reach /vibe. Nothing was changed.'); } finally { clearTimeout(timer); }
277
+ };
278
+ const WHY = {
279
+ principal_credential_required: 'Your sign-in is an older kind that cannot name an operator. Sign in again: npx slashvibe-mcp setup',
280
+ identity_not_attested: 'Your handle has no GitHub-attested identity yet. Sign in again: npx slashvibe-mcp setup',
281
+ credential_superseded: 'Your sign-in no longer matches this handle. Sign in again: npx slashvibe-mcp setup',
282
+ agent_credential_required: 'That is not this agent\'s credential. Only the person who holds an agent\'s credential can name themselves its operator.',
283
+ agent_not_found: 'That handle is not an agent on /vibe yet. The agent has to sign in once as itself first (npx slashvibe-mcp agent signin, in its own env).',
284
+ live_grant_exists: 'This agent already has an operator named. If it is you: npx slashvibe-mcp operate renew @agent. If it is someone else, they must revoke first; an operator is never silently replaced.',
285
+ unauthorized: 'Sign in as yourself first: npx slashvibe-mcp setup',
286
+ };
287
+ const refuse = (r) => { throw new Error(agentAuth.scrub(WHY[r.body && r.body.error] || (r.body && r.body.message) || `The service refused (${r.status}). Nothing was changed.`)); };
288
+ const noteFile = path.join(vibeHome(), 'operating.json');
289
+ const notes = () => { try { const v = JSON.parse(fs.readFileSync(noteFile, 'utf8')); return v && typeof v === 'object' ? v : {}; } catch { return {}; } };
290
+ const remember = (agent, value) => {
291
+ const all = notes(); if (value) all[agent] = value; else delete all[agent];
292
+ try { fs.mkdirSync(path.dirname(noteFile), { recursive: true, mode: 0o700 }); fs.writeFileSync(noteFile, JSON.stringify(all, null, 2), { mode: 0o600 }); } catch {}
293
+ };
294
+ const day = (iso) => (Number.isFinite(Date.parse(iso)) ? new Date(iso).toISOString().slice(0, 10) : 'an unknown date');
295
+ const listLive = async () => {
296
+ const r = await call('GET');
297
+ if (r.status !== 200) refuse(r);
298
+ return (r.body.grants || []).filter((g) => g && !g.revoked_at && Date.parse(g.expires_at) > Date.now());
299
+ };
300
+
301
+ if (verb === 'list') {
302
+ const live = await listLive();
303
+ if (!live.length) { say('You are not named as the operator of any agent.'); say('Name yourself: npx slashvibe-mcp operate @agent (with that agent\'s credential in VIBE_AGENT_MINT_FILE)'); return; }
304
+ say('You are named as the operator of:');
305
+ for (const g of live) say(` @${agentAuth.norm(g.agent_handle)} until ${day(g.expires_at)}`);
306
+ say('Renew: npx slashvibe-mcp operate renew @agent · stop: npx slashvibe-mcp operate revoke @agent');
307
+ return;
308
+ }
309
+
310
+ const agent = agentAuth.norm(words[0]);
311
+ if (!agentAuth.HANDLE.test(agent)) throw new Error(`"${words[0] || ''}" is not a handle. Which agent? npx slashvibe-mcp operate @agent`);
312
+ if (agent === me) throw new Error(`@${agent} is you. An operator is a person who runs an agent.`);
313
+
314
+ if (verb === 'revoke' || verb === 'renew') {
315
+ const mine = (await listLive()).find((g) => agentAuth.norm(g.agent_handle) === agent);
316
+ if (!mine && verb === 'revoke') { remember(agent, null); say(`You are not named as @${agent}'s operator.`); return; }
317
+ if (mine) {
318
+ if (verb === 'renew' && !secret) throw new Error(`Renewing needs @${agent}'s credential: set VIBE_AGENT_MINT_FILE for this command. Nothing was changed.`);
319
+ const r = await call('DELETE', `?grant_id=${encodeURIComponent(mine.grant_id)}`);
320
+ if (r.status !== 200) refuse(r);
321
+ remember(agent, null);
322
+ if (verb === 'revoke') { say(`You are no longer named as @${agent}'s operator. Messages it already sent keep saying who ran it then.`); return; }
323
+ }
324
+ }
325
+
326
+ if (!secret) throw new Error(`Naming yourself @${agent}'s operator needs that agent's own credential, as proof you run it. Put it in a file and run:\n VIBE_AGENT_MINT_FILE=<that file> npx slashvibe-mcp operate @${agent}`);
327
+ const daysFlag = flags.find((f) => f.startsWith('--days='));
328
+ const days = daysFlag ? Number(daysFlag.split('=')[1]) : 30;
329
+ if (!Number.isInteger(days) || days < 1 || days > 30) throw new Error('--days must be between 1 and 30. The service does not name an operator for longer than 30 days at a time.');
330
+ const r = await call('POST', '', { agent_handle: agent, expires_in_hours: days * 24, scope: ['messages:send'] }, true);
331
+ if (r.status !== 200 || !r.body.success) refuse(r);
332
+ remember(agent, { expires_at: r.body.expires_at, grant_id: r.body.grant_id });
333
+ say(`\u{1F916} @${agent} is now shown as an agent run by @${me}, until ${day(r.body.expires_at)}.`);
334
+ say('That covers what it sends from now on. It ends on that date unless you renew it:');
335
+ say(` npx slashvibe-mcp operate renew @${agent} · stop being named: npx slashvibe-mcp operate revoke @${agent}`);
336
+ }
337
+
198
338
  if (['help', '--help', '-h'].includes(args[0])) {
199
339
  process.stdout.write(`${USAGE}\n`);
200
340
  } else if (['--version', '-v', 'version'].includes(args[0])) {
@@ -245,6 +385,17 @@ if (['help', '--help', '-h'].includes(args[0])) {
245
385
  process.stderr.write(`${error?.message || error}\n`);
246
386
  process.exitCode = 1;
247
387
  }
388
+ } else if (args[0] === 'agent' || args[0] === 'operate') {
389
+ // An agent as itself, and the person who runs it (agent-auth.js).
390
+ (args[0] === 'agent' ? agentCli : operateCli)(args.slice(1), (t) => process.stdout.write(`${t}\n`)).catch((error) => {
391
+ process.stderr.write(`${require('./agent-auth').scrub(error?.message || error)}\n`);
392
+ process.exitCode = 1;
393
+ });
394
+ } else if ((args.includes('setup') || (args.length === 0 && process.stdin.isTTY)) && require('./agent-auth').isAgent()) {
395
+ // Setup is a person signing in through GitHub. An agent that did that would
396
+ // become a person as far as /vibe knows.
397
+ process.stderr.write(`This is set up as the agent @${require('./agent-auth').configured().handle}. Setup is for people. An agent signs in with: npx slashvibe-mcp agent signin\n`);
398
+ process.exitCode = 1;
248
399
  } else if (args[0] === 'door') {
249
400
  // A door (door.js). Typed by the person; nothing a session's agent can call sets or shares one.
250
401
  doorCli(args.slice(1), (t) => process.stdout.write(`${t}\n`)).catch((error) => {
package/config.js CHANGED
@@ -430,7 +430,10 @@ const savePrivyToken = saveAuthToken;
430
430
  * Accepts 'github', 'privy', and 'browser' as valid auth methods (backwards compat)
431
431
  */
432
432
  function hasOAuth() {
433
- const validAuthMethods = ['github', 'privy', 'browser'];
433
+ // 'agent': a session minted for an agent's own credential (agent-auth.js). It is a
434
+ // server-signed bearer session like the others; without it here an agent that had
435
+ // signed in was sent to the GitHub login meant for people.
436
+ const validAuthMethods = ['github', 'privy', 'browser', 'agent'];
434
437
 
435
438
  const data = getSessionData();
436
439
  if (validAuthMethods.includes(data?.authMethod) && data?.token) return true;
package/index.js CHANGED
@@ -34,6 +34,7 @@ const store = require('./store');
34
34
  const authStore = require('./auth-store');
35
35
  const actorSession = require('./actor-session');
36
36
  const arrival = require('./arrival');
37
+ const agentAuth = require('./agent-auth');
37
38
  const pkg = require('./package.json');
38
39
 
39
40
  // ─── MCP protocol identity (spec 2026-07-28, dual-era) ──────────────────
@@ -112,6 +113,12 @@ class VibeMCPServer {
112
113
  constructor() {
113
114
  authStore.hydrate();
114
115
 
116
+ // An agent as itself (agent-auth.js): its session comes from its own
117
+ // credential, not a browser. Started here, awaited by the first tool call.
118
+ this.agentReady = agentAuth.isAgent()
119
+ ? agentAuth.ensureSession().catch(() => ({ ok: false, message: 'This agent could not be signed in.' }))
120
+ : null;
121
+
115
122
  // Refresh the delivery credential once at startup so a dead token family
116
123
  // becomes one truthful re-sign-in state, not a failure at send time.
117
124
  this.actorAccessReady = actorSession.getAccessToken().catch((error) => {
@@ -219,6 +226,20 @@ class VibeMCPServer {
219
226
  if (!tool) return fail(-32601, `Unknown tool: ${params?.name}`);
220
227
  const action = params.name.replace('vibe_', '');
221
228
 
229
+ // An agent signs in with its own credential and nothing else. The two
230
+ // sign-in tools belong to people: a browser the agent cannot use, and a
231
+ // pasted token that would let any message swap this agent's identity.
232
+ if (this.agentReady) {
233
+ const state = await this.agentReady;
234
+ const who = agentAuth.configured();
235
+ if (['vibe_init', 'vibe_token'].includes(params.name)) {
236
+ return ok({ content: [{ type: 'text', text: `This session is the agent @${who.handle}. It signs in with its agent credential; there is nothing to do here.${state && state.ok ? '' : ` ${agentAuth.scrub(state && state.message)}`}` }] });
237
+ }
238
+ if (!isAuthed()) {
239
+ return ok({ content: [{ type: 'text', text: `@${who.handle} is not signed in to /vibe. ${agentAuth.scrub((state && state.message) || '')}\nNothing was done. This is fixed by whoever runs this agent, not from inside the session.` }] });
240
+ }
241
+ }
242
+
222
243
  // The sign-in gate. The gated tool's arguments describe ITS job, not
223
244
  // the person signing in (a recipient is not an identity), so nothing
224
245
  // is forwarded: GitHub says who you are.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slashvibe-mcp",
3
- "version": "0.9.9",
3
+ "version": "0.9.10",
4
4
  "mcpName": "io.github.vibecodinginc/vibe",
5
5
  "description": "Telepathic messaging between people, from inside Claude Code",
6
6
  "main": "index.js",
@@ -81,6 +81,7 @@
81
81
  "vibe-home.js",
82
82
  "door.js",
83
83
  "tools/visit.js",
84
- "tools/bump.js"
84
+ "tools/bump.js",
85
+ "agent-auth.js"
85
86
  ]
86
87
  }
package/presence.js CHANGED
@@ -89,6 +89,10 @@ async function initSession() {
89
89
 
90
90
  async function register(sessionId, handle) {
91
91
  if (sessionInitialized) return;
92
+ // An agent's session is the one its credential minted (agent-auth.js).
93
+ // Registering here answers with a second token and saves it over the first,
94
+ // and that one carries no agent identity. The heartbeat alone says "here".
95
+ if (require('./agent-auth').isAgent()) { sessionInitialized = true; return; }
92
96
  const result = await store.registerSession(sessionId, handle);
93
97
  sessionInitialized = Boolean(result && result.success);
94
98
  }
package/tools/deliver.js CHANGED
@@ -51,9 +51,18 @@ async function deliver(m) {
51
51
  replyTo: m.replyTo || null,
52
52
  idempotencyKey: typeof m.idempotencyKey === 'string' && m.idempotencyKey ? m.idempotencyKey : undefined,
53
53
  approvedSha256: typeof m.approvedSha256 === 'string' && m.approvedSha256 ? m.approvedSha256 : undefined,
54
- // 'composed': the person wrote it. 'context_move': their agent prepared it
55
- // from the active session and the person chose Send.
56
- origin: m.origin || 'composed',
54
+ // WHO DECIDED TO SEND, said truthfully. This is the one place every message
55
+ // passes, so it is the one place that decides:
56
+ // 'agent_self' this session IS an agent, signed in as itself. No person
57
+ // chose Send, whichever tool path the message took.
58
+ // 'agent_line' a person's agent sent it over an open line, unread by them
59
+ // (set by tools/line.js).
60
+ // 'context_move' the agent prepared it and the person chose Send.
61
+ // 'composed' the person's own words.
62
+ // Until the service accepts the two agent values it drops them to "unlabelled",
63
+ // which is still true. The old behaviour recorded them as 'composed', which the
64
+ // service defines as "a human wrote it".
65
+ origin: require('../agent-auth').isAgent() ? 'agent_self' : (m.origin || 'composed'),
57
66
  });
58
67
 
59
68
  // A falsy result is a failure too: nothing may read as delivery without a receipt.
package/tools/line.js CHANGED
@@ -66,7 +66,7 @@ async function askHandler(args = {}) {
66
66
  const no = commonRefusal(to, question, 'question');
67
67
  if (no) return no;
68
68
 
69
- const sent = await deliver({ to, message: question + line.ASKED(me) });
69
+ const sent = await deliver({ to, message: question + line.ASKED(me), origin: 'agent_line' });
70
70
  if (!sent.data || !sent.data.sent) return sent;
71
71
  const askId = sent.data.message_id;
72
72
  const project = typeof args.project === 'string' ? args.project.trim().slice(0, 60) : null;
@@ -149,7 +149,7 @@ async function answerHandler(args = {}) {
149
149
  if (line.isAgentAnswer(row.text)) return refuse('Nothing sent. That message is itself an agent\'s answer; answers are not answered unattended. If something real remains to say, prepare it with vibe_prepare.');
150
150
  if (line.receipts().some((r) => r.kind === 'answered' && r.answers === id)) return refuse('Nothing sent. That question was already answered from this machine.');
151
151
 
152
- const sent = await deliver({ to, message: message + line.ANSWERED(me), replyTo: id });
152
+ const sent = await deliver({ to, message: message + line.ANSWERED(me), replyTo: id, origin: 'agent_line' });
153
153
  if (!sent.data || !sent.data.sent) return sent;
154
154
  line.record({ kind: 'answered', with: to, id: sent.data.message_id, answers: id, asked: line.stripMark(row.text || ''), said: message });
155
155
  return {
package/tools/start.js CHANGED
@@ -137,6 +137,28 @@ async function handler(args = {}) {
137
137
  : '\n\nyou have not said what you are working on.\nother people\'s agents read that line to decide whether a question is for you.\noffer to set one: vibe_start with building.';
138
138
  if (reach.isQuiet()) display += '\nquiet is on: nothing reaches you while you work. off: npx slashvibe-mcp unquiet';
139
139
  if (reach.isInvisible()) display += '\ninvisible is on: you do not show as here. off: npx slashvibe-mcp visible';
140
+ // An agent as itself says so, and says who (if anyone) is named as running it.
141
+ try {
142
+ const agentAuth = require('../agent-auth');
143
+ if (agentAuth.isAgent()) {
144
+ const who = await agentAuth.publicIdentity(myHandle);
145
+ display += who && who.operator
146
+ ? `\n\u{1F916} this session is the agent @${cell(myHandle, 39)}, shown to people as run by @${cell(who.operator, 39)}`
147
+ : `\n\u{1F916} this session is the agent @${cell(myHandle, 39)}. ${who ? `no operator is named for you: the person who runs you can name themselves with npx slashvibe-mcp operate @${cell(myHandle, 39)}` : 'could not read how /vibe shows you right now'}`;
148
+ } else {
149
+ // A person who runs agents: say when being named is about to lapse.
150
+ const fs = require('fs');
151
+ const path = require('path');
152
+ const notes = JSON.parse(fs.readFileSync(path.join(require('../vibe-home').vibeHome(), 'operating.json'), 'utf8'));
153
+ for (const [agent, g] of Object.entries(notes || {}).slice(0, 5)) {
154
+ const left = Date.parse(g && g.expires_at) - Date.now();
155
+ if (!Number.isFinite(left)) continue;
156
+ if (left <= 0) display += `\n\u{1F916} you are no longer named as @${cell(agent, 39)}'s operator (it lapsed). name yourself again: npx slashvibe-mcp operate @${cell(agent, 39)}`;
157
+ else if (left < 7 * 24 * 60 * 60 * 1000) display += `\n\u{1F916} you are named as @${cell(agent, 39)}'s operator for ${Math.max(1, Math.ceil(left / 86400000))} more day(s). renew: npx slashvibe-mcp operate renew @${cell(agent, 39)}`;
158
+ }
159
+ }
160
+ } catch (e) {}
161
+
140
162
  // Your own door, and who holds it. Local facts; nothing here is published.
141
163
  try {
142
164
  const own = require('../door').mine();