slashvibe-mcp 0.9.15 → 0.9.16
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/invite.js +53 -8
- package/package.json +1 -1
- package/presence.js +18 -9
- package/protocol/handle.js +9 -5
- package/setup.js +14 -10
- package/store/api.js +37 -13
- package/tools/_shared.js +7 -3
- package/tools/deliver.js +13 -6
- package/tools/drafts.js +27 -8
- package/tools/line.js +14 -1
package/invite.js
CHANGED
|
@@ -29,6 +29,18 @@ function fromArg(argv = process.argv) {
|
|
|
29
29
|
return null;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* The platform folds '-' to '_' when it first gives a GitHub login a handle
|
|
34
|
+
* (api/lib/handles.js), and its identity lookup answers with that spelling:
|
|
35
|
+
* asking for "a-b" finds "a_b". Only that one difference is forgiven when
|
|
36
|
+
* confirming the answer; any other mismatch is still "could not confirm".
|
|
37
|
+
*/
|
|
38
|
+
const sameAccount = (asked, answered) => asked.replace(/-/g, '_') === answered.replace(/-/g, '_');
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* { found: true, kind, handle } where handle is the platform's own spelling;
|
|
42
|
+
* { found: false } on a definite 404; { found: null } when it could not tell.
|
|
43
|
+
*/
|
|
32
44
|
async function lookup(h, { apiUrl, fetchImpl = fetch } = {}) {
|
|
33
45
|
const base = String(apiUrl || process.env.VIBE_API_URL || 'https://www.slashvibe.dev').replace(/\/+$/, '');
|
|
34
46
|
const controller = new AbortController();
|
|
@@ -37,8 +49,9 @@ async function lookup(h, { apiUrl, fetchImpl = fetch } = {}) {
|
|
|
37
49
|
const response = await fetchImpl(`${base}/api/identity/${encodeURIComponent(h)}`, { signal: controller.signal, headers: { Accept: 'application/json' } });
|
|
38
50
|
if (response.status === 404) return { found: false };
|
|
39
51
|
const who = response.ok ? await response.json().catch(() => null) : null;
|
|
40
|
-
|
|
41
|
-
|
|
52
|
+
const handle = who ? String(who.handle || '').toLowerCase() : '';
|
|
53
|
+
if (!handle || !sameAccount(h, handle)) return { found: null };
|
|
54
|
+
return { found: true, kind: who.kind === 'agent' ? 'agent' : (who.kind === 'human' ? 'human' : 'account'), handle };
|
|
42
55
|
} catch {
|
|
43
56
|
return { found: null };
|
|
44
57
|
} finally {
|
|
@@ -46,6 +59,34 @@ async function lookup(h, { apiUrl, fetchImpl = fetch } = {}) {
|
|
|
46
59
|
}
|
|
47
60
|
}
|
|
48
61
|
|
|
62
|
+
/**
|
|
63
|
+
* The handle to address, for a recipient typed with a '-'.
|
|
64
|
+
*
|
|
65
|
+
* GitHub sign-in gives a login like "a-b" the handle "a_b" (the platform folds
|
|
66
|
+
* '-' to '_'), and its inbox is read under that spelling. A message addressed
|
|
67
|
+
* to "a-b" is accepted by the platform but stored under "a-b", where "a_b"
|
|
68
|
+
* never sees it. So the platform's own answer decides: when the identity
|
|
69
|
+
* lookup finds the account under a spelling that differs only by '-' for '_',
|
|
70
|
+
* that spelling is used. Some older accounts really are stored with the dash;
|
|
71
|
+
* then the lookup says so and the dash stays. Nothing is folded blindly.
|
|
72
|
+
*
|
|
73
|
+
* No '-', no request. Any answer other than a found account (absent, unclear,
|
|
74
|
+
* offline, a throw) leaves the handle exactly as typed.
|
|
75
|
+
*
|
|
76
|
+
* @returns {Promise<{ handle: string, who: object|null }>} who is the lookup
|
|
77
|
+
* result when one was made (callers reuse it rather than asking twice).
|
|
78
|
+
*/
|
|
79
|
+
async function resolveRecipient(h, opts = {}) {
|
|
80
|
+
const typed = String(h || '');
|
|
81
|
+
if (!typed.includes('-')) return { handle: typed, who: null };
|
|
82
|
+
let who;
|
|
83
|
+
try { who = await lookup(typed, opts); } catch { who = { found: null }; }
|
|
84
|
+
if (!who || typeof who !== 'object') who = { found: null };
|
|
85
|
+
const theirs = who.found === true && typeof who.handle === 'string' ? who.handle : '';
|
|
86
|
+
const handle = theirs && theirs !== typed && sameAccount(typed, theirs) && validHandle(theirs) ? theirs : typed;
|
|
87
|
+
return { handle, who };
|
|
88
|
+
}
|
|
89
|
+
|
|
49
90
|
/**
|
|
50
91
|
* Mark the inviter as known. Returns the lines to print; never throws, because
|
|
51
92
|
* a setup that just succeeded must not end in an error over a courtesy.
|
|
@@ -57,15 +98,19 @@ async function accept(typed, me, opts = {}) {
|
|
|
57
98
|
const who = await lookup(h, opts);
|
|
58
99
|
if (who.found === false) return { known: false, lines: [`There is no @${h} on /vibe, so nobody was marked as your inviter. Check the spelling with them.`] };
|
|
59
100
|
if (who.found !== true) return { known: false, lines: [`Could not confirm @${h} just now, so they were not marked. Write to them once and they are known.`] };
|
|
60
|
-
|
|
61
|
-
|
|
101
|
+
// Their messages arrive from the handle as the platform stores it, which
|
|
102
|
+
// can differ from what was typed only by '-' for '_'. That is the one marked.
|
|
103
|
+
const them = who.handle && validHandle(who.handle) ? who.handle : h;
|
|
104
|
+
if (them === reach.norm(me)) return { known: false, lines: [] };
|
|
105
|
+
reach.know(them, opts.env);
|
|
106
|
+
if (!reach.isKnown(them, opts.env)) return { known: false, lines: [] };
|
|
62
107
|
const what = who.kind === 'agent' ? ', an agent,' : '';
|
|
63
108
|
return {
|
|
64
109
|
known: true,
|
|
65
|
-
handle:
|
|
110
|
+
handle: them,
|
|
66
111
|
lines: [
|
|
67
|
-
`@${
|
|
68
|
-
`Nothing was sent and no line was opened. Undo: npx slashvibe-mcp mute @${
|
|
112
|
+
`@${them}${what} invited you, so what they write reaches you while you work.`,
|
|
113
|
+
`Nothing was sent and no line was opened. Undo: npx slashvibe-mcp mute @${them}`,
|
|
69
114
|
],
|
|
70
115
|
};
|
|
71
116
|
}
|
|
@@ -77,4 +122,4 @@ function line(me) {
|
|
|
77
122
|
return { command: `npx slashvibe-mcp setup --from @${h}`, link: `https://www.slashvibe.dev/join?from=${h}` };
|
|
78
123
|
}
|
|
79
124
|
|
|
80
|
-
module.exports = { fromArg, accept, line, lookup };
|
|
125
|
+
module.exports = { fromArg, accept, line, lookup, resolveRecipient };
|
package/package.json
CHANGED
package/presence.js
CHANGED
|
@@ -145,15 +145,20 @@ async function poll() {
|
|
|
145
145
|
* Known = an open line, a send recorded on this machine, or (checked once and
|
|
146
146
|
* then remembered) any message of yours in the conversation, so someone you
|
|
147
147
|
* wrote to from another device still reaches you here. Reading the
|
|
148
|
-
* conversation does not mark it read.
|
|
148
|
+
* conversation does not mark it read.
|
|
149
|
+
*
|
|
150
|
+
* Three answers: true, false (the conversation was read and holds nothing of
|
|
151
|
+
* yours), or null (it could not be read, so this says nothing either way).
|
|
152
|
+
* store.getThread reports a failed read by value, an empty list carrying
|
|
153
|
+
* readFailed, rather than by throwing; a throw counts as could-not-tell too.
|
|
149
154
|
*/
|
|
150
155
|
async function knows(me, them) {
|
|
151
156
|
if (line.isOpen(them) || reach.isKnown(them)) return true;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
+
let thread;
|
|
158
|
+
try { thread = await store.getThread(me, them); } catch { return null; }
|
|
159
|
+
if (!Array.isArray(thread) || thread.readFailed) return null;
|
|
160
|
+
const mine = String(me).toLowerCase();
|
|
161
|
+
if (thread.some((m) => String((m && m.from) || '').toLowerCase() === mine)) { reach.know(them); return true; }
|
|
157
162
|
return false;
|
|
158
163
|
}
|
|
159
164
|
|
|
@@ -186,11 +191,15 @@ async function noteArrivals(handle, threads) {
|
|
|
186
191
|
.filter((t) => !arrival.isClaimed(t.lastMessageId) && !arrival.isSpooled(t.lastMessageId));
|
|
187
192
|
// Only someone you know reaches you mid-work (reach.js). A muted person, or
|
|
188
193
|
// someone you have never written to, stays waiting: remembered here so the
|
|
189
|
-
// question is asked once per message, not once per poll.
|
|
194
|
+
// question is asked once per message, not once per poll. A conversation that
|
|
195
|
+
// could not be read decides nothing, so that message is asked about again
|
|
196
|
+
// on the next poll instead of being parked for the rest of the session.
|
|
190
197
|
const candidates = [];
|
|
191
198
|
for (const t of wanted) {
|
|
192
|
-
if (
|
|
193
|
-
|
|
199
|
+
if (reach.isMuted(t.lastFrom)) { waitingAtStart.add(t.lastMessageId); continue; }
|
|
200
|
+
const known = await knows(handle, t.lastFrom);
|
|
201
|
+
if (known === true) candidates.push(t);
|
|
202
|
+
else if (known === false) waitingAtStart.add(t.lastMessageId);
|
|
194
203
|
}
|
|
195
204
|
if (candidates.length === 0) return;
|
|
196
205
|
const allowed = new Set(candidates.map((t) => t.lastMessageId));
|
package/protocol/handle.js
CHANGED
|
@@ -4,13 +4,17 @@
|
|
|
4
4
|
* This exists because the same defect has landed three times now: a padded/cased handle
|
|
5
5
|
* normalized differently in different layers, so a self-DM passed the self-check AND
|
|
6
6
|
* delivered. The most recent instance is instructive — `normalizeHandle` in
|
|
7
|
-
* tools/_shared.js
|
|
8
|
-
* (the leading space
|
|
9
|
-
* padded self-target through. Order of operations, not intent.
|
|
7
|
+
* tools/_shared.js stripped a leading `@` BEFORE trimming, so " @alice " became "@alice"
|
|
8
|
+
* (the leading space defeated the ^@ match), which then failed to equal "alice" and let a
|
|
9
|
+
* padded self-target through. Order of operations, not intent. (Fixed: it trims first
|
|
10
|
+
* now, and tools/deliver.js uses canonicalHandle for the recipient and the self-check.)
|
|
10
11
|
*
|
|
11
12
|
* Rules, matching api/lib/handles.js so the platform and the protocol agree:
|
|
12
13
|
* strip zero-width characters → NFC normalize → trim → strip leading @s → trim again
|
|
13
|
-
* → lowercase
|
|
14
|
+
* → lowercase. The dash is KEPT: a handle is a GitHub login and logins may contain
|
|
15
|
+
* '-'. The platform's handles.js folds '-' to '_' when it first assigns a handle, so
|
|
16
|
+
* 'a-b' and 'a_b' can name the same account there; this form does not merge them
|
|
17
|
+
* (see the note in canonicalHandle).
|
|
14
18
|
*
|
|
15
19
|
* NOT done: unicode folding of letters. Platform handles are ASCII [a-z0-9_], so a
|
|
16
20
|
* non-ASCII handle is INVALID rather than something to fold — folding lookalikes would
|
|
@@ -25,7 +29,6 @@
|
|
|
25
29
|
// Zero-width and bidi controls: invisible padding that makes two handles look identical.
|
|
26
30
|
const INVISIBLE = /[---]/g;
|
|
27
31
|
|
|
28
|
-
/** Canonical comparison/storage form, or '' when there isn't one. */
|
|
29
32
|
/**
|
|
30
33
|
* The recipient exactly as the platform STORES it (message-service
|
|
31
34
|
* storedRecipientHandle: lowercase, leading @ stripped, hyphens KEPT). The
|
|
@@ -36,6 +39,7 @@ function storedRecipientHandle(value) {
|
|
|
36
39
|
return String(value || '').toLowerCase().replace(/^@/, '');
|
|
37
40
|
}
|
|
38
41
|
|
|
42
|
+
/** Canonical comparison/storage form, or '' when there isn't one. */
|
|
39
43
|
function canonicalHandle(value) {
|
|
40
44
|
if (typeof value !== 'string') return '';
|
|
41
45
|
let h = value.replace(INVISIBLE, '');
|
package/setup.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
const fs = require('fs');
|
|
18
18
|
const path = require('path');
|
|
19
19
|
const os = require('os');
|
|
20
|
-
const {
|
|
20
|
+
const { execFile, execSync } = require('child_process');
|
|
21
21
|
const { beginOAuth } = require('./oauth-callback');
|
|
22
22
|
const actorSession = require('./actor-session');
|
|
23
23
|
|
|
@@ -290,18 +290,21 @@ function openBrowser(url) {
|
|
|
290
290
|
console.log(`${colors.dim} (browser suppressed for conformance run)${colors.reset}`);
|
|
291
291
|
return;
|
|
292
292
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
293
|
+
// No shell: the URL is one argument to the opener, so nothing in it (a
|
|
294
|
+
// quote, an &, a $) can be read as a command.
|
|
295
|
+
let file;
|
|
296
|
+
let args;
|
|
297
|
+
if (process.platform === 'darwin') {
|
|
298
|
+
file = 'open'; args = [url];
|
|
299
|
+
} else if (process.platform === 'win32') {
|
|
300
|
+
// `cmd /c start` would hand the URL to cmd's parser, where & ends the
|
|
301
|
+
// command. The URL handler opens it in the default browser without one.
|
|
302
|
+
file = 'rundll32'; args = ['url.dll,FileProtocolHandler', url];
|
|
300
303
|
} else {
|
|
301
|
-
|
|
304
|
+
file = 'xdg-open'; args = [url];
|
|
302
305
|
}
|
|
303
306
|
|
|
304
|
-
|
|
307
|
+
execFile(file, args, (err) => {
|
|
305
308
|
if (err) {
|
|
306
309
|
console.log(`${colors.yellow} Could not open browser automatically.${colors.reset}`);
|
|
307
310
|
console.log(`${colors.cyan} Please open: ${url}${colors.reset}`);
|
|
@@ -593,4 +596,5 @@ module.exports = {
|
|
|
593
596
|
saveAuthConfig,
|
|
594
597
|
retireDeadCredential,
|
|
595
598
|
installHostCommands,
|
|
599
|
+
openBrowser,
|
|
596
600
|
};
|
package/store/api.js
CHANGED
|
@@ -534,8 +534,8 @@ async function sendMessage(from, to, body, type = 'dm', payload = null, options
|
|
|
534
534
|
|
|
535
535
|
// Handle auth errors
|
|
536
536
|
if (!result.success && result.error?.includes('Authentication')) {
|
|
537
|
-
console.error('[vibe] Auth failed for message.
|
|
538
|
-
return { error: 'auth_failed', message: 'Authentication failed.
|
|
537
|
+
console.error('[vibe] Auth failed for message. Sign in again: npx slashvibe-mcp setup');
|
|
538
|
+
return { error: 'auth_failed', message: 'Authentication failed. Sign in again by running `npx slashvibe-mcp setup` in a terminal.' };
|
|
539
539
|
}
|
|
540
540
|
|
|
541
541
|
// Handle 401 — distinguish "never signed in" from "session expired".
|
|
@@ -543,14 +543,14 @@ async function sendMessage(from, to, body, type = 'dm', payload = null, options
|
|
|
543
543
|
// A misleading "expired" message here is a first-session papercut for the pilot.
|
|
544
544
|
if (result.statusCode === 401) {
|
|
545
545
|
if (!config.hasOAuth()) {
|
|
546
|
-
console.error('[vibe] DM requires sign-in. Run
|
|
546
|
+
console.error('[vibe] DM requires sign-in. Run: npx slashvibe-mcp setup');
|
|
547
547
|
return {
|
|
548
548
|
error: 'not_signed_in',
|
|
549
|
-
message: "You're not signed in yet — sending a DM needs a /vibe identity. Run `
|
|
549
|
+
message: "You're not signed in yet — sending a DM needs a /vibe identity. Run `npx slashvibe-mcp setup` in a terminal to sign in with GitHub (opens a browser), then try again.",
|
|
550
550
|
};
|
|
551
551
|
}
|
|
552
|
-
console.error('[vibe] Auth expired. Run
|
|
553
|
-
return { error: 'auth_expired', message: 'Your /vibe session expired. Run `
|
|
552
|
+
console.error('[vibe] Auth expired. Run: npx slashvibe-mcp setup');
|
|
553
|
+
return { error: 'auth_expired', message: 'Your /vibe session expired. Run `npx slashvibe-mcp setup` in a terminal to sign in again.' };
|
|
554
554
|
}
|
|
555
555
|
|
|
556
556
|
// Handle storage errors (KV write failed)
|
|
@@ -565,12 +565,25 @@ async function sendMessage(from, to, body, type = 'dm', payload = null, options
|
|
|
565
565
|
return { error: result.error, message: result.message || 'Failed to send message.' };
|
|
566
566
|
}
|
|
567
567
|
|
|
568
|
+
// Delivered only on a real success: success === true, or the stored
|
|
569
|
+
// message itself. A 200 whose body was not JSON comes back from
|
|
570
|
+
// requestOnce as { raw }, and { success: false } with no error string
|
|
571
|
+
// names no failure; both used to fall through to "Sent" with no receipt.
|
|
572
|
+
// The write may still have happened, so this is an uncertain failure,
|
|
573
|
+
// never a definite one (tools/deliver.js keeps it out of DEFINITE).
|
|
574
|
+
const delivered = result.success === true || Boolean(result.message && typeof result.message === 'object');
|
|
575
|
+
if (!delivered) {
|
|
576
|
+
console.error('[vibe] Send reply unreadable; outcome unknown.');
|
|
577
|
+
return {
|
|
578
|
+
error: 'unconfirmed_response',
|
|
579
|
+
message: "/vibe answered, but its reply could not be read, so it is not known whether the message was stored. It may or may not have reached them.",
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
|
|
568
583
|
// Emit list_changed notification for successful message send
|
|
569
584
|
// This allows other Claude Code instances to see the new message instantly
|
|
570
|
-
if (
|
|
571
|
-
|
|
572
|
-
global.vibeNotifier.emitImmediate(); // Immediate for DMs
|
|
573
|
-
}
|
|
585
|
+
if (global.vibeNotifier) {
|
|
586
|
+
global.vibeNotifier.emitImmediate(); // Immediate for DMs
|
|
574
587
|
}
|
|
575
588
|
|
|
576
589
|
// A success with no message body must still come back truthy — callers read
|
|
@@ -593,7 +606,7 @@ async function sendMessage(from, to, body, type = 'dm', payload = null, options
|
|
|
593
606
|
console.error('Send failed:', e.message);
|
|
594
607
|
return {
|
|
595
608
|
error: 'transport_failed',
|
|
596
|
-
message: "That didn't send — the connection dropped mid-request. Nothing was delivered. Worth one retry
|
|
609
|
+
message: "That didn't send — the connection dropped mid-request. Nothing was delivered. Worth one retry.",
|
|
597
610
|
};
|
|
598
611
|
}
|
|
599
612
|
}
|
|
@@ -816,7 +829,11 @@ async function getThreadWithRequest(makeRequest, myHandle, theirHandle) {
|
|
|
816
829
|
// The proxy accepts both its current snake_case response and the legacy row
|
|
817
830
|
// names used by older deployments. Keep the array contract for callers while
|
|
818
831
|
// carrying response metadata alongside it for a lookup-free read PATCH.
|
|
819
|
-
const rows = result.messages || result.thread
|
|
832
|
+
const rows = result.messages || result.thread;
|
|
833
|
+
// A reply with no message list (a non-JSON body arrives as { raw }) is not
|
|
834
|
+
// an empty conversation. Callers keep their array; the ones that must tell
|
|
835
|
+
// "nothing there" from "could not read" check readFailed (presence.js).
|
|
836
|
+
if (!Array.isArray(rows)) return failedThread();
|
|
820
837
|
const messages = rows.map(m => ({
|
|
821
838
|
id: m.id || null,
|
|
822
839
|
from: m.from,
|
|
@@ -841,12 +858,19 @@ async function getThreadWithRequest(makeRequest, myHandle, theirHandle) {
|
|
|
841
858
|
return messages;
|
|
842
859
|
}
|
|
843
860
|
|
|
861
|
+
/** An empty thread that says it is empty because the read failed. */
|
|
862
|
+
function failedThread() {
|
|
863
|
+
const empty = [];
|
|
864
|
+
Object.defineProperty(empty, 'readFailed', { value: true, enumerable: false });
|
|
865
|
+
return empty;
|
|
866
|
+
}
|
|
867
|
+
|
|
844
868
|
async function getThread(myHandle, theirHandle) {
|
|
845
869
|
try {
|
|
846
870
|
return await getThreadWithRequest(request, myHandle, theirHandle);
|
|
847
871
|
} catch (e) {
|
|
848
872
|
console.error('Thread failed:', e.message);
|
|
849
|
-
return
|
|
873
|
+
return failedThread();
|
|
850
874
|
}
|
|
851
875
|
}
|
|
852
876
|
|
package/tools/_shared.js
CHANGED
|
@@ -24,7 +24,7 @@ const store = require('../store');
|
|
|
24
24
|
function requireInit() {
|
|
25
25
|
if (!config.isInitialized()) {
|
|
26
26
|
return {
|
|
27
|
-
display: "You're not signed in yet. Run `
|
|
27
|
+
display: "You're not signed in yet. Run `npx slashvibe-mcp setup` in a terminal — GitHub opens in your browser and your username becomes your @handle.",
|
|
28
28
|
error: 'not_initialized'
|
|
29
29
|
};
|
|
30
30
|
}
|
|
@@ -36,13 +36,17 @@ function requireInit() {
|
|
|
36
36
|
// ─────────────────────────────────────────────────────────────
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
* Normalize a handle string (remove
|
|
39
|
+
* Normalize a handle string (trim, remove leading @s, lowercase).
|
|
40
|
+
* Trim comes first: stripping the @ before trimming turned " @alice " into
|
|
41
|
+
* "@alice", which then failed to equal "alice" (protocol/handle.js has the
|
|
42
|
+
* history). For anything that decides who a message goes to, use
|
|
43
|
+
* canonicalHandle from protocol/handle.js.
|
|
40
44
|
* @param {string} handle - Raw handle input
|
|
41
45
|
* @returns {string} Normalized handle
|
|
42
46
|
*/
|
|
43
47
|
function normalizeHandle(handle) {
|
|
44
48
|
if (!handle) return '';
|
|
45
|
-
return handle.toString().replace(
|
|
49
|
+
return handle.toString().trim().replace(/^@+/, '').trim().toLowerCase();
|
|
46
50
|
}
|
|
47
51
|
|
|
48
52
|
/**
|
package/tools/deliver.js
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
|
|
12
12
|
const config = require('../config');
|
|
13
13
|
const store = require('../store');
|
|
14
|
-
const { requireInit,
|
|
14
|
+
const { requireInit, isHereNow } = require('./_shared');
|
|
15
|
+
const { canonicalHandle } = require('../protocol/handle');
|
|
15
16
|
|
|
16
17
|
const MAX_LENGTH = 2000;
|
|
17
18
|
|
|
@@ -22,8 +23,10 @@ const MAX_LENGTH = 2000;
|
|
|
22
23
|
const DEFINITE = new Set(['not_signed_in', 'self_dm', 'message_too_long', 'approved_content_mismatch',
|
|
23
24
|
'approved_sha256_malformed', 'approved_send_unsupported_route', 'private_composition_data', 'idempotency_conflict']);
|
|
24
25
|
// Errors whose message already names the fix; they get no generic retry hint.
|
|
26
|
+
// An unreadable reply is one of them: it may have been stored, and a typed
|
|
27
|
+
// resend carries a fresh key, so "worth one retry" could deliver it twice.
|
|
25
28
|
const REMEDY_CARRYING = new Set(['auth_expired', 'not_signed_in', 'auth_failed', 'handle_not_found',
|
|
26
|
-
'self_dm', 'storage_error', 'transport_failed']);
|
|
29
|
+
'self_dm', 'storage_error', 'transport_failed', 'unconfirmed_response']);
|
|
27
30
|
|
|
28
31
|
/**
|
|
29
32
|
* @param {{to: string, message: string, replyTo?: string|null, origin?: string,
|
|
@@ -33,10 +36,12 @@ async function deliver(m) {
|
|
|
33
36
|
const initCheck = requireInit();
|
|
34
37
|
if (initCheck) return { ...initCheck, data: { sent: false, definite: true } };
|
|
35
38
|
|
|
39
|
+
// Both sides in the one canonical form, so a padded or prefixed "@me" is
|
|
40
|
+
// still recognised as you (protocol/handle.js).
|
|
36
41
|
const me = config.getHandle();
|
|
37
|
-
const them =
|
|
42
|
+
const them = canonicalHandle(typeof m.to === 'string' ? m.to : String(m.to || ''));
|
|
38
43
|
if (!them) return { display: 'Nothing sent. Who is it for?', data: { sent: false, definite: true } };
|
|
39
|
-
if (them === me) return { display: "You can't message yourself.", data: { sent: false, definite: true } };
|
|
44
|
+
if (them === canonicalHandle(me || '')) return { display: "You can't message yourself.", data: { sent: false, definite: true } };
|
|
40
45
|
|
|
41
46
|
const text = typeof m.message === 'string' ? m.message.trim() : '';
|
|
42
47
|
if (!text) return { display: 'Nothing sent. The message is empty.', data: { sent: false, definite: true } };
|
|
@@ -91,9 +96,11 @@ async function deliver(m) {
|
|
|
91
96
|
|
|
92
97
|
// Nobody has to be online. Say so once, when it applies; presence being
|
|
93
98
|
// unreadable never turns a real send into noise.
|
|
99
|
+
// Only a presence read that succeeded can say they are not here; a failed
|
|
100
|
+
// one says nothing (getActiveUsers flattens a failure to an empty room).
|
|
94
101
|
try {
|
|
95
|
-
const room = await store.
|
|
96
|
-
if (!isHereNow((room || []).find((u) => u.handle === them))) {
|
|
102
|
+
const room = await store.getActiveUsersResult();
|
|
103
|
+
if (room && room.ok === true && !isHereNow((room.users || []).find((u) => u && u.handle === them))) {
|
|
97
104
|
display += `\n_@${them} is not in a session right now. It reaches them when they next are._`;
|
|
98
105
|
}
|
|
99
106
|
} catch (e) {}
|
package/tools/drafts.js
CHANGED
|
@@ -209,7 +209,7 @@ const sendKey = (d) => `draft-${d.id}-${textHash(d).slice(0, 10)}`;
|
|
|
209
209
|
* The #392 approval digest over the EXACT snapshot the person approved:
|
|
210
210
|
* SHA-256 of "<stored recipient>\n<body>", where the recipient is the form
|
|
211
211
|
* the platform stores (lowercase, no @) and the body is the composed text
|
|
212
|
-
* trimmed — exactly what
|
|
212
|
+
* trimmed — exactly what deliver() sends. Computed once, at claim, from the
|
|
213
213
|
* snapshot; never recomputed after a change to the previewed content.
|
|
214
214
|
*/
|
|
215
215
|
const approvedDigest = (to, message) => crypto.createHash('sha256').update(`${storedRecipientHandle(to)}\n${message}`, 'utf8').digest('hex');
|
|
@@ -321,14 +321,25 @@ async function draftHandler(args) {
|
|
|
321
321
|
// Is the person on /vibe at all? Asked only for a NEW draft to a handle
|
|
322
322
|
// shaped like a GitHub login. Only a definite "no such handle" (404) makes
|
|
323
323
|
// the draft held; a lookup that could not confirm keeps today's behaviour.
|
|
324
|
+
//
|
|
325
|
+
// A handle with a '-' is also addressed by the platform's spelling of it
|
|
326
|
+
// (invite.resolveRecipient): the draft's `to`, its rev, its digest and the
|
|
327
|
+
// stored recipient all use what the lookup answered. That one lookup also
|
|
328
|
+
// serves the held check, so a prepare never asks twice.
|
|
324
329
|
let absent = false;
|
|
330
|
+
let resolvedTo = null;
|
|
325
331
|
if (!wantId && args && args.handle && message) {
|
|
326
332
|
const to = canonicalHandle(args.handle);
|
|
327
333
|
// Someone you already know is on /vibe: no lookup, so the ordinary
|
|
328
334
|
// preview costs no extra request and cannot be slowed by this one.
|
|
329
335
|
let known = false;
|
|
330
336
|
try { known = require('../reach').isKnown(to); } catch { known = false; }
|
|
331
|
-
if (to && to !== me && to
|
|
337
|
+
if (to && to !== me && to.includes('-') && !to.endsWith('/claude')) {
|
|
338
|
+
const r = await invite.resolveRecipient(to);
|
|
339
|
+
resolvedTo = r.handle;
|
|
340
|
+
// Absent means the login as typed: a held draft is for that GitHub account.
|
|
341
|
+
if (!known && isGithubLogin(to)) absent = Boolean(r.who && r.who.found === false);
|
|
342
|
+
} else if (to && to !== me && to !== 'echo' && !known && isGithubLogin(to)) {
|
|
332
343
|
try { absent = (await invite.lookup(to)).found === false; } catch { absent = false; }
|
|
333
344
|
}
|
|
334
345
|
}
|
|
@@ -338,12 +349,12 @@ async function draftHandler(args) {
|
|
|
338
349
|
if (wantId && !d) return { display: `No draft ${wantId} — it may have expired (drafts live 24h, locally). Prepare it again.` };
|
|
339
350
|
if (!d) {
|
|
340
351
|
if (!args || !args.handle || !message) return { display: 'To prepare a message: pass a handle and a message (or a draft id to edit). Nothing is sent by this step.' };
|
|
341
|
-
const to = canonicalHandle(args.handle);
|
|
352
|
+
const to = resolvedTo || canonicalHandle(args.handle);
|
|
342
353
|
if (!to) return { display: 'To prepare a message: pass a handle and a message (or a draft id to edit). Nothing is sent by this step.' };
|
|
343
354
|
if (to === me) return { display: "You can't draft to yourself." };
|
|
344
355
|
// @echo is the feedback line with its own path and no receipt shape;
|
|
345
356
|
// it is not a person to draft to (codex P2).
|
|
346
|
-
if (to === 'echo') return { display: '@echo is the feedback line
|
|
357
|
+
if (to === 'echo') return { display: '@echo is the feedback line. To write to it, send the person\'s own words with vibe_send (handle + message). Nothing drafted.' };
|
|
347
358
|
// An approval-bound send targets a durable conversation; the live
|
|
348
359
|
// session route stores nothing and the platform refuses it (CB-007).
|
|
349
360
|
if (to.endsWith('/claude')) return { display: `Drafts go to a person's durable conversation, not a live session — use @${to.replace(/\/claude$/, '')} instead. Nothing drafted.` };
|
|
@@ -474,9 +485,17 @@ async function sendHandler(args) {
|
|
|
474
485
|
if (!args || !args.handle || typeof args.message !== 'string' || !args.message.trim()) {
|
|
475
486
|
return { display: 'Nothing sent. Pass a draft id and rev, or a handle and the exact message.' };
|
|
476
487
|
}
|
|
477
|
-
|
|
488
|
+
// Addressed by the platform's spelling when the handle has a '-'
|
|
489
|
+
// (invite.resolveRecipient). Done here, not in deliver: a draft's digest
|
|
490
|
+
// is computed over its `to` before deliver runs, so deliver must not
|
|
491
|
+
// change the recipient.
|
|
492
|
+
let to = canonicalHandle(args.handle);
|
|
493
|
+
if (to && to !== canonicalHandle(me || '') && !to.endsWith('/claude')) {
|
|
494
|
+
try { to = (await invite.resolveRecipient(to)).handle; } catch (e) {}
|
|
495
|
+
}
|
|
496
|
+
const result = await deliver({ to: to || args.handle, message: args.message, replyTo: cleanId(args.reply_to) });
|
|
478
497
|
// The thread has moved on: what they say next answers THIS.
|
|
479
|
-
if (result.data && result.data.sent) { try { clearReturnBinding(args.handle); } catch (e) {} }
|
|
498
|
+
if (result.data && result.data.sent) { try { clearReturnBinding(to || args.handle); } catch (e) {} }
|
|
480
499
|
return result;
|
|
481
500
|
}
|
|
482
501
|
|
|
@@ -567,8 +586,8 @@ async function sendHandler(args) {
|
|
|
567
586
|
function heldRefusal(r) {
|
|
568
587
|
const status = r && r.statusCode;
|
|
569
588
|
const nothing = 'Nothing was kept.';
|
|
570
|
-
if (status === 401) return `${nothing} /vibe does not see you signed in. Run \`
|
|
571
|
-
if (status === 403) return `${nothing} Holding a message for someone needs a fresh sign-in on this machine. Run \`
|
|
589
|
+
if (status === 401) return `${nothing} /vibe does not see you signed in. Run \`npx slashvibe-mcp setup\` in a terminal to sign in, then keep it again.`;
|
|
590
|
+
if (status === 403) return `${nothing} Holding a message for someone needs a fresh sign-in on this machine. Run \`npx slashvibe-mcp setup\` in a terminal, then keep it again.`;
|
|
572
591
|
if (status === 400 && r.error === 'No invite codes remaining') return `${nothing} You already have 3 unused invitations, the most /vibe allows at once. Pass on one of the links you already have; a slot opens when someone signs in with one or it expires after ${HELD_DAYS} days.`;
|
|
573
592
|
if (status === 400 && typeof r.error === 'string' && /^first_thought is \d+ chars/.test(r.error)) return `${nothing} The message is over the 2000-char limit. Edit it shorter, then keep it again.`;
|
|
574
593
|
if (status === 409 && r.error === 'approval_mismatch') return `${nothing} What /vibe would store is not what you approved. Open the draft again with vibe_prepare and approve what it shows now.`;
|
package/tools/line.js
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
const fs = require('fs');
|
|
19
19
|
const path = require('path');
|
|
20
|
+
const crypto = require('crypto');
|
|
20
21
|
const config = require('../config');
|
|
21
22
|
const store = require('../store');
|
|
22
23
|
const line = require('../line');
|
|
@@ -137,6 +138,13 @@ function arrived(id) {
|
|
|
137
138
|
} catch { return null; }
|
|
138
139
|
}
|
|
139
140
|
|
|
141
|
+
/**
|
|
142
|
+
* One idempotency key per (this handle, question). Same family and bounds as
|
|
143
|
+
* the draft keys (`draft-<id>-<hash>`): short, ASCII, well under the service's
|
|
144
|
+
* 200-character limit whatever the id looks like.
|
|
145
|
+
*/
|
|
146
|
+
const answerKey = (me, id) => `answer-${crypto.createHash('sha1').update(`${me}\n${id}`).digest('hex').slice(0, 20)}`;
|
|
147
|
+
|
|
140
148
|
async function answerHandler(args = {}) {
|
|
141
149
|
const initCheck = requireInit();
|
|
142
150
|
if (initCheck) return initCheck;
|
|
@@ -154,7 +162,11 @@ async function answerHandler(args = {}) {
|
|
|
154
162
|
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.');
|
|
155
163
|
if (line.receipts().some((r) => r.kind === 'answered' && r.answers === id)) return refuse('Nothing sent. That question was already answered from this machine.');
|
|
156
164
|
|
|
157
|
-
|
|
165
|
+
// The receipt check above is local and not atomic with the send: two answers
|
|
166
|
+
// to one question in flight together would both pass it. The key is the same
|
|
167
|
+
// for any answer from this handle to this question, so the service stores at
|
|
168
|
+
// most one (a second, different answer is refused as an idempotency conflict).
|
|
169
|
+
const sent = await deliver({ to, message: message + line.ANSWERED(me), replyTo: id, origin: 'agent_line', idempotencyKey: answerKey(me, id) });
|
|
158
170
|
if (!sent.data || !sent.data.sent) return sent;
|
|
159
171
|
line.record({ kind: 'answered', with: to, id: sent.data.message_id, answers: id, asked: line.stripMark(row.text || ''), said: message });
|
|
160
172
|
// The person is shown the answer by the hook, not by the agent's memory.
|
|
@@ -168,4 +180,5 @@ async function answerHandler(args = {}) {
|
|
|
168
180
|
module.exports = {
|
|
169
181
|
vibe_ask: { definition: askDefinition, handler: askHandler },
|
|
170
182
|
vibe_answer: { definition: answerDefinition, handler: answerHandler },
|
|
183
|
+
answerKey,
|
|
171
184
|
};
|