@agent-chat/mention-watcher 0.0.1 → 0.0.2
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/dist/chunk-YNXFY4Q4.js +122 -0
- package/dist/cli.js +33 -0
- package/dist/setup-332LIDBJ.js +7 -0
- package/dist/setup.js +3 -117
- package/package.json +2 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/setup.ts
|
|
4
|
+
import { readFileSync, writeFileSync, existsSync } from "fs";
|
|
5
|
+
import { join } from "path";
|
|
6
|
+
function loadEnvFile(path) {
|
|
7
|
+
if (!existsSync(path)) return {};
|
|
8
|
+
const result = {};
|
|
9
|
+
for (const line of readFileSync(path, "utf8").split("\n")) {
|
|
10
|
+
const trimmed = line.trim();
|
|
11
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
12
|
+
const eq = trimmed.indexOf("=");
|
|
13
|
+
if (eq < 0) continue;
|
|
14
|
+
const key = trimmed.slice(0, eq).trim();
|
|
15
|
+
const val = trimmed.slice(eq + 1).trim().replace(/^["']|["']$/g, "");
|
|
16
|
+
result[key] = val;
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
function writeEnvFile(path, updates) {
|
|
21
|
+
const existing = existsSync(path) ? readFileSync(path, "utf8") : "";
|
|
22
|
+
const lines = existing.split("\n");
|
|
23
|
+
const touched = /* @__PURE__ */ new Set();
|
|
24
|
+
const updated = lines.map((line) => {
|
|
25
|
+
const eq = line.indexOf("=");
|
|
26
|
+
if (eq < 0) return line;
|
|
27
|
+
const key = line.slice(0, eq).trim();
|
|
28
|
+
if (key in updates) {
|
|
29
|
+
touched.add(key);
|
|
30
|
+
return `${key}=${updates[key]}`;
|
|
31
|
+
}
|
|
32
|
+
return line;
|
|
33
|
+
});
|
|
34
|
+
for (const [key, val] of Object.entries(updates)) {
|
|
35
|
+
if (!touched.has(key)) updated.push(`${key}=${val}`);
|
|
36
|
+
}
|
|
37
|
+
writeFileSync(path, updated.filter((l, i) => l !== "" || i < updated.length - 1).join("\n") + "\n");
|
|
38
|
+
}
|
|
39
|
+
function updateMcpConfig(configPath, serverName, agentToken) {
|
|
40
|
+
if (!existsSync(configPath)) return false;
|
|
41
|
+
try {
|
|
42
|
+
const raw = readFileSync(configPath, "utf8");
|
|
43
|
+
const config = JSON.parse(raw);
|
|
44
|
+
const server = config?.mcpServers?.[serverName];
|
|
45
|
+
if (!server) return false;
|
|
46
|
+
server.env = server.env ?? {};
|
|
47
|
+
server.env.AGENT_TOKEN = agentToken;
|
|
48
|
+
writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
|
|
49
|
+
return true;
|
|
50
|
+
} catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function runSetup() {
|
|
55
|
+
const cwd = process.cwd();
|
|
56
|
+
const envPath = join(cwd, ".env");
|
|
57
|
+
const fileEnv = loadEnvFile(envPath);
|
|
58
|
+
const env = { ...fileEnv, ...process.env };
|
|
59
|
+
const API_URL = env.API_SERVER_URL ?? "http://localhost:3000";
|
|
60
|
+
const EMAIL = env.SETUP_EMAIL ?? env.ADMIN_EMAIL ?? "admin@localhost";
|
|
61
|
+
const PASSWORD = env.SETUP_PASSWORD ?? env.ADMIN_PASSWORD ?? "admin123";
|
|
62
|
+
const NAME = env.SETUP_NAME ?? env.ADMIN_NAME ?? "Admin";
|
|
63
|
+
const AGENT_NAME = env.SETUP_AGENT_NAME ?? env.AGENT_NAME ?? "dev-agent";
|
|
64
|
+
const MCP_NAME = env.MCP_SERVER_NAME ?? "agent-chat";
|
|
65
|
+
console.log(`
|
|
66
|
+
agent-chat setup`);
|
|
67
|
+
console.log(` API server : ${API_URL}`);
|
|
68
|
+
console.log(` Account : ${EMAIL}`);
|
|
69
|
+
console.log(` Agent name : ${AGENT_NAME}`);
|
|
70
|
+
console.log("");
|
|
71
|
+
let res;
|
|
72
|
+
try {
|
|
73
|
+
res = await fetch(`${API_URL}/auth/setup`, {
|
|
74
|
+
method: "POST",
|
|
75
|
+
headers: { "Content-Type": "application/json" },
|
|
76
|
+
body: JSON.stringify({ name: NAME, email: EMAIL, password: PASSWORD, agentName: AGENT_NAME })
|
|
77
|
+
});
|
|
78
|
+
} catch (err) {
|
|
79
|
+
console.error(` \u2717 Could not reach API server at ${API_URL}`);
|
|
80
|
+
console.error(` Make sure the dev server is running: pnpm dev`);
|
|
81
|
+
console.error(` Error: ${err.message}`);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
if (!res.ok) {
|
|
85
|
+
const body = await res.text();
|
|
86
|
+
console.error(` \u2717 Setup failed (${res.status}): ${body}`);
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
const data = await res.json();
|
|
90
|
+
console.log(` \u2713 Account : ${data.entity.name} <${data.entity.email}>`);
|
|
91
|
+
console.log(` \u2713 Agent : ${data.agentEntity.name}`);
|
|
92
|
+
console.log(` \u2713 Token : ${data.agentToken}`);
|
|
93
|
+
console.log("");
|
|
94
|
+
writeEnvFile(envPath, {
|
|
95
|
+
AGENT_TOKEN: data.agentToken,
|
|
96
|
+
BOOTSTRAP_AGENT_TOKEN: data.agentToken,
|
|
97
|
+
API_SERVER_URL: API_URL,
|
|
98
|
+
WS_SERVER_URL: env.WS_SERVER_URL ?? "ws://localhost:3001"
|
|
99
|
+
});
|
|
100
|
+
console.log(` \u2713 Written : ${envPath}`);
|
|
101
|
+
const mcpPaths = [
|
|
102
|
+
join(cwd, ".mcp.json"),
|
|
103
|
+
join(cwd, ".claude", "mcp.json"),
|
|
104
|
+
join(cwd, ".cursor", "mcp.json")
|
|
105
|
+
];
|
|
106
|
+
for (const p of mcpPaths) {
|
|
107
|
+
if (updateMcpConfig(p, MCP_NAME, data.agentToken)) {
|
|
108
|
+
console.log(` \u2713 Updated : ${p}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
console.log("");
|
|
112
|
+
console.log(` Restart the dev server to apply the new token:`);
|
|
113
|
+
console.log(` source .env && pnpm dev`);
|
|
114
|
+
console.log("");
|
|
115
|
+
console.log(` Then start the mention watcher:`);
|
|
116
|
+
console.log(` source .env && WATCH_CHANNELS=random agent-chat-watch -- claude`);
|
|
117
|
+
console.log("");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export {
|
|
121
|
+
runSetup
|
|
122
|
+
};
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli.ts
|
|
4
|
+
var [, , subcommand, ...rest] = process.argv;
|
|
5
|
+
switch (subcommand) {
|
|
6
|
+
case "setup": {
|
|
7
|
+
const { runSetup } = await import("./setup-332LIDBJ.js");
|
|
8
|
+
await runSetup();
|
|
9
|
+
break;
|
|
10
|
+
}
|
|
11
|
+
case "watch": {
|
|
12
|
+
process.argv = [process.argv[0], process.argv[1], ...rest];
|
|
13
|
+
await import("./watch.js");
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
default: {
|
|
17
|
+
process.stderr.write(
|
|
18
|
+
[
|
|
19
|
+
"",
|
|
20
|
+
" Usage:",
|
|
21
|
+
" npx @agent-chat/mention-watcher setup",
|
|
22
|
+
" npx @agent-chat/mention-watcher watch -- claude",
|
|
23
|
+
" npx @agent-chat/mention-watcher watch -- claude --model claude-opus-4-5",
|
|
24
|
+
"",
|
|
25
|
+
" Commands:",
|
|
26
|
+
" setup Register an account + agent and write AGENT_TOKEN to .env",
|
|
27
|
+
" watch Start the mention watcher and spawn the given LLM CLI",
|
|
28
|
+
""
|
|
29
|
+
].join("\n")
|
|
30
|
+
);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
}
|
package/dist/setup.js
CHANGED
|
@@ -1,121 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { join } from "path";
|
|
6
|
-
function loadEnvFile(path) {
|
|
7
|
-
if (!existsSync(path)) return {};
|
|
8
|
-
const result = {};
|
|
9
|
-
for (const line of readFileSync(path, "utf8").split("\n")) {
|
|
10
|
-
const trimmed = line.trim();
|
|
11
|
-
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
12
|
-
const eq = trimmed.indexOf("=");
|
|
13
|
-
if (eq < 0) continue;
|
|
14
|
-
const key = trimmed.slice(0, eq).trim();
|
|
15
|
-
const val = trimmed.slice(eq + 1).trim().replace(/^["']|["']$/g, "");
|
|
16
|
-
result[key] = val;
|
|
17
|
-
}
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
function writeEnvFile(path, updates) {
|
|
21
|
-
const existing = existsSync(path) ? readFileSync(path, "utf8") : "";
|
|
22
|
-
const lines = existing.split("\n");
|
|
23
|
-
const touched = /* @__PURE__ */ new Set();
|
|
24
|
-
const updated = lines.map((line) => {
|
|
25
|
-
const eq = line.indexOf("=");
|
|
26
|
-
if (eq < 0) return line;
|
|
27
|
-
const key = line.slice(0, eq).trim();
|
|
28
|
-
if (key in updates) {
|
|
29
|
-
touched.add(key);
|
|
30
|
-
return `${key}=${updates[key]}`;
|
|
31
|
-
}
|
|
32
|
-
return line;
|
|
33
|
-
});
|
|
34
|
-
for (const [key, val] of Object.entries(updates)) {
|
|
35
|
-
if (!touched.has(key)) updated.push(`${key}=${val}`);
|
|
36
|
-
}
|
|
37
|
-
writeFileSync(path, updated.filter((l, i) => l !== "" || i < updated.length - 1).join("\n") + "\n");
|
|
38
|
-
}
|
|
39
|
-
function updateMcpConfig(configPath, serverName, agentToken) {
|
|
40
|
-
if (!existsSync(configPath)) return false;
|
|
41
|
-
try {
|
|
42
|
-
const raw = readFileSync(configPath, "utf8");
|
|
43
|
-
const config = JSON.parse(raw);
|
|
44
|
-
const server = config?.mcpServers?.[serverName];
|
|
45
|
-
if (!server) return false;
|
|
46
|
-
server.env = server.env ?? {};
|
|
47
|
-
server.env.AGENT_TOKEN = agentToken;
|
|
48
|
-
writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
|
|
49
|
-
return true;
|
|
50
|
-
} catch {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
async function runSetup() {
|
|
55
|
-
const cwd = process.cwd();
|
|
56
|
-
const envPath = join(cwd, ".env");
|
|
57
|
-
const fileEnv = loadEnvFile(envPath);
|
|
58
|
-
const env = { ...fileEnv, ...process.env };
|
|
59
|
-
const API_URL = env.API_SERVER_URL ?? "http://localhost:3000";
|
|
60
|
-
const EMAIL = env.SETUP_EMAIL ?? env.ADMIN_EMAIL ?? "admin@localhost";
|
|
61
|
-
const PASSWORD = env.SETUP_PASSWORD ?? env.ADMIN_PASSWORD ?? "admin123";
|
|
62
|
-
const NAME = env.SETUP_NAME ?? env.ADMIN_NAME ?? "Admin";
|
|
63
|
-
const AGENT_NAME = env.SETUP_AGENT_NAME ?? env.AGENT_NAME ?? "dev-agent";
|
|
64
|
-
const MCP_NAME = env.MCP_SERVER_NAME ?? "agent-chat";
|
|
65
|
-
console.log(`
|
|
66
|
-
agent-chat setup`);
|
|
67
|
-
console.log(` API server : ${API_URL}`);
|
|
68
|
-
console.log(` Account : ${EMAIL}`);
|
|
69
|
-
console.log(` Agent name : ${AGENT_NAME}`);
|
|
70
|
-
console.log("");
|
|
71
|
-
let res;
|
|
72
|
-
try {
|
|
73
|
-
res = await fetch(`${API_URL}/auth/setup`, {
|
|
74
|
-
method: "POST",
|
|
75
|
-
headers: { "Content-Type": "application/json" },
|
|
76
|
-
body: JSON.stringify({ name: NAME, email: EMAIL, password: PASSWORD, agentName: AGENT_NAME })
|
|
77
|
-
});
|
|
78
|
-
} catch (err) {
|
|
79
|
-
console.error(` \u2717 Could not reach API server at ${API_URL}`);
|
|
80
|
-
console.error(` Make sure the dev server is running: pnpm dev`);
|
|
81
|
-
console.error(` Error: ${err.message}`);
|
|
82
|
-
process.exit(1);
|
|
83
|
-
}
|
|
84
|
-
if (!res.ok) {
|
|
85
|
-
const body = await res.text();
|
|
86
|
-
console.error(` \u2717 Setup failed (${res.status}): ${body}`);
|
|
87
|
-
process.exit(1);
|
|
88
|
-
}
|
|
89
|
-
const data = await res.json();
|
|
90
|
-
console.log(` \u2713 Account : ${data.entity.name} <${data.entity.email}>`);
|
|
91
|
-
console.log(` \u2713 Agent : ${data.agentEntity.name}`);
|
|
92
|
-
console.log(` \u2713 Token : ${data.agentToken}`);
|
|
93
|
-
console.log("");
|
|
94
|
-
writeEnvFile(envPath, {
|
|
95
|
-
AGENT_TOKEN: data.agentToken,
|
|
96
|
-
BOOTSTRAP_AGENT_TOKEN: data.agentToken,
|
|
97
|
-
API_SERVER_URL: API_URL,
|
|
98
|
-
WS_SERVER_URL: env.WS_SERVER_URL ?? "ws://localhost:3001"
|
|
99
|
-
});
|
|
100
|
-
console.log(` \u2713 Written : ${envPath}`);
|
|
101
|
-
const mcpPaths = [
|
|
102
|
-
join(cwd, ".mcp.json"),
|
|
103
|
-
join(cwd, ".claude", "mcp.json"),
|
|
104
|
-
join(cwd, ".cursor", "mcp.json")
|
|
105
|
-
];
|
|
106
|
-
for (const p of mcpPaths) {
|
|
107
|
-
if (updateMcpConfig(p, MCP_NAME, data.agentToken)) {
|
|
108
|
-
console.log(` \u2713 Updated : ${p}`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
console.log("");
|
|
112
|
-
console.log(` Restart the dev server to apply the new token:`);
|
|
113
|
-
console.log(` source .env && pnpm dev`);
|
|
114
|
-
console.log("");
|
|
115
|
-
console.log(` Then start the mention watcher:`);
|
|
116
|
-
console.log(` source .env && WATCH_CHANNELS=random agent-chat-watch -- claude`);
|
|
117
|
-
console.log("");
|
|
118
|
-
}
|
|
2
|
+
import {
|
|
3
|
+
runSetup
|
|
4
|
+
} from "./chunk-YNXFY4Q4.js";
|
|
119
5
|
|
|
120
6
|
// src/setup-runner.ts
|
|
121
7
|
runSetup().catch((err) => {
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-chat/mention-watcher",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "PTY wrapper that pushes @mentions from agent-chat into Claude Code (or any LLM CLI)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
+
"agent-chat": "./dist/cli.js",
|
|
7
8
|
"agent-chat-watch": "./dist/watch.js",
|
|
8
9
|
"agent-chat-setup": "./dist/setup.js"
|
|
9
10
|
},
|