@allansantos-dev/smart-tool 0.9.14 → 0.9.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/README.md +13 -5
- package/client_hooks.py +46 -12
- package/hook_decision.py +8 -0
- package/integration_metrics.py +50 -0
- package/package.json +1 -1
- package/redirect_rule.py +401 -67
- package/router.py +16 -9
- package/setup_ui.py +987 -709
- package/version.py +1 -1
package/setup_ui.py
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
-
"""Tela de
|
|
2
|
+
"""Tela de configuração do Smart Tool, servida pelo daemon em `GET /setup`.
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
Uma seção por vez, escolhida na barra lateral: Overview (checklist do que precisa de
|
|
5
|
+
atenção, problemas primeiro), Agents (MCP, hook — inclusive desatualizado, com o que a
|
|
6
|
+
atualização muda — e controle de navegador), Models (gateway, modelos, modelos locais),
|
|
7
|
+
Web search (provedores e chaves protegidas por DPAPI), Agent rules, Redirects (métricas e
|
|
8
|
+
padrões de bloqueio), Setup audit e Startup (autostart).
|
|
7
9
|
|
|
8
10
|
`SETUP_TOKEN` é gerado uma vez por processo (nunca persistido em disco) e embutido no
|
|
9
|
-
HTML de `GET /setup`;
|
|
10
|
-
`POST /setup/providers` e `POST /setup/autostart`) exigem
|
|
11
|
+
HTML de `GET /setup`; toda rota `POST /setup/...` que escreve estado exige
|
|
11
12
|
esse token de volta no header `X-Setup-Token`. Não é uma
|
|
12
13
|
trava contra quem já tem acesso de leitura à máquina (que também leria o token de
|
|
13
14
|
`GET /setup`) — só impede escrever config sem nunca ter carregado a página.
|
|
@@ -32,6 +33,7 @@ import local_embedder
|
|
|
32
33
|
import project_store
|
|
33
34
|
import secret_store
|
|
34
35
|
import setup_audit
|
|
36
|
+
import integration_metrics
|
|
35
37
|
import version
|
|
36
38
|
import web_search_external
|
|
37
39
|
|
|
@@ -70,6 +72,7 @@ def status_payload():
|
|
|
70
72
|
models = model_defaults.ensure_recommended_models(gateway["status"] == "ready")
|
|
71
73
|
cfg = config.load_config()
|
|
72
74
|
return {
|
|
75
|
+
"version": version.VERSION,
|
|
73
76
|
"gateway": gateway,
|
|
74
77
|
"models_status": models["status"],
|
|
75
78
|
"models_message": models["message"],
|
|
@@ -179,7 +182,8 @@ def handle_integration_get():
|
|
|
179
182
|
for key, info in AGENT_CLIENTS.items():
|
|
180
183
|
spec, state = client_hooks.CLIENTS[key], client_hooks.status(info)
|
|
181
184
|
clients.append({"client": key, "label": spec["label"], "mcp_url": registered.get(key), "hook": state["installed"],
|
|
182
|
-
"
|
|
185
|
+
"hook_state": state["state"], "hook_changes": state["changes"], "hook_error": state["error"],
|
|
186
|
+
"after_install": spec.get("after_install"), "file": spec["files"][0], "docs": spec["docs"],
|
|
183
187
|
"register_command": " ".join(endpoint_sync.register_command(key, setup_origin())),
|
|
184
188
|
"browser_control": browser.get(key), "browser_control_error": browser_error})
|
|
185
189
|
try:
|
|
@@ -208,7 +212,8 @@ def handle_integration_get():
|
|
|
208
212
|
"duplicate_mode_error": duplicate_error, "duplicate_modes": list(config.DUPLICATE_MODES),
|
|
209
213
|
"pattern_proposals": proposals_mode, "pattern_proposals_error": proposals_error,
|
|
210
214
|
"block_patterns": {"proposals": stored["proposals"], "accepted": stored["accepted"],
|
|
211
|
-
"rejected": len(stored["rejected"]), "error": patterns_error}
|
|
215
|
+
"rejected": len(stored["rejected"]), "error": patterns_error},
|
|
216
|
+
"redirects": integration_metrics.redirects()}
|
|
212
217
|
|
|
213
218
|
|
|
214
219
|
def handle_integration_save(body):
|
|
@@ -409,181 +414,237 @@ _PAGE_TEMPLATE = """<!doctype html>
|
|
|
409
414
|
<head>
|
|
410
415
|
<meta charset="utf-8">
|
|
411
416
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
412
|
-
<title>Smart Tool
|
|
417
|
+
<title>Settings · Smart Tool</title>
|
|
413
418
|
<style>
|
|
414
|
-
:root {
|
|
415
|
-
--bg: #
|
|
416
|
-
--
|
|
417
|
-
--
|
|
418
|
-
--body: "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
|
|
419
|
-
--mono: "Cascadia Mono", "Cascadia Code", Consolas, monospace;
|
|
420
|
-
}
|
|
419
|
+
:root { color-scheme: light dark;
|
|
420
|
+
--bg: #f6f7f9; --surface: #ffffff; --line: #dde1e6; --ink: #1b2430; --muted: #5b6472; --soft: #eef1f5;
|
|
421
|
+
--accent: #2f6fed; --on-accent: #ffffff; --selected: #eaf1ff;
|
|
422
|
+
--ok: #18723c; --ok-bg: #e6f4ea; --warn: #805300; --warn-bg: #fdf3dc; --bad: #b52c2c; --bad-bg: #fbe9e9; --idle: #5b6472; --idle-bg: #eef1f5;
|
|
423
|
+
--body: "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif; --mono: "Cascadia Mono", Consolas, monospace; }
|
|
421
424
|
@media (prefers-color-scheme: dark) {
|
|
422
|
-
:root { --bg: #
|
|
423
|
-
--
|
|
425
|
+
:root { --bg: #14171c; --surface: #1c2027; --line: #39414e; --ink: #e6e9ee; --muted: #a6afbb; --soft: #232831;
|
|
426
|
+
--accent: #91baff; --on-accent: #14171c; --selected: #263751;
|
|
427
|
+
--ok: #68dc93; --ok-bg: #163322; --warn: #e0b565; --warn-bg: #3a2e14; --bad: #ff9696; --bad-bg: #3d1d1d; --idle: #a6afbb; --idle-bg: #262b33; }
|
|
424
428
|
}
|
|
425
429
|
* { box-sizing: border-box; }
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
.
|
|
432
|
-
.
|
|
433
|
-
.
|
|
434
|
-
.
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
.
|
|
438
|
-
|
|
439
|
-
.
|
|
440
|
-
.
|
|
441
|
-
.
|
|
442
|
-
.
|
|
443
|
-
.
|
|
444
|
-
.
|
|
445
|
-
|
|
446
|
-
.
|
|
447
|
-
.
|
|
448
|
-
.
|
|
449
|
-
.
|
|
450
|
-
.
|
|
451
|
-
.
|
|
452
|
-
.
|
|
453
|
-
.
|
|
454
|
-
|
|
455
|
-
.
|
|
456
|
-
.
|
|
457
|
-
|
|
458
|
-
.
|
|
459
|
-
.
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
.
|
|
467
|
-
.
|
|
468
|
-
|
|
469
|
-
.
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
.
|
|
480
|
-
|
|
481
|
-
.
|
|
430
|
+
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 var(--body); }
|
|
431
|
+
a { color: var(--accent); }
|
|
432
|
+
[hidden] { display: none !important; }
|
|
433
|
+
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
|
|
434
|
+
|
|
435
|
+
.top { max-width: 1240px; margin: 0 auto; padding: 26px 28px 18px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
|
|
436
|
+
.top h1 { margin: 0; font-size: 24px; letter-spacing: -.01em; }
|
|
437
|
+
.top .where { color: var(--muted); font: 12px var(--mono); }
|
|
438
|
+
.shell { max-width: 1240px; margin: 0 auto 60px; padding: 0 28px; display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 28px; align-items: start; }
|
|
439
|
+
|
|
440
|
+
.side { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 2px; }
|
|
441
|
+
.side .group { margin: 16px 10px 6px; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
|
|
442
|
+
.side .group:first-child { margin-top: 0; }
|
|
443
|
+
.side a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 12px; border-radius: 8px; color: var(--ink); text-decoration: none; border: 1px solid transparent; }
|
|
444
|
+
.side a:hover { background: var(--soft); }
|
|
445
|
+
.side a[aria-current="page"] { background: var(--selected); border-color: var(--accent); font-weight: 600; }
|
|
446
|
+
.side .count { min-width: 22px; padding: 0 7px; border-radius: 11px; font-size: 12px; font-weight: 700; text-align: center; background: var(--warn-bg); color: var(--warn); }
|
|
447
|
+
.side .count[data-tone="bad"] { background: var(--bad-bg); color: var(--bad); }
|
|
448
|
+
.side .rule { margin: 18px 10px 0; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 12px; }
|
|
449
|
+
|
|
450
|
+
.page-head { margin: 0 0 18px; }
|
|
451
|
+
.page-head h2 { margin: 0 0 4px; font-size: 26px; letter-spacing: -.01em; }
|
|
452
|
+
.page-head p { margin: 0; color: var(--muted); max-width: 70ch; }
|
|
453
|
+
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 20px 22px; margin-bottom: 18px; }
|
|
454
|
+
.card > h3 { margin: 0 0 4px; font-size: 18px; }
|
|
455
|
+
.card > .lede { margin: 0 0 14px; color: var(--muted); font-size: 14px; max-width: 75ch; }
|
|
456
|
+
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
|
|
457
|
+
.card-head h3 { margin: 0; font-size: 18px; }
|
|
458
|
+
|
|
459
|
+
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px 2px 4px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; --tone: var(--idle); background: var(--idle-bg); color: var(--tone); }
|
|
460
|
+
.pill::before { content: "–"; display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; font-size: 12px; font-weight: 800; background: var(--tone); color: var(--surface); }
|
|
461
|
+
.pill[data-tone="ok"] { --tone: var(--ok); background: var(--ok-bg); }
|
|
462
|
+
.pill[data-tone="ok"]::before { content: "✓"; }
|
|
463
|
+
.pill[data-tone="warn"] { --tone: var(--warn); background: var(--warn-bg); }
|
|
464
|
+
.pill[data-tone="warn"]::before { content: "!"; }
|
|
465
|
+
.pill[data-tone="bad"] { --tone: var(--bad); background: var(--bad-bg); }
|
|
466
|
+
.pill[data-tone="bad"]::before { content: "✕"; }
|
|
467
|
+
.pill[data-tone="busy"]::before { content: "…"; }
|
|
468
|
+
|
|
469
|
+
.summary-banner { display: flex; gap: 14px; align-items: center; padding: 16px 20px; border-radius: 12px; margin-bottom: 18px; background: var(--ok-bg); color: var(--ok); font-weight: 600; }
|
|
470
|
+
.summary-banner[data-tone="warn"] { background: var(--warn-bg); color: var(--warn); }
|
|
471
|
+
.summary-banner[data-tone="bad"] { background: var(--bad-bg); color: var(--bad); }
|
|
472
|
+
.summary-banner[data-tone="busy"] { background: var(--idle-bg); color: var(--idle); }
|
|
473
|
+
.checklist { list-style: none; margin: 0; padding: 0; }
|
|
474
|
+
.check { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 16px; align-items: center; padding: 14px 0; border-top: 1px solid var(--line); }
|
|
475
|
+
.check:first-child { border-top: 0; padding-top: 0; }
|
|
476
|
+
.check-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-weight: 600; }
|
|
477
|
+
.check-text { grid-column: 1; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
|
|
478
|
+
.check-action { grid-column: 2; grid-row: 1 / span 2; }
|
|
479
|
+
|
|
480
|
+
.row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; padding: 16px 0; border-top: 1px solid var(--line); align-items: start; }
|
|
481
|
+
.row:first-of-type { border-top: 0; }
|
|
482
|
+
.row-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-weight: 600; }
|
|
483
|
+
.row-text { grid-column: 1; color: var(--muted); font-size: 14px; max-width: 72ch; overflow-wrap: anywhere; }
|
|
484
|
+
.row-side { grid-column: 2; grid-row: 1 / span 2; display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
|
|
485
|
+
.row-more { grid-column: 1 / -1; }
|
|
486
|
+
.callout { margin: 10px 0 0; padding: 12px 14px; border-radius: 8px; background: var(--warn-bg); color: var(--ink); font-size: 14px; }
|
|
487
|
+
.callout strong { color: var(--warn); }
|
|
488
|
+
.callout ul { margin: 6px 0 0; padding-left: 20px; }
|
|
489
|
+
.callout.info { background: var(--soft); }
|
|
490
|
+
.callout.info strong { color: var(--ink); }
|
|
491
|
+
|
|
492
|
+
fieldset.choice { border: 0; padding: 16px 0; margin: 0; border-top: 1px solid var(--line); min-width: 0; }
|
|
493
|
+
fieldset.choice:first-of-type { border-top: 0; padding-top: 4px; }
|
|
494
|
+
fieldset.choice legend { font-weight: 600; font-size: 16px; padding: 0; float: left; width: 100%; }
|
|
495
|
+
fieldset.choice legend + * { clear: both; }
|
|
496
|
+
.choice-intro { color: var(--muted); font-size: 14px; margin: 4px 0 10px; max-width: 75ch; }
|
|
497
|
+
.option { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 2px 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; margin-top: 8px; cursor: pointer; }
|
|
498
|
+
.option:hover { border-color: var(--accent); }
|
|
499
|
+
.option:has(input:checked) { border-color: var(--accent); background: var(--selected); }
|
|
500
|
+
.option input { margin: 3px 0 0; width: 18px; height: 18px; accent-color: var(--accent); }
|
|
501
|
+
.option-title { font-weight: 600; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
|
|
502
|
+
.option-text { grid-column: 2; color: var(--muted); font-size: 14px; }
|
|
503
|
+
.tag { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--accent); border: 1px solid currentColor; border-radius: 4px; padding: 0 5px; }
|
|
504
|
+
.saved { font-size: 13px; margin-top: 8px; min-height: 1.3em; }
|
|
505
|
+
|
|
506
|
+
.field { margin: 0 0 14px; }
|
|
507
|
+
.field label { display: block; font-weight: 600; margin: 0 0 3px; }
|
|
508
|
+
.field .explain { display: block; color: var(--muted); font-size: 13px; margin: 0 0 6px; max-width: 72ch; }
|
|
509
|
+
.field .hint { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
|
|
510
|
+
.pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 16px; }
|
|
511
|
+
input:not([type]), input[type=text], input[type=number], input[type=password], select {
|
|
512
|
+
width: 100%; max-width: 560px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); font: 14px var(--mono); }
|
|
482
513
|
input[type=password] { font-family: var(--body); }
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
.
|
|
486
|
-
button {
|
|
487
|
-
|
|
488
|
-
button
|
|
489
|
-
|
|
490
|
-
.
|
|
491
|
-
.
|
|
492
|
-
.state[data-state="ok"]::before { background: var(--ok); }
|
|
493
|
-
.state[data-state="bad"]::before { background: var(--bad); }
|
|
494
|
-
.state[data-state="warn"]::before { background: var(--warn); }
|
|
495
|
-
.mono { font-family: var(--mono); font-size: .8rem; overflow-wrap: anywhere; }
|
|
496
|
-
.msg { font-size: .84rem; min-height: 1.3em; margin-top: 10px; }
|
|
514
|
+
button { font: 600 14px var(--body); min-height: 38px; padding: 7px 15px; border-radius: 6px; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
|
|
515
|
+
button:hover { border-color: var(--accent); background: var(--selected); }
|
|
516
|
+
button.primary { background: var(--accent); border-color: transparent; color: var(--on-accent); }
|
|
517
|
+
button.primary:hover { filter: brightness(1.08); }
|
|
518
|
+
button.small { min-height: 30px; padding: 3px 10px; font-size: 13px; }
|
|
519
|
+
button:disabled { opacity: .5; cursor: default; }
|
|
520
|
+
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
|
|
521
|
+
.msg { font-size: 14px; margin-top: 10px; min-height: 1.3em; overflow-wrap: anywhere; }
|
|
522
|
+
.msg:empty { min-height: 0; margin: 0; }
|
|
497
523
|
.msg.error { color: var(--bad); }
|
|
498
524
|
.msg.ok { color: var(--ok); }
|
|
499
525
|
.msg.warn { color: var(--warn); }
|
|
500
|
-
.
|
|
501
|
-
.
|
|
502
|
-
.
|
|
503
|
-
.
|
|
504
|
-
.
|
|
505
|
-
.
|
|
506
|
-
|
|
507
|
-
.
|
|
526
|
+
.mono { font: 13px var(--mono); overflow-wrap: anywhere; }
|
|
527
|
+
details.more { margin-top: 10px; }
|
|
528
|
+
details.more > summary { cursor: pointer; color: var(--accent); font-size: 14px; }
|
|
529
|
+
pre.code { margin: 8px 0 0; padding: 12px 14px; max-height: 320px; overflow: auto; font: 12px/1.5 var(--mono); background: var(--soft); border-radius: 8px; white-space: pre; }
|
|
530
|
+
.confirm-box { margin-top: 12px; padding: 14px 16px; border: 1px solid var(--accent); border-radius: 8px; background: var(--selected); }
|
|
531
|
+
.confirm-box p { margin: 0 0 6px; font-size: 14px; }
|
|
532
|
+
|
|
533
|
+
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 6px 0 16px; }
|
|
534
|
+
.tile { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
|
|
535
|
+
.tile .value { font-size: 28px; font-weight: 700; line-height: 1.1; }
|
|
536
|
+
.tile .label { color: var(--muted); font-size: 13px; }
|
|
537
|
+
.bars { list-style: none; margin: 6px 0 0; padding: 0; }
|
|
538
|
+
.bars li { display: grid; grid-template-columns: minmax(90px, 200px) minmax(0, 1fr) 54px; gap: 10px; align-items: center; padding: 4px 0; font-size: 14px; }
|
|
539
|
+
.bars .bar { height: 10px; border-radius: 5px; background: var(--soft); overflow: hidden; }
|
|
540
|
+
.bars .bar span { display: block; height: 100%; background: var(--accent); border-radius: 5px; }
|
|
541
|
+
.bars .num { text-align: right; font-variant-numeric: tabular-nums; }
|
|
542
|
+
.bars .name { overflow-wrap: anywhere; }
|
|
543
|
+
|
|
544
|
+
.provider-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; padding: 16px 0; border-top: 1px solid var(--line); align-items: start; }
|
|
545
|
+
.provider-row:first-of-type { border-top: 0; padding-top: 4px; }
|
|
546
|
+
.provider-row .key-form { grid-column: 1 / -1; }
|
|
547
|
+
|
|
548
|
+
.pattern-tools { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 10px; margin-top: 12px; }
|
|
508
549
|
.pattern-list { list-style: none; margin: 10px 0 0; padding: 0; border-top: 1px solid var(--line); }
|
|
509
|
-
.pattern-row { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: start;
|
|
510
|
-
|
|
511
|
-
.pattern-
|
|
512
|
-
.pattern-row input[type=checkbox] { margin-top: 6px; }
|
|
550
|
+
.pattern-row { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: start; padding: 10px 0; border-bottom: 1px solid var(--line); }
|
|
551
|
+
.pattern-row.plain { grid-template-columns: minmax(0, 1fr); }
|
|
552
|
+
.pattern-row input[type=checkbox] { margin-top: 6px; width: 18px; height: 18px; accent-color: var(--accent); }
|
|
513
553
|
.pattern-body summary { display: flex; gap: 8px; align-items: baseline; cursor: pointer; min-width: 0; }
|
|
514
|
-
.pattern-tool { font:
|
|
515
|
-
.pattern-code { font:
|
|
516
|
-
-webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
|
|
554
|
+
.pattern-tool { font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); flex: none; }
|
|
555
|
+
.pattern-code { font: 13px/1.4 var(--mono); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
|
|
517
556
|
.pattern-body[open] .pattern-code { -webkit-line-clamp: unset; }
|
|
518
|
-
.pattern-
|
|
519
|
-
.pattern-meta { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 6px; flex-wrap: wrap; }
|
|
520
|
-
.pattern-detail { font-size: .84rem; padding: 4px 0 2px; }
|
|
557
|
+
.pattern-detail { font-size: 14px; }
|
|
521
558
|
.pattern-detail p { margin: 4px 0; }
|
|
522
|
-
.pattern-
|
|
523
|
-
.pattern-
|
|
524
|
-
.
|
|
525
|
-
|
|
526
|
-
.pattern-blocking > summary { cursor: pointer; font: 600 .9rem var(--display); }
|
|
559
|
+
.pattern-meta { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 6px; flex-wrap: wrap; }
|
|
560
|
+
.pattern-reach { font: 13px var(--mono); color: var(--muted); }
|
|
561
|
+
.pager { justify-content: space-between; }
|
|
562
|
+
|
|
527
563
|
.audit-list { list-style: none; padding: 0; margin: 10px 0; }
|
|
528
|
-
.audit-row { padding: 10px 0; border-
|
|
529
|
-
.audit-head { display: flex; gap: 8px; align-items:
|
|
530
|
-
.audit-
|
|
531
|
-
.
|
|
532
|
-
.
|
|
533
|
-
.
|
|
534
|
-
.
|
|
535
|
-
.
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
@media (max-width:
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
.
|
|
542
|
-
.
|
|
543
|
-
.
|
|
544
|
-
.
|
|
545
|
-
.
|
|
546
|
-
.
|
|
547
|
-
|
|
548
|
-
.station:last-child .wire { display: none; }
|
|
549
|
-
.station h2 { margin-top: 0; }
|
|
550
|
-
.pair { grid-template-columns: minmax(0, 1fr); }
|
|
551
|
-
}
|
|
552
|
-
@media (prefers-reduced-motion: reduce) {
|
|
553
|
-
html { scroll-behavior: auto; }
|
|
554
|
-
.station[data-live="1"] .wire::after, .dot { transition: none; }
|
|
564
|
+
.audit-row { padding: 10px 0; border-top: 1px solid var(--line); }
|
|
565
|
+
.audit-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
|
|
566
|
+
.audit-detail { font-size: 14px; margin: 4px 0 0; overflow-wrap: anywhere; color: var(--muted); }
|
|
567
|
+
.new-tag { font-size: 12px; font-weight: 700; color: var(--accent); }
|
|
568
|
+
dl.facts { margin: 0; }
|
|
569
|
+
dl.facts > div { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; }
|
|
570
|
+
dl.facts > div:first-child { border-top: 0; }
|
|
571
|
+
dl.facts dt { color: var(--muted); }
|
|
572
|
+
dl.facts dd { margin: 0; overflow-wrap: anywhere; }
|
|
573
|
+
|
|
574
|
+
@media (max-width: 860px) {
|
|
575
|
+
.shell { grid-template-columns: minmax(0, 1fr); gap: 16px; }
|
|
576
|
+
.side { position: static; flex-direction: row; overflow-x: auto; gap: 6px; padding-bottom: 6px; }
|
|
577
|
+
.side .group, .side .rule { display: none; }
|
|
578
|
+
.side a { white-space: nowrap; }
|
|
579
|
+
.pair, .pattern-tools { grid-template-columns: minmax(0, 1fr); }
|
|
580
|
+
.row, .check, .provider-row { grid-template-columns: minmax(0, 1fr); }
|
|
581
|
+
.row-side, .check-action { grid-column: 1; grid-row: auto; justify-content: flex-start; }
|
|
582
|
+
.check-action { order: 1; justify-self: start; }
|
|
583
|
+
dl.facts > div { grid-template-columns: minmax(0, 1fr); gap: 2px; }
|
|
555
584
|
}
|
|
556
585
|
</style>
|
|
557
586
|
</head>
|
|
558
587
|
<body>
|
|
559
|
-
<
|
|
560
|
-
<
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
<
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
<
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
<
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
<
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
588
|
+
<header class="top">
|
|
589
|
+
<div><h1>Smart Tool settings</h1><span class="where">__SETUP_ORIGIN__ · version <span id="app-version"></span></span></div>
|
|
590
|
+
<nav><a href="/projects">Projects and indexing →</a></nav>
|
|
591
|
+
</header>
|
|
592
|
+
<div class="shell">
|
|
593
|
+
<nav class="side" aria-label="Settings sections">
|
|
594
|
+
<a href="#overview" data-page="overview"><span>Overview</span><span class="count" data-count="overview" hidden></span></a>
|
|
595
|
+
<div class="group">Connect</div>
|
|
596
|
+
<a href="#agents" data-page="agents"><span>Agents</span><span class="count" data-count="agents" hidden></span></a>
|
|
597
|
+
<a href="#models" data-page="models"><span>Models</span><span class="count" data-count="models" hidden></span></a>
|
|
598
|
+
<a href="#web" data-page="web"><span>Web search</span><span class="count" data-count="web" hidden></span></a>
|
|
599
|
+
<div class="group">Behavior</div>
|
|
600
|
+
<a href="#rules" data-page="rules"><span>Agent rules</span><span class="count" data-count="rules" hidden></span></a>
|
|
601
|
+
<a href="#redirects" data-page="redirects"><span>Redirects</span><span class="count" data-count="redirects" hidden></span></a>
|
|
602
|
+
<div class="group">Maintenance</div>
|
|
603
|
+
<a href="#audit" data-page="audit"><span>Setup audit</span><span class="count" data-count="audit" hidden></span></a>
|
|
604
|
+
<a href="#startup" data-page="startup"><span>Startup</span><span class="count" data-count="startup" hidden></span></a>
|
|
605
|
+
<p class="rule">Choices apply as soon as you pick them. Typed values (addresses, keys, model names) are saved with the button next to them.</p>
|
|
606
|
+
</nav>
|
|
607
|
+
|
|
608
|
+
<main>
|
|
609
|
+
<section class="page" data-page="overview" aria-labelledby="h-overview">
|
|
610
|
+
<header class="page-head"><h2 id="h-overview" tabindex="-1">Overview</h2>
|
|
611
|
+
<p>Everything Smart Tool needs to work, checked on this machine. Anything that needs you comes first, with a button that takes you to the fix.</p></header>
|
|
612
|
+
<div class="summary-banner" id="overview-banner" data-tone="busy" role="status">Checking…</div>
|
|
613
|
+
<div class="card"><ul class="checklist" id="overview-list"></ul></div>
|
|
614
|
+
</section>
|
|
615
|
+
|
|
616
|
+
<section class="page" data-page="agents" aria-labelledby="h-agents" hidden>
|
|
617
|
+
<header class="page-head"><h2 id="h-agents" tabindex="-1">Agents</h2>
|
|
618
|
+
<p>Connect your coding agents to Smart Tool. Each agent needs two things: the connection (MCP server), which gives it smart_search, web_search and web_fetch, and the redirect hook, which sends its folder searches and web lookups to those tools.</p></header>
|
|
619
|
+
<div class="msg" id="agents-msg" role="status"></div>
|
|
620
|
+
<div id="agents-list"></div>
|
|
621
|
+
</section>
|
|
622
|
+
|
|
623
|
+
<section class="page" data-page="rules" aria-labelledby="h-rules" hidden>
|
|
624
|
+
<header class="page-head"><h2 id="h-rules" tabindex="-1">Agent rules</h2>
|
|
625
|
+
<p>How the hook treats your agents' tool calls. These apply to every connected agent on its next tool call; nothing needs reinstalling.</p></header>
|
|
626
|
+
<div class="card" id="rules-card"></div>
|
|
627
|
+
</section>
|
|
628
|
+
|
|
629
|
+
<section class="page" data-page="redirects" aria-labelledby="h-redirects" hidden>
|
|
630
|
+
<header class="page-head"><h2 id="h-redirects" tabindex="-1">Redirects</h2>
|
|
631
|
+
<p>What the hook did with your agents' native searches, and what the agent did next. Below, the block patterns a model proposed from calls the fixed rule let through.</p></header>
|
|
632
|
+
<div class="card" id="redirects-card"><p class="lede">Loading…</p></div>
|
|
633
|
+
<div class="card">
|
|
634
|
+
<h3>Block patterns</h3>
|
|
635
|
+
<p class="lede">The hook decides with a fixed rule: content searches over a project folder go to smart_search. A model reviews the calls the rule let through, afterwards and without delaying them, and proposes patterns. Each proposal shows how many logged calls it would have blocked. Nothing blocks until you accept it.</p>
|
|
636
|
+
<div class="msg" id="patterns-msg" role="status"></div>
|
|
637
|
+
<div id="patterns-list"></div>
|
|
638
|
+
</div>
|
|
639
|
+
</section>
|
|
640
|
+
|
|
641
|
+
<section class="page" data-page="models" aria-labelledby="h-models" hidden>
|
|
642
|
+
<header class="page-head"><h2 id="h-models" tabindex="-1">Models</h2>
|
|
643
|
+
<p>Smart Tool uses models for code search (embedding and rerank), for deciding where a search goes, and for web research. They come through a model gateway you connect here.</p></header>
|
|
644
|
+
<div class="card" id="gateway">
|
|
645
|
+
<div class="card-head"><h3>1. Model gateway</h3><span class="pill" id="gateway-pill" data-tone="busy">Checking</span></div>
|
|
646
|
+
<p class="lede">Where embedding, chat and rerank calls go. The OpenAI-compatible adapter covers OpenAI, OpenRouter, a LiteLLM proxy and Ollama. Other adapters go in as a .py file in the folder shown below.</p>
|
|
647
|
+
<div class="field">
|
|
587
648
|
<label for="gateway-adapter">Adapter</label>
|
|
588
649
|
<select id="gateway-adapter"></select>
|
|
589
650
|
<span class="hint mono" id="gateway-dir"></span>
|
|
@@ -591,184 +652,268 @@ _PAGE_TEMPLATE = """<!doctype html>
|
|
|
591
652
|
<div id="gateway-fields"></div>
|
|
592
653
|
<div class="msg error" id="gateway-errors" role="status" hidden></div>
|
|
593
654
|
<div class="actions">
|
|
594
|
-
<button type="button" id="gateway-save">Test and save</button>
|
|
595
|
-
<button type="button"
|
|
655
|
+
<button type="button" class="primary" id="gateway-save">Test and save</button>
|
|
656
|
+
<button type="button" id="gateway-clear">Disconnect</button>
|
|
596
657
|
</div>
|
|
597
658
|
<div class="msg" id="gateway-msg" role="status"></div>
|
|
598
|
-
</
|
|
659
|
+
</div>
|
|
599
660
|
|
|
600
|
-
<
|
|
601
|
-
<
|
|
602
|
-
<p class="lede">Any id
|
|
603
|
-
<
|
|
661
|
+
<div class="card" id="models-card">
|
|
662
|
+
<div class="card-head"><h3>2. Models</h3><span class="pill" id="models-pill" data-tone="busy">Checking</span></div>
|
|
663
|
+
<p class="lede">Any model id your gateway accepts. The gateway's catalog shows up as suggestions while you type.</p>
|
|
664
|
+
<p class="callout info" id="models-blocked" hidden><strong>Connect the gateway first.</strong> The catalog and the model choice open once the gateway answers.</p>
|
|
604
665
|
<div id="models-form" hidden>
|
|
605
|
-
<
|
|
606
|
-
<
|
|
607
|
-
<
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
</div>
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
<
|
|
617
|
-
|
|
618
|
-
<
|
|
619
|
-
</fieldset>
|
|
620
|
-
<fieldset>
|
|
621
|
-
<legend>Web research</legend>
|
|
622
|
-
<div class="field"><label for="sel-research">Iterative research model</label><input id="sel-research" list="dl-research" autocomplete="off" spellcheck="false"><datalist id="dl-research"></datalist>
|
|
623
|
-
<span class="hint">Used by web_search with depth=research. Empty uses the router model.</span></div>
|
|
624
|
-
<div class="pair">
|
|
625
|
-
<div class="field"><label for="num-research-iterations">Maximum rounds</label><input type="number" id="num-research-iterations" step="1"><span class="hint" id="research-iterations-hint"></span></div>
|
|
626
|
-
<div class="field"><label for="num-quick-timeout">Quick search time limit (s)</label><input type="number" id="num-quick-timeout" step="1"><span class="hint" id="quick-timeout-hint"></span></div>
|
|
666
|
+
<div class="pair">
|
|
667
|
+
<div class="field"><label for="sel-embedding">Embedding</label><span class="explain">Turns code into vectors for indexing and smart_search.</span><input id="sel-embedding" list="dl-embedding" autocomplete="off" spellcheck="false"><datalist id="dl-embedding"></datalist></div>
|
|
668
|
+
<div class="field"><label for="sel-rerank">Rerank (optional)</label><span class="explain">Reorders search results by relevance. Empty keeps the hybrid order.</span><input id="sel-rerank" list="dl-rerank" autocomplete="off" spellcheck="false"><datalist id="dl-rerank"></datalist></div>
|
|
669
|
+
</div>
|
|
670
|
+
<div class="pair">
|
|
671
|
+
<div class="field"><label for="sel-scope">Index classification</label><span class="explain">Decides scope, code or documentation, and languages while indexing. Runs once per project.</span><input id="sel-scope" list="dl-scope" autocomplete="off" spellcheck="false"><datalist id="dl-scope"></datalist></div>
|
|
672
|
+
<div class="field"><label for="sel-router">Router</label><span class="explain">Decides before each agent Grep, Read or Bash. Use a small model without reasoning: above 10 s routing turns off.</span><input id="sel-router" list="dl-router" autocomplete="off" spellcheck="false"><datalist id="dl-router"></datalist></div>
|
|
673
|
+
</div>
|
|
674
|
+
<div class="field"><label for="sel-research">Web research</label><span class="explain">Used by web_search with depth=research. Empty uses the router model.</span><input id="sel-research" list="dl-research" autocomplete="off" spellcheck="false"><datalist id="dl-research"></datalist></div>
|
|
675
|
+
<details class="more">
|
|
676
|
+
<summary>Advanced web research limits</summary>
|
|
677
|
+
<div class="pair" style="margin-top:12px">
|
|
678
|
+
<div class="field"><label for="num-research-iterations">Maximum research rounds</label><span class="explain">How many search rounds a research may run before answering.</span><input type="number" id="num-research-iterations" step="1"><span class="hint" id="research-iterations-hint"></span></div>
|
|
679
|
+
<div class="field"><label for="num-quick-timeout">Quick search time limit (s)</label><span class="explain">How long a quick web search waits for its sources.</span><input type="number" id="num-quick-timeout" step="1"><span class="hint" id="quick-timeout-hint"></span></div>
|
|
627
680
|
</div>
|
|
628
|
-
<div class="field"><label for="num-site-memory-threshold">
|
|
629
|
-
</
|
|
630
|
-
<div class="actions"><button type="button" id="btn-save-models">Save models</button></div>
|
|
681
|
+
<div class="field"><label for="num-site-memory-threshold">Per-site memory similarity</label><span class="explain">How close a new question must be to a remembered page of the same site to reuse it.</span><input type="number" id="num-site-memory-threshold" step="0.01"><span class="hint" id="site-memory-threshold-hint"></span></div>
|
|
682
|
+
</details>
|
|
683
|
+
<div class="actions"><button type="button" class="primary" id="btn-save-models">Save models</button></div>
|
|
631
684
|
<div class="msg" id="models-msg" role="status"></div>
|
|
632
685
|
</div>
|
|
633
|
-
</
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
<
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
</
|
|
644
|
-
|
|
645
|
-
<
|
|
646
|
-
<
|
|
647
|
-
<p class="lede">
|
|
648
|
-
<div
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
<
|
|
655
|
-
|
|
656
|
-
<div class="
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
<h2>Agents</h2>
|
|
661
|
-
<p class="lede">The Smart Tool MCP server and the hook that redirects Grep/Read/Bash to smart_search and WebSearch/WebFetch to web_search/web_fetch. In Claude Code the hook is a direct HTTP call to the daemon; in Codex, a thin command that forwards to the daemon. If the port changes, the daemon rewrites these URLs on its own.</p>
|
|
662
|
-
<div class="field"><label for="sel-hook-mode">Hook behavior</label>
|
|
663
|
-
<select id="sel-hook-mode">
|
|
664
|
-
<option value="redirect">Redirect: block the native tool and point to Smart Tool (default)</option>
|
|
665
|
-
<option value="advise">Advise only: let the native tool run and tell the agent what Smart Tool would do</option>
|
|
666
|
-
<option value="off">Off: no routing</option>
|
|
667
|
-
</select>
|
|
668
|
-
<span class="hint" id="hook-mode-hint">Applies to every client on the next tool call; nothing is reinstalled.</span></div>
|
|
669
|
-
<div class="actions"><button type="button" id="btn-save-hook-mode">Save behavior</button></div>
|
|
670
|
-
<div class="field" style="margin-top:16px"><label for="sel-doc-mode">Documentation on edit</label>
|
|
671
|
-
<select id="sel-doc-mode">
|
|
672
|
-
<option value="remind">Remind: the edit runs; the agent is told which touched functions lack a docstring (default)</option>
|
|
673
|
-
<option value="require">Require: an edit that leaves a touched function without a docstring is blocked until it adds one</option>
|
|
674
|
-
<option value="off">Off: no documentation checks</option>
|
|
675
|
-
</select>
|
|
676
|
-
<span class="hint">Only public functions the edit touches (private, nested and override functions are exempt, as in pydocstyle, eslint-plugin-jsdoc and Checkstyle). A documented function is mentioned again only when its signature changes; body-only edits stay silent.</span></div>
|
|
677
|
-
<div class="actions"><button type="button" id="btn-save-doc-mode">Save documentation</button></div>
|
|
678
|
-
<div class="field" style="margin-top:16px"><label for="sel-duplicate-mode">Duplicate functions on edit</label>
|
|
679
|
-
<select id="sel-duplicate-mode">
|
|
680
|
-
<option value="warn">Warn: the edit runs; the agent is told when a written function copies one already in the project (default)</option>
|
|
681
|
-
<option value="off">Off: no duplicate checks on edit</option>
|
|
682
|
-
</select>
|
|
683
|
-
<span class="hint">Compares functions the edit writes with the indexed code: identical bodies, and near-identical ones with only local names changed. Never blocks.</span></div>
|
|
684
|
-
<div class="actions"><button type="button" id="btn-save-duplicate-mode">Save duplicates</button></div>
|
|
685
|
-
<div class="field" style="margin-top:16px"><label for="sel-pattern-proposals">Block patterns proposed by a model</label>
|
|
686
|
-
<select id="sel-pattern-proposals">
|
|
687
|
-
<option value="on">On: searches the rule lets run are reviewed in the background and may become proposals (default)</option>
|
|
688
|
-
<option value="off">Off: no review</option>
|
|
689
|
-
</select>
|
|
690
|
-
<span class="hint">The hook decides with a fixed rule: content searches over a project folder go to smart_search. The scope model (else the router model) never delays a call: it reviews, afterwards, bulk reads the rule could not measure and proposes patterns, each checked against the logged calls. Nothing blocks until you accept it here.</span></div>
|
|
691
|
-
<div class="actions"><button type="button" id="btn-save-pattern-proposals">Save proposals setting</button></div>
|
|
692
|
-
<div id="patterns-list"></div>
|
|
693
|
-
<div class="msg" id="agents-msg" role="status"></div>
|
|
694
|
-
<div id="agents-list"></div>
|
|
695
|
-
</section>
|
|
686
|
+
</div>
|
|
687
|
+
|
|
688
|
+
<div class="card" id="local-models-card">
|
|
689
|
+
<div class="card-head"><h3>3. Local models</h3><span class="pill" id="local-pill" data-tone="busy">Checking</span></div>
|
|
690
|
+
<p class="lede">Embedding from the mcp-memory sidecar on this machine. Switching between gateway and local rebuilds the project indexes; going back to a model used before reuses its vector cache.</p>
|
|
691
|
+
<fieldset class="choice" id="local-models-choice"><legend>When to use the local model</legend></fieldset>
|
|
692
|
+
</div>
|
|
693
|
+
</section>
|
|
694
|
+
|
|
695
|
+
<section class="page" data-page="web" aria-labelledby="h-web" hidden>
|
|
696
|
+
<header class="page-head"><h2 id="h-web" tabindex="-1">Web search</h2>
|
|
697
|
+
<p>web_search asks several providers at once. All of them work without a key on their public free tier; add your own key only if you need more volume.</p></header>
|
|
698
|
+
<div class="card">
|
|
699
|
+
<h3>Providers</h3>
|
|
700
|
+
<p class="lede">A key is tested with a real search before it is saved, and is protected by DPAPI in this Windows profile.</p>
|
|
701
|
+
<div id="provider-list"><p class="lede">Loading…</p></div>
|
|
702
|
+
</div>
|
|
703
|
+
<div class="card">
|
|
704
|
+
<h3>Your contact (optional)</h3>
|
|
705
|
+
<p class="lede">Wikimedia asks tools to name a contact in their User-Agent. It stays on this machine and is sent only to the search APIs.</p>
|
|
706
|
+
<div class="field"><label for="contact-input">Email or website</label>
|
|
707
|
+
<input id="contact-input" autocomplete="off" spellcheck="false" placeholder="you@example.com or https://your.site">
|
|
708
|
+
<span class="hint mono" id="contact-hint"></span></div>
|
|
709
|
+
<div class="actions"><button type="button" class="primary" id="btn-save-contact">Save contact</button></div>
|
|
710
|
+
<div class="msg" id="contact-msg" role="status"></div>
|
|
711
|
+
</div>
|
|
712
|
+
</section>
|
|
696
713
|
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
<p
|
|
714
|
+
<section class="page" data-page="audit" aria-labelledby="h-audit" hidden>
|
|
715
|
+
<header class="page-head"><h2 id="h-audit" tabindex="-1">Setup audit</h2>
|
|
716
|
+
<p>What Claude Code and Codex load for a project, and where they collide: hooks deciding on the same tool at once, hooks or MCP servers that do not work, tools offered twice, skills and instructions one agent never sees. It runs on its own for the registered projects and never changes anything.</p></header>
|
|
717
|
+
<div class="card">
|
|
700
718
|
<div class="field"><label for="sel-audit-project">Project</label>
|
|
701
719
|
<select id="sel-audit-project"></select>
|
|
702
720
|
<span class="hint" id="audit-hint"></span></div>
|
|
703
|
-
<div class="actions"><button type="button" id="btn-audit-run">Run now</button></div>
|
|
721
|
+
<div class="actions"><button type="button" class="primary" id="btn-audit-run">Run now</button></div>
|
|
704
722
|
<div class="msg" id="audit-msg" role="status"></div>
|
|
705
723
|
<div id="audit-report"></div>
|
|
706
|
-
</
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
<
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
<
|
|
715
|
-
<div class="
|
|
716
|
-
<div class="
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
<
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
</
|
|
724
|
+
</div>
|
|
725
|
+
</section>
|
|
726
|
+
|
|
727
|
+
<section class="page" data-page="startup" aria-labelledby="h-startup" hidden>
|
|
728
|
+
<header class="page-head"><h2 id="h-startup" tabindex="-1">Startup</h2>
|
|
729
|
+
<p>The Smart Tool service runs in the background on this machine. Your agents talk to it at the address below.</p></header>
|
|
730
|
+
<div class="card">
|
|
731
|
+
<div class="card-head"><h3>Start with Windows</h3><span class="pill" id="autostart-pill" data-tone="busy">Checking</span></div>
|
|
732
|
+
<p class="lede">Starts Smart Tool when you sign in, so agents find it without you starting it by hand.</p>
|
|
733
|
+
<div class="actions"><button type="button" id="btn-autostart-toggle" disabled>Checking</button></div>
|
|
734
|
+
<div class="msg" id="autostart-msg" role="status"></div>
|
|
735
|
+
</div>
|
|
736
|
+
<div class="card">
|
|
737
|
+
<h3>This installation</h3>
|
|
738
|
+
<dl class="facts">
|
|
739
|
+
<div><dt>Version</dt><dd id="fact-version"></dd></div>
|
|
740
|
+
<div><dt>Service address</dt><dd class="mono">__SETUP_ORIGIN__</dd></div>
|
|
741
|
+
<div><dt>MCP endpoint</dt><dd class="mono">__SETUP_ORIGIN__/mcp</dd></div>
|
|
742
|
+
</dl>
|
|
743
|
+
</div>
|
|
744
|
+
</section>
|
|
745
|
+
</main>
|
|
746
|
+
</div>
|
|
724
747
|
<script>
|
|
725
748
|
const TOKEN = __SETUP_TOKEN__;
|
|
726
749
|
let status = __STATUS_JSON__;
|
|
727
750
|
const $ = (id) => document.getElementById(id);
|
|
751
|
+
const loaded = { integration: null, autostart: null, providers: null, audit: null };
|
|
752
|
+
const failed = {};
|
|
753
|
+
let serviceDown = false;
|
|
728
754
|
|
|
729
|
-
function
|
|
730
|
-
|
|
755
|
+
function node(tag, className, text) {
|
|
756
|
+
const el = document.createElement(tag);
|
|
757
|
+
if (className) el.className = className;
|
|
758
|
+
if (text !== undefined) el.textContent = text;
|
|
759
|
+
return el;
|
|
760
|
+
}
|
|
761
|
+
function button(label, className, onClick) {
|
|
762
|
+
const el = node("button", className, label);
|
|
763
|
+
el.type = "button";
|
|
764
|
+
if (onClick) el.addEventListener("click", onClick);
|
|
765
|
+
return el;
|
|
766
|
+
}
|
|
767
|
+
function pill(tone, label) {
|
|
768
|
+
const el = node("span", "pill", label);
|
|
769
|
+
el.dataset.tone = tone;
|
|
770
|
+
return el;
|
|
771
|
+
}
|
|
772
|
+
function plural(n, word) { return n + " " + word + (n === 1 ? "" : "s"); }
|
|
773
|
+
function setPill(id, tone, label) { const el = $(id); el.dataset.tone = tone; el.textContent = label; }
|
|
774
|
+
function setMsg(target, kind, text) {
|
|
775
|
+
const el = typeof target === "string" ? $(target) : target;
|
|
776
|
+
el.className = (el.dataset.base || "msg") + (kind ? " " + kind : "");
|
|
777
|
+
el.textContent = text;
|
|
778
|
+
}
|
|
731
779
|
async function post(path, body) {
|
|
732
780
|
const resp = await fetch(path, { method: "POST", headers: { "X-Setup-Token": TOKEN, "Content-Type": "application/json" }, body: JSON.stringify(body) });
|
|
733
781
|
const data = await resp.json().catch(() => ({}));
|
|
734
782
|
if (!resp.ok || data.error) throw new Error(data.error || `HTTP error ${resp.status}.`);
|
|
735
783
|
return data;
|
|
736
784
|
}
|
|
785
|
+
async function getJSON(path) {
|
|
786
|
+
const resp = await fetch(path);
|
|
787
|
+
const data = await resp.json().catch(() => ({}));
|
|
788
|
+
if (!resp.ok || data.error) throw new Error(data.error || `HTTP error ${resp.status}.`);
|
|
789
|
+
return data;
|
|
790
|
+
}
|
|
737
791
|
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
792
|
+
const PAGES = [...document.querySelectorAll("section.page")].map((section) => section.dataset.page);
|
|
793
|
+
function showPage(name, focus) {
|
|
794
|
+
if (!PAGES.includes(name)) name = "overview";
|
|
795
|
+
for (const section of document.querySelectorAll("section.page")) section.hidden = section.dataset.page !== name;
|
|
796
|
+
for (const link of document.querySelectorAll(".side a")) {
|
|
797
|
+
if (link.dataset.page === name) link.setAttribute("aria-current", "page"); else link.removeAttribute("aria-current");
|
|
798
|
+
}
|
|
799
|
+
if (focus) $("h-" + name).focus();
|
|
800
|
+
}
|
|
801
|
+
function go(page) {
|
|
802
|
+
if (location.hash === "#" + page) showPage(page, true); else location.hash = page;
|
|
803
|
+
}
|
|
804
|
+
window.addEventListener("hashchange", () => showPage(location.hash.slice(1), true));
|
|
805
|
+
showPage(location.hash.slice(1), false);
|
|
806
|
+
$("app-version").textContent = status.version;
|
|
807
|
+
$("fact-version").textContent = status.version;
|
|
808
|
+
|
|
809
|
+
function agentState(item) {
|
|
810
|
+
if (!item.mcp_url) return { tone: "bad", label: "Not connected", action: "Connect",
|
|
811
|
+
text: "The smart-tool MCP server is not registered in " + item.label + ", so it has no smart_search, web_search or web_fetch." };
|
|
812
|
+
if (item.hook_error) return { tone: "bad", label: "Hook unreadable", action: "Open",
|
|
813
|
+
text: "Could not read " + item.file + ": " + item.hook_error };
|
|
814
|
+
if (item.hook_state === "outdated") return { tone: "warn", label: "Hook outdated", action: "Update hook", hook: true,
|
|
815
|
+
text: "The redirect hook was written by an older Smart Tool. " + item.hook_changes.join(" ") };
|
|
816
|
+
if (item.hook_state === "missing") return { tone: "warn", label: "No hook", action: "Install hook", hook: true,
|
|
817
|
+
text: "Connected, but its folder searches and web lookups are not redirected to Smart Tool." };
|
|
818
|
+
return { tone: "ok", label: "Connected", action: "Open", text: "Connection and redirect hook are up to date." };
|
|
743
819
|
}
|
|
744
820
|
|
|
745
|
-
function
|
|
821
|
+
function overviewItems() {
|
|
822
|
+
const items = [];
|
|
746
823
|
const gw = status.gateway;
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
824
|
+
items.push(serviceDown
|
|
825
|
+
? { tone: "bad", label: "Not responding", title: "Smart Tool service", page: "startup", action: "Open", text: "The service stopped answering this page. Start Smart Tool again and reload." }
|
|
826
|
+
: { tone: "ok", label: "Running", title: "Smart Tool service", page: "startup", action: "Open",
|
|
827
|
+
text: "Answering at " + location.origin + "." + (loaded.autostart ? (loaded.autostart.installed ? " Starts with Windows." : " Not started with Windows.") : "") });
|
|
828
|
+
items.push(gw.status === "ready"
|
|
829
|
+
? { tone: "ok", label: "Connected", title: "Model gateway", page: "models", action: "Open", text: "Model calls go through " + gw.label + "." }
|
|
830
|
+
: { tone: "bad", label: "Not connected", title: "Model gateway", page: "models", action: "Connect", text: (gw.error || "No gateway configured.") + " Code search and routing need it." });
|
|
831
|
+
if (gw.status === "ready") items.push(status.models_status === "ready"
|
|
832
|
+
? { tone: "ok", label: "Ready", title: "Models", page: "models", action: "Open", text: [status.embedding_model, status.rerank_model].filter(Boolean).join(" · ") || "Ready." }
|
|
833
|
+
: { tone: "warn", label: "Choose models", title: "Models", page: "models", action: "Choose", text: status.models_message || "Some models are not chosen yet." });
|
|
834
|
+
const integration = loaded.integration;
|
|
835
|
+
if (failed.integration) items.push({ tone: "bad", label: "Unavailable", title: "Agents", page: "agents", action: "Open", text: failed.integration });
|
|
836
|
+
else if (!integration) items.push({ tone: "busy", label: "Checking", title: "Agents", page: "agents", action: "Open", text: "Reading Claude Code and Codex settings…" });
|
|
837
|
+
else {
|
|
838
|
+
for (const item of integration.clients) {
|
|
839
|
+
const state = agentState(item);
|
|
840
|
+
items.push({ ...state, title: item.label, page: "agents", run: state.hook ? () => { go("agents"); hookControls[item.client](); } : null });
|
|
841
|
+
}
|
|
842
|
+
for (const rule of RULES) {
|
|
843
|
+
if (integration[rule.key + "_error"]) items.push({ tone: "bad", label: "Unreadable", title: rule.title, page: "rules", action: "Open", text: integration[rule.key + "_error"] });
|
|
844
|
+
}
|
|
845
|
+
if (integration.hook_mode === "off") items.push({ tone: "warn", label: "Off", title: "Redirects", page: "rules", action: "Turn on", text: "The hook lets every native search run; agents are not sent to Smart Tool." });
|
|
846
|
+
const waiting = integration.block_patterns.proposals.length;
|
|
847
|
+
if (integration.block_patterns.error) items.push({ tone: "bad", label: "Unreadable", title: "Block patterns", page: "redirects", action: "Open", text: integration.block_patterns.error });
|
|
848
|
+
else if (waiting) items.push({ tone: "warn", label: waiting + " waiting", title: "Block patterns", page: "redirects", action: "Review", text: "A model proposed " + plural(waiting, "pattern") + " to block. Nothing blocks until you accept." });
|
|
849
|
+
}
|
|
850
|
+
if (failed.providers) items.push({ tone: "bad", label: "Unavailable", title: "Web search", page: "web", action: "Open", text: failed.providers });
|
|
851
|
+
else if (loaded.providers) {
|
|
852
|
+
const list = Object.values(loaded.providers.providers);
|
|
853
|
+
const unreadable = list.filter((info) => info.status === "unreadable");
|
|
854
|
+
const keyed = list.filter((info) => info.status === "configured").length;
|
|
855
|
+
items.push(unreadable.length
|
|
856
|
+
? { tone: "bad", label: "Key unreadable", title: "Web search", page: "web", action: "Fix", text: unreadable.map((info) => info.label).join(", ") + ": the saved key cannot be opened in this Windows profile. Paste it again." }
|
|
857
|
+
: { tone: "ok", label: "Ready", title: "Web search", page: "web", action: "Open", text: plural(list.length, "provider") + " on their free tier" + (keyed ? ", " + keyed + " with your key." : "; no key needed.") });
|
|
858
|
+
}
|
|
859
|
+
if (failed.audit) items.push({ tone: "bad", label: "Unavailable", title: "Setup audit", page: "audit", action: "Open", text: failed.audit });
|
|
860
|
+
else if (loaded.audit && loaded.audit.projects.length) {
|
|
861
|
+
const errors = Object.values(loaded.audit.index).reduce((sum, entry) => sum + entry.summary.error, 0);
|
|
862
|
+
items.push(errors
|
|
863
|
+
? { tone: "warn", label: plural(errors, "problem"), title: "Setup audit", page: "audit", action: "See report", text: "Hooks or MCP servers that collide or do not work in your registered projects." }
|
|
864
|
+
: { tone: "ok", label: "Clean", title: "Setup audit", page: "audit", action: "Open", text: "No collision or broken piece in the audited projects." });
|
|
865
|
+
}
|
|
866
|
+
const rank = { bad: 0, warn: 1, busy: 2, idle: 3, ok: 4 };
|
|
867
|
+
return items.map((item, index) => ({ ...item, index })).sort((a, b) => rank[a.tone] - rank[b.tone] || a.index - b.index);
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
function renderOverview() {
|
|
871
|
+
const items = overviewItems();
|
|
872
|
+
const list = $("overview-list");
|
|
873
|
+
list.replaceChildren();
|
|
874
|
+
for (const item of items) {
|
|
875
|
+
const row = node("li", "check");
|
|
876
|
+
const title = node("div", "check-title");
|
|
877
|
+
title.append(pill(item.tone, item.label), node("span", "", item.title));
|
|
878
|
+
const action = button(item.action, item.tone === "bad" || item.tone === "warn" ? "primary" : "", item.run || (() => go(item.page)));
|
|
879
|
+
action.setAttribute("aria-label", item.action + ": " + item.title);
|
|
880
|
+
const side = node("div", "check-action");
|
|
881
|
+
side.appendChild(action);
|
|
882
|
+
row.append(title, side, node("div", "check-text", item.text));
|
|
883
|
+
list.appendChild(row);
|
|
884
|
+
}
|
|
885
|
+
const problems = items.filter((item) => item.tone === "bad" || item.tone === "warn");
|
|
886
|
+
const pending = items.some((item) => item.tone === "busy");
|
|
887
|
+
const banner = $("overview-banner");
|
|
888
|
+
banner.dataset.tone = problems.some((item) => item.tone === "bad") ? "bad" : problems.length ? "warn" : pending ? "busy" : "ok";
|
|
889
|
+
banner.textContent = problems.length ? problems.length + (problems.length === 1 ? " thing needs" : " things need") + " your attention."
|
|
890
|
+
: pending ? "Checking…" : "Everything is working.";
|
|
891
|
+
const counts = {};
|
|
892
|
+
for (const item of problems) {
|
|
893
|
+
const entry = counts[item.page] || (counts[item.page] = { count: 0, bad: false });
|
|
894
|
+
entry.count += 1;
|
|
895
|
+
entry.bad = entry.bad || item.tone === "bad";
|
|
896
|
+
}
|
|
897
|
+
counts.overview = { count: problems.length, bad: problems.some((item) => item.tone === "bad") };
|
|
898
|
+
for (const badge of document.querySelectorAll(".side .count")) {
|
|
899
|
+
const entry = counts[badge.dataset.count];
|
|
900
|
+
badge.hidden = !entry;
|
|
901
|
+
badge.textContent = entry ? entry.count : "";
|
|
902
|
+
badge.dataset.tone = entry && entry.bad ? "bad" : "warn";
|
|
903
|
+
badge.title = entry ? plural(entry.count, "item") + (entry.count === 1 ? " needs" : " need") + " attention" : "";
|
|
904
|
+
}
|
|
759
905
|
}
|
|
760
906
|
|
|
907
|
+
let gatewaySignature = null;
|
|
761
908
|
function renderGateway() {
|
|
762
909
|
const gw = status.gateway;
|
|
763
910
|
const ready = gw.status === "ready";
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
el.textContent = ready ? "Connected through " + gw.label : (gw.error || "Gateway unavailable");
|
|
911
|
+
setPill("gateway-pill", ready ? "ok" : "bad", ready ? "Connected through " + gw.label : "Not connected");
|
|
912
|
+
if (!ready) setMsg("gateway-msg", "error", gw.error || "Gateway unavailable.");
|
|
767
913
|
$("gateway-dir").textContent = "Your adapters: " + gw.dir;
|
|
768
914
|
$("gateway-errors").hidden = !gw.errors.length;
|
|
769
915
|
$("gateway-errors").textContent = gw.errors.length ? "Adapters that failed to load: " + gw.errors.join(" · ") : "";
|
|
770
916
|
const select = $("gateway-adapter");
|
|
771
|
-
// Redraw only when the adapters or their stored state change: the 15 s refresh must not wipe what is being typed.
|
|
772
917
|
const signature = JSON.stringify([gw.selected, gw.adapters]);
|
|
773
918
|
if (signature !== gatewaySignature && document.activeElement !== select && !select.dataset.touched) {
|
|
774
919
|
gatewaySignature = signature;
|
|
@@ -779,39 +924,40 @@ function renderGateway() {
|
|
|
779
924
|
$("gateway-clear").disabled = !gw.selected;
|
|
780
925
|
$("models-blocked").hidden = ready;
|
|
781
926
|
$("models-form").hidden = !ready;
|
|
927
|
+
if (!ready) setPill("models-pill", "idle", "Waiting for the gateway");
|
|
928
|
+
else if (status.models_status === "ready") setPill("models-pill", "ok", "Ready");
|
|
929
|
+
else setPill("models-pill", "warn", "Choose models");
|
|
782
930
|
}
|
|
783
|
-
|
|
784
|
-
let gatewaySignature = null;
|
|
785
931
|
function renderGatewayFields() {
|
|
786
932
|
const adapter = status.gateway.adapters.find((a) => a.name === $("gateway-adapter").value);
|
|
787
933
|
const box = $("gateway-fields");
|
|
788
934
|
box.replaceChildren();
|
|
789
935
|
for (const field of (adapter || { fields: [] }).fields) {
|
|
790
|
-
const wrap =
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
936
|
+
const wrap = node("div", "field");
|
|
937
|
+
const input = node("input");
|
|
938
|
+
input.type = "text";
|
|
939
|
+
input.autocomplete = "off";
|
|
940
|
+
input.spellcheck = false;
|
|
794
941
|
input.id = "gateway-field-" + field.name;
|
|
795
|
-
|
|
796
|
-
|
|
942
|
+
const label = node("label", "", field.label + (field.required ? "" : " (optional)"));
|
|
943
|
+
label.htmlFor = input.id;
|
|
944
|
+
const hint = node("span", "hint");
|
|
797
945
|
input.dataset.field = field.name;
|
|
798
946
|
input.dataset.secret = field.secret ? "1" : "";
|
|
799
947
|
if (field.secret) {
|
|
800
948
|
input.type = "password";
|
|
801
949
|
input.autocomplete = "new-password";
|
|
802
950
|
input.placeholder = field.state === "configured" ? "Saved · paste another to replace" : "";
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
if (field.state === "configured") {
|
|
806
|
-
const remove = document.createElement("button");
|
|
807
|
-
remove.type = "button"; remove.className = "quiet"; remove.textContent = "Remove";
|
|
808
|
-
remove.addEventListener("click", () => saveGateway({ adapter: adapter.name, remove_secret: field.name }));
|
|
809
|
-
wrap.appendChild(remove);
|
|
810
|
-
}
|
|
951
|
+
hint.textContent = (field.state === "unreadable" ? "The saved value cannot be opened in this Windows profile; paste it again. " : "")
|
|
952
|
+
+ (field.hint || "") + " Protected by DPAPI.";
|
|
811
953
|
} else {
|
|
812
954
|
input.value = field.value || "";
|
|
813
955
|
input.placeholder = field.placeholder || "";
|
|
814
|
-
|
|
956
|
+
hint.textContent = field.hint || "";
|
|
957
|
+
}
|
|
958
|
+
wrap.append(label, input, hint);
|
|
959
|
+
if (field.secret && field.state === "configured") {
|
|
960
|
+
wrap.appendChild(button("Remove saved value", "small", () => saveGateway({ adapter: adapter.name, remove_secret: field.name })));
|
|
815
961
|
}
|
|
816
962
|
box.appendChild(wrap);
|
|
817
963
|
}
|
|
@@ -825,22 +971,18 @@ function gatewayValues() {
|
|
|
825
971
|
return values;
|
|
826
972
|
}
|
|
827
973
|
$("gateway-adapter").addEventListener("change", () => { $("gateway-adapter").dataset.touched = "1"; renderGatewayFields(); });
|
|
828
|
-
|
|
829
|
-
function render() { renderPath(); renderGateway(); }
|
|
830
|
-
render();
|
|
831
|
-
requestAnimationFrame(() => requestAnimationFrame(() => document.body.classList.add("ready")));
|
|
832
|
-
|
|
833
974
|
async function saveGateway(body) {
|
|
834
975
|
const buttons = [$("gateway-save"), $("gateway-clear")];
|
|
835
976
|
buttons.forEach((b) => b.disabled = true);
|
|
836
|
-
setMsg("gateway-msg", "", body.adapter ? "Testing…" : "Disconnecting…");
|
|
977
|
+
setMsg("gateway-msg", "", body.adapter ? "Testing the connection…" : "Disconnecting…");
|
|
837
978
|
try {
|
|
838
979
|
const data = await post("/setup/gateway", body);
|
|
839
980
|
status.gateway = data.gateway;
|
|
840
981
|
delete $("gateway-adapter").dataset.touched;
|
|
841
982
|
gatewaySignature = null;
|
|
842
983
|
setMsg("gateway-msg", data.gateway.status === "ready" ? "ok" : "warn",
|
|
843
|
-
body.adapter ? "
|
|
984
|
+
body.adapter ? (data.gateway.status === "ready" ? "Saved. The gateway answered." : "Saved, but the gateway does not answer: " + (data.gateway.error || "no reason given."))
|
|
985
|
+
: "Gateway disconnected.");
|
|
844
986
|
await refreshStatus(true);
|
|
845
987
|
} catch (error) {
|
|
846
988
|
setMsg("gateway-msg", "error", error.message);
|
|
@@ -852,44 +994,7 @@ async function saveGateway(body) {
|
|
|
852
994
|
$("gateway-save").addEventListener("click", () => saveGateway({ adapter: $("gateway-adapter").value, values: gatewayValues() }));
|
|
853
995
|
$("gateway-clear").addEventListener("click", () => saveGateway({ adapter: "" }));
|
|
854
996
|
|
|
855
|
-
|
|
856
|
-
function renderAutostart() {
|
|
857
|
-
const el = $("autostart-status");
|
|
858
|
-
el.dataset.state = autostartState.installed ? "ok" : "warn";
|
|
859
|
-
el.textContent = autostartState.installed ? `On via ${autostartState.method === "task" ? "Scheduled Task" : "Startup folder"}` : "Off";
|
|
860
|
-
$("st-daemon-verdict").textContent = autostartState.installed ? "Responding · starts with Windows" : "Responding · manual start";
|
|
861
|
-
const btn = $("btn-autostart-toggle");
|
|
862
|
-
btn.disabled = false;
|
|
863
|
-
btn.textContent = autostartState.installed ? "Turn off automatic start" : "Turn on automatic start";
|
|
864
|
-
}
|
|
865
|
-
async function loadAutostart() {
|
|
866
|
-
try {
|
|
867
|
-
const resp = await fetch("/setup/autostart");
|
|
868
|
-
autostartState = await resp.json();
|
|
869
|
-
renderAutostart();
|
|
870
|
-
} catch (error) {
|
|
871
|
-
$("autostart-status").dataset.state = "bad";
|
|
872
|
-
$("autostart-status").textContent = "Status unavailable";
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
loadAutostart();
|
|
876
|
-
$("btn-autostart-toggle").addEventListener("click", async () => {
|
|
877
|
-
const action = autostartState.installed ? "remove" : "install";
|
|
878
|
-
$("btn-autostart-toggle").disabled = true;
|
|
879
|
-
setMsg("autostart-msg", "", action === "install" ? "Turning on…" : "Turning off…");
|
|
880
|
-
try {
|
|
881
|
-
const data = await post("/setup/autostart", { action });
|
|
882
|
-
setMsg("autostart-msg", "ok", action === "install"
|
|
883
|
-
? (data.method === "task" ? "Turned on via Scheduled Task." : `Turned on via the Startup folder; the Scheduled Task was refused: ${data.fallback_reason || "no reason given"}.`)
|
|
884
|
-
: "Turned off.");
|
|
885
|
-
await loadAutostart();
|
|
886
|
-
} catch (error) {
|
|
887
|
-
setMsg("autostart-msg", "error", error.message);
|
|
888
|
-
$("btn-autostart-toggle").disabled = false;
|
|
889
|
-
}
|
|
890
|
-
});
|
|
891
|
-
|
|
892
|
-
function fillSelect(input, options, current) {
|
|
997
|
+
function fillSuggestions(input, options, current) {
|
|
893
998
|
$(input.getAttribute("list")).replaceChildren(...options.map((opt) => new Option(opt, opt)));
|
|
894
999
|
input.value = current || "";
|
|
895
1000
|
}
|
|
@@ -902,14 +1007,12 @@ function fillNumber(id, hintId, range, current, recommended, unit) {
|
|
|
902
1007
|
let modelsLoaded = false;
|
|
903
1008
|
async function loadModels() {
|
|
904
1009
|
try {
|
|
905
|
-
const
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
fillSelect($("sel-embedding"), data.embedding, data.current.embedding_model);
|
|
912
|
-
fillSelect($("sel-rerank"), data.rerank, data.current.rerank_model);
|
|
1010
|
+
const data = await getJSON("/setup/models");
|
|
1011
|
+
fillSuggestions($("sel-router"), data.chat_lightweight.length ? data.chat_lightweight : data.chat, data.current.router_model);
|
|
1012
|
+
fillSuggestions($("sel-scope"), data.chat, data.current.scope_model);
|
|
1013
|
+
fillSuggestions($("sel-research"), data.chat, data.current.research_model);
|
|
1014
|
+
fillSuggestions($("sel-embedding"), data.embedding, data.current.embedding_model);
|
|
1015
|
+
fillSuggestions($("sel-rerank"), data.rerank, data.current.rerank_model);
|
|
913
1016
|
fillNumber("num-research-iterations", "research-iterations-hint", data.ranges.research_max_iterations, data.current.research_max_iterations, data.recommended.research_max_iterations, "");
|
|
914
1017
|
fillNumber("num-quick-timeout", "quick-timeout-hint", data.ranges.quick_search_timeout_s, data.current.quick_search_timeout_s, data.recommended.quick_search_timeout_s, " s");
|
|
915
1018
|
fillNumber("num-site-memory-threshold", "site-memory-threshold-hint", data.ranges.site_memory_similarity_threshold, data.current.site_memory_similarity_threshold, data.recommended.site_memory_similarity_threshold, "");
|
|
@@ -919,8 +1022,6 @@ async function loadModels() {
|
|
|
919
1022
|
setMsg("models-msg", "error", "Could not read the gateway catalog: " + error.message);
|
|
920
1023
|
}
|
|
921
1024
|
}
|
|
922
|
-
if (status.gateway.status === "ready") loadModels();
|
|
923
|
-
|
|
924
1025
|
$("btn-save-models").addEventListener("click", async () => {
|
|
925
1026
|
if (!modelsLoaded) { setMsg("models-msg", "error", "The catalog has not loaded yet; nothing was saved."); return; }
|
|
926
1027
|
setMsg("models-msg", "", "Saving…");
|
|
@@ -945,140 +1046,318 @@ async function refreshStatus(force) {
|
|
|
945
1046
|
const next = await resp.json();
|
|
946
1047
|
const reload = next.gateway.status === "ready" && (force || status.gateway.status !== "ready");
|
|
947
1048
|
status = next;
|
|
948
|
-
|
|
1049
|
+
serviceDown = false;
|
|
1050
|
+
renderGateway();
|
|
949
1051
|
if (reload && !modelsLoaded) loadModels();
|
|
950
1052
|
} catch (error) {
|
|
951
|
-
|
|
952
|
-
station("st-daemon", "bad", false, true);
|
|
1053
|
+
serviceDown = true;
|
|
953
1054
|
}
|
|
1055
|
+
renderOverview();
|
|
954
1056
|
}
|
|
955
|
-
setInterval(refreshStatus, 15000);
|
|
956
1057
|
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
const
|
|
960
|
-
const
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
1058
|
+
function choiceGroup(fieldset, name, options, current, onPick) {
|
|
1059
|
+
for (const [value, title, text, recommended] of options) {
|
|
1060
|
+
const option = node("label", "option");
|
|
1061
|
+
const radio = node("input");
|
|
1062
|
+
radio.type = "radio";
|
|
1063
|
+
radio.name = name;
|
|
1064
|
+
radio.value = value;
|
|
1065
|
+
radio.checked = value === current;
|
|
1066
|
+
radio.addEventListener("change", () => { if (radio.checked) onPick(value); });
|
|
1067
|
+
const head = node("span", "option-title", title);
|
|
1068
|
+
if (recommended) head.appendChild(node("span", "tag", "Recommended"));
|
|
1069
|
+
option.append(radio, head, node("span", "option-text", text));
|
|
1070
|
+
fieldset.appendChild(option);
|
|
968
1071
|
}
|
|
1072
|
+
const saved = node("div", "saved msg");
|
|
1073
|
+
saved.dataset.base = "saved msg";
|
|
1074
|
+
saved.setAttribute("role", "status");
|
|
1075
|
+
fieldset.appendChild(saved);
|
|
1076
|
+
return saved;
|
|
969
1077
|
}
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
1078
|
+
function checkRadio(name, value) {
|
|
1079
|
+
for (const radio of document.querySelectorAll(`input[name="${name}"]`)) radio.checked = radio.value === value;
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
const LOCAL_OPTIONS = [
|
|
1083
|
+
["fallback", "Only as a fallback", "Use the local model only when the gateway does not have the embedding model.", true],
|
|
1084
|
+
["prefer", "Prefer local", "Use the local model even when the gateway has it; your code vectors stay on this machine."],
|
|
1085
|
+
["off", "Never", "Always use the gateway."],
|
|
1086
|
+
];
|
|
1087
|
+
let localMode = null;
|
|
1088
|
+
const localSaved = choiceGroup($("local-models-choice"), "local_models", LOCAL_OPTIONS, null, async (mode) => {
|
|
1089
|
+
setMsg(localSaved, "", "Saving…");
|
|
973
1090
|
try {
|
|
974
|
-
await post("/setup/local-models", { mode
|
|
975
|
-
|
|
976
|
-
|
|
1091
|
+
await post("/setup/local-models", { mode });
|
|
1092
|
+
localMode = mode;
|
|
1093
|
+
setMsg(localSaved, "ok", "Saved. The indexes adjust on the next search or check.");
|
|
977
1094
|
} catch (error) {
|
|
978
|
-
|
|
1095
|
+
checkRadio("local_models", localMode);
|
|
1096
|
+
setMsg(localSaved, "error", error.message);
|
|
979
1097
|
}
|
|
980
1098
|
});
|
|
1099
|
+
async function loadLocalModels() {
|
|
1100
|
+
try {
|
|
1101
|
+
const data = await getJSON("/setup/local-models");
|
|
1102
|
+
localMode = data.mode;
|
|
1103
|
+
checkRadio("local_models", data.mode);
|
|
1104
|
+
if (!data.sidecar.configured) setPill("local-pill", "idle", "No sidecar on this machine");
|
|
1105
|
+
else if (data.sidecar.embedding_model) setPill("local-pill", "ok", "Sidecar answering: " + data.sidecar.embedding_model);
|
|
1106
|
+
else setPill("local-pill", "warn", "Sidecar not answering (" + data.sidecar.url + ")");
|
|
1107
|
+
} catch (error) {
|
|
1108
|
+
setPill("local-pill", "bad", "Status unavailable");
|
|
1109
|
+
setMsg(localSaved, "error", error.message);
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
const RULES = [
|
|
1114
|
+
{ key: "hook_mode", title: "Redirect behavior", applies: "Applies on the next tool call.",
|
|
1115
|
+
intro: "What the hook does when an agent reaches for a native search or web tool that Smart Tool covers.",
|
|
1116
|
+
options: [["redirect", "Redirect", "Stop the native tool and tell the agent which Smart Tool call to make instead.", true],
|
|
1117
|
+
["advise", "Advise only", "Let the native tool run and tell the agent what Smart Tool would have done."],
|
|
1118
|
+
["off", "Off", "No routing; agents use their native tools as usual."]] },
|
|
1119
|
+
{ key: "doc_mode", title: "Documentation on edit", applies: "Applies on the next edit.",
|
|
1120
|
+
intro: "Checks the public functions an edit touches. Private, nested and override functions are exempt, as in pydocstyle, eslint-plugin-jsdoc and Checkstyle. A documented function comes up again only when its signature changes.",
|
|
1121
|
+
options: [["remind", "Remind", "The edit runs; the agent is told which touched functions lack a docstring.", true],
|
|
1122
|
+
["require", "Require", "An edit that leaves a touched function without a docstring is blocked until it adds one."],
|
|
1123
|
+
["off", "Off", "No documentation checks."]] },
|
|
1124
|
+
{ key: "duplicate_mode", title: "Duplicate functions on edit", applies: "Applies on the next edit.",
|
|
1125
|
+
intro: "Compares the functions an edit writes with the indexed code: identical bodies, and near-identical ones with only local names changed. It never blocks.",
|
|
1126
|
+
options: [["warn", "Warn", "The edit runs; the agent is told when a function copies one already in the project.", true],
|
|
1127
|
+
["off", "Off", "No duplicate checks."]] },
|
|
1128
|
+
{ key: "pattern_proposals", title: "Block patterns proposed by a model", applies: "Applies to the next review.",
|
|
1129
|
+
intro: "Afterwards, never delaying a call, the scope model (else the router model) reviews searches the fixed rule let through and may propose block patterns. Nothing blocks until you accept it on the Redirects page.",
|
|
1130
|
+
options: [["on", "On", "Review in the background and list proposals for you.", true],
|
|
1131
|
+
["off", "Off", "No review and no proposals."]] },
|
|
1132
|
+
];
|
|
1133
|
+
function renderRules() {
|
|
1134
|
+
const card = $("rules-card");
|
|
1135
|
+
if (card.dataset.built) {
|
|
1136
|
+
for (const rule of RULES) checkRadio(rule.key, loaded.integration[rule.key]);
|
|
1137
|
+
return;
|
|
1138
|
+
}
|
|
1139
|
+
card.dataset.built = "1";
|
|
1140
|
+
card.replaceChildren();
|
|
1141
|
+
for (const rule of RULES) {
|
|
1142
|
+
const fieldset = node("fieldset", "choice");
|
|
1143
|
+
fieldset.appendChild(node("legend", "", rule.title));
|
|
1144
|
+
fieldset.appendChild(node("p", "choice-intro", rule.intro));
|
|
1145
|
+
const saved = choiceGroup(fieldset, rule.key, rule.options, loaded.integration[rule.key], async (mode) => {
|
|
1146
|
+
setMsg(saved, "", "Saving…");
|
|
1147
|
+
try {
|
|
1148
|
+
await post("/setup/integration", { action: rule.key, mode });
|
|
1149
|
+
loaded.integration[rule.key] = mode;
|
|
1150
|
+
loaded.integration[rule.key + "_error"] = "";
|
|
1151
|
+
setMsg(saved, "ok", "Saved. " + rule.applies);
|
|
1152
|
+
renderOverview();
|
|
1153
|
+
} catch (error) {
|
|
1154
|
+
checkRadio(rule.key, loaded.integration[rule.key]);
|
|
1155
|
+
setMsg(saved, "error", error.message);
|
|
1156
|
+
}
|
|
1157
|
+
});
|
|
1158
|
+
if (loaded.integration[rule.key + "_error"]) setMsg(saved, "error", loaded.integration[rule.key + "_error"]);
|
|
1159
|
+
card.appendChild(fieldset);
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
981
1162
|
|
|
982
|
-
function
|
|
983
|
-
if (item.browser_control_error) return "Browser control status unreadable: " + item.browser_control_error;
|
|
1163
|
+
function browserState(item) {
|
|
1164
|
+
if (item.browser_control_error) return ["bad", "Unreadable", "Browser control status unreadable: " + item.browser_control_error];
|
|
984
1165
|
const state = item.browser_control || {};
|
|
985
|
-
if (state.state === "registered") return "
|
|
986
|
-
if (state.state === "kept") return "
|
|
987
|
-
if (state.state === "undenied") return "Browser control is registered without its safety rule: " + state.reason;
|
|
988
|
-
if (state.state === "unavailable") return "
|
|
989
|
-
return "
|
|
1166
|
+
if (state.state === "registered") return ["ok", "On", "Agents can open pages in an isolated, headless Chromium through the Playwright MCP server."];
|
|
1167
|
+
if (state.state === "kept") return ["ok", "Your own server", "Your own playwright MCP server is kept as it is."];
|
|
1168
|
+
if (state.state === "undenied") return ["bad", "Safety rule missing", "Browser control is registered without its safety rule: " + state.reason];
|
|
1169
|
+
if (state.state === "unavailable") return ["idle", "Unavailable", "Not available on this machine (" + state.reason + "). Pages are still read by web_fetch."];
|
|
1170
|
+
return ["idle", "Not set up", "Set up together with the connection."];
|
|
990
1171
|
}
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1172
|
+
const hookControls = {};
|
|
1173
|
+
function row(titleText, pillEl, text) {
|
|
1174
|
+
const el = node("div", "row");
|
|
1175
|
+
const title = node("div", "row-title");
|
|
1176
|
+
title.append(node("span", "", titleText), pillEl);
|
|
1177
|
+
const side = node("div", "row-side");
|
|
1178
|
+
const body = node("div", "row-text", text);
|
|
1179
|
+
el.append(title, side, body);
|
|
1180
|
+
return { el, side, body };
|
|
1181
|
+
}
|
|
1182
|
+
function agentCard(item) {
|
|
1183
|
+
const card = node("article", "card");
|
|
1184
|
+
const state = agentState(item);
|
|
1185
|
+
const head = node("div", "card-head");
|
|
1186
|
+
head.append(node("h3", "", item.label), pill(state.tone, state.label));
|
|
1187
|
+
const msg = node("div", "msg");
|
|
1188
|
+
msg.setAttribute("role", "status");
|
|
1189
|
+
|
|
1190
|
+
const mcp = row("Connection (MCP server)", item.mcp_url ? pill("ok", "Registered") : pill("bad", "Not registered"),
|
|
1191
|
+
item.mcp_url ? "Registered at " + item.mcp_url + ". Gives the agent smart_search, web_search and web_fetch."
|
|
1192
|
+
: "Not registered. Without it the agent has no smart_search, web_search or web_fetch.");
|
|
1193
|
+
if (!item.mcp_url) {
|
|
1194
|
+
const register = button("Connect", "primary", async () => {
|
|
1195
|
+
register.disabled = true;
|
|
1196
|
+
setMsg(msg, "", "Registering the MCP server in " + item.label + "…");
|
|
1197
|
+
try {
|
|
1198
|
+
const result = await post("/setup/integration", { client: item.client, action: "register_mcp" });
|
|
1199
|
+
await loadIntegration();
|
|
1200
|
+
setMsg(agentMsg(item.client), "ok", "Registered with: " + result.command + ". " + browserState({ browser_control: result.browser_control })[2]
|
|
1201
|
+
+ " Reconnect open " + item.label + " sessions (/mcp) to see the tools.");
|
|
1202
|
+
} catch (error) {
|
|
1203
|
+
setMsg(msg, "error", error.message);
|
|
1204
|
+
register.disabled = false;
|
|
1205
|
+
}
|
|
1206
|
+
});
|
|
1207
|
+
mcp.side.appendChild(register);
|
|
1208
|
+
const manual = node("details", "more row-more");
|
|
1209
|
+
manual.append(node("summary", "", "Or run it yourself in a terminal"), node("pre", "code", item.register_command));
|
|
1210
|
+
mcp.el.appendChild(manual);
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
const hookPill = item.hook_error ? pill("bad", "Unreadable") : item.hook_state === "current" ? pill("ok", "Up to date")
|
|
1214
|
+
: item.hook_state === "outdated" ? pill("warn", "Outdated") : pill("warn", "Not installed");
|
|
1215
|
+
const hook = row("Redirect hook", hookPill, item.hook_error ? "Could not read " + item.file + ": " + item.hook_error
|
|
1216
|
+
: "Runs before the agent's own search and web tools: folder searches go to smart_search, web lookups to web_search and web_fetch, so the agent reads less. It lives in " + item.file + ".");
|
|
1217
|
+
if (item.hook_state === "outdated") {
|
|
1218
|
+
const why = node("div", "callout");
|
|
1219
|
+
why.append(node("strong", "", "Why update: "), document.createTextNode("this entry was written by an older Smart Tool version."));
|
|
1220
|
+
const list = node("ul");
|
|
1221
|
+
for (const change of item.hook_changes) list.appendChild(node("li", "", change));
|
|
1222
|
+
why.append(list, node("div", "", "Updating rewrites only Smart Tool's entry. Your other hooks stay as they are, and the file is backed up first."));
|
|
1223
|
+
hook.body.appendChild(why);
|
|
1224
|
+
} else if (item.hook_state === "missing" && !item.hook_error) {
|
|
1225
|
+
hook.body.appendChild(node("div", "callout info", "Installing adds one entry to this file. Your other hooks stay as they are, and the file is backed up first."));
|
|
1226
|
+
}
|
|
1227
|
+
const docs = node("a", "", "How " + item.label + " hooks work");
|
|
1228
|
+
docs.href = item.docs;
|
|
1229
|
+
docs.target = "_blank";
|
|
1230
|
+
docs.rel = "noopener noreferrer";
|
|
1231
|
+
const docsLine = node("div", "hint");
|
|
1232
|
+
docsLine.style.marginTop = "6px";
|
|
1233
|
+
docsLine.appendChild(docs);
|
|
1234
|
+
hook.body.appendChild(docsLine);
|
|
1235
|
+
|
|
1236
|
+
const confirm = node("div", "confirm-box row-more");
|
|
1237
|
+
confirm.hidden = true;
|
|
1238
|
+
const confirmFile = node("p", "mono");
|
|
1239
|
+
const preview = node("pre", "code");
|
|
1240
|
+
const exact = node("details", "more");
|
|
1241
|
+
exact.append(node("summary", "", "Show the exact entry that will be written"), preview);
|
|
1242
|
+
const confirmMsg = node("div", "msg");
|
|
1243
|
+
confirmMsg.setAttribute("role", "status");
|
|
1244
|
+
const write = button("Confirm and write", "primary");
|
|
1245
|
+
const cancel = button("Cancel", "");
|
|
1246
|
+
const confirmActions = node("div", "actions");
|
|
1247
|
+
confirmActions.append(write, cancel);
|
|
1248
|
+
confirm.append(node("p", "", "Review the change, then confirm. The preview is valid for 10 minutes."), confirmFile, exact, confirmMsg, confirmActions);
|
|
1249
|
+
if (item.after_install) confirm.appendChild(node("p", "callout info", "After writing: " + item.after_install));
|
|
1250
|
+
hook.el.appendChild(confirm);
|
|
1251
|
+
|
|
1252
|
+
const hookLabel = item.hook_state === "outdated" ? "Update hook" : "Install hook";
|
|
1253
|
+
const start = button(hookLabel, "primary");
|
|
1254
|
+
start.hidden = item.hook_state === "current" || Boolean(item.hook_error) || item.hook_state === null;
|
|
1255
|
+
hook.side.appendChild(start);
|
|
1256
|
+
async function openPreview() {
|
|
1257
|
+
start.disabled = true;
|
|
1258
|
+
setMsg(msg, "", "Preparing the change…");
|
|
1259
|
+
try {
|
|
1260
|
+
const plan = await post("/setup/integration", { client: item.client, action: "preview" });
|
|
1261
|
+
setMsg(msg, "", "");
|
|
1262
|
+
if (plan.installed) { await loadIntegration(); return; }
|
|
1263
|
+
confirmFile.textContent = (item.hook_state === "outdated" ? "Replaces Smart Tool's entry with this one under " : "Adds this entry under ") + plan.event + " in " + plan.file;
|
|
1264
|
+
preview.textContent = JSON.stringify(plan.change, null, 2);
|
|
1265
|
+
confirm.hidden = false;
|
|
1266
|
+
start.hidden = true;
|
|
1267
|
+
setMsg(confirmMsg, "", "");
|
|
1268
|
+
write.disabled = false;
|
|
1269
|
+
write.onclick = async () => {
|
|
1270
|
+
write.disabled = true;
|
|
1271
|
+
setMsg(confirmMsg, "", "Writing…");
|
|
1055
1272
|
try {
|
|
1056
|
-
const
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
button.hidden = true;
|
|
1061
|
-
setMsg("agents-msg", "", "");
|
|
1062
|
-
row.querySelector(".confirm").onclick = async () => {
|
|
1063
|
-
try {
|
|
1064
|
-
const result = await post("/setup/integration", { client: item.client, action: "install", token: preview.token });
|
|
1065
|
-
setMsg("agents-msg", "ok", item.label + ": hook written. Backup: " + (result.backup || "new file") + (result.after_install ? ". " + result.after_install : ""));
|
|
1066
|
-
await loadAgents();
|
|
1067
|
-
} catch (error) {
|
|
1068
|
-
setMsg("agents-msg", "error", error.message);
|
|
1069
|
-
}
|
|
1070
|
-
};
|
|
1273
|
+
const result = await post("/setup/integration", { client: item.client, action: "install", token: plan.token });
|
|
1274
|
+
await loadIntegration();
|
|
1275
|
+
setMsg(agentMsg(item.client), "ok", "Hook written. Backup: " + (result.backup || "none, the file was new") + "."
|
|
1276
|
+
+ (result.after_install ? " " + result.after_install : ""));
|
|
1071
1277
|
} catch (error) {
|
|
1072
|
-
setMsg(
|
|
1278
|
+
setMsg(confirmMsg, "error", error.message);
|
|
1279
|
+
write.disabled = false;
|
|
1073
1280
|
}
|
|
1074
|
-
}
|
|
1075
|
-
|
|
1076
|
-
|
|
1281
|
+
};
|
|
1282
|
+
write.focus();
|
|
1283
|
+
} catch (error) {
|
|
1284
|
+
setMsg(msg, "error", error.message);
|
|
1285
|
+
} finally {
|
|
1286
|
+
start.disabled = false;
|
|
1077
1287
|
}
|
|
1078
|
-
} catch (error) {
|
|
1079
|
-
setMsg("agents-msg", "error", "Agent status unavailable: " + error.message);
|
|
1080
1288
|
}
|
|
1289
|
+
start.addEventListener("click", openPreview);
|
|
1290
|
+
cancel.addEventListener("click", () => { confirm.hidden = true; start.hidden = false; start.focus(); });
|
|
1291
|
+
hookControls[item.client] = () => { card.scrollIntoView({ block: "start" }); if (!start.hidden) openPreview(); };
|
|
1292
|
+
|
|
1293
|
+
const [browserTone, browserLabel, browserText] = browserState(item);
|
|
1294
|
+
const browser = row("Browser control", pill(browserTone, browserLabel), browserText);
|
|
1295
|
+
if (item.mcp_url && !["registered", "kept"].includes((item.browser_control || {}).state)) {
|
|
1296
|
+
const retry = button("Set up", "", async () => {
|
|
1297
|
+
retry.disabled = true;
|
|
1298
|
+
setMsg(msg, "", "Checking whether agents can drive a browser here…");
|
|
1299
|
+
try {
|
|
1300
|
+
const result = await post("/setup/integration", { client: item.client, action: "browser_control" });
|
|
1301
|
+
await loadIntegration();
|
|
1302
|
+
setMsg(agentMsg(item.client), "ok", browserState({ browser_control: result.browser_control })[2]);
|
|
1303
|
+
} catch (error) {
|
|
1304
|
+
setMsg(msg, "error", error.message);
|
|
1305
|
+
retry.disabled = false;
|
|
1306
|
+
}
|
|
1307
|
+
});
|
|
1308
|
+
browser.side.appendChild(retry);
|
|
1309
|
+
}
|
|
1310
|
+
msg.dataset.client = item.client;
|
|
1311
|
+
card.append(head, msg, mcp.el, hook.el, browser.el);
|
|
1312
|
+
return card;
|
|
1081
1313
|
}
|
|
1314
|
+
function agentMsg(client) { return document.querySelector(`#agents-list .msg[data-client="${client}"]`); }
|
|
1315
|
+
|
|
1316
|
+
function renderAgents() {
|
|
1317
|
+
const list = $("agents-list");
|
|
1318
|
+
list.replaceChildren(...loaded.integration.clients.map(agentCard));
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
function bars(entries) {
|
|
1322
|
+
const list = node("ul", "bars");
|
|
1323
|
+
const top = Math.max(1, ...entries.map(([, count]) => count));
|
|
1324
|
+
for (const [name, count] of entries) {
|
|
1325
|
+
const item = node("li");
|
|
1326
|
+
const bar = node("span", "bar");
|
|
1327
|
+
const fill = node("span");
|
|
1328
|
+
fill.style.width = Math.round(count / top * 100) + "%";
|
|
1329
|
+
bar.appendChild(fill);
|
|
1330
|
+
item.append(node("span", "name", name), bar, node("span", "num", String(count)));
|
|
1331
|
+
list.appendChild(item);
|
|
1332
|
+
}
|
|
1333
|
+
return list;
|
|
1334
|
+
}
|
|
1335
|
+
function tile(value, label) {
|
|
1336
|
+
const el = node("div", "tile");
|
|
1337
|
+
el.append(node("div", "value", String(value)), node("div", "label", label));
|
|
1338
|
+
return el;
|
|
1339
|
+
}
|
|
1340
|
+
function renderRedirects(stats) {
|
|
1341
|
+
const card = $("redirects-card");
|
|
1342
|
+
card.replaceChildren(node("h3", "", "Native searches redirected"),
|
|
1343
|
+
node("p", "lede", "Last " + stats.days + " days. After each redirect, Smart Tool looks at the same session's next call to see whether the agent followed it."));
|
|
1344
|
+
if (!stats.total) { card.appendChild(node("p", "", "No native search was redirected in the last " + stats.days + " days.")); return; }
|
|
1345
|
+
const out = stats.outcomes, tokens = stats.tokens_per_call;
|
|
1346
|
+
const tiles = node("div", "tiles");
|
|
1347
|
+
tiles.append(tile(stats.total, "redirected"), tile(out.followed || 0, "then used smart_search"),
|
|
1348
|
+
tile(out.native || 0, "then ran an allowed native call"), tile(out.blocked_again || 0, "blocked again"),
|
|
1349
|
+
tile(out.no_other_call || 0, "no other call within 15 min"));
|
|
1350
|
+
card.appendChild(tiles);
|
|
1351
|
+
if (out.unknown) card.appendChild(node("p", "hint", plural(out.unknown, "redirect") + " had no session logged, so their next call is unknown."));
|
|
1352
|
+
const byTool = Object.entries(stats.by_tool).sort((a, b) => b[1] - a[1]);
|
|
1353
|
+
if (byTool.length) card.append(node("h4", "", "By tool"), bars(byTool));
|
|
1354
|
+
const byReason = Object.entries(stats.by_reason).sort((a, b) => b[1] - a[1]);
|
|
1355
|
+
if (byReason.length) card.append(node("h4", "", "By reason"), bars(byReason));
|
|
1356
|
+
card.appendChild(node("p", "hint", "Context per call, measured over " + plural(tokens.measured, "call") + ": a native call of the kinds redirected costs about "
|
|
1357
|
+
+ tokens.native_redirected + " tokens; a smart_search round trip about " + tokens.smart_search
|
|
1358
|
+
+ " tokens. A redirect saves context only when one smart_search replaces several native searches and reads; that part is not measured yet."));
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1082
1361
|
const PATTERN_PAGE_SIZE = 8;
|
|
1083
1362
|
const patternView = { page: 0, filter: "", sort: "impact", selected: new Set(), open: false };
|
|
1084
1363
|
let lastPatterns = null;
|
|
@@ -1095,26 +1374,22 @@ function patternPage(items, view) {
|
|
|
1095
1374
|
matched: sorted.length, total: items.length,
|
|
1096
1375
|
calls: items.reduce((sum, item) => sum + (item.history_matches || 0), 0) };
|
|
1097
1376
|
}
|
|
1098
|
-
function patternEl(tag, className, text) {
|
|
1099
|
-
const el = document.createElement(tag);
|
|
1100
|
-
if (className) el.className = className;
|
|
1101
|
-
if (text !== undefined) el.textContent = text;
|
|
1102
|
-
return el;
|
|
1103
|
-
}
|
|
1104
1377
|
async function decidePatterns(ids, decision, label) {
|
|
1105
1378
|
try {
|
|
1106
1379
|
const result = await post("/setup/integration", { action: "block_patterns", ids, decision });
|
|
1107
1380
|
for (const id of ids) patternView.selected.delete(id);
|
|
1381
|
+
loaded.integration = result;
|
|
1108
1382
|
renderPatterns(result.block_patterns);
|
|
1109
|
-
|
|
1383
|
+
renderOverview();
|
|
1384
|
+
setMsg("patterns-msg", "ok", label + ": " + plural(ids.length, "pattern") + ".");
|
|
1110
1385
|
} catch (error) {
|
|
1111
|
-
setMsg("
|
|
1386
|
+
setMsg("patterns-msg", "error", error.message);
|
|
1112
1387
|
}
|
|
1113
1388
|
}
|
|
1114
1389
|
function patternRow(item, actions, selectable) {
|
|
1115
|
-
const
|
|
1390
|
+
const entry = node("li", "pattern-row" + (selectable ? "" : " plain"));
|
|
1116
1391
|
if (selectable) {
|
|
1117
|
-
const check =
|
|
1392
|
+
const check = node("input");
|
|
1118
1393
|
check.type = "checkbox";
|
|
1119
1394
|
check.checked = patternView.selected.has(item.id);
|
|
1120
1395
|
check.setAttribute("aria-label", "Select " + item.pattern);
|
|
@@ -1122,50 +1397,42 @@ function patternRow(item, actions, selectable) {
|
|
|
1122
1397
|
if (check.checked) patternView.selected.add(item.id); else patternView.selected.delete(item.id);
|
|
1123
1398
|
renderPatterns(lastPatterns);
|
|
1124
1399
|
});
|
|
1125
|
-
|
|
1400
|
+
entry.appendChild(check);
|
|
1126
1401
|
}
|
|
1127
|
-
const body =
|
|
1128
|
-
const summary =
|
|
1129
|
-
const code =
|
|
1402
|
+
const body = node("details", "pattern-body");
|
|
1403
|
+
const summary = node("summary");
|
|
1404
|
+
const code = node("code", "pattern-code", item.pattern);
|
|
1130
1405
|
code.title = item.pattern;
|
|
1131
|
-
summary.append(
|
|
1132
|
-
const detail =
|
|
1133
|
-
detail.append(
|
|
1134
|
-
patternEl("p", "hint mono", item.pattern));
|
|
1406
|
+
summary.append(node("span", "pattern-tool", item.tool), code);
|
|
1407
|
+
const detail = node("div", "pattern-detail");
|
|
1408
|
+
detail.append(node("p", "", item.reason), node("p", "hint mono", "Example: " + item.example), node("p", "hint mono", item.pattern));
|
|
1135
1409
|
body.append(summary, detail);
|
|
1136
|
-
const reach =
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
for (const [decision, label] of actions)
|
|
1140
|
-
|
|
1141
|
-
button.type = "button";
|
|
1142
|
-
button.addEventListener("click", () => decidePatterns([item.id], decision, label));
|
|
1143
|
-
buttons.appendChild(button);
|
|
1144
|
-
}
|
|
1145
|
-
const meta = patternEl("div", "pattern-meta");
|
|
1410
|
+
const reach = node("span", "pattern-reach", item.history_total ? "would block " + item.history_matches + " of " + item.history_total + " logged " + item.tool + " calls" : "no logged calls to compare");
|
|
1411
|
+
const buttons = node("span", "actions");
|
|
1412
|
+
buttons.style.marginTop = "0";
|
|
1413
|
+
for (const [decision, label] of actions) buttons.appendChild(button(label, "small", () => decidePatterns([item.id], decision, label)));
|
|
1414
|
+
const meta = node("div", "pattern-meta");
|
|
1146
1415
|
meta.append(reach, buttons);
|
|
1147
|
-
const main =
|
|
1416
|
+
const main = node("div");
|
|
1148
1417
|
main.append(body, meta);
|
|
1149
|
-
|
|
1150
|
-
return
|
|
1418
|
+
entry.appendChild(main);
|
|
1419
|
+
return entry;
|
|
1151
1420
|
}
|
|
1152
1421
|
function renderPatterns(patterns) {
|
|
1153
1422
|
lastPatterns = patterns;
|
|
1154
1423
|
const box = $("patterns-list");
|
|
1155
|
-
box.
|
|
1156
|
-
if (patterns.error) { box.appendChild(
|
|
1424
|
+
box.replaceChildren();
|
|
1425
|
+
if (patterns.error) { box.appendChild(node("p", "msg error", patterns.error)); return; }
|
|
1157
1426
|
const proposals = patterns.proposals;
|
|
1158
1427
|
const live = new Set(proposals.map((item) => item.id));
|
|
1159
1428
|
for (const id of [...patternView.selected]) if (!live.has(id)) patternView.selected.delete(id);
|
|
1160
|
-
if (proposals.length)
|
|
1429
|
+
if (!proposals.length) box.appendChild(node("p", "", "No proposal waiting for you."));
|
|
1430
|
+
else {
|
|
1161
1431
|
const view = patternPage(proposals, patternView);
|
|
1162
1432
|
patternView.page = view.page;
|
|
1163
|
-
|
|
1164
|
-
const
|
|
1165
|
-
|
|
1166
|
-
patternEl("span", "hint", "Together they would have blocked " + view.calls + " logged call(s). Open a row for its reason and example."));
|
|
1167
|
-
const tools = patternEl("div", "pattern-tools");
|
|
1168
|
-
const filter = patternEl("input");
|
|
1433
|
+
box.appendChild(node("p", "", plural(proposals.length, "proposal") + " waiting. Together they would have blocked " + plural(view.calls, "logged call") + ". Open a row for its reason and an example."));
|
|
1434
|
+
const tools = node("div", "pattern-tools");
|
|
1435
|
+
const filter = node("input");
|
|
1169
1436
|
filter.type = "text";
|
|
1170
1437
|
filter.placeholder = "Filter by pattern, reason or example";
|
|
1171
1438
|
filter.value = patternView.filter;
|
|
@@ -1177,103 +1444,189 @@ function renderPatterns(patterns) {
|
|
|
1177
1444
|
const again = document.querySelector(".pattern-tools input[type=text]");
|
|
1178
1445
|
if (again) { again.focus(); again.setSelectionRange(again.value.length, again.value.length); }
|
|
1179
1446
|
});
|
|
1180
|
-
const sort =
|
|
1447
|
+
const sort = node("select");
|
|
1181
1448
|
sort.setAttribute("aria-label", "Order of proposed patterns");
|
|
1182
|
-
for (const [value, label] of [["impact", "Most blocked calls first"], ["newest", "Newest first"]])
|
|
1183
|
-
const option = patternEl("option", "", label);
|
|
1184
|
-
option.value = value;
|
|
1185
|
-
sort.appendChild(option);
|
|
1186
|
-
}
|
|
1449
|
+
for (const [value, label] of [["impact", "Most blocked calls first"], ["newest", "Newest first"]]) sort.appendChild(new Option(label, value));
|
|
1187
1450
|
sort.value = patternView.sort;
|
|
1188
1451
|
sort.addEventListener("change", () => { patternView.sort = sort.value; patternView.page = 0; renderPatterns(lastPatterns); });
|
|
1189
1452
|
tools.append(filter, sort);
|
|
1190
|
-
const bulk =
|
|
1453
|
+
const bulk = node("div", "actions");
|
|
1191
1454
|
const pageIds = view.rows.map((item) => item.id);
|
|
1192
1455
|
const allOnPage = pageIds.length > 0 && pageIds.every((id) => patternView.selected.has(id));
|
|
1193
|
-
const selectPage =
|
|
1194
|
-
selectPage.type = "button";
|
|
1195
|
-
selectPage.disabled = !pageIds.length;
|
|
1196
|
-
selectPage.addEventListener("click", () => {
|
|
1456
|
+
const selectPage = button(allOnPage ? "Clear this page" : "Select this page", "", () => {
|
|
1197
1457
|
for (const id of pageIds) if (allOnPage) patternView.selected.delete(id); else patternView.selected.add(id);
|
|
1198
1458
|
renderPatterns(lastPatterns);
|
|
1199
1459
|
});
|
|
1460
|
+
selectPage.disabled = !pageIds.length;
|
|
1200
1461
|
const count = patternView.selected.size;
|
|
1201
|
-
const accept =
|
|
1202
|
-
const reject =
|
|
1203
|
-
|
|
1204
|
-
button.type = "button";
|
|
1205
|
-
button.disabled = !count;
|
|
1206
|
-
button.addEventListener("click", () => decidePatterns([...patternView.selected], decision, label));
|
|
1207
|
-
}
|
|
1462
|
+
const accept = button("Accept selected (" + count + ")", "primary", () => decidePatterns([...patternView.selected], "accept", "Accepted"));
|
|
1463
|
+
const reject = button("Reject selected (" + count + ")", "", () => decidePatterns([...patternView.selected], "reject", "Rejected"));
|
|
1464
|
+
accept.disabled = reject.disabled = !count;
|
|
1208
1465
|
bulk.append(selectPage, accept, reject);
|
|
1209
|
-
const list =
|
|
1466
|
+
const list = node("ul", "pattern-list");
|
|
1210
1467
|
for (const item of view.rows) list.appendChild(patternRow(item, [["accept", "Accept"], ["reject", "Reject"]], true));
|
|
1211
|
-
if (!view.rows.length) list.appendChild(
|
|
1212
|
-
const pager =
|
|
1213
|
-
const prev =
|
|
1214
|
-
const next =
|
|
1215
|
-
prev.type = "button";
|
|
1216
|
-
next.type = "button";
|
|
1468
|
+
if (!view.rows.length) list.appendChild(node("li", "hint", "No proposal matches the filter."));
|
|
1469
|
+
const pager = node("div", "actions pager");
|
|
1470
|
+
const prev = button("Previous", "", () => { patternView.page -= 1; renderPatterns(lastPatterns); });
|
|
1471
|
+
const next = button("Next", "", () => { patternView.page += 1; renderPatterns(lastPatterns); });
|
|
1217
1472
|
prev.disabled = view.page === 0;
|
|
1218
1473
|
next.disabled = view.page >= view.pages - 1;
|
|
1219
|
-
prev.addEventListener("click", () => { patternView.page -= 1; renderPatterns(lastPatterns); });
|
|
1220
|
-
next.addEventListener("click", () => { patternView.page += 1; renderPatterns(lastPatterns); });
|
|
1221
1474
|
const first = view.page * PATTERN_PAGE_SIZE;
|
|
1222
1475
|
const shown = view.matched ? (first + 1) + "–" + (first + view.rows.length) : "0";
|
|
1223
1476
|
const filtered = view.matched < view.total ? " (filtered from " + view.total + ")" : "";
|
|
1224
|
-
pager.append(prev,
|
|
1225
|
-
|
|
1226
|
-
box.appendChild(panel);
|
|
1477
|
+
pager.append(prev, node("span", "hint", shown + " of " + view.matched + filtered + " · page " + (view.page + 1) + " of " + view.pages), next);
|
|
1478
|
+
box.append(tools, bulk, list, pager);
|
|
1227
1479
|
}
|
|
1228
1480
|
if (patterns.accepted.length) {
|
|
1229
|
-
const blocking =
|
|
1481
|
+
const blocking = node("details", "more");
|
|
1230
1482
|
blocking.open = patternView.open;
|
|
1231
1483
|
blocking.addEventListener("toggle", () => { patternView.open = blocking.open; });
|
|
1232
|
-
blocking.appendChild(
|
|
1233
|
-
const list =
|
|
1484
|
+
blocking.appendChild(node("summary", "", "Patterns you accepted, blocking now (" + patterns.accepted.length + ")"));
|
|
1485
|
+
const list = node("ul", "pattern-list");
|
|
1234
1486
|
for (const item of patterns.accepted) list.appendChild(patternRow(item, [["remove", "Remove"]], false));
|
|
1235
1487
|
blocking.appendChild(list);
|
|
1236
1488
|
box.appendChild(blocking);
|
|
1237
1489
|
}
|
|
1238
|
-
if (patterns.rejected) box.appendChild(
|
|
1490
|
+
if (patterns.rejected) box.appendChild(node("p", "hint", plural(patterns.rejected, "rejected proposal") + " not offered again."));
|
|
1239
1491
|
}
|
|
1240
|
-
|
|
1241
|
-
|
|
1492
|
+
|
|
1493
|
+
async function loadIntegration() {
|
|
1242
1494
|
try {
|
|
1243
|
-
await
|
|
1244
|
-
|
|
1495
|
+
loaded.integration = await getJSON("/setup/integration");
|
|
1496
|
+
delete failed.integration;
|
|
1497
|
+
renderAgents();
|
|
1498
|
+
renderRules();
|
|
1499
|
+
renderRedirects(loaded.integration.redirects);
|
|
1500
|
+
renderPatterns(loaded.integration.block_patterns);
|
|
1245
1501
|
} catch (error) {
|
|
1246
|
-
|
|
1502
|
+
failed.integration = "Agent status unavailable: " + error.message;
|
|
1503
|
+
setMsg("agents-msg", "error", failed.integration);
|
|
1504
|
+
$("rules-card").replaceChildren(node("p", "msg error", failed.integration));
|
|
1505
|
+
$("redirects-card").replaceChildren(node("p", "msg error", failed.integration));
|
|
1247
1506
|
}
|
|
1248
|
-
|
|
1249
|
-
|
|
1507
|
+
renderOverview();
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
async function loadAutostart() {
|
|
1250
1511
|
try {
|
|
1251
|
-
await
|
|
1252
|
-
|
|
1512
|
+
loaded.autostart = await getJSON("/setup/autostart");
|
|
1513
|
+
const on = loaded.autostart.installed;
|
|
1514
|
+
setPill("autostart-pill", on ? "ok" : "idle", on ? "On, via " + (loaded.autostart.method === "task" ? "Scheduled Task" : "Startup folder") : "Off");
|
|
1515
|
+
const toggle = $("btn-autostart-toggle");
|
|
1516
|
+
toggle.disabled = false;
|
|
1517
|
+
toggle.className = on ? "" : "primary";
|
|
1518
|
+
toggle.textContent = on ? "Turn off" : "Turn on";
|
|
1253
1519
|
} catch (error) {
|
|
1254
|
-
|
|
1520
|
+
setPill("autostart-pill", "bad", "Status unavailable");
|
|
1521
|
+
setMsg("autostart-msg", "error", error.message);
|
|
1255
1522
|
}
|
|
1256
|
-
|
|
1257
|
-
|
|
1523
|
+
renderOverview();
|
|
1524
|
+
}
|
|
1525
|
+
$("btn-autostart-toggle").addEventListener("click", async () => {
|
|
1526
|
+
const action = loaded.autostart.installed ? "remove" : "install";
|
|
1527
|
+
$("btn-autostart-toggle").disabled = true;
|
|
1528
|
+
setMsg("autostart-msg", "", action === "install" ? "Turning on…" : "Turning off…");
|
|
1258
1529
|
try {
|
|
1259
|
-
await post("/setup/
|
|
1260
|
-
setMsg("
|
|
1530
|
+
const data = await post("/setup/autostart", { action });
|
|
1531
|
+
setMsg("autostart-msg", "ok", action === "install"
|
|
1532
|
+
? (data.method === "task" ? "Turned on via Scheduled Task." : `Turned on via the Startup folder; the Scheduled Task was refused: ${data.fallback_reason || "no reason given"}.`)
|
|
1533
|
+
: "Turned off.");
|
|
1534
|
+
await loadAutostart();
|
|
1261
1535
|
} catch (error) {
|
|
1262
|
-
setMsg("
|
|
1536
|
+
setMsg("autostart-msg", "error", error.message);
|
|
1537
|
+
$("btn-autostart-toggle").disabled = false;
|
|
1263
1538
|
}
|
|
1264
1539
|
});
|
|
1265
|
-
|
|
1540
|
+
|
|
1541
|
+
const PROVIDER_STATES = { keyless: ["ok", "Free tier, no key"], configured: ["ok", "Your key"], unreadable: ["bad", "Key unreadable"] };
|
|
1542
|
+
function providerRow(name, info) {
|
|
1543
|
+
const entry = node("div", "provider-row");
|
|
1544
|
+
const [tone, label] = PROVIDER_STATES[info.status] || ["bad", info.status];
|
|
1545
|
+
const title = node("div", "row-title");
|
|
1546
|
+
title.append(node("span", "", info.label), pill(tone, label));
|
|
1547
|
+
const text = node("div", "row-text");
|
|
1548
|
+
text.append(node("div", "", "Without a key: " + info.free), node("div", "", "With your key: " + info.keyed));
|
|
1549
|
+
if (info.status === "unreadable") text.appendChild(node("div", "msg error", "The saved key cannot be opened in this Windows profile; paste it again."));
|
|
1550
|
+
const side = node("div", "row-side");
|
|
1551
|
+
const form = node("div", "key-form");
|
|
1552
|
+
form.hidden = true;
|
|
1553
|
+
const field = node("div", "field");
|
|
1554
|
+
const input = node("input");
|
|
1555
|
+
input.type = "password";
|
|
1556
|
+
input.autocomplete = "new-password";
|
|
1557
|
+
input.id = name + "-key";
|
|
1558
|
+
input.placeholder = info.key_prefix ? `Paste the key (starts with ${info.key_prefix})` : "Paste the key from your account";
|
|
1559
|
+
const fieldLabel = node("label", "", info.label + " API key");
|
|
1560
|
+
fieldLabel.htmlFor = input.id;
|
|
1561
|
+
const signup = node("a", "", "Create a key in your " + info.label + " account");
|
|
1562
|
+
signup.href = info.signup;
|
|
1563
|
+
signup.target = "_blank";
|
|
1564
|
+
signup.rel = "noopener noreferrer";
|
|
1565
|
+
const hint = node("span", "hint");
|
|
1566
|
+
hint.appendChild(signup);
|
|
1567
|
+
field.append(fieldLabel, input, hint);
|
|
1568
|
+
const msg = node("div", "msg");
|
|
1569
|
+
msg.setAttribute("role", "status");
|
|
1570
|
+
const save = button("Test and save", "primary", async () => {
|
|
1571
|
+
if (!input.value.trim()) { setMsg(msg, "error", "Paste the API key before saving."); return; }
|
|
1572
|
+
save.disabled = true;
|
|
1573
|
+
setMsg(msg, "", "Testing the key with a real search…");
|
|
1574
|
+
try {
|
|
1575
|
+
const data = await post("/setup/providers", { provider: name, action: "save", api_key: input.value.trim() });
|
|
1576
|
+
await loadProviders(name, `Key accepted (${plural(data.validated_results, "result")} in the test) and protected on this Windows machine.`);
|
|
1577
|
+
} catch (error) {
|
|
1578
|
+
setMsg(msg, "error", error.message);
|
|
1579
|
+
save.disabled = false;
|
|
1580
|
+
}
|
|
1581
|
+
});
|
|
1582
|
+
const formActions = node("div", "actions");
|
|
1583
|
+
formActions.append(save, button("Cancel", "", () => { form.hidden = true; open.hidden = false; }));
|
|
1584
|
+
form.append(field, formActions);
|
|
1585
|
+
const open = button(info.status === "keyless" ? "Add key" : "Replace key", "", () => { form.hidden = false; open.hidden = true; input.focus(); });
|
|
1586
|
+
side.appendChild(open);
|
|
1587
|
+
if (info.status !== "keyless") {
|
|
1588
|
+
const remove = button("Remove key", "", async () => {
|
|
1589
|
+
remove.disabled = true;
|
|
1590
|
+
setMsg(msg, "", "Removing…");
|
|
1591
|
+
try {
|
|
1592
|
+
await post("/setup/providers", { provider: name, action: "remove" });
|
|
1593
|
+
await loadProviders(name, "Key removed; the free tier is active.");
|
|
1594
|
+
} catch (error) {
|
|
1595
|
+
setMsg(msg, "error", error.message);
|
|
1596
|
+
remove.disabled = false;
|
|
1597
|
+
}
|
|
1598
|
+
});
|
|
1599
|
+
side.appendChild(remove);
|
|
1600
|
+
}
|
|
1601
|
+
msg.dataset.provider = name;
|
|
1602
|
+
entry.append(title, side, text, form, msg);
|
|
1603
|
+
return entry;
|
|
1604
|
+
}
|
|
1605
|
+
async function loadProviders(provider, message) {
|
|
1606
|
+
try {
|
|
1607
|
+
loaded.providers = await getJSON("/setup/providers");
|
|
1608
|
+
delete failed.providers;
|
|
1609
|
+
$("provider-list").replaceChildren(...Object.entries(loaded.providers.providers).map(([name, info]) => providerRow(name, info)));
|
|
1610
|
+
if (provider) setMsg(document.querySelector(`#provider-list .msg[data-provider="${provider}"]`), "ok", message);
|
|
1611
|
+
if (document.activeElement !== $("contact-input")) $("contact-input").value = loaded.providers.contact;
|
|
1612
|
+
$("contact-hint").textContent = "Sent as: " + loaded.providers.user_agent;
|
|
1613
|
+
} catch (error) {
|
|
1614
|
+
failed.providers = "Provider status unavailable: " + error.message;
|
|
1615
|
+
$("provider-list").replaceChildren(node("p", "msg error", failed.providers));
|
|
1616
|
+
}
|
|
1617
|
+
renderOverview();
|
|
1618
|
+
}
|
|
1619
|
+
$("btn-save-contact").addEventListener("click", async () => {
|
|
1266
1620
|
try {
|
|
1267
|
-
await post("/setup/
|
|
1268
|
-
|
|
1269
|
-
|
|
1621
|
+
const data = await post("/setup/contact", { contact: $("contact-input").value.trim() });
|
|
1622
|
+
$("contact-hint").textContent = "Sent as: " + data.user_agent;
|
|
1623
|
+
setMsg("contact-msg", "ok", "Contact saved.");
|
|
1270
1624
|
} catch (error) {
|
|
1271
|
-
setMsg("
|
|
1625
|
+
setMsg("contact-msg", "error", error.message);
|
|
1272
1626
|
}
|
|
1273
1627
|
});
|
|
1274
1628
|
|
|
1275
|
-
const AUDIT_SEVERITY = { error: "Error", warn: "Warning", info: "Note" };
|
|
1276
|
-
let auditProjects = [];
|
|
1629
|
+
const AUDIT_SEVERITY = { error: ["bad", "Error"], warn: ["warn", "Warning"], info: ["idle", "Note"] };
|
|
1277
1630
|
function auditWhen(seconds) {
|
|
1278
1631
|
return seconds ? new Date(seconds * 1000).toLocaleString() : "never";
|
|
1279
1632
|
}
|
|
@@ -1281,40 +1634,40 @@ function renderAudit(report) {
|
|
|
1281
1634
|
const box = $("audit-report");
|
|
1282
1635
|
box.replaceChildren();
|
|
1283
1636
|
if (!report) {
|
|
1284
|
-
box.appendChild(
|
|
1637
|
+
box.appendChild(node("p", "hint", "Not audited yet: the next scheduled run covers it, or press Run now."));
|
|
1285
1638
|
return;
|
|
1286
1639
|
}
|
|
1287
1640
|
const s = report.summary;
|
|
1288
|
-
box.appendChild(
|
|
1641
|
+
box.appendChild(node("p", "", plural(s.error, "error") + ", " + plural(s.warn, "warning") + ", " + plural(s.info, "note") + " · "
|
|
1289
1642
|
+ (report.trigger === "schedule" ? "scheduled run" : "run on request") + " at " + auditWhen(report.checked_at)));
|
|
1290
1643
|
const changes = report.changes;
|
|
1291
|
-
if (changes) box.appendChild(
|
|
1644
|
+
if (changes) box.appendChild(node("p", "hint", "Since the previous run: " + changes.new.length + " new, "
|
|
1292
1645
|
+ changes.resolved.length + " resolved" + (changes.snapshot_changed ? " (configuration changed)." : ".")));
|
|
1293
|
-
const list =
|
|
1646
|
+
const list = node("ul", "audit-list");
|
|
1294
1647
|
for (const finding of report.findings) {
|
|
1295
|
-
const
|
|
1296
|
-
const head =
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
if (finding.new) head.appendChild(
|
|
1300
|
-
const detail =
|
|
1648
|
+
const entry = node("li", "audit-row");
|
|
1649
|
+
const head = node("div", "audit-head");
|
|
1650
|
+
const [tone, label] = AUDIT_SEVERITY[finding.severity] || ["idle", finding.severity];
|
|
1651
|
+
head.append(pill(tone, label), node("span", "pattern-tool", finding.harness), node("strong", "", finding.subject));
|
|
1652
|
+
if (finding.new) head.appendChild(node("span", "new-tag", "new"));
|
|
1653
|
+
const detail = node("p", "audit-detail", finding.detail + " ");
|
|
1301
1654
|
if ((finding.source || "").startsWith("https://")) {
|
|
1302
|
-
const link =
|
|
1655
|
+
const link = node("a", "", "documentation");
|
|
1303
1656
|
link.setAttribute("href", finding.source);
|
|
1304
1657
|
link.setAttribute("target", "_blank");
|
|
1305
1658
|
link.setAttribute("rel", "noopener noreferrer");
|
|
1306
1659
|
detail.appendChild(link);
|
|
1307
1660
|
}
|
|
1308
|
-
|
|
1309
|
-
list.appendChild(
|
|
1661
|
+
entry.append(head, detail);
|
|
1662
|
+
list.appendChild(entry);
|
|
1310
1663
|
}
|
|
1311
1664
|
if (report.findings.length) box.appendChild(list);
|
|
1312
|
-
else box.appendChild(
|
|
1665
|
+
else box.appendChild(node("p", "msg ok", "No collision or broken piece found."));
|
|
1313
1666
|
if (changes && changes.resolved.length) {
|
|
1314
|
-
const resolved =
|
|
1315
|
-
resolved.appendChild(
|
|
1316
|
-
const items =
|
|
1317
|
-
for (const finding of changes.resolved) items.appendChild(
|
|
1667
|
+
const resolved = node("details", "more");
|
|
1668
|
+
resolved.appendChild(node("summary", "", "Resolved since the previous run (" + changes.resolved.length + ")"));
|
|
1669
|
+
const items = node("ul", "audit-list");
|
|
1670
|
+
for (const finding of changes.resolved) items.appendChild(node("li", "audit-detail", finding.subject + ": " + finding.detail));
|
|
1318
1671
|
resolved.appendChild(items);
|
|
1319
1672
|
box.appendChild(resolved);
|
|
1320
1673
|
}
|
|
@@ -1324,11 +1677,11 @@ function renderAudit(report) {
|
|
|
1324
1677
|
if (servers.length) costs.push(side + ": " + servers.map((m) => m.name + " " + m.tools + " tools (~"
|
|
1325
1678
|
+ Math.round(m.tool_chars / 4).toLocaleString() + " tokens)").join(", "));
|
|
1326
1679
|
}
|
|
1327
|
-
if (costs.length) box.appendChild(
|
|
1328
|
-
const unverified =
|
|
1329
|
-
unverified.appendChild(
|
|
1330
|
-
const items =
|
|
1331
|
-
for (const item of report.unverified) items.appendChild(
|
|
1680
|
+
if (costs.length) box.appendChild(node("p", "hint", "MCP tools offered — " + costs.join(" · ")));
|
|
1681
|
+
const unverified = node("details", "more");
|
|
1682
|
+
unverified.appendChild(node("summary", "", "Not verified (" + report.unverified.length + ")"));
|
|
1683
|
+
const items = node("ul", "audit-list");
|
|
1684
|
+
for (const item of report.unverified) items.appendChild(node("li", "audit-detail", item));
|
|
1332
1685
|
unverified.appendChild(items);
|
|
1333
1686
|
box.appendChild(unverified);
|
|
1334
1687
|
}
|
|
@@ -1342,32 +1695,31 @@ async function showAudit(root) {
|
|
|
1342
1695
|
async function loadAudit() {
|
|
1343
1696
|
try {
|
|
1344
1697
|
const data = await post("/setup/audit", { action: "index" });
|
|
1345
|
-
|
|
1698
|
+
loaded.audit = data;
|
|
1699
|
+
delete failed.audit;
|
|
1346
1700
|
const select = $("sel-audit-project");
|
|
1347
|
-
select.replaceChildren()
|
|
1348
|
-
for (const root of data.projects) {
|
|
1701
|
+
select.replaceChildren(...data.projects.map((root) => {
|
|
1349
1702
|
const entry = data.index[root];
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
select.appendChild(option);
|
|
1354
|
-
}
|
|
1355
|
-
$("audit-hint").textContent = data.projects.length ? "Runs every " + Math.round(data.schedule_s / 60) + " minutes." : "Register a project to audit it.";
|
|
1703
|
+
return new Option(root + (entry ? " — " + plural(entry.summary.error, "error") + ", " + plural(entry.summary.warn, "warning") : " — not audited yet"), root);
|
|
1704
|
+
}));
|
|
1705
|
+
$("audit-hint").textContent = data.projects.length ? "Runs on its own every " + Math.round(data.schedule_s / 60) + " minutes." : "Register a project on the Projects page to audit it.";
|
|
1356
1706
|
$("btn-audit-run").disabled = !data.projects.length;
|
|
1357
1707
|
if (data.projects.length) {
|
|
1358
|
-
const worst = data.projects.slice().sort((a, b) => ((data.index[b] || {summary: {error: -1}}).summary.error)
|
|
1359
|
-
- ((data.index[a] || {summary: {error: -1}}).summary.error))[0];
|
|
1708
|
+
const worst = data.projects.slice().sort((a, b) => ((data.index[b] || { summary: { error: -1 } }).summary.error)
|
|
1709
|
+
- ((data.index[a] || { summary: { error: -1 } }).summary.error))[0];
|
|
1360
1710
|
select.value = worst;
|
|
1361
1711
|
await showAudit(worst);
|
|
1362
1712
|
}
|
|
1363
1713
|
} catch (error) {
|
|
1364
|
-
|
|
1714
|
+
failed.audit = "Setup audit unavailable: " + error.message;
|
|
1715
|
+
setMsg("audit-msg", "error", failed.audit);
|
|
1365
1716
|
}
|
|
1717
|
+
renderOverview();
|
|
1366
1718
|
}
|
|
1367
1719
|
$("sel-audit-project").addEventListener("change", () => showAudit($("sel-audit-project").value));
|
|
1368
1720
|
$("btn-audit-run").addEventListener("click", async () => {
|
|
1369
|
-
const
|
|
1370
|
-
|
|
1721
|
+
const run = $("btn-audit-run");
|
|
1722
|
+
run.disabled = true;
|
|
1371
1723
|
setMsg("audit-msg", "", "Auditing; MCP servers are being contacted…");
|
|
1372
1724
|
try {
|
|
1373
1725
|
renderAudit((await post("/setup/audit", { action: "run", project_root: $("sel-audit-project").value })).report);
|
|
@@ -1375,93 +1727,19 @@ $("btn-audit-run").addEventListener("click", async () => {
|
|
|
1375
1727
|
} catch (error) {
|
|
1376
1728
|
setMsg("audit-msg", "error", error.message);
|
|
1377
1729
|
} finally {
|
|
1378
|
-
|
|
1379
|
-
}
|
|
1380
|
-
});
|
|
1381
|
-
loadAudit();
|
|
1382
|
-
|
|
1383
|
-
const providerLabels = { keyless: ["warn", "No key · free tier"], configured: ["ok", "Key configured"], unreadable: ["bad", "Key unreadable in this Windows profile"] };
|
|
1384
|
-
function providerCard(name, info) {
|
|
1385
|
-
const card = document.createElement("div");
|
|
1386
|
-
card.className = "provider";
|
|
1387
|
-
card.innerHTML = `
|
|
1388
|
-
<div class="provider-head"><strong></strong><span class="state" aria-live="polite"></span></div>
|
|
1389
|
-
<p class="hint free"></p><p class="hint keyed"></p>
|
|
1390
|
-
<p class="hint"><a target="_blank" rel="noopener noreferrer">Create a key in your provider account</a></p>
|
|
1391
|
-
<label>API key</label>
|
|
1392
|
-
<input type="password" autocomplete="new-password">
|
|
1393
|
-
<div class="actions"><button type="button" data-action="save">Validate and save</button><button type="button" class="quiet" data-action="remove">Remove key</button></div>
|
|
1394
|
-
<div class="msg" role="status"></div>`;
|
|
1395
|
-
card.querySelector("strong").textContent = info.label;
|
|
1396
|
-
card.querySelector(".free").textContent = info.free;
|
|
1397
|
-
card.querySelector(".keyed").textContent = info.keyed;
|
|
1398
|
-
const link = card.querySelector("a");
|
|
1399
|
-
link.href = info.signup;
|
|
1400
|
-
const input = card.querySelector("input");
|
|
1401
|
-
input.id = name + "-key";
|
|
1402
|
-
card.querySelector("label").htmlFor = input.id;
|
|
1403
|
-
input.placeholder = info.key_prefix ? `Paste the key (starts with ${info.key_prefix})` : "Paste the key from your account";
|
|
1404
|
-
const [kind, label] = providerLabels[info.status] || ["bad", info.status];
|
|
1405
|
-
Object.assign(card.querySelector(".state"), { textContent: label }).dataset.state = kind;
|
|
1406
|
-
const msg = card.querySelector(".msg");
|
|
1407
|
-
msg.id = name + "-msg";
|
|
1408
|
-
card.querySelector('[data-action="remove"]').disabled = info.status === "keyless";
|
|
1409
|
-
for (const button of card.querySelectorAll("button")) {
|
|
1410
|
-
button.addEventListener("click", async () => {
|
|
1411
|
-
const action = button.dataset.action;
|
|
1412
|
-
if (action === "save" && !input.value.trim()) { setMsg(msg.id, "error", "Paste the API key before saving."); return; }
|
|
1413
|
-
button.disabled = true;
|
|
1414
|
-
setMsg(msg.id, "", action === "save" ? "Testing the key with a real search…" : "Removing…");
|
|
1415
|
-
try {
|
|
1416
|
-
const data = await post("/setup/providers", { provider: name, action, ...(action === "save" ? { api_key: input.value.trim() } : {}) });
|
|
1417
|
-
input.value = "";
|
|
1418
|
-
await loadProviders(action === "save" ? `Key accepted by the provider (${data.validated_results} result(s) in the test) and protected on this Windows machine.` : "Key removed; free tier active.");
|
|
1419
|
-
} catch (error) {
|
|
1420
|
-
setMsg(msg.id, "error", error.message);
|
|
1421
|
-
button.disabled = false;
|
|
1422
|
-
}
|
|
1423
|
-
});
|
|
1424
|
-
}
|
|
1425
|
-
return card;
|
|
1426
|
-
}
|
|
1427
|
-
$("btn-save-contact").addEventListener("click", async () => {
|
|
1428
|
-
try {
|
|
1429
|
-
const data = await post("/setup/contact", { contact: $("contact-input").value.trim() });
|
|
1430
|
-
$("contact-hint").textContent = "Sent as: " + data.user_agent;
|
|
1431
|
-
setMsg("contact-msg", "ok", "Contact saved.");
|
|
1432
|
-
} catch (error) {
|
|
1433
|
-
setMsg("contact-msg", "error", error.message);
|
|
1730
|
+
run.disabled = false;
|
|
1434
1731
|
}
|
|
1435
1732
|
});
|
|
1436
1733
|
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
$("provider-select").addEventListener("change", () => showProvider());
|
|
1444
|
-
|
|
1445
|
-
async function loadProviders(message) {
|
|
1446
|
-
const list = $("provider-panel");
|
|
1447
|
-
try {
|
|
1448
|
-
const resp = await fetch("/setup/providers");
|
|
1449
|
-
const data = await resp.json();
|
|
1450
|
-
if (!resp.ok || data.error) throw new Error(data.error);
|
|
1451
|
-
providers = data.providers;
|
|
1452
|
-
const select = $("provider-select");
|
|
1453
|
-
const chosen = select.value;
|
|
1454
|
-
select.replaceChildren(...Object.entries(providers).map(([name, info]) =>
|
|
1455
|
-
new Option(info.label + " · " + ((providerLabels[info.status] || [null, info.status])[1]), name)));
|
|
1456
|
-
if (chosen && providers[chosen]) select.value = chosen;
|
|
1457
|
-
showProvider(message);
|
|
1458
|
-
if (document.activeElement !== $("contact-input")) $("contact-input").value = data.contact;
|
|
1459
|
-
$("contact-hint").textContent = "Sent as: " + data.user_agent;
|
|
1460
|
-
} catch (error) {
|
|
1461
|
-
list.replaceChildren(Object.assign(document.createElement("p"), { className: "msg error", textContent: "Provider status unavailable: " + error.message }));
|
|
1462
|
-
}
|
|
1463
|
-
}
|
|
1734
|
+
renderGateway();
|
|
1735
|
+
renderOverview();
|
|
1736
|
+
if (status.gateway.status === "ready") loadModels();
|
|
1737
|
+
loadLocalModels();
|
|
1738
|
+
loadIntegration();
|
|
1739
|
+
loadAutostart();
|
|
1464
1740
|
loadProviders();
|
|
1741
|
+
loadAudit();
|
|
1742
|
+
setInterval(refreshStatus, 15000);
|
|
1465
1743
|
</script>
|
|
1466
1744
|
</body>
|
|
1467
1745
|
</html>
|