contextguard 0.2.0 → 0.2.1

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/agent.js CHANGED
@@ -309,6 +309,13 @@ const createAgent = (serverCommand, policyConfig = {}, supabaseConfig) => {
309
309
  }
310
310
  // Update agent status to online
311
311
  await supabaseClient.updateAgentStatus(supabaseConfig.agentId, "online");
312
+ // Send periodic heartbeats every 30 seconds
313
+ const heartbeatInterval = setInterval(() => {
314
+ supabaseClient
315
+ .updateAgentStatus(supabaseConfig.agentId, "online")
316
+ .catch(() => { });
317
+ }, 30000);
318
+ heartbeatInterval.unref();
312
319
  }
313
320
  state.process = (0, child_process_1.spawn)(serverCommand[0], serverCommand.slice(1), {
314
321
  stdio: ["pipe", "pipe", "pipe"],
package/dist/cli.js CHANGED
@@ -42,6 +42,7 @@ var __importStar = (this && this.__importStar) || (function () {
42
42
  Object.defineProperty(exports, "__esModule", { value: true });
43
43
  exports.main = main;
44
44
  const fs = __importStar(require("fs"));
45
+ const os = __importStar(require("os"));
45
46
  const agent_1 = require("./agent");
46
47
  const sse_proxy_1 = require("./sse-proxy");
47
48
  const policy_1 = require("./policy");
@@ -253,6 +254,37 @@ async function main() {
253
254
  if (supabaseConfig) {
254
255
  console.log(`✓ Supabase integration enabled (Agent ID: ${supabaseConfig.agentId})`);
255
256
  }
257
+ // Start REST-based heartbeat if CONTEXTGUARD_API_KEY is set
258
+ const cgApiKey = process.env.CONTEXTGUARD_API_KEY;
259
+ if (cgApiKey) {
260
+ const baseUrl = process.env.CONTEXTGUARD_BASE_URL || "https://contextguard.dev";
261
+ const agentId = process.env.AGENT_ID || `${os.hostname()}-${process.pid}`;
262
+ const sendHeartbeat = async () => {
263
+ try {
264
+ await fetch(`${baseUrl}/api/agents/heartbeat`, {
265
+ method: "POST",
266
+ headers: {
267
+ "Content-Type": "application/json",
268
+ Authorization: `Bearer ${cgApiKey}`,
269
+ },
270
+ body: JSON.stringify({
271
+ agent_id: agentId,
272
+ name: agentId,
273
+ hostname: os.hostname(),
274
+ version: process.env.npm_package_version || "unknown",
275
+ mcp_server_command: serverCommand,
276
+ }),
277
+ });
278
+ }
279
+ catch {
280
+ // silently ignore — don't break the agent if dashboard is unreachable
281
+ }
282
+ };
283
+ sendHeartbeat();
284
+ const interval = setInterval(sendHeartbeat, 30000);
285
+ interval.unref();
286
+ console.log(`✓ ContextGuard monitoring enabled (Agent ID: ${agentId})`);
287
+ }
256
288
  // Create and start agent
257
289
  const agent = (0, agent_1.createAgent)(parseCommand(serverCommand), config, supabaseConfig);
258
290
  await agent.start();
package/dist/init.d.ts CHANGED
@@ -4,4 +4,4 @@
4
4
  * contextguard init — automatically patch claude_desktop_config.json
5
5
  * so that every MCP server is wrapped with ContextGuard.
6
6
  */
7
- export declare function runInit(argv: string[]): Promise<void>;
7
+ export declare function runInit(argv: string[]): void;
package/dist/init.js CHANGED
@@ -68,9 +68,13 @@ function findConfigPath() {
68
68
  }
69
69
  // ── Wrapping helpers ─────────────────────────────────────────────────────────
70
70
  function isAlreadyWrapped(server) {
71
- if (server.command === "contextguard")
71
+ if (server.command === "npx" && server.args?.[1] === "contextguard") {
72
72
  return true;
73
- return (server.args ?? []).includes("contextguard");
73
+ }
74
+ if (server.command === "contextguard") {
75
+ return true;
76
+ }
77
+ return false;
74
78
  }
75
79
  /**
76
80
  * Wrap an MCP server entry:
@@ -106,7 +110,7 @@ function parseInitArgs(argv) {
106
110
  return { apiKey, configPath, dryRun };
107
111
  }
108
112
  // ── Main ─────────────────────────────────────────────────────────────────────
109
- async function runInit(argv) {
113
+ function runInit(argv) {
110
114
  const { apiKey, configPath: customPath, dryRun } = parseInitArgs(argv);
111
115
  if (!apiKey) {
112
116
  console.error("\n❌ Missing required argument: --api-key <key>\n" +
@@ -126,8 +130,9 @@ async function runInit(argv) {
126
130
  try {
127
131
  config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
128
132
  }
129
- catch {
130
- console.error(`\n❌ Failed to parse config: ${configPath}\n`);
133
+ catch (err) {
134
+ console.error(`\n❌ Failed to parse config: ${configPath}`);
135
+ console.error(` Error: ${err instanceof Error ? err.message : String(err)}\n`);
131
136
  process.exit(1);
132
137
  }
133
138
  const servers = { ...(config.mcpServers ?? {}) };
@@ -76,7 +76,7 @@ const createSupabaseClient = (config) => {
76
76
  const statusData = {
77
77
  agent_id: agentId,
78
78
  status: status,
79
- last_seen: new Date().toISOString(),
79
+ last_heartbeat: new Date().toISOString(),
80
80
  };
81
81
  const { error } = await supabase
82
82
  .from("agents")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contextguard",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Security monitoring wrapper for MCP servers with enterprise features",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",