Adds @magpie-community/gateway-nowledge-mem, an asynchronous gateway hook by IceCodeNew (#526): before each request it recalls from the user's Nowledge Mem (and the Context Bundle / Working Memory on a session's first turn), and, only when `capture` is turned on, imports completed conversations as Mem Threads. It applies to direct local requests and the `magpie-key` sharing key this computer writes into the user's own agents; other gateway keys, remote and unknown origins are never included. A page sets the connection and runs a real connection test through a loopback service guarded by Host, Origin and a per-start token. The package writes nothing into magpie's Library. registry.json gains one compact entry. Reviewed head 3f4ba91 (f9eb686 plus a maintainer commit adding a test that starts the service and expects 403 for a foreign Host, Origin and token). Run at 3f4ba91's tree on mote (macOS, Bun 1.4.2, HOME=$(mktemp -d)): repo `bun test` 3861 pass, 9 skip, 0 fail; `bun scripts/check.mjs` exit 0; packages/nowledge-mem 53 pass, 1 skip. Broken by hand: each of the service's four guards in handle() turns the new test red; earlier rounds broke the origin gate, the block escaping, the secret check and the cleartext-HTTP guard, each red. Not tried: a real Mem server, a real magpie with the plugin installed, Windows. Co-authored-by: IceCodeNew <32576256+IceCodeNew@users.noreply.github.com>
36 lines
1.5 KiB
JavaScript
36 lines
1.5 KiB
JavaScript
// Runs the live checks in e2e.run.mjs when NMEM_E2E=1 and a Nowledge Mem is
|
|
// configured by the repository's .env (NMEM_API_URL and NMEM_API_KEY) or the
|
|
// environment. Without both nothing is spawned and no request leaves this
|
|
// machine, so the repository's tests stay offline by default.
|
|
//
|
|
// The runner is a separate process: the offline tests replace globalThis.fetch
|
|
// (packages/cursor/nonet.mjs) to keep Cursor's token local, and a live check
|
|
// must not share that process.
|
|
import { expect, test } from "bun:test"
|
|
import { existsSync, readFileSync } from "node:fs"
|
|
import { fileURLToPath } from "node:url"
|
|
|
|
function configured() {
|
|
if (process.env.NMEM_API_URL && process.env.NMEM_API_KEY) return true
|
|
const path = fileURLToPath(new URL("../../.env", import.meta.url))
|
|
if (!existsSync(path)) return false
|
|
const text = readFileSync(path, "utf8")
|
|
return /^\s*(?:export\s+)?NMEM_API_URL\s*=\s*\S+/mu.test(text) && /^\s*(?:export\s+)?NMEM_API_KEY\s*=\s*\S+/mu.test(text)
|
|
}
|
|
|
|
const e2e = process.env.NMEM_E2E === "1" && configured() ? test : test.skip
|
|
|
|
e2e("the live Nowledge Mem checks pass", () => {
|
|
const runner = fileURLToPath(new URL("./e2e.run.mjs", import.meta.url))
|
|
const result = Bun.spawnSync({
|
|
cmd: [process.execPath, runner],
|
|
cwd: fileURLToPath(new URL(".", import.meta.url)),
|
|
stdout: "pipe",
|
|
stderr: "pipe",
|
|
timeout: 120_000,
|
|
})
|
|
const output = `${result.stdout?.toString() ?? ""}${result.stderr?.toString() ?? ""}`
|
|
if (result.exitCode !== 0) console.error(output)
|
|
expect(result.exitCode).toBe(0)
|
|
}, 240_000)
|