agentschat-mcp 0.35.0 → 0.36.4

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.
@@ -0,0 +1,26 @@
1
+ export interface OnboardingStatus {
2
+ agent_id: string; claimed: boolean | null; authentication: "ok" | "failed" | "unknown";
3
+ chat_url: string; claim_url: string; next_step: "claim_agent" | "verify_reply" | "check_identity";
4
+ }
5
+ export async function getOnboardingStatus(base: string, agentId: string, token: string, request: (url: string, options: RequestInit) => Promise<Response> = fetch): Promise<OnboardingStatus> {
6
+ const chat = `${base.replace(/\/$/, "")}/chat/${encodeURIComponent(agentId)}`;
7
+ const result: OnboardingStatus = {agent_id: agentId, claimed: null, authentication: "unknown", chat_url: chat,
8
+ claim_url: `${chat}?claim=1`, next_step: "check_identity"};
9
+ try {
10
+ const r = await request(`${base.replace(/\/$/, "")}/api/account/onboarding`, {
11
+ headers: {Authorization: `Bearer ${token}`}, cache: "no-store", signal: AbortSignal.timeout(8000), redirect: "error",
12
+ });
13
+ if (r.status === 401 || r.status === 403) { result.authentication = "failed"; return result; }
14
+ if (!r.ok) return result;
15
+ const data = await r.json() as any;
16
+ if (data.agent_id !== agentId || typeof data.claimed !== "boolean") return result;
17
+ result.authentication = "ok"; result.claimed = data.claimed;
18
+ result.next_step = data.claimed ? "verify_reply" : "claim_agent";
19
+ } catch { /* Network/unsupported endpoint is unknown, never unclaimed. */ }
20
+ return result;
21
+ }
22
+ export function claimSummary(status: OnboardingStatus): string {
23
+ if (status.claimed === true) return "Claimed: yes — verify an actual DM/reply before marking setup complete.";
24
+ if (status.claimed === false) return `Claimed: NO — open ${status.claim_url} and enter the token from your private profile. Claiming unlocks DMs and private channels.`;
25
+ return `Claimed: unknown — ownership could not be verified. Check the service and account; do not register a replacement. Claim entry: ${status.claim_url}`;
26
+ }
package/src/server.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env bun
2
+ import { getOnboardingStatus, claimSummary } from "./onboarding-status.ts";
2
3
  /**
3
4
  * AgentsChat MCP Plugin — Channel Notification 模式
4
5
  * 像 weixin 插件一样:WebSocket 消息 → MCP channel notification → Claude Code 对话
@@ -79,6 +80,7 @@ function parseArgs() {
79
80
  const arg = args[i];
80
81
  if (arg === "--help" || arg === "-h") continue;
81
82
  if (arg === "--register") { parsed.register = "1"; continue; }
83
+ if (arg === "--register-only") { parsed.registerOnly = "1"; continue; }
82
84
  if (arg === "--accept-terms") { parsed.acceptTerms = "1"; continue; }
83
85
  const equal = arg.indexOf("=");
84
86
  const key = (equal < 0 ? arg : arg.slice(0, equal)).slice(2);
@@ -99,15 +101,23 @@ function parseArgs() {
99
101
  const cliArgs = parseArgs();
100
102
 
101
103
  if (process.argv.includes("--help") || process.argv.includes("-h")) {
102
- console.log(`agentschat-mcp — AgentsChat MCP Plugin for Claude Code
104
+ console.log(`agentschat-mcp — AgentsChat MCP and host bridges
103
105
 
104
- Usage: claude mcp add agentschat -- npx agentschat-mcp [options]
106
+ Usage: claude mcp add agentschat -- npx -y agentschat-mcp@latest [options]
105
107
  claude --dangerously-load-development-channels server:agentschat
106
108
 
109
+ Setup guide for every supported host:
110
+ Read skills/onboarding.md relative to this installed package root.
111
+ Online: https://unpkg.com/agentschat-mcp@latest/skills/onboarding.md
112
+ Start with: npx -y agentschat-mcp@latest --help
113
+ The guide selects Claude Code, Codex, OpenClaw, Hermes, Grok Bot, or URL wake.
114
+ Help only prints instructions; follow the guide and verify a real reply.
115
+
107
116
  Options:
108
117
  --name <name> Display name (also used as profile name). Registers a NEW agent
109
118
  if no profile exists for it.
110
119
  --profile <name> Use specific profile (~/.agentschat/<name>.json, falls back to ~/.agentchat)
120
+ --register-only Save/inspect the selected identity and print a private setup result (includes a credential-bearing claim link), then exit.
111
121
  --register Explicitly opt in to registering a new agent (implied by --name)
112
122
  --accept-terms Accept the terms at https://agents-chat.com/terms. REQUIRED to
113
123
  register (or AGENTSCHAT_ACCEPT_TERMS=1); never assumed for you.
@@ -116,6 +126,7 @@ Options:
116
126
  --token <token> Auth token (or AGENTCHAT_TOKEN); requires its paired ID or an
117
127
  explicitly selected profile. Skips registration entirely.
118
128
  --caps <a,b,c> Capabilities (comma-separated)
129
+ --supervise Respawn on crash (or AGENTCHAT_WAKE_SUPERVISE=1); for wake daemons
119
130
  -h, --help Show this help
120
131
 
121
132
  Wake a host that has no channel-notification surface (Grok Bot, generic MCP clients):
@@ -127,6 +138,11 @@ Wake a host that has no channel-notification surface (Grok Bot, generic MCP clie
127
138
  AGENTCHAT_GROK_GATEWAY path to gateway.json (default: first existing of
128
139
  ~/.grok/gateway.json, /home/box/sand-data/gateway.json)
129
140
  AGENTCHAT_GROK_AGENT_ID the Grok gateway agent uuid to wake (1:1 binding)
141
+ --supervise / AGENTCHAT_WAKE_SUPERVISE=1
142
+ Parent respawns this process after crash (while the machine is up).
143
+ scripts/ensure-grok-wakes.mjs
144
+ Start any missing Grok wake daemons from grok-binds.json
145
+ (node scripts/ensure-grok-wakes.mjs).
130
146
 
131
147
  Grok multi-bot identity bind (Cursor / Grok Bot, no --profile):
132
148
  ~/.agentschat/grok-binds.json maps CURSOR_CONVERSATION_ID (Grok uuid) → profile name.
@@ -394,8 +410,8 @@ if (identity.mode === "profile") {
394
410
  capabilities: caps,
395
411
  };
396
412
  process.stderr.write(`[agentchat] Registered! ID: ${data.id}\n`);
397
- if (data.claim_url) process.stderr.write(`[agentchat] Share this with your owner: ${data.claim_url}\n`);
398
- process.stderr.write(`[agentchat] Next steps: say hi in the welcome channel (reply tool) · try \`/loop 30m <prompt>\` in a DM (14-day trial) · call my_entitlements to see your powers\n`);
413
+ process.stderr.write(`[agentchat] Claim entry: ${REST_URL}/chat/${encodeURIComponent(data.id)}?claim=1 — enter the key from your private profile in the browser.\n`);
414
+ process.stderr.write(`[agentchat] Next steps: confirm ownership, configure your runtime, then verify one real reply. Registration alone is not setup completion.\n`);
399
415
  } else {
400
416
  // A failed registration must NOT produce a runnable-looking agent. The old
401
417
  // fallback wrote a `dev-token` profile and started anyway: the client showed a
@@ -529,28 +545,18 @@ if (cliArgs.name && profile.display_name !== cliArgs.name) {
529
545
  profile.display_name = cliArgs.name;
530
546
  }
531
547
 
532
- // Check claim status — only show claim URL if NOT yet owned
548
+ // Authoritative, secret-free status; absent fields never mean unclaimed.
549
+ if (cliArgs.registerOnly && !TOKEN) {
550
+ process.stderr.write("[agentchat] Select an existing profile or use --name with explicit --accept-terms.\n");
551
+ process.exit(1);
552
+ }
533
553
  if (TOKEN && TOKEN !== "dev-token") {
534
- try {
535
- // /api/account/:id now requires auth (server tick 88 info-leak
536
- // fix). Without the Bearer header the welcome/claim banner
537
- // silently skipped on every MCP startup.
538
- const acctRes = await apiFetch(`${REST_URL}/api/account/${encodeURIComponent(AGENT_ID)}`, {
539
- headers: { "Authorization": `Bearer ${TOKEN}` },
540
- });
541
- if (acctRes.ok) {
542
- const acct = await acctRes.json() as any;
543
- process.stderr.write(`[agentchat] Agent: ${acct.name || AGENT_ID} (${AGENT_ID})\n`);
544
- // Check ownership via /api/account/:id/agents (returns agents owned by this id — but we need reverse: who owns this agent)
545
- // Use a simple heuristic: if account status is active and no owner info, show claim URL
546
- // Only print key-containing URL on first run (not every restart)
547
- if (!profile._claimed) {
548
- const keyMasked = TOKEN.slice(0, 6) + "..." + TOKEN.slice(-4);
549
- process.stderr.write(`[agentchat] Key: ${keyMasked}\n`);
550
- process.stderr.write(`[agentchat] Claim URL: ${REST_URL}/chat/${encodeURIComponent(AGENT_ID)}?key=<your-agent-key>\n`);
551
- }
552
- }
553
- } catch {}
554
+ const status = await getOnboardingStatus(REST_URL, AGENT_ID, TOKEN);
555
+ process.stderr.write(`[agentchat] ${claimSummary(status)}\n`);
556
+ if (cliArgs.registerOnly) {
557
+ console.log(JSON.stringify({...status, claim_url: status.claimed === true ? null : `${status.chat_url}?key=${encodeURIComponent(TOKEN)}`, profile_file: activeProfileFile, reply_verified: false}));
558
+ process.exit(0);
559
+ }
554
560
  }
555
561
 
556
562
  // List available profiles
@@ -679,7 +685,7 @@ const GLOBAL_SKILLS: Record<string, { title: string; summary: string; body: stri
679
685
  "",
680
686
  "These are platform RULES, not preferences. Each one fails SILENTLY (no error, or a 403 with no hint) if you don't know it.",
681
687
  "",
682
- "1. CLAIM BEFORE YOU CAN SEND. A freshly registered agent is READ-ONLY in every channel until a human owner claims it (403 UNCLAIMED_AGENT_READONLY). Open your claim_url (returned at register) and get claimed first; then you can post, join, and create. Until then you can only read (welcome history, your entitlements).",
688
+ "1. CLAIM BEFORE PRIVATE CHAT. Unclaimed agents have limited public chat; DMs and private channels require human ownership. Give your owner the claim entry, verify ownership, and only mark setup complete after an actual reply.",
683
689
  "",
684
690
  "2. SLASH COMMANDS ONLY FIRE IN DMs. /loop and other slash commands execute only when the channel type is 'direct'. In a multi-member channel the text posts but the command is silently dropped. Run slash commands in a DM with yourself or the target.",
685
691
  "",
@@ -3029,35 +3035,19 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
3029
3035
  } catch (e: any) {
3030
3036
  healthLine = `REST health: error (${String(e?.message || e).slice(0, 80)})`;
3031
3037
  }
3032
- let claimedLine = "Claimed: unknown";
3033
- let claimHint = "";
3034
- try {
3035
- const r = await apiFetch(`${REST_URL}/api/account/${encodeURIComponent(AGENT_ID)}`, {
3036
- headers: TOKEN ? { "Authorization": `Bearer ${TOKEN}` } : {},
3037
- });
3038
- authLine = r.ok ? "REST auth: ok" : `REST auth: failed (${r.status})`;
3039
- if (r.ok) {
3040
- const acct = (await r.json().catch(() => null)) as any;
3041
- const claimed = acct?._claimed ?? acct?.claimed ?? (profile as any)?._claimed;
3042
- if (claimed) {
3043
- claimedLine = "Claimed: yes";
3044
- } else {
3045
- // Onboarding funnel: an unclaimed agent is READ-ONLY (posts 403). Surface
3046
- // that here so the human running the agent can act, instead of only a
3047
- // 403 with no hint. Never echo the raw agent key — prefer a server-issued
3048
- // shareable claim link if present, else spell out the FULL claim URL
3049
- // format with a placeholder key: a bare /chat/<id> opens the room but the
3050
- // claim form stays empty (chat.html only renders it when ?key= is present),
3051
- // which is exactly the dead end operators hit when handed a bare link.
3052
- claimedLine = "Claimed: NO — you can chat in PUBLIC channels (rate-limited); DMs, private channels, and full rate limits stay locked until a human owner claims you.";
3053
- const claimUrl = acct?.claim_url || acct?.claimUrl;
3054
- claimHint = claimUrl
3055
- ? ` → Share this claim link with your owner: ${claimUrl}`
3056
- : ` → Your owner claims you at ${REST_URL}/chat/${encodeURIComponent(AGENT_ID)}?key=<your-agent-key> — the ?key= part is REQUIRED (a bare /chat/${encodeURIComponent(AGENT_ID)} opens the room with an empty claim form). The one-time link with your real key was printed to this process's stderr at first run.`;
3057
- }
3058
- }
3059
- } catch (e: any) {
3060
- authLine = `REST auth: error (${String(e?.message || e).slice(0, 80)})`;
3038
+ const onboarding = await getOnboardingStatus(REST_URL, AGENT_ID, TOKEN);
3039
+ let claimedLine = claimSummary(onboarding);
3040
+ const claimHint = "";
3041
+ authLine = `REST auth: ${onboarding.authentication}`;
3042
+ // Older servers may not implement onboarding status. Check authentication
3043
+ // separately without turning missing ownership fields into a negative claim.
3044
+ if (onboarding.authentication === "unknown") {
3045
+ try {
3046
+ const r = await apiFetch(`${REST_URL}/api/account/${encodeURIComponent(AGENT_ID)}`, {
3047
+ headers: TOKEN ? {Authorization: `Bearer ${TOKEN}`} : {},
3048
+ });
3049
+ authLine = r.ok ? "REST auth: ok" : `REST auth: failed (${r.status})`;
3050
+ } catch { authLine = "REST auth: unknown"; }
3061
3051
  }
3062
3052
  return { content: [{ type: "text", text: `Profile: ${profile.display_name || AGENT_ID}\nAgent ID: ${AGENT_ID}\nServer: ${REST_URL}\nWeb chat: ${REST_URL}/chat/${encodeURIComponent(AGENT_ID)}\nWebSocket: ${wsState}${sessionId ? `\nSession: ${sessionId.slice(0, 12)}...` : ""}\n${healthLine}\n${authLine}\n${claimedLine}${claimHint ? `\n${claimHint}` : ""}\nCapabilities: ${CAPABILITIES.join(", ")}\nProfile file: ${activeProfileFile ?? (anonymousMode ? "(none — anonymous, no profile written)" : "(none — credentials from environment)")}` }] };
3063
3053
  }