Phase 2 part 4: discovery per signal (Claude web search, explee.com)

Each signal's page can search for organizations that show it, by hand or
every 7, 14 or 30 days. Claude with the web_search_20260209 server tool
(pause_turn resumed) works from the signal's "How to spot it" lines and
the profile's targets; a company is kept only if its evidence URL was
among the pages searched. explee.com's company search runs the signal's
description in the target sizes, scored against the hypothesis, keeping
strong matches. Our sites, the inventory, existing prospects, CRM
Accounts and suppressed domains are left out. New companies go to Review
tagged with the signal. Schema 8 adds discovery_runs (counts, searches,
why companies were left out) and the signal's schedule and explee.com
description.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 18:27:35 -07:00
co-authored by Claude Opus 5.5
parent b025a97e4a
commit 157902f7e2
15 changed files with 1234 additions and 15 deletions
+83 -5
View File
@@ -4,6 +4,7 @@
package explee
import (
"bytes"
"context"
"encoding/json"
"errors"
@@ -42,10 +43,30 @@ func (c *Client) get(ctx context.Context, path string, q url.Values, out any) er
if len(q) > 0 {
u += "?" + q.Encode()
}
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil)
return c.do(ctx, http.MethodGet, u, nil, out)
}
func (c *Client) post(ctx context.Context, path string, body, out any) error {
raw, err := json.Marshal(body)
if err != nil {
return err
}
return c.do(ctx, http.MethodPost, c.base+path, raw, out)
}
func (c *Client) do(ctx context.Context, method, u string, body []byte, out any) error {
path := strings.TrimPrefix(u, c.base)
var rd io.Reader
if body != nil {
rd = bytes.NewReader(body)
}
req, err := http.NewRequestWithContext(ctx, method, u, rd)
if err != nil {
return err
}
if body != nil {
req.Header.Set("Content-Type", "application/json")
}
req.Header.Set("X-API-Key", c.key)
req.Header.Set("Accept", "application/json")
res, err := c.http.Do(req)
@@ -53,17 +74,20 @@ func (c *Client) get(ctx context.Context, path string, q url.Values, out any) er
return err
}
defer res.Body.Close()
body, err := io.ReadAll(io.LimitReader(res.Body, 32<<20))
raw, err := io.ReadAll(io.LimitReader(res.Body, 32<<20))
if err != nil {
return err
}
if res.StatusCode == http.StatusUnauthorized || res.StatusCode == http.StatusForbidden {
return ErrUnauthorized
}
if res.StatusCode != http.StatusOK {
return fmt.Errorf("explee.com %s: HTTP %d: %s", path, res.StatusCode, strings.TrimSpace(string(body[:min(len(body), 300)])))
if res.StatusCode == http.StatusPaymentRequired {
return errors.New("explee.com needs a positive credit balance for searches (HTTP 402)")
}
return json.Unmarshal(body, out)
if res.StatusCode != http.StatusOK {
return fmt.Errorf("explee.com %s: HTTP %d: %s", path, res.StatusCode, strings.TrimSpace(string(raw[:min(len(raw), 300)])))
}
return json.Unmarshal(raw, out)
}
// Me checks the key; it returns the key owner's email or name.
@@ -203,3 +227,57 @@ func (c *Client) HotLeads(ctx context.Context, since time.Time) ([]HotLead, erro
}
return all, nil
}
// CompanySearch asks for companies that do something, optionally scored
// against criteria. The first 10 results of a search are free.
type CompanySearch struct {
Definition string // what the companies do, in plain words
Criteria []string // each company is scored 0-5 against these
SizeMin int // employees; 0: no limit
SizeMax int
PageSize int // 10 stays in the free results
}
// Company is one search result.
type Company struct {
Name string `json:"name"`
Domain string `json:"domain"`
URL string `json:"url"`
Description string `json:"description"`
Industry string `json:"industry"`
Geo string `json:"geo"`
GeoCity string `json:"geo_city"`
Size *int `json:"size"`
LinkedInID *int64 `json:"linkedin_id"`
Criteria map[string]struct {
Score float64 `json:"score"`
Reasoning string `json:"reasoning"`
} `json:"criteria"`
Match *int `json:"match"` // 1 no match, 2 weak, 3 strong (with criteria)
}
// SearchCompanies runs a company search.
func (c *Client) SearchCompanies(ctx context.Context, s CompanySearch) ([]Company, error) {
filters := map[string]any{"definition": s.Definition}
if len(s.Criteria) > 0 {
filters["criteria"] = s.Criteria
}
if s.SizeMin > 0 || s.SizeMax > 0 {
size := map[string]int{}
if s.SizeMin > 0 {
size["min"] = s.SizeMin
}
if s.SizeMax > 0 {
size["max"] = s.SizeMax
}
filters["size"] = size
}
if s.PageSize <= 0 {
s.PageSize = 10
}
var out struct {
Companies []Company `json:"companies"`
}
err := c.post(ctx, "/search/companies", map[string]any{"filters": filters, "page": 1, "page_size": s.PageSize}, &out)
return out.Companies, err
}