Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@

# AGENTMEMORY_AUTO_COMPRESS=true # Run LLM-written compression on every observation batch. Requires BOTH this flag and a configured provider; a provider alone leaves synthetic compression active.
# AGENTMEMORY_INJECT_CONTEXT=true # Opt in to Claude-style hook context injection. Pi/OMP use 1 in their launch environment for file enrichment; native prompt recall is independent.
# AGENTMEMORY_ENRICH_TIMEOUT_MS=2000 # How long the PreToolUse hook waits for /agentmemory/enrich before it gives up and adds no context. Default 2000 ms. Raise it when enrich replies arrive after the hook has given up.
# AGENTMEMORY_ENRICH_TIMEOUT_MS=2000 # PreToolUse hook wait (default 2000 ms). Set this in the hook process environment; setting it only in this server env file does not change the hook timeout.
# CONSOLIDATION_ENABLED=false # Disable the consolidation pipeline. Otherwise enabled when an LLM provider is configured, unless AGENTMEMORY_PROVIDER=noop.
# CONSOLIDATION_DECAY_DAYS=30 # Age (days) after which non-reinforced memories decay during consolidation
# GRAPH_EXTRACTION_ENABLED=true # Extract concept-graph edges on remember; powers the graph-traversal recall path
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
engine_pin=$(node --import tsx --input-type=module -e 'import { III_PINNED_VERSION } from "./src/version.ts"; console.log(III_PINNED_VERSION)')
engine_bin="$HOME/.cache/agentmemory-release-gate/iii-${engine_pin}-linux-x64"
test -x "$engine_bin"
AGENTMEMORY_TEST_III="$engine_bin" AGENTMEMORY_REQUIRE_LIVE_TESTS=1 npx vitest run test/compose-supervision-integration.test.ts test/codex-live-daemon.test.ts
AGENTMEMORY_TEST_III="$engine_bin" AGENTMEMORY_REQUIRE_LIVE_TESTS=1 npx vitest run test/compose-supervision-integration.test.ts test/codex-live-daemon.test.ts test/compose-c1-integration.test.ts
Comment thread
rohitg00 marked this conversation as resolved.
Resolved
- run: npm run test:startup:packaged -- --skip-build --out "${{ runner.temp }}/startup-gate"
- name: Test packaged vector recovery
shell: bash
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1200,8 +1200,8 @@ EMBEDDING_PROVIDER=local

# Optional automatic context injection through the shared hooks
# AGENTMEMORY_INJECT_CONTEXT=true
# How long the PreToolUse hook waits for that context, in ms (default 2000)
# AGENTMEMORY_ENRICH_TIMEOUT_MS=2000
# Set the PreToolUse timeout in the hook process environment, not this server file:
# AGENTMEMORY_ENRICH_TIMEOUT_MS=2000 (default 2000 ms)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

# Optional outside LLM for summaries and consolidation. A key alone does nothing;
# this line selects the provider whose key agentmemory may use.
Expand Down
3 changes: 3 additions & 0 deletions src/cli/compose-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ function yamlString(value: string): string {
if (/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/.test(value)) {
throw new Error("A Compose path or configuration value contains an unsupported control character.");
}
if (/[\r\n\u0080-\u009f\u2028\u2029]/.test(value)) {
return JSON.stringify(value).replace(/[\u0080-\u009f\u2028\u2029]/g, (char) => `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`);
}
return `'${value.replace(/'/g, "''")}'`;
}

Expand Down
95 changes: 95 additions & 0 deletions test/compose-c1-integration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { spawn, spawnSync, type ChildProcess } from "node:child_process";
import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { createServer } from "node:net";
import { createRequire } from "node:module";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { pathToFileURL } from "node:url";
import { setTimeout as sleep } from "node:timers/promises";
import { describe, expect, it } from "vitest";
import { composeNamespace, writeWorkerCompose } from "../src/cli/compose-project.js";
import { III_PINNED_VERSION } from "../src/version.js";

const engine = process.env.AGENTMEMORY_TEST_III;
const version = engine ? spawnSync(engine, ["--version"], { encoding: "utf8", timeout: 3000 }) : null;
const available = version?.status === 0 && version.stdout.trim() === III_PINNED_VERSION;
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Resolved
const skipped = !available || process.platform === "win32" || process.env.AGENTMEMORY_SKIP_LIVE_TESTS === "1";
if (process.env.AGENTMEMORY_REQUIRE_LIVE_TESTS === "1" && skipped) {
throw new Error(`Required Compose C1 test needs iii ${III_PINNED_VERSION} and live tests enabled on macOS or Linux`);
}

async function freePort(): Promise<number> {
const server = createServer();
await new Promise<void>((accept, reject) => {
server.once("error", reject);
server.listen(0, "127.0.0.1", accept);
});
const port = (server.address() as { port: number }).port;
await new Promise<void>((accept) => server.close(() => accept()));
return port;
}

async function stop(child: ChildProcess): Promise<void> {
if (child.exitCode !== null || child.signalCode !== null) return;
const exited = new Promise<void>((accept) => child.once("exit", () => accept()));
child.kill("SIGINT");
const result = await Promise.race([exited.then(() => true), sleep(5000).then(() => false)]);
if (!result && child.pid) {
try { process.kill(-child.pid, "SIGKILL"); } catch {}
await exited;
}
}

describe.skipIf(skipped)("pinned Compose C1 environment round trip", () => {
it("delivers all C1 characters and line breaks unchanged to a real worker", async () => {
const root = mkdtempSync(join(tmpdir(), "agentmemory-compose-c1-"));
let child: ChildProcess | undefined;
try {
const pkg = join(root, "worker");
const snapshot = join(root, "received.json");
mkdirSync(join(pkg, "dist"), { recursive: true });
const value = `first\n${String.fromCharCode(...Array.from({ length: 32 }, (_, i) => 0x80 + i))}\u2028\u2029\r\nquote'\"\\\tend\n`;
const sdk = pathToFileURL(createRequire(import.meta.url).resolve("iii-sdk")).href;
writeFileSync(join(pkg, "dist/index.mjs"), `
import sdkModule from ${JSON.stringify(sdk)};
import { renameSync, writeFileSync } from "node:fs";
const { registerWorker } = sdkModule;
const worker = registerWorker(process.env.III_URL, { workerName: "agentmemory" });
worker.registerFunction("test::env", async () => process.env.OPENAI_BASE_URL);
writeFileSync(${JSON.stringify(`${snapshot}.tmp`)}, JSON.stringify(process.env.OPENAI_BASE_URL));
renameSync(${JSON.stringify(`${snapshot}.tmp`)}, ${JSON.stringify(snapshot)});
`);
const ports = { restPort: await freePort(), viewerPort: await freePort(), enginePort: await freePort() };
const project = writeWorkerCompose({
ports, projectRoot: pkg, dataDir: join(root, "data"), homeDir: join(root, "home"),
nodeBin: process.execPath, workerEnvironment: { OPENAI_BASE_URL: value },
});
const header = project.text.slice(0, project.text.indexOf("containers:\n"));
const app = project.text.slice(project.text.indexOf(" agentmemory:\n"))
.replace(" start_after: [state, http]", " start_after: []");
writeFileSync(project.file, `${header}containers:\n${app}`);
child = spawn(engine!, ["compose", "--namespace", composeNamespace(ports.restPort), "--up", "--file", project.file], {
env: { PATH: process.env.PATH, HOME: join(root, "home"), USERPROFILE: join(root, "home"),
III_COMPOSE_STATE_DIR: project.stateDir, III_TELEMETRY_ENABLED: "false", III_BUNDLE_WORKERS_DISABLED: "1", RUST_LOG: "error" },
detached: true, stdio: ["ignore", "ignore", "pipe"],
});
let logs = "";
child.stderr?.on("data", (chunk) => { logs = `${logs}${chunk}`.slice(-16000); });
const deadline = Date.now() + 20000;
while (Date.now() < deadline) {
try {
expect(JSON.parse(readFileSync(snapshot, "utf8"))).toBe(value);
return;
} catch (error) {
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
}
if (child.exitCode !== null || child.signalCode !== null) throw new Error(`Compose exited before the worker received its value: ${logs}`);
await sleep(50);
}
throw new Error(`Worker environment snapshot timed out: ${logs}`);
} finally {
if (child) await stop(child);
rmSync(root, { recursive: true, force: true });
}
}, 30000);
});
24 changes: 24 additions & 0 deletions test/compose-project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,30 @@ const options = (overrides: Record<string, unknown> = {}) => ({
});

describe("Worker Compose project", () => {
it.each(Array.from({ length: 32 }, (_, offset) => 0x80 + offset))(
"escapes C1 character U+%s in single-line and multiline scalars", (code) => {
for (const value of [`first${String.fromCharCode(code)}second`, `first\n${String.fromCharCode(code)}second`]) {
const text = renderWorkerCompose(options({ workerEnvironment: { OPENAI_BASE_URL: value } }));
expect(text).not.toMatch(/[\u0080-\u009f]/);
expect(parse(text).containers.agentmemory.environment.OPENAI_BASE_URL).toBe(value);
}
},
);
it.each(["first\u2028second", "first\u2029second", "first\n\u2028\u2029second"])(
"escapes Unicode line and paragraph separators: %j", (value) => {
const text = renderWorkerCompose(options({ workerEnvironment: { OPENAI_BASE_URL: value } }));
expect(text).not.toMatch(/[\u2028\u2029]/);
expect(text).toContain(`OPENAI_BASE_URL: ${JSON.stringify(value).replace(/[\u2028\u2029]/g, (char) => `\\u${char.charCodeAt(0).toString(16)}`)}`);
expect(parse(text).containers.agentmemory.environment.OPENAI_BASE_URL).toBe(value);
},
);
it.each(["first\nsecond", "first\rsecond", "first\r\nsecond", "\nleading\n\ntrailing\n", "quote'\"\\\nnext\tline"])(
"preserves multiline configuration values through YAML parsing: %j", (value) => {
const text = renderWorkerCompose(options({ workerEnvironment: { OPENAI_BASE_URL: value } }));
expect(parse(text).containers.agentmemory.environment.OPENAI_BASE_URL).toBe(value);
},
);

it("pins registry workers and configures the isolated engine, state and HTTP", () => {
const text = renderWorkerCompose(options());
expect(text).toContain("namespace: agentmemory-3511");
Expand Down