agentschat-mcp 0.36.12 → 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 +49 -0
- package/README.md +129 -96
- 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-bridge.js +164 -29
- package/dist/server.js +1037 -186
- package/package.json +8 -4
- package/skills/grok-wake-keepalive.md +12 -1
- package/skills/onboarding.md +248 -106
- package/skills/url-wake-keepalive.md +4 -0
- 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 +553 -112
- 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
package/dist/codex-bridge.js
CHANGED
|
@@ -171,7 +171,7 @@ async function getOnboardingStatus(base, agentId, token, request = fetch) {
|
|
|
171
171
|
return result;
|
|
172
172
|
result.authentication = "ok";
|
|
173
173
|
result.claimed = data.claimed;
|
|
174
|
-
result.next_step = data.claimed ? "verify_reply" : "
|
|
174
|
+
result.next_step = data.claimed ? "verify_reply" : "join_public_chat";
|
|
175
175
|
} catch {}
|
|
176
176
|
return result;
|
|
177
177
|
}
|
|
@@ -292,9 +292,9 @@ ${text}`,
|
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
// codex/run.ts
|
|
295
|
-
import { readFileSync as
|
|
295
|
+
import { readFileSync as readFileSync9 } from "node:fs";
|
|
296
296
|
import { homedir as homedir4 } from "node:os";
|
|
297
|
-
import { join as
|
|
297
|
+
import { join as join10 } from "node:path";
|
|
298
298
|
|
|
299
299
|
// codex/bots-config.ts
|
|
300
300
|
import { readFileSync as readFileSync3, realpathSync as realpathSync3, mkdirSync as mkdirSync3 } from "node:fs";
|
|
@@ -1437,6 +1437,8 @@ class AppServer {
|
|
|
1437
1437
|
}
|
|
1438
1438
|
async start() {
|
|
1439
1439
|
const env = Object.fromEntries(Object.entries(process.env).filter(([k]) => !/^AGENTS?CHAT_|^RELAY_/.test(k)));
|
|
1440
|
+
env.AGENTSCHAT_LOCK_OWNER_PID = String(process.pid);
|
|
1441
|
+
env.AGENTSCHAT_TOOL_ONLY = "1";
|
|
1440
1442
|
if (this.runtime) {
|
|
1441
1443
|
env.CODEX_HOME = this.runtime.home;
|
|
1442
1444
|
env.CODEX_SQLITE_HOME = this.runtime.home;
|
|
@@ -1644,8 +1646,8 @@ function isTeamLeadSkillInvocation(prompt) {
|
|
|
1644
1646
|
}
|
|
1645
1647
|
|
|
1646
1648
|
// codex/bridge.ts
|
|
1647
|
-
import { existsSync as
|
|
1648
|
-
import { join as
|
|
1649
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync6, readFileSync as readFileSync7, renameSync as renameSync4, writeFileSync as writeFileSync4, openSync, closeSync, unlinkSync as unlinkSync3 } from "node:fs";
|
|
1650
|
+
import { join as join8 } from "node:path";
|
|
1649
1651
|
|
|
1650
1652
|
// codex/thread-history.ts
|
|
1651
1653
|
import { createHash as createHash2 } from "node:crypto";
|
|
@@ -1780,6 +1782,124 @@ async function verifyLoopTick(raw, config, owner, list) {
|
|
|
1780
1782
|
return current && current.owner_id === owner ? current : null;
|
|
1781
1783
|
}
|
|
1782
1784
|
|
|
1785
|
+
// src/session-bind.ts
|
|
1786
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
1787
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync5, readFileSync as readFileSync6, unlinkSync as unlinkSync2 } from "node:fs";
|
|
1788
|
+
import { tmpdir } from "node:os";
|
|
1789
|
+
import { join as join7 } from "node:path";
|
|
1790
|
+
|
|
1791
|
+
// src/profile-store.ts
|
|
1792
|
+
import { existsSync as existsSync3, writeFileSync as writeFileSync3, renameSync as renameSync3, chmodSync, unlinkSync, statSync as statSync2 } from "fs";
|
|
1793
|
+
var defaultWarn = (m) => process.stderr.write(m);
|
|
1794
|
+
function safeWriteProfile(path, data, warn = defaultWarn) {
|
|
1795
|
+
const tmp = path + ".tmp";
|
|
1796
|
+
try {
|
|
1797
|
+
if (existsSync3(tmp))
|
|
1798
|
+
unlinkSync(tmp);
|
|
1799
|
+
} catch (e) {
|
|
1800
|
+
warn(`[agentchat] WARNING: stale ${tmp} could not be removed: ${e}
|
|
1801
|
+
`);
|
|
1802
|
+
}
|
|
1803
|
+
writeFileSync3(tmp, JSON.stringify(data, null, 2), { mode: 384 });
|
|
1804
|
+
renameSync3(tmp, path);
|
|
1805
|
+
try {
|
|
1806
|
+
chmodSync(path, 384);
|
|
1807
|
+
} catch (e) {
|
|
1808
|
+
warn(`[agentchat] WARNING: could not chmod ${path} to 0600: ${e}
|
|
1809
|
+
`);
|
|
1810
|
+
}
|
|
1811
|
+
try {
|
|
1812
|
+
const mode = statSync2(path).mode & 511;
|
|
1813
|
+
if (mode !== 384) {
|
|
1814
|
+
warn(`[agentchat] WARNING: ${path} is mode ${mode.toString(8)}, expected 600 — it holds your agent key. Fix: chmod 600 ${path}
|
|
1815
|
+
`);
|
|
1816
|
+
}
|
|
1817
|
+
} catch (e) {
|
|
1818
|
+
warn(`[agentchat] WARNING: could not verify permissions of ${path}: ${e}
|
|
1819
|
+
`);
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
|
|
1823
|
+
// src/session-bind.ts
|
|
1824
|
+
function isPidAlive(pid) {
|
|
1825
|
+
if (typeof pid !== "number" || !Number.isInteger(pid) || pid <= 0)
|
|
1826
|
+
return false;
|
|
1827
|
+
try {
|
|
1828
|
+
process.kill(pid, 0);
|
|
1829
|
+
return true;
|
|
1830
|
+
} catch (e) {
|
|
1831
|
+
if (e && typeof e === "object" && e.code === "EPERM")
|
|
1832
|
+
return true;
|
|
1833
|
+
return false;
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
function resolveLockDir(homeDir, env = process.env) {
|
|
1837
|
+
const explicit = env.AGENTSCHAT_LOCK_DIR?.trim();
|
|
1838
|
+
if (explicit)
|
|
1839
|
+
return explicit;
|
|
1840
|
+
const hash = createHash3("sha256").update(homeDir || ".").digest("hex").slice(0, 12);
|
|
1841
|
+
const baseTmp = process.platform === "win32" ? tmpdir() : "/tmp";
|
|
1842
|
+
return join7(baseTmp, `agentschat-locks-${hash}`);
|
|
1843
|
+
}
|
|
1844
|
+
function lockFilePath(lockDir, agentId) {
|
|
1845
|
+
const safe = String(agentId || "").trim().replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
1846
|
+
return join7(lockDir, `${safe}.lock`);
|
|
1847
|
+
}
|
|
1848
|
+
function readAgentLock(lockDir, agentId) {
|
|
1849
|
+
if (!agentId)
|
|
1850
|
+
return null;
|
|
1851
|
+
const file = lockFilePath(lockDir, agentId);
|
|
1852
|
+
if (!existsSync4(file))
|
|
1853
|
+
return null;
|
|
1854
|
+
try {
|
|
1855
|
+
const raw = JSON.parse(readFileSync6(file, "utf8"));
|
|
1856
|
+
if (!raw || typeof raw !== "object" || typeof raw.pid !== "number" || typeof raw.agentId !== "string") {
|
|
1857
|
+
return null;
|
|
1858
|
+
}
|
|
1859
|
+
return raw;
|
|
1860
|
+
} catch {
|
|
1861
|
+
return null;
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
function acquireAgentLock(opts) {
|
|
1865
|
+
if (!opts.agentId)
|
|
1866
|
+
return null;
|
|
1867
|
+
const record = {
|
|
1868
|
+
pid: opts.currentPid ?? process.pid,
|
|
1869
|
+
agentId: opts.agentId,
|
|
1870
|
+
profileName: opts.profileName ?? null,
|
|
1871
|
+
sessionId: opts.sessionId ?? null,
|
|
1872
|
+
runtime: opts.runtime ?? "mcp",
|
|
1873
|
+
updatedAt: new Date().toISOString()
|
|
1874
|
+
};
|
|
1875
|
+
try {
|
|
1876
|
+
mkdirSync5(opts.lockDir, { recursive: true, mode: 448 });
|
|
1877
|
+
safeWriteProfile(lockFilePath(opts.lockDir, opts.agentId), record);
|
|
1878
|
+
return record;
|
|
1879
|
+
} catch {
|
|
1880
|
+
return null;
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1883
|
+
function releaseAgentLock(opts) {
|
|
1884
|
+
if (!opts.agentId)
|
|
1885
|
+
return false;
|
|
1886
|
+
const currentPid = opts.currentPid ?? process.pid;
|
|
1887
|
+
const existing = readAgentLock(opts.lockDir, opts.agentId);
|
|
1888
|
+
if (!existing)
|
|
1889
|
+
return false;
|
|
1890
|
+
const samePid = existing.pid === currentPid;
|
|
1891
|
+
const sameSession = Boolean(opts.currentSessionId && existing.sessionId && opts.currentSessionId === existing.sessionId);
|
|
1892
|
+
const dead = !isPidAlive(existing.pid);
|
|
1893
|
+
if (!samePid && !sameSession && !dead)
|
|
1894
|
+
return false;
|
|
1895
|
+
try {
|
|
1896
|
+
unlinkSync2(lockFilePath(opts.lockDir, opts.agentId));
|
|
1897
|
+
return true;
|
|
1898
|
+
} catch {
|
|
1899
|
+
return false;
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
|
|
1783
1903
|
// codex/bridge.ts
|
|
1784
1904
|
function permitted(m, c) {
|
|
1785
1905
|
if (m.meta?.kind === "loop_tick")
|
|
@@ -1826,18 +1946,31 @@ class Bridge {
|
|
|
1826
1946
|
this.activity = activity;
|
|
1827
1947
|
this.owner = owner;
|
|
1828
1948
|
this.loops = loops;
|
|
1829
|
-
|
|
1830
|
-
this.file =
|
|
1831
|
-
this.lock =
|
|
1949
|
+
mkdirSync6(config.stateDir, { recursive: true, mode: 448 });
|
|
1950
|
+
this.file = join8(config.stateDir, "state.json");
|
|
1951
|
+
this.lock = join8(config.stateDir, "bridge.lock");
|
|
1952
|
+
if (existsSync5(this.lock)) {
|
|
1953
|
+
try {
|
|
1954
|
+
const holderPid = Number(readFileSync7(this.lock, "utf8").trim());
|
|
1955
|
+
if (holderPid > 0 && !isPidAlive(holderPid))
|
|
1956
|
+
unlinkSync3(this.lock);
|
|
1957
|
+
} catch {}
|
|
1958
|
+
}
|
|
1832
1959
|
try {
|
|
1833
1960
|
const fd = openSync(this.lock, "wx", 384);
|
|
1834
|
-
|
|
1961
|
+
writeFileSync4(fd, String(process.pid));
|
|
1835
1962
|
closeSync(fd);
|
|
1836
1963
|
} catch {
|
|
1837
1964
|
throw new Error(`Bridge already locked: ${this.lock}. If its process has exited, remove that lock manually.`);
|
|
1838
1965
|
}
|
|
1966
|
+
const homeDir = process.env.HOME || process.env.USERPROFILE || ".";
|
|
1967
|
+
acquireAgentLock({
|
|
1968
|
+
lockDir: resolveLockDir(homeDir, process.env),
|
|
1969
|
+
agentId: config.agentId,
|
|
1970
|
+
runtime: "codex-bridge"
|
|
1971
|
+
});
|
|
1839
1972
|
try {
|
|
1840
|
-
this.state =
|
|
1973
|
+
this.state = existsSync5(this.file) ? JSON.parse(readFileSync7(this.file, "utf8")) : { version: 1, threads: {}, entries: [] };
|
|
1841
1974
|
if (this.state.version !== 1 || !this.state.threads || !Array.isArray(this.state.entries))
|
|
1842
1975
|
throw new Error("Invalid bridge state");
|
|
1843
1976
|
for (const e of this.state.entries) {
|
|
@@ -1848,14 +1981,14 @@ class Bridge {
|
|
|
1848
1981
|
}
|
|
1849
1982
|
this.save();
|
|
1850
1983
|
} catch {
|
|
1851
|
-
|
|
1984
|
+
unlinkSync3(this.lock);
|
|
1852
1985
|
throw new Error("Cannot load bridge state; refusing to discard history");
|
|
1853
1986
|
}
|
|
1854
1987
|
}
|
|
1855
1988
|
save() {
|
|
1856
1989
|
const tmp = this.file + ".tmp";
|
|
1857
|
-
|
|
1858
|
-
|
|
1990
|
+
writeFileSync4(tmp, JSON.stringify(this.state), { mode: 384 });
|
|
1991
|
+
renameSync4(tmp, this.file);
|
|
1859
1992
|
}
|
|
1860
1993
|
accept(raw) {
|
|
1861
1994
|
if (this.stopped || !addressed(raw, this.config))
|
|
@@ -1974,7 +2107,7 @@ This scheduled skill run supports ${TEAM_LEAD_NO_UPDATE}; return it alone only w
|
|
|
1974
2107
|
Authorized task:
|
|
1975
2108
|
${authorizedTask}` : `You are the online AgentsChat bot ${this.config.agentId}, running through Codex App Server in ${this.config.cwd}. This message was delivered to you live. If asked whether you are online, confirm your own availability.
|
|
1976
2109
|
Use this channel's shared conversation and configured tools to carry out the request.
|
|
1977
|
-
Recurring-task setup, only when requested: create the server loop as this bot in this same channel. Then verify its record with list_loops and confirm this bot is claimed with whoami and obtain its owner_account_id with my_entitlements. Maintain the private file ${
|
|
2110
|
+
Recurring-task setup, only when requested: create the server loop as this bot in this same channel. Then verify its record with list_loops and confirm this bot is claimed with whoami and obtain its owner_account_id with my_entitlements. Maintain the private file ${join8(this.config.stateDir, "loop-grants.json")} (mode 0600): {"version":1,"grants":[{"loop_id":"server loop ID","channel_id":"this channel ID","agent_id":"this bot ID","owner_id":"verified owner ID","interval_ms":60000,"prompt":"exact server prompt"}]}. Use the actual server interval, preserve other grants, and confirm setup only after both server registration and the matching local grant exist. Stopping a loop also removes its grant. Do not change unrelated loops.
|
|
1978
2111
|
AgentsChat message:
|
|
1979
2112
|
` + JSON.stringify(e.message);
|
|
1980
2113
|
e.answer = this.redact(await this.codex.generate(channel.thread, (channel.bootstrap ?? "") + prompt));
|
|
@@ -2032,8 +2165,10 @@ AgentsChat message:
|
|
|
2032
2165
|
async stop() {
|
|
2033
2166
|
this.pause();
|
|
2034
2167
|
await this.draining;
|
|
2035
|
-
if (
|
|
2036
|
-
|
|
2168
|
+
if (existsSync5(this.lock))
|
|
2169
|
+
unlinkSync3(this.lock);
|
|
2170
|
+
const homeDir = process.env.HOME || process.env.USERPROFILE || ".";
|
|
2171
|
+
releaseAgentLock({ lockDir: resolveLockDir(homeDir, process.env), agentId: this.config.agentId });
|
|
2037
2172
|
}
|
|
2038
2173
|
}
|
|
2039
2174
|
|
|
@@ -2114,8 +2249,8 @@ class HeartbeatMonitor {
|
|
|
2114
2249
|
}
|
|
2115
2250
|
|
|
2116
2251
|
// codex/inbox-sync.ts
|
|
2117
|
-
import { existsSync as
|
|
2118
|
-
import { join as
|
|
2252
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync7, readFileSync as readFileSync8, renameSync as renameSync5, writeFileSync as writeFileSync5 } from "node:fs";
|
|
2253
|
+
import { join as join9 } from "node:path";
|
|
2119
2254
|
|
|
2120
2255
|
// src/timestamps.ts
|
|
2121
2256
|
function normalizeTimestampForCursor(ts, mode) {
|
|
@@ -2157,9 +2292,9 @@ class InboxSync {
|
|
|
2157
2292
|
this.receive = receive;
|
|
2158
2293
|
this.active = active;
|
|
2159
2294
|
this.log = log;
|
|
2160
|
-
|
|
2161
|
-
this.file =
|
|
2162
|
-
this.state =
|
|
2295
|
+
mkdirSync7(stateDir, { recursive: true, mode: 448 });
|
|
2296
|
+
this.file = join9(stateDir, "inbound-cursors.json");
|
|
2297
|
+
this.state = existsSync6(this.file) ? JSON.parse(readFileSync8(this.file, "utf8")) : { version: 1, channels: {} };
|
|
2163
2298
|
if (this.state.version !== 1 || !this.state.channels || typeof this.state.channels !== "object" || Array.isArray(this.state.channels))
|
|
2164
2299
|
throw new Error("Invalid inbound cursors; refusing to discard checkpoint");
|
|
2165
2300
|
for (const value of Object.values(this.state.channels))
|
|
@@ -2167,8 +2302,8 @@ class InboxSync {
|
|
|
2167
2302
|
this.state.channels = Object.assign(Object.create(null), this.state.channels);
|
|
2168
2303
|
}
|
|
2169
2304
|
save() {
|
|
2170
|
-
|
|
2171
|
-
|
|
2305
|
+
writeFileSync5(this.file + ".tmp", JSON.stringify(this.state), { mode: 384 });
|
|
2306
|
+
renameSync5(this.file + ".tmp", this.file);
|
|
2172
2307
|
}
|
|
2173
2308
|
watch(channel) {
|
|
2174
2309
|
this.channels.add(channel);
|
|
@@ -2350,7 +2485,7 @@ class AgentsChatTransport {
|
|
|
2350
2485
|
if (current() && socket.readyState === WebSocket.OPEN)
|
|
2351
2486
|
socket.send(JSON.stringify(value));
|
|
2352
2487
|
};
|
|
2353
|
-
const
|
|
2488
|
+
const join10 = (channel) => {
|
|
2354
2489
|
if (!this.config.channels.length || this.config.channels.includes(channel)) {
|
|
2355
2490
|
this.inboxSync?.watch(channel);
|
|
2356
2491
|
send({ type: "join_channel", channel_id: channel, agent_id: this.config.agentId });
|
|
@@ -2390,7 +2525,7 @@ class AgentsChatTransport {
|
|
|
2390
2525
|
const ids = channels.map((c) => c.id ?? c.channel_id).filter((id) => typeof id === "string" && (!this.config.channels.length || this.config.channels.includes(id)));
|
|
2391
2526
|
this.inboxSync?.memberships(ids);
|
|
2392
2527
|
for (const id of ids)
|
|
2393
|
-
|
|
2528
|
+
join10(id);
|
|
2394
2529
|
this.inboxSync?.sync();
|
|
2395
2530
|
}).catch(() => {
|
|
2396
2531
|
if (current()) {
|
|
@@ -2406,7 +2541,7 @@ class AgentsChatTransport {
|
|
|
2406
2541
|
pending.resolve();
|
|
2407
2542
|
}
|
|
2408
2543
|
} else if (data.type === "channel_created" && typeof data.channel_id === "string")
|
|
2409
|
-
|
|
2544
|
+
join10(data.channel_id);
|
|
2410
2545
|
else if (["message", "thread_reply"].includes(data.type))
|
|
2411
2546
|
this.receive(data);
|
|
2412
2547
|
else if (data.type === "shard_moved" || data.type === "please_reconnect")
|
|
@@ -2495,14 +2630,14 @@ async function main() {
|
|
|
2495
2630
|
return;
|
|
2496
2631
|
}
|
|
2497
2632
|
if (values["gui-thread"] || values["gui-message-file"] || values["gui-status"]) {
|
|
2498
|
-
const channel = new GuiChannel(
|
|
2633
|
+
const channel = new GuiChannel(join10(homedir4(), ".agentschat/codex-gui-outbox"), values["gui-thread"] ? [values["gui-thread"]] : []);
|
|
2499
2634
|
if (values["gui-status"]) {
|
|
2500
2635
|
console.log(JSON.stringify(channel.list().map(({ prompt: prompt2, ...receipt2 }) => receipt2)));
|
|
2501
2636
|
return;
|
|
2502
2637
|
}
|
|
2503
2638
|
if (!values["gui-thread"] || !values["gui-message-file"])
|
|
2504
2639
|
throw new Error("GUI submission requires --gui-thread and --gui-message-file");
|
|
2505
|
-
const { prompt, ...receipt } = channel.enqueue(values["gui-thread"],
|
|
2640
|
+
const { prompt, ...receipt } = channel.enqueue(values["gui-thread"], readFileSync9(values["gui-message-file"], "utf8"));
|
|
2506
2641
|
console.log(JSON.stringify(receipt));
|
|
2507
2642
|
return;
|
|
2508
2643
|
}
|
|
@@ -2538,7 +2673,7 @@ async function main() {
|
|
|
2538
2673
|
const runtime = prepareRuntimeHome(c.stateDir, undefined, c.codexHomeMode, c.codexBin);
|
|
2539
2674
|
codex = new AppServer(c.codexBin, undefined, undefined, c.permissions, runtime, c.effort, c.model);
|
|
2540
2675
|
if (values.conversations || values["read-conversation"]) {
|
|
2541
|
-
const state = JSON.parse(
|
|
2676
|
+
const state = JSON.parse(readFileSync9(join10(c.stateDir, "state.json"), "utf8"));
|
|
2542
2677
|
const channels = state.channels ?? {};
|
|
2543
2678
|
if (values.conversations) {
|
|
2544
2679
|
console.log(JSON.stringify(Object.entries(channels).map(([channel2, data]) => ({ channel: channel2, thread: data.thread, isolated: data.namespace === runtime.home }))));
|