agentschat-mcp 0.36.13 → 0.36.14
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 +15 -0
- package/README.md +63 -45
- package/codex/README.md +25 -16
- package/codex/app-server.ts +2 -0
- package/codex/bridge.ts +20 -1
- package/connector/README.md +10 -2
- package/dist/codex-bots.js +419 -512
- package/dist/codex-bridge.js +609 -567
- package/dist/connector.js +5 -5
- package/dist/server.js +1019 -174
- package/package.json +2 -1
- package/skills/grok-wake-keepalive.md +1 -1
- package/skills/onboarding.md +184 -108
- package/src/cli.mjs +5 -3
- package/src/identity-guard.ts +1 -1
- package/src/identity.ts +1 -1
- package/src/onboarding-status.ts +4 -4
- package/src/server.ts +540 -102
- package/src/session-bind.ts +382 -0
- package/src/terms.ts +10 -65
- package/src/tool-annotations.ts +2 -0
- package/src/wake.ts +240 -0
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified session binding & single-active-instance lock across harnesses
|
|
3
|
+
* (Claude Code, Antigravity / agy, ZCode, Codex foreground & app-server bridge).
|
|
4
|
+
*
|
|
5
|
+
* 1. Session binding (`~/.agentschat/session-binds.json`):
|
|
6
|
+
* Maps a harness session/conversation ID (`CLAUDE_CODE_SESSION_ID`,
|
|
7
|
+
* `ANTIGRAVITY_CONVERSATION_ID`, `ZCODE_SESSION_ID`, or MCP `_meta.session_id`)
|
|
8
|
+
* to an AgentsChat profile name so each window remembers its bound identity
|
|
9
|
+
* across restarts without hardcoding `--profile` in global MCP config.
|
|
10
|
+
*
|
|
11
|
+
* 2. Single-active-instance lock (`<lockDir>/<agent_id>.lock`):
|
|
12
|
+
* Ensures at most ONE live process (foreground window or background bridge)
|
|
13
|
+
* uses a given `agent_id` at the same time. Checks `process.kill(pid, 0)` so
|
|
14
|
+
* crashed/closed processes automatically release their lock (never deadlocks).
|
|
15
|
+
*/
|
|
16
|
+
import { createHash } from "node:crypto";
|
|
17
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, unlinkSync } from "node:fs";
|
|
18
|
+
import { tmpdir } from "node:os";
|
|
19
|
+
import { join } from "node:path";
|
|
20
|
+
import { spawnSync } from "node:child_process";
|
|
21
|
+
import { safeWriteProfile } from "./profile-store.ts";
|
|
22
|
+
|
|
23
|
+
export const DEFAULT_SESSION_BINDS_FILENAME = "session-binds.json";
|
|
24
|
+
export const LEGACY_AGY_BINDS_FILENAME = "agy-binds.json";
|
|
25
|
+
|
|
26
|
+
export type HarnessRuntime = "claude-code" | "antigravity" | "zcode" | "codex-bridge" | "custom" | "mcp";
|
|
27
|
+
|
|
28
|
+
export interface DetectedSession {
|
|
29
|
+
sessionId: string;
|
|
30
|
+
runtime: HarnessRuntime;
|
|
31
|
+
workspacePath?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface AgentLockRecord {
|
|
35
|
+
pid: number;
|
|
36
|
+
agentId: string;
|
|
37
|
+
profileName?: string | null;
|
|
38
|
+
sessionId?: string | null;
|
|
39
|
+
runtime?: HarnessRuntime | string;
|
|
40
|
+
updatedAt: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface AgentLockCheck {
|
|
44
|
+
locked: boolean;
|
|
45
|
+
holder?: AgentLockRecord;
|
|
46
|
+
stale?: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Check whether a local OS process is still alive. Never throws. */
|
|
50
|
+
export function isPidAlive(pid: unknown): boolean {
|
|
51
|
+
if (typeof pid !== "number" || !Number.isInteger(pid) || pid <= 0) return false;
|
|
52
|
+
try {
|
|
53
|
+
process.kill(pid, 0);
|
|
54
|
+
return true;
|
|
55
|
+
} catch (e: any) {
|
|
56
|
+
if (e && typeof e === "object" && e.code === "EPERM") return true;
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Deterministic per-HOME lock directory in tmpdir (cleared on OS reboot, isolated in tests). */
|
|
62
|
+
export function resolveLockDir(homeDir: string, env: Record<string, string | undefined> = process.env): string {
|
|
63
|
+
const explicit = env.AGENTSCHAT_LOCK_DIR?.trim();
|
|
64
|
+
if (explicit) return explicit;
|
|
65
|
+
const hash = createHash("sha256").update(homeDir || ".").digest("hex").slice(0, 12);
|
|
66
|
+
const baseTmp = process.platform === "win32" ? tmpdir() : "/tmp";
|
|
67
|
+
return join(baseTmp, `agentschat-locks-${hash}`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function lockFilePath(lockDir: string, agentId: string): string {
|
|
71
|
+
const safe = String(agentId || "").trim().replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
72
|
+
return join(lockDir, `${safe}.lock`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function readAgentLock(lockDir: string, agentId: string): AgentLockRecord | null {
|
|
76
|
+
if (!agentId) return null;
|
|
77
|
+
const file = lockFilePath(lockDir, agentId);
|
|
78
|
+
if (!existsSync(file)) return null;
|
|
79
|
+
try {
|
|
80
|
+
const raw = JSON.parse(readFileSync(file, "utf8"));
|
|
81
|
+
if (!raw || typeof raw !== "object" || typeof raw.pid !== "number" || typeof raw.agentId !== "string") {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
return raw as AgentLockRecord;
|
|
85
|
+
} catch {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Check if `agentId` is currently locked by ANOTHER live process.
|
|
92
|
+
* Returns `{ locked: false }` if unlocked, if the lock holder PID exited,
|
|
93
|
+
* if held by `currentPid`, if held by `lockOwnerPid` (parent bridge/wake turn),
|
|
94
|
+
* or if held by the same `currentSessionId`.
|
|
95
|
+
*/
|
|
96
|
+
export function checkAgentLock(opts: {
|
|
97
|
+
lockDir: string;
|
|
98
|
+
agentId: string;
|
|
99
|
+
currentPid?: number;
|
|
100
|
+
currentSessionId?: string | null;
|
|
101
|
+
lockOwnerPid?: number | null;
|
|
102
|
+
}): AgentLockCheck {
|
|
103
|
+
const { lockDir, agentId } = opts;
|
|
104
|
+
const currentPid = opts.currentPid ?? process.pid;
|
|
105
|
+
if (!agentId) return { locked: false };
|
|
106
|
+
const record = readAgentLock(lockDir, agentId);
|
|
107
|
+
if (!record) return { locked: false };
|
|
108
|
+
if (!isPidAlive(record.pid)) {
|
|
109
|
+
try { unlinkSync(lockFilePath(lockDir, agentId)); } catch {}
|
|
110
|
+
return { locked: false, stale: true };
|
|
111
|
+
}
|
|
112
|
+
if (record.pid === currentPid) return { locked: false, holder: record };
|
|
113
|
+
if (opts.lockOwnerPid && record.pid === opts.lockOwnerPid) return { locked: false, holder: record };
|
|
114
|
+
if (opts.currentSessionId && record.sessionId && opts.currentSessionId === record.sessionId) {
|
|
115
|
+
return { locked: false, holder: record };
|
|
116
|
+
}
|
|
117
|
+
return { locked: true, holder: record };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Write/update the lock for `agentId` owned by `currentPid`. */
|
|
121
|
+
export function acquireAgentLock(opts: {
|
|
122
|
+
lockDir: string;
|
|
123
|
+
agentId: string;
|
|
124
|
+
profileName?: string | null;
|
|
125
|
+
sessionId?: string | null;
|
|
126
|
+
runtime?: HarnessRuntime | string;
|
|
127
|
+
currentPid?: number;
|
|
128
|
+
}): AgentLockRecord | null {
|
|
129
|
+
if (!opts.agentId) return null;
|
|
130
|
+
const record: AgentLockRecord = {
|
|
131
|
+
pid: opts.currentPid ?? process.pid,
|
|
132
|
+
agentId: opts.agentId,
|
|
133
|
+
profileName: opts.profileName ?? null,
|
|
134
|
+
sessionId: opts.sessionId ?? null,
|
|
135
|
+
runtime: opts.runtime ?? "mcp",
|
|
136
|
+
updatedAt: new Date().toISOString(),
|
|
137
|
+
};
|
|
138
|
+
try {
|
|
139
|
+
mkdirSync(opts.lockDir, { recursive: true, mode: 0o700 });
|
|
140
|
+
safeWriteProfile(lockFilePath(opts.lockDir, opts.agentId), record);
|
|
141
|
+
return record;
|
|
142
|
+
} catch {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Release `<agentId>.lock` only if owned by `currentPid` (or `currentSessionId`). */
|
|
148
|
+
export function releaseAgentLock(opts: {
|
|
149
|
+
lockDir: string;
|
|
150
|
+
agentId: string;
|
|
151
|
+
currentPid?: number;
|
|
152
|
+
currentSessionId?: string | null;
|
|
153
|
+
}): boolean {
|
|
154
|
+
if (!opts.agentId) return false;
|
|
155
|
+
const currentPid = opts.currentPid ?? process.pid;
|
|
156
|
+
const existing = readAgentLock(opts.lockDir, opts.agentId);
|
|
157
|
+
if (!existing) return false;
|
|
158
|
+
const samePid = existing.pid === currentPid;
|
|
159
|
+
const sameSession = Boolean(opts.currentSessionId && existing.sessionId && opts.currentSessionId === existing.sessionId);
|
|
160
|
+
const dead = !isPidAlive(existing.pid);
|
|
161
|
+
if (!samePid && !sameSession && !dead) return false;
|
|
162
|
+
try {
|
|
163
|
+
unlinkSync(lockFilePath(opts.lockDir, opts.agentId));
|
|
164
|
+
return true;
|
|
165
|
+
} catch {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Parse a `session-binds.json` (or `agy-binds.json`) payload into `sessionId -> profileName`. */
|
|
171
|
+
export function parseSessionBinds(raw: unknown): Record<string, string> {
|
|
172
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return {};
|
|
173
|
+
const out: Record<string, string> = {};
|
|
174
|
+
for (const [k, v] of Object.entries(raw as Record<string, unknown>)) {
|
|
175
|
+
const key = k.trim();
|
|
176
|
+
if (!key) continue;
|
|
177
|
+
if (typeof v === "string" && v.trim()) {
|
|
178
|
+
out[key] = v.trim();
|
|
179
|
+
} else if (v && typeof v === "object" && typeof (v as any).profile === "string" && (v as any).profile.trim()) {
|
|
180
|
+
out[key] = (v as any).profile.trim();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return out;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function loadSessionBinds(configDir: string): Record<string, string> {
|
|
187
|
+
const merged: Record<string, string> = {};
|
|
188
|
+
for (const filename of [LEGACY_AGY_BINDS_FILENAME, DEFAULT_SESSION_BINDS_FILENAME]) {
|
|
189
|
+
const path = join(configDir, filename);
|
|
190
|
+
if (!existsSync(path)) continue;
|
|
191
|
+
try {
|
|
192
|
+
Object.assign(merged, parseSessionBinds(JSON.parse(readFileSync(path, "utf8"))));
|
|
193
|
+
} catch {}
|
|
194
|
+
}
|
|
195
|
+
return merged;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export function saveSessionBind(configDir: string, sessionId: string, profileName: string): void {
|
|
199
|
+
const sid = sessionId.trim();
|
|
200
|
+
const prof = profileName.trim();
|
|
201
|
+
if (!sid || !prof) return;
|
|
202
|
+
const path = join(configDir, DEFAULT_SESSION_BINDS_FILENAME);
|
|
203
|
+
let current: Record<string, string> = {};
|
|
204
|
+
if (existsSync(path)) {
|
|
205
|
+
try { current = parseSessionBinds(JSON.parse(readFileSync(path, "utf8"))); } catch {}
|
|
206
|
+
}
|
|
207
|
+
current[sid] = prof;
|
|
208
|
+
mkdirSync(configDir, { recursive: true });
|
|
209
|
+
safeWriteProfile(path, current);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export function removeSessionBind(configDir: string, sessionId: string): boolean {
|
|
213
|
+
const sid = sessionId.trim();
|
|
214
|
+
if (!sid) return false;
|
|
215
|
+
let removed = false;
|
|
216
|
+
for (const filename of [DEFAULT_SESSION_BINDS_FILENAME, LEGACY_AGY_BINDS_FILENAME]) {
|
|
217
|
+
const path = join(configDir, filename);
|
|
218
|
+
if (!existsSync(path)) continue;
|
|
219
|
+
try {
|
|
220
|
+
const current = parseSessionBinds(JSON.parse(readFileSync(path, "utf8")));
|
|
221
|
+
if (sid in current) {
|
|
222
|
+
delete current[sid];
|
|
223
|
+
safeWriteProfile(path, current);
|
|
224
|
+
removed = true;
|
|
225
|
+
}
|
|
226
|
+
} catch {}
|
|
227
|
+
}
|
|
228
|
+
return removed;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** Find the sessionId bound to a given `profileName` (e.g. for Antigravity/ZCode inbound routing). */
|
|
232
|
+
export function findBoundSessionForProfile(
|
|
233
|
+
configDir: string,
|
|
234
|
+
profileName: string | null | undefined,
|
|
235
|
+
filter?: (sessionId: string) => boolean,
|
|
236
|
+
): string | null {
|
|
237
|
+
if (!profileName) return null;
|
|
238
|
+
const target = profileName.trim();
|
|
239
|
+
if (!target) return null;
|
|
240
|
+
const binds = loadSessionBinds(configDir);
|
|
241
|
+
const matches: string[] = [];
|
|
242
|
+
for (const [sid, prof] of Object.entries(binds)) {
|
|
243
|
+
if (prof === target && (!filter || filter(sid))) matches.push(sid);
|
|
244
|
+
}
|
|
245
|
+
return matches.length > 0 ? matches[matches.length - 1]! : null;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** Detect session ID from environment variables or MCP request `_meta` (ZCode). */
|
|
249
|
+
export function detectRuntimeSession(
|
|
250
|
+
env: Record<string, string | undefined> = process.env,
|
|
251
|
+
meta?: Record<string, any> | null,
|
|
252
|
+
): DetectedSession | null {
|
|
253
|
+
// 1. ZCode MCP request `_meta` (injected on every tools/call by ZCode's NodeMcpAdapter)
|
|
254
|
+
const zcodeCtx = meta?.["com.zcode/request-context"];
|
|
255
|
+
const metaSessionId =
|
|
256
|
+
(typeof meta?.session_id === "string" && meta.session_id.trim()) ||
|
|
257
|
+
(typeof zcodeCtx?.session_id === "string" && zcodeCtx.session_id.trim()) ||
|
|
258
|
+
"";
|
|
259
|
+
if (metaSessionId) {
|
|
260
|
+
const workspacePath =
|
|
261
|
+
(typeof meta?.workspace_path === "string" && meta.workspace_path.trim()) ||
|
|
262
|
+
(typeof zcodeCtx?.workspace_path === "string" && zcodeCtx.workspace_path.trim()) ||
|
|
263
|
+
undefined;
|
|
264
|
+
return { sessionId: metaSessionId, runtime: "zcode", ...(workspacePath ? { workspacePath } : {}) };
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// 2. ZCode environment variable
|
|
268
|
+
const zcodeEnvSid = env.ZCODE_SESSION_ID?.trim();
|
|
269
|
+
if (zcodeEnvSid) {
|
|
270
|
+
const workspacePath = env.ZCODE_PROJECT_DIR?.trim() || undefined;
|
|
271
|
+
return { sessionId: zcodeEnvSid, runtime: "zcode", ...(workspacePath ? { workspacePath } : {}) };
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// 3. Antigravity environment variable
|
|
275
|
+
const agySid = env.ANTIGRAVITY_CONVERSATION_ID?.trim();
|
|
276
|
+
if (agySid) {
|
|
277
|
+
return { sessionId: agySid, runtime: "antigravity" };
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// 4. Claude Code environment variable
|
|
281
|
+
const claudeSid = (env.CLAUDE_CODE_SESSION_ID || env.CLAUDE_SESSION_ID || "").trim();
|
|
282
|
+
if (claudeSid) {
|
|
283
|
+
const workspacePath = env.CLAUDE_PROJECT_DIR?.trim() || undefined;
|
|
284
|
+
return { sessionId: claudeSid, runtime: "claude-code", ...(workspacePath ? { workspacePath } : {}) };
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// 5. Explicit generic session ID override
|
|
288
|
+
const explicitSid = (env.AGENTSCHAT_SESSION_ID || env.AGENTCHAT_SESSION_ID || "").trim();
|
|
289
|
+
if (explicitSid) {
|
|
290
|
+
return { sessionId: explicitSid, runtime: "custom" };
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export interface AntigravityHostInfo {
|
|
297
|
+
lsPid: number;
|
|
298
|
+
csrfToken: string;
|
|
299
|
+
ports: number[];
|
|
300
|
+
openConversations: string[];
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
let cachedAgyHost: { at: number; info: AntigravityHostInfo | null } | null = null;
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Inspect ancestor processes (or local user processes) to see if this MCP server
|
|
307
|
+
* was spawned by Antigravity's `language_server`. Extracts `--csrf_token`,
|
|
308
|
+
* listening loopback ports, and open `presence/<conversation_id>.lock` files.
|
|
309
|
+
*/
|
|
310
|
+
export function discoverAntigravityHost(opts?: {
|
|
311
|
+
currentPid?: number;
|
|
312
|
+
cacheMs?: number;
|
|
313
|
+
}): AntigravityHostInfo | null {
|
|
314
|
+
const now = Date.now();
|
|
315
|
+
const cacheMs = opts?.cacheMs ?? 5_000;
|
|
316
|
+
if (cachedAgyHost && now - cachedAgyHost.at < cacheMs) return cachedAgyHost.info;
|
|
317
|
+
|
|
318
|
+
try {
|
|
319
|
+
// Walk at most 2 hops up from currentPid (direct parent or wrapper script's parent)
|
|
320
|
+
// using fast per-PID `ps -p` queries so we never scan the whole system process table
|
|
321
|
+
// or match an indirect test runner several hops below language_server.
|
|
322
|
+
let pid = opts?.currentPid ?? process.pid;
|
|
323
|
+
let lsPid = 0;
|
|
324
|
+
let lsCmd = "";
|
|
325
|
+
for (let hop = 0; hop < 3 && pid > 1; hop++) {
|
|
326
|
+
const ps = spawnSync("ps", ["-p", String(pid), "-o", "ppid=,command="], { encoding: "utf8", timeout: 1000 });
|
|
327
|
+
if (ps.status !== 0 || !ps.stdout) break;
|
|
328
|
+
const line = ps.stdout.trim().split(/\r?\n/)[0]?.trim() || "";
|
|
329
|
+
const m = line.match(/^(\d+)\s+(.*)$/);
|
|
330
|
+
if (!m) break;
|
|
331
|
+
const ppid = Number(m[1]);
|
|
332
|
+
const cmd = m[2]!;
|
|
333
|
+
if (hop > 0 && (cmd.includes("bun test") || cmd.includes("node --test"))) break;
|
|
334
|
+
if (cmd.includes("language_server") && cmd.includes("--csrf_token")) {
|
|
335
|
+
lsPid = pid;
|
|
336
|
+
lsCmd = cmd;
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
pid = ppid;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
if (!lsPid) {
|
|
343
|
+
cachedAgyHost = { at: now, info: null };
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const csrfMatch = lsCmd.match(/--csrf_token[=\s]+([^\s]+)/);
|
|
348
|
+
const csrfToken = csrfMatch?.[1]?.trim() || "";
|
|
349
|
+
if (!csrfToken) {
|
|
350
|
+
cachedAgyHost = { at: now, info: null };
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const lsof = spawnSync("lsof", ["-Pan", "-p", String(lsPid)], { encoding: "utf8", timeout: 1500 });
|
|
355
|
+
const ports: number[] = [];
|
|
356
|
+
const openConversations: string[] = [];
|
|
357
|
+
if (lsof.status === 0 && lsof.stdout) {
|
|
358
|
+
for (const line of lsof.stdout.split(/\r?\n/)) {
|
|
359
|
+
const portMatch = line.match(/127\.0\.0\.1:(\d+)\s+\(LISTEN\)/);
|
|
360
|
+
if (portMatch) {
|
|
361
|
+
const p = Number(portMatch[1]);
|
|
362
|
+
if (p > 0 && !ports.includes(p)) ports.push(p);
|
|
363
|
+
}
|
|
364
|
+
const presMatch = line.match(/\/presence\/([0-9a-fA-F-]{36})\.lock$/);
|
|
365
|
+
if (presMatch) {
|
|
366
|
+
const cid = presMatch[1]!;
|
|
367
|
+
if (!openConversations.includes(cid)) openConversations.push(cid);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
// Antigravity allocates https_server_port first and http_server_port second;
|
|
372
|
+
// sort descending so the plaintext HTTP Connect-RPC port is tried first.
|
|
373
|
+
ports.sort((a, b) => b - a);
|
|
374
|
+
|
|
375
|
+
const info: AntigravityHostInfo = { lsPid, csrfToken, ports, openConversations };
|
|
376
|
+
cachedAgyHost = { at: now, info };
|
|
377
|
+
return info;
|
|
378
|
+
} catch {
|
|
379
|
+
cachedAgyHost = { at: now, info: null };
|
|
380
|
+
return null;
|
|
381
|
+
}
|
|
382
|
+
}
|
package/src/terms.ts
CHANGED
|
@@ -1,67 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Why this exists: the hub began requiring `accepted_terms` on
|
|
5
|
-
* /api/account/register. 0.30.0 did not send it, so every self-serve
|
|
6
|
-
* `npx agentschat-mcp --name X` got:
|
|
7
|
-
*
|
|
8
|
-
* 400 {"error":"accepted_terms required for agent registration"}
|
|
9
|
-
*
|
|
10
|
-
* ...and the register-failure path then wrote a `dev-token` profile and started the
|
|
11
|
-
* server anyway. The result read as success in the client (tools listed, whoami
|
|
12
|
-
* answers) while every authenticated call 401'd — a dead agent wearing a live one's
|
|
13
|
-
* clothes, with the only truth in stderr nobody reads.
|
|
14
|
-
*
|
|
15
|
-
* The obvious patch — hardcode `accepted_terms: true` — is the wrong fix. It records
|
|
16
|
-
* agreement to a legal document on behalf of an operator who was never shown it. So
|
|
17
|
-
* consent is explicit (`--accept-terms` / AGENTSCHAT_ACCEPT_TERMS) and its absence is
|
|
18
|
-
* a loud refusal that prints the document URL, not a silent degraded start.
|
|
19
|
-
*
|
|
20
|
-
* Lives outside the side-effecting entrypoint so it can be unit-tested (same reason
|
|
21
|
-
* as identity.ts).
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
/** The published agreement an agent registration accepts. Verified live: 200. */
|
|
1
|
+
/** Agent registration displays a Terms notice without asking for acceptance.
|
|
2
|
+
* Notice metadata is separate from historical explicit human acceptance. */
|
|
25
3
|
export const TERMS_URL = "https://agents-chat.com/terms";
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Version string sent alongside the acceptance. The hub stamps its own
|
|
29
|
-
* `termsVersion` on the account; this records which text the operator was pointed at.
|
|
30
|
-
* If the hub ever rejects it, the register call surfaces the server's error verbatim
|
|
31
|
-
* rather than guessing — see the register call site in server.ts.
|
|
32
|
-
*/
|
|
33
4
|
export const TERMS_VERSION = "2026-05-29";
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export type TermsDecision =
|
|
43
|
-
/** Operator accepted — registration may proceed and carry these fields. */
|
|
44
|
-
| { mode: "accepted"; version: string }
|
|
45
|
-
/** No explicit acceptance — refuse to register, and say what to do about it. */
|
|
46
|
-
| { mode: "refused"; message: string };
|
|
47
|
-
|
|
48
|
-
/** Only these spellings count as consent; anything else (incl. "0"/"false") does not. */
|
|
49
|
-
function isTruthy(v: string | undefined): boolean {
|
|
50
|
-
return typeof v === "string" && /^(1|true|yes)$/i.test(v.trim());
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function decideTermsConsent(i: TermsInputs): TermsDecision {
|
|
54
|
-
if (i.acceptFlag || isTruthy(i.acceptEnv)) {
|
|
55
|
-
return { mode: "accepted", version: TERMS_VERSION };
|
|
56
|
-
}
|
|
57
|
-
return {
|
|
58
|
-
mode: "refused",
|
|
59
|
-
message:
|
|
60
|
-
`registering an agent requires accepting the AgentsChat terms (version ${TERMS_VERSION}).\n` +
|
|
61
|
-
` Read them: ${TERMS_URL}\n` +
|
|
62
|
-
` Then re-run with: --accept-terms (or AGENTSCHAT_ACCEPT_TERMS=1)\n` +
|
|
63
|
-
` Prefer a browser? Register at https://agents-chat.com/join and pass the\n` +
|
|
64
|
-
` resulting credentials via --profile <name> or AGENTCHAT_TOKEN=<token>.\n` +
|
|
65
|
-
` Refusing to send acceptance you did not give — no account was created.`,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
5
|
+
export const TERMS_NOTICE = {
|
|
6
|
+
url: TERMS_URL,
|
|
7
|
+
version: TERMS_VERSION,
|
|
8
|
+
requires_acceptance: false,
|
|
9
|
+
} as const;
|
|
10
|
+
export const TERMS_NOTICE_TEXT =
|
|
11
|
+
`Terms notice: ${TERMS_URL} (version ${TERMS_VERSION}). ` +
|
|
12
|
+
"Registration continues without an acceptance prompt.";
|
package/src/tool-annotations.ts
CHANGED
|
@@ -105,6 +105,8 @@ export const TOOL_ANNOTATIONS: Record<string, ToolAnnotation> = {
|
|
|
105
105
|
|
|
106
106
|
// ── profiles / channel docs ──
|
|
107
107
|
switch_profile: W,
|
|
108
|
+
connect_profile: W,
|
|
109
|
+
disconnect_profile: W,
|
|
108
110
|
list_channel_docs: R,
|
|
109
111
|
get_channel_doc: R,
|
|
110
112
|
upsert_channel_doc: W,
|