Commit 100d404
feat(ai): evidence ledger and Impressum-first lead research (#3)
The agent's only research tool was a single GET with a few regexes, and
whatever it produced went straight into the lead with no record of where
it came from — including over a value the operator had typed. This gives
it eyes and a memory of what it saw.
Evidence ledger (api/src/facts.ts, new `lead_facts` table)
Every machine-written value is now an observation carrying its source,
what the source literally said, and a grade. Only a claim the business
makes about itself fills an empty field; anything weaker, and anything
disagreeing with a hand-set value, becomes a suggestion a human accepts
or rejects. Provenance is derived rather than stored: a lead value counts
as machine-set only while it still matches an applied fact, so imports
and manual edits are untouchable. Fields the leads table has no column
for (USt-IdNr., Handelsregister, Rechtsform, Geschäftsführung) live in
the ledger and are there when the lead becomes a Kunde.
Impressum-first research (api/src/ai/research.ts)
Replaces fetch_website. Walks homepage -> Impressum and returns
observations with source URLs. §5 DDG obliges every German business site
to publish exactly the fields we want, which makes it a free primary
source. probeTech now measures mobile_friendly, tech and
staleness_signal off the markup instead of letting the model imagine
them. The SSRF guard is shared and now also covers redirect targets.
Built for the local model: create_lead({ research: true, analyze: true })
does the whole URL-to-qualified-lead path in one call, research_company
records what it observed itself rather than making a small model chain
six record_fact calls, params are flat and enum-constrained, and every
response explains why it did what it did.
MCP reaches all of it — research_company, list_lead_facts, review_facts
in the read tier; research_lead, record_fact, resolve_fact in the
reversible-write tier — over new routes under /api/ai and /api/leads.
Two bugs fixed on the way:
- analyzeLead overwrote a priority a human set by dragging a card, on
every re-run. It now only revises a priority it set itself. score is
left alone since it is the model's own fit metric and the importer
seeds it.
- decode() handled no German named entities, so `Müller` would have
been filed as a Firmenname.
UI: a Recherche & Herkunft panel in the lead drawer with the review queue
and a provenance trail.
vite.config.ts takes an API_URL override so the dev server can point at
an API on another port; the default is unchanged.
195 api + 17 cli tests pass, including HTTP integration over the Bearer
token path MCP uses. Verified in a running instance: grading correct over
the wire, accept wrote through, reject left the field alone, unreachable
site degraded cleanly.
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>1 parent 15ba14e commit 100d404
22 files changed
Lines changed: 2110 additions & 60 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
23 | 29 | | |
24 | 30 | | |
25 | 31 | | |
| |||
41 | 47 | | |
42 | 48 | | |
43 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
44 | 70 | | |
45 | 71 | | |
| 72 | + | |
46 | 73 | | |
47 | 74 | | |
48 | 75 | | |
| |||
73 | 100 | | |
74 | 101 | | |
75 | 102 | | |
| 103 | + | |
76 | 104 | | |
77 | 105 | | |
78 | 106 | | |
79 | | - | |
| 107 | + | |
80 | 108 | | |
81 | 109 | | |
82 | 110 | | |
| |||
88 | 116 | | |
89 | 117 | | |
90 | 118 | | |
91 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
92 | 134 | | |
93 | 135 | | |
94 | 136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
17 | 35 | | |
18 | 36 | | |
19 | 37 | | |
| |||
45 | 63 | | |
46 | 64 | | |
47 | 65 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
54 | 74 | | |
55 | 75 | | |
56 | 76 | | |
| |||
76 | 96 | | |
77 | 97 | | |
78 | 98 | | |
| 99 | + | |
| 100 | + | |
79 | 101 | | |
80 | 102 | | |
81 | 103 | | |
| |||
0 commit comments