Lines 7-49javascript
7 * event name as argv[2]:
9 * node remnic-codex-hook.cjs <event>
11 * Events: session-start | user-prompt-recall | post-tool-observe | session-end
13 * This is a faithful port of the original four bash scripts — same endpoints,
14 * env vars, token resolution, cursor/lock hardening, engram→remnic migration,
15 * daemon health/auto-start, git coding-context projectId derivation, and
16 * session-end memory materialization. Node replaces the per-script `node -e`
17 * one-liners and Unix tools (curl/git/sed/mktemp/…) so the exact same logic
18 * runs on Windows, macOS, and Linux.
20 * Fail-open everywhere: any unexpected error degrades to `{"continue":true}`.
25const fs = require("fs");
26const os = require("os");
27const path = require("path");
28const http = require("http");
29const https = require("https");
30const { execFileSync, spawn, spawnSync } = require("child_process");
31
HighChild Process
Package source references child process execution.
hooks/bin/remnic-codex-hook.cjsView on unpkg · L29 32const HOME = process.env.HOME || process.env.USERPROFILE || os.homedir();
33
HighSame File Env Network Execution
A single source file combines environment access, network access, and code or shell execution; review context before blocking.
hooks/bin/remnic-codex-hook.cjsView on unpkg · L27 34// Daemon base URL resolution (issue #1571 — remote/network parity with
35// @remnic/plugin-pi's `remnicDaemonUrl`). A full REMNIC_DAEMON_URL
36// (e.g. "http://macstudio.tailnet:4318" or "https://remnic.internal:443")
37// takes precedence and lets a Codex host talk to a shared central daemon
38// over Tailscale/LAN/VPN. The legacy REMNIC_HOST/REMNIC_PORT pair remains
39// supported as a backward-compat fallback so existing installs and the
40// test harness (which spins a mock on 127.0.0.1:<port>) keep working.
41const RAW_DAEMON_URL = process.env.REMNIC_DAEMON_URL || process.env.ENGRAM_DAEMON_URL || "";
42const HOST = process.env.REMNIC_HOST || process.env.ENGRAM_HOST || "127.0.0.1";
43const PORT = process.env.REMNIC_PORT || process.env.ENGRAM_PORT || "4318";
45// Parse once. `protocol` is "http:" or "https:" so https.request is selected
46// for TLS daemons (common for remote/private deployments behind a proxy).
48// An EXPLICIT but invalid REMNIC_DAEMON_URL (missing scheme, typo, e.g.
49// "macstudio:4318") must NOT silently fall through to REMNIC_HOST/REMNIC_PORT —