Security assistant chat as the front page (Nox-style, WebLLM on device, grounded in the Devseis knowledge base, Run audit from chat); phone check moved to phone.html
Browse files- README.md +14 -1
- about.html +1 -1
- app/model-version.json +6 -1
- app/renderer/knowledge.js +136 -0
- chat/chat.css +99 -0
- chat/chat.js +310 -0
- docs/MODEL_LLM.md +2 -0
- download.html +3 -3
- index.html +66 -76
- library/build_knowledge.py +184 -0
- library/knowledge.json +0 -0
- mobile/app.js +4 -0
- mobile/test/e2e.cjs +2 -1
- phone.html +92 -0
- training/build_chat.py +297 -0
- training/chat-contexts.mjs +26 -0
README.md
CHANGED
|
@@ -151,6 +151,19 @@ npm start # run the app
|
|
| 151 |
|
| 152 |
Offline fine-tuning on CPU: `training/train_lora.py` (LoRA on Qwen2.5-0.5B-Instruct; see `--benchmark` and `--resume`).
|
| 153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
## Install on a Mac
|
| 155 |
|
| 156 |
Download from **https://devseis-endpoint-auditor.static.hf.space/download.html** (universal app for Apple silicon and
|
|
@@ -167,7 +180,7 @@ Code collects the evidence and decides every verdict; the fine-tuned model expla
|
|
| 167 |
|
| 168 |
## Phone check (iPhone, iPad, Android)
|
| 169 |
|
| 170 |
-
The
|
| 171 |
|
| 172 |
1. **Detects** what a browser can see: OS and version (Safari 26+ hides the iOS version in its user agent, so Safari's own version is used; Android uses client hints), device model (Android), browser, whether a device unlock method is set up (WebAuthn), and WebGPU support.
|
| 173 |
2. **Asks** the rest, one question at a time with *where to look* in Settings (`catalog/mobile_questions.json`). Every result is labelled `detected` or `self-reported` in the evidence and the report.
|
|
|
|
| 151 |
|
| 152 |
Offline fine-tuning on CPU: `training/train_lora.py` (LoRA on Qwen2.5-0.5B-Instruct; see `--benchmark` and `--resume`).
|
| 153 |
|
| 154 |
+
## Security assistant (chat)
|
| 155 |
+
|
| 156 |
+
The Space's front page is a chat assistant in the style of Devseis Nox: ask about securing a computer or phone,
|
| 157 |
+
ISO 27001, GDPR or the EU AI Act, and run an audit from the chat. The model runs on the device with WebLLM (1.5B,
|
| 158 |
+
about 1 GB on first use); answers are grounded in the Devseis knowledge base (`library/knowledge.json`, 321 passages
|
| 159 |
+
generated by `library/build_knowledge.py` from the catalog and library), cite their sources, and are checked
|
| 160 |
+
(`chatProblems` in `app/renderer/knowledge.js`). Without WebGPU, or if the GPU fails, it answers directly from the
|
| 161 |
+
knowledge base. **Run audit**: on phones it starts the phone check (`phone.html`), which hands the report back to the
|
| 162 |
+
chat; on computers it leads to the desktop app, or the app's `…-evidence.json` report can be attached so the chat answers
|
| 163 |
+
from the user's own results and writes the full report. Conversations stay in the browser.
|
| 164 |
+
Until model v0.4 (Qwen2.5-1.5B fine-tuned for chat and reports) is published, the chat uses the base Qwen2.5-1.5B-Instruct
|
| 165 |
+
(`chat.version` in `app/model-version.json`).
|
| 166 |
+
|
| 167 |
## Install on a Mac
|
| 168 |
|
| 169 |
Download from **https://devseis-endpoint-auditor.static.hf.space/download.html** (universal app for Apple silicon and
|
|
|
|
| 180 |
|
| 181 |
## Phone check (iPhone, iPad, Android)
|
| 182 |
|
| 183 |
+
The phone check (`phone.html`, also reachable from the chat's Run audit) runs entirely in the browser:
|
| 184 |
|
| 185 |
1. **Detects** what a browser can see: OS and version (Safari 26+ hides the iOS version in its user agent, so Safari's own version is used; Android uses client hints), device model (Android), browser, whether a device unlock method is set up (WebAuthn), and WebGPU support.
|
| 186 |
2. **Asks** the rest, one question at a time with *where to look* in Settings (`catalog/mobile_questions.json`). Every result is labelled `detected` or `self-reported` in the evidence and the report.
|
about.html
CHANGED
|
@@ -54,7 +54,7 @@
|
|
| 54 |
<main>
|
| 55 |
<span class="tag">Open source · stage 1</span>
|
| 56 |
<h1>Devseis Endpoint Auditor</h1>
|
| 57 |
-
<p class="lead">A read-only audit of Windows, Linux, macOS, iPhone and Android devices against a security baseline, GDPR technical controls, EU AI Act controls and organisational controls, written up by a small AI auditor model that runs on the device. <a href="index.html">
|
| 58 |
|
| 59 |
<div class="grid">
|
| 60 |
<div class="card"><b>Read-only collectors</b><span>PowerShell, Linux shell and macOS shell scripts. They read settings and never change the system.</span></div>
|
|
|
|
| 54 |
<main>
|
| 55 |
<span class="tag">Open source · stage 1</span>
|
| 56 |
<h1>Devseis Endpoint Auditor</h1>
|
| 57 |
+
<p class="lead">A read-only audit of Windows, Linux, macOS, iPhone and Android devices against a security baseline, GDPR technical controls, EU AI Act controls and organisational controls, written up by a small AI auditor model that runs on the device. <a href="index.html">ask the assistant</a>, <a href="phone.html">check your phone</a> or <a href="download.html">download the Mac app</a>.</p>
|
| 58 |
|
| 59 |
<div class="grid">
|
| 60 |
<div class="card"><b>Read-only collectors</b><span>PowerShell, Linux shell and macOS shell scripts. They read settings and never change the system.</span></div>
|
app/model-version.json
CHANGED
|
@@ -1,4 +1,9 @@
|
|
| 1 |
{
|
| 2 |
"version": "v0.3",
|
| 3 |
-
"note": "Model version the desktop app and phone check use (Devseis/endpoint-auditor-0.5b-*-MLC tags). Read at start-up, so installed apps follow updates."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"version": "v0.3",
|
| 3 |
+
"note": "Model version the desktop app and phone check use (Devseis/endpoint-auditor-0.5b-*-MLC tags). Read at start-up, so installed apps follow updates.",
|
| 4 |
+
"chat": {
|
| 5 |
+
"version": null,
|
| 6 |
+
"size": "1.5B",
|
| 7 |
+
"note": "Chat model: Devseis/endpoint-auditor-1.5b-*-MLC tag. null = base Qwen2.5-1.5B-Instruct until v0.4 is published."
|
| 8 |
+
}
|
| 9 |
}
|
app/renderer/knowledge.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Chat grounding: search the Devseis knowledge base (library/knowledge.json) and build the chat prompt.
|
| 2 |
+
// Used by the web chat, the desktop app and (through training/chat-contexts.mjs) the training-data builder,
|
| 3 |
+
// so the model is trained on exactly the prompts it gets at runtime. Pure functions, no DOM or network.
|
| 4 |
+
|
| 5 |
+
export const CHAT_SYSTEM_PROMPT = 'You are the Devseis security assistant. You help people secure their computers and phones and '
|
| 6 |
+
+ 'understand ISO 27001, GDPR and the EU AI Act. Answer in plain language that a non-technical person can follow, using only '
|
| 7 |
+
+ 'the CONTEXT and MY AUDIT below, and cite the passages you use as [1], [2]. If the CONTEXT does not answer the question, say '
|
| 8 |
+
+ 'you do not know rather than guessing. If the question is about the user\'s own device and MY AUDIT is "none", explain that '
|
| 9 |
+
+ 'you cannot see their device and suggest running an audit. Never invent settings, versions or numbers.';
|
| 10 |
+
|
| 11 |
+
const STOP = new Set('a an and are as at be by can do does for from has have how i if in is it its me my of on or should so that the their them this to was what when where which who why will with you your'.split(' '));
|
| 12 |
+
// Words people use -> words the knowledge base uses.
|
| 13 |
+
const SYNONYMS = {
|
| 14 |
+
filevault: 'encryption disk', bitlocker: 'encryption disk', luks: 'encryption disk', encrypt: 'encryption', encrypted: 'encryption',
|
| 15 |
+
antivirus: 'malware antivirus', virus: 'malware', defender: 'malware antivirus defender', xprotect: 'malware', clamav: 'malware',
|
| 16 |
+
passcode: 'passcode screen lock', pin: 'passcode pin screen lock', autolock: 'auto lock screen timeout', lock: 'lock screen',
|
| 17 |
+
password: 'password', admin: 'administrator', administrator: 'administrator', sudo: 'administrator', root: 'administrator rooted',
|
| 18 |
+
jailbreak: 'jailbroken', jailbroken: 'jailbroken', rooted: 'rooted', update: 'updates update', updates: 'updates update', patch: 'updates security patch',
|
| 19 |
+
backup: 'backup', 'time machine': 'backup', icloud: 'icloud backup', usb: 'usb storage', 'usb stick': 'usb storage', thumb: 'usb storage',
|
| 20 |
+
firewall: 'firewall', vpn: 'remote access', rdp: 'remote access', teamviewer: 'remote access teamviewer', anydesk: 'remote access anydesk',
|
| 21 |
+
cve: 'vulnerabilities vulnerability', vulnerability: 'vulnerabilities vulnerability', vulnerable: 'vulnerabilities', ai: 'ai', chatgpt: 'chatgpt ai',
|
| 22 |
+
gpt: 'chatgpt ai', copilot: 'copilot ai', gemini: 'gemini ai', iphone: 'iphone ios', ipad: 'iphone ios ipados', mac: 'macos', macbook: 'macos',
|
| 23 |
+
osx: 'macos', windows: 'windows', win: 'windows', ubuntu: 'linux ubuntu', debian: 'linux debian', fedora: 'linux', android: 'android',
|
| 24 |
+
galaxy: 'android', pixel: 'android', samsung: 'android', gdpr: 'gdpr', iso: 'iso 27001', '27001': 'iso 27001', 'ai act': 'ai act',
|
| 25 |
+
install: 'install', download: 'install download', privacy: 'privacy', private: 'privacy', notifications: 'notification lock screen previews',
|
| 26 |
+
};
|
| 27 |
+
const OS_WORDS = { macos: ['macos', 'mac', 'macbook', 'osx', 'filevault'], windows: ['windows', 'win', 'bitlocker', 'defender'],
|
| 28 |
+
linux: ['linux', 'ubuntu', 'debian', 'fedora', 'luks'], ios: ['iphone', 'ipad', 'ios'], android: ['android', 'galaxy', 'pixel', 'samsung'] };
|
| 29 |
+
|
| 30 |
+
function stem(word) {
|
| 31 |
+
if (word.length > 5 && word.endsWith('ing')) return word.slice(0, -3);
|
| 32 |
+
if (word.length > 4 && word.endsWith('ed')) return word.slice(0, -2);
|
| 33 |
+
if (word.length > 4 && word.endsWith('es') && !word.endsWith('ses')) return word.slice(0, -2);
|
| 34 |
+
if (word.length > 3 && word.endsWith('s') && !word.endsWith('ss')) return word.slice(0, -1);
|
| 35 |
+
return word;
|
| 36 |
+
}
|
| 37 |
+
export function tokens(text, expand = false) {
|
| 38 |
+
let t = String(text).toLowerCase();
|
| 39 |
+
if (expand) for (const [k, v] of Object.entries(SYNONYMS)) if (k.includes(' ') && t.includes(k)) t += ' ' + v;
|
| 40 |
+
const words = t.split(/[^a-z0-9.]+/).map(w => w.replace(/^\.+|\.+$/g, '')).filter(w => w && !STOP.has(w));
|
| 41 |
+
const out = [];
|
| 42 |
+
for (const w of words) {
|
| 43 |
+
out.push(stem(w));
|
| 44 |
+
if (expand && SYNONYMS[w]) for (const s of SYNONYMS[w].split(' ')) out.push(stem(s));
|
| 45 |
+
}
|
| 46 |
+
return out;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
// The operating system a question is about, if it names one.
|
| 50 |
+
export function osInQuestion(question) {
|
| 51 |
+
const words = new Set(String(question).toLowerCase().split(/[^a-z0-9]+/));
|
| 52 |
+
for (const [os, list] of Object.entries(OS_WORDS)) if (list.some(w => words.has(w))) return os;
|
| 53 |
+
return null;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
export class Knowledge {
|
| 57 |
+
constructor(data) {
|
| 58 |
+
this.chunks = data.chunks;
|
| 59 |
+
this.docs = this.chunks.map(c => {
|
| 60 |
+
const tf = new Map();
|
| 61 |
+
for (const t of [...tokens(c.title), ...tokens(c.title), ...tokens(c.text)]) tf.set(t, (tf.get(t) || 0) + 1);
|
| 62 |
+
let len = 0; for (const v of tf.values()) len += v;
|
| 63 |
+
return { tf, len };
|
| 64 |
+
});
|
| 65 |
+
this.avg = this.docs.reduce((s, d) => s + d.len, 0) / this.docs.length;
|
| 66 |
+
this.df = new Map();
|
| 67 |
+
for (const d of this.docs) for (const t of d.tf.keys()) this.df.set(t, (this.df.get(t) || 0) + 1);
|
| 68 |
+
this.byId = new Map(this.chunks.map((c, i) => [c.id, i]));
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// Top-k passages (BM25), preferring the OS the question names, else the device's OS.
|
| 72 |
+
search(question, { k = 4, os = null } = {}) {
|
| 73 |
+
const target = osInQuestion(question) || os;
|
| 74 |
+
const q = tokens(question, true);
|
| 75 |
+
const N = this.docs.length, k1 = 1.4, b = 0.75;
|
| 76 |
+
const scores = this.docs.map((d, i) => {
|
| 77 |
+
let s = 0;
|
| 78 |
+
for (const t of new Set(q)) {
|
| 79 |
+
const f = d.tf.get(t); if (!f) continue;
|
| 80 |
+
const idf = Math.log(1 + (N - this.df.get(t) + 0.5) / (this.df.get(t) + 0.5));
|
| 81 |
+
s += idf * (f * (k1 + 1)) / (f + k1 * (1 - b + b * d.len / this.avg));
|
| 82 |
+
}
|
| 83 |
+
const c = this.chunks[i];
|
| 84 |
+
if (target && c.os) s *= c.os === target ? 1.6 : 0.45;
|
| 85 |
+
return { i, s };
|
| 86 |
+
});
|
| 87 |
+
return scores.filter(x => x.s > 0).sort((a, b) => b.s - a.s || a.i - b.i).slice(0, k).map(x => this.chunks[x.i]);
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
get(id) { const i = this.byId.get(id); return i === undefined ? null : this.chunks[i]; }
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
// Short, model-friendly summary of an audit the user ran (evidence JSON), or "none".
|
| 94 |
+
export function auditBrief(evidence, maxGaps = 8) {
|
| 95 |
+
if (!evidence) return 'none';
|
| 96 |
+
const h = evidence.host, s = evidence.summary;
|
| 97 |
+
const assessed = s.Compliant + s['Non-Compliant'];
|
| 98 |
+
const lines = [`${h.os_name} ${h.os_version} (${h.os_family}), audited ${String(evidence.audit.started_at).slice(0, 10)}; `
|
| 99 |
+
+ `${s.Compliant} of ${assessed} assessed checks compliant; ${s['Non-Compliant']} gaps, ${s.Pending} pending, ${s.Error} not read.`];
|
| 100 |
+
const gaps = evidence.results.filter(r => r.status === 'Non-Compliant').slice(0, maxGaps);
|
| 101 |
+
if (gaps.length) lines.push('Gaps: ' + gaps.map(r => `${r.name}: ${r.actual}`).join('; ') + '.');
|
| 102 |
+
return lines.join(' ');
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
// Messages for one chat turn. history: earlier [{role, content}] turns (already answered).
|
| 106 |
+
export function chatMessages(question, passages, audit = 'none', history = []) {
|
| 107 |
+
const context = passages.length ? passages.map((p, n) => `[${n + 1}] ${p.title}: ${p.text}`).join('\n') : '(no matching passages)';
|
| 108 |
+
const user = `CONTEXT:\n${context}\n\nMY AUDIT: ${audit}\n\nQUESTION: ${question}`;
|
| 109 |
+
return [{ role: 'system', content: CHAT_SYSTEM_PROMPT }, ...history.slice(-4), { role: 'user', content: user }];
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
// Grounding rules for a chat answer (same as check_chat() in training/build_chat.py).
|
| 113 |
+
const NUMBER = /(?<![\w.])\d+(?:\.\d+)?(?!\w)/g;
|
| 114 |
+
export function chatProblems(userPrompt, answer) {
|
| 115 |
+
const problems = [];
|
| 116 |
+
const passages = (userPrompt.split('MY AUDIT:')[0].match(/^\[\d+\] /gm) || []).length;
|
| 117 |
+
for (const m of answer.matchAll(/\[(\d+)\]/g)) if (+m[1] < 1 || +m[1] > passages) problems.push(`citation [${m[1]}] out of range`);
|
| 118 |
+
const allowed = new Set(userPrompt.match(NUMBER) || []);
|
| 119 |
+
for (const n of answer.match(NUMBER) || []) if (!allowed.has(n) && !(/^\d+$/.test(n) && +n <= 12)) problems.push(`number ${n} not in sources`);
|
| 120 |
+
return problems;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
// With an audit attached: the fix guide for the gap the question names, else the top gap, is always among the
|
| 124 |
+
// passages (as in the training data), so "what should I fix first?" is answered from the right guide.
|
| 125 |
+
export function searchWithAudit(kb, question, evidence, { k = 4, os = null } = {}) {
|
| 126 |
+
let passages = kb.search(question, { k, os: evidence ? evidence.host.os_family : os });
|
| 127 |
+
if (!evidence) return passages;
|
| 128 |
+
const gaps = evidence.results.filter(r => r.status === 'Non-Compliant').slice(0, 8);
|
| 129 |
+
if (!gaps.length) return passages;
|
| 130 |
+
const q = String(question).toLowerCase();
|
| 131 |
+
const named = gaps.find(g => q.includes(g.name.toLowerCase()));
|
| 132 |
+
const gap = named || gaps[0];
|
| 133 |
+
const gold = kb.get(`fix:${gap.id}:${evidence.host.os_family}`);
|
| 134 |
+
if (gold && !passages.some(p => p.id === gold.id)) passages = [...passages.slice(0, k - 1), gold];
|
| 135 |
+
return passages;
|
| 136 |
+
}
|
chat/chat.css
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Devseis Security Assistant: layout follows Devseis Nox (header, empty state with chips, thread, pill composer, sidebar). */
|
| 2 |
+
:root { --bg: #f4f6fb; --panel: #fff; --border: #e2e6ee; --text: #171a21; --muted: #666f80; --accent: #ED2939; --accent-dark: #C81E2B;
|
| 3 |
+
--accent-text: #fff; --accent-soft: rgba(237, 41, 57, .08); --accent-border: rgba(237, 41, 57, .35); --bubble-bot: #fff; --bubble-user: #ED2939;
|
| 4 |
+
--input-bg: #fff; --blue: #00A1DE; --ok: #1a7f37; --warn: #9a6700; }
|
| 5 |
+
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --bg: #0b0e14; --panel: #11151d; --border: #232a37; --text: #e8ecf4; --muted: #8b94a7;
|
| 6 |
+
--accent: #ff4d5a; --accent-dark: #ED2939; --accent-soft: rgba(255, 77, 90, .14); --accent-border: rgba(255, 77, 90, .4); --bubble-bot: #161c27; --bubble-user: #c81e2b; --input-bg: #1a202b; --ok: #3fb950; --warn: #d29922; } }
|
| 7 |
+
:root[data-theme="dark"] { --bg: #0b0e14; --panel: #11151d; --border: #232a37; --text: #e8ecf4; --muted: #8b94a7;
|
| 8 |
+
--accent: #ff4d5a; --accent-dark: #ED2939; --accent-soft: rgba(255, 77, 90, .14); --accent-border: rgba(255, 77, 90, .4); --bubble-bot: #161c27; --bubble-user: #c81e2b; --input-bg: #1a202b; --ok: #3fb950; --warn: #d29922; }
|
| 9 |
+
* { box-sizing: border-box; }
|
| 10 |
+
html, body { height: 100%; }
|
| 11 |
+
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
|
| 12 |
+
height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
|
| 13 |
+
a { color: var(--blue); }
|
| 14 |
+
.hidden { display: none !important; }
|
| 15 |
+
.muted { color: var(--muted); } .tiny { font-size: 12px; }
|
| 16 |
+
button { font: inherit; cursor: pointer; }
|
| 17 |
+
button:focus-visible, a:focus-visible, .chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
| 18 |
+
|
| 19 |
+
header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top));
|
| 20 |
+
border-bottom: 1px solid var(--border); background: var(--panel); border-top: 3px solid var(--accent); flex-shrink: 0; }
|
| 21 |
+
.header-left, .header-actions { display: flex; align-items: center; gap: 6px; }
|
| 22 |
+
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-size: 15px; }
|
| 23 |
+
.brand img { width: 28px; height: 28px; }
|
| 24 |
+
.icon-btn { width: 38px; height: 38px; border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--text); display: grid; place-items: center; }
|
| 25 |
+
.icon-btn:hover { background: var(--accent-soft); }
|
| 26 |
+
.audit-btn { background: var(--accent); color: var(--accent-text); border: 0; border-radius: 999px; padding: 8px 14px; font-weight: 700; font-size: 14px; white-space: nowrap; }
|
| 27 |
+
.audit-btn:hover { background: var(--accent-dark); }
|
| 28 |
+
.status-bar { padding: 6px 16px; background: var(--accent-soft); border-bottom: 1px solid var(--border); font-size: 13px; }
|
| 29 |
+
.status-progress { height: 4px; background: var(--border); border-radius: 99px; overflow: hidden; margin-top: 4px; }
|
| 30 |
+
#statusFill { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
|
| 31 |
+
|
| 32 |
+
main { flex: 1; overflow-y: auto; padding: 18px 14px 8px; }
|
| 33 |
+
.empty-state { max-width: 680px; margin: 6vh auto 0; text-align: center; }
|
| 34 |
+
.hero-icon img { width: 64px; height: 64px; }
|
| 35 |
+
.empty-state h1 { font-size: clamp(24px, 4.5vw, 32px); line-height: 1.2; margin: 10px 0; }
|
| 36 |
+
.hero-sub { color: var(--muted); font-size: 17px; margin: 0 auto 20px; max-width: 560px; }
|
| 37 |
+
.chips { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; max-width: 600px; margin: 0 auto; }
|
| 38 |
+
@media (max-width: 520px) { .chips { grid-template-columns: 1fr; } }
|
| 39 |
+
.chip { text-align: left; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; color: var(--text); font-size: 15px; }
|
| 40 |
+
.chip:hover { border-color: var(--accent-border); background: var(--accent-soft); }
|
| 41 |
+
|
| 42 |
+
#thread { max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
|
| 43 |
+
.msg { display: flex; gap: 10px; align-items: flex-start; }
|
| 44 |
+
.msg.user { justify-content: flex-end; }
|
| 45 |
+
.avatar { width: 30px; height: 30px; flex: none; border-radius: 8px; }
|
| 46 |
+
.bubble { max-width: min(640px, 88%); padding: 11px 15px; border-radius: 18px; overflow-wrap: anywhere; }
|
| 47 |
+
.msg.user .bubble { background: var(--bubble-user); color: #fff; border-bottom-right-radius: 6px; white-space: pre-wrap; }
|
| 48 |
+
.msg.bot .bubble { background: var(--bubble-bot); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
|
| 49 |
+
.bubble p { margin: 0 0 8px; } .bubble p:last-child { margin-bottom: 0; }
|
| 50 |
+
.bubble ol, .bubble ul { margin: 6px 0 8px 20px; padding: 0; } .bubble li { margin: 3px 0; }
|
| 51 |
+
.bubble code { font: 13px ui-monospace, Menlo, monospace; background: var(--accent-soft); padding: 1px 5px; border-radius: 5px; }
|
| 52 |
+
.cite { display: inline-block; font-size: 11px; font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 6px; padding: 0 5px; margin: 0 1px; cursor: pointer; vertical-align: 1px; border: 0; }
|
| 53 |
+
.sources { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
|
| 54 |
+
.source { font-size: 12px; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px; background: transparent; }
|
| 55 |
+
.source.open { border-color: var(--accent-border); color: var(--text); }
|
| 56 |
+
.source-text { font-size: 13px; color: var(--muted); border-left: 3px solid var(--accent-border); padding: 4px 10px; margin-top: 8px; }
|
| 57 |
+
.note { font-size: 12px; color: var(--warn); margin-top: 8px; }
|
| 58 |
+
.typing span { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); margin-right: 3px; animation: blink 1.2s infinite; }
|
| 59 |
+
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
|
| 60 |
+
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
|
| 61 |
+
.card { border: 1px solid var(--border); background: var(--panel); border-radius: 16px; padding: 14px; }
|
| 62 |
+
.card .score { font-size: 30px; font-weight: 800; }
|
| 63 |
+
.card .pill { display: inline-block; font-size: 12px; font-weight: 700; border: 1px solid; border-radius: 99px; padding: 0 8px; margin: 2px 4px 2px 0; }
|
| 64 |
+
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
|
| 65 |
+
.small-btn { border: 1px solid var(--border); background: var(--panel); color: var(--text); border-radius: 10px; padding: 7px 12px; font-size: 14px; }
|
| 66 |
+
.primary-btn { border: 0; background: var(--accent); color: #fff; border-radius: 10px; padding: 8px 14px; font-size: 14px; font-weight: 700; }
|
| 67 |
+
|
| 68 |
+
#composer { display: flex; align-items: flex-end; gap: 8px; max-width: 812px; width: 100%; margin: 0 auto; padding: 8px 14px 4px; flex-shrink: 0; }
|
| 69 |
+
.input-pill { flex: 1; display: flex; background: var(--input-bg); border: 1px solid var(--border); border-radius: 22px; padding: 4px 6px 4px 16px; }
|
| 70 |
+
.input-pill:focus-within { box-shadow: 0 0 0 2px var(--accent-border); }
|
| 71 |
+
#input { flex: 1; border: 0; outline: 0; resize: none; background: transparent; color: var(--text); font: inherit; max-height: 180px; padding: 9px 0; }
|
| 72 |
+
.send-btn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
|
| 73 |
+
.send-btn:disabled { opacity: .4; cursor: default; }
|
| 74 |
+
.attach { width: 44px; height: 44px; flex: none; }
|
| 75 |
+
.disclaimer { text-align: center; font-size: 11.5px; color: var(--muted); margin: 0 0 calc(8px + env(safe-area-inset-bottom)); padding: 0 12px; }
|
| 76 |
+
|
| 77 |
+
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 9; }
|
| 78 |
+
.sidebar { position: fixed; top: 0; bottom: 0; left: 0; width: min(320px, 86vw); background: var(--panel); border-right: 1px solid var(--border); z-index: 10;
|
| 79 |
+
transform: translateX(-102%); transition: transform .2s; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); }
|
| 80 |
+
.sidebar.open { transform: none; }
|
| 81 |
+
.sidebar-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); }
|
| 82 |
+
.sidebar-head h2 { font-size: 16px; margin: 0; }
|
| 83 |
+
.sidebar-list { flex: 1; overflow-y: auto; padding: 8px; }
|
| 84 |
+
.convo { display: flex; align-items: center; gap: 6px; padding: 9px 10px; border-radius: 10px; cursor: pointer; font-size: 14px; }
|
| 85 |
+
.convo:hover, .convo.active { background: var(--accent-soft); }
|
| 86 |
+
.convo span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
| 87 |
+
.convo button { opacity: .5; border: 0; background: transparent; color: var(--text); }
|
| 88 |
+
.sidebar-foot { border-top: 1px solid var(--border); padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); font-size: 14px; }
|
| 89 |
+
.sidebar-foot .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
|
| 90 |
+
|
| 91 |
+
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 20; padding: 16px; }
|
| 92 |
+
.modal-card { background: var(--panel); border-radius: 18px; padding: 20px; max-width: 460px; width: 100%; border: 1px solid var(--border); }
|
| 93 |
+
.modal-card h2 { margin: 0 0 6px; font-size: 20px; }
|
| 94 |
+
.option { display: block; width: 100%; text-align: left; border: 1px solid var(--border); background: var(--bg); color: var(--text); border-radius: 14px; padding: 12px 14px; margin: 10px 0; text-decoration: none; }
|
| 95 |
+
.option:hover { border-color: var(--accent-border); }
|
| 96 |
+
.option b { display: block; } .option span { color: var(--muted); font-size: 14px; }
|
| 97 |
+
.option.recommended { border: 2px solid var(--accent); }
|
| 98 |
+
.link-btn { border: 0; background: transparent; color: var(--muted); text-decoration: underline; padding: 6px 0; }
|
| 99 |
+
@media (max-width: 560px) { .brand span { display: none; } .audit-btn { padding: 8px 12px; } .hero-sub { font-size: 16px; } }
|
chat/chat.js
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Devseis Security Assistant: chat about endpoint security with the Devseis model running on the device (WebLLM),
|
| 2 |
+
// grounded in the Devseis knowledge base (library/knowledge.json), plus audits: the phone check on phones, the desktop
|
| 3 |
+
// app (or its report file) on computers. Conversations are stored only in this browser.
|
| 4 |
+
import { Knowledge, chatMessages, auditBrief, chatProblems, searchWithAudit } from '../app/renderer/knowledge.js';
|
| 5 |
+
import { Library, findingPrompt, findingTemplate, summaryPrompt, summaryTemplate, aiPrompt, aiTemplate, writeAnswer, ANSWER_SCHEMAS } from '../app/renderer/auditor-core.js';
|
| 6 |
+
import { buildReportHtml } from '../app/renderer/report.js';
|
| 7 |
+
import { detectDevice } from '../mobile/detect.js';
|
| 8 |
+
|
| 9 |
+
const WEBLLM_URL = 'https://esm.run/@mlc-ai/web-llm@0.2.85';
|
| 10 |
+
const STORE = 'devseis.chats.v1';
|
| 11 |
+
const $ = id => document.getElementById(id);
|
| 12 |
+
const esc = s => String(s ?? '').replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
| 13 |
+
|
| 14 |
+
const state = { kb: null, device: null, config: null, engine: null, enginePromise: null, modelLabel: '', busy: false, chats: [], current: null, libData: null };
|
| 15 |
+
|
| 16 |
+
// ---------- storage ----------
|
| 17 |
+
function loadChats() { try { return JSON.parse(localStorage.getItem(STORE)) || []; } catch { return []; } }
|
| 18 |
+
function saveChats() { try { localStorage.setItem(STORE, JSON.stringify(state.chats.slice(0, 50))); } catch { /* private mode or full */ } }
|
| 19 |
+
function newChat() {
|
| 20 |
+
const chat = { id: Date.now().toString(36), title: 'New conversation', messages: [], audit: null };
|
| 21 |
+
state.chats.unshift(chat); state.current = chat; saveChats(); render(); return chat;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
// ---------- model ----------
|
| 25 |
+
async function getEngine() {
|
| 26 |
+
if (state.engine !== null || state.enginePromise) return state.enginePromise || state.engine;
|
| 27 |
+
state.enginePromise = (async () => {
|
| 28 |
+
if (!('gpu' in navigator)) throw new Error('This browser has no WebGPU');
|
| 29 |
+
const adapter = await navigator.gpu.requestAdapter();
|
| 30 |
+
if (!adapter) throw new Error('No WebGPU graphics adapter');
|
| 31 |
+
const quant = adapter.features.has('shader-f16') ? 'q4f16_1' : 'q4f32_1';
|
| 32 |
+
const webllm = await import(WEBLLM_URL);
|
| 33 |
+
const base = webllm.prebuiltAppConfig.model_list.find(m => m.model_id === `Qwen2.5-1.5B-Instruct-${quant}-MLC`);
|
| 34 |
+
const v = state.config?.chat?.version;
|
| 35 |
+
const custom = v ? { ...base, model: `https://huggingface.co/Devseis/endpoint-auditor-1.5b-${quant}-MLC/resolve/${v}/`, model_id: `devseis-assistant-1.5b-${v}-${quant}` } : null;
|
| 36 |
+
const appConfig = { ...webllm.prebuiltAppConfig, model_list: custom ? [...webllm.prebuiltAppConfig.model_list, custom] : webllm.prebuiltAppConfig.model_list };
|
| 37 |
+
const initProgressCallback = r => status(`Getting the AI ready on this device (first time only, about 1 GB): ${Math.round((r.progress || 0) * 100)}%`, r.progress || 0);
|
| 38 |
+
let engine, label;
|
| 39 |
+
if (custom) {
|
| 40 |
+
try { engine = await webllm.CreateMLCEngine(custom.model_id, { appConfig, initProgressCallback }); label = `Devseis assistant ${v} (1.5B)`; } catch (e) { console.warn('Devseis model failed, using base', e); }
|
| 41 |
+
}
|
| 42 |
+
if (!engine) { engine = await webllm.CreateMLCEngine(base.model_id, { appConfig, initProgressCallback }); label = 'Qwen2.5 1.5B (base, until the Devseis model loads)'; }
|
| 43 |
+
state.modelLabel = label; $('modelName').textContent = label; status('');
|
| 44 |
+
return engine;
|
| 45 |
+
})().then(e => (state.engine = e), err => { state.engine = false; state.modelLabel = `Not available: ${err.message}`; $('modelName').textContent = 'Knowledge base only'; status(''); return false; });
|
| 46 |
+
return state.enginePromise;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
function status(text, fraction) {
|
| 50 |
+
$('statusBar').classList.toggle('hidden', !text);
|
| 51 |
+
$('statusText').textContent = text;
|
| 52 |
+
$('statusFill').style.width = `${Math.round((fraction || 0) * 100)}%`;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
// ---------- rendering ----------
|
| 56 |
+
function markdown(text, passages, msgIndex) {
|
| 57 |
+
const lines = esc(text).split('\n');
|
| 58 |
+
let html = '', list = null;
|
| 59 |
+
const close = () => { if (list) { html += `</${list}>`; list = null; } };
|
| 60 |
+
for (const line of lines) {
|
| 61 |
+
const ol = /^\s*\d+\.\s+(.*)$/.exec(line), ul = /^\s*[-•]\s+(.*)$/.exec(line);
|
| 62 |
+
if (ol || ul) {
|
| 63 |
+
const tag = ol ? 'ol' : 'ul';
|
| 64 |
+
if (list !== tag) { close(); html += `<${tag}>`; list = tag; }
|
| 65 |
+
html += `<li>${(ol || ul)[1]}</li>`;
|
| 66 |
+
} else { close(); if (line.trim()) html += `<p>${line}</p>`; }
|
| 67 |
+
}
|
| 68 |
+
close();
|
| 69 |
+
return html.replace(/\*\*(.+?)\*\*/g, '<b>$1</b>').replace(/`([^`]+)`/g, '<code>$1</code>')
|
| 70 |
+
.replace(/\[(\d+)\]/g, (m, n) => passages && passages[n - 1] ? `<button type="button" class="cite" data-msg="${msgIndex}" data-n="${n}" title="${esc(passages[n - 1].title)}">${n}</button>` : '');
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
function auditCard(audit) {
|
| 74 |
+
const s = audit.summary, assessed = s.Compliant + s['Non-Compliant'];
|
| 75 |
+
const pct = assessed ? Math.round(100 * s.Compliant / assessed) : 0;
|
| 76 |
+
const colours = { Compliant: 'var(--ok)', 'Non-Compliant': 'var(--accent)', Pending: 'var(--warn)', NotApplicable: 'var(--muted)', Error: '#8250df' };
|
| 77 |
+
const gaps = audit.results.filter(r => r.status === 'Non-Compliant').slice(0, 5);
|
| 78 |
+
return `<div class="card"><div class="muted tiny">AUDIT REPORT · ${esc(audit.host.os_name)} ${esc(audit.host.os_version)} · ${esc(String(audit.audit.started_at).slice(0, 10))}</div>
|
| 79 |
+
<div class="score">${pct}%</div><div class="muted">${s.Compliant} of ${assessed} assessed checks compliant</div>
|
| 80 |
+
<div>${Object.entries(s).filter(([, v]) => v).map(([k, v]) => `<span class="pill" style="color:${colours[k]}">${v} ${k}</span>`).join('')}</div>
|
| 81 |
+
${gaps.length ? `<p style="margin:8px 0 0"><b>Top gaps:</b> ${gaps.map(g => esc(g.name)).join(', ')}</p>` : ''}
|
| 82 |
+
<div class="btn-row"><button type="button" class="primary-btn" data-ask="What should I fix first?">What should I fix first?</button>
|
| 83 |
+
<button type="button" class="small-btn" data-report="1">📄 Write my full report</button></div></div>`;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
function render() {
|
| 87 |
+
const chat = state.current;
|
| 88 |
+
$('emptyState').classList.toggle('hidden', Boolean(chat && (chat.messages.length || chat.audit)));
|
| 89 |
+
const thread = $('thread');
|
| 90 |
+
thread.innerHTML = '';
|
| 91 |
+
if (!chat) return renderSidebar();
|
| 92 |
+
if (chat.audit) thread.insertAdjacentHTML('beforeend', `<div class="msg bot"><img class="avatar" src="app/build/icon.png" alt="">${auditCard(chat.audit)}</div>`);
|
| 93 |
+
chat.messages.forEach((m, i) => {
|
| 94 |
+
if (m.role === 'user') { thread.insertAdjacentHTML('beforeend', `<div class="msg user"><div class="bubble">${esc(m.content)}</div></div>`); return; }
|
| 95 |
+
const sources = (m.passages || []).map((p, n) => `<button type="button" class="source" data-msg="${i}" data-n="${n + 1}">[${n + 1}] ${esc(p.title)}</button>`).join('');
|
| 96 |
+
thread.insertAdjacentHTML('beforeend', `<div class="msg bot"><img class="avatar" src="app/build/icon.png" alt=""><div class="bubble" id="m${i}">
|
| 97 |
+
${m.pending ? '<div class="typing"><span></span><span></span><span></span></div>' : markdown(m.content, m.passages, i)}
|
| 98 |
+
${!m.pending && sources && !m.noSources ? `<div class="sources"><span class="muted tiny">Sources:</span>${sources}</div>` : ''}
|
| 99 |
+
${m.note ? `<div class="note">${esc(m.note)}</div>` : ''}<div class="source-slot"></div></div></div>`);
|
| 100 |
+
});
|
| 101 |
+
renderSidebar();
|
| 102 |
+
$('chatMain').scrollTop = $('chatMain').scrollHeight;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
function renderSidebar() {
|
| 106 |
+
$('sidebarList').innerHTML = state.chats.map(c => `<div class="convo${c === state.current ? ' active' : ''}" data-id="${c.id}"><span>${esc(c.title)}</span><button type="button" data-del="${c.id}" aria-label="Delete">✕</button></div>`).join('')
|
| 107 |
+
|| '<p class="muted tiny" style="padding:8px">No conversations yet.</p>';
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
function showSource(msgIndex, n, anchor) {
|
| 111 |
+
const m = state.current.messages[msgIndex];
|
| 112 |
+
const p = m && m.passages && m.passages[n - 1];
|
| 113 |
+
if (!p) return;
|
| 114 |
+
const slot = document.querySelector(`#m${msgIndex} .source-slot`);
|
| 115 |
+
slot.innerHTML = `<div class="source-text"><b>[${n}] ${esc(p.title)}</b><br>${esc(p.text)}</div>`;
|
| 116 |
+
document.querySelectorAll(`#m${msgIndex} .source`).forEach(b => b.classList.toggle('open', b.dataset.n === String(n)));
|
| 117 |
+
if (anchor) slot.scrollIntoView({ block: 'nearest' });
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
// ---------- asking ----------
|
| 121 |
+
async function ask(question) {
|
| 122 |
+
if (state.busy || !question.trim()) return;
|
| 123 |
+
const chat = state.current || newChat();
|
| 124 |
+
if (chat.title === 'New conversation') chat.title = question.slice(0, 60);
|
| 125 |
+
const history = chat.messages.filter(m => !m.pending).slice(-4).map(m => ({ role: m.role, content: m.content }));
|
| 126 |
+
chat.messages.push({ role: 'user', content: question });
|
| 127 |
+
const reply = { role: 'assistant', content: '', pending: true, passages: [] };
|
| 128 |
+
chat.messages.push(reply);
|
| 129 |
+
state.busy = true; updateSend(); render();
|
| 130 |
+
try {
|
| 131 |
+
const os = chat.audit ? chat.audit.host.os_family : (state.device && (state.device.os_family || (state.device.desktop ? desktopOs() : null)));
|
| 132 |
+
const passages = searchWithAudit(state.kb, question, chat.audit, { k: 4, os });
|
| 133 |
+
reply.passages = passages;
|
| 134 |
+
const messages = chatMessages(question, passages, auditBrief(chat.audit), history);
|
| 135 |
+
let engine = await getEngine();
|
| 136 |
+
let streamed = false;
|
| 137 |
+
if (engine) {
|
| 138 |
+
// A GPU can be lost (memory pressure, sleep); restart the model once, then fall back to the knowledge base.
|
| 139 |
+
for (let attempt = 0; attempt < 2 && engine; attempt++) {
|
| 140 |
+
try {
|
| 141 |
+
reply.pending = false; reply.content = '';
|
| 142 |
+
const stream = await engine.chat.completions.create({ messages, temperature: 0, max_tokens: 700, stream: true });
|
| 143 |
+
let last = 0;
|
| 144 |
+
for await (const chunk of stream) {
|
| 145 |
+
reply.content += chunk.choices[0]?.delta?.content || '';
|
| 146 |
+
if (Date.now() - last > 120) { last = Date.now(); const el = $(`m${chat.messages.length - 1}`); if (el) el.innerHTML = markdown(clean(reply.content), passages, chat.messages.length - 1); }
|
| 147 |
+
}
|
| 148 |
+
streamed = true;
|
| 149 |
+
break;
|
| 150 |
+
} catch (error) {
|
| 151 |
+
if (!/lost|Instance reference|GPUDevice|disposed/i.test(error.message)) throw error;
|
| 152 |
+
status('The graphics processor was reset; restarting the AI…', 0.5);
|
| 153 |
+
state.engine = null; state.enginePromise = null;
|
| 154 |
+
engine = attempt === 0 ? await getEngine() : null;
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
if (streamed) {
|
| 159 |
+
reply.content = clean(reply.content);
|
| 160 |
+
reply.noSources = !/\[\d+\]/.test(reply.content) && /can only help|don't have|do not have|not able to|can't answer|cannot answer|sorry/i.test(reply.content);
|
| 161 |
+
const problems = chatProblems(messages[messages.length - 1].content, reply.content);
|
| 162 |
+
reply.cited = /\[\d+\]/.test(reply.content);
|
| 163 |
+
if (problems.length) reply.note = 'Some details in this answer could not be matched to the sources. Check them in the sources below before acting.';
|
| 164 |
+
} else {
|
| 165 |
+
reply.content = passages.length
|
| 166 |
+
? `The AI model isn't available right now, but here is what the Devseis knowledge base says:\n\n${passages.slice(0, 2).map((p, i) => `**${p.title}** [${i + 1}]\n${p.text}`).join('\n\n')}`
|
| 167 |
+
: 'The AI model isn\'t available right now, and the Devseis knowledge base has nothing on that question. I cover device security, ISO 27001, GDPR and the EU AI Act.';
|
| 168 |
+
reply.cited = true; reply.note = 'Shown directly from the knowledge base (the AI model is not available on this device right now).';
|
| 169 |
+
}
|
| 170 |
+
} catch (error) {
|
| 171 |
+
reply.content = `Something went wrong: ${error.message}`;
|
| 172 |
+
}
|
| 173 |
+
reply.pending = false; state.busy = false; saveChats(); updateSend(); render();
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
// Models sometimes emit HTML entities; show plain characters.
|
| 177 |
+
function clean(text) { return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, "'"); }
|
| 178 |
+
|
| 179 |
+
function desktopOs() { const ua = navigator.userAgent; return /Windows/.test(ua) ? 'windows' : /Mac/.test(ua) ? 'macos' : 'linux'; }
|
| 180 |
+
|
| 181 |
+
// ---------- audits ----------
|
| 182 |
+
function openAuditModal() {
|
| 183 |
+
const d = state.device || {};
|
| 184 |
+
const phone = d.os_family === 'ios' || d.os_family === 'android';
|
| 185 |
+
const os = phone ? null : desktopOs();
|
| 186 |
+
const osName = { macos: 'Mac', windows: 'Windows', linux: 'Linux' }[os];
|
| 187 |
+
$('auditOptions').innerHTML = phone
|
| 188 |
+
? `<p class="muted">The check runs in this browser: the phone answers what it can, you answer the rest. About 5 minutes.</p>
|
| 189 |
+
<a class="option recommended" href="phone.html?return=chat"><b>📱 Start the phone check</b><span>Your answers and report stay on this phone.</span></a>`
|
| 190 |
+
: `<p class="muted">A web page can't read a computer's settings, so computers are audited with the free Devseis app. It only reads, changes nothing, and takes about 15 minutes.</p>
|
| 191 |
+
<a class="option recommended" href="download.html#${os}"><b>💻 Get the desktop app for ${osName}${os === 'windows' ? ' (beta)' : ''}</b><span>Step-by-step install guide.</span></a>
|
| 192 |
+
<button type="button" class="option" id="optAttach"><b>📎 I already ran an audit</b><span>Add the report file (<code>…-evidence.json</code>, saved next to the PDF) and I'll answer from your results.</span></button>
|
| 193 |
+
<a class="option" href="phone.html"><b>📱 Check a phone instead</b><span>Open the phone check on the phone itself.</span></a>`;
|
| 194 |
+
$('auditModal').classList.remove('hidden');
|
| 195 |
+
const att = $('optAttach'); if (att) att.addEventListener('click', () => { $('auditModal').classList.add('hidden'); $('fileInput').click(); });
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
function attachAudit(evidence) {
|
| 199 |
+
if (!evidence || evidence.schema_version !== '1.0' || !Array.isArray(evidence.results) || !evidence.host) throw new Error('This is not a Devseis audit report file.');
|
| 200 |
+
const chat = state.current && !state.current.messages.length && !state.current.audit ? state.current : newChat();
|
| 201 |
+
chat.audit = evidence; chat.title = `Audit: ${evidence.host.os_name} ${String(evidence.audit.started_at).slice(0, 10)}`;
|
| 202 |
+
saveChats(); render();
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
async function loadLibrary() {
|
| 206 |
+
if (state.libData) return state.libData;
|
| 207 |
+
const get = async p => { const r = await fetch(p); if (!r.ok) throw new Error(`${p}: ${r.status}`); return r.json(); };
|
| 208 |
+
const [catalog, controls, guidance, aiTools] = await Promise.all(['catalog/checks.json', 'library/controls.json', 'library/check_guidance.json', 'library/ai_tools.json'].map(get));
|
| 209 |
+
state.libData = new Library({ catalog, controls, guidance, aiTools });
|
| 210 |
+
return state.libData;
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
async function writeReport() {
|
| 214 |
+
const chat = state.current; if (!chat || !chat.audit || state.busy) return;
|
| 215 |
+
state.busy = true; updateSend();
|
| 216 |
+
const evidence = chat.audit;
|
| 217 |
+
try {
|
| 218 |
+
const lib = await loadLibrary();
|
| 219 |
+
const engine = await getEngine();
|
| 220 |
+
const generate = engine ? async (system, prompt, task) => (await engine.chat.completions.create({
|
| 221 |
+
messages: [{ role: 'system', content: system }, { role: 'user', content: prompt }], temperature: 0, max_tokens: task === 'ai_classification' ? 1600 : 1200,
|
| 222 |
+
response_format: { type: 'json_object', schema: JSON.stringify(ANSWER_SCHEMAS[task]) } })).choices[0].message.content : null;
|
| 223 |
+
const targets = evidence.results.filter(r => ['Non-Compliant', 'Error', 'Pending'].includes(r.status));
|
| 224 |
+
const findings = {}, sources = { model: 0, template: 0 };
|
| 225 |
+
let i = 0;
|
| 226 |
+
for (const r of targets) {
|
| 227 |
+
status(`Writing your report: ${r.name} (${++i} of ${targets.length})`, i / (targets.length + 2));
|
| 228 |
+
const out = await writeAnswer('finding', findingPrompt(evidence, r, lib), findingTemplate(evidence, r, lib), r.section === 'org' ? null : generate);
|
| 229 |
+
findings[r.id] = out.answer; sources[out.source] += 1;
|
| 230 |
+
}
|
| 231 |
+
status('Writing your report: summary', 0.95);
|
| 232 |
+
const base = summaryTemplate(evidence, lib);
|
| 233 |
+
const so = await writeAnswer('summary', summaryPrompt(evidence, lib), base, generate);
|
| 234 |
+
sources[so.source] += 1;
|
| 235 |
+
const summary = so.source === 'model' ? { ...base, summary: so.answer.summary, next_steps: so.answer.next_steps } : base;
|
| 236 |
+
const ai = aiPrompt(evidence, lib);
|
| 237 |
+
let aiResult = null;
|
| 238 |
+
if (ai) { const o = await writeAnswer('ai_classification', ai, aiTemplate(evidence, lib), generate); aiResult = o.answer; sources[o.source] += 1; }
|
| 239 |
+
const html = buildReportHtml({ evidence, findings, summary, ai: aiResult, sha256: '(from attached file)', model: state.engine ? state.modelLabel : null, sources });
|
| 240 |
+
const url = URL.createObjectURL(new Blob([html], { type: 'text/html' }));
|
| 241 |
+
chat.messages.push({ role: 'assistant', content: `Your full report is ready: ${sources.model} parts written by the AI, ${sources.template} by the built-in writer. Open it and use your browser's Print › Save as PDF to keep it.`, passages: [] });
|
| 242 |
+
saveChats(); render();
|
| 243 |
+
const last = $(`m${chat.messages.length - 1}`);
|
| 244 |
+
last.insertAdjacentHTML('beforeend', `<div class="btn-row"><a class="primary-btn" href="${url}" target="_blank" rel="noopener" style="text-decoration:none">📄 Open the report</a></div>`);
|
| 245 |
+
} catch (error) {
|
| 246 |
+
chat.messages.push({ role: 'assistant', content: `The report could not be written: ${error.message}`, passages: [] }); render();
|
| 247 |
+
}
|
| 248 |
+
status(''); state.busy = false; updateSend();
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
// ---------- wiring ----------
|
| 252 |
+
function updateSend() { $('sendBtn').disabled = state.busy || !$('input').value.trim(); }
|
| 253 |
+
function closeSidebar() { $('sidebar').classList.remove('open'); $('overlay').classList.add('hidden'); }
|
| 254 |
+
|
| 255 |
+
$('composer').addEventListener('submit', e => { e.preventDefault(); const q = $('input').value.trim(); $('input').value = ''; $('input').style.height = ''; updateSend(); ask(q); });
|
| 256 |
+
$('input').addEventListener('input', () => { const t = $('input'); t.style.height = 'auto'; t.style.height = `${Math.min(t.scrollHeight, 180)}px`; updateSend(); });
|
| 257 |
+
$('input').addEventListener('keydown', e => { if (e.key === 'Enter' && !e.shiftKey && !e.isComposing) { e.preventDefault(); $('composer').requestSubmit(); } });
|
| 258 |
+
document.querySelectorAll('.chip').forEach(c => c.addEventListener('click', () => (c.dataset.action === 'audit' ? openAuditModal() : ask(c.dataset.prompt))));
|
| 259 |
+
$('auditBtn').addEventListener('click', openAuditModal);
|
| 260 |
+
$('auditClose').addEventListener('click', () => $('auditModal').classList.add('hidden'));
|
| 261 |
+
$('auditModal').addEventListener('click', e => { if (e.target === $('auditModal')) $('auditModal').classList.add('hidden'); });
|
| 262 |
+
$('attachBtn').addEventListener('click', () => $('fileInput').click());
|
| 263 |
+
$('fileInput').addEventListener('change', async () => {
|
| 264 |
+
const f = $('fileInput').files[0]; $('fileInput').value = '';
|
| 265 |
+
if (!f) return;
|
| 266 |
+
try { attachAudit(JSON.parse((await f.text()).replace(/^/, ''))); } catch (error) {
|
| 267 |
+
const chat = state.current || newChat(); chat.messages.push({ role: 'assistant', content: `I couldn't read that file: ${error.message} Use the …-evidence.json file the Devseis app saves next to the PDF report.`, passages: [] }); render();
|
| 268 |
+
}
|
| 269 |
+
});
|
| 270 |
+
$('thread').addEventListener('click', e => {
|
| 271 |
+
const t = e.target.closest('button'); if (!t) return;
|
| 272 |
+
if (t.dataset.ask) ask(t.dataset.ask);
|
| 273 |
+
else if (t.dataset.report) writeReport();
|
| 274 |
+
else if (t.dataset.msg) showSource(+t.dataset.msg, +t.dataset.n, true);
|
| 275 |
+
});
|
| 276 |
+
$('newChat').addEventListener('click', () => { newChat(); $('input').focus(); });
|
| 277 |
+
$('sidebarToggle').addEventListener('click', () => { $('sidebar').classList.add('open'); $('overlay').classList.remove('hidden'); });
|
| 278 |
+
$('sidebarClose').addEventListener('click', closeSidebar);
|
| 279 |
+
$('overlay').addEventListener('click', closeSidebar);
|
| 280 |
+
$('sidebarList').addEventListener('click', e => {
|
| 281 |
+
const del = e.target.closest('[data-del]');
|
| 282 |
+
if (del) { state.chats = state.chats.filter(c => c.id !== del.dataset.del); if (state.current && state.current.id === del.dataset.del) state.current = state.chats[0] || null; saveChats(); render(); return; }
|
| 283 |
+
const row = e.target.closest('.convo'); if (row) { state.current = state.chats.find(c => c.id === row.dataset.id); render(); closeSidebar(); }
|
| 284 |
+
});
|
| 285 |
+
$('clearAll').addEventListener('click', () => { state.chats = []; state.current = null; saveChats(); render(); });
|
| 286 |
+
$('themeToggle').addEventListener('click', () => {
|
| 287 |
+
const dark = document.documentElement.dataset.theme ? document.documentElement.dataset.theme === 'dark' : matchMedia('(prefers-color-scheme: dark)').matches;
|
| 288 |
+
document.documentElement.dataset.theme = dark ? 'light' : 'dark';
|
| 289 |
+
try { localStorage.setItem('devseis.theme', document.documentElement.dataset.theme); } catch { /* ignore */ }
|
| 290 |
+
});
|
| 291 |
+
|
| 292 |
+
async function init() {
|
| 293 |
+
try { const t = localStorage.getItem('devseis.theme'); if (t) document.documentElement.dataset.theme = t; } catch { /* ignore */ }
|
| 294 |
+
state.chats = loadChats();
|
| 295 |
+
state.current = state.chats[0] || null;
|
| 296 |
+
const [kb, device, config] = await Promise.all([
|
| 297 |
+
fetch('library/knowledge.json').then(r => r.json()),
|
| 298 |
+
detectDevice().catch(() => ({})),
|
| 299 |
+
fetch('app/model-version.json', { cache: 'no-cache' }).then(r => r.json()).catch(() => ({})),
|
| 300 |
+
]);
|
| 301 |
+
state.kb = new Knowledge(kb); state.device = device; state.config = config;
|
| 302 |
+
// Coming back from the phone check with a fresh report.
|
| 303 |
+
if (location.hash === '#audit') {
|
| 304 |
+
try { const ev = JSON.parse(localStorage.getItem('devseis.lastAudit')); if (ev) { attachAudit(ev); localStorage.removeItem('devseis.lastAudit'); } } catch { /* ignore */ }
|
| 305 |
+
history.replaceState(null, '', location.pathname);
|
| 306 |
+
}
|
| 307 |
+
render();
|
| 308 |
+
if (new URLSearchParams(location.search).has('test')) Object.assign(window, { __chat: state, __ask: ask });
|
| 309 |
+
}
|
| 310 |
+
init();
|
docs/MODEL_LLM.md
CHANGED
|
@@ -107,6 +107,8 @@ date it was built with, so a dataset version stays reproducible.
|
|
| 107 |
| **auditor-0.5b v0.3** | v0.3 (tag `v0.3`) | 3,000 balanced, including phones (out of 39,500; none over 3,072 tokens) | Windows, Linux, macOS, iPhone, Android; 74 checks; real CVEs; evidence labels; computed summary scores | **In use** by the desktop apps and the phone check since 2026-10-10. Trained 375 steps (final validation loss 0.0109). Held-out: 100% valid, 100% grounded, 100% exact fields (60 examples). WebLLM on the GPU: q0f16 8/8 and q4f16_1 8/8 grounded on phone cases. Published with tag `v0.3` in all four model repositories |
|
| 108 |
| auditor-0.5b v0.4+ | v0.3 + expert-reviewed library + gold findings | more, on a GPU if available | same, better wording and priorities | Later |
|
| 109 |
|
|
|
|
|
|
|
| 110 |
Dataset v0.2 is not trained on: it was superseded by v0.3 before a run started.
|
| 111 |
|
| 112 |
**Settings (all runs):** Qwen2.5-0.5B-Instruct, LoRA r=16, alpha=32 (8.8 M trainable parameters, 1.75%), learning rate
|
|
|
|
| 107 |
| **auditor-0.5b v0.3** | v0.3 (tag `v0.3`) | 3,000 balanced, including phones (out of 39,500; none over 3,072 tokens) | Windows, Linux, macOS, iPhone, Android; 74 checks; real CVEs; evidence labels; computed summary scores | **In use** by the desktop apps and the phone check since 2026-10-10. Trained 375 steps (final validation loss 0.0109). Held-out: 100% valid, 100% grounded, 100% exact fields (60 examples). WebLLM on the GPU: q0f16 8/8 and q4f16_1 8/8 grounded on phone cases. Published with tag `v0.3` in all four model repositories |
|
| 108 |
| auditor-0.5b v0.4+ | v0.3 + expert-reviewed library + gold findings | more, on a GPU if available | same, better wording and priorities | Later |
|
| 109 |
|
| 110 |
+
| auditor-1.5b v0.4 | v0.4 = v0.3 report tasks + 1,286 grounded chat examples (fixes, why, risk, controls, AI tools, phone settings, statuses, the auditor, the user's own audit, no-audit, out-of-scope, unknown) | 2,400 balanced (about 60% report, 40% chat) | Qwen2.5-**1.5B**; chat **and** reports in one model | **Training** since 2026-10-10 12:00 (about 300 steps, about 30 hours). Will power the chat and replace 0.5B v0.3 |
|
| 111 |
+
|
| 112 |
Dataset v0.2 is not trained on: it was superseded by v0.3 before a run started.
|
| 113 |
|
| 114 |
**Settings (all runs):** Qwen2.5-0.5B-Instruct, LoRA r=16, alpha=32 (8.8 M trainable parameters, 1.75%), learning rate
|
download.html
CHANGED
|
@@ -69,7 +69,7 @@
|
|
| 69 |
<body>
|
| 70 |
<header class="top">
|
| 71 |
<div class="brand"><img src="app/build/icon.png" alt=""><span>Devseis <b>Endpoint Auditor</b></span></div>
|
| 72 |
-
<nav><a href="index.html">Phone check</a><a href="about.html">About</a></nav>
|
| 73 |
</header>
|
| 74 |
|
| 75 |
<main>
|
|
@@ -170,10 +170,10 @@
|
|
| 170 |
<details><summary>What is in the report?</summary><p>A score, the most important gaps, and for each problem: what was found, why it matters, how risky it is, and simple steps to fix it — mapped to ISO 27001, GDPR and the EU AI Act.</p></details>
|
| 171 |
<details><summary>Do I need internet?</summary><p>Only the first time (to download the AI auditor). After that, checks work offline.</p></details>
|
| 172 |
<details><summary>I'm setting this up for a company</summary><p>Before running, edit <code>baseline.conf</code> (approved admins, approved AI tools, rules) and <code>organisational.conf</code> (8 company questions). They are in <span class="path">~/Library/Application Support/Devseis Endpoint Auditor</span> on Mac, <span class="path">%APPDATA%\Devseis Endpoint Auditor</span> on Windows and <span class="path">~/.config/Devseis Endpoint Auditor</span> on Linux.</p></details>
|
| 173 |
-
<details><summary>What about my phone?</summary><p>Open <a href="
|
| 174 |
<p class="muted">Not legal advice or a certification. Open source by Devseis: code Apache-2.0, data CC BY 4.0. <a href="https://huggingface.co/spaces/Devseis/endpoint-auditor/tree/main">Source</a> · <a href="https://huggingface.co/datasets/Devseis/endpoint-auditor-releases">All releases</a></p>
|
| 175 |
</main>
|
| 176 |
-
<footer class="foot">Devseis · <a href="index.html">Phone check</a> · <a href="about.html">About</a></footer>
|
| 177 |
|
| 178 |
<script>
|
| 179 |
// Pick the visitor's system, and fill in links, sizes and checksums from the releases repository.
|
|
|
|
| 69 |
<body>
|
| 70 |
<header class="top">
|
| 71 |
<div class="brand"><img src="app/build/icon.png" alt=""><span>Devseis <b>Endpoint Auditor</b></span></div>
|
| 72 |
+
<nav><a href="index.html">Assistant</a><a href="phone.html">Phone check</a><a href="about.html">About</a></nav>
|
| 73 |
</header>
|
| 74 |
|
| 75 |
<main>
|
|
|
|
| 170 |
<details><summary>What is in the report?</summary><p>A score, the most important gaps, and for each problem: what was found, why it matters, how risky it is, and simple steps to fix it — mapped to ISO 27001, GDPR and the EU AI Act.</p></details>
|
| 171 |
<details><summary>Do I need internet?</summary><p>Only the first time (to download the AI auditor). After that, checks work offline.</p></details>
|
| 172 |
<details><summary>I'm setting this up for a company</summary><p>Before running, edit <code>baseline.conf</code> (approved admins, approved AI tools, rules) and <code>organisational.conf</code> (8 company questions). They are in <span class="path">~/Library/Application Support/Devseis Endpoint Auditor</span> on Mac, <span class="path">%APPDATA%\Devseis Endpoint Auditor</span> on Windows and <span class="path">~/.config/Devseis Endpoint Auditor</span> on Linux.</p></details>
|
| 173 |
+
<details><summary>What about my phone?</summary><p>Open <a href="phone.html">the phone check</a> on your iPhone or Android phone — the phone check runs in the browser, nothing to install.</p></details>
|
| 174 |
<p class="muted">Not legal advice or a certification. Open source by Devseis: code Apache-2.0, data CC BY 4.0. <a href="https://huggingface.co/spaces/Devseis/endpoint-auditor/tree/main">Source</a> · <a href="https://huggingface.co/datasets/Devseis/endpoint-auditor-releases">All releases</a></p>
|
| 175 |
</main>
|
| 176 |
+
<footer class="foot">Devseis · <a href="index.html">Assistant</a> · <a href="phone.html">Phone check</a> · <a href="about.html">About</a></footer>
|
| 177 |
|
| 178 |
<script>
|
| 179 |
// Pick the visitor's system, and fill in links, sizes and checksums from the releases repository.
|
index.html
CHANGED
|
@@ -2,91 +2,81 @@
|
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="utf-8">
|
| 5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
| 6 |
-
<meta name="description" content="
|
| 7 |
<meta name="theme-color" content="#ED2939">
|
| 8 |
-
<title>Devseis
|
| 9 |
-
<link rel="
|
|
|
|
|
|
|
| 10 |
</head>
|
| 11 |
<body>
|
| 12 |
-
<header
|
| 13 |
-
<div class="
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
</header>
|
|
|
|
| 16 |
|
| 17 |
-
<main>
|
| 18 |
-
<
|
| 19 |
-
|
| 20 |
-
<h1
|
| 21 |
-
<p class="
|
| 22 |
-
<div
|
| 23 |
-
|
| 24 |
-
<
|
| 25 |
-
<
|
| 26 |
-
<
|
| 27 |
-
<div class="row"><button class="secondary" data-demo="ios">iPhone</button><button class="secondary" data-demo="android">Android</button></div>
|
| 28 |
</div>
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
<li><b>Honest:</b> every result says whether it was <i>detected</i> or <i>self-reported</i>.</li>
|
| 33 |
-
</ul>
|
| 34 |
-
<button id="start" class="primary" disabled>Start the check</button>
|
| 35 |
-
<p class="muted center"><a href="about.html">About the project</a></p>
|
| 36 |
-
</section>
|
| 37 |
-
|
| 38 |
-
<!-- 2. Approval -->
|
| 39 |
-
<section id="s-consent" class="screen hidden">
|
| 40 |
-
<h1>Before we start</h1>
|
| 41 |
-
<div class="card">
|
| 42 |
-
<p><b>What will be checked</b> (<span id="check-count"></span> checks):</p>
|
| 43 |
-
<ul id="plan" class="plan"></ul>
|
| 44 |
-
</div>
|
| 45 |
-
<label class="card toggle">
|
| 46 |
-
<input type="checkbox" id="use-ai">
|
| 47 |
-
<span><b>Use the AI auditor</b><br><span id="ai-note" class="muted"></span></span>
|
| 48 |
-
</label>
|
| 49 |
-
<p class="muted">Nothing on the phone is changed. You can stop at any time.</p>
|
| 50 |
-
<div class="row"><button class="secondary" id="consent-back">Back</button><button class="primary" id="consent-ok">I agree, continue</button></div>
|
| 51 |
-
</section>
|
| 52 |
|
| 53 |
-
|
| 54 |
-
<
|
| 55 |
-
<
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
<
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
<
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
-
|
| 73 |
-
<
|
| 74 |
-
<
|
| 75 |
-
<div
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
</div>
|
| 80 |
-
<p id="pdf-note" class="muted"></p>
|
| 81 |
-
<button class="link" id="again">Check again</button>
|
| 82 |
-
</section>
|
| 83 |
-
</main>
|
| 84 |
|
| 85 |
-
<
|
| 86 |
-
Open source by Devseis · <a href="about.html">about</a> ·
|
| 87 |
-
<a href="https://huggingface.co/spaces/Devseis/endpoint-auditor/tree/main">code (Apache-2.0)</a> ·
|
| 88 |
-
<a href="https://huggingface.co/datasets/Devseis/endpoint-auditor-synthetic">data (CC BY 4.0)</a> · Not legal advice or a certification.
|
| 89 |
-
</footer>
|
| 90 |
-
<script type="module" src="mobile/app.js"></script>
|
| 91 |
</body>
|
| 92 |
</html>
|
|
|
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="utf-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover, interactive-widget=resizes-content">
|
| 6 |
+
<meta name="description" content="Devseis security assistant: ask about securing your computer or phone, ISO 27001, GDPR and the EU AI Act, and run a free audit. The AI runs on your device; nothing is uploaded.">
|
| 7 |
<meta name="theme-color" content="#ED2939">
|
| 8 |
+
<title>Devseis Security Assistant</title>
|
| 9 |
+
<link rel="icon" href="app/build/icon.png">
|
| 10 |
+
<link rel="apple-touch-icon" href="app/build/icon.png">
|
| 11 |
+
<link rel="stylesheet" href="chat/chat.css">
|
| 12 |
</head>
|
| 13 |
<body>
|
| 14 |
+
<header>
|
| 15 |
+
<div class="header-left">
|
| 16 |
+
<button type="button" id="sidebarToggle" class="icon-btn" aria-label="Conversations" title="Conversations">
|
| 17 |
+
<svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M4 6h16M4 12h16M4 18h16"/></svg>
|
| 18 |
+
</button>
|
| 19 |
+
<a class="brand" href="index.html"><img src="app/build/icon.png" alt=""><span>Devseis <b>Security Assistant</b></span></a>
|
| 20 |
+
</div>
|
| 21 |
+
<div class="header-actions">
|
| 22 |
+
<button type="button" id="newChat" class="icon-btn" aria-label="New chat" title="New chat">
|
| 23 |
+
<svg viewBox="0 0 24 24" width="19" height="19" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M12 5v14M5 12h14"/></svg>
|
| 24 |
+
</button>
|
| 25 |
+
<button type="button" id="themeToggle" class="icon-btn" aria-label="Light or dark" title="Light or dark">◐</button>
|
| 26 |
+
<button type="button" id="auditBtn" class="audit-btn">🛡 Run audit</button>
|
| 27 |
+
</div>
|
| 28 |
</header>
|
| 29 |
+
<div class="status-bar hidden" id="statusBar"><div class="status-text" id="statusText"></div><div class="status-progress"><div id="statusFill"></div></div></div>
|
| 30 |
|
| 31 |
+
<main id="chatMain">
|
| 32 |
+
<div class="empty-state" id="emptyState">
|
| 33 |
+
<div class="hero-icon"><img src="app/build/icon.png" alt=""></div>
|
| 34 |
+
<h1>Hi, I'm your Devseis security assistant.</h1>
|
| 35 |
+
<p class="hero-sub">Ask me how to secure your computer or phone, or about ISO 27001, GDPR and the EU AI Act. I can also <b>audit this device</b> for free. I run on your device: nothing you type is uploaded.</p>
|
| 36 |
+
<div class="chips">
|
| 37 |
+
<button type="button" class="chip" data-prompt="How do I turn on disk encryption on my computer?">🔒 Turn on disk encryption</button>
|
| 38 |
+
<button type="button" class="chip" data-prompt="Is ChatGPT OK to use at work under GDPR?">🤖 Is ChatGPT OK at work?</button>
|
| 39 |
+
<button type="button" class="chip" data-prompt="What does ISO 27001 A.8.7 require?">📘 Explain ISO 27001 A.8.7</button>
|
| 40 |
+
<button type="button" class="chip" data-action="audit">🛡 Audit this device</button>
|
|
|
|
| 41 |
</div>
|
| 42 |
+
</div>
|
| 43 |
+
<div id="thread" aria-live="polite"></div>
|
| 44 |
+
</main>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
<form id="composer" autocomplete="off">
|
| 47 |
+
<button type="button" id="attachBtn" class="icon-btn attach" title="Add an audit report (.json from the Devseis app)" aria-label="Add an audit report">
|
| 48 |
+
<svg viewBox="0 0 24 24" width="19" height="19" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21.44 11.05l-9.19 9.19a5.5 5.5 0 01-7.78-7.78l9.2-9.19a3.5 3.5 0 014.95 4.95l-9.2 9.19a1.5 1.5 0 01-2.12-2.12l8.49-8.48"/></svg>
|
| 49 |
+
</button>
|
| 50 |
+
<input type="file" id="fileInput" accept=".json,application/json" hidden>
|
| 51 |
+
<div class="input-pill">
|
| 52 |
+
<textarea id="input" rows="1" placeholder="Ask about security, or add your audit report…" aria-label="Message"></textarea>
|
| 53 |
+
</div>
|
| 54 |
+
<button type="submit" id="sendBtn" class="send-btn" aria-label="Send" disabled>
|
| 55 |
+
<svg viewBox="0 0 24 24" width="18" height="18" fill="currentColor"><path d="M3.4 20.4l17.45-7.48a1 1 0 000-1.84L3.4 3.6a.99.99 0 00-1.39.91L2 9.12c0 .5.37.93.87.99L17 12 2.87 13.88c-.5.07-.87.5-.87 1l.01 4.61c0 .71.73 1.2 1.39.91z"/></svg>
|
| 56 |
+
</button>
|
| 57 |
+
</form>
|
| 58 |
+
<p class="disclaimer">Runs on your device · Answers come from the Devseis knowledge base and can be wrong · Not legal advice</p>
|
| 59 |
|
| 60 |
+
<div class="overlay hidden" id="overlay"></div>
|
| 61 |
+
<aside class="sidebar" id="sidebar" aria-label="Conversations">
|
| 62 |
+
<div class="sidebar-head"><h2>Conversations</h2><button type="button" class="icon-btn" id="sidebarClose" aria-label="Close">✕</button></div>
|
| 63 |
+
<div class="sidebar-list" id="sidebarList"></div>
|
| 64 |
+
<div class="sidebar-foot">
|
| 65 |
+
<div class="row"><span>AI model</span><span class="muted" id="modelName">loads on first question</span></div>
|
| 66 |
+
<div class="row"><a href="phone.html">📱 Phone check</a><a href="download.html">💻 Desktop app</a></div>
|
| 67 |
+
<div class="row"><a href="about.html">About</a><button type="button" class="small-btn" id="clearAll">Clear history</button></div>
|
| 68 |
+
<p class="muted tiny">Conversations are stored only in this browser. Open source by Devseis (Apache-2.0).</p>
|
| 69 |
+
</div>
|
| 70 |
+
</aside>
|
| 71 |
|
| 72 |
+
<div class="modal hidden" id="auditModal" role="dialog" aria-modal="true" aria-labelledby="auditTitle">
|
| 73 |
+
<div class="modal-card">
|
| 74 |
+
<h2 id="auditTitle">Audit this device</h2>
|
| 75 |
+
<div id="auditOptions"></div>
|
| 76 |
+
<button type="button" class="link-btn" id="auditClose">Not now</button>
|
| 77 |
+
</div>
|
| 78 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
+
<script type="module" src="chat/chat.js"></script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
</body>
|
| 82 |
</html>
|
library/build_knowledge.py
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Build library/knowledge.json: the passages the chat assistant answers from (and cites).
|
| 3 |
+
|
| 4 |
+
Generated from the catalog and library so the chat never drifts from the audit:
|
| 5 |
+
fix how to fix / why it matters, per check and OS (check_guidance.json + catalog rule + references)
|
| 6 |
+
control ISO 27001 / GDPR / EU AI Act control summaries (controls.json)
|
| 7 |
+
tool AI tool profiles (ai_tools.json) and EU AI Act risk categories
|
| 8 |
+
phone where a setting is on iPhone / Android (catalog/mobile_questions.json)
|
| 9 |
+
status what each audit status means
|
| 10 |
+
faq the auditor itself: what it checks, privacy, install, phone check
|
| 11 |
+
Usage: python3 library/build_knowledge.py
|
| 12 |
+
"""
|
| 13 |
+
import json
|
| 14 |
+
import os
|
| 15 |
+
import re
|
| 16 |
+
import sys
|
| 17 |
+
|
| 18 |
+
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 19 |
+
OS_LABEL = {"windows": "Windows", "linux": "Linux", "macos": "macOS", "ios": "iPhone", "android": "Android"}
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def load(*parts):
|
| 23 |
+
with open(os.path.join(ROOT, *parts), encoding="utf-8") as handle:
|
| 24 |
+
return json.load(handle)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def read_conf(path):
|
| 28 |
+
conf = {}
|
| 29 |
+
for line in open(os.path.join(ROOT, path), encoding="utf-8"):
|
| 30 |
+
if "=" in line and not line.lstrip().startswith("#"):
|
| 31 |
+
key, value = line.split("=", 1)
|
| 32 |
+
conf[key.strip()] = value.strip().strip('"')
|
| 33 |
+
return conf
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def fill(text, baseline):
|
| 37 |
+
"""Same placeholder rules as the report builder (training/build_dataset.py), including derived values."""
|
| 38 |
+
sys.path.insert(0, os.path.join(ROOT, "training"))
|
| 39 |
+
from build_dataset import fill as report_fill
|
| 40 |
+
return report_fill(text, baseline)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
FAQ = [
|
| 44 |
+
("What the Devseis Endpoint Auditor is",
|
| 45 |
+
"The Devseis Endpoint Auditor is a free, open-source, read-only check of a computer or phone against ISO 27001, GDPR "
|
| 46 |
+
"technical controls and the EU AI Act. It reads security settings, compares them with a baseline, matches installed "
|
| 47 |
+
"software against known vulnerabilities, and an AI auditor that runs on the device writes a report with findings, "
|
| 48 |
+
"risk levels and fix steps. It is not a certification and not legal advice."),
|
| 49 |
+
("Does the audit change anything?",
|
| 50 |
+
"No. The audit only reads settings such as password rules, firewall, disk encryption and installed software. It never "
|
| 51 |
+
"changes them. Administrator rights are requested because some settings can only be read by an administrator."),
|
| 52 |
+
("Privacy: where do audit results go?",
|
| 53 |
+
"Nowhere. Evidence and reports stay on the device. The app downloads only two things: the AI auditor model and a signed "
|
| 54 |
+
"list of known vulnerabilities. Nothing about the device is uploaded. Chat history is stored only in this browser."),
|
| 55 |
+
("How to run an audit of a computer",
|
| 56 |
+
"A web page cannot read a computer's settings, so computers are audited with the free Devseis desktop app for Mac, "
|
| 57 |
+
"Windows (beta) and Linux. Download it from the Download page, install it, click Run audit and enter the computer "
|
| 58 |
+
"password once. The first run downloads the AI auditor; the audit then takes about 5 to 15 minutes and ends with a PDF report."),
|
| 59 |
+
("How to install on a Mac",
|
| 60 |
+
"Open the downloaded .dmg file and drag Devseis Endpoint Auditor to Applications. The first time, macOS says it could not "
|
| 61 |
+
"verify the app because it is not yet notarised: click Done, then open System Settings, Privacy & Security, and click "
|
| 62 |
+
"Open Anyway. After that it opens normally. It needs macOS 13 or newer."),
|
| 63 |
+
("How to install on Windows",
|
| 64 |
+
"Run the downloaded setup .exe. Windows SmartScreen shows 'Windows protected your PC' because the app is not yet "
|
| 65 |
+
"code-signed: click More info, then Run anyway. Click Next, Install and Finish. When the audit starts, click Yes in the "
|
| 66 |
+
"User Account Control prompt. The Windows version is a beta."),
|
| 67 |
+
("How to install on Linux",
|
| 68 |
+
"On Ubuntu, Debian, Linux Mint or Pop!_OS, double-click the .deb file and click Install. On other distributions, make "
|
| 69 |
+
"the AppImage executable (Properties, Permissions, Allow executing file as program) and double-click it. The audit asks "
|
| 70 |
+
"for the password with the normal desktop prompt."),
|
| 71 |
+
("How the phone check works",
|
| 72 |
+
"Phones are checked in the browser: open the Devseis page on the iPhone or Android phone and start the phone check. The "
|
| 73 |
+
"browser detects what it can (system version, whether a screen lock is set up) and asks the rest with help on where to "
|
| 74 |
+
"look in Settings. Every result is labelled detected or self-reported. The report can be saved or shared as a PDF."),
|
| 75 |
+
("What self-reported and detected mean",
|
| 76 |
+
"Detected means the browser or the app read the value itself. Self-reported means the user answered a question; the "
|
| 77 |
+
"value was not verified on the device. Phone checks are mostly self-reported because browsers cannot read phone settings."),
|
| 78 |
+
("What is in the audit report",
|
| 79 |
+
"The report has a compliance score, the most important gaps, and for each problem: what was found, why it matters, the "
|
| 80 |
+
"risk level, step-by-step fixes for that operating system, how to verify the fix, and the related ISO 27001, GDPR and EU "
|
| 81 |
+
"AI Act references. It also lists AI tools found and their EU AI Act risk class."),
|
| 82 |
+
("Does the auditor need internet?",
|
| 83 |
+
"Only the first time, to download the AI auditor and the vulnerability list. After that audits and chat work offline. "
|
| 84 |
+
"Pending security updates can only be checked online because they ask the vendor."),
|
| 85 |
+
("Settings for organisations",
|
| 86 |
+
"Before running audits, an organisation can edit baseline.conf (approved administrator accounts, approved AI tools, "
|
| 87 |
+
"limits such as screen lock within 5 minutes) and organisational.conf (answers to 8 organisational questions such as "
|
| 88 |
+
"record of processing, DPIA and breach procedure). The desktop app keeps them in its settings folder."),
|
| 89 |
+
("The Devseis AI auditor model",
|
| 90 |
+
"The assistant and the report writer are a small language model fine-tuned by Devseis from Qwen2.5 and run on the "
|
| 91 |
+
"device with WebLLM. Audit verdicts are decided by rules in code, not by the model; the model explains, prioritises and "
|
| 92 |
+
"writes, and every report answer is checked against the evidence before it is used."),
|
| 93 |
+
]
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def main():
|
| 97 |
+
catalog = load("catalog", "checks.json")
|
| 98 |
+
guidance = load("library", "check_guidance.json")
|
| 99 |
+
controls = load("library", "controls.json")
|
| 100 |
+
tools = load("library", "ai_tools.json")
|
| 101 |
+
phone = load("catalog", "mobile_questions.json")
|
| 102 |
+
baseline = read_conf("baseline.conf")
|
| 103 |
+
refs = catalog["references"]
|
| 104 |
+
ctl = {(c["framework"], c["id"]): c for c in controls["controls"]}
|
| 105 |
+
chunks = []
|
| 106 |
+
|
| 107 |
+
def add(cid, kind, title, text, os_family=None, check=None):
|
| 108 |
+
chunks.append({"id": cid, "kind": kind, "title": title, "text": re.sub(r"\s+", " ", text).strip(),
|
| 109 |
+
**({"os": os_family} if os_family else {}), **({"check": check} if check else {})})
|
| 110 |
+
|
| 111 |
+
def ref_text(check):
|
| 112 |
+
out = []
|
| 113 |
+
for key, label in (("iso27001", "ISO 27001:2022"), ("gdpr", "GDPR"), ("ai_act", "EU AI Act")):
|
| 114 |
+
for r in check["controls"][key]:
|
| 115 |
+
title = (ctl.get((label, r)) or {}).get("title") or refs[key].get(r, "")
|
| 116 |
+
out.append(f"{label} {r}" + (f" ({title})" if title else ""))
|
| 117 |
+
return "; ".join(out)
|
| 118 |
+
|
| 119 |
+
for check in catalog["checks"]:
|
| 120 |
+
if check["section"] == "org":
|
| 121 |
+
g = guidance["checks"].get(guidance["aliases"].get(check["id"], check["id"]))
|
| 122 |
+
add(f"fix:{check['id']}", "fix", check["name"],
|
| 123 |
+
f"{check['name']} is an organisational control, answered once by the organisation, not read from a device. "
|
| 124 |
+
f"{g['why'] if g else ''} Rule: {check['rule']} Related: {ref_text(check)}.", check=check["id"])
|
| 125 |
+
continue
|
| 126 |
+
g = guidance["checks"].get(guidance["aliases"].get(check["id"], check["id"]))
|
| 127 |
+
if not g:
|
| 128 |
+
continue
|
| 129 |
+
for os_family in check["os"]:
|
| 130 |
+
name = (check.get("names") or {}).get(os_family, check["name"])
|
| 131 |
+
steps = g["fix"].get("all", []) + g["fix"].get(os_family, [])
|
| 132 |
+
text = (f"{name} on {OS_LABEL[os_family]}. Why it matters: {g['why']} Risk if missing: {g['risk']['level']} - "
|
| 133 |
+
f"{g['risk']['reason']} Requirement: {fill(check['rule'], baseline)} How to fix on {OS_LABEL[os_family]}: "
|
| 134 |
+
+ " ".join(f"({i}) {fill(s, baseline)}" for i, s in enumerate(steps, 1))
|
| 135 |
+
+ f" How to verify: {fill(g['verify'], baseline)} Related controls: {ref_text(check)}.")
|
| 136 |
+
add(f"fix:{check['id']}:{os_family}", "fix", f"{name} on {OS_LABEL[os_family]}", text, os_family, check["id"])
|
| 137 |
+
|
| 138 |
+
for c in controls["controls"]:
|
| 139 |
+
add(f"control:{c['framework']}:{c['id']}", "control", f"{c['framework']} {c['id']} {c['title']}",
|
| 140 |
+
f"{c['framework']} {c['id']} ({c['title']}): {c['summary']} An auditor looks for: {'; '.join(c.get('auditor_looks_for', []))}. "
|
| 141 |
+
f"On endpoints: {c.get('endpoint_relevance', '')}")
|
| 142 |
+
|
| 143 |
+
for name, t in tools["tools"].items():
|
| 144 |
+
add(f"tool:{name}", "tool", f"{name} (AI tool)",
|
| 145 |
+
f"{name}: {t['kind']}, provider {t['provider']}, data location: {t['data_location']}. Default EU AI Act risk class "
|
| 146 |
+
f"for general office use: {t['default_risk']}. GDPR: {t['gdpr_notes']} Whether it is allowed at work depends on the "
|
| 147 |
+
f"organisation's approved AI tools list and on the purpose: some purposes make any AI tool high-risk or prohibited.")
|
| 148 |
+
rules = tools["purpose_rules"]
|
| 149 |
+
for key, title in (("prohibited", "EU AI Act prohibited AI practices"), ("high_risk_examples", "EU AI Act high-risk AI uses"),
|
| 150 |
+
("limited_risk", "EU AI Act limited-risk AI (transparency duties)"), ("minimal_risk", "EU AI Act minimal-risk AI")):
|
| 151 |
+
items = rules[key] if isinstance(rules[key], list) else [rules[key]]
|
| 152 |
+
add(f"aiact:{key}", "control", title, f"{title}: " + "; ".join(items) + ".")
|
| 153 |
+
|
| 154 |
+
for check_id, per_os in phone["checks"].items():
|
| 155 |
+
for os_family, spec in per_os.items():
|
| 156 |
+
name = next(((c.get("names") or {}).get(os_family, c["name"]) for c in catalog["checks"] if c["id"] == check_id), check_id)
|
| 157 |
+
add(f"phone:{check_id}:{os_family}", "phone", f"Where to find {name} on {OS_LABEL[os_family]}",
|
| 158 |
+
f"{name} on {OS_LABEL[os_family]}: {spec['question']} Where to look: {spec['where']}", os_family, check_id)
|
| 159 |
+
|
| 160 |
+
notes = guidance["status_notes"]
|
| 161 |
+
add("status:all", "status", "What the audit statuses mean",
|
| 162 |
+
"Compliant: the setting meets the baseline. Non-Compliant: it does not meet the baseline. "
|
| 163 |
+
f"Pending: {notes['Pending']} NotApplicable: {notes['NotApplicable']} Error: {notes['Error']}")
|
| 164 |
+
|
| 165 |
+
counts = {o: sum(o in c["os"] for c in catalog["checks"]) for o in OS_LABEL}
|
| 166 |
+
add("faq:checks", "faq", "How many checks the audit runs",
|
| 167 |
+
"The audit catalog has " + str(len(catalog["checks"])) + " checks: " + ", ".join(f"{OS_LABEL[o]} {n}" for o, n in counts.items())
|
| 168 |
+
+ ". They cover passwords and lockout, malware protection, firewall, screen lock, USB storage, administrator accounts, "
|
| 169 |
+
"disk encryption, updates and known vulnerabilities, GDPR technical controls (backups, logging, remote access, "
|
| 170 |
+
"telemetry and more), EU AI Act controls (AI tools found, shadow AI, risk classification) and 8 organisational controls.")
|
| 171 |
+
for i, (title, text) in enumerate(FAQ):
|
| 172 |
+
add(f"faq:{i}", "faq", title, text)
|
| 173 |
+
|
| 174 |
+
out = {"version": catalog["catalog_version"], "chunks": chunks}
|
| 175 |
+
with open(os.path.join(ROOT, "library", "knowledge.json"), "w", encoding="utf-8") as handle:
|
| 176 |
+
json.dump(out, handle, ensure_ascii=False, indent=0)
|
| 177 |
+
kinds = {}
|
| 178 |
+
for c in chunks:
|
| 179 |
+
kinds[c["kind"]] = kinds.get(c["kind"], 0) + 1
|
| 180 |
+
print(f"knowledge.json: {len(chunks)} passages {kinds}")
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
if __name__ == "__main__":
|
| 184 |
+
main()
|
library/knowledge.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
mobile/app.js
CHANGED
|
@@ -268,6 +268,10 @@ function showResult() {
|
|
| 268 |
<p class="muted">Written ${sources.model ? `by the AI auditor (${sources.model}) and ` : ''}by the built-in writer (${sources.template}).</p>
|
| 269 |
</div>`;
|
| 270 |
$('pdf-note').textContent = 'The report stays on this phone until you save or share it.';
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
show('done');
|
| 272 |
}
|
| 273 |
|
|
|
|
| 268 |
<p class="muted">Written ${sources.model ? `by the AI auditor (${sources.model}) and ` : ''}by the built-in writer (${sources.template}).</p>
|
| 269 |
</div>`;
|
| 270 |
$('pdf-note').textContent = 'The report stays on this phone until you save or share it.';
|
| 271 |
+
try { localStorage.setItem('devseis.lastAudit', state.report.evidenceText); } catch { /* private mode */ }
|
| 272 |
+
if (!document.getElementById('ask-assistant')) {
|
| 273 |
+
document.querySelector('#s-done .actions').insertAdjacentHTML('afterbegin', '<a class="dl-mac" id="ask-assistant" href="index.html#audit">💬 Ask the assistant about this report</a>');
|
| 274 |
+
}
|
| 275 |
show('done');
|
| 276 |
}
|
| 277 |
|
mobile/test/e2e.cjs
CHANGED
|
@@ -28,7 +28,7 @@ app.whenReady().then(async () => {
|
|
| 28 |
const until = async (code, ms = 60000) => { const t = Date.now(); while (!(await js(code))) { if (Date.now() - t > ms) throw new Error(`timeout: ${code}`); await new Promise(r => setTimeout(r, 200)); } };
|
| 29 |
try {
|
| 30 |
await win.webContents.session.clearCache();
|
| 31 |
-
await win.loadURL(`${process.env.BASE_URL || 'http://127.0.0.1:8765/'}
|
| 32 |
await until(`!document.getElementById('start').disabled`);
|
| 33 |
const device = await js(`document.getElementById('device-card').innerText`);
|
| 34 |
await js(`document.getElementById('start').click()`);
|
|
@@ -48,6 +48,7 @@ app.whenReady().then(async () => {
|
|
| 48 |
const evidence = await js(`window.__devseisState.report.evidenceText`);
|
| 49 |
const result = await js(`document.getElementById('result').innerText`);
|
| 50 |
const pdfSize = await js(`window.__devseisMakePdf().then(b => b.size)`);
|
|
|
|
| 51 |
const html = await js(`window.__devseisState.report.html`);
|
| 52 |
fs.writeFileSync(out, evidence);
|
| 53 |
fs.writeFileSync(out.replace(/\.json$/, '.html'), html);
|
|
|
|
| 28 |
const until = async (code, ms = 60000) => { const t = Date.now(); while (!(await js(code))) { if (Date.now() - t > ms) throw new Error(`timeout: ${code}`); await new Promise(r => setTimeout(r, 200)); } };
|
| 29 |
try {
|
| 30 |
await win.webContents.session.clearCache();
|
| 31 |
+
await win.loadURL(`${process.env.BASE_URL || 'http://127.0.0.1:8765/'}phone.html?test`);
|
| 32 |
await until(`!document.getElementById('start').disabled`);
|
| 33 |
const device = await js(`document.getElementById('device-card').innerText`);
|
| 34 |
await js(`document.getElementById('start').click()`);
|
|
|
|
| 48 |
const evidence = await js(`window.__devseisState.report.evidenceText`);
|
| 49 |
const result = await js(`document.getElementById('result').innerText`);
|
| 50 |
const pdfSize = await js(`window.__devseisMakePdf().then(b => b.size)`);
|
| 51 |
+
console.log('handoff:', await js(`(document.getElementById('ask-assistant')||{}).href + ' stored=' + !!localStorage.getItem('devseis.lastAudit')`));
|
| 52 |
const html = await js(`window.__devseisState.report.html`);
|
| 53 |
fs.writeFileSync(out, evidence);
|
| 54 |
fs.writeFileSync(out.replace(/\.json$/, '.html'), html);
|
phone.html
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
| 6 |
+
<meta name="description" content="Free, private security and compliance check for your phone (ISO 27001, GDPR, EU AI Act). Runs in your browser; nothing about your phone is uploaded.">
|
| 7 |
+
<meta name="theme-color" content="#ED2939">
|
| 8 |
+
<title>Devseis Phone Check</title>
|
| 9 |
+
<link rel="stylesheet" href="mobile/styles.css">
|
| 10 |
+
</head>
|
| 11 |
+
<body>
|
| 12 |
+
<header class="top">
|
| 13 |
+
<div class="brand"><span class="mark">D</span><span>Devseis <b>Phone Check</b></span></div>
|
| 14 |
+
<div style="display:flex;gap:8px;align-items:center"><div id="model-chip" class="chip hidden"></div><a class="chip" href="index.html">← Assistant</a></div>
|
| 15 |
+
</header>
|
| 16 |
+
|
| 17 |
+
<main>
|
| 18 |
+
<!-- 1. Start -->
|
| 19 |
+
<section id="s-start" class="screen">
|
| 20 |
+
<h1 id="hero-title">Is this phone ready for work?</h1>
|
| 21 |
+
<p class="lead" id="hero-lead">A free check against <b>ISO 27001</b>, <b>GDPR</b> and the <b>EU AI Act</b>, written by the Devseis AI auditor <b>inside your browser</b>.</p>
|
| 22 |
+
<div id="device-card" class="card device"><span class="muted">Detecting this device…</span></div>
|
| 23 |
+
<div id="desktop-note" class="card note hidden">
|
| 24 |
+
<p><a class="dl-mac" id="dl-desktop" href="download.html">Download the desktop app for Mac</a></p>
|
| 25 |
+
<p class="muted" id="desktop-other"></p>
|
| 26 |
+
<p class="muted">The phone check runs on phones: open this page on your iPhone or Android. To try it here as a demo, choose a phone type:</p>
|
| 27 |
+
<div class="row"><button class="secondary" data-demo="ios">iPhone</button><button class="secondary" data-demo="android">Android</button></div>
|
| 28 |
+
</div>
|
| 29 |
+
<ul class="facts" id="facts">
|
| 30 |
+
<li><b>Private:</b> your answers and the report stay on this phone. Only the AI model and vulnerability data are downloaded.</li>
|
| 31 |
+
<li><b>About 5 minutes:</b> the browser detects what it can; you answer the rest, with help on where to look.</li>
|
| 32 |
+
<li><b>Honest:</b> every result says whether it was <i>detected</i> or <i>self-reported</i>.</li>
|
| 33 |
+
</ul>
|
| 34 |
+
<button id="start" class="primary" disabled>Start the check</button>
|
| 35 |
+
<p class="muted center"><a href="about.html">About the project</a></p>
|
| 36 |
+
</section>
|
| 37 |
+
|
| 38 |
+
<!-- 2. Approval -->
|
| 39 |
+
<section id="s-consent" class="screen hidden">
|
| 40 |
+
<h1>Before we start</h1>
|
| 41 |
+
<div class="card">
|
| 42 |
+
<p><b>What will be checked</b> (<span id="check-count"></span> checks):</p>
|
| 43 |
+
<ul id="plan" class="plan"></ul>
|
| 44 |
+
</div>
|
| 45 |
+
<label class="card toggle">
|
| 46 |
+
<input type="checkbox" id="use-ai">
|
| 47 |
+
<span><b>Use the AI auditor</b><br><span id="ai-note" class="muted"></span></span>
|
| 48 |
+
</label>
|
| 49 |
+
<p class="muted">Nothing on the phone is changed. You can stop at any time.</p>
|
| 50 |
+
<div class="row"><button class="secondary" id="consent-back">Back</button><button class="primary" id="consent-ok">I agree, continue</button></div>
|
| 51 |
+
</section>
|
| 52 |
+
|
| 53 |
+
<!-- 3. Questions -->
|
| 54 |
+
<section id="s-question" class="screen hidden">
|
| 55 |
+
<div class="progress"><div id="q-bar" class="bar"></div></div>
|
| 56 |
+
<p class="muted" id="q-count"></p>
|
| 57 |
+
<h2 id="q-check" class="check-name"></h2>
|
| 58 |
+
<h1 id="q-text"></h1>
|
| 59 |
+
<div class="where"><span class="where-label">Where to look</span><span id="q-where"></span></div>
|
| 60 |
+
<div id="q-answers" class="answers"></div>
|
| 61 |
+
<div class="row"><button class="secondary" id="q-back">Back</button></div>
|
| 62 |
+
</section>
|
| 63 |
+
|
| 64 |
+
<!-- 4. Writing the report -->
|
| 65 |
+
<section id="s-work" class="screen hidden">
|
| 66 |
+
<h1 id="w-title">Writing your report</h1>
|
| 67 |
+
<p id="w-step" class="muted"></p>
|
| 68 |
+
<div class="progress big"><div id="w-bar" class="bar"></div></div>
|
| 69 |
+
<p id="w-current" class="muted"></p>
|
| 70 |
+
</section>
|
| 71 |
+
|
| 72 |
+
<!-- 5. Result -->
|
| 73 |
+
<section id="s-done" class="screen hidden">
|
| 74 |
+
<div id="result"></div>
|
| 75 |
+
<div class="actions">
|
| 76 |
+
<button class="primary" id="share-pdf">Save or share PDF</button>
|
| 77 |
+
<button class="secondary" id="view-report">View full report</button>
|
| 78 |
+
<button class="secondary" id="save-json">Download evidence (JSON)</button>
|
| 79 |
+
</div>
|
| 80 |
+
<p id="pdf-note" class="muted"></p>
|
| 81 |
+
<button class="link" id="again">Check again</button>
|
| 82 |
+
</section>
|
| 83 |
+
</main>
|
| 84 |
+
|
| 85 |
+
<footer class="foot">
|
| 86 |
+
Open source by Devseis · <a href="about.html">about</a> ·
|
| 87 |
+
<a href="https://huggingface.co/spaces/Devseis/endpoint-auditor/tree/main">code (Apache-2.0)</a> ·
|
| 88 |
+
<a href="https://huggingface.co/datasets/Devseis/endpoint-auditor-synthetic">data (CC BY 4.0)</a> · Not legal advice or a certification.
|
| 89 |
+
</footer>
|
| 90 |
+
<script type="module" src="mobile/app.js"></script>
|
| 91 |
+
</body>
|
| 92 |
+
</html>
|
training/build_chat.py
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Chat training examples for model v0.4 (questions about endpoint security, ISO 27001, GDPR, EU AI Act, the auditor,
|
| 3 |
+
and the user's own audit), grounded in library/knowledge.json and cited as [n].
|
| 4 |
+
|
| 5 |
+
Answers are composed from the same library facts the passages are built from, so they are grounded by construction;
|
| 6 |
+
check_chat() verifies it (citations exist, numbers appear in the prompt, refusals cite nothing). Prompts are built by
|
| 7 |
+
training/chat-contexts.mjs with the app's own search, so training matches runtime.
|
| 8 |
+
|
| 9 |
+
Usage: python3 training/build_chat.py --evidence synthetic/out-v0.3/evidence.jsonl --base training/out-v0.3 --out training/out-v0.4
|
| 10 |
+
"""
|
| 11 |
+
import argparse
|
| 12 |
+
import json
|
| 13 |
+
import os
|
| 14 |
+
import random
|
| 15 |
+
import re
|
| 16 |
+
import subprocess
|
| 17 |
+
import sys
|
| 18 |
+
|
| 19 |
+
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 20 |
+
sys.path.insert(0, os.path.join(ROOT, "library"))
|
| 21 |
+
import build_knowledge as kb_build # noqa: E402
|
| 22 |
+
|
| 23 |
+
DATASET_VERSION = "0.4.0"
|
| 24 |
+
OS_LABEL = kb_build.OS_LABEL
|
| 25 |
+
NUMBER = re.compile(r"(?<![\w.])\d+(?:\.\d+)?(?!\w)")
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def load(*parts):
|
| 29 |
+
with open(os.path.join(ROOT, *parts), encoding="utf-8") as handle:
|
| 30 |
+
return json.load(handle)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def cite(order, cid):
|
| 34 |
+
return f"[{order.index(cid) + 1}]"
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def steps_text(steps):
|
| 38 |
+
return "\n".join(f"{i}. {s}" for i, s in enumerate(steps, 1))
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
OUT_OF_SCOPE = ["What's a good pizza recipe?", "Write me a poem about the sea.", "Who won the football match last night?",
|
| 42 |
+
"Can you help me with my maths homework?", "What's the weather like tomorrow?", "Tell me a joke.",
|
| 43 |
+
"Translate 'good morning' into Spanish.", "Which phone should I buy?", "How do I lose weight?",
|
| 44 |
+
"Recommend a good film for tonight.", "Write a cover letter for a sales job.", "What is the capital of Australia?",
|
| 45 |
+
"How do I make sourdough bread?", "Summarise the plot of Hamlet.", "What stocks should I buy?",
|
| 46 |
+
"Plan a weekend trip to Paris.", "How do I fix a leaking tap?", "Write Python code to sort a list.",
|
| 47 |
+
"What's the best gaming laptop?", "Explain how black holes form.", "Help me write a birthday message.",
|
| 48 |
+
"Who is the president of France?", "How many calories are in a banana?", "Give me a workout plan."]
|
| 49 |
+
UNKNOWN = ["How do I configure VLANs on a Cisco switch?", "What is the PCI DSS requirement 8.3.6?", "How do I set up SSO with Okta?",
|
| 50 |
+
"Is our AWS S3 bucket policy secure?", "How do I configure DMARC for my domain?", "What does SOC 2 Type II require for change management?",
|
| 51 |
+
"How do I harden a Kubernetes cluster?", "Which SIEM should we buy?", "What does HIPAA say about encryption?",
|
| 52 |
+
"How do I configure Azure Conditional Access?", "What does NIS2 require from my company?", "How do I rotate keys in HashiCorp Vault?",
|
| 53 |
+
"Is our WordPress site secure?", "How do I set up a WAF in Cloudflare?", "What are the DORA ICT risk rules?",
|
| 54 |
+
"How do I scan my network with nmap?"]
|
| 55 |
+
OWN_DEVICE = ["Is my laptop secure?", "Is my firewall OK?", "Is my computer compliant with ISO 27001?", "What should I fix first?",
|
| 56 |
+
"Am I GDPR compliant?", "Does my phone have any security problems?", "Is my disk encrypted?", "Are my passwords strong enough?",
|
| 57 |
+
"Do I have any viruses?", "Is my screen lock OK?", "Which of my apps are outdated?", "Is my Mac up to date?",
|
| 58 |
+
"Am I using any unapproved AI tools?", "What is my compliance score?"]
|
| 59 |
+
SCOPE = ("I can only help with device security, ISO 27001, GDPR and the EU AI Act, so I can't answer that. "
|
| 60 |
+
"Ask me, for example, how to turn on disk encryption, whether an AI tool is OK for work, or run an audit of this device.")
|
| 61 |
+
DONT_KNOW = ("I don't have reliable information about that in my knowledge base, so I won't guess. I cover security settings "
|
| 62 |
+
"on Windows, macOS, Linux, iPhone and Android, ISO 27001, GDPR and the EU AI Act.")
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def make_jobs(rng, catalog, guidance, controls, tools, phone, evidences):
|
| 66 |
+
"""(job for chat-contexts.mjs, answer builder(order) -> text, meta)."""
|
| 67 |
+
jobs = []
|
| 68 |
+
checks = [c for c in catalog["checks"] if c["section"] != "org"]
|
| 69 |
+
G = lambda cid: guidance["checks"][guidance["aliases"].get(cid, cid)]
|
| 70 |
+
refs_of = lambda c: [f"{lab} {r}" for key, lab in (("iso27001", "ISO 27001:2022"), ("gdpr", "GDPR"), ("ai_act", "EU AI Act")) for r in c["controls"][key]]
|
| 71 |
+
baseline = kb_build.read_conf("baseline.conf")
|
| 72 |
+
fill = lambda t: kb_build.fill(t, baseline)
|
| 73 |
+
|
| 74 |
+
for c in checks:
|
| 75 |
+
g = G(c["id"])
|
| 76 |
+
for os_family in c["os"]:
|
| 77 |
+
name = (c.get("names") or {}).get(os_family, c["name"])
|
| 78 |
+
label = OS_LABEL[os_family]
|
| 79 |
+
gold = f"fix:{c['id']}:{os_family}"
|
| 80 |
+
steps = [fill(s) for s in g["fix"].get("all", []) + g["fix"].get(os_family, [])]
|
| 81 |
+
q_fix = rng.choice([f"How do I fix {name.lower()} on {label}?", f"How can I set up {name.lower()} on my {label}?",
|
| 82 |
+
f"My audit says '{name}' is non-compliant on my {label}. What should I do?",
|
| 83 |
+
f"What steps do I take for {name.lower()} on {label}?"])
|
| 84 |
+
jobs.append(({"question": q_fix, "os": os_family, "gold": [gold]},
|
| 85 |
+
lambda o, g=g, steps=steps, gold=gold, label=label: f"{g['why']} To fix it on {label} {cite(o, gold)}:\n{steps_text(steps)}\n\nTo check it worked: {fill(g['verify'])}",
|
| 86 |
+
("fix", os_family)))
|
| 87 |
+
if rng.random() < 0.45:
|
| 88 |
+
q = rng.choice([f"Why does {name.lower()} matter?", f"What's the risk if {name.lower()} isn't set up on my {label}?",
|
| 89 |
+
f"Is {name.lower()} really important on {label}?"])
|
| 90 |
+
jobs.append(({"question": q, "os": os_family, "gold": [gold]},
|
| 91 |
+
lambda o, g=g, gold=gold: f"{g['why']} If it is missing, the risk is {g['risk']['level'].lower()}: {g['risk']['reason']} {cite(o, gold)}",
|
| 92 |
+
("why", os_family)))
|
| 93 |
+
if rng.random() < 0.25:
|
| 94 |
+
rl = refs_of(c)
|
| 95 |
+
if rl:
|
| 96 |
+
q = rng.choice([f"Which ISO 27001, GDPR or EU AI Act rules cover {name.lower()}?", f"What compliance controls relate to {name.lower()}?"])
|
| 97 |
+
jobs.append(({"question": q, "os": os_family, "gold": [gold]},
|
| 98 |
+
lambda o, rl=rl, name=name, gold=gold: f"{name} relates to {', '.join(rl)} {cite(o, gold)}. "
|
| 99 |
+
"Meeting the setting is evidence for these controls; it is not a certification on its own.",
|
| 100 |
+
("refs", os_family)))
|
| 101 |
+
if rng.random() < 0.2:
|
| 102 |
+
q = f"How do I check that {name.lower()} is set correctly on {label}?"
|
| 103 |
+
jobs.append(({"question": q, "os": os_family, "gold": [gold]},
|
| 104 |
+
lambda o, g=g, gold=gold: f"{fill(g['verify'])} {cite(o, gold)}", ("verify", os_family)))
|
| 105 |
+
|
| 106 |
+
for check_id, per_os in phone["checks"].items():
|
| 107 |
+
for os_family, spec in per_os.items():
|
| 108 |
+
name = next(((c.get("names") or {}).get(os_family, c["name"]) for c in catalog["checks"] if c["id"] == check_id), check_id)
|
| 109 |
+
gold = f"phone:{check_id}:{os_family}"
|
| 110 |
+
for q in rng.sample([f"Where do I find {name.lower()} on my {OS_LABEL[os_family]}?", f"How do I see {name.lower()} on {OS_LABEL[os_family]}?",
|
| 111 |
+
f"Where is the {name.lower()} setting on my {OS_LABEL[os_family]}?"], 2):
|
| 112 |
+
jobs.append(({"question": q, "os": os_family, "gold": [gold]},
|
| 113 |
+
lambda o, spec=spec, gold=gold: f"Go to {spec['where']} {cite(o, gold)}", ("phone", os_family)))
|
| 114 |
+
|
| 115 |
+
for c in controls["controls"]:
|
| 116 |
+
gold = f"control:{c['framework']}:{c['id']}"
|
| 117 |
+
name = f"{c['framework'].replace(':2022', '')} {c['id']}"
|
| 118 |
+
for q in rng.sample([f"What does {name} require?", f"Explain {name} ({c['title']}) in simple terms.",
|
| 119 |
+
f"What does an auditor look for under {name}?"], 2):
|
| 120 |
+
jobs.append(({"question": q, "os": None, "gold": [gold]},
|
| 121 |
+
lambda o, c=c, gold=gold: f"{c['id']} ({c['title']}): {c['summary']} {cite(o, gold)}\n\nAn auditor looks for:\n"
|
| 122 |
+
+ "\n".join(f"- {x}" for x in c.get("auditor_looks_for", [])) + (f"\n\nOn devices: {c['endpoint_relevance']}" if c.get("endpoint_relevance") else ""),
|
| 123 |
+
("control", "any")))
|
| 124 |
+
|
| 125 |
+
for name, t in tools["tools"].items():
|
| 126 |
+
gold = f"tool:{name}"
|
| 127 |
+
for q in rng.sample([f"Is {name} OK to use at work?", f"Can I use {name} with customer data under GDPR?",
|
| 128 |
+
f"What is the EU AI Act risk class of {name}?", f"Is {name} safe for my company?"], 3):
|
| 129 |
+
jobs.append(({"question": q, "os": None, "gold": [gold]},
|
| 130 |
+
lambda o, t=t, name=name, gold=gold: f"{name} is a {t['kind'].lower()} from {t['provider']}; data goes to: {t['data_location'].lower()} {cite(o, gold)}. "
|
| 131 |
+
f"For general office use its default EU AI Act risk class is {t['default_risk']}. GDPR: {t['gdpr_notes']}\n\n"
|
| 132 |
+
"Whether it is allowed depends on your organisation's approved AI tools list and on what you use it for: some purposes "
|
| 133 |
+
"(for example screening job applicants) make any AI tool high-risk.", ("tool", "any")))
|
| 134 |
+
rules = tools["purpose_rules"]
|
| 135 |
+
for key, qs in (("prohibited", ["Which AI uses are banned under the EU AI Act?", "What AI practices are prohibited in the EU?", "Is emotion recognition at work allowed?"]),
|
| 136 |
+
("high_risk_examples", ["When does an AI tool become high-risk under the EU AI Act?", "What are examples of high-risk AI uses?"]),
|
| 137 |
+
("limited_risk", ["What does limited-risk AI mean under the EU AI Act?"]), ("minimal_risk", ["What is minimal-risk AI?"])):
|
| 138 |
+
items = rules[key] if isinstance(rules[key], list) else [rules[key]]
|
| 139 |
+
gold = f"aiact:{key}"
|
| 140 |
+
for q in qs:
|
| 141 |
+
jobs.append(({"question": q, "os": None, "gold": [gold]},
|
| 142 |
+
lambda o, items=items, gold=gold: f"Under the EU AI Act {cite(o, gold)}:\n" + "\n".join(f"- {x}" for x in items), ("aiact", "any")))
|
| 143 |
+
|
| 144 |
+
faq_q = {0: ["What is the Devseis Endpoint Auditor?", "What does this tool do?"], 1: ["Does the audit change anything on my computer?", "Will the audit change my settings?"],
|
| 145 |
+
2: ["Where do my audit results go?", "Is my data sent anywhere?"], 3: ["How do I audit my computer?", "Can you check my laptop from the browser?"],
|
| 146 |
+
4: ["How do I install the app on my Mac?", "The Mac says it cannot verify the app. What do I do?"],
|
| 147 |
+
5: ["How do I install it on Windows?", "Windows says it protected my PC. Is that normal?"], 6: ["How do I install it on Linux?"],
|
| 148 |
+
7: ["How does the phone check work?", "Can you check my iPhone?"], 8: ["What does self-reported mean?"],
|
| 149 |
+
9: ["What is in the audit report?"], 10: ["Do I need internet to run an audit?"], 11: ["How do I set up the auditor for my company?"],
|
| 150 |
+
12: ["Which AI model do you use?", "Who decides if a check passes, you or code?"]}
|
| 151 |
+
for i, qs in faq_q.items():
|
| 152 |
+
gold = f"faq:{i}"
|
| 153 |
+
text = kb_build.FAQ[i][1]
|
| 154 |
+
for q in qs:
|
| 155 |
+
jobs.append(({"question": q, "os": None, "gold": [gold]}, lambda o, text=text, gold=gold: f"{text} {cite(o, gold)}", ("faq", "any")))
|
| 156 |
+
for q in ["How many checks does the audit run?", "What does the audit check?"]:
|
| 157 |
+
jobs.append(({"question": q, "os": None, "gold": ["faq:checks"]}, lambda o: f"{kb_build_checks_text()} {cite(o, 'faq:checks')}", ("faq", "any")))
|
| 158 |
+
for q in ["What does Pending mean in my report?", "What do the statuses in the report mean?", "Why does a check say Error?",
|
| 159 |
+
"What does NotApplicable mean?", "What does Non-Compliant mean?", "Why are some checks 'not read'?"]:
|
| 160 |
+
jobs.append(({"question": q, "os": None, "gold": ["status:all"]}, lambda o: f"{status_text()} {cite(o, 'status:all')}", ("status", "any")))
|
| 161 |
+
|
| 162 |
+
for q in OUT_OF_SCOPE:
|
| 163 |
+
for device in (None, "macos", "windows"):
|
| 164 |
+
jobs.append(({"question": q, "os": device, "gold": []}, lambda o: SCOPE, ("oos", "any")))
|
| 165 |
+
for q in UNKNOWN:
|
| 166 |
+
for device in (None, "linux", "windows"):
|
| 167 |
+
jobs.append(({"question": q, "os": device, "gold": []}, lambda o: DONT_KNOW, ("unknown", "any")))
|
| 168 |
+
for q in OWN_DEVICE:
|
| 169 |
+
for device in ("macos", "windows", "ios", None):
|
| 170 |
+
jobs.append(({"question": q, "os": device, "gold": ["faq:3"] if device not in ("ios", "android") else ["faq:7"]},
|
| 171 |
+
lambda o, device=device: ("I can't see your device from here, so I can't tell you yet. "
|
| 172 |
+
+ ("Run the phone check: open this page on the phone and tap Start the check " if device in ("ios", "android")
|
| 173 |
+
else "Run an audit with the free Devseis desktop app: it reads the settings, changes nothing, and takes about 5 to 15 minutes ")
|
| 174 |
+
+ cite(o, "faq:3" if device not in ("ios", "android") else "faq:7")
|
| 175 |
+
+ ". Then ask me again and I will answer from your real results."), ("noaudit", device or "any")))
|
| 176 |
+
|
| 177 |
+
# Questions about the user's own audit (MY AUDIT filled in from a synthetic audit).
|
| 178 |
+
import itertools
|
| 179 |
+
for ev in itertools.islice(evidences, 0, 260):
|
| 180 |
+
gaps = [r for r in ev["results"] if r["status"] == "Non-Compliant"][:8]
|
| 181 |
+
brief = audit_brief(ev)
|
| 182 |
+
os_family = ev["host"]["os_family"]
|
| 183 |
+
if not gaps:
|
| 184 |
+
jobs.append(({"question": "What should I fix first?", "os": os_family, "gold": [], "audit": brief},
|
| 185 |
+
lambda o, ev=ev: "Your audit found no gaps: every assessed check meets the baseline. Keep automatic updates on and run the audit again after major changes.",
|
| 186 |
+
("audit", os_family)))
|
| 187 |
+
continue
|
| 188 |
+
top = gaps[0]
|
| 189 |
+
gold = f"fix:{top['id']}:{os_family}"
|
| 190 |
+
if not any(c["id"] == top["id"] and os_family in c["os"] for c in checks):
|
| 191 |
+
continue
|
| 192 |
+
g = G(top["id"])
|
| 193 |
+
steps = [fill(s) for s in g["fix"].get("all", []) + g["fix"].get(os_family, [])]
|
| 194 |
+
s = ev["summary"]
|
| 195 |
+
jobs.append(({"question": rng.choice(["What should I fix first?", "Where do I start?", "What is the most important thing to fix?"]),
|
| 196 |
+
"os": os_family, "gold": [gold], "audit": brief},
|
| 197 |
+
lambda o, top=top, gaps=gaps, s=s, steps=steps, g=g, gold=gold: (
|
| 198 |
+
f"Your audit found {s['Non-Compliant']} gaps. Start with {top['name']} (found: {top['actual']}). {g['why']} To fix it {cite(o, gold)}:\n"
|
| 199 |
+
f"{steps_text(steps)}" + (f"\n\nThen look at: {', '.join(r['name'] for r in gaps[1:4])}." if len(gaps) > 1 else "")),
|
| 200 |
+
("audit", os_family)))
|
| 201 |
+
pick = rng.choice(gaps)
|
| 202 |
+
gold2 = f"fix:{pick['id']}:{os_family}"
|
| 203 |
+
if any(c["id"] == pick["id"] and os_family in c["os"] for c in checks):
|
| 204 |
+
g2 = G(pick["id"])
|
| 205 |
+
steps2 = [fill(x) for x in g2["fix"].get("all", []) + g2["fix"].get(os_family, [])]
|
| 206 |
+
jobs.append(({"question": f"How do I fix {pick['name'].lower()}?", "os": os_family, "gold": [gold2], "audit": brief},
|
| 207 |
+
lambda o, pick=pick, steps2=steps2, g2=g2, gold2=gold2: (
|
| 208 |
+
f"Your audit found {pick['name']}: {pick['actual']}. {g2['why']} To fix it {cite(o, gold2)}:\n{steps_text(steps2)}\n\n"
|
| 209 |
+
f"Then run the audit again to confirm."), ("audit", os_family)))
|
| 210 |
+
return jobs
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
def audit_brief(ev):
|
| 214 |
+
"""Python twin of auditBrief() in app/renderer/knowledge.js (tested for identical output)."""
|
| 215 |
+
h, s = ev["host"], ev["summary"]
|
| 216 |
+
assessed = s["Compliant"] + s["Non-Compliant"]
|
| 217 |
+
lines = [f"{h['os_name']} {h['os_version']} ({h['os_family']}), audited {str(ev['audit']['started_at'])[:10]}; "
|
| 218 |
+
f"{s['Compliant']} of {assessed} assessed checks compliant; {s['Non-Compliant']} gaps, {s['Pending']} pending, {s['Error']} not read."]
|
| 219 |
+
gaps = [r for r in ev["results"] if r["status"] == "Non-Compliant"][:8]
|
| 220 |
+
if gaps:
|
| 221 |
+
lines.append("Gaps: " + "; ".join(f"{r['name']}: {r['actual']}" for r in gaps) + ".")
|
| 222 |
+
return " ".join(lines)
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
def kb_build_checks_text():
|
| 226 |
+
k = {c["id"]: c for c in load("library", "knowledge.json")["chunks"]}
|
| 227 |
+
return k["faq:checks"]["text"]
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
def status_text():
|
| 231 |
+
k = {c["id"]: c for c in load("library", "knowledge.json")["chunks"]}
|
| 232 |
+
return k["status:all"]["text"]
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
def check_chat(example):
|
| 236 |
+
"""Grounding rules for chat answers (also used at runtime in the app)."""
|
| 237 |
+
prompt, answer = example["messages"][-2]["content"], example["messages"][-1]["content"]
|
| 238 |
+
problems = []
|
| 239 |
+
n_passages = len(re.findall(r"^\[\d+\] ", prompt.split("MY AUDIT:")[0], re.M))
|
| 240 |
+
for c in re.findall(r"\[(\d+)\]", answer):
|
| 241 |
+
if not 1 <= int(c) <= n_passages:
|
| 242 |
+
problems.append(f"citation [{c}] out of range")
|
| 243 |
+
allowed = set(NUMBER.findall(prompt))
|
| 244 |
+
for n in NUMBER.findall(answer):
|
| 245 |
+
if n not in allowed and not (n.isdigit() and int(n) <= 12): # list numbering
|
| 246 |
+
problems.append(f"number {n} not in prompt")
|
| 247 |
+
return problems
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
def main():
|
| 251 |
+
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
| 252 |
+
parser.add_argument("--evidence", default=os.path.join(ROOT, "synthetic", "out-v0.3", "evidence.jsonl"))
|
| 253 |
+
parser.add_argument("--base", default=os.path.join(ROOT, "training", "out-v0.3"), help="report-task data to include")
|
| 254 |
+
parser.add_argument("--out", default=os.path.join(ROOT, "training", "out-v0.4"))
|
| 255 |
+
parser.add_argument("--seed", type=int, default=11)
|
| 256 |
+
args = parser.parse_args()
|
| 257 |
+
rng = random.Random(args.seed)
|
| 258 |
+
catalog, guidance, controls = load("catalog", "checks.json"), load("library", "check_guidance.json"), load("library", "controls.json")
|
| 259 |
+
tools, phone = load("library", "ai_tools.json"), load("catalog", "mobile_questions.json")
|
| 260 |
+
evidences = [json.loads(l) for l in open(args.evidence)][:600]
|
| 261 |
+
jobs = make_jobs(rng, catalog, guidance, controls, tools, phone, evidences)
|
| 262 |
+
# A few examples carry an earlier, unrelated turn so the model learns to answer the latest question.
|
| 263 |
+
for job, _, _ in jobs:
|
| 264 |
+
job["shuffle"] = rng.random() < 0.5
|
| 265 |
+
proc = subprocess.run(["node", os.path.join(ROOT, "training", "chat-contexts.mjs")], input="".join(json.dumps(j) + "\n" for j, _, _ in jobs),
|
| 266 |
+
capture_output=True, text=True, check=True)
|
| 267 |
+
built = [json.loads(l) for l in proc.stdout.splitlines() if l.strip()]
|
| 268 |
+
examples, bad = [], 0
|
| 269 |
+
for (job, answer, (kind, os_family)), b in zip(jobs, built):
|
| 270 |
+
msgs = b["messages"] + [{"role": "assistant", "content": answer(b["order"])}]
|
| 271 |
+
ex = {"messages": msgs, "meta": {"task": "chat", "os": os_family, "status": kind, "dataset_version": DATASET_VERSION}}
|
| 272 |
+
if check_chat(ex):
|
| 273 |
+
bad += 1
|
| 274 |
+
continue
|
| 275 |
+
examples.append(ex)
|
| 276 |
+
rng.shuffle(examples)
|
| 277 |
+
n = len(examples)
|
| 278 |
+
split = {"test": examples[: n // 20], "validation": examples[n // 20: n // 10], "train": examples[n // 10:]}
|
| 279 |
+
os.makedirs(args.out, exist_ok=True)
|
| 280 |
+
for name, chat in split.items():
|
| 281 |
+
base = [json.loads(l) for l in open(os.path.join(args.base, f"{name}.jsonl"))]
|
| 282 |
+
for b in base:
|
| 283 |
+
b["meta"]["dataset_version"] = DATASET_VERSION
|
| 284 |
+
rows = base + chat
|
| 285 |
+
random.Random(args.seed + len(name)).shuffle(rows)
|
| 286 |
+
with open(os.path.join(args.out, f"{name}.jsonl"), "w", encoding="utf-8") as handle:
|
| 287 |
+
for r in rows:
|
| 288 |
+
handle.write(json.dumps(r, ensure_ascii=False) + "\n")
|
| 289 |
+
print(f"{name:<11} {len(rows):>6} examples ({len(chat)} chat)")
|
| 290 |
+
kinds = {}
|
| 291 |
+
for e in examples:
|
| 292 |
+
kinds[e["meta"]["status"]] = kinds.get(e["meta"]["status"], 0) + 1
|
| 293 |
+
print("chat kinds:", kinds, "| rejected by grounding check:", bad)
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
if __name__ == "__main__":
|
| 297 |
+
main()
|
training/chat-contexts.mjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Build chat prompts for training with the same search and prompt code as the app (app/renderer/knowledge.js).
|
| 2 |
+
// stdin: JSON lines {question, os, gold: [chunk ids], audit, history}
|
| 3 |
+
// stdout: JSON lines {messages, order: [chunk ids in context order]}
|
| 4 |
+
// Gold passages are always in the context (the question is answerable from them); the other slots are filled by search,
|
| 5 |
+
// so the model also learns to ignore irrelevant passages.
|
| 6 |
+
import { readFileSync } from 'node:fs';
|
| 7 |
+
import path from 'node:path';
|
| 8 |
+
import { fileURLToPath } from 'node:url';
|
| 9 |
+
import { Knowledge, chatMessages } from '../app/renderer/knowledge.js';
|
| 10 |
+
|
| 11 |
+
const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
|
| 12 |
+
const kb = new Knowledge(JSON.parse(readFileSync(path.join(root, 'library', 'knowledge.json'), 'utf8')));
|
| 13 |
+
const K = 4;
|
| 14 |
+
for (const line of readFileSync(0, 'utf8').split('\n').filter(Boolean)) {
|
| 15 |
+
const job = JSON.parse(line);
|
| 16 |
+
let passages = kb.search(job.question, { k: K, os: job.os || null });
|
| 17 |
+
for (const id of job.gold || []) {
|
| 18 |
+
if (passages.some(p => p.id === id)) continue;
|
| 19 |
+
const gold = kb.get(id);
|
| 20 |
+
if (!gold) throw new Error(`unknown passage ${id}`);
|
| 21 |
+
passages = [...passages.slice(0, K - 1), gold];
|
| 22 |
+
}
|
| 23 |
+
if (job.shuffle && passages.length > 1) passages = [...passages.slice(1), passages[0]];
|
| 24 |
+
process.stdout.write(JSON.stringify({ messages: chatMessages(job.question, passages, job.audit || 'none', job.history || []),
|
| 25 |
+
order: passages.map(p => p.id) }) + '\n');
|
| 26 |
+
}
|