@clagentic/console 1.7.1-beta.1 → 1.8.0-beta.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.
Files changed (39) hide show
  1. package/bin/cli.js +198 -2542
  2. package/lib/build-sha.json +2 -2
  3. package/lib/cli/daemon-launch.js +797 -0
  4. package/lib/cli/ipc-subcommands.js +186 -0
  5. package/lib/cli/menus.js +849 -0
  6. package/lib/cli/net-detect.js +209 -0
  7. package/lib/cli/tui.js +589 -0
  8. package/lib/pages.js +13 -17
  9. package/lib/public/css/diagnostics.css +15 -0
  10. package/lib/public/css/overlays.css +19 -0
  11. package/lib/public/index.html +12 -11
  12. package/lib/public/manifest.json +1 -1
  13. package/lib/public/modules/app-connection.js +150 -4
  14. package/lib/public/modules/app-history-replay.js +155 -0
  15. package/lib/public/modules/app-home-hub.js +2 -16
  16. package/lib/public/modules/app-messages.js +1245 -1489
  17. package/lib/public/modules/app-notifications.js +4 -4
  18. package/lib/public/modules/command-palette.js +11 -22
  19. package/lib/public/modules/context-sources.js +1 -6
  20. package/lib/public/modules/filebrowser.js +25 -13
  21. package/lib/public/modules/mcp-ui.js +2 -2
  22. package/lib/public/modules/notifications.js +22 -1
  23. package/lib/public/modules/playbook.js +6 -6
  24. package/lib/public/modules/project-settings.js +5 -13
  25. package/lib/public/modules/qrcode.js +2 -2
  26. package/lib/public/modules/relative-time.js +27 -0
  27. package/lib/public/modules/scheduler-history.js +1 -5
  28. package/lib/public/modules/server-settings.js +28 -15
  29. package/lib/public/modules/sidebar-projects.js +1 -1
  30. package/lib/public/modules/sidebar-sessions.js +1 -15
  31. package/lib/public/modules/sidebar.js +3 -3
  32. package/lib/public/modules/utils.js +1 -0
  33. package/lib/public/sw.js +24 -4
  34. package/lib/server-auth.js +48 -2
  35. package/lib/server-settings.js +70 -4
  36. package/lib/server.js +200 -4
  37. package/lib/smtp.js +6 -6
  38. package/lib/yoke/adapters/codex.js +1 -1
  39. package/package.json +1 -1
@@ -0,0 +1,209 @@
1
+ // lib/cli/net-detect.js
2
+ //
3
+ // Network/cert detection helpers for bin/cli.js: LAN/Tailscale IP discovery,
4
+ // port-availability checks, and mkcert-based TLS cert provisioning.
5
+ // Extracted verbatim from bin/cli.js (lr-4e49 Part 1), no behavior change.
6
+
7
+ var os = require("os");
8
+ var fs = require("fs");
9
+ var path = require("path");
10
+ var net = require("net");
11
+ var execSync = require("child_process").execSync;
12
+ var execFileSync = require("child_process").execFileSync;
13
+
14
+ // --- Network ---
15
+ function getLocalIP() {
16
+ var interfaces = os.networkInterfaces();
17
+
18
+ // Prefer Tailscale IP
19
+ for (var name in interfaces) {
20
+ if (/^(tailscale|utun)/.test(name)) {
21
+ for (var j = 0; j < interfaces[name].length; j++) {
22
+ var addr = interfaces[name][j];
23
+ if (addr.family === "IPv4" && !addr.internal && addr.address.startsWith("100.")) {
24
+ return addr.address;
25
+ }
26
+ }
27
+ }
28
+ }
29
+
30
+ // All interfaces for Tailscale CGNAT range
31
+ for (var addrs of Object.values(interfaces)) {
32
+ for (var k = 0; k < addrs.length; k++) {
33
+ if (addrs[k].family === "IPv4" && !addrs[k].internal && addrs[k].address.startsWith("100.")) {
34
+ return addrs[k].address;
35
+ }
36
+ }
37
+ }
38
+
39
+ // Fall back to LAN IP
40
+ for (var addrs2 of Object.values(interfaces)) {
41
+ for (var m = 0; m < addrs2.length; m++) {
42
+ if (addrs2[m].family === "IPv4" && !addrs2[m].internal) {
43
+ return addrs2[m].address;
44
+ }
45
+ }
46
+ }
47
+
48
+ return "localhost";
49
+ }
50
+
51
+ // --- Certs ---
52
+ function isRoutableIP(addr) {
53
+ if (addr.startsWith("10.")) return true;
54
+ if (addr.startsWith("192.168.")) return true;
55
+ if (addr.startsWith("100.")) {
56
+ var second = parseInt(addr.split(".")[1], 10);
57
+ return second >= 64 && second <= 127; // CGNAT (Tailscale)
58
+ }
59
+ if (addr.startsWith("172.")) {
60
+ var second = parseInt(addr.split(".")[1], 10);
61
+ return second >= 16 && second <= 31;
62
+ }
63
+ return false;
64
+ }
65
+
66
+ function getAllIPs() {
67
+ var ips = [];
68
+ var ifaces = os.networkInterfaces();
69
+ for (var addrs of Object.values(ifaces)) {
70
+ for (var j = 0; j < addrs.length; j++) {
71
+ if (addrs[j].family === "IPv4" && !addrs[j].internal && isRoutableIP(addrs[j].address)) {
72
+ ips.push(addrs[j].address);
73
+ }
74
+ }
75
+ }
76
+ return ips;
77
+ }
78
+
79
+ /**
80
+ * Ensure a TLS cert exists for the given IP, generating one with mkcert if
81
+ * needed. `configDir` is the console config directory (CONFIG_DIR);
82
+ * `forceMkcert` mirrors the CLI --local-cert flag (suppresses the migration
83
+ * notice / mkcertDetected flag downstream).
84
+ */
85
+ function ensureCerts(ip, configDir, forceMkcert) {
86
+ // certs/ now lives under CONFIG_DIR (= ~/.clagentic/console/).
87
+ // Old location was ~/.clagentic/certs/ — migration runs in daemon.js on startup.
88
+ var certDir = path.join(configDir, "certs");
89
+ var keyPath = path.join(certDir, "key.pem");
90
+ var certPath = path.join(certDir, "cert.pem");
91
+
92
+
93
+ var mkcertInstalled = hasMkcert();
94
+
95
+ var caRoot = null;
96
+ if (mkcertInstalled) {
97
+ try {
98
+ caRoot = path.join(
99
+ execSync("mkcert -CAROOT", { encoding: "utf8" }).trim(),
100
+ "rootCA.pem"
101
+ );
102
+ if (!fs.existsSync(caRoot)) caRoot = null;
103
+ } catch (e) {}
104
+ }
105
+
106
+ // Collect all IPv4 addresses (Tailscale + LAN)
107
+ var allIPs = getAllIPs();
108
+
109
+ if (fs.existsSync(keyPath) && fs.existsSync(certPath)) {
110
+ var needRegen = false;
111
+ var isMkcertCert = false;
112
+ try {
113
+ var certText = execFileSync("openssl", ["x509", "-in", certPath, "-text", "-noout"], { encoding: "utf8" });
114
+ // If cert is from an external CA (e.g. Tailscale/Let's Encrypt), never regenerate
115
+ if (certText.indexOf("mkcert") === -1) return { key: keyPath, cert: certPath, caRoot: caRoot };
116
+ isMkcertCert = true;
117
+ for (var i = 0; i < allIPs.length; i++) {
118
+ if (certText.indexOf(allIPs[i]) === -1) {
119
+ needRegen = true;
120
+ break;
121
+ }
122
+ }
123
+ } catch (e) { needRegen = true; }
124
+ // mkcert cert but mkcert uninstalled: CA is gone, cert is untrusted. Skip it.
125
+ if (isMkcertCert && !mkcertInstalled) needRegen = true;
126
+ if (!needRegen) {
127
+ return { key: keyPath, cert: certPath, caRoot: caRoot, mkcertDetected: mkcertInstalled && !forceMkcert };
128
+ }
129
+ }
130
+
131
+ // mkcert installed: generate local cert (legacy behavior)
132
+ if (mkcertInstalled) {
133
+ fs.mkdirSync(certDir, { recursive: true });
134
+
135
+ var domains = ["localhost", "127.0.0.1", "::1"];
136
+ for (var i = 0; i < allIPs.length; i++) {
137
+ if (domains.indexOf(allIPs[i]) === -1) domains.push(allIPs[i]);
138
+ }
139
+
140
+ try {
141
+ var mkcertArgs = ["-key-file", keyPath, "-cert-file", certPath].concat(domains);
142
+ execFileSync("mkcert", mkcertArgs, { stdio: "pipe" });
143
+ } catch (err) {
144
+ // mkcert generation failed
145
+ }
146
+
147
+ if (fs.existsSync(keyPath) && fs.existsSync(certPath)) {
148
+ return { key: keyPath, cert: certPath, caRoot: caRoot, mkcertDetected: !forceMkcert };
149
+ }
150
+ }
151
+
152
+ return null;
153
+ }
154
+
155
+ // --- Port availability ---
156
+
157
+ function isPortFree(p) {
158
+ return new Promise(function (resolve) {
159
+ var srv = net.createServer();
160
+ srv.once("error", function () { resolve(false); });
161
+ srv.once("listening", function () { srv.close(function () { resolve(true); }); });
162
+ srv.listen(p);
163
+ });
164
+ }
165
+
166
+ // --- Detect tools ---
167
+ function getTailscaleIP() {
168
+ var interfaces = os.networkInterfaces();
169
+ for (var name in interfaces) {
170
+ if (/^(tailscale|utun)/.test(name)) {
171
+ for (var i = 0; i < interfaces[name].length; i++) {
172
+ var addr = interfaces[name][i];
173
+ if (addr.family === "IPv4" && !addr.internal && addr.address.startsWith("100.")) {
174
+ return addr.address;
175
+ }
176
+ }
177
+ }
178
+ }
179
+ for (var addrs of Object.values(interfaces)) {
180
+ for (var j = 0; j < addrs.length; j++) {
181
+ if (addrs[j].family === "IPv4" && !addrs[j].internal && addrs[j].address.startsWith("100.")) {
182
+ return addrs[j].address;
183
+ }
184
+ }
185
+ }
186
+ return null;
187
+ }
188
+
189
+ function hasTailscale() {
190
+ return getTailscaleIP() !== null;
191
+ }
192
+
193
+ function hasMkcert() {
194
+ try {
195
+ execSync("mkcert -CAROOT", { stdio: "pipe", encoding: "utf8" });
196
+ return true;
197
+ } catch (e) { return false; }
198
+ }
199
+
200
+ module.exports = {
201
+ getLocalIP: getLocalIP,
202
+ isRoutableIP: isRoutableIP,
203
+ getAllIPs: getAllIPs,
204
+ ensureCerts: ensureCerts,
205
+ isPortFree: isPortFree,
206
+ getTailscaleIP: getTailscaleIP,
207
+ hasTailscale: hasTailscale,
208
+ hasMkcert: hasMkcert,
209
+ };