Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

Merge CodeAtlas logging with the exploration frontend

Martin Vogel80f4f41f9bcb
diff --cc graph-ui/src/main.tsx
index e5577fa53,98df07e10..603579afe
--- a/graph-ui/src/main.tsx
+++ b/graph-ui/src/main.tsx
@@@ -6,8 -7,12 +7,13 @@@ import { installUiLog } from './app/ui-
// still auf ihren Initialwert zurueck.
import './styles/tokens.css';
import './styles/terminal.css';
+import './styles/workspace.css';
+ // Before anything else can fail: the console keeps printing, and from here
+ // on a copy of every line, every uncaught error and every failed request
+ // reaches the server's file (app/ui-log.ts, GET /api/ui-log).
+ installUiLog();
+
const container = document.getElementById('root');
if (container === null) {
throw new Error('#root fehlt in index.html');
diff --cc graph-ui/src/projects/projects-model.ts
index 2dcaf3771,1b0a62e8a..6f577b18c
--- a/graph-ui/src/projects/projects-model.ts
+++ b/graph-ui/src/projects/projects-model.ts
@@@ -192,13 -193,60 +193,65 @@@ export interface ServerProcess
elapsed: string;
command: string;
isSelf: boolean;
+ /** Unit-aware measurements; legacy numeric fields above remain compatible. */
+ telemetry?: { cpu: number | null; memoryMb: number | null };
}
+export type ProcessCpuUnit = 'percent' | 'seconds' | 'unknown';
+export type ProcessMemoryKind = 'resident' | 'working_set' | 'peak_resident' | 'unknown';
+
+ /** The tail of the frontend log file the server keeps (POST /api/ui-log). */
+ export interface UiLogTail {
+ /** The file on the server; what a bug report attaches. */
+ path: string;
+ /** The rotated file before it, when there is one. Empty otherwise. */
+ previousPath: string;
+ sizeBytes: number;
+ /** True when the lines do not start at the first line of the file. */
+ partial: boolean;
+ /** One JSON object per line, as written by the server. */
+ lines: string[];
+ total: number;
+ }
+
+ export function readUiLogTail(raw: unknown): UiLogTail {
+ const record = isRecord(raw) ? raw : {};
+ const lines = strings(record['lines']);
+ return {
+ path: text(record['path']),
+ previousPath: text(record['previous_path']),
+ sizeBytes: optionalNumber(record['size_bytes']) ?? 0,
+ partial: record['partial'] === true,
+ lines,
+ total: optionalNumber(record['total']) ?? lines.length,
+ };
+ }
+
+ /**
+ * One line of the frontend log as the panel shows it: time, level, source
+ * and message, with the detail in brackets. The file keeps the JSON; a
+ * reader scanning the panel wants the sentence. A line that is not JSON is
+ * shown as it is.
+ */
+ export function uiLogLineText(line: string): string {
+ let parsed: unknown;
+ try {
+ parsed = JSON.parse(line);
+ } catch {
+ return line;
+ }
+ if (!isRecord(parsed)) {
+ return line;
+ }
+ const when = text(parsed['ts']).length > 0 ? text(parsed['ts']) : text(parsed['received']);
+ const level = text(parsed['level']);
+ const source = text(parsed['source']);
+ const message = text(parsed['message']);
+ const detail = text(parsed['detail']);
+ const head = [when, level, source.length > 0 ? `${source}:` : ''].filter((part) => part.length > 0).join(' ');
+ return `${head} ${message}${detail.length > 0 ? ` (${detail})` : ''}`.trim();
+ }
+
export interface ProcessReport {
selfPid: number;
selfRssMb: number;
diff --cc graph-ui/verification/w6/stylegate.json
index b3064c1a2,7252bf49f..df114b2d2
--- a/graph-ui/verification/w6/stylegate.json
+++ b/graph-ui/verification/w6/stylegate.json
@@@ -34,7 -40,7 +34,7 @@@
},
{
"file": "README.md",
- "line": 38,
- "line": 6,
++ "line": 47,
"text": "Projektregeln in `CLAUDE.md`, der aufgenommene Fremdcode in `THIRD_PARTY.md`.",
"reason": "der Satz, der Attribution verbietet, muss seinen Gegenstand nennen duerfen; die Zeile traegt kein Urheberschafts-Muster"
},
@@@ -139,8 -146,8 +139,8 @@@
"reason": "Docblocks und Zeilenkommentare sind kein Bildschirmtext. Der Parser sieht den Unterschied, ein regulaerer Ausdruck koennte ihn nicht sehen."
}
],
- "filesConsidered": 727,
- "textFiles": 572,
- "filesConsidered": 586,
- "textFiles": 462,
- "binaryFiles": 124,
- "generatedAt": "2026-08-30T18:51:16.137Z"
++ "filesConsidered": 734,
++ "textFiles": 579,
+ "binaryFiles": 155,
- "generatedAt": "2026-09-09T17:46:30.681Z"
++ "generatedAt": "2026-09-09T17:55:42.603Z"
}
diff --cc graph-ui/verification/w7/promises.json
index 694a47374,98bf80d48..039313061
--- a/graph-ui/verification/w7/promises.json
+++ b/graph-ui/verification/w7/promises.json
@@@ -3,7 -3,7 +3,7 @@@
"promiseMatches": [],
"deadAffordances": 0,
"deadAffordanceMatches": [],
- "filesScanned": 186,
- "filesScanned": 149,
++ "filesScanned": 190,
"whitelist": [
{
"rule": "disabled",
@@@ -102,5 -102,5 +102,5 @@@
"onToggle"
],
"scanned": "src/**/*.{ts,tsx} ohne *.test.*",
- "generatedAt": "2026-09-09T17:46:31.026Z"
- "generatedAt": "2026-08-30T18:51:16.558Z"
++ "generatedAt": "2026-09-09T17:55:42.944Z"
}
diff --cc tests/test_httpd.c
index cf56d2808,c9fa41fbd..b74533a6c
--- a/tests/test_httpd.c
+++ b/tests/test_httpd.c
@@@ -1071,18 -1048,223 +1071,227 @@@ TEST(ui_server_free_never_joins_active_
PASS();
}
- /* The UI's connections have a fixed allowlist: two local services and the
+ /* ── Frontend log file (POST/GET /api/ui-log) ─────────────────── */
+
+ static int ui_log_read_file(const char *path, char *out, size_t outsz) {
+ FILE *f = cbm_fopen(path, "rb");
+ if (!f)
+ return -1;
+ size_t n = fread(out, 1, outsz - 1, f);
+ fclose(f);
+ out[n] = '\0';
+ return (int)n;
+ }
+
+ static int ui_log_count_char(const char *s, char ch) {
+ int n = 0;
+ for (; *s; s++) {
+ if (*s == ch)
+ n++;
+ }
+ return n;
+ }
+
+ static int ui_log_post(int port, const char *body, char *resp, size_t respsz) {
+ size_t cap = strlen(body) + 512;
+ char *req = malloc(cap);
+ if (!req)
+ return 0;
+ snprintf(req, cap,
+ "POST /api/ui-log HTTP/1.1\r\nHost: 127.0.0.1:%d\r\n"
+ "Content-Type: application/json\r\nContent-Length: %zu\r\n\r\n%s",
+ port, strlen(body), body);
+ int n = th_http(port, req, resp, respsz);
+ free(req);
+ return n;
+ }
+
+ /* One post, two entries: both land as JSON lines in <cache>/logs/ui.log with
+ * the fields the frontend sent, GET /api/ui-log tails the file back, and the
+ * error (not the plain log line) is mirrored into the ring GET /api/logs
+ * serves. */
+ TEST(ui_log_post_writes_jsonl_and_tail_reads_it) {
+ ui_delete_fixture_t fx;
+ ASSERT_EQ(ui_delete_fixture_init(&fx), 0);
+ th_server_t ts;
+ ASSERT_EQ(th_server_start(&ts), 0);
+ int port = cbm_http_server_port(ts.srv);
+
+ const char *body =
+ "{\"page\":\"/?project=demo\",\"session\":\"s1\",\"entries\":["
+ "{\"ts\":\"2026-09-08T10:00:00.000Z\",\"seq\":1,\"level\":\"error\",\"source\":\"rpc\","
+ "\"message\":\"get_code_snippet returned no source\",\"detail\":\"HTTP 200\","
+ "\"stack\":\"Error: x\\n at y\"},"
+ "{\"ts\":\"2026-09-08T10:00:01.000Z\",\"seq\":2,\"level\":\"log\",\"source\":\"console\","
+ "\"message\":\"galaxy \\\"ready\\\"\"}]}";
+ char resp[16384];
+ ASSERT_TRUE(ui_log_post(port, body, resp, sizeof(resp)) > 0);
+ ASSERT_EQ(th_status(resp), 200);
+ ASSERT_NOT_NULL(strstr(resp, "\"accepted\":2"));
+ ASSERT_NOT_NULL(strstr(resp, "\"dropped\":0"));
+ ASSERT_NOT_NULL(strstr(resp, "\"file_error\":false"));
+ ASSERT_NOT_NULL(strstr(resp, "/logs/ui.log\""));
+
+ char path[1024];
+ snprintf(path, sizeof(path), "%s/logs/ui.log", fx.cache_dir);
+ char content[8192];
+ ASSERT_TRUE(ui_log_read_file(path, content, sizeof(content)) > 0);
+ ASSERT_EQ(ui_log_count_char(content, '\n'), 2);
+ ASSERT_TRUE(strncmp(content, "{\"received\":\"", 13) == 0);
+ ASSERT_NOT_NULL(strstr(content, "\"page\":\"/?project=demo\",\"session\":\"s1\",\"seq\":1"));
+ ASSERT_NOT_NULL(strstr(content, "\"level\":\"error\",\"source\":\"rpc\","
+ "\"message\":\"get_code_snippet returned no source\","
+ "\"detail\":\"HTTP 200\",\"stack\":\"Error: x\\n at y\"}"));
+ ASSERT_NOT_NULL(strstr(content,
+ "\"seq\":2,\"ts\":\"2026-09-08T10:00:01.000Z\",\"level\":\"log\","
+ "\"source\":\"console\",\"message\":\"galaxy \\\"ready\\\"\"}"));
+
+ /* The tail, asked for one line: the newest, and it says it is partial. */
+ char req[256];
+ snprintf(req, sizeof(req), "GET /api/ui-log?lines=1 HTTP/1.1\r\nHost: 127.0.0.1:%d\r\n\r\n",
+ port);
+ ASSERT_TRUE(th_http(port, req, resp, sizeof(resp)) > 0);
+ ASSERT_EQ(th_status(resp), 200);
+ ASSERT_NOT_NULL(strstr(resp, "\"partial\":true"));
+ ASSERT_NOT_NULL(strstr(resp, "\"total\":2"));
+ ASSERT_NOT_NULL(strstr(resp, "galaxy"));
+ ASSERT_TRUE(strstr(resp, "get_code_snippet") == NULL);
+ ASSERT_NOT_NULL(strstr(resp, "\"size_bytes\":"));
+ ASSERT_TRUE(strstr(resp, "previous_path") == NULL);
+
+ /* Asked for more than there is: both, complete. */
+ snprintf(req, sizeof(req), "GET /api/ui-log?lines=10 HTTP/1.1\r\nHost: 127.0.0.1:%d\r\n\r\n",
+ port);
+ ASSERT_TRUE(th_http(port, req, resp, sizeof(resp)) > 0);
+ ASSERT_EQ(th_status(resp), 200);
+ ASSERT_NOT_NULL(strstr(resp, "\"partial\":false"));
+ ASSERT_NOT_NULL(strstr(resp, "get_code_snippet"));
+ ASSERT_NOT_NULL(strstr(resp, "galaxy"));
+
+ /* The ring carries the error, not the log line. */
+ snprintf(req, sizeof(req), "GET /api/logs?lines=50 HTTP/1.1\r\nHost: 127.0.0.1:%d\r\n\r\n",
+ port);
+ ASSERT_TRUE(th_http(port, req, resp, sizeof(resp)) > 0);
+ ASSERT_EQ(th_status(resp), 200);
+ ASSERT_NOT_NULL(strstr(resp, "ui.error rpc: get_code_snippet returned no source"));
+ ASSERT_TRUE(strstr(resp, "ui.log console") == NULL);
+
+ th_server_stop(&ts);
+ ui_delete_fixture_cleanup(&fx);
+ PASS();
+ }
+
+ /* Refused bodies never create the file: empty, not JSON, no entries[], and a
+ * post above the 64 KiB cap. Entries that are not objects are counted as
+ * dropped rather than refused, so one bad entry does not cost the rest. */
+ TEST(ui_log_post_refuses_bad_bodies) {
+ ui_delete_fixture_t fx;
+ ASSERT_EQ(ui_delete_fixture_init(&fx), 0);
+ th_server_t ts;
+ ASSERT_EQ(th_server_start(&ts), 0);
+ int port = cbm_http_server_port(ts.srv);
+ char resp[4096];
+ char req[512];
+
+ snprintf(req, sizeof(req),
+ "POST /api/ui-log HTTP/1.1\r\nHost: 127.0.0.1:%d\r\n"
+ "Content-Type: application/json\r\nContent-Length: 0\r\n\r\n",
+ port);
+ ASSERT_TRUE(th_http(port, req, resp, sizeof(resp)) > 0);
+ ASSERT_EQ(th_status(resp), 400);
+
+ ASSERT_TRUE(ui_log_post(port, "not json", resp, sizeof(resp)) > 0);
+ ASSERT_EQ(th_status(resp), 400);
+
+ ASSERT_TRUE(ui_log_post(port, "{\"page\":\"/\"}", resp, sizeof(resp)) > 0);
+ ASSERT_EQ(th_status(resp), 400);
+
+ size_t big_len = 70000;
+ char *big = malloc(big_len + 64);
+ ASSERT_NOT_NULL(big);
+ strcpy(big, "{\"entries\":[{\"message\":\"");
+ size_t at = strlen(big);
+ memset(big + at, 'a', big_len);
+ strcpy(big + at + big_len, "\"}]}");
+ ASSERT_TRUE(ui_log_post(port, big, resp, sizeof(resp)) > 0);
+ ASSERT_EQ(th_status(resp), 413);
+ free(big);
+
+ char path[1024];
+ snprintf(path, sizeof(path), "%s/logs/ui.log", fx.cache_dir);
+ ASSERT_TRUE(!cbm_file_exists(path));
+
+ ASSERT_TRUE(ui_log_post(port, "{\"entries\":[42,{\"message\":\"kept\"}]}", resp, sizeof(resp)) >
+ 0);
+ ASSERT_EQ(th_status(resp), 200);
+ ASSERT_NOT_NULL(strstr(resp, "\"accepted\":1,\"dropped\":1"));
+ ASSERT_TRUE(cbm_file_exists(path));
+
+ th_server_stop(&ts);
+ ui_delete_fixture_cleanup(&fx);
+ PASS();
+ }
+
+ /* The file rotates once to ui.log.1 when it has reached the configured size
+ * at the time of a post; the tail names the previous file. */
+ TEST(ui_log_rotates_at_configured_size) {
+ ui_delete_fixture_t fx;
+ ASSERT_EQ(ui_delete_fixture_init(&fx), 0);
+ cbm_setenv("CBM_UI_LOG_ROTATE_BYTES", "300", 1);
+ th_server_t ts;
+ ASSERT_EQ(th_server_start(&ts), 0);
+ int port = cbm_http_server_port(ts.srv);
+ char resp[8192];
+
+ const char *names[] = {"first", "second", "third"};
+ for (int i = 0; i < 3; i++) {
+ char body[1024];
+ char pad[320];
+ memset(pad, 'p', sizeof(pad) - 1);
+ pad[sizeof(pad) - 1] = '\0';
+ snprintf(body, sizeof(body), "{\"entries\":[{\"level\":\"info\",\"message\":\"%s %s\"}]}",
+ names[i], pad);
+ ASSERT_TRUE(ui_log_post(port, body, resp, sizeof(resp)) > 0);
+ ASSERT_EQ(th_status(resp), 200);
+ }
+
+ char path[1024], previous[1040];
+ snprintf(path, sizeof(path), "%s/logs/ui.log", fx.cache_dir);
+ snprintf(previous, sizeof(previous), "%s.1", path);
+ char content[4096];
+ ASSERT_TRUE(ui_log_read_file(path, content, sizeof(content)) > 0);
+ ASSERT_NOT_NULL(strstr(content, "\"message\":\"third "));
+ ASSERT_TRUE(strstr(content, "second") == NULL);
+ ASSERT_TRUE(ui_log_read_file(previous, content, sizeof(content)) > 0);
+ ASSERT_NOT_NULL(strstr(content, "\"message\":\"second "));
+ ASSERT_TRUE(strstr(content, "first") == NULL);
+
+ char req[256];
+ snprintf(req, sizeof(req), "GET /api/ui-log HTTP/1.1\r\nHost: 127.0.0.1:%d\r\n\r\n", port);
+ ASSERT_TRUE(th_http(port, req, resp, sizeof(resp)) > 0);
+ ASSERT_EQ(th_status(resp), 200);
+ ASSERT_NOT_NULL(strstr(resp, "\"previous_path\":\""));
+ ASSERT_NOT_NULL(strstr(resp, "ui.log.1\""));
+ ASSERT_NOT_NULL(strstr(resp, "third "));
+
+ th_server_stop(&ts);
+ cbm_unsetenv("CBM_UI_LOG_ROTATE_BYTES");
+ ui_delete_fixture_cleanup(&fx);
+ PASS();
+ }
+
-/* The UI's CSP stays loopback-only: the served page may reach the server
- * itself and the two loopback services the reader can start (the local-model
- * sidecar on 4141, the agent bridge on 4142), and nothing else. Every host
- * named in the policy is 127.0.0.1 on one of those two ports. */
-TEST(ui_csp_connect_src_is_loopback_only) {
++/* The UI connections have a fixed allowlist: two local services and the
+ * model host plus its verified download CDN. Browser consent controls model
+ * downloads; script sources remain local, with no unrestricted CDN or eval
+ * allowance. */
+TEST(ui_csp_connect_src_has_explicit_download_hosts) {
const char *csp = CBM_UI_CSP_VALUE;
- ASSERT_NOT_NULL(strstr(csp, "connect-src 'self' http://127.0.0.1:4141 http://127.0.0.1:4142;"));
- ASSERT_TRUE(strstr(csp, "https://") == NULL);
+ ASSERT_NOT_NULL(strstr(csp, "connect-src 'self' http://127.0.0.1:4141 http://127.0.0.1:4142 "
+ "https://huggingface.co https://us.aws.cdn.hf.co;"));
+ ASSERT_NOT_NULL(strstr(csp, "script-src 'self' 'wasm-unsafe-eval';"));
+ ASSERT_NOT_NULL(strstr(csp, "worker-src 'self' blob:;"));
+ ASSERT_TRUE(strstr(csp, "*") == NULL);
+ ASSERT_TRUE(strstr(csp, "'unsafe-eval'") == NULL);
ASSERT_TRUE(strstr(csp, "ws://") == NULL);
ASSERT_TRUE(strstr(csp, "wss://") == NULL);
int hosts = 0;
@@@ -2517,10 -2692,12 +2726,13 @@@ SUITE(httpd)
RUN_TEST(ui_server_rejects_non_loopback_host);
RUN_TEST(ui_server_unknown_path_404);
RUN_TEST(ui_server_process_kill_route_is_unavailable);
+ RUN_TEST(ui_server_process_measurements_declare_platform_semantics);
RUN_TEST(ui_server_routes_indexing_through_joinable_daemon_executor);
RUN_TEST(ui_server_free_never_joins_active_index_worker);
- RUN_TEST(ui_csp_connect_src_is_loopback_only);
+ RUN_TEST(ui_csp_connect_src_has_explicit_download_hosts);
+ RUN_TEST(ui_log_post_writes_jsonl_and_tail_reads_it);
+ RUN_TEST(ui_log_post_refuses_bad_bodies);
+ RUN_TEST(ui_log_rotates_at_configured_size);
RUN_TEST(ui_server_root_without_embedded_assets_is_not_found);
RUN_TEST(ui_server_same_origin_request_is_allowed);
RUN_TEST(ui_server_rejects_foreign_and_null_origins);