@solongate/proxy 0.59.5 → 0.61.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.
- package/dist/api-client/agents.d.ts +10 -0
- package/dist/api-client/audit.d.ts +22 -0
- package/dist/api-client/client.d.ts +39 -0
- package/dist/api-client/index.d.ts +18 -0
- package/dist/api-client/policies.d.ts +82 -0
- package/dist/api-client/settings.d.ts +22 -0
- package/dist/api-client/stats.d.ts +9 -0
- package/dist/api-client/types.d.ts +224 -0
- package/dist/commands/agents.d.ts +4 -0
- package/dist/commands/args.d.ts +15 -0
- package/dist/commands/audit.d.ts +1 -0
- package/dist/commands/dlp.d.ts +1 -0
- package/dist/commands/format.d.ts +22 -0
- package/dist/commands/index.d.ts +7 -0
- package/dist/commands/index.js +938 -0
- package/dist/commands/policy.d.ts +1 -0
- package/dist/commands/ratelimit.d.ts +1 -0
- package/dist/commands/stats.d.ts +1 -0
- package/dist/index.js +2156 -284
- package/dist/tui/App.d.ts +1 -0
- package/dist/tui/components.d.ts +40 -0
- package/dist/tui/hooks.d.ts +13 -0
- package/dist/tui/index.d.ts +1 -0
- package/dist/tui/index.js +999 -0
- package/dist/tui/panels/Agents.d.ts +3 -0
- package/dist/tui/panels/Audit.d.ts +4 -0
- package/dist/tui/panels/Dlp.d.ts +4 -0
- package/dist/tui/panels/Policies.d.ts +4 -0
- package/dist/tui/panels/RateLimit.d.ts +4 -0
- package/dist/tui/panels/Stats.d.ts +3 -0
- package/dist/tui/theme.d.ts +16 -0
- package/package.json +7 -2
|
@@ -0,0 +1,999 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/tui/index.tsx
|
|
8
|
+
import { render } from "ink";
|
|
9
|
+
|
|
10
|
+
// src/tui/App.tsx
|
|
11
|
+
import { Box as Box8, Text as Text8, useApp, useInput as useInput5 } from "ink";
|
|
12
|
+
import { useState as useState6 } from "react";
|
|
13
|
+
|
|
14
|
+
// src/cli-utils.ts
|
|
15
|
+
var c = {
|
|
16
|
+
reset: "\x1B[0m",
|
|
17
|
+
bold: "\x1B[1m",
|
|
18
|
+
dim: "\x1B[2m",
|
|
19
|
+
italic: "\x1B[3m",
|
|
20
|
+
white: "\x1B[97m",
|
|
21
|
+
gray: "\x1B[90m",
|
|
22
|
+
blue1: "\x1B[38;2;20;50;160m",
|
|
23
|
+
blue2: "\x1B[38;2;40;80;190m",
|
|
24
|
+
blue3: "\x1B[38;2;60;110;215m",
|
|
25
|
+
blue4: "\x1B[38;2;90;140;230m",
|
|
26
|
+
blue5: "\x1B[38;2;130;170;240m",
|
|
27
|
+
blue6: "\x1B[38;2;170;200;250m",
|
|
28
|
+
green: "\x1B[38;2;80;200;120m",
|
|
29
|
+
red: "\x1B[38;2;220;80;80m",
|
|
30
|
+
cyan: "\x1B[38;2;100;200;220m",
|
|
31
|
+
yellow: "\x1B[38;2;220;200;80m",
|
|
32
|
+
bgBlue: "\x1B[48;2;20;50;160m"
|
|
33
|
+
};
|
|
34
|
+
var BANNER_FULL = [
|
|
35
|
+
" \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557",
|
|
36
|
+
" \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D",
|
|
37
|
+
" \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2557 ",
|
|
38
|
+
" \u255A\u2550\u2550\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u255D ",
|
|
39
|
+
" \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557",
|
|
40
|
+
" \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D"
|
|
41
|
+
];
|
|
42
|
+
var BANNER_COLORS = [c.blue1, c.blue2, c.blue3, c.blue4, c.blue5, c.blue6];
|
|
43
|
+
|
|
44
|
+
// src/tui/components.tsx
|
|
45
|
+
import { Box, Text } from "ink";
|
|
46
|
+
|
|
47
|
+
// src/tui/theme.ts
|
|
48
|
+
var theme = {
|
|
49
|
+
accent: "cyan",
|
|
50
|
+
accentBright: "#5a8ce6",
|
|
51
|
+
ok: "green",
|
|
52
|
+
warn: "yellow",
|
|
53
|
+
bad: "red",
|
|
54
|
+
dim: "gray"
|
|
55
|
+
};
|
|
56
|
+
function decisionColor(decision) {
|
|
57
|
+
const d = (decision || "").toUpperCase();
|
|
58
|
+
if (d === "ALLOW") return theme.ok;
|
|
59
|
+
if (d === "DENY" || d === "DENIED") return theme.bad;
|
|
60
|
+
return theme.dim;
|
|
61
|
+
}
|
|
62
|
+
function modeColor(m) {
|
|
63
|
+
if (m === "block" || m === "active" || m === "on") return theme.ok;
|
|
64
|
+
if (m === "detect" || m === "idle") return theme.warn;
|
|
65
|
+
return theme.dim;
|
|
66
|
+
}
|
|
67
|
+
var BLOCKS = ["\u2581", "\u2582", "\u2583", "\u2584", "\u2585", "\u2586", "\u2587", "\u2588"];
|
|
68
|
+
function sparkline(values, width) {
|
|
69
|
+
let v = values;
|
|
70
|
+
if (width && v.length > width) v = v.slice(v.length - width);
|
|
71
|
+
if (v.length === 0) return "";
|
|
72
|
+
const max = Math.max(...v, 0);
|
|
73
|
+
if (max === 0) return BLOCKS[0].repeat(v.length);
|
|
74
|
+
return v.map((n) => BLOCKS[Math.min(BLOCKS.length - 1, Math.round(n / max * (BLOCKS.length - 1)))]).join("");
|
|
75
|
+
}
|
|
76
|
+
function truncate(s, n) {
|
|
77
|
+
if (!s) return "";
|
|
78
|
+
return s.length <= n ? s : s.slice(0, Math.max(0, n - 1)) + "\u2026";
|
|
79
|
+
}
|
|
80
|
+
function ago(ts) {
|
|
81
|
+
const t = typeof ts === "number" ? ts : Date.parse(ts);
|
|
82
|
+
if (Number.isNaN(t)) return String(ts ?? "");
|
|
83
|
+
const s = Math.max(0, (Date.now() - t) / 1e3);
|
|
84
|
+
if (s < 60) return `${Math.floor(s)}s`;
|
|
85
|
+
if (s < 3600) return `${Math.floor(s / 60)}m`;
|
|
86
|
+
if (s < 86400) return `${Math.floor(s / 3600)}h`;
|
|
87
|
+
return `${Math.floor(s / 86400)}d`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/tui/components.tsx
|
|
91
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
92
|
+
function DataView({
|
|
93
|
+
loading,
|
|
94
|
+
error,
|
|
95
|
+
empty,
|
|
96
|
+
emptyText,
|
|
97
|
+
children
|
|
98
|
+
}) {
|
|
99
|
+
if (error) return /* @__PURE__ */ jsxs(Text, { color: theme.bad, children: [
|
|
100
|
+
"\u2717 ",
|
|
101
|
+
error
|
|
102
|
+
] });
|
|
103
|
+
if (loading) return /* @__PURE__ */ jsx(Text, { color: theme.dim, children: "Loading\u2026" });
|
|
104
|
+
if (empty) return /* @__PURE__ */ jsx(Text, { color: theme.dim, children: emptyText ?? "No data." });
|
|
105
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
106
|
+
}
|
|
107
|
+
function Table({ columns, rows }) {
|
|
108
|
+
const fit = (s, w) => {
|
|
109
|
+
const v = s ?? "";
|
|
110
|
+
if (v.length > w) return v.slice(0, Math.max(0, w - 1)) + "\u2026";
|
|
111
|
+
return v.padEnd(w);
|
|
112
|
+
};
|
|
113
|
+
return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
|
|
114
|
+
/* @__PURE__ */ jsx(Box, { children: columns.map((c2, i) => /* @__PURE__ */ jsx(Text, { color: theme.dim, children: fit(c2.header, c2.width) + " " }, i)) }),
|
|
115
|
+
rows.map((row, ri) => /* @__PURE__ */ jsx(Box, { children: row.map((cell, ci) => /* @__PURE__ */ jsx(Text, { color: cell.color, dimColor: cell.dim, bold: cell.bold, children: fit(cell.value, columns[ci]?.width ?? 10) + " " }, ci)) }, ri))
|
|
116
|
+
] });
|
|
117
|
+
}
|
|
118
|
+
function KeyHints({ hints }) {
|
|
119
|
+
return /* @__PURE__ */ jsx(Box, { children: hints.map(([key, label], i) => /* @__PURE__ */ jsxs(Text, { color: theme.dim, children: [
|
|
120
|
+
/* @__PURE__ */ jsx(Text, { color: theme.accent, children: key }),
|
|
121
|
+
" ",
|
|
122
|
+
label,
|
|
123
|
+
i < hints.length - 1 ? " " : ""
|
|
124
|
+
] }, i)) });
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// src/tui/panels/Policies.tsx
|
|
128
|
+
import { Box as Box2, Text as Text2, useInput } from "ink";
|
|
129
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
130
|
+
|
|
131
|
+
// src/api-client/client.ts
|
|
132
|
+
import { readFileSync, existsSync } from "fs";
|
|
133
|
+
import { resolve, join } from "path";
|
|
134
|
+
import { homedir } from "os";
|
|
135
|
+
var DEFAULT_API_URL = "https://api.solongate.com";
|
|
136
|
+
var ApiError = class extends Error {
|
|
137
|
+
status;
|
|
138
|
+
code;
|
|
139
|
+
constructor(status, code, message) {
|
|
140
|
+
super(message);
|
|
141
|
+
this.name = "ApiError";
|
|
142
|
+
this.status = status;
|
|
143
|
+
this.code = code;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
var NotAuthenticatedError = class extends Error {
|
|
147
|
+
constructor() {
|
|
148
|
+
super("Not logged in. Run `solongate login` first.");
|
|
149
|
+
this.name = "NotAuthenticatedError";
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
function loginCredentialFile() {
|
|
153
|
+
try {
|
|
154
|
+
const p = join(homedir(), ".solongate", "cloud-guard.json");
|
|
155
|
+
if (!existsSync(p)) return {};
|
|
156
|
+
const c2 = JSON.parse(readFileSync(p, "utf-8"));
|
|
157
|
+
return c2 && typeof c2 === "object" ? c2 : {};
|
|
158
|
+
} catch {
|
|
159
|
+
return {};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function dotenvApiKey() {
|
|
163
|
+
try {
|
|
164
|
+
const envPath = resolve(".env");
|
|
165
|
+
if (!existsSync(envPath)) return void 0;
|
|
166
|
+
for (const line of readFileSync(envPath, "utf-8").split("\n")) {
|
|
167
|
+
const trimmed = line.trim();
|
|
168
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
169
|
+
const eq = trimmed.indexOf("=");
|
|
170
|
+
if (eq === -1) continue;
|
|
171
|
+
const key = trimmed.slice(0, eq).trim();
|
|
172
|
+
if (key !== "SOLONGATE_API_KEY") continue;
|
|
173
|
+
return trimmed.slice(eq + 1).trim().replace(/^["']|["']$/g, "");
|
|
174
|
+
}
|
|
175
|
+
} catch {
|
|
176
|
+
}
|
|
177
|
+
return void 0;
|
|
178
|
+
}
|
|
179
|
+
var cached = null;
|
|
180
|
+
function isAuthenticated() {
|
|
181
|
+
try {
|
|
182
|
+
resolveCredentials();
|
|
183
|
+
return true;
|
|
184
|
+
} catch {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function resolveCredentials(apiUrlOverride) {
|
|
189
|
+
if (cached && !apiUrlOverride) return cached;
|
|
190
|
+
const file = loginCredentialFile();
|
|
191
|
+
const apiKey = process.env["SOLONGATE_API_KEY"] || file.apiKey || dotenvApiKey();
|
|
192
|
+
if (!apiKey) throw new NotAuthenticatedError();
|
|
193
|
+
const apiUrl = apiUrlOverride || process.env["SOLONGATE_API_URL"] || file.apiUrl || DEFAULT_API_URL;
|
|
194
|
+
const creds = { apiKey, apiUrl: apiUrl.replace(/\/$/, "") };
|
|
195
|
+
if (!apiUrlOverride) cached = creds;
|
|
196
|
+
return creds;
|
|
197
|
+
}
|
|
198
|
+
function buildUrl(base, path, query) {
|
|
199
|
+
const url = new URL(`${base}/api/v1${path}`);
|
|
200
|
+
if (query) {
|
|
201
|
+
for (const [k, v] of Object.entries(query)) {
|
|
202
|
+
if (v === void 0) continue;
|
|
203
|
+
url.searchParams.set(k, String(v));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return url.toString();
|
|
207
|
+
}
|
|
208
|
+
async function request(method, path, opts = {}) {
|
|
209
|
+
const creds = resolveCredentials(opts.apiUrl);
|
|
210
|
+
const url = buildUrl(creds.apiUrl, path, opts.query);
|
|
211
|
+
const headers = {
|
|
212
|
+
Authorization: `Bearer ${creds.apiKey}`
|
|
213
|
+
};
|
|
214
|
+
let bodyInit;
|
|
215
|
+
if (opts.body !== void 0) {
|
|
216
|
+
headers["Content-Type"] = "application/json";
|
|
217
|
+
bodyInit = JSON.stringify(opts.body);
|
|
218
|
+
}
|
|
219
|
+
let res;
|
|
220
|
+
try {
|
|
221
|
+
res = await fetch(url, {
|
|
222
|
+
method,
|
|
223
|
+
headers,
|
|
224
|
+
body: bodyInit,
|
|
225
|
+
signal: AbortSignal.timeout(opts.timeoutMs ?? 15e3)
|
|
226
|
+
});
|
|
227
|
+
} catch (err) {
|
|
228
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
229
|
+
throw new ApiError(0, "NETWORK_ERROR", `Cannot reach SolonGate API: ${msg}`);
|
|
230
|
+
}
|
|
231
|
+
const text = await res.text().catch(() => "");
|
|
232
|
+
let json = void 0;
|
|
233
|
+
if (text) {
|
|
234
|
+
try {
|
|
235
|
+
json = JSON.parse(text);
|
|
236
|
+
} catch {
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (!res.ok) {
|
|
240
|
+
const envelope = json?.error;
|
|
241
|
+
if (envelope && typeof envelope === "object") {
|
|
242
|
+
throw new ApiError(res.status, envelope.code || "ERROR", envelope.message || res.statusText);
|
|
243
|
+
}
|
|
244
|
+
if (typeof envelope === "string") {
|
|
245
|
+
throw new ApiError(res.status, "ERROR", envelope);
|
|
246
|
+
}
|
|
247
|
+
if (res.status === 401) throw new ApiError(401, "AUTHENTICATION_ERROR", "Invalid API key. Run `solongate login`.");
|
|
248
|
+
if (res.status === 429) throw new ApiError(429, "RATE_LIMITED", "Rate limited by the API. Slow down and retry.");
|
|
249
|
+
throw new ApiError(res.status, "ERROR", text || res.statusText || `HTTP ${res.status}`);
|
|
250
|
+
}
|
|
251
|
+
return json;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// src/api-client/policies.ts
|
|
255
|
+
var policies_exports = {};
|
|
256
|
+
__export(policies_exports, {
|
|
257
|
+
active: () => active,
|
|
258
|
+
addRule: () => addRule,
|
|
259
|
+
create: () => create,
|
|
260
|
+
dryRun: () => dryRun,
|
|
261
|
+
get: () => get,
|
|
262
|
+
list: () => list,
|
|
263
|
+
remove: () => remove,
|
|
264
|
+
revokeRule: () => revokeRule,
|
|
265
|
+
rollback: () => rollback,
|
|
266
|
+
setActive: () => setActive,
|
|
267
|
+
update: () => update,
|
|
268
|
+
versions: () => versions
|
|
269
|
+
});
|
|
270
|
+
function list() {
|
|
271
|
+
return request("GET", "/policies");
|
|
272
|
+
}
|
|
273
|
+
function get(id, version) {
|
|
274
|
+
return request("GET", `/policies/${encodeURIComponent(id)}`, {
|
|
275
|
+
query: version !== void 0 ? { version } : void 0
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
function create(policy) {
|
|
279
|
+
return request("POST", "/policies", { body: policy });
|
|
280
|
+
}
|
|
281
|
+
function update(id, policy) {
|
|
282
|
+
return request("PUT", `/policies/${encodeURIComponent(id)}`, { body: policy });
|
|
283
|
+
}
|
|
284
|
+
function remove(id) {
|
|
285
|
+
return request("DELETE", `/policies/${encodeURIComponent(id)}`);
|
|
286
|
+
}
|
|
287
|
+
function addRule(id, spec) {
|
|
288
|
+
return request("POST", `/policies/${encodeURIComponent(id)}/rules`, { body: spec });
|
|
289
|
+
}
|
|
290
|
+
function revokeRule(id, ruleId) {
|
|
291
|
+
return request("DELETE", `/policies/${encodeURIComponent(id)}/rules/${encodeURIComponent(ruleId)}`);
|
|
292
|
+
}
|
|
293
|
+
function versions(id, opts = {}) {
|
|
294
|
+
return request("GET", `/policies/${encodeURIComponent(id)}/versions`, { query: opts });
|
|
295
|
+
}
|
|
296
|
+
function rollback(id, version) {
|
|
297
|
+
return request("POST", `/policies/${encodeURIComponent(id)}/rollback`, { body: { version } });
|
|
298
|
+
}
|
|
299
|
+
function active(agentId) {
|
|
300
|
+
return request("GET", "/policies/active", { query: agentId ? { agent_id: agentId } : void 0 });
|
|
301
|
+
}
|
|
302
|
+
function setActive(policyId) {
|
|
303
|
+
return request("POST", "/policies/active", { body: { policyId: policyId ?? "" } });
|
|
304
|
+
}
|
|
305
|
+
function dryRun(body) {
|
|
306
|
+
return request("POST", "/policies/dry-run", { body });
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// src/api-client/settings.ts
|
|
310
|
+
var settings_exports = {};
|
|
311
|
+
__export(settings_exports, {
|
|
312
|
+
clearRateLimitHistory: () => clearRateLimitHistory,
|
|
313
|
+
getGuardStatus: () => getGuardStatus,
|
|
314
|
+
getRateLimitHistory: () => getRateLimitHistory,
|
|
315
|
+
getSecurityLayers: () => getSecurityLayers,
|
|
316
|
+
setSecurityLayers: () => setSecurityLayers
|
|
317
|
+
});
|
|
318
|
+
function getSecurityLayers() {
|
|
319
|
+
return request("GET", "/settings/security-layers");
|
|
320
|
+
}
|
|
321
|
+
function setSecurityLayers(layers) {
|
|
322
|
+
return request("PUT", "/settings/security-layers", { body: { layers } });
|
|
323
|
+
}
|
|
324
|
+
function getRateLimitHistory() {
|
|
325
|
+
return request("GET", "/settings/rate-limit-history");
|
|
326
|
+
}
|
|
327
|
+
function clearRateLimitHistory() {
|
|
328
|
+
return request("DELETE", "/settings/rate-limit-history", { query: { all: 1 } });
|
|
329
|
+
}
|
|
330
|
+
function getGuardStatus() {
|
|
331
|
+
return request("GET", "/settings/guard-status");
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// src/api-client/stats.ts
|
|
335
|
+
var stats_exports = {};
|
|
336
|
+
__export(stats_exports, {
|
|
337
|
+
drift: () => drift,
|
|
338
|
+
get: () => get2,
|
|
339
|
+
securityInsights: () => securityInsights,
|
|
340
|
+
timeseries: () => timeseries
|
|
341
|
+
});
|
|
342
|
+
function get2() {
|
|
343
|
+
return request("GET", "/stats");
|
|
344
|
+
}
|
|
345
|
+
function timeseries(opts = {}) {
|
|
346
|
+
return request("GET", "/stats/timeseries", { query: opts });
|
|
347
|
+
}
|
|
348
|
+
function drift(days) {
|
|
349
|
+
return request("GET", "/stats/drift", { query: days !== void 0 ? { days } : void 0 });
|
|
350
|
+
}
|
|
351
|
+
function securityInsights(days) {
|
|
352
|
+
return request("GET", "/stats/security-insights", { query: days !== void 0 ? { days } : void 0 });
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// src/api-client/audit.ts
|
|
356
|
+
var audit_exports = {};
|
|
357
|
+
__export(audit_exports, {
|
|
358
|
+
list: () => list2,
|
|
359
|
+
whitelist: () => whitelist
|
|
360
|
+
});
|
|
361
|
+
function list2(query = {}) {
|
|
362
|
+
return request("GET", "/audit-logs", { query });
|
|
363
|
+
}
|
|
364
|
+
function whitelist(id, scope = "exact") {
|
|
365
|
+
return request("POST", `/audit-logs/${encodeURIComponent(id)}/whitelist`, { body: { scope } });
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// src/api-client/agents.ts
|
|
369
|
+
var agents_exports = {};
|
|
370
|
+
__export(agents_exports, {
|
|
371
|
+
anomalies: () => anomalies,
|
|
372
|
+
get: () => get3,
|
|
373
|
+
live: () => live
|
|
374
|
+
});
|
|
375
|
+
function live(opts = {}) {
|
|
376
|
+
return request("GET", "/agents/live", {
|
|
377
|
+
query: { limit: opts.limit, include_deactivated: opts.includeDeactivated ? 1 : void 0 }
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
function get3(id, scan = false) {
|
|
381
|
+
return request("GET", `/agents/${encodeURIComponent(id)}`, { query: scan ? { scan: 1 } : void 0 });
|
|
382
|
+
}
|
|
383
|
+
function anomalies(id, limit) {
|
|
384
|
+
return request("GET", `/agents/${encodeURIComponent(id)}/anomalies`, {
|
|
385
|
+
query: limit !== void 0 ? { limit } : void 0
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// src/api-client/index.ts
|
|
390
|
+
var api = { policies: policies_exports, settings: settings_exports, stats: stats_exports, audit: audit_exports, agents: agents_exports };
|
|
391
|
+
|
|
392
|
+
// src/tui/hooks.ts
|
|
393
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
394
|
+
function useLoader(fn, deps = []) {
|
|
395
|
+
const [data, setData] = useState(null);
|
|
396
|
+
const [error, setError] = useState(null);
|
|
397
|
+
const [loading, setLoading] = useState(true);
|
|
398
|
+
const [nonce, setNonce] = useState(0);
|
|
399
|
+
const alive = useRef(true);
|
|
400
|
+
const fnRef = useRef(fn);
|
|
401
|
+
fnRef.current = fn;
|
|
402
|
+
useEffect(() => {
|
|
403
|
+
alive.current = true;
|
|
404
|
+
return () => {
|
|
405
|
+
alive.current = false;
|
|
406
|
+
};
|
|
407
|
+
}, []);
|
|
408
|
+
useEffect(() => {
|
|
409
|
+
setLoading(true);
|
|
410
|
+
fnRef.current().then((d) => {
|
|
411
|
+
if (!alive.current) return;
|
|
412
|
+
setData(d);
|
|
413
|
+
setError(null);
|
|
414
|
+
}).catch((e) => {
|
|
415
|
+
if (!alive.current) return;
|
|
416
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
417
|
+
}).finally(() => {
|
|
418
|
+
if (alive.current) setLoading(false);
|
|
419
|
+
});
|
|
420
|
+
}, [nonce, ...deps]);
|
|
421
|
+
const reload = useCallback(() => setNonce((n) => n + 1), []);
|
|
422
|
+
return { data, error, loading, reload };
|
|
423
|
+
}
|
|
424
|
+
function usePoll(reload, intervalMs, enabled = true) {
|
|
425
|
+
useEffect(() => {
|
|
426
|
+
if (!enabled) return;
|
|
427
|
+
const t = setInterval(reload, intervalMs);
|
|
428
|
+
return () => clearInterval(t);
|
|
429
|
+
}, [reload, intervalMs, enabled]);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// src/tui/panels/Policies.tsx
|
|
433
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
434
|
+
function PoliciesPanel({ focused }) {
|
|
435
|
+
const list3 = useLoader(() => api.policies.list());
|
|
436
|
+
const policies = list3.data?.policies ?? [];
|
|
437
|
+
const [view, setView] = useState2("list");
|
|
438
|
+
const [pi, setPi] = useState2(0);
|
|
439
|
+
const [ri, setRi] = useState2(0);
|
|
440
|
+
const [rules, setRules] = useState2(null);
|
|
441
|
+
const [mode, setMode] = useState2("denylist");
|
|
442
|
+
const [status, setStatus] = useState2(null);
|
|
443
|
+
const selected = policies[Math.min(pi, Math.max(0, policies.length - 1))];
|
|
444
|
+
const detail = useLoader(() => selected ? api.policies.get(selected.id) : Promise.resolve(null), [selected?.id]);
|
|
445
|
+
useEffect2(() => {
|
|
446
|
+
if (detail.data) {
|
|
447
|
+
setRules(detail.data.rules);
|
|
448
|
+
setMode(detail.data.mode ?? "denylist");
|
|
449
|
+
setRi(0);
|
|
450
|
+
}
|
|
451
|
+
}, [detail.data]);
|
|
452
|
+
const persist = async (nextRules, nextMode) => {
|
|
453
|
+
if (!detail.data || !selected) return;
|
|
454
|
+
setStatus("Saving\u2026");
|
|
455
|
+
try {
|
|
456
|
+
const res = await api.policies.update(selected.id, {
|
|
457
|
+
id: selected.id,
|
|
458
|
+
name: detail.data.name,
|
|
459
|
+
description: detail.data.description,
|
|
460
|
+
mode: nextMode,
|
|
461
|
+
agents: detail.data.agents,
|
|
462
|
+
rules: nextRules
|
|
463
|
+
});
|
|
464
|
+
setRules(res.rules);
|
|
465
|
+
setStatus("\u2713 Saved v" + res._version);
|
|
466
|
+
list3.reload();
|
|
467
|
+
} catch (e) {
|
|
468
|
+
setStatus("\u2717 " + (e instanceof Error ? e.message : String(e)));
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
useInput(
|
|
472
|
+
(input, key) => {
|
|
473
|
+
if (view === "list") {
|
|
474
|
+
if (key.upArrow) setPi((n) => Math.max(0, n - 1));
|
|
475
|
+
else if (key.downArrow) setPi((n) => Math.min(policies.length - 1, n + 1));
|
|
476
|
+
else if (key.return || key.rightArrow) {
|
|
477
|
+
setStatus(null);
|
|
478
|
+
setView("detail");
|
|
479
|
+
}
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
const rs2 = rules ?? [];
|
|
483
|
+
if (key.leftArrow) {
|
|
484
|
+
setView("list");
|
|
485
|
+
setStatus(null);
|
|
486
|
+
} else if (key.upArrow) setRi((n) => Math.max(0, n - 1));
|
|
487
|
+
else if (key.downArrow) setRi((n) => Math.min(rs2.length - 1, n + 1));
|
|
488
|
+
else if (input === " " || input === "e") {
|
|
489
|
+
if (!rs2[ri]) return;
|
|
490
|
+
const next = rs2.map((r, i) => i === ri ? { ...r, enabled: !r.enabled } : r);
|
|
491
|
+
setRules(next);
|
|
492
|
+
void persist(next, mode);
|
|
493
|
+
} else if (input === "d") {
|
|
494
|
+
const target = rs2[ri];
|
|
495
|
+
if (!target || !selected) return;
|
|
496
|
+
setStatus("Deleting\u2026");
|
|
497
|
+
void api.policies.revokeRule(selected.id, target.id).then(() => {
|
|
498
|
+
setStatus("\u2713 Deleted");
|
|
499
|
+
detail.reload();
|
|
500
|
+
list3.reload();
|
|
501
|
+
}).catch((e) => setStatus("\u2717 " + (e instanceof Error ? e.message : String(e))));
|
|
502
|
+
} else if (input === "m") {
|
|
503
|
+
const nm = mode === "denylist" ? "whitelist" : "denylist";
|
|
504
|
+
setMode(nm);
|
|
505
|
+
void persist(rs2, nm);
|
|
506
|
+
}
|
|
507
|
+
},
|
|
508
|
+
{ isActive: focused }
|
|
509
|
+
);
|
|
510
|
+
if (view === "list") {
|
|
511
|
+
return /* @__PURE__ */ jsx2(DataView, { loading: list3.loading && !list3.data, error: list3.error, empty: !!list3.data && policies.length === 0, emptyText: "No policies.", children: /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", children: [
|
|
512
|
+
/* @__PURE__ */ jsx2(Text2, { color: theme.dim, children: focused ? "\u2191\u2193 select \xB7 enter open" : "press \u2192 to browse" }),
|
|
513
|
+
/* @__PURE__ */ jsx2(Box2, { marginTop: 1, flexDirection: "column", children: policies.map((p, i) => /* @__PURE__ */ jsxs2(Text2, { color: i === pi ? theme.accentBright : void 0, bold: i === pi, children: [
|
|
514
|
+
(i === pi ? "\u25B8 " : " ") + truncate(p.name, 26).padEnd(27),
|
|
515
|
+
/* @__PURE__ */ jsxs2(Text2, { color: theme.dim, children: [
|
|
516
|
+
p.mode.padEnd(10),
|
|
517
|
+
" ",
|
|
518
|
+
p.rules.length,
|
|
519
|
+
" rules \xB7 v",
|
|
520
|
+
p.version
|
|
521
|
+
] })
|
|
522
|
+
] }, p.id)) })
|
|
523
|
+
] }) });
|
|
524
|
+
}
|
|
525
|
+
const rs = rules ?? [];
|
|
526
|
+
return /* @__PURE__ */ jsx2(DataView, { loading: detail.loading && !rules, error: detail.error, children: /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", children: [
|
|
527
|
+
/* @__PURE__ */ jsxs2(Box2, { children: [
|
|
528
|
+
/* @__PURE__ */ jsx2(Text2, { bold: true, color: theme.accentBright, children: truncate(selected?.name ?? "", 30) }),
|
|
529
|
+
/* @__PURE__ */ jsx2(Text2, { color: theme.dim, children: " mode: " }),
|
|
530
|
+
/* @__PURE__ */ jsx2(Text2, { color: mode === "whitelist" ? theme.ok : void 0, children: mode })
|
|
531
|
+
] }),
|
|
532
|
+
/* @__PURE__ */ jsx2(Text2, { color: theme.dim, children: "\u2191\u2193 rule \xB7 space toggle \xB7 d delete \xB7 m mode \xB7 \u2190 back" }),
|
|
533
|
+
/* @__PURE__ */ jsx2(Box2, { marginTop: 1, children: /* @__PURE__ */ jsx2(
|
|
534
|
+
Table,
|
|
535
|
+
{
|
|
536
|
+
columns: [
|
|
537
|
+
{ header: "", width: 2 },
|
|
538
|
+
{ header: "EFFECT", width: 7 },
|
|
539
|
+
{ header: "PRIO", width: 4 },
|
|
540
|
+
{ header: "TOOL", width: 20 },
|
|
541
|
+
{ header: "DESCRIPTION", width: 34 }
|
|
542
|
+
],
|
|
543
|
+
rows: rs.map((r, i) => [
|
|
544
|
+
{ value: i === ri ? "\u25B8" : "", color: theme.accentBright },
|
|
545
|
+
{ value: r.effect, color: r.effect === "ALLOW" ? theme.ok : theme.bad, dim: !r.enabled },
|
|
546
|
+
{ value: String(r.priority), dim: true },
|
|
547
|
+
{ value: (r.enabled ? "" : "\u2298 ") + truncate(r.toolPattern, 18), color: theme.accent, dim: !r.enabled },
|
|
548
|
+
{ value: truncate(r.description || "\u2014", 34), dim: !r.enabled }
|
|
549
|
+
])
|
|
550
|
+
}
|
|
551
|
+
) }),
|
|
552
|
+
rs.length === 0 ? /* @__PURE__ */ jsx2(Text2, { color: theme.dim, children: "(no rules)" }) : null,
|
|
553
|
+
status ? /* @__PURE__ */ jsx2(Box2, { marginTop: 1, children: /* @__PURE__ */ jsx2(Text2, { color: status.startsWith("\u2717") ? theme.bad : theme.ok, children: status }) }) : null
|
|
554
|
+
] }) });
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// src/tui/panels/RateLimit.tsx
|
|
558
|
+
import { Box as Box3, Text as Text3, useInput as useInput2 } from "ink";
|
|
559
|
+
import { useEffect as useEffect3, useState as useState3 } from "react";
|
|
560
|
+
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
561
|
+
var MODES = ["off", "detect", "block"];
|
|
562
|
+
var FIELDS = ["mode", "perMinute", "perHour", "perDay"];
|
|
563
|
+
function RateLimitPanel({ focused }) {
|
|
564
|
+
const layersQ = useLoader(() => api.settings.getSecurityLayers());
|
|
565
|
+
const historyQ = useLoader(() => api.settings.getRateLimitHistory());
|
|
566
|
+
const insightsQ = useLoader(() => api.stats.securityInsights(7));
|
|
567
|
+
const [draft, setDraft] = useState3(null);
|
|
568
|
+
const [dirty, setDirty] = useState3(false);
|
|
569
|
+
const [fi, setFi] = useState3(0);
|
|
570
|
+
const [status, setStatus] = useState3(null);
|
|
571
|
+
useEffect3(() => {
|
|
572
|
+
if (layersQ.data && !draft) setDraft({ ...layersQ.data.layers.rateLimit });
|
|
573
|
+
}, [layersQ.data, draft]);
|
|
574
|
+
const adjust = (dir, step) => {
|
|
575
|
+
if (!draft) return;
|
|
576
|
+
const field = FIELDS[fi];
|
|
577
|
+
if (field === "mode") {
|
|
578
|
+
const idx = (MODES.indexOf(draft.mode) + dir + MODES.length) % MODES.length;
|
|
579
|
+
setDraft({ ...draft, mode: MODES[idx] });
|
|
580
|
+
} else {
|
|
581
|
+
setDraft({ ...draft, [field]: Math.max(0, draft[field] + dir * step) });
|
|
582
|
+
}
|
|
583
|
+
setDirty(true);
|
|
584
|
+
setStatus(null);
|
|
585
|
+
};
|
|
586
|
+
const save = async () => {
|
|
587
|
+
if (!draft || !layersQ.data) return;
|
|
588
|
+
setStatus("Saving\u2026");
|
|
589
|
+
try {
|
|
590
|
+
const next = { ...layersQ.data.layers, rateLimit: draft };
|
|
591
|
+
const res = await api.settings.setSecurityLayers(next);
|
|
592
|
+
setDraft({ ...res.layers.rateLimit });
|
|
593
|
+
setDirty(false);
|
|
594
|
+
setStatus("\u2713 Saved");
|
|
595
|
+
historyQ.reload();
|
|
596
|
+
} catch (e) {
|
|
597
|
+
setStatus("\u2717 " + (e instanceof Error ? e.message : String(e)));
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
useInput2(
|
|
601
|
+
(input, key) => {
|
|
602
|
+
const step = key.shift ? 10 : 1;
|
|
603
|
+
if (key.upArrow) setFi((n) => (n - 1 + FIELDS.length) % FIELDS.length);
|
|
604
|
+
else if (key.downArrow) setFi((n) => (n + 1) % FIELDS.length);
|
|
605
|
+
else if (key.leftArrow) adjust(-1, step);
|
|
606
|
+
else if (key.rightArrow) adjust(1, step);
|
|
607
|
+
else if (input === "s") void save();
|
|
608
|
+
},
|
|
609
|
+
{ isActive: focused }
|
|
610
|
+
);
|
|
611
|
+
const history = (historyQ.data?.history ?? []).slice().sort((a, b) => b.ts - a.ts);
|
|
612
|
+
const bursts = (insightsQ.data?.["anomalies"] ?? []).slice(0, 6);
|
|
613
|
+
return /* @__PURE__ */ jsx3(DataView, { loading: layersQ.loading && !draft, error: layersQ.error, children: draft ? /* @__PURE__ */ jsxs3(Box3, { flexDirection: "column", children: [
|
|
614
|
+
/* @__PURE__ */ jsx3(Text3, { color: theme.dim, children: focused ? "\u2191\u2193 field \xB7 \u2190\u2192 \xB11 \xB7 shift+\u2190\u2192 \xB110 \xB7 s save" : "press \u2192 to edit" }),
|
|
615
|
+
/* @__PURE__ */ jsxs3(Box3, { marginTop: 1, flexDirection: "column", children: [
|
|
616
|
+
/* @__PURE__ */ jsx3(FieldRow, { label: "Mode", active: focused && fi === 0, children: /* @__PURE__ */ jsx3(Text3, { color: modeColor(draft.mode), children: draft.mode }) }),
|
|
617
|
+
/* @__PURE__ */ jsx3(FieldRow, { label: "Per minute", active: focused && fi === 1, children: /* @__PURE__ */ jsx3(Text3, { bold: true, children: draft.perMinute }) }),
|
|
618
|
+
/* @__PURE__ */ jsx3(FieldRow, { label: "Per hour", active: focused && fi === 2, children: /* @__PURE__ */ jsx3(Text3, { bold: true, children: draft.perHour === 0 ? "off" : draft.perHour }) }),
|
|
619
|
+
/* @__PURE__ */ jsx3(FieldRow, { label: "Per day", active: focused && fi === 3, children: /* @__PURE__ */ jsx3(Text3, { bold: true, children: draft.perDay === 0 ? "off" : draft.perDay }) })
|
|
620
|
+
] }),
|
|
621
|
+
dirty || status ? /* @__PURE__ */ jsxs3(Box3, { marginTop: 1, children: [
|
|
622
|
+
dirty ? /* @__PURE__ */ jsx3(Text3, { color: theme.warn, children: "\u25CF unsaved \u2014 press s to apply " }) : null,
|
|
623
|
+
status ? /* @__PURE__ */ jsx3(Text3, { color: status.startsWith("\u2717") ? theme.bad : theme.ok, children: status }) : null
|
|
624
|
+
] }) : null,
|
|
625
|
+
/* @__PURE__ */ jsxs3(Box3, { marginTop: 1, flexDirection: "column", children: [
|
|
626
|
+
/* @__PURE__ */ jsxs3(Text3, { color: theme.dim, children: [
|
|
627
|
+
"Change history ",
|
|
628
|
+
history.length ? `(${history.length})` : ""
|
|
629
|
+
] }),
|
|
630
|
+
history.length ? /* @__PURE__ */ jsx3(
|
|
631
|
+
Table,
|
|
632
|
+
{
|
|
633
|
+
columns: [
|
|
634
|
+
{ header: "WHEN", width: 8 },
|
|
635
|
+
{ header: "/MIN", width: 6 },
|
|
636
|
+
{ header: "/HOUR", width: 7 },
|
|
637
|
+
{ header: "/DAY", width: 6 }
|
|
638
|
+
],
|
|
639
|
+
rows: history.slice(0, 5).map((h, i) => [
|
|
640
|
+
{ value: ago(h.ts) + " ago", dim: true, bold: i === 0 },
|
|
641
|
+
{ value: String(h.minute), bold: i === 0 },
|
|
642
|
+
{ value: h.hour === 0 ? "off" : String(h.hour), dim: h.hour === 0 },
|
|
643
|
+
{ value: h.day === 0 ? "off" : String(h.day), dim: h.day === 0 }
|
|
644
|
+
])
|
|
645
|
+
}
|
|
646
|
+
) : /* @__PURE__ */ jsx3(Text3, { color: theme.dim, children: " no changes" })
|
|
647
|
+
] }),
|
|
648
|
+
/* @__PURE__ */ jsxs3(Box3, { marginTop: 1, flexDirection: "column", children: [
|
|
649
|
+
/* @__PURE__ */ jsxs3(Text3, { color: theme.dim, children: [
|
|
650
|
+
"Recent bursts ",
|
|
651
|
+
insightsQ.loading && !insightsQ.data ? "\u2026" : `(${bursts.length})`
|
|
652
|
+
] }),
|
|
653
|
+
bursts.length ? /* @__PURE__ */ jsx3(
|
|
654
|
+
Table,
|
|
655
|
+
{
|
|
656
|
+
columns: [
|
|
657
|
+
{ header: "RESULT", width: 9 },
|
|
658
|
+
{ header: "AGENT", width: 16 },
|
|
659
|
+
{ header: "CALLS/LIMIT", width: 12 },
|
|
660
|
+
{ header: "WHEN", width: 8 }
|
|
661
|
+
],
|
|
662
|
+
rows: bursts.map((b) => [
|
|
663
|
+
{ value: b.blocked ? "blocked" : "BYPASSED", color: b.blocked ? theme.accent : theme.bad, bold: !b.blocked },
|
|
664
|
+
{ value: (b.agent || "\u2014").slice(0, 16), dim: true },
|
|
665
|
+
{ value: `${b.count}/${b.limit}` },
|
|
666
|
+
{ value: ago(b.minute) + " ago", dim: true }
|
|
667
|
+
])
|
|
668
|
+
}
|
|
669
|
+
) : /* @__PURE__ */ jsxs3(Text3, { color: theme.dim, children: [
|
|
670
|
+
" ",
|
|
671
|
+
insightsQ.error ? insightsQ.error : "none in 7d"
|
|
672
|
+
] })
|
|
673
|
+
] })
|
|
674
|
+
] }) : null });
|
|
675
|
+
}
|
|
676
|
+
function FieldRow({ label, active: active2, children }) {
|
|
677
|
+
return /* @__PURE__ */ jsxs3(Box3, { children: [
|
|
678
|
+
/* @__PURE__ */ jsx3(Text3, { color: active2 ? theme.accentBright : void 0, children: (active2 ? "\u25B8 " : " ") + label.padEnd(12) }),
|
|
679
|
+
children
|
|
680
|
+
] });
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
// src/tui/panels/Dlp.tsx
|
|
684
|
+
import { Box as Box4, Text as Text4, useInput as useInput3 } from "ink";
|
|
685
|
+
import { useEffect as useEffect4, useState as useState4 } from "react";
|
|
686
|
+
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
687
|
+
var MODES2 = ["off", "detect", "block"];
|
|
688
|
+
function DlpPanel({ focused }) {
|
|
689
|
+
const q = useLoader(() => api.settings.getSecurityLayers());
|
|
690
|
+
const [dlp, setDlp] = useState4(null);
|
|
691
|
+
const [available, setAvailable] = useState4([]);
|
|
692
|
+
const [sel, setSel] = useState4(0);
|
|
693
|
+
const [status, setStatus] = useState4(null);
|
|
694
|
+
useEffect4(() => {
|
|
695
|
+
if (q.data && !dlp) {
|
|
696
|
+
setDlp({ ...q.data.layers.dlp, patterns: [...q.data.layers.dlp.patterns] });
|
|
697
|
+
setAvailable(q.data.availablePatterns);
|
|
698
|
+
}
|
|
699
|
+
}, [q.data, dlp]);
|
|
700
|
+
const persist = async (nextDlp) => {
|
|
701
|
+
if (!q.data) return;
|
|
702
|
+
setDlp(nextDlp);
|
|
703
|
+
setStatus("Saving\u2026");
|
|
704
|
+
try {
|
|
705
|
+
const res = await api.settings.setSecurityLayers({ ...q.data.layers, dlp: nextDlp });
|
|
706
|
+
setDlp({ ...res.layers.dlp, patterns: [...res.layers.dlp.patterns] });
|
|
707
|
+
setStatus("\u2713 Saved");
|
|
708
|
+
} catch (e) {
|
|
709
|
+
setStatus("\u2717 " + (e instanceof Error ? e.message : String(e)));
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
useInput3(
|
|
713
|
+
(input, key) => {
|
|
714
|
+
if (!dlp) return;
|
|
715
|
+
if (key.upArrow) setSel((n) => Math.max(0, n - 1));
|
|
716
|
+
else if (key.downArrow) setSel((n) => Math.min(available.length - 1, n + 1));
|
|
717
|
+
else if (input === " " || key.return) {
|
|
718
|
+
const p = available[sel];
|
|
719
|
+
if (!p) return;
|
|
720
|
+
const set = new Set(dlp.patterns);
|
|
721
|
+
if (set.has(p)) set.delete(p);
|
|
722
|
+
else set.add(p);
|
|
723
|
+
void persist({ ...dlp, patterns: [...set] });
|
|
724
|
+
} else if (input === "m") {
|
|
725
|
+
const idx = (MODES2.indexOf(dlp.mode) + 1) % MODES2.length;
|
|
726
|
+
void persist({ ...dlp, mode: MODES2[idx] });
|
|
727
|
+
}
|
|
728
|
+
},
|
|
729
|
+
{ isActive: focused }
|
|
730
|
+
);
|
|
731
|
+
const enabled = new Set(dlp?.patterns ?? []);
|
|
732
|
+
return /* @__PURE__ */ jsx4(DataView, { loading: q.loading && !dlp, error: q.error, children: dlp ? /* @__PURE__ */ jsxs4(Box4, { flexDirection: "column", children: [
|
|
733
|
+
/* @__PURE__ */ jsxs4(Box4, { children: [
|
|
734
|
+
/* @__PURE__ */ jsx4(Text4, { children: "mode: " }),
|
|
735
|
+
/* @__PURE__ */ jsx4(Text4, { color: modeColor(dlp.mode), children: dlp.mode }),
|
|
736
|
+
/* @__PURE__ */ jsx4(Text4, { color: theme.dim, children: focused ? " \u2191\u2193 move \xB7 space toggle \xB7 m mode" : " press \u2192 to edit" })
|
|
737
|
+
] }),
|
|
738
|
+
/* @__PURE__ */ jsx4(Box4, { marginTop: 1, flexDirection: "column", children: available.map((p, i) => {
|
|
739
|
+
const on = enabled.has(p);
|
|
740
|
+
return /* @__PURE__ */ jsxs4(Text4, { color: focused && i === sel ? theme.accentBright : void 0, bold: focused && i === sel, children: [
|
|
741
|
+
(focused && i === sel ? "\u25B8 " : " ") + (on ? "\u25CF " : "\u25CB "),
|
|
742
|
+
/* @__PURE__ */ jsx4(Text4, { color: on ? theme.ok : theme.dim, children: p })
|
|
743
|
+
] }, p);
|
|
744
|
+
}) }),
|
|
745
|
+
dlp.custom.length ? /* @__PURE__ */ jsxs4(Box4, { marginTop: 1, flexDirection: "column", children: [
|
|
746
|
+
/* @__PURE__ */ jsx4(Text4, { color: theme.dim, children: "Custom:" }),
|
|
747
|
+
dlp.custom.map((c2) => /* @__PURE__ */ jsxs4(Text4, { children: [
|
|
748
|
+
" ",
|
|
749
|
+
/* @__PURE__ */ jsx4(Text4, { color: theme.accent, children: c2.name }),
|
|
750
|
+
" ",
|
|
751
|
+
/* @__PURE__ */ jsx4(Text4, { color: theme.dim, children: c2.re })
|
|
752
|
+
] }, c2.name))
|
|
753
|
+
] }) : null,
|
|
754
|
+
status ? /* @__PURE__ */ jsx4(Box4, { marginTop: 1, children: /* @__PURE__ */ jsx4(Text4, { color: status.startsWith("\u2717") ? theme.bad : theme.ok, children: status }) }) : null
|
|
755
|
+
] }) : null });
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// src/tui/panels/Stats.tsx
|
|
759
|
+
import { Box as Box5, Text as Text5 } from "ink";
|
|
760
|
+
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
761
|
+
function StatsPanel({ active: active2 }) {
|
|
762
|
+
const stats = useLoader(() => api.stats.get());
|
|
763
|
+
const ts = useLoader(() => api.stats.timeseries({ period: "24h" }));
|
|
764
|
+
usePoll(() => {
|
|
765
|
+
stats.reload();
|
|
766
|
+
ts.reload();
|
|
767
|
+
}, 5e3, active2);
|
|
768
|
+
const s = stats.data;
|
|
769
|
+
const points = ts.data?.timeseries ?? [];
|
|
770
|
+
return /* @__PURE__ */ jsx5(DataView, { loading: stats.loading && !s, error: stats.error, children: s ? /* @__PURE__ */ jsxs5(Box5, { flexDirection: "column", children: [
|
|
771
|
+
/* @__PURE__ */ jsxs5(Box5, { children: [
|
|
772
|
+
/* @__PURE__ */ jsxs5(Text5, { bold: true, children: [
|
|
773
|
+
s.total_calls,
|
|
774
|
+
" "
|
|
775
|
+
] }),
|
|
776
|
+
/* @__PURE__ */ jsx5(Text5, { color: theme.dim, children: "calls " }),
|
|
777
|
+
/* @__PURE__ */ jsxs5(Text5, { color: theme.ok, children: [
|
|
778
|
+
s.allowed,
|
|
779
|
+
" allowed"
|
|
780
|
+
] }),
|
|
781
|
+
/* @__PURE__ */ jsx5(Text5, { color: theme.dim, children: " " }),
|
|
782
|
+
/* @__PURE__ */ jsxs5(Text5, { color: theme.bad, children: [
|
|
783
|
+
s.denied,
|
|
784
|
+
" denied"
|
|
785
|
+
] })
|
|
786
|
+
] }),
|
|
787
|
+
/* @__PURE__ */ jsxs5(Text5, { color: theme.dim, children: [
|
|
788
|
+
s.active_policies,
|
|
789
|
+
" policies \xB7 ",
|
|
790
|
+
s.registered_tools,
|
|
791
|
+
" tools"
|
|
792
|
+
] }),
|
|
793
|
+
/* @__PURE__ */ jsxs5(Box5, { marginTop: 1, flexDirection: "column", children: [
|
|
794
|
+
/* @__PURE__ */ jsxs5(Text5, { color: theme.dim, children: [
|
|
795
|
+
"Last 24h ",
|
|
796
|
+
ts.data ? `(per ${ts.data.granularity})` : ""
|
|
797
|
+
] }),
|
|
798
|
+
/* @__PURE__ */ jsxs5(Box5, { children: [
|
|
799
|
+
/* @__PURE__ */ jsx5(Text5, { children: "total " }),
|
|
800
|
+
/* @__PURE__ */ jsx5(Text5, { color: theme.accent, children: sparkline(points.map((p) => p.total), 64) })
|
|
801
|
+
] }),
|
|
802
|
+
/* @__PURE__ */ jsxs5(Box5, { children: [
|
|
803
|
+
/* @__PURE__ */ jsx5(Text5, { children: "allowed " }),
|
|
804
|
+
/* @__PURE__ */ jsx5(Text5, { color: theme.ok, children: sparkline(points.map((p) => p.allowed), 64) })
|
|
805
|
+
] }),
|
|
806
|
+
/* @__PURE__ */ jsxs5(Box5, { children: [
|
|
807
|
+
/* @__PURE__ */ jsx5(Text5, { children: "denied " }),
|
|
808
|
+
/* @__PURE__ */ jsx5(Text5, { color: theme.bad, children: sparkline(points.map((p) => p.denied), 64) })
|
|
809
|
+
] })
|
|
810
|
+
] }),
|
|
811
|
+
/* @__PURE__ */ jsxs5(Box5, { marginTop: 1, flexDirection: "column", children: [
|
|
812
|
+
/* @__PURE__ */ jsx5(Text5, { color: theme.dim, children: "Recent" }),
|
|
813
|
+
/* @__PURE__ */ jsx5(
|
|
814
|
+
Table,
|
|
815
|
+
{
|
|
816
|
+
columns: [
|
|
817
|
+
{ header: "DECISION", width: 9 },
|
|
818
|
+
{ header: "TOOL", width: 20 },
|
|
819
|
+
{ header: "MS", width: 5 },
|
|
820
|
+
{ header: "WHEN", width: 6 }
|
|
821
|
+
],
|
|
822
|
+
rows: (s.recent_activity ?? []).slice(0, 8).map((a) => [
|
|
823
|
+
{ value: a.decision, color: decisionColor(a.decision) },
|
|
824
|
+
{ value: truncate(a.tool_name, 20), color: theme.accent },
|
|
825
|
+
{ value: String(a.evaluation_time_ms ?? "\u2014"), dim: true },
|
|
826
|
+
{ value: ago(a.created_at), dim: true }
|
|
827
|
+
])
|
|
828
|
+
}
|
|
829
|
+
)
|
|
830
|
+
] })
|
|
831
|
+
] }) : null });
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
// src/tui/panels/Audit.tsx
|
|
835
|
+
import { Box as Box6, Text as Text6, useInput as useInput4 } from "ink";
|
|
836
|
+
import { useState as useState5 } from "react";
|
|
837
|
+
import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
838
|
+
var FILTERS = [void 0, "DENY", "ALLOW"];
|
|
839
|
+
function AuditPanel({ active: active2, focused }) {
|
|
840
|
+
const [fi, setFi] = useState5(0);
|
|
841
|
+
const filter = FILTERS[fi];
|
|
842
|
+
const audit = useLoader(() => api.audit.list({ filter, limit: 14 }), [fi]);
|
|
843
|
+
usePoll(audit.reload, 5e3, active2);
|
|
844
|
+
useInput4(
|
|
845
|
+
(input) => {
|
|
846
|
+
if (input === "f") setFi((n) => (n + 1) % FILTERS.length);
|
|
847
|
+
},
|
|
848
|
+
{ isActive: focused }
|
|
849
|
+
);
|
|
850
|
+
const entries = audit.data?.entries ?? [];
|
|
851
|
+
return /* @__PURE__ */ jsx6(DataView, { loading: audit.loading && !audit.data, error: audit.error, empty: !!audit.data && entries.length === 0, emptyText: "No audit entries.", children: /* @__PURE__ */ jsxs6(Box6, { flexDirection: "column", children: [
|
|
852
|
+
/* @__PURE__ */ jsxs6(Text6, { color: theme.dim, children: [
|
|
853
|
+
audit.data?.total ?? 0,
|
|
854
|
+
" entries \xB7 filter: ",
|
|
855
|
+
/* @__PURE__ */ jsx6(Text6, { color: theme.accent, children: filter ?? "all" }),
|
|
856
|
+
" (press f)"
|
|
857
|
+
] }),
|
|
858
|
+
/* @__PURE__ */ jsx6(Box6, { marginTop: 1, children: /* @__PURE__ */ jsx6(
|
|
859
|
+
Table,
|
|
860
|
+
{
|
|
861
|
+
columns: [
|
|
862
|
+
{ header: "DECISION", width: 9 },
|
|
863
|
+
{ header: "TOOL", width: 18 },
|
|
864
|
+
{ header: "AGENT", width: 14 },
|
|
865
|
+
{ header: "REASON", width: 26 },
|
|
866
|
+
{ header: "DLP", width: 4 },
|
|
867
|
+
{ header: "WHEN", width: 6 }
|
|
868
|
+
],
|
|
869
|
+
rows: entries.map((e) => [
|
|
870
|
+
{ value: e.decision, color: decisionColor(e.decision) },
|
|
871
|
+
{ value: truncate(e.tool_name, 18), color: theme.accent },
|
|
872
|
+
{ value: truncate(e.agent_name ?? "\u2014", 14), dim: true },
|
|
873
|
+
{ value: truncate(e.reason ?? "\u2014", 26) },
|
|
874
|
+
{ value: e.dlp_matches?.length ? String(e.dlp_matches.length) : "0", color: e.dlp_matches?.length ? theme.bad : void 0, dim: !e.dlp_matches?.length },
|
|
875
|
+
{ value: ago(e.created_at), dim: true }
|
|
876
|
+
])
|
|
877
|
+
}
|
|
878
|
+
) })
|
|
879
|
+
] }) });
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
// src/tui/panels/Agents.tsx
|
|
883
|
+
import { Box as Box7, Text as Text7 } from "ink";
|
|
884
|
+
import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
885
|
+
function AgentsPanel({ active: active2 }) {
|
|
886
|
+
const agents = useLoader(() => api.agents.live({ limit: 14 }));
|
|
887
|
+
usePoll(agents.reload, 4e3, active2);
|
|
888
|
+
const data = agents.data;
|
|
889
|
+
const rows = data?.agents ?? [];
|
|
890
|
+
return /* @__PURE__ */ jsx7(DataView, { loading: agents.loading && !data, error: agents.error, empty: !!data && rows.length === 0, emptyText: "No agent sessions.", children: /* @__PURE__ */ jsxs7(Box7, { flexDirection: "column", children: [
|
|
891
|
+
data ? /* @__PURE__ */ jsxs7(Text7, { color: theme.dim, children: [
|
|
892
|
+
/* @__PURE__ */ jsxs7(Text7, { color: theme.ok, children: [
|
|
893
|
+
data.counts.active,
|
|
894
|
+
" active"
|
|
895
|
+
] }),
|
|
896
|
+
" \xB7 ",
|
|
897
|
+
/* @__PURE__ */ jsxs7(Text7, { color: theme.warn, children: [
|
|
898
|
+
data.counts.idle,
|
|
899
|
+
" idle"
|
|
900
|
+
] }),
|
|
901
|
+
" \xB7 ",
|
|
902
|
+
data.counts.deactivated,
|
|
903
|
+
" off"
|
|
904
|
+
] }) : null,
|
|
905
|
+
/* @__PURE__ */ jsx7(Box7, { marginTop: 1, children: /* @__PURE__ */ jsx7(
|
|
906
|
+
Table,
|
|
907
|
+
{
|
|
908
|
+
columns: [
|
|
909
|
+
{ header: "STATUS", width: 7 },
|
|
910
|
+
{ header: "AGENT", width: 20 },
|
|
911
|
+
{ header: "CALLS", width: 6 },
|
|
912
|
+
{ header: "DENY", width: 5 },
|
|
913
|
+
{ header: "DLP", width: 4 },
|
|
914
|
+
{ header: "TRUST", width: 6 },
|
|
915
|
+
{ header: "CHARACTER", width: 20 }
|
|
916
|
+
],
|
|
917
|
+
rows: rows.map((a) => [
|
|
918
|
+
{ value: a.status, color: modeColor(a.status) },
|
|
919
|
+
{ value: truncate(a.agent_name ?? a.agent_id ?? a.session_id, 20), color: theme.accent },
|
|
920
|
+
{ value: String(a.total_calls) },
|
|
921
|
+
{ value: String(a.denied_calls), color: a.denied_calls ? theme.bad : void 0, dim: !a.denied_calls },
|
|
922
|
+
{ value: String(a.dlp_events), color: a.dlp_events ? theme.bad : void 0, dim: !a.dlp_events },
|
|
923
|
+
{ value: `${a.trust_score}` },
|
|
924
|
+
{ value: truncate(a.character || "\u2014", 20), dim: true }
|
|
925
|
+
])
|
|
926
|
+
}
|
|
927
|
+
) })
|
|
928
|
+
] }) });
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
// src/tui/App.tsx
|
|
932
|
+
import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
933
|
+
var SECTIONS = [
|
|
934
|
+
{ label: "Policies", Panel: PoliciesPanel },
|
|
935
|
+
{ label: "Rate Limit", Panel: RateLimitPanel },
|
|
936
|
+
{ label: "DLP", Panel: DlpPanel },
|
|
937
|
+
{ label: "Stats", Panel: StatsPanel },
|
|
938
|
+
{ label: "Audit", Panel: AuditPanel },
|
|
939
|
+
{ label: "Agents", Panel: AgentsPanel }
|
|
940
|
+
];
|
|
941
|
+
var BANNER_HEX = ["#1432A0", "#2850BE", "#3C6ED7", "#5A8CE6", "#82AAF0", "#AAC8FA"];
|
|
942
|
+
function Banner() {
|
|
943
|
+
const wide = (process.stdout.columns ?? 80) >= 82;
|
|
944
|
+
if (!wide) {
|
|
945
|
+
return /* @__PURE__ */ jsxs8(Box8, { children: [
|
|
946
|
+
/* @__PURE__ */ jsx8(Text8, { bold: true, color: theme.accentBright, children: "SolonGate" }),
|
|
947
|
+
/* @__PURE__ */ jsx8(Text8, { color: theme.dim, children: " \u2014 security control center" })
|
|
948
|
+
] });
|
|
949
|
+
}
|
|
950
|
+
return /* @__PURE__ */ jsxs8(Box8, { flexDirection: "column", children: [
|
|
951
|
+
BANNER_FULL.map((line, i) => /* @__PURE__ */ jsx8(Text8, { bold: true, color: BANNER_HEX[i], children: line }, i)),
|
|
952
|
+
/* @__PURE__ */ jsx8(Text8, { color: theme.dim, children: " security control center \xB7 manage policies, rate limits, DLP & more" })
|
|
953
|
+
] });
|
|
954
|
+
}
|
|
955
|
+
function App() {
|
|
956
|
+
const { exit } = useApp();
|
|
957
|
+
const [section, setSection] = useState6(0);
|
|
958
|
+
const [focus, setFocus] = useState6("nav");
|
|
959
|
+
useInput5((input, key) => {
|
|
960
|
+
if (focus === "nav") {
|
|
961
|
+
if (key.upArrow) setSection((n) => (n - 1 + SECTIONS.length) % SECTIONS.length);
|
|
962
|
+
else if (key.downArrow) setSection((n) => (n + 1) % SECTIONS.length);
|
|
963
|
+
else if (key.rightArrow || key.return || key.tab) setFocus("panel");
|
|
964
|
+
else if (input === "q") exit();
|
|
965
|
+
} else {
|
|
966
|
+
if (key.escape || key.tab) setFocus("nav");
|
|
967
|
+
}
|
|
968
|
+
});
|
|
969
|
+
const current = SECTIONS[section];
|
|
970
|
+
const Panel = current.Panel;
|
|
971
|
+
return /* @__PURE__ */ jsxs8(Box8, { flexDirection: "column", paddingX: 1, paddingTop: 1, children: [
|
|
972
|
+
/* @__PURE__ */ jsx8(Banner, {}),
|
|
973
|
+
/* @__PURE__ */ jsxs8(Box8, { marginTop: 1, children: [
|
|
974
|
+
/* @__PURE__ */ jsx8(Box8, { flexDirection: "column", width: 16, borderStyle: "round", borderColor: focus === "nav" ? theme.accent : "gray", paddingX: 1, children: SECTIONS.map((s, i) => /* @__PURE__ */ jsx8(Text8, { color: i === section ? theme.accentBright : void 0, bold: i === section, children: (i === section ? "\u25B8 " : " ") + s.label }, s.label)) }),
|
|
975
|
+
/* @__PURE__ */ jsx8(Box8, { flexGrow: 1, minHeight: 16, borderStyle: "round", borderColor: focus === "panel" ? theme.accent : "gray", paddingX: 1, paddingY: 0, children: /* @__PURE__ */ jsx8(Panel, { active: true, focused: focus === "panel" }) })
|
|
976
|
+
] }),
|
|
977
|
+
/* @__PURE__ */ jsx8(Box8, { marginTop: 1, children: focus === "nav" ? /* @__PURE__ */ jsx8(KeyHints, { hints: [["\u2191\u2193", "section"], ["\u2192/enter", "open"], ["q", "quit"]] }) : /* @__PURE__ */ jsx8(KeyHints, { hints: [["\u2191\u2193", "move"], ["\u2190\u2192/space/s", "edit"], ["esc", "back to menu"]] }) })
|
|
978
|
+
] });
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
// src/tui/index.tsx
|
|
982
|
+
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
983
|
+
async function launchTui() {
|
|
984
|
+
if (!process.stdout.isTTY || !process.stdin.isTTY) {
|
|
985
|
+
process.stderr.write(
|
|
986
|
+
"The SolonGate TUI needs an interactive terminal.\nUse the scriptable commands instead, e.g. `solongate stats`, `solongate policy list`.\n"
|
|
987
|
+
);
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
990
|
+
if (!isAuthenticated()) {
|
|
991
|
+
process.stderr.write("Not logged in. Run `solongate login` first.\n");
|
|
992
|
+
return;
|
|
993
|
+
}
|
|
994
|
+
const { waitUntilExit } = render(/* @__PURE__ */ jsx9(App, {}));
|
|
995
|
+
await waitUntilExit();
|
|
996
|
+
}
|
|
997
|
+
export {
|
|
998
|
+
launchTui
|
|
999
|
+
};
|