mirror of
https://github.com/hanzoai/cloud.git
synced 2026-11-17 16:36:24 +00:00
`go build ./cmd/cloud` failed on a fresh clone: the feature-flag evaluator linked a Rust staticlib nobody had built, and there were no make targets at all. The evaluator moves behind `-tags flags_native`, because cgo is on by default and already links C — only an explicit tag can mean "the Rust archive exists". Cold build now takes 37s and needs nothing but Go. The encryption refusal contradicted itself. It offered "or run a pure-Go dev build" as the way out while running ON one, having just logged that encryption was off. Both statements came from a time when !cgo meant "cannot encrypt"; hanzoai/sqlite reports EncryptionAvailable() == true under both build tags now, so the pure-Go build is exactly as capable and exactly as refusing. The route is deleted, not the refusal — a build that CAN encrypt and has no key must keep failing closed. `make dev` mints a real key instead of an exemption, so the laptop runs the production path. Three local apps, every route a typed op: base (documents), tasks (a durable queue with atomic lease/ack), functions (registry + runner, STAGED because it executes code). No kv and no sql — base is already both, and two more doors onto one room would be two more names to keep in agreement. Typed ops are the reason /mcp answers at all. zip projects its op registry into MCP, the schema'd OpenAPI document and the call plane, but it does that from Listen, which runs after the console catch-all is registered — so the endpoint existed and still 404'd. Prepare() moves ahead of the catch-all. 19 MCP tools and 22 JSON schemas where there were none, because there were zero typed ops in this tree before. Plugins build on first request instead of at boot. The manifest is still validated at boot — a typo must not wait for traffic — but a plugin whose source is missing no longer takes the whole binary down with it. The console is embedded and served at /, through a serveFS that takes an fs.FS so the serving code stays single. A /v1 miss is still JSON: a client expecting JSON never receives an HTML shell. PORT is read when CLOUD_LISTEN says nothing. It was the first thing everyone tried and the one thing that did nothing. .githooks/pre-push refuses any push to origin carrying commits or imports from the private edition. It treats every refs/remotes namespace that is not origin as private, which catches forgeall/* and incx/* — leftovers from removed remotes holding thousands of private commits that an enumerated list misses.
64 lines
2.2 KiB
Go
64 lines
2.2 KiB
Go
//go:build cgo && flags_native
|
|
|
|
package flags
|
|
|
|
// The native evaluator — hanzo-flags (native/flags), a stateless Rust staticlib
|
|
// with PostHog-compatible semantics (rollout hash, property operators, variants,
|
|
// payloads), embedded over FFI. Evaluation is a pure in-memory function of
|
|
// (definitions JSON, context JSON): no KV, no network, no state — SQLite-backed
|
|
// definitions come from the Go side and the result returns in microseconds.
|
|
//
|
|
// Build: `make native` (cargo build --release -p hanzo-flags) produces
|
|
// native/flags/target/release/libhanzo_flags.a, then build the binary with
|
|
// `-tags flags_native` to link it — `make build TAGS=flags_native` does both.
|
|
//
|
|
// It is behind a tag rather than behind cgo because those are different
|
|
// questions. cgo is on in a default build and already links C (SQLCipher), so
|
|
// "cgo" cannot mean "the Rust archive exists"; only an explicit tag can. Without
|
|
// the tag engine_stub.go supplies the fallback and a fresh clone builds with no
|
|
// Rust toolchain installed.
|
|
|
|
/*
|
|
#cgo LDFLAGS: ${SRCDIR}/../../native/flags/target/release/libhanzo_flags.a
|
|
#cgo linux LDFLAGS: -lm -ldl -lpthread
|
|
#include <stdlib.h>
|
|
|
|
extern char* hanzo_flags_evaluate(const char* defs, const char* ctx);
|
|
extern void hanzo_flags_free(char* s);
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"unsafe"
|
|
)
|
|
|
|
// engineAvailable reports whether the native evaluator is linked in.
|
|
const engineAvailable = true
|
|
|
|
// engineEvaluate runs the native evaluator over one definitions array and one
|
|
// evaluation context (both JSON) and returns the PostHog-shaped response.
|
|
func engineEvaluate(defsJSON, ctxJSON []byte) (json.RawMessage, error) {
|
|
cDefs := C.CString(string(defsJSON))
|
|
defer C.free(unsafe.Pointer(cDefs))
|
|
cCtx := C.CString(string(ctxJSON))
|
|
defer C.free(unsafe.Pointer(cCtx))
|
|
|
|
out := C.hanzo_flags_evaluate(cDefs, cCtx)
|
|
if out == nil {
|
|
return nil, fmt.Errorf("flags: native evaluator returned nil")
|
|
}
|
|
defer C.hanzo_flags_free(out)
|
|
res := []byte(C.GoString(out))
|
|
|
|
// The engine reports failures as {"error": "..."} — surface them as errors.
|
|
var probe struct {
|
|
Error string `json:"error"`
|
|
}
|
|
if err := json.Unmarshal(res, &probe); err == nil && probe.Error != "" {
|
|
return nil, fmt.Errorf("flags: %s", probe.Error)
|
|
}
|
|
return json.RawMessage(res), nil
|
|
}
|