Compare commits
20
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f14025304e | ||
|
|
dd6d7e9395 | ||
|
|
68d478224f | ||
|
|
117f3c2cfd | ||
|
|
140d86a4b9 | ||
|
|
c96c393a4a | ||
|
|
3d0d95cf00 | ||
|
|
ed28fdbd2a | ||
|
|
7e511d5b78 | ||
|
|
0d26519fab | ||
|
|
a429b823e5 | ||
|
|
6847233183 | ||
|
|
6d7638ab73 | ||
|
|
bd1a91dab7 | ||
|
|
a5a1f91d95 | ||
|
|
80e3b7a1cf | ||
|
|
ef4189c72d | ||
|
|
60c20ed98d | ||
|
|
9f22380e82 | ||
|
|
e2eff3b9c7 |
@@ -36,9 +36,11 @@ PLAN.md decisions + execution + open questions
|
|||||||
docs/ published docs
|
docs/ published docs
|
||||||
skills/ in-project agent skills (vendored, no external links)
|
skills/ in-project agent skills (vendored, no external links)
|
||||||
bin/ self-describing tools bin/{subject}/{method}.go (shebang)
|
bin/ self-describing tools bin/{subject}/{method}.go (shebang)
|
||||||
bin/brain/ search.go, serve.go; libs in internal/brain and internal/httpapi
|
bin/brain/ search.go (deduction); libs in internal/brain
|
||||||
internal/ shared Go (brain/rank is cgo-free)
|
internal/ shared Go (brain/rank is cgo-free)
|
||||||
bin/watch/ corpus watcher (internal via bin/brain/watch later)
|
bin/serve.go async Go HTTP server entry (self-executing go run shebang)
|
||||||
|
bin/watch/ corpus watcher Go package (mtimes, no inotify deps)
|
||||||
|
bin/server/ async Go HTTP server (goroutines, bounded worker pool)
|
||||||
bin/mail/ mail pipeline: sync (Go), import (md), index_mail (rebuild)
|
bin/mail/ mail pipeline: sync (Go), import (md), index_mail (rebuild)
|
||||||
bin/tools/ vendored python libs behind bin/* (kblib, yamlout, websearch)
|
bin/tools/ vendored python libs behind bin/* (kblib, yamlout, websearch)
|
||||||
bin/docker-entrypoint container entrypoint (brain index|search|serve|watch)
|
bin/docker-entrypoint container entrypoint (brain index|search|serve|watch)
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
//usr/bin/env go run -tags=brain_serve "$0" "$@"; exit
|
|
||||||
//go:build brain_serve
|
|
||||||
//
|
|
||||||
// bin/brain/serve.go - HTTP API for the 2dph brain.
|
|
||||||
//
|
|
||||||
// KB_ROOT=/path/to/2dph ./bin/brain/serve.go
|
|
||||||
// KB_SEARCH_CMD=... KB_WORKERS=4 KB_PORT=8630 ./bin/brain/serve.go
|
|
||||||
//
|
|
||||||
// Default search backend is var/bin/brain-search (Go), not Python.
|
|
||||||
// NOTE: never run `gofmt -w` on this file — it breaks the shebang.
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/eSlider/2dph/internal/httpapi"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
if os.Getenv("KB_ROOT") == "" {
|
|
||||||
if wd, err := os.Getwd(); err == nil {
|
|
||||||
os.Setenv("KB_ROOT", wd)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
httpapi.Run()
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
// Deprecated shebang mains at bin root (serve.go is tagged brain_serve).
|
|
||||||
package main
|
|
||||||
+13
-8
@@ -1,22 +1,27 @@
|
|||||||
//usr/bin/env go run -tags=brain_serve "$0" "$@"; exit
|
//usr/bin/env go run "$0" "$@"; exit
|
||||||
//go:build brain_serve
|
// bin/serve.go - async Go HTTP server for the 2dph brain (see bin/server).
|
||||||
//
|
//
|
||||||
// bin/serve.go — deprecated; use bin/brain/serve.go.
|
// KB_ROOT=/path/to/2dph ./bin/serve.go # serve the brain
|
||||||
|
// KB_SEARCH_CMD=... KB_WORKERS=4 KB_PORT=8630 ./bin/serve.go
|
||||||
|
//
|
||||||
|
// Shebang trick: the first line is a Go `//` comment; when executed, env runs
|
||||||
|
// `go run "$0"` so this file doubles as an executable script. The real code
|
||||||
|
// lives in the importable package (module path, never a relative import).
|
||||||
|
// NOTE: never run `gofmt -w` on this file - it rewrites `//usr/bin/env` to
|
||||||
|
// `// usr/...` and breaks the shebang.
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/eSlider/2dph/internal/httpapi"
|
"github.com/eSlider/2dph/bin/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Fprintln(os.Stderr, "bin/serve.go is deprecated; use bin/brain/serve.go")
|
if env := os.Getenv("KB_ROOT"); env == "" {
|
||||||
if os.Getenv("KB_ROOT") == "" {
|
|
||||||
if wd, err := os.Getwd(); err == nil {
|
if wd, err := os.Getwd(); err == nil {
|
||||||
os.Setenv("KB_ROOT", wd)
|
os.Setenv("KB_ROOT", wd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
httpapi.Run()
|
server.Run()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,15 @@
|
|||||||
//
|
//
|
||||||
// Async by design: every request runs on its own goroutine, and CPU-heavy
|
// Async by design: every request runs on its own goroutine, and CPU-heavy
|
||||||
// searches are serialized through a bounded worker pool (a counting
|
// searches are serialized through a bounded worker pool (a counting
|
||||||
// semaphore) so N requests can't spawn N search processes at once.
|
// semaphore) so N requests can't spawn N Python interpreters at once.
|
||||||
//
|
//
|
||||||
// Used by bin/brain/serve.go.
|
// Used by bin/serve.go which is a self-executing shebang script:
|
||||||
package httpapi
|
//
|
||||||
|
// ///usr/bin/env go run "$0" "$@"; exit
|
||||||
|
// package main
|
||||||
|
// import "github.com/eSlider/2dph/bin/server"
|
||||||
|
// func main() { server.Run() }
|
||||||
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -95,8 +100,8 @@ func writeRaw(w http.ResponseWriter, code int, body []byte) {
|
|||||||
w.Write(body)
|
w.Write(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
// brainSearcher shells out to the Go brain-search binary (not Python).
|
// brainSearcher shells out to bin/kb/search --json. A single python search
|
||||||
// A single search is bounded and short-lived; the worker pool keeps at most N live.
|
// is bounded and short-lived; the worker pool keeps at most N live.
|
||||||
type brainSearcher struct {
|
type brainSearcher struct {
|
||||||
cmdPath string
|
cmdPath string
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
@@ -117,18 +122,15 @@ func (b *brainSearcher) Search(ctx context.Context, query string, limit int) ([]
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultSearchCmd(root string) string {
|
// Run starts the HTTP server. Reads env: KB_SEARCH_CMD (default bin/kb/search,
|
||||||
if env := os.Getenv("KB_SEARCH_CMD"); env != "" {
|
// relative to the repo root given by KB_ROOT), KB_WORKERS (default 4), KB_PORT
|
||||||
return env
|
// (default 8630).
|
||||||
}
|
|
||||||
return filepath.Join(root, "var", "bin", "brain-search")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run starts the HTTP server. Reads env: KB_SEARCH_CMD (default
|
|
||||||
// $KB_ROOT/var/bin/brain-search), KB_WORKERS (default 4), KB_PORT (default 8630).
|
|
||||||
func Run() {
|
func Run() {
|
||||||
root := os.Getenv("KB_ROOT")
|
root := os.Getenv("KB_ROOT")
|
||||||
searchPath := defaultSearchCmd(root)
|
searchPath := os.Getenv("KB_SEARCH_CMD")
|
||||||
|
if searchPath == "" {
|
||||||
|
searchPath = filepath.Join(root, "bin", "kb", "search")
|
||||||
|
}
|
||||||
workers := 4
|
workers := 4
|
||||||
if raw := os.Getenv("KB_WORKERS"); raw != "" {
|
if raw := os.Getenv("KB_WORKERS"); raw != "" {
|
||||||
if n, err := strconv.Atoi(raw); err == nil && n > 0 {
|
if n, err := strconv.Atoi(raw); err == nil && n > 0 {
|
||||||
@@ -145,7 +147,7 @@ func Run() {
|
|||||||
searcher := &brainSearcher{cmdPath: searchPath, timeout: 60 * time.Second}
|
searcher := &brainSearcher{cmdPath: searchPath, timeout: 60 * time.Second}
|
||||||
handler := NewServer(searcher, workers)
|
handler := NewServer(searcher, workers)
|
||||||
addr := "127.0.0.1:" + strconv.Itoa(port)
|
addr := "127.0.0.1:" + strconv.Itoa(port)
|
||||||
log.Printf("serve: %s (workers=%d cmd=%s)", addr, workers, searchPath)
|
log.Printf("serve: %s (workers=%d)", addr, workers)
|
||||||
if err := http.ListenAndServe(addr, handler); err != nil {
|
if err := http.ListenAndServe(addr, handler); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
package httpapi
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -142,17 +141,6 @@ func TestSearchRejectsBadLimit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultSearchCmdIsBrainNotPython(t *testing.T) {
|
|
||||||
t.Setenv("KB_SEARCH_CMD", "")
|
|
||||||
cmd := defaultSearchCmd("/repo")
|
|
||||||
if strings.Contains(strings.ToLower(cmd), "python") {
|
|
||||||
t.Fatalf("search path still python: %s", cmd)
|
|
||||||
}
|
|
||||||
if !strings.Contains(cmd, "brain") {
|
|
||||||
t.Fatalf("search path must be the Go brain binary, got %s", cmd)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSearchTimeout(t *testing.T) {
|
func TestSearchTimeout(t *testing.T) {
|
||||||
fs := &fakeSearcher{delay: time.Second}
|
fs := &fakeSearcher{delay: time.Second}
|
||||||
h := NewServer(fs, 1)
|
h := NewServer(fs, 1)
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
# CRM association proof (oo CLI ↔ corpus)
|
|
||||||
|
|
||||||
Proven with `oo` (eslider/go-onlyoffice) against the OnlyOffice portal
|
|
||||||
(`office.produktor.io`). Portal CRM is the SSOT for company ↔ person ↔
|
|
||||||
project associations; the corpus SoT (`eslider/cv/projects/knowledge-mesh-seed.yaml`)
|
|
||||||
is the second, independent source. Facts that can be backed by both are
|
|
||||||
written to the brain under `root=facts` by `bin/facts/crm`.
|
|
||||||
|
|
||||||
## What was verified
|
|
||||||
|
|
||||||
- Logical counts (portal MySQL): 1300 contacts = 897 persons + 404 companies,
|
|
||||||
198 projects, 998 deals, 939 project↔contact links.
|
|
||||||
- Every client company linked to a project has ≥1 person underneath.
|
|
||||||
- Every person `company_id` resolves to an existing company.
|
|
||||||
- Corpus org list (9) maps 1:1 onto CRM companies:
|
|
||||||
ProProdukt SL / produktor.io, Dyvenia, Immowelt AG, WhereGroup,
|
|
||||||
Keynote SIGOS, D2S/SYSTEMS, GRID, Pack und Cup, Markets Platform.
|
|
||||||
- 78 person↔company association facts written to the brain
|
|
||||||
(`how=crm-crosscheck`, `type=association`). Recall@5 in `bin/kb/eval` = 1.0.
|
|
||||||
|
|
||||||
## Mistakes found
|
|
||||||
|
|
||||||
| # | Mistake | Fix |
|
|
||||||
|---|---------|-----|
|
|
||||||
| 1 | Duplicate legal entity `GoldenRatio.Exchange` (contact 759) vs `Golden Ratio Exchange` (763); 3 deals (211, 287, 559) were linked to 759 | `oo contacts merge 759 763` — 763 kept, 759 removed, deal links re-pointed to 763 |
|
|
||||||
| 2 | `env/`-wide: OnlyOffice creds file used wrong UX (user `eslider`, password with `$2` suffix) making `oo` auth fail | `.env` fixed to `eslider@gmail.com` + clean password; `.env` stays gitignored |
|
|
||||||
|
|
||||||
## Gates after fix
|
|
||||||
|
|
||||||
- `uv run python -m unittest discover -s bin/tools -t .` → 26 tests OK
|
|
||||||
- `bin/facts/audit self` + `bin/facts/audit db` → ok
|
|
||||||
- `bin/kb/eval` → recall@5 = 1.0
|
|
||||||
- `go test ./...` (bin/server + bin/watch) → ok
|
|
||||||
Reference in New Issue
Block a user