|
|
|
@@ -147,7 +147,7 @@ step "Phase 1 — preflight checks"
|
|
|
|
|
|
|
|
|
|
need() { command -v "$1" >/dev/null 2>&1 || MISSING+=" $1"; }
|
|
|
|
|
MISSING=""
|
|
|
|
|
need git; need cc; need curl; need python3; need security; need launchctl
|
|
|
|
|
need git; need cc; need curl; need python3; need security; need launchctl; need jq
|
|
|
|
|
if [ -n "$MISSING" ]; then
|
|
|
|
|
warn "Missing tools:${MISSING}"
|
|
|
|
|
if command -v brew >/dev/null 2>&1; then
|
|
|
|
@@ -175,13 +175,16 @@ elif [ -n "${ANTHROPIC_API_KEY:-}" ]; then
|
|
|
|
|
else
|
|
|
|
|
if [ "$DRY_RUN" = 1 ]; then
|
|
|
|
|
echo " [dry-run] would prompt for Anthropic API key and store in Keychain"
|
|
|
|
|
else
|
|
|
|
|
elif [ -t 0 ]; then
|
|
|
|
|
echo " Enter your Anthropic API key (input hidden). Get one at https://console.anthropic.com/"
|
|
|
|
|
read -r -s -p " ANTHROPIC_API_KEY: " _key; echo
|
|
|
|
|
[ -n "$_key" ] || die "No key entered. Re-run when you have one."
|
|
|
|
|
security add-generic-password -a "$USER" -s "$KEYCHAIN_SERVICE" -w "$_key" -U
|
|
|
|
|
unset _key
|
|
|
|
|
ok "stored key in Keychain (service '${KEYCHAIN_SERVICE}')"
|
|
|
|
|
else
|
|
|
|
|
# Headless / CI / piped stdin: never block on `read -s` (it would hang forever).
|
|
|
|
|
die "No Anthropic API key and stdin is not a TTY (headless/CI). Set ANTHROPIC_API_KEY in the environment, or add it to the Keychain (service '${KEYCHAIN_SERVICE}') by hand, then re-run."
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
@@ -207,14 +210,15 @@ elif [ "$USE_LOCAL_BINARIES" = 1 ]; then
|
|
|
|
|
else
|
|
|
|
|
clone_or_pull "${NEURON_REPO_URL}" "$NEURON_REPO" "$NEURON_REPO_BRANCH"
|
|
|
|
|
clone_or_pull "${ENGRAM_REPO_URL}" "$ENGRAM_REPO" "main"
|
|
|
|
|
clone_or_pull "${FOUNDATION_REPO_URL}" "$FOUNDATION_REPO" "main"
|
|
|
|
|
# NOTE: no foundation.git — that repo does not exist. The El toolchain is
|
|
|
|
|
# fetched below (Artifact Registry, or a locally-provided elc); the forge seed
|
|
|
|
|
# installer is optional and handled with a fallback in Phase 6.
|
|
|
|
|
|
|
|
|
|
# ── El toolchain (needed to transpile .el -> .c for engram/wrapper/proxy) ──
|
|
|
|
|
# soul does NOT need this: dist/soul.c is committed and compiled directly.
|
|
|
|
|
EL_RUNTIME_DIR="${DEV_ROOT}/.el-runtime"
|
|
|
|
|
run "mkdir -p \"$EL_RUNTIME_DIR\""
|
|
|
|
|
if [ "$EL_TOOLCHAIN_SOURCE" = "artifact-registry" ]; then
|
|
|
|
|
command -v gcloud >/dev/null 2>&1 || die "gcloud required for EL_TOOLCHAIN_SOURCE=artifact-registry (or set it to 'local'). Ask Will for GCP access to project ${GCP_PROJECT}."
|
|
|
|
|
if [ "$EL_TOOLCHAIN_SOURCE" = "artifact-registry" ] && command -v gcloud >/dev/null 2>&1; then
|
|
|
|
|
# Mirrors .gitea/workflows/ci.yaml: pull el-runtime-c, el-runtime-h, el-elc.
|
|
|
|
|
for pkg in el-runtime-c el-runtime-h el-elc; do
|
|
|
|
|
step "fetching $pkg from Artifact Registry"
|
|
|
|
@@ -224,41 +228,58 @@ else
|
|
|
|
|
run "mv \"$EL_RUNTIME_DIR\"/el_runtime.h* \"$EL_RUNTIME_DIR/el_runtime.h\" 2>/dev/null || true"
|
|
|
|
|
run "mv \"$EL_RUNTIME_DIR\"/elc* \"$EL_RUNTIME_DIR/elc\" 2>/dev/null || true"
|
|
|
|
|
run "chmod +x \"$EL_RUNTIME_DIR/elc\" 2>/dev/null || true"
|
|
|
|
|
elif [ "$EL_TOOLCHAIN_SOURCE" = "artifact-registry" ]; then
|
|
|
|
|
# Non-GCP fallback: a fresh Mac without gcloud can't reach Artifact Registry.
|
|
|
|
|
# Don't die — soul (from committed dist/soul.c) still builds below. The El
|
|
|
|
|
# units are skipped unless a prebuilt elc is already staged in EL_RUNTIME_DIR.
|
|
|
|
|
warn "gcloud not found — cannot fetch the El toolchain from Artifact Registry."
|
|
|
|
|
warn "Continuing without it: soul will still build. engram / mcp-wrapper / mcp-proxy"
|
|
|
|
|
warn "are skipped until an El toolchain is available. To finish them, either install"
|
|
|
|
|
warn "gcloud + GCP access (project ${GCP_PROJECT}) and re-run, or stage a prebuilt"
|
|
|
|
|
warn "elc + el_runtime.{c,h} in ${EL_RUNTIME_DIR} and set EL_TOOLCHAIN_SOURCE=local."
|
|
|
|
|
else
|
|
|
|
|
# Local: build the El compiler + runtime from the foundation/el checkout.
|
|
|
|
|
# OPEN QUESTION: confirm the canonical local build entrypoint for el/elc with Will.
|
|
|
|
|
warn "EL_TOOLCHAIN_SOURCE=local: expecting el_runtime.{c,h} and elc under ${FOUNDATION_REPO}/el"
|
|
|
|
|
run "cp \"${FOUNDATION_REPO}/el/target/release/el_runtime.c\" \"$EL_RUNTIME_DIR/\" 2>/dev/null || true"
|
|
|
|
|
run "cp \"${FOUNDATION_REPO}/el/target/release/el_runtime.h\" \"$EL_RUNTIME_DIR/\" 2>/dev/null || true"
|
|
|
|
|
run "cp \"${FOUNDATION_REPO}/el/target/release/elc\" \"$EL_RUNTIME_DIR/\" 2>/dev/null || true"
|
|
|
|
|
# Local: expect a prebuilt El runtime + elc already staged in EL_RUNTIME_DIR
|
|
|
|
|
# (foundation.git no longer exists, so there is nothing to build from here).
|
|
|
|
|
warn "EL_TOOLCHAIN_SOURCE=local: expecting el_runtime.{c,h} and elc already in ${EL_RUNTIME_DIR}"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
RT="$EL_RUNTIME_DIR"
|
|
|
|
|
CFLAGS_SSL="-I$(brew --prefix openssl@3 2>/dev/null)/include"
|
|
|
|
|
LDFLAGS_SSL="-L$(brew --prefix openssl@3 2>/dev/null)/lib"
|
|
|
|
|
|
|
|
|
|
# ── soul: compile committed dist/soul.c directly (verified CI recipe) ──────
|
|
|
|
|
step "building soul (dist/soul.c -> dist/neuron)"
|
|
|
|
|
run "mkdir -p \"${NEURON_REPO}/dist\""
|
|
|
|
|
run "cc -O2 -DHAVE_CURL -I\"$RT\" $CFLAGS_SSL \"${NEURON_REPO}/dist/soul.c\" \"$RT/el_runtime.c\" $LDFLAGS_SSL -lssl -lcrypto -lcurl -lpthread -lm -o \"$SOUL_BIN\""
|
|
|
|
|
run "strip -S \"$SOUL_BIN\" 2>/dev/null || true"
|
|
|
|
|
ok "soul built"
|
|
|
|
|
# Every native build links el_runtime.c. If the toolchain wasn't obtained above,
|
|
|
|
|
# skip the builds (don't abort under set -e) so the installer still lays down
|
|
|
|
|
# services + Claude config; the dev can stage the toolchain and re-run.
|
|
|
|
|
if [ "$DRY_RUN" = 1 ] || [ -f "$RT/el_runtime.c" ]; then
|
|
|
|
|
# ── soul: compile committed dist/soul.c directly (verified CI recipe) ──────
|
|
|
|
|
step "building soul (dist/soul.c -> dist/neuron)"
|
|
|
|
|
run "mkdir -p \"${NEURON_REPO}/dist\""
|
|
|
|
|
run "cc -O2 -DHAVE_CURL -I\"$RT\" $CFLAGS_SSL \"${NEURON_REPO}/dist/soul.c\" \"$RT/el_runtime.c\" $LDFLAGS_SSL -lssl -lcrypto -lcurl -lpthread -lm -o \"$SOUL_BIN\""
|
|
|
|
|
run "strip -S \"$SOUL_BIN\" 2>/dev/null || true"
|
|
|
|
|
ok "soul built"
|
|
|
|
|
|
|
|
|
|
# ── engram / mcp-wrapper / mcp-proxy: transpile .el -> .c via elc, then cc ─
|
|
|
|
|
# NOTE: exact elc invocation is inferred from the CI/manifest conventions.
|
|
|
|
|
# Verify flags with Will if a build fails (see README OPEN QUESTIONS).
|
|
|
|
|
build_el_unit() { # <src.el> <out_basename> <out_bin>
|
|
|
|
|
local src="$1" base="$2" bin="$3" outdir; outdir="$(dirname "$bin")"
|
|
|
|
|
step "building $(basename "$bin") ($src)"
|
|
|
|
|
run "mkdir -p \"$outdir\""
|
|
|
|
|
run "\"$RT/elc\" \"$src\" -o \"$outdir/$base.c\""
|
|
|
|
|
run "cc -O2 -DHAVE_CURL -I\"$RT\" $CFLAGS_SSL \"$outdir/$base.c\" \"$RT/el_runtime.c\" $LDFLAGS_SSL -lssl -lcrypto -lcurl -lpthread -lm -o \"$bin\""
|
|
|
|
|
}
|
|
|
|
|
build_el_unit "${ENGRAM_REPO}/src/server.el" "server" "$ENGRAM_BIN"
|
|
|
|
|
build_el_unit "${NEURON_REPO}/mcp-wrapper/src/main.el" "main" "$MCP_WRAPPER_BIN"
|
|
|
|
|
build_el_unit "${NEURON_REPO}/mcp-proxy/src/main.el" "main" "$MCP_PROXY_BIN"
|
|
|
|
|
build_el_unit "${FOUNDATION_REPO}/forge/src/forge.el" "forge" "$FORGE_BIN"
|
|
|
|
|
ok "engram, mcp-wrapper, mcp-proxy, forge built"
|
|
|
|
|
# ── engram / mcp-wrapper / mcp-proxy: transpile .el -> .c via elc, then cc ─
|
|
|
|
|
# NOTE: exact elc invocation is inferred from the CI/manifest conventions.
|
|
|
|
|
# Verify flags with Will if a build fails (see README OPEN QUESTIONS).
|
|
|
|
|
build_el_unit() { # <src.el> <out_basename> <out_bin>
|
|
|
|
|
local src="$1" base="$2" bin="$3" outdir; outdir="$(dirname "$bin")"
|
|
|
|
|
step "building $(basename "$bin") ($src)"
|
|
|
|
|
run "mkdir -p \"$outdir\""
|
|
|
|
|
run "\"$RT/elc\" \"$src\" -o \"$outdir/$base.c\""
|
|
|
|
|
run "cc -O2 -DHAVE_CURL -I\"$RT\" $CFLAGS_SSL \"$outdir/$base.c\" \"$RT/el_runtime.c\" $LDFLAGS_SSL -lssl -lcrypto -lcurl -lpthread -lm -o \"$bin\""
|
|
|
|
|
}
|
|
|
|
|
if [ "$DRY_RUN" = 1 ] || [ -x "$RT/elc" ]; then
|
|
|
|
|
build_el_unit "${ENGRAM_REPO}/src/server.el" "server" "$ENGRAM_BIN"
|
|
|
|
|
build_el_unit "${NEURON_REPO}/mcp-wrapper/src/main.el" "main" "$MCP_WRAPPER_BIN"
|
|
|
|
|
build_el_unit "${NEURON_REPO}/mcp-proxy/src/main.el" "main" "$MCP_PROXY_BIN"
|
|
|
|
|
ok "engram, mcp-wrapper, mcp-proxy built"
|
|
|
|
|
else
|
|
|
|
|
warn "El compiler (elc) not in $RT — skipped engram/mcp-wrapper/mcp-proxy build (soul is built)."
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
warn "El runtime (el_runtime.c) not in $RT — skipping native builds (soul, engram, wrapper, proxy)."
|
|
|
|
|
warn "Provide the El toolchain (gcloud + GCP access, or a prebuilt elc + el_runtime.{c,h} in $RT), then re-run."
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# ─────────────────────────────────────────────────────────────────────────────
|
|
|
|
@@ -307,10 +328,10 @@ if [ "$DRY_RUN" = 1 ]; then
|
|
|
|
|
else
|
|
|
|
|
# Wait for engram to be listening (up to ~30s).
|
|
|
|
|
for i in $(seq 1 30); do
|
|
|
|
|
if curl -fsS "http://localhost:${ENGRAM_PORT}/api/health" >/dev/null 2>&1; then break; fi
|
|
|
|
|
if curl -fsS "http://localhost:${ENGRAM_PORT}/health" >/dev/null 2>&1; then break; fi
|
|
|
|
|
sleep 1
|
|
|
|
|
done
|
|
|
|
|
if curl -fsS "http://localhost:${ENGRAM_PORT}/api/health" >/dev/null 2>&1; then
|
|
|
|
|
if curl -fsS "http://localhost:${ENGRAM_PORT}/health" >/dev/null 2>&1; then
|
|
|
|
|
# Skip if identity root already present (idempotent).
|
|
|
|
|
if curl -fsS "http://localhost:${ENGRAM_PORT}/api/nodes/kn-efeb4a5b-5aff-4759-8a97-7233099be6ee" \
|
|
|
|
|
-H "Authorization: Bearer ${ENGRAM_API_KEY}" 2>/dev/null | grep -q 'kn-efeb4a5b'; then
|
|
|
|
@@ -344,19 +365,44 @@ for h in neuron-self-load.sh neuron-agent-preamble.sh pre-compact.sh; do
|
|
|
|
|
done
|
|
|
|
|
ok "installed core hooks (self-load, agent-preamble, pre-compact)"
|
|
|
|
|
|
|
|
|
|
# 7c. local MCP registration -> mcp-proxy front door
|
|
|
|
|
# 7c. local MCP registration -> mcp-proxy front door.
|
|
|
|
|
# Claude Code reads MCP servers from ~/.claude.json (the "mcpServers" key), NOT
|
|
|
|
|
# ~/.claude/mcp.json. Render a reference copy, then jq-merge just the "neuron"
|
|
|
|
|
# entry into ~/.claude.json so we preserve every other server and top-level key.
|
|
|
|
|
render "${TEMPLATES}/claude/mcp.json.tmpl" "${CLAUDE_DIR}/mcp.json.neuron"
|
|
|
|
|
if [ -f "${CLAUDE_DIR}/mcp.json" ] && grep -q '"neuron"' "${CLAUDE_DIR}/mcp.json" 2>/dev/null; then
|
|
|
|
|
ok "~/.claude/mcp.json already registers 'neuron' — wrote reference copy mcp.json.neuron"
|
|
|
|
|
CLAUDE_JSON="${HOME}/.claude.json"
|
|
|
|
|
if [ "$DRY_RUN" = 1 ]; then
|
|
|
|
|
echo " [dry-run] merge mcpServers.neuron into ${CLAUDE_JSON} (jq deep-merge)"
|
|
|
|
|
else
|
|
|
|
|
run "cp \"${CLAUDE_DIR}/mcp.json.neuron\" \"${CLAUDE_DIR}/mcp.json\""
|
|
|
|
|
ok "wrote ~/.claude/mcp.json (neuron -> http://127.0.0.1:${PROXY_PORT}/)"
|
|
|
|
|
[ -f "$CLAUDE_JSON" ] || echo '{}' > "$CLAUDE_JSON"
|
|
|
|
|
_tmp="$(mktemp)"
|
|
|
|
|
if jq -s '.[0] * .[1]' "$CLAUDE_JSON" "${CLAUDE_DIR}/mcp.json.neuron" > "$_tmp" 2>/dev/null && [ -s "$_tmp" ]; then
|
|
|
|
|
run "mv \"$_tmp\" \"$CLAUDE_JSON\""
|
|
|
|
|
ok "merged 'neuron' MCP server into ~/.claude.json (neuron -> http://127.0.0.1:${PROXY_PORT}/)"
|
|
|
|
|
else
|
|
|
|
|
rm -f "$_tmp"
|
|
|
|
|
warn "could not jq-merge ~/.claude.json (invalid JSON?) — add 'neuron' from ~/.claude/mcp.json.neuron by hand"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# 7d. settings hooks — write a reference; ask user to merge if they already have settings
|
|
|
|
|
# 7d. settings hooks — merge the neuron hooks into any existing ~/.claude/settings.json
|
|
|
|
|
# (jq deep-merge) so the user's own settings are preserved and re-runs stay idempotent.
|
|
|
|
|
if [ -f "${CLAUDE_DIR}/settings.json" ]; then
|
|
|
|
|
run "cp \"${TEMPLATES}/claude/settings.core.json\" \"${CLAUDE_DIR}/settings.core.json\""
|
|
|
|
|
warn "~/.claude/settings.json exists — wrote settings.core.json for you to merge the 'hooks' block"
|
|
|
|
|
if [ "$DRY_RUN" = 1 ]; then
|
|
|
|
|
echo " [dry-run] merge neuron hooks from settings.core.json into ~/.claude/settings.json (jq)"
|
|
|
|
|
else
|
|
|
|
|
_tmp="$(mktemp)"
|
|
|
|
|
# Drop the documentation-only "//..." keys before merging into the real file.
|
|
|
|
|
if jq -s '.[0] * (.[1] | with_entries(select(.key | startswith("//") | not)))' \
|
|
|
|
|
"${CLAUDE_DIR}/settings.json" "${TEMPLATES}/claude/settings.core.json" > "$_tmp" 2>/dev/null && [ -s "$_tmp" ]; then
|
|
|
|
|
run "mv \"$_tmp\" \"${CLAUDE_DIR}/settings.json\""
|
|
|
|
|
ok "merged neuron hooks into existing ~/.claude/settings.json"
|
|
|
|
|
else
|
|
|
|
|
rm -f "$_tmp"
|
|
|
|
|
warn "could not jq-merge ~/.claude/settings.json — merge the 'hooks' block from settings.core.json by hand"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
run "cp \"${TEMPLATES}/claude/settings.core.json\" \"${CLAUDE_DIR}/settings.json\""
|
|
|
|
|
ok "wrote ~/.claude/settings.json"
|
|
|
|
@@ -374,7 +420,7 @@ else
|
|
|
|
|
if curl -fsS --max-time 4 "$2" >/dev/null 2>&1; then ok "$1 healthy ($2)"; else warn "$1 NOT responding ($2)"; fi
|
|
|
|
|
}
|
|
|
|
|
sleep 3
|
|
|
|
|
check "engram" "http://localhost:${ENGRAM_PORT}/api/health"
|
|
|
|
|
check "engram" "http://localhost:${ENGRAM_PORT}/health"
|
|
|
|
|
check "soul" "http://localhost:${SOUL_PORT}/health"
|
|
|
|
|
check "mcp-wrapper" "http://localhost:${WRAPPER_PORT}/health"
|
|
|
|
|
check "mcp-proxy" "http://localhost:${PROXY_PORT}/health"
|
|
|
|
@@ -385,7 +431,7 @@ echo "${c_grn}━━━━━━━━━━━━━━━━━━━━━━
|
|
|
|
|
echo "${c_grn} Neuron core dev stack install complete.${c_off}"
|
|
|
|
|
echo "${c_grn}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${c_off}"
|
|
|
|
|
echo " Verify by hand:"
|
|
|
|
|
echo " curl http://localhost:${ENGRAM_PORT}/api/health"
|
|
|
|
|
echo " curl http://localhost:${ENGRAM_PORT}/health"
|
|
|
|
|
echo " curl http://localhost:${SOUL_PORT}/health"
|
|
|
|
|
echo " curl http://localhost:${PROXY_PORT}/health"
|
|
|
|
|
echo " launchctl list | grep ai.neuron"
|
|
|
|
|