penthera 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/CHANGELOG.md +315 -0
  2. package/README.md +139 -76
  3. package/SECURITY.md +8 -6
  4. package/docs/examples/pr-dependency-review.yml +1 -1
  5. package/lib/adaptive-probes.js +3 -3
  6. package/lib/advisories/evidence.js +248 -0
  7. package/lib/advisories/index.js +228 -0
  8. package/lib/advisories/products.js +83 -0
  9. package/lib/advisories/versions.js +65 -0
  10. package/lib/agents/hidden-content.js +122 -11
  11. package/lib/agents/index.js +26 -6
  12. package/lib/agents/lock.js +33 -5
  13. package/lib/agents/rules.js +33 -4
  14. package/lib/compliance/index.js +4 -4
  15. package/lib/crawler.js +12 -15
  16. package/lib/deps/capabilities.js +21 -5
  17. package/lib/deps/findings.js +309 -0
  18. package/lib/deps/index.js +13 -272
  19. package/lib/deps/iocs.js +74 -0
  20. package/lib/deps/lockfile.js +3 -8
  21. package/lib/deps/online.js +8 -3
  22. package/lib/deps/popular-packages.json.gz +0 -0
  23. package/lib/deps/popular-pypi.json.gz +0 -0
  24. package/lib/deps/python/capabilities.js +16 -3
  25. package/lib/deps/python/index.js +5 -1
  26. package/lib/deps/python/lockfiles.js +11 -5
  27. package/lib/deps/python/source.js +75 -26
  28. package/lib/deps/python/toml.js +15 -3
  29. package/lib/deps/source.js +28 -9
  30. package/lib/deps/typosquat.js +30 -5
  31. package/lib/fix/apply.js +253 -34
  32. package/lib/fix/index.js +7 -4
  33. package/lib/fix/model.js +25 -5
  34. package/lib/fix/util.js +6 -2
  35. package/lib/fuzzer.js +3 -3
  36. package/lib/git.js +65 -0
  37. package/lib/hook/index.js +157 -73
  38. package/lib/hook/policy.js +10 -4
  39. package/lib/install/index.js +4 -7
  40. package/lib/machine.js +0 -13
  41. package/lib/memory/store.js +11 -4
  42. package/lib/nuclei-loader.js +0 -25
  43. package/lib/owasp-wstg.js +4 -0
  44. package/lib/plugins.js +1 -1
  45. package/lib/provenance.js +1 -0
  46. package/lib/recon.js +12 -31
  47. package/lib/references.json +224 -0
  48. package/lib/retirejs.js +4 -4
  49. package/lib/rules/advisories/advisories.json +186 -0
  50. package/lib/rules/advisories/eol.json +413 -0
  51. package/lib/rules/advisories/pack.json +20 -0
  52. package/lib/rules/advisories/pack.json.sig +6 -0
  53. package/lib/rules/allowed_signers +13 -0
  54. package/lib/rules/core/agent-exec.json +29 -0
  55. package/lib/rules/core/agent-instructions.json +17 -0
  56. package/lib/rules/core/pack.json +30 -0
  57. package/lib/rules/core/pack.json.sig +6 -0
  58. package/lib/rules/core/secrets.json +161 -0
  59. package/lib/rules/core/templates.json +52 -0
  60. package/lib/rules/index.js +107 -0
  61. package/lib/rules/ioc-2025-2026/files.json +43 -0
  62. package/lib/rules/ioc-2025-2026/hosts.json +35 -0
  63. package/lib/rules/ioc-2025-2026/pack.json +25 -0
  64. package/lib/rules/ioc-2025-2026/pack.json.sig +6 -0
  65. package/lib/rules/ioc-2025-2026/packages.json +1048 -0
  66. package/lib/rules/pack.js +452 -0
  67. package/lib/rules/regex-guard.js +81 -9
  68. package/lib/rules/sshsig.js +205 -0
  69. package/lib/templates.js +24 -20
  70. package/lib/tmp.js +21 -0
  71. package/lib/whitebox/frameworks.js +1 -1
  72. package/lib/whitebox/secrets.js +117 -41
  73. package/package.json +12 -4
  74. package/scripts/rules/build-pack.mjs +80 -0
  75. package/scripts/rules/check-bundled.mjs +30 -0
  76. package/scripts/rules/sign-pack.sh +32 -0
  77. package/skills/penthera/SKILL.md +16 -15
  78. package/src/agent/git.js +147 -14
  79. package/src/agent/loop.js +165 -46
  80. package/src/cli/agent.js +11 -5
  81. package/src/cli/deps.js +0 -2
  82. package/src/cli/detect.js +14 -7
  83. package/src/cli/fix.js +26 -8
  84. package/src/cli/hook.js +2 -1
  85. package/src/cli/onboarding.js +14 -6
  86. package/src/cli/report-outputs.js +1 -0
  87. package/src/cli/rules.js +144 -0
  88. package/src/cli/ui.js +43 -10
  89. package/src/cli.js +24 -1
  90. package/src/report/evidence.js +105 -21
  91. package/src/report/footer.js +1 -1
  92. package/src/report/md-escape.js +8 -0
  93. package/src/scan-repo.js +6 -0
  94. package/src/scan-url.js +11 -3
  95. package/src/ui/api/data.js +39 -6
  96. package/src/ui/api/routes.js +44 -11
  97. package/src/ui/api/runs.js +32 -7
  98. package/src/ui/security.js +20 -23
  99. package/src/ui/server.js +52 -27
  100. package/src/ui/static/app.css +583 -213
  101. package/src/ui/static/favicon.svg +1 -1
  102. package/src/ui/static/fonts/DepartureMono-LICENSE.txt +93 -0
  103. package/src/ui/static/fonts/DepartureMono-Regular.woff2 +0 -0
  104. package/src/ui/static/index.html +5 -4
  105. package/src/ui/static/js/api.js +114 -6
  106. package/src/ui/static/js/app.js +81 -42
  107. package/src/ui/static/js/center.js +246 -133
  108. package/src/ui/static/js/charts.js +99 -18
  109. package/src/ui/static/js/copy.js +68 -9
  110. package/src/ui/static/js/dialog.js +152 -0
  111. package/src/ui/static/js/left.js +23 -60
  112. package/src/ui/static/js/menubar.js +170 -0
  113. package/src/ui/static/js/onboarding.js +104 -0
  114. package/src/ui/static/js/panels.js +186 -0
  115. package/src/ui/static/js/right.js +69 -188
  116. package/src/ui/static/js/state.js +36 -5
  117. package/src/ui/static/logo.svg +10 -0
  118. package/src/ui/static/mark.svg +3 -0
  119. package/src/utils/http.js +162 -13
  120. package/docs/METHODOLOGY.md +0 -375
  121. package/docs/commands/README.md +0 -24
  122. package/docs/commands/action.md +0 -21
  123. package/docs/commands/agents.md +0 -38
  124. package/docs/commands/deps.md +0 -115
  125. package/docs/commands/fix.md +0 -53
  126. package/docs/commands/hook.md +0 -69
  127. package/docs/commands/init.md +0 -114
  128. package/docs/commands/install.md +0 -53
  129. package/docs/commands/scan.md +0 -100
  130. package/docs/commands/skill.md +0 -58
  131. package/docs/compare/README.md +0 -25
  132. package/docs/compare/github.md +0 -60
  133. package/docs/compare/semgrep.md +0 -54
  134. package/docs/compare/snyk.md +0 -62
  135. package/docs/compare/socket.md +0 -78
  136. package/docs/compare/zap.md +0 -59
  137. package/docs/compliance-cra.md +0 -141
  138. package/docs/compliance-nis2.md +0 -168
  139. package/docs/dashboard.md +0 -187
  140. package/docs/evidence.md +0 -162
  141. package/docs/funding/due-diligence-checklist.md +0 -79
  142. package/docs/funding/nlnet-ngi-zero-draft.md +0 -273
  143. package/docs/funding/partner-one-pager.md +0 -84
  144. package/docs/funding/sponsor-tiers.md +0 -81
  145. package/docs/index.md +0 -81
  146. package/docs/internal-audit.md +0 -83
  147. package/docs/local-loop.md +0 -276
  148. package/docs/marketing.md +0 -151
  149. package/docs/owasp-wstg-coverage.md +0 -79
  150. package/docs/plan.md +0 -102
  151. package/docs/privacy.md +0 -38
  152. package/docs/references.bib +0 -559
  153. package/docs/references.md +0 -119
  154. package/docs/release-plan.md +0 -228
  155. package/docs/research/socket-positioning-notes.md +0 -183
  156. package/docs/use-cases/README.md +0 -14
  157. package/docs/use-cases/agencies.md +0 -71
  158. package/docs/use-cases/ai-coding-teams.md +0 -81
  159. package/docs/use-cases/eu-sme-compliance.md +0 -68
  160. package/docs/use-cases/open-source-maintainers.md +0 -75
  161. package/docs/use-cases/solo-founder.md +0 -65
  162. package/lib/deps/popular-packages.json +0 -1
  163. package/lib/deps/popular-pypi.json +0 -1
@@ -1 +1 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 8 8" shape-rendering="crispEdges"><rect width="8" height="8" fill="#000"/><path d="M1 1h4v1h1v2H5v1H3v2H1zM3 2v2h2V2z" fill="#fff"/><rect x="6" y="6" width="1" height="1" fill="#0000ed"/></svg>
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect width="32" height="32" fill="#0000ed"/><path transform="translate(10 4) scale(0.0857)" d="M58.7302 243.645L108.182 280L58.7302 255.125H0L33.3333 243.645V11.4806L0 0H75.5556C115.238 0 140 19.7722 140 50.0683C140 94.7152 92.0635 117.676 58.7302 119.909V243.645ZM58.7302 3.18906V116.72C78.7302 115.125 112.698 103.964 112.698 58.3599C112.698 27.4259 93.6508 3.18906 58.7302 3.18906Z" fill="#fff"/></svg>
@@ -0,0 +1,93 @@
1
+ Copyright 2022–2024 Helena Zhang (helenazhang.com).
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ https://openfontlicense.org
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -5,7 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
6
6
  <meta name="color-scheme" content="dark light">
7
7
  <meta name="referrer" content="no-referrer">
8
- <title>penthera ui</title>
8
+ <title>Penthera</title>
9
9
  <link rel="icon" href="/favicon.svg" type="image/svg+xml">
10
10
  <script src="/js/theme.js"></script>
11
11
  <link rel="stylesheet" href="/app.css">
@@ -13,12 +13,13 @@
13
13
  </head>
14
14
  <body>
15
15
  <a class="skip" href="#center">Skip to content</a>
16
+ <header class="menubar" id="menubar"></header>
16
17
  <div class="app" id="app">
17
- <aside class="left" id="left" aria-label="Projects and runs"></aside>
18
- <main class="center" id="center" tabindex="-1">
18
+ <aside class="left pane" id="left" aria-label="Projects and runs"></aside>
19
+ <main class="center pane" id="center" tabindex="-1">
19
20
  <noscript><p class="pad">penthera ui needs JavaScript: every view reads from the local API on this machine.</p></noscript>
20
21
  </main>
21
- <aside class="right" id="right" aria-label="Details"></aside>
22
+ <aside class="right pane" id="right" aria-label="Details"></aside>
22
23
  <div class="scrim" id="scrim" hidden></div>
23
24
  </div>
24
25
  <div class="sr" role="status" aria-live="polite" id="announce"></div>
@@ -1,6 +1,11 @@
1
- // Same-origin JSON client. The session cookie is HttpOnly and SameSite=Strict,
2
- // so it rides along on its own; POSTs send JSON so the server's Origin and
3
- // Content-Type checks pass for this page and fail for every other site.
1
+ // Same-origin JSON client. `penthera ui` prints a link with a one-time token
2
+ // after the # (never sent over the network). signIn() posts it once, gets a
3
+ // session id back and keeps that in this tab's sessionStorage; every request
4
+ // then carries it as `Authorization: Bearer`. No cookie: cookies are not bound
5
+ // to a port, so every other server on 127.0.0.1 would receive one.
6
+
7
+ const SESSION_KEY = "penthera-ui-session";
8
+ let sid = null;
4
9
 
5
10
  export class ApiError extends Error {
6
11
  constructor(message, status) {
@@ -9,12 +14,34 @@ export class ApiError extends Error {
9
14
  }
10
15
  }
11
16
 
12
- async function call(method, path, body) {
17
+ function stored() {
18
+ try { return sessionStorage.getItem(SESSION_KEY); } catch { return null; }
19
+ }
20
+
21
+ /** Redeem `#t=<token>` from the address bar (and remove it from there), or reuse this tab's session. */
22
+ export async function signIn() {
23
+ const m = /^#t=([A-Za-z0-9_-]{16,128})$/.exec(location.hash);
24
+ if (m) {
25
+ history.replaceState(null, "", location.pathname);
26
+ const r = await call("POST", "/api/session", { token: m[1] }, false);
27
+ sid = r.session;
28
+ try { sessionStorage.setItem(SESSION_KEY, sid); } catch { /* storage off: this page load only */ }
29
+ return;
30
+ }
31
+ sid = stored();
32
+ }
33
+
34
+ function headers(extra = {}) {
35
+ return sid ? { ...extra, Authorization: `Bearer ${sid}` } : extra;
36
+ }
37
+
38
+ async function call(method, path, body, auth = true) {
39
+ const base = body === undefined ? { Accept: "application/json" } : { Accept: "application/json", "Content-Type": "application/json" };
13
40
  const res = await fetch(path, {
14
41
  method,
15
- credentials: "same-origin",
42
+ credentials: "omit",
16
43
  cache: "no-store",
17
- headers: body === undefined ? { Accept: "application/json" } : { Accept: "application/json", "Content-Type": "application/json" },
44
+ headers: auth ? headers(base) : base,
18
45
  body: body === undefined ? undefined : JSON.stringify(body),
19
46
  });
20
47
  let data = null;
@@ -23,7 +50,88 @@ async function call(method, path, body) {
23
50
  return data;
24
51
  }
25
52
 
53
+ /** Fetch a file the API serves as an attachment and hand it to the browser as a download. */
54
+ async function download(path) {
55
+ const res = await fetch(path, { credentials: "omit", cache: "no-store", headers: headers() });
56
+ if (!res.ok) {
57
+ let data = null;
58
+ try { data = await res.json(); } catch { /* not JSON */ }
59
+ throw new ApiError(data?.error || `${res.status} ${res.statusText}`, res.status);
60
+ }
61
+ const name = /filename="([^"]+)"/.exec(res.headers.get("Content-Disposition") || "")?.[1] || "penthera-report.md";
62
+ const href = URL.createObjectURL(await res.blob());
63
+ const a = document.createElement("a");
64
+ a.href = href;
65
+ a.download = name;
66
+ document.body.append(a);
67
+ a.click();
68
+ a.remove();
69
+ setTimeout(() => URL.revokeObjectURL(href), 10_000);
70
+ }
71
+
72
+ /**
73
+ * Read a run's event stream with fetch, so it carries the Authorization
74
+ * header (EventSource cannot). Reconnects with Last-Event-ID after a dropped
75
+ * connection. Returns { close }.
76
+ * @param {string} path
77
+ * @param {(type: string, data: string) => void} onEvent
78
+ */
79
+ function stream(path, onEvent) {
80
+ const ctl = new AbortController();
81
+ let last = 0;
82
+ let done = false;
83
+ let tries = 0;
84
+ const dispatch = (block) => {
85
+ let type = "message";
86
+ let id = null;
87
+ const data = [];
88
+ for (const line of block.split("\n")) {
89
+ if (!line || line.startsWith(":")) continue;
90
+ const i = line.indexOf(":");
91
+ const field = i < 0 ? line : line.slice(0, i);
92
+ const value = i < 0 ? "" : line.slice(i + 1).replace(/^ /, "");
93
+ if (field === "event") type = value;
94
+ else if (field === "data") data.push(value);
95
+ else if (field === "id") id = value;
96
+ }
97
+ if (id != null && /^\d+$/.test(id)) last = Number(id);
98
+ if (type === "end") done = true;
99
+ onEvent(type, data.join("\n"));
100
+ };
101
+ (async () => {
102
+ while (!done && !ctl.signal.aborted) {
103
+ try {
104
+ const res = await fetch(path, {
105
+ credentials: "omit", cache: "no-store", signal: ctl.signal,
106
+ headers: headers({ Accept: "text/event-stream", ...(last ? { "Last-Event-ID": String(last) } : {}) }),
107
+ });
108
+ if (!res.ok || !res.body) { onEvent("error", JSON.stringify({ status: res.status })); return; }
109
+ tries = 0;
110
+ const reader = res.body.pipeThrough(new TextDecoderStream()).getReader();
111
+ let buf = "";
112
+ for (;;) {
113
+ const { value, done: eof } = await reader.read();
114
+ if (eof) break;
115
+ buf += value.replace(/\r\n?/g, "\n");
116
+ let cut;
117
+ while ((cut = buf.indexOf("\n\n")) >= 0) {
118
+ dispatch(buf.slice(0, cut));
119
+ buf = buf.slice(cut + 2);
120
+ }
121
+ }
122
+ } catch {
123
+ if (ctl.signal.aborted) return;
124
+ }
125
+ if (done || ++tries > 5) return;
126
+ await new Promise((r) => setTimeout(r, 500 * tries));
127
+ }
128
+ })();
129
+ return { close: () => ctl.abort() };
130
+ }
131
+
26
132
  export const api = {
27
133
  get: (path) => call("GET", path),
28
134
  post: (path, body = {}) => call("POST", path, body),
135
+ download,
136
+ stream,
29
137
  };
@@ -1,17 +1,23 @@
1
- // penthera ui: one view. Left: projects and runs. Centre: the selected project
2
- // or run. Right: cards, or the open finding, or settings.
1
+ // penthera ui: a menu bar over three tiled windows. Projects on the left, the
2
+ // selected project (five tabs) or run in the centre, the inspector on the
3
+ // right. Runs start from the New scan dialog; every action is also in a menu.
3
4
  import { h, clear, announce } from "./dom.js";
4
- import { api } from "./api.js";
5
- import { patternDefs } from "./charts.js";
6
- import { state, set, on } from "./state.js";
5
+ import { api, signIn } from "./api.js";
6
+ import { patternDefs, riskLevel } from "./charts.js";
7
+ import { state, set, on, TABS, countsInView } from "./state.js";
8
+ import { renderMenubar, closeMenus } from "./menubar.js";
7
9
  import { renderLeft } from "./left.js";
8
- import { renderCenter, renderBar, refreshList, moveFinding, answerPending } from "./center.js";
10
+ import { renderCenter, refreshList, moveFinding, answerPending } from "./center.js";
9
11
  import { renderRight } from "./right.js";
12
+ import { newScan, about } from "./dialog.js";
13
+ import { setup } from "./onboarding.js";
10
14
  import { ERR } from "./copy.js";
11
15
 
12
16
  const THEME_KEY = "penthera-ui-theme";
17
+ const UX_KEY = "penthera-ui-mode";
13
18
  const PANELS_KEY = "penthera-ui-panels";
14
19
  const app = document.getElementById("app");
20
+ const menubar = document.getElementById("menubar");
15
21
  const left = document.getElementById("left");
16
22
  const center = document.getElementById("center");
17
23
  const right = document.getElementById("right");
@@ -27,73 +33,83 @@ const theme = {
27
33
  },
28
34
  };
29
35
 
30
- // ── Side panels: [ and ] toggle; drawers below 1180px / 760px ──
36
+ // ── Side windows: [ and ] toggle; drawers below 1180px / 760px ──
31
37
  const narrowRight = () => window.matchMedia("(max-width: 1180px)").matches;
32
38
  const narrowLeft = () => window.matchMedia("(max-width: 760px)").matches;
33
39
  function savedPanels() {
34
40
  try { return JSON.parse(localStorage.getItem(PANELS_KEY) || "null"); } catch { return null; }
35
41
  }
36
- function applyPanels({ left: l, right: r }) {
37
- app.classList.toggle("no-left", !l);
38
- app.classList.toggle("no-right", !r);
39
- scrim.hidden = !((r && narrowRight()) || (l && narrowLeft()));
42
+ const panels = { left: true, right: true, ...(savedPanels() || {}) };
43
+ function applyPanels() {
44
+ app.classList.toggle("no-left", !panels.left);
45
+ app.classList.toggle("no-right", !panels.right);
46
+ scrim.hidden = !((panels.right && narrowRight()) || (panels.left && narrowLeft()));
40
47
  if (!narrowRight()) {
41
- try { localStorage.setItem(PANELS_KEY, JSON.stringify({ left: l, right: r })); } catch { /* per-viewer convenience only */ }
48
+ try { localStorage.setItem(PANELS_KEY, JSON.stringify(panels)); } catch { /* per-viewer convenience only */ }
42
49
  }
50
+ if (state.meta) renderMenubar(menubar, ctx);
43
51
  }
44
- const panels = { left: true, right: true, ...(savedPanels() || {}) };
45
- if (narrowLeft()) panels.left = false;
46
- if (narrowRight()) panels.right = false;
47
- applyPanels(panels);
48
- function toggleLeft() { panels.left = !panels.left; applyPanels(panels); }
49
- function toggleRight() { panels.right = !panels.right; applyPanels(panels); }
52
+ function toggleLeft() { panels.left = !panels.left; applyPanels(); }
53
+ function toggleRight() { panels.right = !panels.right; applyPanels(); }
50
54
  scrim.addEventListener("click", () => {
51
55
  if (narrowLeft()) panels.left = false;
52
56
  if (narrowRight()) panels.right = false;
53
- applyPanels(panels);
57
+ applyPanels();
54
58
  });
55
59
 
56
60
  // ── Context the renderers share ──
57
61
  const ctx = {
58
62
  theme,
63
+ panels,
59
64
  toggleLeft,
60
65
  toggleRight,
61
66
  refresh,
62
- refreshMeta: async () => { state.meta = await api.get("/api/meta"); },
63
- redrawRight: () => renderRight(right, ctx),
67
+ setTheme(t) { theme.set(t); renderMenubar(menubar, ctx); if (state.right === "settings") renderRight(right, ctx); },
68
+ newScan(kind, project) { closeMenus(); newScan(ctx, { kind, project }); },
69
+ about() { about(); },
70
+ setup() { closeMenus(); setup(ctx); },
71
+ setUx(ux) {
72
+ try { localStorage.setItem(UX_KEY, ux); } catch { /* this page only */ }
73
+ set({ ux, tab: "findings", filter: null });
74
+ announce(`${ux === "simple" ? "Simple" : "Advanced"} mode`);
75
+ },
76
+ /** Setup closed: keep what was chosen, Simple if nothing was. */
77
+ finishSetup(ux) { ctx.setUx(ux || "simple"); },
78
+ openTab(tab, project) {
79
+ const patch = { tab };
80
+ if (project) patch.sel = { kind: "project", key: project };
81
+ else if (state.sel.kind !== "all" && state.sel.kind !== "project") patch.sel = { kind: "all", key: null };
82
+ set(patch);
83
+ },
64
84
  openFinding(f) {
65
85
  set({ finding: { id: f.id, project: f.project }, right: "finding" });
66
- if (!panels.right) { panels.right = true; applyPanels(panels); }
86
+ if (!panels.right) { panels.right = true; applyPanels(); }
67
87
  for (const b of document.querySelectorAll("#findings-list .row")) {
68
88
  b.setAttribute("aria-current", String(b.dataset.id === f.id && b.dataset.project === f.project));
69
89
  }
70
90
  },
71
- focusBar(kind) {
72
- if (kind && kind !== state.mode) set({ mode: kind });
73
- if (narrowLeft() && panels.left) { panels.left = false; applyPanels(panels); }
74
- const input = document.getElementById("bar-input");
75
- (input && !input.disabled ? input : document.querySelector(".bar .btn.primary"))?.focus();
76
- },
77
91
  };
78
92
 
79
93
  async function refresh() {
80
94
  const [overview, findings, runs] = await Promise.all([api.get("/api/overview"), api.get("/api/findings"), api.get("/api/runs")]);
81
- set({ overview, findings: findings.findings, runs });
95
+ const live = runs.live.find((r) => r.status === "running" && r.pending);
96
+ set({ overview, findings: findings.findings, runs, ...(live && !state.pending ? { pending: { index: live.pending.index, total: live.pending.total } } : {}) });
82
97
  }
83
98
 
84
- // ── Redraw on state changes, one column at a time ──
99
+ // ── Redraw on state changes, one window at a time ──
85
100
  on((patch) => {
86
101
  const keys = Object.keys(patch);
87
102
  if (keys.includes("query") && keys.length === 1) { refreshList(ctx); return; }
88
- if (keys.some((k) => ["overview", "runs", "sel", "meta", "right"].includes(k))) renderLeft(left, { onNewScan: () => ctx.focusBar("scan"), toggleLeft, theme });
89
- if (keys.some((k) => ["overview", "findings", "sel", "mode"].includes(k))) {
90
- // A live transcript is rebuilt only when the selection changes; data refreshes redraw the bar.
91
- if (state.sel.kind === "run" && !keys.includes("sel")) renderBar(center, ctx);
92
- else renderCenter(center, ctx);
93
- if (keys.includes("sel") && narrowLeft() && panels.left) { panels.left = false; applyPanels(panels); }
103
+ if (keys.some((k) => ["overview", "runs", "sel", "meta", "right", "tab", "pending", "ux"].includes(k))) renderMenubar(menubar, ctx);
104
+ if (keys.some((k) => ["overview", "runs", "sel", "meta"].includes(k))) renderLeft(left, ctx);
105
+ if (keys.some((k) => ["overview", "sel"].includes(k))) app.dataset.risk = String(riskLevel(countsInView()));
106
+ if (keys.some((k) => ["overview", "findings", "sel", "tab", "filter", "ux"].includes(k))) {
107
+ // A live transcript is rebuilt only when the selection changes, never on a data refresh.
108
+ if (!(state.sel.kind === "run" && !keys.includes("sel"))) renderCenter(center, ctx);
109
+ if (keys.includes("sel") && narrowLeft() && panels.left) { panels.left = false; applyPanels(); }
94
110
  }
95
- if (keys.some((k) => ["sel", "right", "finding"].includes(k)) || (keys.includes("runs") && state.right === "cards")) {
96
- if (patch.openRight && !panels.right) { panels.right = true; applyPanels(panels); }
111
+ if (keys.some((k) => ["sel", "right", "finding", "ux"].includes(k)) || (keys.includes("overview") && state.right === "none")) {
112
+ if (state.right !== "none" && !panels.right) { panels.right = true; applyPanels(); }
97
113
  renderRight(right, ctx);
98
114
  }
99
115
  });
@@ -103,29 +119,52 @@ function isTyping(e) {
103
119
  const t = e.target;
104
120
  return t instanceof HTMLElement && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName));
105
121
  }
122
+ document.addEventListener("pointerdown", (e) => { if (!menubar.contains(e.target)) closeMenus(); });
106
123
  document.addEventListener("keydown", (e) => {
107
124
  if (e.metaKey || e.ctrlKey || e.altKey) return;
125
+ if (document.querySelector("dialog[open]")) return; // the dialog owns the keyboard
108
126
  if (e.key === "Escape") {
127
+ if (closeMenus()) return;
109
128
  const q = document.getElementById("q");
110
129
  if (document.activeElement === q && q.value) { q.value = ""; set({ query: "" }); return; }
111
- if (state.right !== "cards") { set({ right: "cards", finding: null }); return; }
130
+ if (state.right !== "none") { set({ right: "none", finding: null }); return; }
112
131
  if ((narrowRight() && panels.right) || (narrowLeft() && panels.left)) scrim.click();
113
132
  return;
114
133
  }
115
- if (isTyping(e)) return;
134
+ if (isTyping(e) || menubar.contains(e.target)) return;
116
135
  if (answerPending(e.key)) { e.preventDefault(); return; }
117
- if (e.key === "/") { const q = document.getElementById("q"); if (q) { e.preventDefault(); q.focus(); } return; }
136
+ const tab = state.ux === "advanced" && TABS.find((t) => t.key === e.key);
137
+ if (tab) { e.preventDefault(); ctx.openTab(tab.id); return; }
138
+ if (e.key === "n") { e.preventDefault(); ctx.newScan(); return; }
139
+ if (e.key === "/") {
140
+ e.preventDefault();
141
+ if (state.tab !== "findings" || !(state.sel.kind === "all" || state.sel.kind === "project")) ctx.openTab("findings");
142
+ document.getElementById("q")?.focus();
143
+ return;
144
+ }
118
145
  if (e.key === "j" || e.key === "k") { e.preventDefault(); moveFinding(e.key === "j" ? 1 : -1, ctx); return; }
119
146
  if (e.key === "[") { e.preventDefault(); toggleLeft(); return; }
120
147
  if (e.key === "]") { e.preventDefault(); toggleRight(); }
121
148
  });
122
149
 
150
+ if (narrowLeft()) panels.left = false;
151
+ if (narrowRight()) panels.right = false;
152
+ applyPanels();
153
+
154
+ let savedUx = null;
155
+ try { savedUx = localStorage.getItem(UX_KEY); } catch { /* storage off */ }
156
+ state.ux = savedUx === "advanced" ? "advanced" : "simple";
157
+
123
158
  (async function boot() {
124
159
  document.body.append(patternDefs());
125
160
  try {
161
+ await signIn();
126
162
  state.meta = await api.get("/api/meta");
163
+ renderMenubar(menubar, ctx);
164
+ renderRight(right, ctx);
127
165
  await refresh();
128
- document.title = `penthera ui${state.meta.demo ? " :: demo" : ""}`;
166
+ document.title = `Penthera${state.meta.demo ? " :: demo" : ""}`;
167
+ if (!savedUx) ctx.setup(); // first visit in this browser
129
168
  } catch (e) {
130
169
  clear(center).append(h("div", { class: "col" },
131
170
  h("h1", {}, "Not signed in"),