glassbox 0.7.9 → 0.8.0

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,113 @@
1
+ #!/usr/bin/env node
2
+ #!/usr/bin/env node
3
+
4
+ // src/channel.ts
5
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
6
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
7
+ import { unlinkSync, writeFileSync } from "fs";
8
+ import { createServer } from "http";
9
+ import { join } from "path";
10
+ var dataDir = ".glassbox";
11
+ var args = process.argv.slice(2);
12
+ for (let i = 0; i < args.length; i++) {
13
+ if (args[i] === "--data-dir" && i + 1 < args.length) {
14
+ dataDir = args[i + 1];
15
+ i++;
16
+ }
17
+ }
18
+ var portFile = join(dataDir, "channel-port");
19
+ var mcp = new Server(
20
+ { name: "glassbox-channel", version: "0.1.0" },
21
+ {
22
+ capabilities: {
23
+ experimental: {
24
+ "claude/channel": {}
25
+ }
26
+ },
27
+ instructions: [
28
+ 'Events from the glassbox-channel arrive as <channel source="glassbox-channel">.',
29
+ "When you receive a channel event from glassbox-channel, follow the instructions in the event content.",
30
+ "Typically this means running /glassbox to read and apply the code review feedback.",
31
+ "Do not ask for confirmation \u2014 just execute the requested action.",
32
+ "IMPORTANT: When you finish processing, you MUST run the curl command provided in the event to signal completion."
33
+ ].join(" ")
34
+ }
35
+ );
36
+ await mcp.connect(new StdioServerTransport());
37
+ var httpServer = createServer(async (req, res) => {
38
+ res.setHeader("Access-Control-Allow-Origin", "*");
39
+ res.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
40
+ res.setHeader("Access-Control-Allow-Headers", "Content-Type");
41
+ if (req.method === "OPTIONS") {
42
+ res.writeHead(200);
43
+ res.end();
44
+ return;
45
+ }
46
+ if (req.method === "GET" && req.url === "/health") {
47
+ res.writeHead(200, { "Content-Type": "application/json" });
48
+ res.end(JSON.stringify({ ok: true }));
49
+ return;
50
+ }
51
+ if (req.method === "POST" && req.url === "/trigger") {
52
+ let body = "";
53
+ let bodySize = 0;
54
+ for await (const chunk of req) {
55
+ bodySize += chunk.length;
56
+ if (bodySize > 1048576) {
57
+ res.writeHead(413);
58
+ res.end("Payload too large");
59
+ return;
60
+ }
61
+ body += String(chunk);
62
+ }
63
+ try {
64
+ await mcp.notification({
65
+ method: "notifications/claude/channel",
66
+ params: {
67
+ content: body || "Read .glassbox/latest-review.md and apply the feedback.",
68
+ meta: { type: "review-feedback" }
69
+ }
70
+ });
71
+ res.writeHead(200, { "Content-Type": "application/json" });
72
+ res.end(JSON.stringify({ ok: true }));
73
+ } catch (err) {
74
+ res.writeHead(500, { "Content-Type": "application/json" });
75
+ res.end(JSON.stringify({ error: String(err) }));
76
+ }
77
+ return;
78
+ }
79
+ res.writeHead(404);
80
+ res.end("not found");
81
+ });
82
+ httpServer.listen(0, "127.0.0.1", () => {
83
+ const addr = httpServer.address();
84
+ if (addr !== null && typeof addr !== "string") {
85
+ const port = addr.port;
86
+ try {
87
+ writeFileSync(portFile, String(port), "utf-8");
88
+ } catch {
89
+ }
90
+ process.stderr.write(`glassbox-channel listening on port ${port}
91
+ `);
92
+ }
93
+ });
94
+ function cleanup() {
95
+ try {
96
+ unlinkSync(portFile);
97
+ } catch {
98
+ }
99
+ process.exit(0);
100
+ }
101
+ process.on("SIGTERM", () => {
102
+ cleanup();
103
+ });
104
+ process.on("SIGINT", () => {
105
+ cleanup();
106
+ });
107
+ process.on("exit", () => {
108
+ try {
109
+ unlinkSync(portFile);
110
+ } catch {
111
+ }
112
+ });
113
+ //# sourceMappingURL=channel.js.map