Skip to content
Closed
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
18 changes: 15 additions & 3 deletions App/backend/src/adapters/outbound/skill-writer/codex/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const LEGACY_HOOK_SCRIPT_FILE_NAME = "memmy-memory-resume-hook.mjs";
const HOOK_CONFIG_FILE_NAME = "memmy-memory-config.json";
const WORKSPACE_BRIDGE_FILE_NAME = "memmy-workspace-bridge.mjs";
const HOOK_TIMEOUT_SECONDS = 60;
/** Codex caps SessionEnd hooks at 3s and reports the clamped value as a hook loading problem. */
const SESSION_END_HOOK_TIMEOUT_SECONDS = 3;
const START_MARKER = "<!-- memmy:start v=1 -->";
const END_MARKER = "<!-- memmy:end v=1 -->";
const LEGACY_CLI_START_MARKER = "<!-- memmy-memory cli : start -->";
Expand Down Expand Up @@ -233,7 +235,12 @@ async function upsertCodexHookConfig(filePath: string, hookCommand: string): Pro
];
hooks.SessionStart = codexHookEntries(hooks.SessionStart, hookCommand, "Loading Memmy world model");
hooks.PostCompact = codexHookEntries(hooks.PostCompact, hookCommand, "Updating Memmy world model");
hooks.SessionEnd = codexHookEntries(hooks.SessionEnd, hookCommand, "Closing Memmy memory session");
hooks.SessionEnd = codexHookEntries(
hooks.SessionEnd,
hookCommand,
"Closing Memmy memory session",
SESSION_END_HOOK_TIMEOUT_SECONDS
);
config.hooks = hooks;
await writeFileAtomically(filePath, `${JSON.stringify(config, null, 2)}\n`);
}
Expand Down Expand Up @@ -273,10 +280,15 @@ async function removeCodexHookConfig(filePath: string): Promise<void> {
await writeFileAtomically(filePath, `${JSON.stringify(config, null, 2)}\n`);
}

function codexHookEntries(value: unknown, hookCommand: string, statusMessage: string): Record<string, unknown>[] {
function codexHookEntries(
value: unknown,
hookCommand: string,
statusMessage: string,
timeout: number = HOOK_TIMEOUT_SECONDS
): Record<string, unknown>[] {
return [
...removeCodexResumeHookEntries(value),
{ hooks: [{ type: "command", command: hookCommand, timeout: HOOK_TIMEOUT_SECONDS, statusMessage }] },
{ hooks: [{ type: "command", command: hookCommand, timeout, statusMessage }] },
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@ describe("codex skill target", () => {
}
});

it("caps the SessionEnd hook timeout at the Codex limit and keeps the other hooks at the default", async () => {
const { rootDirectory, memmyConfigPath } = createFixture();
const target = createCodexSkillTarget({ rootDirectory, memmyConfigPath, trustHooks: noOpTrustHooks });

await target.installPlugin?.("codex");

const config = JSON.parse(readFileSync(join(rootDirectory, "hooks.json"), "utf8")) as {
hooks: Record<string, Array<{ hooks: Array<{ command: string; timeout: number; type: string }> }>>;
};
expect(config.hooks.SessionEnd?.[0]?.hooks[0]).toMatchObject({ type: "command", timeout: 3 });
expect(config.hooks.SessionEnd?.[0]?.hooks[0]?.command).toContain("memmy-resume-hook.mjs");
expect(config.hooks.SessionStart?.[0]?.hooks[0]).toMatchObject({ timeout: 60 });
expect(config.hooks.PostCompact?.[0]?.hooks[0]).toMatchObject({ timeout: 60 });
});

it("persists trust for the installed user-level hooks before installation completes", async () => {
const { rootDirectory, memmyConfigPath } = createFixture();
let trustOptions: TrustMemmyCodexHooksOptions | undefined;
Expand Down
18 changes: 15 additions & 3 deletions Memory/src/agent-source/integration/codex/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const LEGACY_HOOK_SCRIPT_FILE_NAME = "memmy-memory-resume-hook.mjs";
const HOOK_CONFIG_FILE_NAME = "memmy-memory-config.json";
const WORKSPACE_BRIDGE_FILE_NAME = "memmy-workspace-bridge.mjs";
const HOOK_TIMEOUT_SECONDS = 60;
/** Codex caps SessionEnd hooks at 3s and reports the clamped value as a hook loading problem. */
const SESSION_END_HOOK_TIMEOUT_SECONDS = 3;
const START_MARKER = "<!-- memmy:start v=1 -->";
const END_MARKER = "<!-- memmy:end v=1 -->";
const LEGACY_CLI_START_MARKER = "<!-- memmy-memory cli : start -->";
Expand Down Expand Up @@ -233,7 +235,12 @@ async function upsertCodexHookConfig(filePath: string, hookCommand: string): Pro
];
hooks.SessionStart = codexHookEntries(hooks.SessionStart, hookCommand, "Loading Memmy world model");
hooks.PostCompact = codexHookEntries(hooks.PostCompact, hookCommand, "Updating Memmy world model");
hooks.SessionEnd = codexHookEntries(hooks.SessionEnd, hookCommand, "Closing Memmy memory session");
hooks.SessionEnd = codexHookEntries(
hooks.SessionEnd,
hookCommand,
"Closing Memmy memory session",
SESSION_END_HOOK_TIMEOUT_SECONDS
);
config.hooks = hooks;
await writeFileAtomically(filePath, `${JSON.stringify(config, null, 2)}\n`);
}
Expand Down Expand Up @@ -273,10 +280,15 @@ async function removeCodexHookConfig(filePath: string): Promise<void> {
await writeFileAtomically(filePath, `${JSON.stringify(config, null, 2)}\n`);
}

function codexHookEntries(value: unknown, hookCommand: string, statusMessage: string): Record<string, unknown>[] {
function codexHookEntries(
value: unknown,
hookCommand: string,
statusMessage: string,
timeout: number = HOOK_TIMEOUT_SECONDS
): Record<string, unknown>[] {
return [
...removeCodexResumeHookEntries(value),
{ hooks: [{ type: "command", command: hookCommand, timeout: HOOK_TIMEOUT_SECONDS, statusMessage }] },
{ hooks: [{ type: "command", command: hookCommand, timeout, statusMessage }] },
];
}

Expand Down
Loading