mapwright-agent 0.2.0__py3-none-any.whl
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.
- mapwright/__init__.py +3 -0
- mapwright/__main__.py +3 -0
- mapwright/analyze.py +809 -0
- mapwright/brief.py +208 -0
- mapwright/cli.py +596 -0
- mapwright/concepts.py +190 -0
- mapwright/config.py +204 -0
- mapwright/connect.py +337 -0
- mapwright/export.py +42 -0
- mapwright/firestore.py +168 -0
- mapwright/flow.py +238 -0
- mapwright/hooks.py +111 -0
- mapwright/ignore.py +248 -0
- mapwright/infra.py +253 -0
- mapwright/mcp.py +153 -0
- mapwright/noise.py +80 -0
- mapwright/redact.py +39 -0
- mapwright/render.py +428 -0
- mapwright/routes_js.py +282 -0
- mapwright/server.py +388 -0
- mapwright/titles.py +111 -0
- mapwright/track.py +715 -0
- mapwright/ui/app.css +277 -0
- mapwright/ui/app.js +1025 -0
- mapwright/ui/icons.svg +73 -0
- mapwright/ui/index.html +35 -0
- mapwright/ui/mark.svg +1 -0
- mapwright/ui/vendor/mermaid.LICENSE +21 -0
- mapwright/ui/vendor/mermaid.min.js +2029 -0
- mapwright_agent-0.2.0.dist-info/METADATA +179 -0
- mapwright_agent-0.2.0.dist-info/RECORD +34 -0
- mapwright_agent-0.2.0.dist-info/WHEEL +4 -0
- mapwright_agent-0.2.0.dist-info/entry_points.txt +3 -0
- mapwright_agent-0.2.0.dist-info/licenses/LICENSE +21 -0
mapwright/ui/app.js
ADDED
|
@@ -0,0 +1,1025 @@
|
|
|
1
|
+
/* Mapwright UI. No framework, no build step. Talks to the local daemon (live) or reads a recorded
|
|
2
|
+
bundle (demo on the website). Text from the project is inserted with textContent, or escaped
|
|
3
|
+
before it goes into highlighted code; the only markup inserted as-is is the SVG Mermaid returns
|
|
4
|
+
in strict mode with HTML labels off. */
|
|
5
|
+
(() => {
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
// ------------------------------------------------------------------ helpers
|
|
9
|
+
const $ = (s, r = document) => r.querySelector(s);
|
|
10
|
+
const el = (tag, cls, text) => { const n = document.createElement(tag); if (cls) n.className = cls; if (text != null) n.textContent = text; return n; };
|
|
11
|
+
const NS = "http://www.w3.org/2000/svg";
|
|
12
|
+
const icon = (name, cls = "i") => { const s = document.createElementNS(NS, "svg"); s.setAttribute("class", cls); const u = document.createElementNS(NS, "use"); u.setAttribute("href", "icons.svg#" + name); s.append(u); return s; };
|
|
13
|
+
const esc = (s) => String(s).replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c]));
|
|
14
|
+
const ago = (ts) => { const d = Math.max(0, Date.now() / 1000 - ts); return d < 60 ? `${Math.floor(d)}s ago` : d < 3600 ? `${Math.floor(d / 60)}m ago` : d < 86400 ? `${Math.floor(d / 3600)}h ago` : new Date(ts * 1000).toLocaleDateString(); };
|
|
15
|
+
const clock = (ts) => new Date(ts * 1000).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
|
|
16
|
+
const base = (p) => p.split("/").pop();
|
|
17
|
+
const short = (id) => (id || "").split(":").pop();
|
|
18
|
+
const store = { get(k, d) { try { const v = localStorage.getItem("mw." + k); return v == null ? d : JSON.parse(v); } catch (e) { return d; } }, set(k, v) { try { localStorage.setItem("mw." + k, JSON.stringify(v)); } catch (e) {} } };
|
|
19
|
+
const url = (path, params = {}) => { const e = Object.entries(params).filter(([, v]) => v != null && v !== "").sort(([a], [b]) => a.localeCompare(b)); return e.length ? path + "?" + e.map(([k, v]) => `${k}=${encodeURIComponent(v)}`).join("&") : path; };
|
|
20
|
+
const debounce = (fn, ms) => { let t; return (...a) => { clearTimeout(t); t = setTimeout(() => fn(...a), ms); }; };
|
|
21
|
+
|
|
22
|
+
// ------------------------------------------------------------------ data source
|
|
23
|
+
const params = new URLSearchParams(location.hash.slice(1));
|
|
24
|
+
const lsGet = (k) => { try { return localStorage.getItem(k); } catch (e) { return null; } };
|
|
25
|
+
const lsSet = (k, v) => { try { localStorage.setItem(k, v); } catch (e) {} };
|
|
26
|
+
// Hosted page (not served by the daemon): talk to the user's own daemon on localhost; only a loopback address is accepted.
|
|
27
|
+
const LOCAL_HOST = /^(127\.0\.0\.1|localhost)$/.test(location.hostname);
|
|
28
|
+
const okBase = (u) => /^http:\/\/(127\.0\.0\.1|localhost):\d{2,5}$/.test(u || "");
|
|
29
|
+
if (okBase(params.get("a"))) lsSet("mw.a", params.get("a"));
|
|
30
|
+
const BASE = LOCAL_HOST ? "" : (okBase(lsGet("mw.a")) ? lsGet("mw.a") : "http://127.0.0.1:7979");
|
|
31
|
+
if (params.get("t") && !LOCAL_HOST) lsSet("mw.live", "1");
|
|
32
|
+
const DEMO = new URLSearchParams(location.search).has("demo") || (document.documentElement.dataset.demo === "1" && !lsGet("mw.live"));
|
|
33
|
+
let token = params.get("t");
|
|
34
|
+
const TOKEN_RE = /^[A-Za-z0-9._~+\-]{8,}$/;
|
|
35
|
+
const tokenStore = {
|
|
36
|
+
load() { for (const st of [() => sessionStorage, () => localStorage]) { try { const v = st().getItem("mw.t"); if (v) return v; } catch (e) {} } return null; },
|
|
37
|
+
save(t) { for (const st of [() => sessionStorage, () => localStorage]) { try { st().setItem("mw.t", t); } catch (e) {} } },
|
|
38
|
+
clear() { for (const st of [() => sessionStorage, () => localStorage]) { try { st().removeItem("mw.t"); } catch (e) {} } },
|
|
39
|
+
};
|
|
40
|
+
if (token) tokenStore.save(token); else token = tokenStore.load();
|
|
41
|
+
if (params.get("t")) history.replaceState(null, "", location.pathname + location.search + (params.get("p") ? "#p=" + params.get("p") : ""));
|
|
42
|
+
let bundle = null;
|
|
43
|
+
|
|
44
|
+
async function api(path, body, method) {
|
|
45
|
+
if (DEMO) {
|
|
46
|
+
if (body !== undefined) { toast("warn", "Read-only demo", "Install Mapwright to record steps, todos and settings."); throw new Error("demo"); }
|
|
47
|
+
if (!bundle) bundle = await (await fetch("demo.json")).json();
|
|
48
|
+
if (path in bundle) return JSON.parse(JSON.stringify(bundle[path]));
|
|
49
|
+
const k = Object.keys(bundle).find((x) => x.split("?")[0] === path.split("?")[0] && path.includes("step=live") === x.includes("step=live"));
|
|
50
|
+
if (k && /\/(version|state|settings|projects|integrations|catalog)$/.test(path.split("?")[0])) return bundle[k];
|
|
51
|
+
throw new Error("not in demo");
|
|
52
|
+
}
|
|
53
|
+
let r;
|
|
54
|
+
try { r = await fetch(BASE + path, { method: method || (body !== undefined ? "POST" : "GET"), cache: "no-store",
|
|
55
|
+
headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" }, body: body !== undefined ? JSON.stringify(body) : undefined }); }
|
|
56
|
+
catch (e) { throw Object.assign(new Error("daemon not reachable"), { network: true }); }
|
|
57
|
+
const data = await r.json().catch(() => ({}));
|
|
58
|
+
if (r.ok && token) tokenStore.save(token);
|
|
59
|
+
if (!r.ok) throw Object.assign(new Error(data.error || String(r.status)), { status: r.status });
|
|
60
|
+
return data;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ------------------------------------------------------------------ state
|
|
64
|
+
const FIXED = [
|
|
65
|
+
{ id: "system", title: "System", icon: "graph" }, { id: "overview", title: "Overview", icon: "eye" }, { id: "d:architecture", title: "Architecture", icon: "layers" },
|
|
66
|
+
{ id: "d:files", title: "Files", icon: "folder" }, { id: "d:classes", title: "Classes", icon: "class" },
|
|
67
|
+
{ id: "d:data", title: "Data", icon: "database" }, { id: "d:cloud", title: "Cloud", icon: "cloud" },
|
|
68
|
+
{ id: "d:processes", title: "Processes", icon: "route" }, { id: "logic", title: "Logic", icon: "function" },
|
|
69
|
+
{ id: "concepts", title: "Concepts", icon: "puzzle" }, { id: "timeline", title: "Timeline", icon: "history" },
|
|
70
|
+
];
|
|
71
|
+
const DTITLE = { architecture: "Architecture · layers and modules", files: "File organisation", classes: "Classes", data: "Data model",
|
|
72
|
+
cloud: "Cloud & infrastructure", processes: "API & core processes", calls: "Call graph", concepts: "Concept map" };
|
|
73
|
+
const LAYER_COLOR = { interface: "#3574f0", ui: "#2aacb8", service: "#5fb865", core: "#9b8cff", data: "#c77dbb", integration: "#e5a13e", util: "#868a91", config: "#b3ae60", test: "#6f737a" };
|
|
74
|
+
const S = {
|
|
75
|
+
projects: [], key: params.get("p") || store.get("key", null), st: null, model: null, modelFor: null, version: -1,
|
|
76
|
+
step: "live", base: "auto", tabs: store.get("tabs", []), active: store.get("active", "system"), left: store.get("left", "project"),
|
|
77
|
+
leftOpen: store.get("leftOpen", true), rightOpen: store.get("rightOpen", true), bottomOpen: store.get("bottomOpen", true), btab: store.get("btab", "steps"),
|
|
78
|
+
sel: null, settings: null, integ: null, brief: null, expanded: new Set(store.get("expanded", [])), view: {}, fnFilter: "", fnSel: null, conn: "connecting",
|
|
79
|
+
};
|
|
80
|
+
const saveUI = () => { ["tabs", "active", "left", "leftOpen", "rightOpen", "bottomOpen", "btab"].forEach((k) => store.set(k, S[k])); store.set("expanded", [...S.expanded]); store.set("key", S.key); };
|
|
81
|
+
const P = (rest) => `/v1/p/${encodeURIComponent(S.key)}/${rest}`;
|
|
82
|
+
const stepParam = () => (S.step === "live" ? "live" : String(S.step));
|
|
83
|
+
|
|
84
|
+
// ------------------------------------------------------------------ theme & mermaid
|
|
85
|
+
function cssv(n) { return getComputedStyle(document.documentElement).getPropertyValue(n).trim(); }
|
|
86
|
+
function setTheme(t) {
|
|
87
|
+
document.documentElement.dataset.theme = t; store.set("theme", t);
|
|
88
|
+
$("#w-theme").replaceChildren(icon(t === "dark" ? "sun" : "moon"));
|
|
89
|
+
const dark = t === "dark";
|
|
90
|
+
mermaid.initialize({ startOnLoad: false, securityLevel: "strict", theme: "base", maxTextSize: 900000, maxEdges: 4000,
|
|
91
|
+
flowchart: { htmlLabels: false, useMaxWidth: false, curve: "basis", padding: 12, nodeSpacing: 34, rankSpacing: 46 },
|
|
92
|
+
class: { htmlLabels: false, useMaxWidth: false }, er: { useMaxWidth: false }, state: { useMaxWidth: false },
|
|
93
|
+
themeVariables: { fontFamily: "Inter, Segoe UI, system-ui, sans-serif", fontSize: "13px", darkMode: dark,
|
|
94
|
+
background: cssv("--editor"), primaryColor: dark ? "#2b2d30" : "#f7f8fa", primaryTextColor: cssv("--text"), primaryBorderColor: dark ? "#4e5157" : "#c9ccd6",
|
|
95
|
+
secondaryColor: dark ? "#26282b" : "#ffffff", tertiaryColor: dark ? "#232427" : "#f2f3f5", lineColor: dark ? "#6f737a" : "#a8adbd",
|
|
96
|
+
clusterBkg: dark ? "rgba(255,255,255,.025)" : "rgba(53,116,240,.03)", clusterBorder: dark ? "#3c3f44" : "#dfe1e5", titleColor: cssv("--text-2"),
|
|
97
|
+
edgeLabelBackground: cssv("--editor"), nodeTextColor: cssv("--text"), mainBkg: dark ? "#2b2d30" : "#f7f8fa", attributeBackgroundColorEven: dark ? "#26282b" : "#fff",
|
|
98
|
+
attributeBackgroundColorOdd: dark ? "#2b2d30" : "#f7f8fa", classText: cssv("--text") } });
|
|
99
|
+
S.view = {}; // re-render diagrams in the new colours
|
|
100
|
+
if (S.st) renderView();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// ------------------------------------------------------------------ boot & polling
|
|
104
|
+
async function boot() {
|
|
105
|
+
setTheme(store.get("theme", "dark"));
|
|
106
|
+
wire();
|
|
107
|
+
if (!DEMO && !token) { S.conn = "token"; renderAll(); authBox("missing"); return; }
|
|
108
|
+
try {
|
|
109
|
+
const pr = await api("/v1/projects");
|
|
110
|
+
S.projects = pr.projects.filter((p) => p.exists);
|
|
111
|
+
if (!S.projects.some((p) => p.key === S.key)) S.key = S.projects[0]?.key || null;
|
|
112
|
+
S.conn = DEMO ? "demo" : "live";
|
|
113
|
+
api("/v1/settings").then((s) => { S.settings = s; if (!store.get("theme", null) && s.settings.theme) setTheme(s.settings.theme); }).catch(() => {});
|
|
114
|
+
} catch (e) { S.conn = e.status === 401 ? "token" : "offline"; renderAll(); if (e.status === 401) authBox("rejected"); else offlineBox(); return; }
|
|
115
|
+
if (!S.key) { renderAll(); welcome(); return; }
|
|
116
|
+
await load(true);
|
|
117
|
+
setInterval(poll, 1500);
|
|
118
|
+
}
|
|
119
|
+
async function poll() {
|
|
120
|
+
if (!S.key || document.hidden) return;
|
|
121
|
+
try {
|
|
122
|
+
const v = await api(P("version"));
|
|
123
|
+
if (S.conn !== "live" && !DEMO) { S.conn = "live"; renderStatus(); }
|
|
124
|
+
if (v.version !== S.version || v.journal !== S.journal) { S.journal = v.journal; await load(false); }
|
|
125
|
+
} catch (e) { if (!DEMO) { if (e.status === 401) { S.conn = "token"; S.st = null; renderAll(); authBox("rejected"); } else { S.conn = "offline"; renderStatus(); } } }
|
|
126
|
+
}
|
|
127
|
+
// ---- first-run / unauthorised / offline states (the token is never written into the DOM)
|
|
128
|
+
function parseToken(text) {
|
|
129
|
+
const raw = String(text || "").trim(); if (!raw) return null;
|
|
130
|
+
let t = null, p = null;
|
|
131
|
+
const h = raw.includes("#") ? raw.slice(raw.indexOf("#") + 1) : raw.includes("t=") ? raw : "";
|
|
132
|
+
if (h) { const q = new URLSearchParams(h); t = q.get("t"); p = q.get("p"); }
|
|
133
|
+
if (!t && !h) t = raw;
|
|
134
|
+
return t && TOKEN_RE.test(t) ? { t, p } : null;
|
|
135
|
+
}
|
|
136
|
+
function forgetToken() { tokenStore.clear(); token = null; S.conn = "token"; S.st = null; S.projects = []; toast("ok", "Token forgotten", "Run `mapwright open` to sign in again."); closeMenus(); renderAll(); authBox("missing"); }
|
|
137
|
+
function stateBox(id, title, paras, cmd) {
|
|
138
|
+
const v = $("#view"); v.replaceChildren();
|
|
139
|
+
const w = el("div", "welcome"), b = el("div", "box"); b.id = id; b.dataset.testid = id;
|
|
140
|
+
const h = el("h1"); const img = el("img"); img.src = "mark.svg"; img.width = 34; img.alt = ""; h.append(img, document.createTextNode(title));
|
|
141
|
+
b.append(h); paras.forEach((t) => b.append(el("p", null, t)));
|
|
142
|
+
if (cmd) { const c = el("div", "cmd"); c.append(el("code", null, cmd)); const cp = el("button", "btn sm", "Copy"); cp.onclick = () => { navigator.clipboard?.writeText(cmd); toast("ok", "Copied", cmd); }; c.append(cp); b.append(c); }
|
|
143
|
+
w.append(b); v.append(w); return b;
|
|
144
|
+
}
|
|
145
|
+
function authBox(why) {
|
|
146
|
+
const b = stateBox("auth-box", "Unauthorised", [why === "rejected" ? "The saved token is not valid any more (the daemon was probably reset)." : "This page needs a local access token, which comes with the link that `mapwright open` prints.",
|
|
147
|
+
"Run this in a terminal to open Mapwright with the right link:"], "mapwright open");
|
|
148
|
+
b.append(el("p", null, "Or paste that link (it ends in #p=…&t=…) or just the token here:"));
|
|
149
|
+
const row = el("div", "actions"); const inp = el("input", "input"); inp.id = "auth-input"; inp.type = "password"; inp.autocomplete = "off"; inp.spellcheck = false; inp.placeholder = "Link or token"; inp.style.flex = "1";
|
|
150
|
+
const go = el("button", "btn primary", "Use token"); go.id = "auth-go";
|
|
151
|
+
const apply = () => { const r = parseToken(inp.value); if (!r) { toast("err", "That does not look like a link or token", "Paste the full link from `mapwright open`."); return; }
|
|
152
|
+
tokenStore.save(r.t); if (r.p) store.set("key", r.p); inp.value = ""; location.hash = ""; location.reload(); };
|
|
153
|
+
go.onclick = apply; inp.onkeydown = (e) => { if (e.key === "Enter") apply(); };
|
|
154
|
+
row.append(inp, go); b.append(row);
|
|
155
|
+
if (token) { const f = el("button", "btn sm", "Forget saved token"); f.id = "auth-forget"; f.onclick = forgetToken; b.append(Object.assign(el("div", "actions"), {})); b.lastChild.append(f); }
|
|
156
|
+
setTimeout(() => inp.focus(), 0);
|
|
157
|
+
}
|
|
158
|
+
function offlineBox() {
|
|
159
|
+
const b = stateBox("offline-box", "Mapwright is not running", ["The local daemon did not answer on this address. Start it in a terminal:"], "mapwright up -d");
|
|
160
|
+
const row = el("div", "actions"); const r = el("button", "btn primary", "Retry"); r.id = "offline-retry"; r.onclick = () => location.reload(); row.append(r); b.append(row);
|
|
161
|
+
}
|
|
162
|
+
async function load(first) {
|
|
163
|
+
const [st, integ] = await Promise.all([api(P("state")), first || !S.integ ? api(url("/v1/integrations", { key: S.key })).catch(() => null) : Promise.resolve(S.integ)]);
|
|
164
|
+
const prevSteps = S.st ? S.st.steps.length : 0;
|
|
165
|
+
S.st = st; S.version = st.version; S.integ = integ; S.model = null; S.brief = null;
|
|
166
|
+
if (!first && st.steps.length > prevSteps) { const s = st.steps[st.steps.length - 1]; toast("ok", `Step ${s.n} recorded`, s.title); }
|
|
167
|
+
if (S.step !== "live" && !st.steps.some((s) => s.n === S.step)) S.step = "live";
|
|
168
|
+
api(url(P("brief"), {})).then((b) => { S.brief = b; renderStatus(); }).catch(() => {});
|
|
169
|
+
if (first && !S.tabs.length) S.tabs = [];
|
|
170
|
+
renderAll();
|
|
171
|
+
}
|
|
172
|
+
async function model() {
|
|
173
|
+
const want = stepParam() + ":" + S.version;
|
|
174
|
+
if (S.model && S.modelFor === want) return S.model;
|
|
175
|
+
S.model = await api(url(P("model"), { step: stepParam() })); S.modelFor = want; return S.model;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ------------------------------------------------------------------ rendering: frame
|
|
179
|
+
function renderAll() {
|
|
180
|
+
const ide = $("#ide");
|
|
181
|
+
ide.style.setProperty("--lw", S.leftOpen ? store.get("lw", 280) + "px" : "0px");
|
|
182
|
+
ide.style.setProperty("--rw", S.rightOpen ? store.get("rw", 320) + "px" : "0px");
|
|
183
|
+
$("#left").hidden = !S.leftOpen; $("#right").hidden = !S.rightOpen; $("#bottom").hidden = !S.bottomOpen;
|
|
184
|
+
$("#bottom").style.setProperty("--bh", store.get("bh", 220) + "px");
|
|
185
|
+
renderToolbar(); renderStripes(); renderLeft(); renderTabs(); renderView(); renderRight(); renderBottom(); renderStatus();
|
|
186
|
+
}
|
|
187
|
+
function renderToolbar() {
|
|
188
|
+
const p = S.projects.find((x) => x.key === S.key);
|
|
189
|
+
const gated = !DEMO && (S.conn === "token" || S.conn === "offline") && !S.st;
|
|
190
|
+
for (const id of ["w-project", "w-step", "w-step-add", "w-agents", "w-search"]) { const n = $("#" + id); n.disabled = gated; n.classList.toggle("gated", gated); n.setAttribute("aria-disabled", gated); }
|
|
191
|
+
if (gated) { $("#w-project-name").textContent = "—"; $("#w-project").title = ""; $("#w-step-badge").textContent = "—"; $("#w-step").classList.remove("live"); $("#w-step-name").textContent = ""; $("#w-agents-dot").className = "ldot"; $("#w-agents-txt").textContent = S.conn === "token" ? "signed out" : "offline"; return; }
|
|
192
|
+
$("#w-project-name").textContent = p ? p.name : "No project";
|
|
193
|
+
$("#w-project").title = p ? p.root : "Choose a project";
|
|
194
|
+
const live = S.step === "live", st = S.st;
|
|
195
|
+
$("#w-step").classList.toggle("live", live);
|
|
196
|
+
$("#w-step-badge").textContent = live ? "LIVE" : "STEP " + S.step;
|
|
197
|
+
const s = st && !live ? st.steps.find((x) => x.n === S.step) : null;
|
|
198
|
+
$("#w-step-name").textContent = live ? (st ? `${st.pending.length} change${st.pending.length === 1 ? "" : "s"} since step ${st.steps.length ? st.steps[st.steps.length - 1].n : 0}` : "") : (s ? s.title : "");
|
|
199
|
+
const conn = (S.integ?.targets || []).filter((t) => Object.values(t.scopes || {}).some((x) => x.connected));
|
|
200
|
+
$("#w-agents-dot").className = "ldot " + (conn.length ? "on" : "");
|
|
201
|
+
$("#w-agents-txt").textContent = conn.length ? conn.map((t) => t.title.split(" (")[0]).slice(0, 2).join(", ") + (conn.length > 2 ? ` +${conn.length - 2}` : "") : DEMO ? "demo" : "connect an agent";
|
|
202
|
+
}
|
|
203
|
+
const LEFT = [["project", "folder", "Project"], ["structure", "list", "Structure"], ["concepts", "puzzle", "Mechanisms"], ["setup", "plug", "Connect"]];
|
|
204
|
+
const BOTTOM = [["steps", "history", "Steps"], ["todo", "check-square", "TODO"], ["problems", "warning", "Problems"], ["activity", "activity", "Activity"]];
|
|
205
|
+
function renderStripes() {
|
|
206
|
+
const l = $("#stripe-l"); l.replaceChildren();
|
|
207
|
+
for (const [id, ic, title] of LEFT) {
|
|
208
|
+
const b = el("button", "sbtn" + (S.leftOpen && S.left === id ? " on" : "")); b.title = title; b.append(icon(ic));
|
|
209
|
+
b.onclick = () => { if (id === "setup") { openTab({ id: "setup", title: "Connect an agent", icon: "plug" }); return; } if (S.left === id && S.leftOpen) S.leftOpen = false; else { S.left = id; S.leftOpen = true; } saveUI(); renderAll(); };
|
|
210
|
+
l.append(b);
|
|
211
|
+
}
|
|
212
|
+
l.append(el("div", "grow"));
|
|
213
|
+
for (const [id, ic, title] of BOTTOM) {
|
|
214
|
+
const b = el("button", "sbtn" + (S.bottomOpen && S.btab === id ? " on" : "")); b.title = title; b.append(icon(ic));
|
|
215
|
+
const n = id === "problems" ? (S.st?.problems.length || 0) : id === "todo" ? (S.st?.todos.filter((t) => t.status === "open").length || 0) : 0;
|
|
216
|
+
if (n && id === "problems") b.append(el("span", "dot"));
|
|
217
|
+
b.onclick = () => { if (S.btab === id && S.bottomOpen) S.bottomOpen = false; else { S.btab = id; S.bottomOpen = true; } saveUI(); renderAll(); };
|
|
218
|
+
l.append(b);
|
|
219
|
+
}
|
|
220
|
+
const r = $("#stripe-r"); r.replaceChildren();
|
|
221
|
+
for (const [id, ic, title] of [["inspector", "info", "Inspector"], ["brief", "doc", "Agent brief"]]) {
|
|
222
|
+
const b = el("button", "sbtn" + (S.rightOpen && (S.rightMode || "inspector") === id ? " on" : "")); b.title = title; b.append(icon(ic));
|
|
223
|
+
b.onclick = () => { if ((S.rightMode || "inspector") === id && S.rightOpen) S.rightOpen = false; else { S.rightMode = id; S.rightOpen = true; } saveUI(); renderAll(); };
|
|
224
|
+
r.append(b);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// ------------------------------------------------------------------ left panel
|
|
229
|
+
function fileIcon(path, dir) {
|
|
230
|
+
if (dir) { const s = el("span", "ficon dir"); s.append(icon("folder")); return s; }
|
|
231
|
+
const ext = (path.split(".").pop() || "").toLowerCase(), name = base(path);
|
|
232
|
+
const map = { py: ["py", "PY"], js: ["js", "JS"], jsx: ["js", "JSX"], mjs: ["js", "JS"], ts: ["ts", "TS"], tsx: ["ts", "TSX"], sql: ["sql", "SQL"], prisma: ["prisma", "PR"],
|
|
233
|
+
md: ["md", "MD"], json: ["json", "{}"], yaml: ["yaml", "Y"], yml: ["yml", "Y"], toml: ["toml", "T"], css: ["css", "#"], html: ["html", "<>"], tf: ["tf", "TF"] };
|
|
234
|
+
const [cls, txt] = /dockerfile|compose/i.test(name) ? ["docker", "D"] : map[ext] || ["other", ext.slice(0, 2).toUpperCase() || "·"];
|
|
235
|
+
return el("span", "ficon " + cls, txt);
|
|
236
|
+
}
|
|
237
|
+
function renderLeft() {
|
|
238
|
+
const body = $("#left-body"), tools = $("#left-tools"); body.replaceChildren(); tools.replaceChildren();
|
|
239
|
+
const title = LEFT.find((x) => x[0] === S.left)?.[2] || "Project"; $("#left-title").textContent = title;
|
|
240
|
+
if (!S.st) { body.append(el("div", "empty", "No project yet.")); return; }
|
|
241
|
+
if (S.left === "project") projectTree(body, tools);
|
|
242
|
+
else if (S.left === "structure") structurePanel(body);
|
|
243
|
+
else if (S.left === "concepts") conceptList(body);
|
|
244
|
+
}
|
|
245
|
+
function projectTree(body, tools) {
|
|
246
|
+
const collapse = el("button", "tbtn"); collapse.title = "Collapse all"; collapse.append(icon("minus")); collapse.onclick = () => { S.expanded.clear(); saveUI(); renderLeft(); };
|
|
247
|
+
const changed = el("button", "tbtn" + (S.onlyChanged ? " on" : "")); changed.title = "Only changed files"; changed.append(icon("diff")); changed.onclick = () => { S.onlyChanged = !S.onlyChanged; renderLeft(); };
|
|
248
|
+
tools.append(changed, collapse);
|
|
249
|
+
const f = el("div", "filter"); f.append(icon("search")); const inp = el("input"); inp.placeholder = "Filter files"; inp.value = S.treeFilter || ""; f.append(inp); body.append(f);
|
|
250
|
+
inp.oninput = debounce(() => { S.treeFilter = inp.value; drawTree(); }, 120);
|
|
251
|
+
const tree = el("div", "tree"); body.append(tree);
|
|
252
|
+
const drawTree = () => {
|
|
253
|
+
tree.replaceChildren();
|
|
254
|
+
const q = (S.treeFilter || "").toLowerCase();
|
|
255
|
+
let files = S.st.files;
|
|
256
|
+
if (S.onlyChanged) files = files.filter((x) => x.status);
|
|
257
|
+
if (q) files = files.filter((x) => x.path.toLowerCase().includes(q));
|
|
258
|
+
const root = {};
|
|
259
|
+
for (const fl of files) { let cur = root; const parts = fl.path.split("/"); parts.slice(0, -1).forEach((p) => { cur = cur[p + "/"] = cur[p + "/"] || {}; }); cur[parts[parts.length - 1]] = fl; }
|
|
260
|
+
const walk = (node, depth, prefix) => {
|
|
261
|
+
const dirs = Object.keys(node).filter((k) => k.endsWith("/")).sort(), leaves = Object.keys(node).filter((k) => !k.endsWith("/")).sort();
|
|
262
|
+
for (const d of dirs) {
|
|
263
|
+
const full = prefix + d, open = q || S.onlyChanged || S.expanded.has(full);
|
|
264
|
+
const r = el("div", "row"); r.style.paddingLeft = 6 + depth * 14 + "px";
|
|
265
|
+
const tw = el("span", "tw"); tw.append(icon(open ? "chevron-down" : "chevron-right")); r.append(tw, fileIcon(d, true), el("span", "nm", d.slice(0, -1)));
|
|
266
|
+
const ch = countChanged(node[d]); if (ch) r.append(el("span", "meta", `${ch} changed`));
|
|
267
|
+
r.onclick = () => { open ? S.expanded.delete(full) : S.expanded.add(full); saveUI(); drawTree(); };
|
|
268
|
+
tree.append(r);
|
|
269
|
+
if (open) walk(node[d], depth + 1, full);
|
|
270
|
+
}
|
|
271
|
+
for (const lf of leaves) {
|
|
272
|
+
const fl = node[lf];
|
|
273
|
+
const r = el("div", "row" + (fl.status ? " " + fl.status : "") + (fl.secret ? " secret" : "") + (S.sel?.kind === "file" && S.sel.ref === fl.path ? " sel" : ""));
|
|
274
|
+
r.style.paddingLeft = 6 + depth * 14 + 12 + "px"; r.title = fl.path + (fl.secret ? " (secret-looking: never read)" : "");
|
|
275
|
+
r.append(fileIcon(fl.path), el("span", "nm", lf));
|
|
276
|
+
if (fl.status) r.append(el("span", "meta", { A: "added", M: "modified", D: "deleted" }[fl.status]));
|
|
277
|
+
else if (fl.functions) r.append(el("span", "meta", `${fl.functions} fn`));
|
|
278
|
+
r.onclick = () => select({ kind: "file", ref: fl.path, file: fl.path });
|
|
279
|
+
r.ondblclick = () => fl.status !== "D" && !fl.secret && openFile(fl.path);
|
|
280
|
+
tree.append(r);
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
walk(root, 0, "");
|
|
284
|
+
if (!files.length) tree.append(el("div", "empty", S.onlyChanged ? "No changes since the last step." : "No files match."));
|
|
285
|
+
};
|
|
286
|
+
drawTree();
|
|
287
|
+
}
|
|
288
|
+
function countChanged(node) { let n = 0; for (const [k, v] of Object.entries(node)) n += k.endsWith("/") ? countChanged(v) : v.status ? 1 : 0; return n; }
|
|
289
|
+
async function structurePanel(body) {
|
|
290
|
+
const path = S.sel?.file || (S.active.startsWith("file:") ? S.active.slice(5) : null);
|
|
291
|
+
if (!path) { body.append(el("div", "empty", "Select a file in the Project panel or a node in a diagram to see its classes and functions.")); return; }
|
|
292
|
+
body.append(el("div", "section", base(path)));
|
|
293
|
+
try {
|
|
294
|
+
const f = await api(url(P("file"), { path, step: stepParam() }));
|
|
295
|
+
const list = el("div", "tree");
|
|
296
|
+
for (const s of (f.symbols || []).sort((a, b) => a.line - b.line)) {
|
|
297
|
+
const r = el("div", "row"); r.style.paddingLeft = (s.kind === "function" && s.qual.includes(".") ? 22 : 8) + "px";
|
|
298
|
+
r.append(icon(s.kind === "class" ? "class" : "function"), el("span", "nm", s.qual.split(".").pop()), el("span", "meta", s.kind === "function" ? `cx ${s.complexity} · ${s.line}` : String(s.line)));
|
|
299
|
+
r.onclick = () => s.fid ? select({ kind: "function", ref: s.fid, file: path, line: s.line }) : openFile(path, s.line);
|
|
300
|
+
r.ondblclick = () => s.fid ? openFlow(s.fid) : openFile(path, s.line);
|
|
301
|
+
list.append(r);
|
|
302
|
+
}
|
|
303
|
+
if (!f.symbols?.length) list.append(el("div", "empty", "No classes or functions in this file."));
|
|
304
|
+
body.append(list);
|
|
305
|
+
} catch (e) { body.append(el("div", "empty", "Not available for this file.")); }
|
|
306
|
+
}
|
|
307
|
+
function conceptList(body) {
|
|
308
|
+
const list = el("div", "tree");
|
|
309
|
+
for (const c of S.st.concepts) {
|
|
310
|
+
const r = el("div", "row"); r.append(icon(c.icon), el("span", "nm", c.title));
|
|
311
|
+
const cl = c.claims.length ? c.claims.every((x) => x.status === "verified") ? "claimed ✓" : "claimed ?" : "";
|
|
312
|
+
r.append(el("span", "meta", cl || `${c.evidence.length}`));
|
|
313
|
+
r.onclick = () => { select({ kind: "concept", ref: c.id }); openTab(FIXED.find((t) => t.id === "concepts")); };
|
|
314
|
+
list.append(r);
|
|
315
|
+
}
|
|
316
|
+
if (!S.st.concepts.length) list.append(el("div", "empty", "No mechanisms detected yet. They appear as code that uses caching, queues, auth, retries and so on is written."));
|
|
317
|
+
body.append(list);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// ------------------------------------------------------------------ tabs
|
|
321
|
+
function allTabs() { return [...FIXED, ...S.tabs]; }
|
|
322
|
+
function openTab(t) { if (!t) return; if (!FIXED.some((x) => x.id === t.id) && !S.tabs.some((x) => x.id === t.id)) S.tabs.push(t); S.active = t.id; saveUI(); renderTabs(); renderView(); renderStatus(); if (S.left === "structure") renderLeft(); }
|
|
323
|
+
function closeTab(id) { S.tabs = S.tabs.filter((t) => t.id !== id); if (S.active === id) S.active = S.tabs.length ? S.tabs[S.tabs.length - 1].id : "overview"; delete S.view[id]; saveUI(); renderTabs(); renderView(); }
|
|
324
|
+
function renderTabs() {
|
|
325
|
+
const box = $("#tabs"); box.replaceChildren();
|
|
326
|
+
for (const t of allTabs()) {
|
|
327
|
+
const fixed = FIXED.some((x) => x.id === t.id);
|
|
328
|
+
const tab = el("div", "tab" + (S.active === t.id ? " on" : "")); tab.setAttribute("role", "tab"); tab.title = t.hint || t.title;
|
|
329
|
+
tab.append(t.file ? fileIcon(t.file) : icon(t.icon || "file"), el("span", null, t.title));
|
|
330
|
+
if (!fixed) { const x = el("span", "x"); x.append(icon("close")); x.onclick = (e) => { e.stopPropagation(); closeTab(t.id); }; tab.append(x); }
|
|
331
|
+
tab.onclick = () => { S.active = t.id; saveUI(); renderTabs(); renderView(); renderStatus(); };
|
|
332
|
+
tab.onauxclick = (e) => { if (e.button === 1 && !fixed) closeTab(t.id); };
|
|
333
|
+
box.append(tab);
|
|
334
|
+
}
|
|
335
|
+
box.querySelector(".tab.on")?.scrollIntoView({ block: "nearest", inline: "nearest" });
|
|
336
|
+
}
|
|
337
|
+
const openFile = (path, line) => { openTab({ id: "file:" + path, title: base(path), file: path, hint: path }); if (line) { S.view["file:" + path] = { line }; renderView(); } };
|
|
338
|
+
const openFlow = (fid) => openTab({ id: "flow:" + fid, title: short(fid) + "()", icon: "function", hint: "Flowchart of " + fid });
|
|
339
|
+
const openDiff = (path, from, to) => openTab({ id: `diff:${path}|${from}|${to}`, title: base(path), icon: "diff", hint: `${path}: step ${from} → ${to}` });
|
|
340
|
+
|
|
341
|
+
// ------------------------------------------------------------------ views
|
|
342
|
+
function renderView() {
|
|
343
|
+
const v = $("#view");
|
|
344
|
+
if (!S.st) return;
|
|
345
|
+
const id = S.active;
|
|
346
|
+
v.replaceChildren();
|
|
347
|
+
if (id === "overview") overview(v);
|
|
348
|
+
else if (id.startsWith("d:")) diagramView(v, id.slice(2));
|
|
349
|
+
else if (id === "logic") logicView(v);
|
|
350
|
+
else if (id === "concepts") conceptsView(v);
|
|
351
|
+
else if (id === "system") systemView(v);
|
|
352
|
+
else if (id === "timeline") timelineView(v);
|
|
353
|
+
else if (id === "setup") setupView(v);
|
|
354
|
+
else if (id.startsWith("file:")) fileView(v, id.slice(5));
|
|
355
|
+
else if (id.startsWith("flow:")) flowView(v, id.slice(5));
|
|
356
|
+
else if (id.startsWith("diff:")) { const [path, from, to] = id.slice(5).split("|"); diffView(v, path, from, to); }
|
|
357
|
+
else { S.active = "overview"; overview(v); }
|
|
358
|
+
}
|
|
359
|
+
function welcome(msg) {
|
|
360
|
+
const v = $("#view"); v.replaceChildren();
|
|
361
|
+
const w = el("div", "welcome"), b = el("div", "box");
|
|
362
|
+
const h = el("h1"); const img = el("img"); img.src = "mark.svg"; img.width = 34; h.append(img, document.createTextNode("Welcome to Mapwright"));
|
|
363
|
+
b.append(h, el("p", null, msg || "A live map of what your coding agent is building: structure, architecture, data, cloud, logic and every step it takes."));
|
|
364
|
+
if (!msg || S.conn === "live") {
|
|
365
|
+
const row = el("div", "actions"); const inp = el("input", "input"); inp.placeholder = "/path/to/your/project"; inp.style.flex = "1";
|
|
366
|
+
const go = el("button", "btn primary", "Track folder"); go.onclick = async () => { try { const r = await api("/v1/projects", { root: inp.value.trim() }); S.key = r.key; saveUI(); location.reload(); } catch (e) { toast("err", "Could not track that folder", e.message); } };
|
|
367
|
+
row.append(inp, go); b.append(row, el("p", null, "Or run `mapwright init` inside the project. Then connect your agent from the Connect panel."));
|
|
368
|
+
}
|
|
369
|
+
w.append(b); v.append(w);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// ---- system view: an abstract, icon-based picture of the whole system, built from the analysis
|
|
373
|
+
const SYS_NODE = { w: 184, h: 84, gx: 64, gy: 22, top: 56, left: 28 };
|
|
374
|
+
async function buildSystem() {
|
|
375
|
+
const m = await model(), st = S.st, files = st.files || [];
|
|
376
|
+
const byLayer = {}; for (const mod of Object.values(m.modules || {})) (byLayer[mod.layer] = byLayer[mod.layer] || []).push(mod.file);
|
|
377
|
+
const status = (paths) => { const set = new Set(paths); let a = 0, c = 0; for (const f of files) if (set.has(f.path)) { if (f.status === "A") a++; else if (f.status === "M") c++; } return a ? "new" : c ? "changed" : null; };
|
|
378
|
+
const fileRows = (paths) => [...new Set(paths)].sort().map((p) => ({ label: base(p), meta: p.includes("/") ? p.slice(0, p.lastIndexOf("/")) : "", run: () => openFile(p) }));
|
|
379
|
+
const fnRows = (paths) => { const set = new Set(paths); return Object.entries(m.functions || {}).filter(([, f]) => set.has(f.file)).sort((a, b) => (b[1].complexity || 0) - (a[1].complexity || 0)).slice(0, 12).map(([id, f]) => ({ label: f.qual, meta: `cx ${f.complexity || 0}`, run: () => select({ kind: "function", ref: id, file: f.file, line: f.line }) })); };
|
|
380
|
+
const infra = (st.infra && st.infra.nodes) || [];
|
|
381
|
+
const infraRows = (nodes) => nodes.map((n) => ({ label: n.label, meta: n.kind, run: () => select({ kind: "infra", ref: n.id }) }));
|
|
382
|
+
const comps = [];
|
|
383
|
+
const add = (c) => { c.sections = c.sections || []; c.stats = c.stats || []; c.state = c.state || status(c.files || []); comps.push(c); };
|
|
384
|
+
const routes = m.routes || [], pages = routes.filter((r) => r.method === "PAGE"), api = routes.filter((r) => r.method !== "PAGE");
|
|
385
|
+
const routeRows = (rs) => rs.slice(0, 40).map((r) => ({ label: `${r.method} ${r.path}`, meta: r.handler || "", run: () => (r.fid ? select({ kind: "function", ref: r.fid, file: r.file, line: r.line }) : r.file && openFile(r.file, r.line)) }));
|
|
386
|
+
add({ id: "clients", tier: 0, icon: "user", title: "Users & clients", sub: pages.length ? `${pages.length} pages` : "browsers · apps · agents", desc: "Whoever or whatever calls the system: people in a browser, other services, agents.",
|
|
387
|
+
files: [], stats: [["pages", pages.length], ["API routes", api.length]], sections: [{ title: "Pages", rows: routeRows(pages) }] });
|
|
388
|
+
const ui = byLayer.ui || [], itf = byLayer.interface || [];
|
|
389
|
+
if (ui.length || pages.length) add({ id: "ui", tier: 1, icon: "eye", title: "User interface", sub: `${ui.length} modules`, desc: "Screens and components the user sees.", files: ui,
|
|
390
|
+
stats: [["modules", ui.length], ["functions", fnRows(ui).length ? Object.values(m.functions || {}).filter((f) => ui.includes(f.file)).length : 0]], sections: [{ title: "Modules", rows: fileRows(ui) }, { title: "Most complex", rows: fnRows(ui) }] });
|
|
391
|
+
if (itf.length || api.length) add({ id: "api", tier: 1, icon: "route", title: "API & interface", sub: api.length ? `${api.length} routes` : `${itf.length} modules`, desc: "Entry points: HTTP routes, CLI commands, handlers.", files: itf,
|
|
392
|
+
stats: [["routes", api.length], ["modules", itf.length]], sections: [{ title: "Routes", rows: routeRows(api) }, { title: "Modules", rows: fileRows(itf) }, { title: "Most complex", rows: fnRows(itf) }] });
|
|
393
|
+
const svc = byLayer.service || [], core = byLayer.core || [];
|
|
394
|
+
if (svc.length) add({ id: "services", tier: 2, icon: "box", title: "Services", sub: `${svc.length} modules`, desc: "Business logic: what the system actually does.", files: svc,
|
|
395
|
+
stats: [["modules", svc.length]], sections: [{ title: "Modules", rows: fileRows(svc) }, { title: "Most complex", rows: fnRows(svc) }] });
|
|
396
|
+
if (core.length) add({ id: "core", tier: 2, icon: "function", title: "Core logic", sub: `${core.length} modules`, desc: "Shared domain code used by the other layers.", files: core,
|
|
397
|
+
stats: [["modules", core.length]], sections: [{ title: "Modules", rows: fileRows(core) }, { title: "Most complex", rows: fnRows(core) }] });
|
|
398
|
+
const tables = Object.entries(m.tables || {}), dbNodes = infra.filter((n) => n.kind === "db");
|
|
399
|
+
const dfiles = [...(byLayer.data || []), ...tables.map(([, t]) => t.file).filter(Boolean)];
|
|
400
|
+
if (tables.length || dbNodes.length || (byLayer.data || []).length) add({ id: "db", tier: 3, icon: "database", title: "Database", sub: tables.length ? `${tables.length} tables` : dbNodes[0]?.label || "data layer", desc: "Where data is stored: tables, collections and their access rules.", files: dfiles,
|
|
401
|
+
stats: [["tables", tables.length], ["engines", dbNodes.length]], sections: [{ title: "Engines", rows: infraRows(dbNodes) }, { title: "Tables and collections", rows: tables.map(([k, t]) => ({ label: t.name || k, meta: t.kind || t.source || "", run: () => select({ kind: "table", ref: k, file: t.file, line: t.line }) })) }, { title: "Data code", rows: fileRows(byLayer.data || []) }] });
|
|
402
|
+
for (const [kind, id, ic, title, d] of [["cache", "cache", "bolt", "Cache", "Fast temporary storage in front of slower data."], ["queue", "queue", "radio", "Queue & jobs", "Work handed off to run later or elsewhere."], ["search", "search", "search", "Search", "Full-text or vector search index."]]) {
|
|
403
|
+
const ns = infra.filter((n) => n.kind === kind); if (ns.length) add({ id, tier: 3, icon: ic, title, sub: ns.map((n) => n.label).join(", "), desc: d, files: [], stats: [["nodes", ns.length]], sections: [{ title: "Found in", rows: infraRows(ns) }] });
|
|
404
|
+
}
|
|
405
|
+
const intg = byLayer.integration || [], ext = infra.filter((n) => n.kind === "external" || n.kind === "cloud");
|
|
406
|
+
if (intg.length) add({ id: "integrations", tier: 4, icon: "plug", title: "Integrations", sub: `${intg.length} modules`, desc: "Code that talks to outside services.", files: intg, stats: [["modules", intg.length]], sections: [{ title: "Modules", rows: fileRows(intg) }, { title: "Most complex", rows: fnRows(intg) }] });
|
|
407
|
+
for (const n of ext.slice(0, 8)) add({ id: "x:" + n.id, tier: 4, icon: n.kind === "cloud" ? "cloud" : "globe", title: n.label, sub: n.kind === "cloud" ? "cloud platform" : "external service", desc: n.detail || "An outside service the system depends on.", files: n.sources || [], stats: [["kind", n.kind]], sections: [{ title: "Seen in", rows: fileRows((n.sources || []).filter((s) => files.some((f) => f.path === s))) }] });
|
|
408
|
+
if (ext.length > 8) add({ id: "x:more", tier: 4, icon: "globe", title: `+${ext.length - 8} more`, sub: "external services", desc: "More outside services.", files: [], stats: [["count", ext.length - 8]], sections: [{ title: "Services", rows: infraRows(ext.slice(8)) }] });
|
|
409
|
+
const plat = infra.filter((n) => !["db", "cache", "queue", "search", "external", "cloud", "app"].includes(n.kind));
|
|
410
|
+
for (const [kinds, id, ic, title, d] of [[["container"], "containers", "server", "Containers", "How the system is packaged and run."], [["ci"], "ci", "rotate", "CI / CD", "Automated build, test and deploy."], [["cdn", "function", "hosting"], "hosting", "cloud", "Hosting & functions", "Where it is deployed."]]) {
|
|
411
|
+
const ns = plat.filter((n) => kinds.includes(n.kind)); if (ns.length) add({ id, tier: 5, icon: ic, title, sub: ns.length + (ns.length === 1 ? " item" : " items"), desc: d, files: ns.flatMap((n) => n.sources || []), stats: [["items", ns.length]], sections: [{ title: "Found in", rows: infraRows(ns) }] });
|
|
412
|
+
}
|
|
413
|
+
const tests = byLayer.test || []; if (tests.length) add({ id: "tests", tier: 5, icon: "beaker", title: "Tests", sub: `${tests.length} files`, desc: "Automated checks.", files: tests, stats: [["files", tests.length]], sections: [{ title: "Files", rows: fileRows(tests) }] });
|
|
414
|
+
return comps;
|
|
415
|
+
}
|
|
416
|
+
async function systemView(v) {
|
|
417
|
+
const sc = el("div", "scroll sys"); v.append(sc);
|
|
418
|
+
let comps; try { comps = await buildSystem(); } catch (e) { sc.append(el("div", "empty", "The system picture is not available for this step.")); return; }
|
|
419
|
+
if (S.active !== "system") return;
|
|
420
|
+
S.sysComps = Object.fromEntries(comps.map((c) => [c.id, c]));
|
|
421
|
+
const { w, h, gx, gy, top, left } = SYS_NODE, main = [0, 1, 2, 3, 4].filter((t) => comps.some((c) => c.tier === t));
|
|
422
|
+
const TIER = ["Clients", "Interface", "Logic", "Data", "Outside"];
|
|
423
|
+
const col = Object.fromEntries(main.map((t, i) => [t, i])), pos = {};
|
|
424
|
+
let maxRows = 1; for (const t of main) { const cs = comps.filter((c) => c.tier === t); maxRows = Math.max(maxRows, cs.length); cs.forEach((c, i) => { pos[c.id] = { x: left + col[t] * (w + gx), y: top + i * (h + gy), c }; }); }
|
|
425
|
+
const plat = comps.filter((c) => c.tier === 5), W = Math.max(main.length * (w + gx) - gx + left * 2, plat.length * (w + 20) + left * 2, 480);
|
|
426
|
+
const platY = top + maxRows * (h + gy) + 44;
|
|
427
|
+
plat.forEach((c, i) => { pos[c.id] = { x: left + i * (w + 20), y: platY, c }; });
|
|
428
|
+
const H = plat.length ? platY + h + 28 : top + maxRows * (h + gy) + 10;
|
|
429
|
+
const svg = document.createElementNS(NS, "svg"); svg.setAttribute("class", "sysmap"); svg.setAttribute("width", W); svg.setAttribute("height", H); svg.setAttribute("viewBox", `0 0 ${W} ${H}`);
|
|
430
|
+
const mk = (tag, attrs, parent = svg) => { const n = document.createElementNS(NS, tag); for (const [k, val] of Object.entries(attrs || {})) n.setAttribute(k, val); parent.append(n); return n; };
|
|
431
|
+
const defs = mk("defs"), mark = mk("marker", { id: "sysarrow", viewBox: "0 0 10 10", refX: 9, refY: 5, markerWidth: 7, markerHeight: 7, orient: "auto-start-reverse" }, defs); mk("path", { d: "M0 1 L9 5 L0 9z", class: "sysarrowhead" }, mark);
|
|
432
|
+
main.forEach((t, i) => { const lb = mk("text", { x: left + i * (w + gx), y: 30, class: "systier" }); lb.textContent = TIER[t].toUpperCase(); });
|
|
433
|
+
if (plat.length) { const lb = mk("text", { x: left, y: platY - 16, class: "systier" }); lb.textContent = "PLATFORM"; mk("line", { x1: left, x2: W - left, y1: platY - 30, y2: platY - 30, class: "sysrule" }); }
|
|
434
|
+
const link = (a, b) => { const p = pos[a], q = pos[b], x1 = p.x + w, y1 = p.y + h / 2, x2 = q.x, y2 = q.y + h / 2, mx = (x1 + x2) / 2; mk("path", { d: `M${x1} ${y1} C${mx} ${y1} ${mx} ${y2} ${x2 - 2} ${y2}`, class: "sysedge", "marker-end": "url(#sysarrow)" }); };
|
|
435
|
+
for (let i = 0; i < main.length - 1; i++) {
|
|
436
|
+
const A = comps.filter((c) => c.tier === main[i]), B = comps.filter((c) => c.tier === main[i + 1]);
|
|
437
|
+
if (A.length * B.length <= 12) for (const a of A) for (const b of B) link(a.id, b.id);
|
|
438
|
+
else { A.forEach((a, k) => link(a.id, B[Math.min(k, B.length - 1)].id)); B.forEach((b, k) => k >= A.length && link(A[A.length - 1].id, b.id)); }
|
|
439
|
+
}
|
|
440
|
+
for (const p of Object.values(pos)) {
|
|
441
|
+
const c = p.c, g = mk("g", { class: "sysnode" + (S.sel?.kind === "component" && S.sel.ref === c.id ? " on" : ""), transform: `translate(${p.x},${p.y})`, tabindex: 0, role: "button" });
|
|
442
|
+
mk("title", {}, g).textContent = c.desc;
|
|
443
|
+
mk("rect", { width: w, height: h, rx: 10, class: "sysbox" }, g);
|
|
444
|
+
mk("circle", { cx: 30, cy: h / 2, r: 18, class: "sysdisc" }, g);
|
|
445
|
+
const ic = mk("use", { href: "icons.svg#" + c.icon, x: 20, y: h / 2 - 10, width: 20, height: 20, class: "sysicon" }, g);
|
|
446
|
+
const t1 = mk("text", { x: 58, y: h / 2 - 3, class: "systitle" }, g); t1.textContent = c.title.length > 17 ? c.title.slice(0, 16) + "…" : c.title;
|
|
447
|
+
const t2 = mk("text", { x: 58, y: h / 2 + 15, class: "syssub" }, g); t2.textContent = (c.sub || "").length > 22 ? c.sub.slice(0, 21) + "…" : c.sub || "";
|
|
448
|
+
if (c.state) { mk("circle", { cx: w - 12, cy: 12, r: 5, class: "sysdot " + c.state }, g); mk("title", {}, g).textContent = c.state === "new" ? "new since the last step" : "changed since the last step"; }
|
|
449
|
+
const open = () => { select({ kind: "component", ref: c.id }); svg.querySelectorAll(".sysnode.on").forEach((n) => n.classList.remove("on")); g.classList.add("on"); };
|
|
450
|
+
g.addEventListener("click", open); g.addEventListener("keydown", (e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); open(); } });
|
|
451
|
+
}
|
|
452
|
+
sc.append(svg, el("div", "syshint", "Click a component to see what is inside it. Drawn from the code: layers, routes, tables and infrastructure."));
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// ---- overview
|
|
456
|
+
function overview(v) {
|
|
457
|
+
const st = S.st, sc = el("div", "scroll"); v.append(sc);
|
|
458
|
+
const hero = el("div", "hero"); const t = el("div"); t.append(el("h1", null, st.name), el("div", "path mono", st.root)); hero.append(t, el("div", "grow"));
|
|
459
|
+
const brief = el("button", "btn"); brief.append(icon("doc"), document.createTextNode("Agent brief")); brief.onclick = () => { S.rightMode = "brief"; S.rightOpen = true; renderAll(); };
|
|
460
|
+
const rec = el("button", "btn primary"); rec.append(icon("flag"), document.createTextNode("Record step")); rec.onclick = recordStep;
|
|
461
|
+
hero.append(brief, rec); sc.append(hero);
|
|
462
|
+
const c = st.counts, stats = el("div", "stats");
|
|
463
|
+
for (const [k, label, tab] of [["files", "files", "d:files"], ["modules", "modules", "d:architecture"], ["functions", "functions", "logic"], ["classes", "classes", "d:classes"],
|
|
464
|
+
["tables", "tables", "d:data"], ["routes", "routes", "d:processes"], ["concepts", "mechanisms", "concepts"], ["infra", "infra nodes", "d:cloud"]]) {
|
|
465
|
+
const s = el("div", "stat"); s.append(el("b", null, String(c[k])), el("span", null, label)); s.onclick = () => openTab(FIXED.find((x) => x.id === tab)); stats.append(s);
|
|
466
|
+
}
|
|
467
|
+
sc.append(stats);
|
|
468
|
+
const grid = el("div", "grid2"); sc.append(grid);
|
|
469
|
+
// latest step
|
|
470
|
+
const last = st.steps[st.steps.length - 1];
|
|
471
|
+
const c1 = card("What the agent did", "timeline");
|
|
472
|
+
if (st.pending.length) {
|
|
473
|
+
c1.body.append(el("div", "li", null)); c1.body.lastChild.append(el("span", "badge auto", "IN PROGRESS"), el("span", "nm", `${st.pending.length} file change${st.pending.length === 1 ? "" : "s"} since step ${last ? last.n : 0}`));
|
|
474
|
+
c1.body.append(changeList(st.pending.slice(0, 6), last ? String(last.n) : "live", "live"));
|
|
475
|
+
}
|
|
476
|
+
if (last) {
|
|
477
|
+
const li = el("div", "li"); li.append(el("span", "badge " + last.source, last.source.toUpperCase()), el("span", "nm", `${last.n}. ${last.title}`), el("span", "meta", ago(last.ts)));
|
|
478
|
+
li.onclick = () => { setStep(last.n); openTab(FIXED.find((x) => x.id === "timeline")); }; c1.body.append(li);
|
|
479
|
+
c1.body.append(deltaChips(last.summary));
|
|
480
|
+
if (last.title_check && last.title_check !== "ok") c1.body.append(Object.assign(el("div", "chip warn", "⚠ " + last.title_check), { style: "margin-top:8px;white-space:normal;height:auto;padding:4px 8px" }));
|
|
481
|
+
}
|
|
482
|
+
grid.append(c1.card);
|
|
483
|
+
// layers
|
|
484
|
+
const c2 = card("Layers", "d:architecture"); const total = Object.values(st.layers).reduce((a, b) => a + b, 0) || 1;
|
|
485
|
+
const bar = el("div", "layerbar"), keys = el("div", "lkeys");
|
|
486
|
+
for (const [k, n] of Object.entries(st.layers).sort((a, b) => b[1] - a[1])) { const i = el("i"); i.style.width = (100 * n / total) + "%"; i.style.background = LAYER_COLOR[k] || "#888"; i.title = `${k}: ${n}`; bar.append(i); const s = el("span"); const d = el("i"); d.style.background = LAYER_COLOR[k] || "#888"; s.append(d, document.createTextNode(`${k} ${n}`)); keys.append(s); }
|
|
487
|
+
c2.body.append(bar, keys); grid.append(c2.card);
|
|
488
|
+
// mechanisms
|
|
489
|
+
const c3 = card("Mechanisms in use", "concepts"); const cw = el("div", "concepts");
|
|
490
|
+
for (const cc of st.concepts.slice(0, 18)) { const p = el("span", "cpill"); p.append(icon(cc.icon), document.createTextNode(cc.title)); p.onclick = () => { select({ kind: "concept", ref: cc.id }); openTab(FIXED.find((x) => x.id === "concepts")); }; cw.append(p); }
|
|
491
|
+
if (!st.concepts.length) cw.append(el("span", "empty", "None detected yet."));
|
|
492
|
+
c3.body.append(cw); grid.append(c3.card);
|
|
493
|
+
// routes
|
|
494
|
+
if (st.routes.length) { const c4 = card("Entry points", "d:processes"); const l = el("div", "list"); for (const r of st.routes.slice(0, 8)) { const li = el("div", "li"); li.append(el("span", "badge acc", r.method), el("span", "nm mono", r.path), el("span", "meta", short(r.fid || r.handler || ""))); li.onclick = () => r.fid ? select({ kind: "function", ref: r.fid, file: r.file, line: r.line }) : openFile(r.file, r.line); l.append(li); } c4.body.append(l); grid.append(c4.card); }
|
|
495
|
+
// infra
|
|
496
|
+
const c5 = card("Cloud & infrastructure", "d:cloud"); const l5 = el("div", "list");
|
|
497
|
+
for (const n of st.infra.nodes.slice(0, 8)) { const li = el("div", "li"); li.append(icon({ db: "database", cache: "layers", queue: "inbox", storage: "box", external: "globe", ci: "git-merge", cloud: "cloud", function: "bolt", app: "server", container: "box", cdn: "globe", search: "search" }[n.kind] || "server"), el("span", "nm", n.label), el("span", "meta", n.kind)); li.onclick = () => select({ kind: "infra", ref: n.id }); l5.append(li); }
|
|
498
|
+
if (!st.infra.nodes.length) l5.append(el("div", "empty", "No Dockerfile, compose, Terraform, CI or service SDKs found yet."));
|
|
499
|
+
c5.body.append(l5); grid.append(c5.card);
|
|
500
|
+
// hotspots & algorithms
|
|
501
|
+
const c6 = card("Complexity hotspots", "logic"); const l6 = el("div", "list");
|
|
502
|
+
for (const h of st.hotspots.slice(0, 7)) { const li = el("div", "li"); li.append(cxBadge(h.complexity), el("span", "nm mono", short(h.id) + "()"), el("span", "meta", base(h.file))); li.onclick = () => select({ kind: "function", ref: h.id, file: h.file, line: h.line }); li.ondblclick = () => openFlow(h.id); l6.append(li); }
|
|
503
|
+
c6.body.append(l6); grid.append(c6.card);
|
|
504
|
+
if (st.algorithms.length) { const c7 = card("Algorithms & techniques (hints)", "logic"); const l7 = el("div", "list"); for (const a of st.algorithms.slice(0, 7)) { const li = el("div", "li"); li.append(el("span", "nm mono", short(a.id) + "()"), el("span", "meta", a.hints.filter((x) => x !== "async I/O").slice(0, 2).join(", "))); li.onclick = () => select({ kind: "function", ref: a.id, file: a.file, line: a.line }); li.ondblclick = () => openFlow(a.id); l7.append(li); } c7.body.append(l7); grid.append(c7.card); }
|
|
505
|
+
// todos & verification
|
|
506
|
+
const c8 = card("Plan", null); const open = st.todos.filter((t) => t.status === "open"), done = st.todos.filter((t) => t.status === "done");
|
|
507
|
+
const l8 = el("div", "list"); for (const td of [...open, ...done].slice(0, 7)) { const li = el("div", "li"); li.append(icon(td.status === "done" ? "check-square" : "check"), el("span", "nm", td.text), el("span", "meta", td.status === "done" ? (td.verified ? "verified" : "unverified") : td.id)); li.onclick = () => { S.btab = "todo"; S.bottomOpen = true; renderAll(); }; l8.append(li); }
|
|
508
|
+
if (!st.todos.length) l8.append(el("div", "empty", "The agent has not recorded a plan. It can with the `todo` tool."));
|
|
509
|
+
c8.body.append(l8); grid.append(c8.card);
|
|
510
|
+
const c9 = card("Verification", null);
|
|
511
|
+
const bad = st.problems.filter((x) => x.kind !== "parse");
|
|
512
|
+
c9.body.append(el("div", "li", null)); c9.body.lastChild.append(icon(bad.length ? "warning" : "check"), el("span", "nm", bad.length ? `${bad.length} claim(s) do not check out` : "Everything the agent claimed checks out against the code"));
|
|
513
|
+
for (const x of bad.slice(0, 4)) { const li = el("div", "li"); li.append(el("span", "badge " + x.status, x.status), el("span", "nm", x.text)); li.onclick = () => { S.btab = "problems"; S.bottomOpen = true; renderAll(); }; c9.body.append(li); }
|
|
514
|
+
grid.append(c9.card);
|
|
515
|
+
}
|
|
516
|
+
function card(title, tab) {
|
|
517
|
+
const c = el("div", "card"), h = el("h3"); h.append(el("span", null, title), el("span", "grow"));
|
|
518
|
+
if (tab) { const a = el("a", null, "Open →"); a.href = "#"; a.onclick = (e) => { e.preventDefault(); openTab(FIXED.find((x) => x.id === tab)); }; h.append(a); }
|
|
519
|
+
const body = el("div"); c.append(h, body); return { card: c, body };
|
|
520
|
+
}
|
|
521
|
+
function cxBadge(n) { return el("span", "cx" + (n >= 20 ? " vh" : n >= 10 ? " h" : ""), String(n)); }
|
|
522
|
+
function deltaChips(sm) {
|
|
523
|
+
const w = el("div", "chips"); w.style.cssText = "display:flex;flex-wrap:wrap;gap:6px;margin-top:8px";
|
|
524
|
+
w.append(el("span", "chip", `${sm.files} files`), el("span", "chip new", `+${sm.added}`), el("span", "chip removed", `−${sm.removed}`));
|
|
525
|
+
for (const [k, d] of Object.entries(sm.delta || {})) for (const [s, n] of Object.entries(d)) w.append(el("span", "chip " + s, `${n} ${s} ${k.replace(/s$/, "")}${n > 1 ? "s" : ""}`));
|
|
526
|
+
return w;
|
|
527
|
+
}
|
|
528
|
+
function changeList(changes, from, to) {
|
|
529
|
+
const box = el("div", "files"); box.style.marginTop = "6px";
|
|
530
|
+
for (const ch of changes) {
|
|
531
|
+
const r = el("div", "fchg"); r.append(el("span", "k " + ch.kind, ch.kind[0].toUpperCase()), el("span", "p mono", ch.path));
|
|
532
|
+
const c = el("span", "c"); if ("added" in ch) { c.append(el("span", "a", `+${ch.added}`), document.createTextNode(" "), el("span", "r", `−${ch.removed}`)); } else c.textContent = ch.note ? "not read" : "";
|
|
533
|
+
r.append(c); r.style.cursor = "pointer"; r.onclick = (e) => { e.stopPropagation(); if (!ch.note) openDiff(ch.path, from, to); };
|
|
534
|
+
box.append(r);
|
|
535
|
+
}
|
|
536
|
+
return box;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// ---- diagrams
|
|
540
|
+
function vbar(title) { const b = el("div", "vbar"); b.append(el("span", "title", title)); return b; }
|
|
541
|
+
function stepSelect(onchange) {
|
|
542
|
+
const s = el("select", "select"); s.title = "Highlight what changed compared with";
|
|
543
|
+
const opts = [["auto", "vs previous step"], ["none", "no highlighting"], ...S.st.steps.map((x) => [String(x.n), `vs step ${x.n}: ${x.title.slice(0, 40)}`])];
|
|
544
|
+
for (const [v, t] of opts) { const o = el("option", null, t); o.value = v; s.append(o); }
|
|
545
|
+
s.value = S.base; s.onchange = () => { S.base = s.value; onchange(); }; return s;
|
|
546
|
+
}
|
|
547
|
+
async function diagramView(v, kind, focus) {
|
|
548
|
+
const bar = vbar(DTITLE[kind] || kind); v.append(bar);
|
|
549
|
+
const tabId = S.active; const vs = S.view[tabId] = S.view[tabId] || { k: 1, x: 20, y: 20, src: false, focus: focus || null };
|
|
550
|
+
if (kind === "processes" || kind === "calls") {
|
|
551
|
+
const sel = el("select", "select"); sel.title = kind === "processes" ? "One entry point" : "Centre on a function";
|
|
552
|
+
sel.append(Object.assign(el("option", null, kind === "processes" ? "all entry points" : "most connected functions"), { value: "" }));
|
|
553
|
+
if (kind === "processes") for (const r of S.st.routes) { const o = el("option", null, `${r.method} ${r.path}`); o.value = `${r.method} ${r.path}`; sel.append(o); }
|
|
554
|
+
else model().then((m) => { Object.entries(m.functions).filter(([, f]) => f.callers.length + f.callees.length).sort((a, b) => a[0].localeCompare(b[0])).slice(0, 400).forEach(([fid]) => { const o = el("option", null, short(fid) + "()"); o.value = fid; sel.append(o); }); sel.value = vs.focus || ""; });
|
|
555
|
+
sel.value = vs.focus || ""; sel.onchange = () => { vs.focus = sel.value || null; vs.fit = true; renderView(); };
|
|
556
|
+
bar.append(sel);
|
|
557
|
+
}
|
|
558
|
+
if (kind === "processes") { const cg = el("button", "btn sm", "Call graph"); cg.onclick = () => openTab({ id: "d:calls", title: "Call graph", icon: "graph" }); bar.append(cg); }
|
|
559
|
+
if (["architecture", "classes", "data", "calls", "files"].includes(kind)) bar.append(stepSelect(() => { vs.fit = true; renderView(); }));
|
|
560
|
+
const note = el("span", "note"); bar.append(note, el("span", "spacer"));
|
|
561
|
+
const legend = el("span", "legend"); bar.append(legend);
|
|
562
|
+
const canvas = el("div", "canvas"); v.append(canvas);
|
|
563
|
+
const z = zoomControls(bar, canvas, vs);
|
|
564
|
+
const src = el("button", "tbtn" + (vs.src ? " on" : "")); src.title = "Show the Mermaid source"; src.append(icon("code"));
|
|
565
|
+
src.onclick = () => { vs.src = !vs.src; renderView(); };
|
|
566
|
+
const copy = el("button", "tbtn"); copy.title = "Copy Mermaid"; copy.append(icon("copy"));
|
|
567
|
+
const dl = el("button", "tbtn"); dl.title = "Download SVG"; dl.append(icon("download"));
|
|
568
|
+
bar.append(el("span", "sep"), src, copy, dl);
|
|
569
|
+
canvas.append(el("div", "msg", "Drawing…"));
|
|
570
|
+
let d;
|
|
571
|
+
try { d = await api(url(P("diagram/" + kind), { step: stepParam(), base: S.base === "auto" ? null : S.base, focus: vs.focus })); }
|
|
572
|
+
catch (e) { canvas.replaceChildren(el("div", "msg", "This view is not available here.")); return; }
|
|
573
|
+
if (S.active !== tabId) return;
|
|
574
|
+
note.textContent = d.note || "";
|
|
575
|
+
for (const [k, dd] of Object.entries(d.delta || {})) for (const [s, n] of Object.entries(dd)) legend.append(el("span", "chip " + s, `${n} ${s}`));
|
|
576
|
+
copy.onclick = () => { navigator.clipboard?.writeText(d.mermaid); toast("ok", "Copied", "Mermaid source is on the clipboard."); };
|
|
577
|
+
await drawMermaid(canvas, d, vs, z, (key, info) => onNode(info), (key, info) => openNode(info));
|
|
578
|
+
dl.onclick = () => { const svg = canvas.querySelector("svg"); if (!svg) return; const blob = new Blob([svg.outerHTML], { type: "image/svg+xml" }); const a = el("a"); a.href = URL.createObjectURL(blob); a.download = `${S.st.name}-${kind}.svg`; a.click(); };
|
|
579
|
+
}
|
|
580
|
+
let mcount = 0;
|
|
581
|
+
async function drawMermaid(canvas, d, vs, z, onClick, onOpen) {
|
|
582
|
+
if (vs.src) { canvas.replaceChildren(el("pre", "src", d.mermaid)); return; }
|
|
583
|
+
let svg;
|
|
584
|
+
try { svg = (await mermaid.render("mw" + ++mcount, d.mermaid)).svg; }
|
|
585
|
+
catch (e) { document.getElementById("dmw" + mcount)?.remove(); canvas.replaceChildren(el("div", "msg", "This diagram could not be drawn; the Mermaid source is shown instead."), el("pre", "src", d.mermaid)); return; }
|
|
586
|
+
const stage = el("div", "stage"); stage.innerHTML = svg; canvas.replaceChildren(stage); // Mermaid output, strict mode
|
|
587
|
+
const s = stage.querySelector("svg"); if (!s) return;
|
|
588
|
+
const w = s.viewBox.baseVal?.width || s.getBBox().width, h = s.viewBox.baseVal?.height || s.getBBox().height;
|
|
589
|
+
s.setAttribute("width", w); s.setAttribute("height", h); s.style.maxWidth = "none";
|
|
590
|
+
if (vs.fit !== false || !vs.fitted) { z.fit(w, h); vs.fitted = true; vs.fit = false; } else z.apply();
|
|
591
|
+
const nodes = d.nodes || {};
|
|
592
|
+
const keyOf = (g) => { const id = g.id || ""; let m;
|
|
593
|
+
if ((m = id.match(/^flowchart-(.+)-\d+$/))) return m[1];
|
|
594
|
+
if ((m = id.match(/^classId-(.+)-\d+$/))) return "class:" + m[1];
|
|
595
|
+
if ((m = id.match(/^entity-(.+)-\d+$/))) return "entity:" + m[1];
|
|
596
|
+
return null; };
|
|
597
|
+
stage.querySelectorAll("g.node, g[id^=classId-], g[id^=entity-]").forEach((g) => {
|
|
598
|
+
const key = keyOf(g); const info = key && nodes[key]; if (!info) return;
|
|
599
|
+
g.style.cursor = "pointer"; g.setAttribute("tabindex", "0");
|
|
600
|
+
const t = document.createElementNS(NS, "title"); t.textContent = (info.ref || "") + (info.file ? `\n${info.file}${info.line ? ":" + info.line : ""}` : "") + "\nclick: inspect · double-click: open"; g.prepend(t);
|
|
601
|
+
g.addEventListener("click", (e) => { e.stopPropagation(); stage.querySelectorAll(".picked").forEach((x) => x.classList.remove("picked")); g.classList.add("picked"); onClick(key, info); });
|
|
602
|
+
g.addEventListener("dblclick", (e) => { e.stopPropagation(); onOpen(key, info); });
|
|
603
|
+
g.addEventListener("keydown", (e) => { if (e.key === "Enter") onOpen(key, info); });
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
function zoomControls(bar, canvas, vs) {
|
|
607
|
+
const lbl = el("span", "zoomlbl"); const apply = () => { const st = canvas.querySelector(".stage"); if (st) st.style.transform = `translate(${vs.x}px,${vs.y}px) scale(${vs.k})`; lbl.textContent = Math.round(vs.k * 100) + "%"; };
|
|
608
|
+
const zoomAt = (f, cx, cy) => { const k2 = Math.min(4, Math.max(0.08, vs.k * f)); vs.x = cx - (cx - vs.x) * (k2 / vs.k); vs.y = cy - (cy - vs.y) * (k2 / vs.k); vs.k = k2; apply(); };
|
|
609
|
+
const fit = (w, h) => { const r = canvas.getBoundingClientRect(); const pad = 28; if (!w) { const s = canvas.querySelector("svg"); if (!s) return; w = +s.getAttribute("width"); h = +s.getAttribute("height"); }
|
|
610
|
+
vs.k = Math.min(1.25, Math.max(0.08, Math.min((r.width - pad * 2) / w, (r.height - pad * 2) / h))); vs.x = (r.width - w * vs.k) / 2; vs.y = Math.max(pad, (r.height - h * vs.k) / 2); apply(); };
|
|
611
|
+
const b = (ic, title, fn) => { const x = el("button", "tbtn"); x.title = title; x.append(icon(ic)); x.onclick = fn; return x; };
|
|
612
|
+
bar.append(b("zoom-out", "Zoom out", () => { const r = canvas.getBoundingClientRect(); zoomAt(1 / 1.2, r.width / 2, r.height / 2); }), lbl,
|
|
613
|
+
b("zoom-in", "Zoom in", () => { const r = canvas.getBoundingClientRect(); zoomAt(1.2, r.width / 2, r.height / 2); }), b("fit", "Fit to window", () => fit()));
|
|
614
|
+
canvas.addEventListener("wheel", (e) => { e.preventDefault(); const r = canvas.getBoundingClientRect(); if (e.ctrlKey || e.metaKey || !e.shiftKey) zoomAt(e.deltaY < 0 ? 1.1 : 1 / 1.1, e.clientX - r.left, e.clientY - r.top); else { vs.x -= e.deltaY; apply(); } }, { passive: false });
|
|
615
|
+
let drag = null;
|
|
616
|
+
canvas.addEventListener("pointerdown", (e) => { if (e.button !== 0 || e.target.closest("pre")) return; drag = { x: e.clientX, y: e.clientY, ox: vs.x, oy: vs.y, moved: false }; canvas.setPointerCapture(e.pointerId); });
|
|
617
|
+
canvas.addEventListener("pointermove", (e) => { if (!drag) return; const dx = e.clientX - drag.x, dy = e.clientY - drag.y; if (Math.abs(dx) + Math.abs(dy) > 3) { drag.moved = true; canvas.classList.add("drag"); } vs.x = drag.ox + dx; vs.y = drag.oy + dy; apply(); });
|
|
618
|
+
canvas.addEventListener("pointerup", () => { drag = null; canvas.classList.remove("drag"); });
|
|
619
|
+
return { apply, fit };
|
|
620
|
+
}
|
|
621
|
+
function onNode(info) {
|
|
622
|
+
const m = { module: "module", function: "function", class: "class", table: "table", file: "file", infra: "infra", concept: "concept", route: "route", dir: "dir", package: "package", layer: "layer" };
|
|
623
|
+
select({ kind: m[info.kind] || info.kind, ref: info.ref, file: info.file, line: info.line });
|
|
624
|
+
}
|
|
625
|
+
function openNode(info) {
|
|
626
|
+
if (info.kind === "function") openFlow(info.ref);
|
|
627
|
+
else if (info.kind === "concept") { select({ kind: "concept", ref: info.ref }); openTab(FIXED.find((x) => x.id === "concepts")); }
|
|
628
|
+
else if (info.kind === "dir") { S.left = "project"; S.leftOpen = true; S.expanded.add(info.ref + "/"); saveUI(); renderLeft(); }
|
|
629
|
+
else if (info.file && !info.file.includes(" ")) openFile(info.file, info.line);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// ---- logic
|
|
633
|
+
async function logicView(v) {
|
|
634
|
+
const sp = el("div", "split"), side = el("div", "side"), content = el("div", "content"); sp.append(side, content); v.append(sp);
|
|
635
|
+
const f = el("div", "filter"); f.append(icon("search")); const inp = el("input"); inp.placeholder = "Filter functions"; inp.value = S.fnFilter; f.append(inp);
|
|
636
|
+
const sort = el("select", "select"); sort.style.margin = "0 8px 8px"; for (const [k, t] of [["cx", "Most complex first"], ["hints", "Algorithms first"], ["calls", "Most connected first"], ["name", "By name"]]) { const o = el("option", null, t); o.value = k; sort.append(o); }
|
|
637
|
+
sort.value = S.fnSort || "cx"; side.append(f, sort);
|
|
638
|
+
const list = el("div", "pbody"); side.append(list);
|
|
639
|
+
const m = await model(); if (S.active !== "logic") return;
|
|
640
|
+
const all = Object.entries(m.functions).filter(([, fn]) => !/(^|\/)tests?\//.test(fn.file));
|
|
641
|
+
const draw = () => {
|
|
642
|
+
list.replaceChildren(); const q = S.fnFilter.toLowerCase();
|
|
643
|
+
let rows = all.filter(([id]) => !q || id.toLowerCase().includes(q));
|
|
644
|
+
const by = { cx: (a, b) => b[1].complexity - a[1].complexity, hints: (a, b) => b[1].hints.length - a[1].hints.length || b[1].complexity - a[1].complexity,
|
|
645
|
+
calls: (a, b) => (b[1].callers.length + b[1].callees.length) - (a[1].callers.length + a[1].callees.length), name: (a, b) => a[0].localeCompare(b[0]) }[S.fnSort || "cx"];
|
|
646
|
+
rows.sort(by);
|
|
647
|
+
for (const [id, fn] of rows.slice(0, 500)) {
|
|
648
|
+
const r = el("div", "fnrow" + (S.fnSel === id ? " sel" : "")); r.append(el("span", "nm", fn.qual + "()"), cxBadge(fn.complexity), el("span", "sub", `${fn.file}:${fn.line} · ${fn.callees.length} calls · ${fn.callers.length} callers`));
|
|
649
|
+
if (fn.hints.length) { const h = el("div", "hints"); h.style.gridColumn = "1 / -1"; fn.hints.slice(0, 3).forEach((x) => h.append(el("span", "hint", x))); r.append(h); }
|
|
650
|
+
r.onclick = () => { S.fnSel = id; draw(); select({ kind: "function", ref: id, file: fn.file, line: fn.line }); drawFlow(id); };
|
|
651
|
+
list.append(r);
|
|
652
|
+
}
|
|
653
|
+
if (!rows.length) list.append(el("div", "empty", "No functions match."));
|
|
654
|
+
};
|
|
655
|
+
inp.oninput = debounce(() => { S.fnFilter = inp.value; draw(); }, 120); sort.onchange = () => { S.fnSort = sort.value; draw(); };
|
|
656
|
+
draw();
|
|
657
|
+
const drawFlow = (id) => { content.replaceChildren(); flowInto(content, id, "logic"); };
|
|
658
|
+
if (S.fnSel && m.functions[S.fnSel]) drawFlow(S.fnSel);
|
|
659
|
+
else { const top = all.sort((a, b) => b[1].complexity - a[1].complexity)[0]; if (top) { S.fnSel = top[0]; draw(); drawFlow(top[0]); } else content.append(el("div", "empty", "No functions yet.")); }
|
|
660
|
+
}
|
|
661
|
+
async function flowView(v, fid) { flowInto(v, fid, "flow:" + fid); }
|
|
662
|
+
async function flowInto(v, fid, tabId) {
|
|
663
|
+
const bar = vbar(short(fid) + "()"); v.append(bar);
|
|
664
|
+
const vs = S.view[tabId + ":" + fid] = S.view[tabId + ":" + fid] || { k: 1, x: 20, y: 20, fit: true };
|
|
665
|
+
const note = el("span", "note"); bar.append(note, el("span", "spacer"));
|
|
666
|
+
const cg = el("button", "btn sm"); cg.append(icon("graph"), document.createTextNode("Call graph")); cg.onclick = () => { openTab({ id: "d:calls", title: "Call graph", icon: "graph" }); S.view["d:calls"] = { k: 1, x: 20, y: 20, focus: fid, fit: true }; renderView(); };
|
|
667
|
+
const code = el("button", "btn sm"); code.append(icon("code"), document.createTextNode("Code")); bar.append(cg, code, el("span", "sep"));
|
|
668
|
+
const canvas = el("div", "canvas"); v.append(canvas); const z = zoomControls(bar, canvas, vs);
|
|
669
|
+
canvas.append(el("div", "msg", "Drawing…"));
|
|
670
|
+
let d; try { d = await api(url(P("flow"), { fid, step: stepParam() })); } catch (e) { canvas.replaceChildren(el("div", "msg", "No flowchart for this function.")); return; }
|
|
671
|
+
const fn = d.function;
|
|
672
|
+
note.textContent = `${fn.file}:${fn.line}-${fn.end} · complexity ${fn.complexity}` + (d.kind === "outline" ? " · outline (JS/TS: branches and calls in order)" : "") + (d.truncated ? " · long: later parts collapsed" : "");
|
|
673
|
+
code.onclick = () => openFile(fn.file, fn.line);
|
|
674
|
+
const nodes = {}; for (const [k, n] of Object.entries(d.nodes)) nodes[k] = { kind: "line", ref: n.label, file: fn.file, line: n.line };
|
|
675
|
+
await drawMermaid(canvas, { ...d, nodes }, vs, z, (k, info) => select({ kind: "function", ref: fid, file: fn.file, line: info.line }), (k, info) => openFile(fn.file, info.line));
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
// ---- concepts
|
|
679
|
+
function conceptsView(v) {
|
|
680
|
+
const bar = vbar("Mechanisms & concepts"); v.append(bar);
|
|
681
|
+
const mapBtn = el("button", "btn sm"); mapBtn.append(icon("graph"), document.createTextNode("Concept map")); mapBtn.onclick = () => openTab({ id: "d:concepts", title: "Concept map", icon: "graph" });
|
|
682
|
+
bar.append(el("span", "note", "Detected in the code, and claimed by the agent (claims are checked)"), el("span", "spacer"), mapBtn);
|
|
683
|
+
const sc = el("div", "scroll"); v.append(sc);
|
|
684
|
+
const groups = {}; for (const c of S.st.concepts) (groups[c.group] = groups[c.group] || []).push(c);
|
|
685
|
+
if (!S.st.concepts.length) sc.append(el("div", "empty", "No mechanisms detected yet."));
|
|
686
|
+
for (const [g, cs] of Object.entries(groups)) {
|
|
687
|
+
sc.append(el("div", "section-title", g[0].toUpperCase() + g.slice(1)));
|
|
688
|
+
const grid = el("div", "grid2");
|
|
689
|
+
for (const c of cs) {
|
|
690
|
+
const cardEl = el("div", "card ccard" + (S.sel?.kind === "concept" && S.sel.ref === c.id ? " sel" : "")); if (S.sel?.ref === c.id) cardEl.style.borderColor = "var(--accent)";
|
|
691
|
+
const top = el("div", "top"), ic = el("div", "cic"); ic.append(icon(c.icon)); const t = el("div"); t.append(el("h4", null, c.title), el("p", null, c.meaning)); top.append(ic, t); cardEl.append(top);
|
|
692
|
+
for (const e of c.evidence.slice(0, 4)) { const r = el("div", "ev"); r.append(el("span", "f mono", `${e.file}:${e.line}`), el("span", "s", (e.symbol ? e.symbol + " · " : "") + e.signal)); r.onclick = () => openFile(e.file, e.line); cardEl.append(r); }
|
|
693
|
+
for (const cl of c.claims) { const r = el("div", "ev"); r.append(el("span", "badge " + cl.status, cl.status), el("span", "f mono", cl.symbol), el("span", "s", cl.reason || "")); r.onclick = () => cl.file && openFile(cl.file, cl.line); cardEl.append(r); }
|
|
694
|
+
cardEl.onclick = (e) => { if (!e.target.closest(".ev")) select({ kind: "concept", ref: c.id }); };
|
|
695
|
+
grid.append(cardEl);
|
|
696
|
+
}
|
|
697
|
+
sc.append(grid);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
// ---- timeline
|
|
702
|
+
function timelineView(v) {
|
|
703
|
+
const bar = vbar("Timeline · every step of the agent's work"); v.append(bar); bar.append(el("span", "note", "Click a step to view every diagram as it was then"), el("span", "spacer"));
|
|
704
|
+
const rec = el("button", "btn sm primary"); rec.append(icon("flag"), document.createTextNode("Record step")); rec.onclick = recordStep; bar.append(rec);
|
|
705
|
+
const sc = el("div", "scroll"), tl = el("div", "tl"); sc.append(tl); v.append(sc);
|
|
706
|
+
const st = S.st, last = st.steps[st.steps.length - 1];
|
|
707
|
+
const liveEl = el("div", "tstep live" + (S.step === "live" ? " on" : "")); const h = el("div", "h"); h.append(el("span", "n", "now"), el("span", "ttl", st.pending.length ? "Work in progress" : "No changes since the last step"), el("span", "badge auto", "LIVE"));
|
|
708
|
+
liveEl.append(h); if (st.pending.length) liveEl.append(changeList(st.pending, last ? String(last.n) : "live", "live"));
|
|
709
|
+
liveEl.onclick = () => setStep("live"); tl.append(liveEl);
|
|
710
|
+
for (const s of [...st.steps].reverse()) {
|
|
711
|
+
const e = el("div", "tstep" + (S.step === s.n ? " on" : "")); const hh = el("div", "h");
|
|
712
|
+
hh.append(el("span", "n", "#" + s.n), el("span", "ttl", s.title), el("span", "badge " + s.source, s.source), el("span", "when", `${clock(s.ts)} · ${ago(s.ts)}`)); e.append(hh);
|
|
713
|
+
if (s.intent) e.append(el("div", "prompt", s.intent));
|
|
714
|
+
else if (s.prompt && s.prompt !== s.title) e.append(el("div", "prompt", "prompt: " + s.prompt));
|
|
715
|
+
if (s.n > 0) e.append(deltaChips(s.summary));
|
|
716
|
+
if (s.title_check && s.title_check !== "ok") { const w = el("div", "chips"); w.append(el("span", "chip warn", "⚠ " + s.title_check)); e.append(w); }
|
|
717
|
+
if (s.changes?.length) e.append(changeList(s.changes.slice(0, 14), String(Math.max(0, s.n - 1)), String(s.n)));
|
|
718
|
+
e.onclick = () => setStep(s.n);
|
|
719
|
+
tl.append(e);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
function setStep(n) { S.step = n; S.base = "auto"; S.model = null; for (const k of Object.keys(S.view)) if (S.view[k]) S.view[k].fit = true; renderAll(); }
|
|
723
|
+
|
|
724
|
+
// ---- files & diffs
|
|
725
|
+
const KW = { python: "def class return if elif else for while in not and or is None True False import from as with try except finally raise yield async await lambda pass break continue global nonlocal assert del match case self",
|
|
726
|
+
js: "function const let var return if else for while do switch case break continue new class extends import from export default async await try catch finally throw typeof instanceof in of null undefined true false this super yield interface type enum implements public private protected readonly static",
|
|
727
|
+
sql: "select from where insert into values update set delete create table primary key foreign references not null unique index join left right inner outer on group by order having limit as and or default" };
|
|
728
|
+
function highlight(line, lang) {
|
|
729
|
+
const kws = new Set((KW[lang] || KW.js).split(" ")); const sqlish = lang === "sql";
|
|
730
|
+
const re = lang === "python" ? /(#.*$)|("""[^]*?"""|'''[^]*?'''|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')|(@[\w.]+)|(\b\d[\d_.]*\b)|(\b[A-Za-z_]\w*\b)/g
|
|
731
|
+
: sqlish ? /(--.*$)|('(?:''|[^'])*')|(@@)|(\b\d+\b)|(\b[A-Za-z_]\w*\b)/g
|
|
732
|
+
: /(\/\/.*$|\/\*.*?\*\/)|(`(?:\\.|[^`\\])*`|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')|(@\w+)|(\b\d[\d_.]*\b)|(\b[A-Za-z_$][\w$]*\b)/g;
|
|
733
|
+
let out = "", last = 0, m, prev = "";
|
|
734
|
+
while ((m = re.exec(line))) {
|
|
735
|
+
out += esc(line.slice(last, m.index)); const t = m[0];
|
|
736
|
+
if (m[1]) out += `<span class="tok-c">${esc(t)}</span>`; else if (m[2]) out += `<span class="tok-s">${esc(t)}</span>`; else if (m[3]) out += `<span class="tok-d">${esc(t)}</span>`;
|
|
737
|
+
else if (m[4]) out += `<span class="tok-n">${esc(t)}</span>`;
|
|
738
|
+
else if (kws.has(sqlish ? t.toLowerCase() : t)) out += `<span class="tok-k">${esc(t)}</span>`;
|
|
739
|
+
else if (/^(def|function|class)$/.test(prev) || line.slice(re.lastIndex).startsWith("(")) out += `<span class="tok-f">${esc(t)}</span>`;
|
|
740
|
+
else out += esc(t);
|
|
741
|
+
prev = m[5] ? t : prev; last = re.lastIndex;
|
|
742
|
+
}
|
|
743
|
+
return out + esc(line.slice(last));
|
|
744
|
+
}
|
|
745
|
+
async function fileView(v, path) {
|
|
746
|
+
const bar = vbar(path); v.append(bar); const note = el("span", "note"); bar.append(note, el("span", "spacer"));
|
|
747
|
+
const steps = S.st.steps, cmpFrom = S.step === "live" ? (steps.length ? String(steps[steps.length - 1].n) : null) : String(Math.max(0, S.step - 1));
|
|
748
|
+
const db = el("button", "btn sm"); db.append(icon("diff"), document.createTextNode("Diff with previous step")); db.onclick = () => openDiff(path, cmpFrom, stepParam()); bar.append(db);
|
|
749
|
+
const box = el("div", "code"); v.append(box);
|
|
750
|
+
let f; try { f = await api(url(P("file"), { path, step: stepParam() })); } catch (e) { box.append(el("div", "empty", "This file is not tracked at this step.")); return; }
|
|
751
|
+
if (f.secret || f.binary || f.text == null) { box.append(el("div", "empty", f.secret ? "Secret-looking file: Mapwright tracks that it changed, but never reads or shows its content." : "Binary or very large file: not shown.")); return; }
|
|
752
|
+
note.textContent = `${f.lang} · ${f.text.split("\n").length} lines` + (S.step !== "live" ? ` · as of step ${S.step}` : "");
|
|
753
|
+
const defs = {}; for (const s of f.symbols || []) if (s.kind === "function") defs[s.line] = s;
|
|
754
|
+
let marks = {};
|
|
755
|
+
if (cmpFrom != null && cmpFrom !== stepParam()) {
|
|
756
|
+
try { const d = await api(url(P("diff"), { path, from: cmpFrom, to: stepParam() })); let ln = 0; for (const l of d.diff.split("\n")) { const h = l.match(/^@@ -\d+(?:,\d+)? \+(\d+)/); if (h) { ln = +h[1]; continue; } if (l.startsWith("+++") || l.startsWith("---")) continue; if (l.startsWith("+")) { marks[ln] = "add"; ln++; } else if (l.startsWith("-")) { marks[ln] = marks[ln] || "chg"; } else ln++; } } catch (e) {}
|
|
757
|
+
}
|
|
758
|
+
const lang = f.lang === "python" ? "python" : f.lang === "sql" ? "sql" : "js";
|
|
759
|
+
const frag = document.createDocumentFragment(); const lines = f.text.split("\n");
|
|
760
|
+
lines.forEach((l, i) => {
|
|
761
|
+
const n = i + 1, row = el("div", "ln" + (marks[n] ? " " + marks[n] : "") + (defs[n] ? " def" : "")); row.id = "L" + n;
|
|
762
|
+
const g = el("span", "g"); const fn = el("span", "fn", "ƒ"); if (defs[n]) { fn.title = "Flowchart of " + defs[n].qual; fn.onclick = () => openFlow(defs[n].fid); }
|
|
763
|
+
g.append(fn, document.createTextNode(String(n)), el("span", "mk")); const t = el("span", "t"); t.innerHTML = lang === "python" || lang === "js" || lang === "sql" ? highlight(l, lang) : esc(l);
|
|
764
|
+
row.append(g, t); frag.append(row);
|
|
765
|
+
});
|
|
766
|
+
box.append(frag);
|
|
767
|
+
const want = (S.view["file:" + path] || {}).line; if (want) { const r = box.querySelector("#L" + want); if (r) { r.classList.add("hl"); requestAnimationFrame(() => r.scrollIntoView({ block: "center" })); } }
|
|
768
|
+
}
|
|
769
|
+
async function diffView(v, path, from, to) {
|
|
770
|
+
const bar = vbar(`${path}`); v.append(bar); bar.append(el("span", "note", `step ${from} → ${to === "live" ? "now" : "step " + to}`), el("span", "spacer"));
|
|
771
|
+
const ob = el("button", "btn sm", "Open file"); ob.onclick = () => openFile(path); bar.append(ob);
|
|
772
|
+
const box = el("div", "diffv"); v.append(box);
|
|
773
|
+
try {
|
|
774
|
+
const d = await api(url(P("diff"), { path, from, to }));
|
|
775
|
+
if (d.secret) { box.append(el("div", "empty", "Secret-looking file: content not read.")); return; }
|
|
776
|
+
if (!d.diff) { box.append(el("div", "empty", "No differences.")); return; }
|
|
777
|
+
for (const l of d.diff.split("\n")) box.append(el("div", l.startsWith("@@") ? "h" : l.startsWith("+++") || l.startsWith("---") ? "m" : l.startsWith("+") ? "a" : l.startsWith("-") ? "r" : "", l || " "));
|
|
778
|
+
} catch (e) { box.append(el("div", "empty", "Diff not available.")); }
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
// ---- setup
|
|
782
|
+
async function setupView(v) {
|
|
783
|
+
const bar = vbar("Connect an agent"); v.append(bar); bar.append(el("span", "note", "Works with any MCP-capable agent; anything else is tracked from the files"), el("span", "spacer"));
|
|
784
|
+
const sc = el("div", "scroll"); v.append(sc);
|
|
785
|
+
let integ = S.integ; try { integ = await api(url("/v1/integrations", { key: S.key })); S.integ = integ; renderToolbar(); } catch (e) {}
|
|
786
|
+
const any = (integ?.targets || []).some((t) => Object.values(t.scopes || {}).some((x) => x.connected));
|
|
787
|
+
const steps = el("div", "steps-h");
|
|
788
|
+
[["Track the project", !!S.st], ["Connect an agent", any], ["Tell the agent (optional)", false], ["Open the map in your editor (optional)", false]].forEach(([t, ok], i) => { const s = el("div", "s" + (ok ? " done" : "")); s.append(el("b", null, ok ? "✓" : String(i + 1)), document.createTextNode(t)); steps.append(s); });
|
|
789
|
+
sc.append(steps);
|
|
790
|
+
sc.append(el("div", "section-title", "1 · Project"));
|
|
791
|
+
const pc = el("div", "card"); const kv = el("dl", "kv"); kv.append(el("dt", null, "Tracking"), el("dd", "mono", S.st.root), el("dt", null, "Steps"), el("dd", null, String(S.st.steps.length)));
|
|
792
|
+
const add = el("div", "actions"); add.style.marginTop = "12px"; const inp = el("input", "input"); inp.placeholder = "Track another folder: /path/to/project"; inp.style.flex = "1";
|
|
793
|
+
const go = el("button", "btn", "Track"); go.onclick = async () => { try { const r = await api("/v1/projects", { root: inp.value.trim() }); S.key = r.key; saveUI(); location.reload(); } catch (e) { if (e.message !== "demo") toast("err", "Could not track that folder", e.message); } };
|
|
794
|
+
add.append(inp, go); pc.append(kv, add); sc.append(pc);
|
|
795
|
+
sc.append(el("div", "section-title", "2 · Agent"));
|
|
796
|
+
const grid = el("div", "agents"); sc.append(grid);
|
|
797
|
+
for (const t of integ?.targets || []) {
|
|
798
|
+
const c = el("div", "card agent"); const h = el("div", "h"); h.append(icon(t.manual ? "doc" : "robot"), el("b", null, t.title)); if (t.installed) h.append(el("span", "badge ok", "found")); c.append(h, el("div", "how", t.how));
|
|
799
|
+
const st = el("div", "st"); for (const [scope, info] of Object.entries(t.scopes || {})) st.append(el("span", "chip" + (info.connected ? " ok" : ""), `${scope}${info.connected ? " ✓" : ""}`)); c.append(st);
|
|
800
|
+
const acts = el("div", "actions");
|
|
801
|
+
for (const [scope, info] of Object.entries(t.scopes || {})) {
|
|
802
|
+
if (info.path === null) continue;
|
|
803
|
+
const b = el("button", "btn sm" + (info.connected ? " danger" : scope === "project" ? " primary" : ""), info.connected ? `Disconnect ${scope}` : `Connect ${scope === "project" ? "this project" : "all projects"}`);
|
|
804
|
+
b.title = info.path || ""; b.onclick = async () => { try { const r = await api(info.connected ? "/v1/disconnect" : "/v1/connect", { target: t.id, scope, key: S.key }); toast("ok", info.connected ? "Disconnected" : "Connected", (r.files || []).join(", ") + (info.connected ? "" : " · restart the agent so it loads Mapwright.")); S.integ = { targets: r.targets }; renderView(); renderToolbar(); } catch (e) { if (e.message !== "demo") toast("err", "Could not change the config", e.message); } };
|
|
805
|
+
acts.append(b);
|
|
806
|
+
}
|
|
807
|
+
const sh = el("button", "btn sm", "Show config"); const snip = el("div", "snip"); snip.hidden = true; const pre = el("pre", null, t.snippet); const cp = el("button", "btn sm", "Copy"); cp.onclick = () => { navigator.clipboard?.writeText(t.snippet); toast("ok", "Copied", "Paste it into the agent's MCP settings."); }; snip.append(pre, cp);
|
|
808
|
+
sh.onclick = () => { snip.hidden = !snip.hidden; }; acts.append(sh); c.append(acts, snip); grid.append(c);
|
|
809
|
+
}
|
|
810
|
+
sc.append(el("div", "section-title", "3 · Tell the agent"));
|
|
811
|
+
const tc = el("div", "card"); tc.append(el("p", null, "Adds six lines to your agent instructions file so it starts from the map, records steps and keeps its plan in Mapwright. Optional: the MCP server already carries short instructions."));
|
|
812
|
+
const ta = el("div", "actions"); ta.style.marginTop = "10px";
|
|
813
|
+
for (const f of ["AGENTS.md", "CLAUDE.md", "GEMINI.md", ".cursorrules"]) { const b = el("button", "btn sm", "Add to " + f); b.onclick = async () => { try { const r = await api("/v1/agents-md", { key: S.key, file: f }); toast("ok", "Written", r.path); } catch (e) { if (e.message !== "demo") toast("err", "Could not write", e.message); } }; ta.append(b); }
|
|
814
|
+
tc.append(ta); sc.append(tc);
|
|
815
|
+
sc.append(el("div", "section-title", "4 · In your editor"));
|
|
816
|
+
const ec = el("div", "card"); ec.append(el("p", null, "VS Code, Cursor and Windsurf: install the Mapwright extension (mapwright-vscode.vsix in the download). It opens this map beside your code, shows the current step in the status bar and can record steps. JetBrains IDEs: open this page in the built-in browser, or keep it in a window next to the IDE."));
|
|
817
|
+
const cmd = el("div", "snip"); cmd.style.marginTop = "10px"; const cpre = el("pre", null, "code --install-extension integrations/vscode/mapwright-vscode-0.1.0.vsix"); cmd.append(cpre); ec.append(cmd); sc.append(ec);
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
// ------------------------------------------------------------------ inspector & brief
|
|
821
|
+
async function select(sel) { S.sel = sel; if (!S.rightOpen || (S.rightMode && S.rightMode !== "inspector")) { S.rightMode = "inspector"; S.rightOpen = true; renderAll(); } else renderRight(); renderStatus(); if (S.left === "structure" && sel.file) renderLeft(); if (S.left === "project") renderLeft(); }
|
|
822
|
+
async function renderRight() {
|
|
823
|
+
const body = $("#right-body"); body.replaceChildren();
|
|
824
|
+
if ((S.rightMode || "inspector") === "brief") { $("#right-title").textContent = "Agent brief"; briefPanel(body); return; }
|
|
825
|
+
$("#right-title").textContent = "Inspector";
|
|
826
|
+
const sel = S.sel; const box = el("div", "insp"); body.append(box);
|
|
827
|
+
if (!sel || !S.st) { box.append(el("div", "empty", "Click any box in a diagram, a file, a function or a mechanism to see what it is, where it lives and how it connects. Double-click opens it.")); return; }
|
|
828
|
+
const kindName = { function: "Function", class: "Class", table: "Table", module: "Module", file: "File", infra: "Infrastructure", concept: "Mechanism", route: "Entry point", dir: "Folder", package: "Package", layer: "Layer", line: "Code" }[sel.kind] || sel.kind;
|
|
829
|
+
box.append(el("div", "kind", kindName));
|
|
830
|
+
if (["function", "class", "table", "module"].includes(sel.kind)) {
|
|
831
|
+
box.append(el("h2", null, short(sel.ref)));
|
|
832
|
+
if (sel.file) { const l = el("div", "loc mono", `${sel.file}${sel.line ? ":" + sel.line : ""}`); l.onclick = () => openFile(sel.file, sel.line); box.append(l); }
|
|
833
|
+
const pre = el("pre", "cardtxt", "…"); box.append(pre);
|
|
834
|
+
const acts = el("div", "actions"); box.append(acts);
|
|
835
|
+
if (sel.kind === "function") { const f = el("button", "btn sm primary"); f.append(icon("function"), document.createTextNode("Flowchart")); f.onclick = () => openFlow(sel.ref); const g = el("button", "btn sm"); g.append(icon("graph"), document.createTextNode("Call graph")); g.onclick = () => { openTab({ id: "d:calls", title: "Call graph", icon: "graph" }); S.view["d:calls"] = { k: 1, x: 20, y: 20, focus: sel.ref, fit: true }; renderView(); }; acts.append(f, g); }
|
|
836
|
+
if (sel.file) { const o = el("button", "btn sm"); o.append(icon("code"), document.createTextNode("Open")); o.onclick = () => openFile(sel.file, sel.line); acts.append(o); }
|
|
837
|
+
const cp = el("button", "btn sm"); cp.append(icon("copy"), document.createTextNode("Copy ref")); cp.onclick = () => { navigator.clipboard?.writeText(sel.ref); toast("ok", "Copied", sel.ref); }; acts.append(cp);
|
|
838
|
+
try { const r = await api(url(P("symbol"), { ref: sel.ref })); pre.textContent = r.card; } catch (e) { pre.textContent = "Details are not available here."; }
|
|
839
|
+
} else if (sel.kind === "file") {
|
|
840
|
+
const f = S.st.files.find((x) => x.path === sel.ref) || { path: sel.ref };
|
|
841
|
+
box.append(el("h2", null, base(sel.ref)), el("div", "loc mono", sel.ref));
|
|
842
|
+
const kv = el("dl", "kv"); [["language", f.lang], ["layer", f.layer], ["lines", f.lines], ["functions", f.functions], ["classes", f.classes], ["status", f.status ? { A: "added since the last step", M: "modified since the last step", D: "deleted" }[f.status] : "unchanged"]].forEach(([k, val]) => { if (val != null && val !== "") kv.append(el("dt", null, k), el("dd", null, String(val))); });
|
|
843
|
+
box.append(kv);
|
|
844
|
+
if (f.secret) box.append(el("div", "chip warn", "secret-looking: never read"));
|
|
845
|
+
const acts = el("div", "actions"); const o = el("button", "btn sm primary", "Open"); o.onclick = () => openFile(sel.ref); acts.append(o);
|
|
846
|
+
if (f.status === "M" || f.status === "A") { const d = el("button", "btn sm", "Diff"); const last = S.st.steps[S.st.steps.length - 1]; d.onclick = () => openDiff(sel.ref, last ? String(last.n) : "live", "live"); acts.append(d); }
|
|
847
|
+
box.append(acts);
|
|
848
|
+
} else if (sel.kind === "component") {
|
|
849
|
+
const c = S.sysComps && S.sysComps[sel.ref]; if (!c) return;
|
|
850
|
+
box.append(el("h2", null, c.title), el("div", "sysdesc", c.desc));
|
|
851
|
+
const kv = el("dl", "kv"); for (const [k, val] of c.stats) kv.append(el("dt", null, k), el("dd", null, String(val))); box.append(kv);
|
|
852
|
+
for (const sec of c.sections) {
|
|
853
|
+
if (!sec.rows.length) continue;
|
|
854
|
+
box.append(el("div", "kind", sec.title));
|
|
855
|
+
for (const r of sec.rows.slice(0, 40)) { const row = el("div", "ev link"); row.append(el("span", null, r.label)); if (r.meta) row.append(el("span", "meta", r.meta)); row.onclick = r.run; box.append(row); }
|
|
856
|
+
if (sec.rows.length > 40) box.append(el("div", "empty", `+${sec.rows.length - 40} more`));
|
|
857
|
+
}
|
|
858
|
+
} else if (sel.kind === "infra") {
|
|
859
|
+
const n = S.st.infra.nodes.find((x) => x.id === sel.ref); if (!n) return;
|
|
860
|
+
box.append(el("h2", null, n.label)); const kv = el("dl", "kv"); kv.append(el("dt", null, "kind"), el("dd", null, n.kind), el("dt", null, "detail"), el("dd", null, n.detail || "—"), el("dt", null, "found in"), el("dd", null, n.sources.join(", "))); box.append(kv);
|
|
861
|
+
const out = S.st.infra.edges.filter((e) => e.from === n.id || e.to === n.id); if (out.length) { box.append(el("div", "kind", "Connections")); for (const e of out) box.append(el("div", "ev", `${e.from === n.id ? "→" : "←"} ${e.label} ${e.from === n.id ? e.to : e.from}`)); }
|
|
862
|
+
const src = n.sources.find((s) => S.st.files.some((f) => f.path === s)); if (src) { const o = el("button", "btn sm", "Open " + base(src)); o.onclick = () => openFile(src); box.append(o); }
|
|
863
|
+
} else if (sel.kind === "concept") {
|
|
864
|
+
const c = S.st.concepts.find((x) => x.id === sel.ref); if (!c) return;
|
|
865
|
+
const h = el("h2"); h.append(icon(c.icon), document.createTextNode(" " + c.title)); box.append(h, el("p", null, c.meaning));
|
|
866
|
+
box.append(el("div", "kind", "Evidence in the code")); for (const e of c.evidence) { const r = el("div", "ev"); r.append(el("span", "f mono", `${e.file}:${e.line}`), el("span", "s", e.signal)); r.onclick = () => openFile(e.file, e.line); box.append(r); }
|
|
867
|
+
if (c.claims.length) { box.append(el("div", "kind", "Claimed by the agent")); for (const cl of c.claims) { const r = el("div", "ev"); r.append(el("span", "badge " + cl.status, cl.status), el("span", "f mono", cl.symbol)); box.append(r, el("div", "s", cl.reason || "")); } }
|
|
868
|
+
} else if (sel.kind === "route") {
|
|
869
|
+
box.append(el("h2", null, sel.ref)); if (sel.file) { const l = el("div", "loc mono", `${sel.file}:${sel.line || ""}`); l.onclick = () => openFile(sel.file, sel.line); box.append(l); }
|
|
870
|
+
const r = S.st.routes.find((x) => `${x.method} ${x.path}` === sel.ref); if (r?.fid) { const b = el("button", "btn sm primary", "Handler flowchart"); b.onclick = () => openFlow(r.fid); box.append(b); }
|
|
871
|
+
} else if (sel.kind === "line") {
|
|
872
|
+
box.append(el("h2", null, sel.ref || "line"), el("div", "loc mono", `${sel.file}:${sel.line}`));
|
|
873
|
+
} else { box.append(el("h2", null, sel.ref || "")); }
|
|
874
|
+
}
|
|
875
|
+
async function briefPanel(body) {
|
|
876
|
+
const box = el("div", "insp"); body.append(box);
|
|
877
|
+
box.append(el("p", null, "What the agent reads instead of exploring files. No source code; it points at file:line so the agent opens only what it needs."));
|
|
878
|
+
const pre = el("pre", "cardtxt", S.brief ? S.brief.text : "…"); box.append(pre);
|
|
879
|
+
const acts = el("div", "actions"); const cp = el("button", "btn sm", "Copy"); cp.onclick = () => { navigator.clipboard?.writeText(pre.textContent); toast("ok", "Copied", "Paste it into any agent's context."); }; acts.append(cp); box.append(acts);
|
|
880
|
+
if (!S.brief) try { S.brief = await api(url(P("brief"), {})); pre.textContent = S.brief.text; renderStatus(); } catch (e) { pre.textContent = "Not available."; }
|
|
881
|
+
if (S.brief) box.append(el("div", "kind", `${S.brief.chars} characters · about ${S.brief.tokens} tokens`));
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
// ------------------------------------------------------------------ bottom panel
|
|
885
|
+
function renderBottom() {
|
|
886
|
+
const tabs = $("#btabs"), body = $("#bbody"); tabs.replaceChildren(); body.replaceChildren();
|
|
887
|
+
if (!S.st) return;
|
|
888
|
+
const counts = { steps: S.st.steps.length, todo: S.st.todos.filter((t) => t.status === "open").length, problems: S.st.problems.length, activity: "" };
|
|
889
|
+
for (const [id, ic, title] of BOTTOM) { const b = el("button", "btab" + (S.btab === id ? " on" : "")); b.append(icon(ic), document.createTextNode(title)); if (counts[id]) b.append(el("span", "n", String(counts[id]))); b.onclick = () => { S.btab = id; saveUI(); renderBottom(); renderStripes(); }; tabs.append(b); }
|
|
890
|
+
tabs.append(el("span", "grow")); const hide = el("button", "tbtn"); hide.title = "Hide"; hide.append(icon("close")); hide.onclick = () => { S.bottomOpen = false; saveUI(); renderAll(); }; tabs.append(hide);
|
|
891
|
+
if (S.btab === "steps") {
|
|
892
|
+
for (const s of [...S.st.steps].reverse()) { const r = el("div", "bl" + (S.step === s.n ? " ok" : "")); r.style.cursor = "pointer"; r.append(icon("flag"), el("span", "when", "#" + s.n), el("span", "txt", s.title), el("span", "badge " + s.source, s.source), el("span", "tag", `${s.summary.files} files +${s.summary.added}/−${s.summary.removed}`), el("span", "when", ago(s.ts))); r.onclick = () => setStep(s.n); body.append(r); }
|
|
893
|
+
} else if (S.btab === "todo") {
|
|
894
|
+
const add = el("div", "addrow"); const inp = el("input", "input"); inp.placeholder = "Add a todo for the agent (it sees it in the map)"; const b = el("button", "btn sm primary", "Add");
|
|
895
|
+
const doAdd = async () => { if (!inp.value.trim()) return; try { await api(P("todo"), { action: "add", text: inp.value.trim() }); inp.value = ""; await load(false); } catch (e) { if (e.message !== "demo") toast("err", "Could not add", e.message); } };
|
|
896
|
+
b.onclick = doAdd; inp.onkeydown = (e) => { if (e.key === "Enter") doAdd(); }; add.append(inp, b); body.append(add);
|
|
897
|
+
for (const t of S.st.todos) { const r = el("div", "bl" + (t.status === "done" ? (t.verified ? " ok" : " warn") : "")); r.append(icon(t.status === "done" ? (t.verified ? "check-square" : "warning") : "check"), el("span", "when", t.id), el("span", "txt", t.text), el("span", "tag", t.status === "done" ? (t.verified ? "done · verified" : "done · " + (t.reason || "unverified")) : t.status + (t.by === "user" ? " · from you" : ""))); body.append(r); }
|
|
898
|
+
if (!S.st.todos.length) body.append(el("div", "empty", "No todos yet."));
|
|
899
|
+
} else if (S.btab === "problems") {
|
|
900
|
+
if (!S.st.problems.length) body.append(el("div", "bl ok", null)), body.lastChild.append(icon("check"), el("span", "txt", "Everything the agent claimed checks out against the code."));
|
|
901
|
+
for (const x of S.st.problems) { const r = el("div", "bl warn"); r.append(icon("warning"), el("span", "badge " + x.status, x.kind), el("span", "txt", x.text)); body.append(r); }
|
|
902
|
+
} else {
|
|
903
|
+
for (const e of [...S.st.activity].reverse()) {
|
|
904
|
+
const txt = e.t === "prompt" ? "prompt: " + (e.text || "") : e.t === "tool" ? `${e.tool} ${(e.files || []).join(", ")}` : e.t === "step" ? `step ${e.n}: ${e.title}` : e.t === "turn_end" ? "agent finished its turn" : e.t === "todo" ? `todo ${e.tid}: ${e.text}` : e.t === "todo_done" ? `todo ${e.tid} done` : e.t === "claim" ? `claim ${e.concept} → ${e.symbol}` : e.t === "note" ? `note ${e.symbol}: ${e.role}` : e.t;
|
|
905
|
+
const r = el("div", "bl"); r.append(icon({ prompt: "user", tool: "terminal", step: "flag", turn_end: "check", todo: "check-square", todo_done: "check-square", claim: "puzzle", note: "doc" }[e.t] || "activity"), el("span", "when", clock(e.ts)), el("span", "txt", txt), el("span", "tag", e.agent || "")); body.append(r);
|
|
906
|
+
}
|
|
907
|
+
if (!S.st.activity.length) body.append(el("div", "empty", "No agent activity recorded yet. Connected agents report prompts, edits and steps here."));
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
// ------------------------------------------------------------------ status bar
|
|
912
|
+
function renderStatus() {
|
|
913
|
+
const s = $("#status"); s.replaceChildren();
|
|
914
|
+
const crumbs = el("div", "crumbs"); const tab = allTabs().find((t) => t.id === S.active);
|
|
915
|
+
if (S.st) crumbs.append(el("b", null, S.st.name)); if (tab) crumbs.append(document.createTextNode(" › " + (tab.hint || tab.title)));
|
|
916
|
+
if (S.sel && S.sel.ref) crumbs.append(document.createTextNode(" › " + short(S.sel.ref)));
|
|
917
|
+
s.append(crumbs);
|
|
918
|
+
if (S.st) {
|
|
919
|
+
s.append(el("span", "it", `${S.st.counts.files} files indexed`));
|
|
920
|
+
if (S.brief) { const b = el("span", "it", `brief ≈ ${S.brief.tokens} tokens`); b.title = "Size of the map an agent reads instead of exploring the code"; s.append(b); }
|
|
921
|
+
const st = el("span", "it", S.step === "live" ? `live · ${S.st.steps.length} steps` : `viewing step ${S.step}`); s.append(st);
|
|
922
|
+
}
|
|
923
|
+
const c = el("span", "it"); const dot = el("span", "ldot " + (S.conn === "live" ? "on" : S.conn === "demo" ? "" : "off")); c.append(dot, document.createTextNode({ live: "connected", demo: "demo data", offline: "daemon offline", token: "unauthorised", connecting: "connecting…" }[S.conn] || S.conn)); s.append(c);
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
// ------------------------------------------------------------------ actions, menus, palette, settings, toasts
|
|
927
|
+
async function recordStep() {
|
|
928
|
+
const title = prompt("Step title (what was done). The changed files are computed by Mapwright.");
|
|
929
|
+
if (!title) return;
|
|
930
|
+
try { const r = await api(P("step"), { title }); toast("ok", "Step recorded", r.receipt); await load(false); } catch (e) { if (e.message !== "demo") toast("err", "Could not record", e.message); }
|
|
931
|
+
}
|
|
932
|
+
function toast(kind, title, text) {
|
|
933
|
+
const t = el("div", "toast " + kind); t.append(icon(kind === "ok" ? "check" : kind === "err" ? "warning" : "info")); const b = el("div"); b.append(el("b", null, title), el("span", null, text || "")); t.append(b);
|
|
934
|
+
$("#toasts").append(t); setTimeout(() => t.remove(), 4500);
|
|
935
|
+
}
|
|
936
|
+
function menu(anchor, items) {
|
|
937
|
+
closeMenus(); const m = el("div", "menu"); const r = anchor.getBoundingClientRect(); m.style.left = r.left + "px"; m.style.top = r.bottom + 4 + "px";
|
|
938
|
+
for (const it of items) { if (it === "-") { m.append(el("hr")); continue; } if (it.header) { m.append(el("div", "mh", it.header)); continue; } const mi = el("div", "mi"); if (it.icon) mi.append(icon(it.icon)); mi.append(el("span", null, it.label)); if (it.meta) mi.append(el("span", "meta", it.meta)); mi.onclick = () => { closeMenus(); it.run(); }; m.append(mi); }
|
|
939
|
+
const scrim = el("div"); scrim.style.cssText = "position:fixed;inset:0;z-index:39"; scrim.onclick = closeMenus; scrim.dataset.menu = "1"; m.dataset.menu = "1";
|
|
940
|
+
document.body.append(scrim, m);
|
|
941
|
+
}
|
|
942
|
+
function closeMenus() { document.querySelectorAll("[data-menu]").forEach((x) => x.remove()); }
|
|
943
|
+
async function palette() {
|
|
944
|
+
if (!DEMO && !S.st) return;
|
|
945
|
+
closeMenus(); const scrim = el("div", "scrim"); const p = el("div", "palette"); scrim.dataset.menu = p.dataset.menu = "1";
|
|
946
|
+
const head = el("div", "ph"); head.append(icon("search")); const inp = el("input"); inp.placeholder = "Search files, symbols, views and actions"; head.append(inp); const res = el("div", "pr"); p.append(head, res);
|
|
947
|
+
document.body.append(scrim, p); scrim.onclick = closeMenus; inp.focus();
|
|
948
|
+
const actions = [
|
|
949
|
+
...allTabs().map((t) => ({ grp: "Views", label: t.title, icon: t.icon || "file", run: () => openTab(t) })), { grp: "Views", label: "Call graph", icon: "graph", run: () => openTab({ id: "d:calls", title: "Call graph", icon: "graph" }) },
|
|
950
|
+
{ grp: "Views", label: "Concept map", icon: "graph", run: () => openTab({ id: "d:concepts", title: "Concept map", icon: "graph" }) },
|
|
951
|
+
{ grp: "Actions", label: "Record a step", icon: "flag", run: recordStep }, { grp: "Actions", label: "Connect an agent", icon: "plug", run: () => openTab({ id: "setup", title: "Connect an agent", icon: "plug" }) },
|
|
952
|
+
{ grp: "Actions", label: "Settings", icon: "gear", meta: "Ctrl+,", run: settings }, { grp: "Actions", label: "Toggle light / dark theme", icon: "sun", run: () => setTheme(document.documentElement.dataset.theme === "dark" ? "light" : "dark") },
|
|
953
|
+
{ grp: "Actions", label: "Copy the agent brief", icon: "copy", run: async () => { const b = S.brief || await api(url(P("brief"), {})); navigator.clipboard?.writeText(b.text); toast("ok", "Copied", `${b.tokens} tokens`); } },
|
|
954
|
+
{ grp: "Actions", label: "Show live (latest)", icon: "history", run: () => setStep("live") },
|
|
955
|
+
];
|
|
956
|
+
let items = [], act = 0;
|
|
957
|
+
const draw = async () => {
|
|
958
|
+
const q = inp.value.trim().toLowerCase(); items = [];
|
|
959
|
+
const files = (S.st?.files || []).filter((f) => f.status !== "D" && (!q || f.path.toLowerCase().includes(q))).slice(0, q ? 8 : 4).map((f) => ({ grp: "Files", label: base(f.path), meta: f.path, icon: "file", run: () => openFile(f.path) }));
|
|
960
|
+
const acts = actions.filter((a) => !q || a.label.toLowerCase().includes(q)).slice(0, q ? 8 : 6);
|
|
961
|
+
items = [...acts, ...files];
|
|
962
|
+
if (q.length >= 2 && S.key) { try { const r = await api(url(P("find"), { q })); if (inp.value.trim().toLowerCase() !== q) return; items = [...r.results.slice(0, 10).map((x) => ({ grp: "Symbols", label: short(x.id), meta: `${x.kind} · ${x.file}:${x.line || ""}`, icon: x.kind === "class" ? "class" : x.kind === "table" ? "table" : x.kind === "module" ? "file" : "function", run: () => x.kind === "function" ? (select({ kind: "function", ref: x.id, file: x.file, line: x.line }), openFlow(x.id)) : x.kind === "module" ? openFile(x.file) : (select({ kind: x.kind, ref: x.id, file: x.file, line: x.line }), openFile(x.file, x.line)) })), ...items]; } catch (e) {} }
|
|
963
|
+
act = 0; render();
|
|
964
|
+
};
|
|
965
|
+
const render = () => { res.replaceChildren(); let g = null; items.forEach((it, i) => { if (it.grp !== g) { g = it.grp; res.append(el("div", "grp", g)); } const mi = el("div", "mi" + (i === act ? " act" : "")); mi.append(icon(it.icon), el("span", null, it.label)); if (it.meta) mi.append(el("span", "meta", it.meta)); mi.onclick = () => { closeMenus(); it.run(); }; res.append(mi); }); if (!items.length) res.append(el("div", "empty", "Nothing matches.")); };
|
|
966
|
+
inp.oninput = debounce(draw, 90);
|
|
967
|
+
inp.onkeydown = (e) => { if (e.key === "ArrowDown") { act = Math.min(items.length - 1, act + 1); render(); e.preventDefault(); } else if (e.key === "ArrowUp") { act = Math.max(0, act - 1); render(); e.preventDefault(); } else if (e.key === "Enter" && items[act]) { closeMenus(); items[act].run(); } else if (e.key === "Escape") closeMenus(); };
|
|
968
|
+
draw();
|
|
969
|
+
}
|
|
970
|
+
async function settings() {
|
|
971
|
+
closeMenus(); let data; try { data = await api("/v1/settings"); } catch (e) { data = { settings: { theme: store.get("theme", "dark"), font_size: 13 }, defaults: {}, version: "demo" }; }
|
|
972
|
+
const s = { ...data.settings }; const scrim = el("div", "scrim"), m = el("div", "modal"); scrim.dataset.menu = m.dataset.menu = "1";
|
|
973
|
+
const head = el("div", "mh2"); head.append(el("span", null, "Settings"), el("span", "grow")); const x = el("button", "tbtn"); x.append(icon("close")); x.onclick = closeMenus; head.append(x);
|
|
974
|
+
const mb = el("div", "mb"), nav = el("div", "nav"), pane = el("div", "pane"); mb.append(nav, pane);
|
|
975
|
+
const foot = el("div", "mf"); const msg = el("span", "msg"); const cancel = el("button", "btn", "Cancel"); const apply = el("button", "btn", "Apply"); const ok = el("button", "btn primary", "OK"); foot.append(msg, cancel, apply, ok);
|
|
976
|
+
m.append(head, mb, foot); document.body.append(scrim, m); scrim.onclick = closeMenus; cancel.onclick = closeMenus;
|
|
977
|
+
const field = (label, ctrl, help) => { const f = el("div", "field"); f.append(el("label", null, label), ctrl); if (help) f.append(el("div", "help", help)); return f; };
|
|
978
|
+
const seg = (key, opts) => { const w = el("div", "seg"); for (const [v, t] of opts) { const b = el("button", s[key] === v ? "on" : null, t); b.onclick = () => { s[key] = v; [...w.children].forEach((c) => c.classList.toggle("on", c === b)); }; w.append(b); } return w; };
|
|
979
|
+
const num = (key, min, max, step = 1) => { const i = el("input", "input"); i.type = "number"; i.min = min; i.max = max; i.step = step; i.value = s[key]; i.style.width = "120px"; i.oninput = () => { s[key] = step < 1 ? parseFloat(i.value) : parseInt(i.value, 10); }; return i; };
|
|
980
|
+
const tog = (key) => { const i = el("input", "toggle"); i.type = "checkbox"; i.checked = !!s[key]; i.onchange = () => { s[key] = i.checked; }; return i; };
|
|
981
|
+
const pages = {
|
|
982
|
+
Appearance: () => [field("Theme", seg("theme", [["dark", "Dark"], ["light", "Light"]])), field("UI font size", num("font_size", 11, 16), "Applies to panels and diagrams.")],
|
|
983
|
+
Tracking: () => [field("Close steps", seg("auto_step", [["turn", "At each turn end"], ["idle", "After a quiet period"], ["off", "Only when asked"]]), "Turn ends come from agent hooks. Without hooks, steps close after the quiet period."),
|
|
984
|
+
field("Quiet period (s)", num("idle_seconds", 5, 3600)), field("Scan interval (s)", num("watch_interval", 0.5, 60, 0.5), "How often the daemon checks tracked projects for changes.")],
|
|
985
|
+
Analysis: () => { const i = el("input", "input"); i.value = (s.ignore || []).join(", "); i.oninput = () => { s.ignore = i.value.split(",").map((x) => x.trim()).filter(Boolean); }; return [field("Folders to skip", i, "Names, comma-separated. node_modules, .venv, dist, build and similar are always skipped."), field("Maximum files", num("max_files", 100, 50000))]; },
|
|
986
|
+
Agents: () => [field("Brief size (characters)", num("brief_budget", 400, 20000, 100), "About four characters per token. 2400 ≈ 600 tokens."), field("Redact secrets in code views", tog("redact"))],
|
|
987
|
+
Integrations: () => { const b = el("button", "btn", "Open Connect an agent"); b.onclick = () => { closeMenus(); openTab({ id: "setup", title: "Connect an agent", icon: "plug" }); }; return [el("p", null, "Connect Claude Code, Cursor, VS Code, Windsurf, opencode, Codex, Gemini CLI and others."), Object.assign(el("div"), { style: "margin-top:12px" }), b]; },
|
|
988
|
+
About: () => { const kv = el("dl", "kv"); [["Version", data.version], ["Data folder", data.home || "—"], ["Port", data.port || "—"], ["Mode", DEMO ? "demo (read-only)" : "local daemon"]].forEach(([k, v]) => kv.append(el("dt", null, k), el("dd", "mono", String(v)))); return [kv, Object.assign(el("p"), { textContent: "Everything stays on this machine. Nothing is sent anywhere.", style: "margin-top:14px;color:var(--muted)" }), ...(DEMO ? [] : [Object.assign(el("p"), { textContent: "The access token is kept in this browser so you do not need the link every time.", style: "margin-top:14px;color:var(--muted)" }), Object.assign(el("button", "btn", "Forget token"), { id: "forget-token", onclick: forgetToken })])]; },
|
|
989
|
+
};
|
|
990
|
+
let cur = "Appearance";
|
|
991
|
+
const show = () => { nav.replaceChildren(); for (const k of Object.keys(pages)) { const r = el("div", "row" + (k === cur ? " sel" : ""), k); r.onclick = () => { cur = k; show(); }; nav.append(r); } pane.replaceChildren(el("h3", null, cur), ...pages[cur]()); };
|
|
992
|
+
show();
|
|
993
|
+
const save = async () => { setTheme(s.theme); document.documentElement.style.setProperty("--ui", (s.font_size || 13) + "px"); const changes = {}; for (const [k, v] of Object.entries(s)) if (JSON.stringify(v) !== JSON.stringify(data.settings[k])) changes[k] = v;
|
|
994
|
+
if (!Object.keys(changes).length || DEMO) { msg.textContent = DEMO ? "Demo: appearance applied in this browser only" : "No changes"; return true; }
|
|
995
|
+
try { const r = await api("/v1/settings", changes); data.settings = r.settings; msg.textContent = "Saved"; return true; } catch (e) { msg.textContent = "Not saved: " + e.message; return false; } };
|
|
996
|
+
apply.onclick = save; ok.onclick = async () => { if (await save()) closeMenus(); };
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
// ------------------------------------------------------------------ wiring
|
|
1000
|
+
function wire() {
|
|
1001
|
+
$("#w-search").onclick = palette; $("#w-search").onkeydown = (e) => { if (e.key === "Enter") palette(); };
|
|
1002
|
+
$("#w-settings").onclick = settings; $("#w-step-add").onclick = recordStep;
|
|
1003
|
+
$("#w-theme").onclick = () => setTheme(document.documentElement.dataset.theme === "dark" ? "light" : "dark");
|
|
1004
|
+
$("#w-agents").onclick = () => openTab({ id: "setup", title: "Connect an agent", icon: "plug" });
|
|
1005
|
+
$("#right-close").onclick = () => { S.rightOpen = false; saveUI(); renderAll(); };
|
|
1006
|
+
$("#w-project").onclick = (e) => menu(e.currentTarget, [{ header: "Tracked projects" }, ...S.projects.map((p) => ({ label: p.name, meta: p.root, icon: p.key === S.key ? "check" : "folder", run: () => { S.key = p.key; S.step = "live"; S.tabs = []; S.active = "overview"; S.sel = null; S.view = {}; saveUI(); load(true); } })), "-", { label: "Track another folder…", icon: "plus", run: () => openTab({ id: "setup", title: "Connect an agent", icon: "plug" }) }]);
|
|
1007
|
+
$("#w-step").onclick = (e) => { if (!S.st) return; menu(e.currentTarget, [{ label: "Live (latest)", meta: `${S.st.pending.length} pending`, icon: S.step === "live" ? "check" : "history", run: () => setStep("live") }, "-", ...[...S.st.steps].reverse().slice(0, 30).map((s) => ({ label: `#${s.n} ${s.title.slice(0, 48)}`, meta: ago(s.ts), icon: S.step === s.n ? "check" : "flag", run: () => setStep(s.n) }))]); };
|
|
1008
|
+
let lastShift = 0;
|
|
1009
|
+
document.addEventListener("keydown", (e) => {
|
|
1010
|
+
if (e.key === "Shift" && !e.repeat) { const now = Date.now(); if (now - lastShift < 350) palette(); lastShift = now; }
|
|
1011
|
+
if ((e.ctrlKey || e.metaKey) && (e.key === "k" || e.key === "p")) { e.preventDefault(); palette(); }
|
|
1012
|
+
if ((e.ctrlKey || e.metaKey) && e.key === ",") { e.preventDefault(); settings(); }
|
|
1013
|
+
if (e.key === "Escape") closeMenus();
|
|
1014
|
+
if (e.altKey && /^[1-9]$/.test(e.key)) { const t = FIXED[+e.key - 1]; if (t) openTab(t); }
|
|
1015
|
+
});
|
|
1016
|
+
document.querySelectorAll(".resize").forEach((h) => h.addEventListener("pointerdown", (e) => {
|
|
1017
|
+
const key = h.dataset.r, start = { x: e.clientX, y: e.clientY, v: store.get(key, key === "bh" ? 220 : key === "lw" ? 280 : 320) }; h.setPointerCapture(e.pointerId);
|
|
1018
|
+
const mv = (ev) => { const d = key === "lw" ? ev.clientX - start.x : key === "rw" ? start.x - ev.clientX : start.y - ev.clientY; const v = Math.max(160, Math.min(key === "bh" ? 600 : 640, start.v + d)); store.set(key, v); key === "bh" ? $("#bottom").style.setProperty("--bh", v + "px") : $("#ide").style.setProperty("--" + key, v + "px"); };
|
|
1019
|
+
const up = () => { h.removeEventListener("pointermove", mv); h.removeEventListener("pointerup", up); for (const k of Object.keys(S.view)) if (S.view[k]) S.view[k].fit = true; };
|
|
1020
|
+
h.addEventListener("pointermove", mv); h.addEventListener("pointerup", up);
|
|
1021
|
+
}));
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
boot();
|
|
1025
|
+
})();
|