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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ The agentmemory entry is the **same MCP server block** across every host that us
| **Cline (CLI)** | `~/.cline/mcp.json` | `agentmemory connect cline` writes the standard `mcpServers` block. VS Code extension users: paste the same block via Cline Settings → MCP Servers → Edit JSON. |
| **Continue.dev** | `~/.continue/config.yaml` (preferred) or `config.json` (legacy) | `agentmemory connect continue` creates `config.yaml` from scratch when neither exists, or modifies existing `config.json`. **If you already have `config.yaml`** the adapter prints the exact block to paste under `mcpServers:` — it won't silently rewrite your yaml because preserving comments and anchors safely needs a YAML parser the package doesn't ship. Continue uses array form (not object) for `mcpServers`. |
| **Zed** | `~/.config/zed/settings.json` | `agentmemory connect zed` writes under `context_servers` (Zed's key, NOT `mcpServers`). Remote MCP servers can be wired via `{"url": "..."}` instead. |
| **Droid (Factory.ai)** | `~/.factory/mcp.json` | `agentmemory connect droid` writes the standard `mcpServers` block. Project-scoped overrides go in `<repo>/.factory/mcp.json`. The `/mcp` slash command inside droid lists configured servers. |
| **Droid (Factory.ai)** | `~/.factory/mcp.json` | `agentmemory connect droid` writes the standard `mcpServers` block. Project-scoped overrides go in `<repo>/.factory/mcp.json`. Pass `--with-hooks` for native auto-capture. |
| **Goose** | Goose MCP settings UI | Same `mcpServers` block — use `goose configure` → Add Extension → MCP. Direct YAML edit at `~/.config/goose/config.yaml` is supported but the schema uses `extensions:` + `cmd` (not `mcpServers:` + `command`). |
| **Aider** | n/a | Talk to the REST API directly: `curl -X POST http://localhost:3111/agentmemory/smart-search -d '{"query": "auth"}'`. |
| **Any agent (32+)** | n/a | `npx skillkit install agentmemory` auto-detects the host and merges. |
Expand Down
55 changes: 55 additions & 0 deletions plugin/hooks/hooks.droid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"hooks": {
"SessionStart": [
{
"hooks": [
{
"type": "command",
"command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/session-start.mjs\""
}
]
}
],
"UserPromptSubmit": [
{
"hooks": [
{
"type": "command",
"command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/prompt-submit.mjs\""
}
]
}
],
"PreToolUse": [
{
"matcher": "Edit|Create|Read|Glob|Grep",
"hooks": [
{
"type": "command",
"command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/pre-tool-use.mjs\""
}
]
}
],
"PostToolUse": [
{
"hooks": [
{
"type": "command",
"command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/post-tool-use.mjs\""
}
]
}
],
"SessionEnd": [
{
"hooks": [
{
"type": "command",
"command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/session-end.mjs\""
}
]
}
]
}
}
2 changes: 1 addition & 1 deletion plugin/skills/agentmemory-agents/REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Generated from `src/cli/connect/index.ts`. Do not edit the block below by hand;
| Continue | `continue` | Using MCP via ~/.continue/config.yaml (preferred) or config.json (legacy, only when no yaml). |
| GitHub Copilot CLI | `copilot-cli` | Using MCP. Install the plugin too for full hooks/skills coverage. |
| Cursor | `cursor` | Using MCP (the only protocol Cursor speaks). Memory bridge runs at :3111 underneath. |
| Droid (Factory.ai) | `droid` | Using MCP via ~/.factory/mcp.json. The `/mcp` slash command inside droid lists configured servers. |
| Droid (Factory.ai) | `droid` | Using MCP via ~/.factory/mcp.json. The `/mcp` slash command inside droid lists configured servers. Pass --with-hooks to also install the native ~/.factory/hooks.json auto-capture hooks. |
| Gemini CLI | `gemini-cli` | Using MCP (the only protocol Gemini CLI speaks). Memory bridge runs at :3111 underneath. |
| Hermes Agent | `hermes` | Using MCP. Hooks are also available, see https://github.com/rohitg00/agentmemory/tree/main/integrations/hermes. |
| Kiro | `kiro` | Using MCP via ~/.kiro/settings/mcp.json (user-level). Workspace overrides live in .kiro/settings/mcp.json. |
Expand Down
18 changes: 14 additions & 4 deletions src/cli/connect/codex-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@ import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";

/**
* Workaround for openai/codex#16430 — Codex Desktop does not dispatch
* Shared merge engine for writing agentmemory's bundled hook scripts into
* a host's global, user-scope hooks config. Originally built as a
* workaround for openai/codex#16430 — Codex Desktop does not dispatch
* plugin-local `hooks.json` even though both `CodexHooks` and `PluginHooks`
* feature flags are stable + default-enabled in
* `codex-rs/features/src/lib.rs`. Until upstream fixes plugin-scope
* dispatch, the same hook commands can be mirrored into the global
* `~/.codex/hooks.json`, which is loaded reliably.
*
* This module builds that mirror, with `${CLAUDE_PLUGIN_ROOT}` resolved to
* The same merge logic now also backs Claude Code's `--with-hooks`
* fallback (`~/.claude/settings.json`, #508 workaround) and Droid's
* native `~/.factory/hooks.json` install, since both hosts consume the
* identical `{ hooks: { <event>: [{ matcher?, hooks: [{ type, command }] }] } }`
* shape — only the bundled manifest file passed to `buildMergedHooks`
* differs per host.
*
* This module builds that merge, with `${CLAUDE_PLUGIN_ROOT}` resolved to
* the bundled `plugin/` directory so the user-scope file does not depend
* on env-var expansion (Codex only injects `CLAUDE_PLUGIN_ROOT` for
* plugin-scope hooks).
* on env-var expansion (only Claude Code actually injects
* `CLAUDE_PLUGIN_ROOT` for plugin-scope hooks — the token is reused here
* purely as an internal placeholder for "the bundled plugin/ dir").
*
* Identification on re-install: every command we write contains the
* resolved `<pluginRoot>/scripts/` prefix, so subsequent installs can
Expand Down
76 changes: 73 additions & 3 deletions src/cli/connect/droid.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,91 @@
import { existsSync, mkdirSync } from "node:fs";
import { homedir } from "node:os";
import { join } from "node:path";
import * as p from "@clack/prompts";
import { createJsonMcpAdapter } from "./json-mcp-adapter.js";
import type { ConnectOptions, ConnectResult } from "./types.js";
import {
buildMergedHooks,
findPluginRoot,
type HookManifest,
} from "./codex-hooks.js";
import { backupFile, logBackup, logInstalled, readJsonSafe, writeJsonAtomic } from "./util.js";

// Factory.ai's Droid CLI stores MCP server config at ~/.factory/mcp.json
// with the canonical `mcpServers` wrapper. Project-scoped overrides live
// at <repo>/.factory/mcp.json. Each entry adds an optional `type` field
// ("stdio" | "http") and `disabled` boolean — agentmemory's stdio block
// works against the same shape without needing the explicit type tag.
// Source: docs.factory.ai/cli/configuration/mcp
//
// Droid also ships a native, first-party hooks system (SessionStart,
// SessionEnd, UserPromptSubmit, PreToolUse, PostToolUse) configured via
// `~/.factory/hooks.json`, in the same `{ hooks: { <event>: [{ matcher?,
// hooks: [{ type, command }] }] } }` shape Claude Code and Codex use — so
// `--with-hooks` reuses `buildMergedHooks` from codex-hooks.ts with the
// bundled `hooks.droid.json` manifest instead of writing a new merge
// strategy. Source: docs.factory.ai/cli/configuration/hooks-guide
const DROID_DIR = join(homedir(), ".factory");
const DROID_HOOKS = join(DROID_DIR, "hooks.json");

export const adapter = createJsonMcpAdapter({
name: "droid",
displayName: "Droid (Factory.ai)",
detectDir: join(homedir(), ".factory"),
configPath: join(homedir(), ".factory", "mcp.json"),
detectDir: DROID_DIR,
configPath: join(DROID_DIR, "mcp.json"),
docs: "https://github.com/rohitg00/agentmemory#other-agents",
protocolNote:
"→ Using MCP via ~/.factory/mcp.json. The `/mcp` slash command inside droid lists configured servers.",
"→ Using MCP via ~/.factory/mcp.json. The `/mcp` slash command inside droid lists configured servers. Pass --with-hooks to also install the native ~/.factory/hooks.json auto-capture hooks.",
// Droid requires `type` per the documented schema. stdio for npx-spawned shim.
extraEntryFields: { type: "stdio" },
installHooks: installDroidHooks,
});

/**
* Merge the bundled `plugin/hooks/hooks.droid.json` into
* `~/.factory/hooks.json`. Same idempotent merge/strip-by-script-path
* behavior as the Codex and Claude Code hook installers: re-running keeps
* user-authored hook entries and only replaces the ones agentmemory owns.
*/
function installDroidHooks(opts: ConnectOptions): ConnectResult {
let pluginRoot: string;
try {
pluginRoot = findPluginRoot();
} catch (err) {
return {
kind: "skipped",
reason: err instanceof Error ? err.message : String(err),
};
}

const existing = readJsonSafe<HookManifest>(DROID_HOOKS);
const merged = buildMergedHooks(existing, pluginRoot, "hooks.droid.json");

if (opts.dryRun) {
p.log.info(
`[dry-run] Would ${existing ? "merge" : "create"} ${DROID_HOOKS} with ${Object.keys(merged.hooks).length} event(s)`,
);
return { kind: "installed", mutatedPath: DROID_HOOKS };
}

let backupPath: string | undefined;
if (existsSync(DROID_HOOKS)) {
backupPath = backupFile(DROID_HOOKS, "droid-hooks", "json");
logBackup(backupPath);
} else {
mkdirSync(DROID_DIR, { recursive: true });
}

writeJsonAtomic(DROID_HOOKS, merged);

logInstalled("Droid hooks", DROID_HOOKS);
p.log.info(
"User-scope hooks reference absolute paths under the bundled plugin/ dir. Re-run `agentmemory connect droid --with-hooks` after upgrading agentmemory to refresh them.",
);

return {
kind: "installed",
mutatedPath: DROID_HOOKS,
...(backupPath !== undefined && { backupPath }),
};
}
32 changes: 32 additions & 0 deletions src/cli/connect/json-mcp-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export type JsonMcpAdapterConfig = {
// Extra fields merged into the agentmemory entry. Droid requires
// type: "stdio"; other hosts ignore unknown fields.
extraEntryFields?: Record<string, unknown>;
// Invoked when `--with-hooks` is passed, independent of whether the MCP
// entry was freshly installed or already wired (mirrors the Claude Code /
// Codex adapters, issue #508 pattern) — hosts that ship a native hook
// config alongside MCP (e.g. Droid's `~/.factory/hooks.json`) pass this
// to install/refresh their hook manifest.
installHooks?: (opts: ConnectOptions) => ConnectResult;
};

type McpEntry = typeof AGENTMEMORY_MCP_BLOCK;
Expand Down Expand Up @@ -69,13 +75,29 @@ export function createJsonMcpAdapter(
const alreadyHas = entryMatches(servers["agentmemory"]);
if (alreadyHas && !opts.force) {
logAlreadyWired(config.displayName, config.configPath);
if (opts.withHooks && config.installHooks) {
const hookResult = config.installHooks(opts);
if (hookResult.kind === "skipped") {
p.log.warn(
`${config.displayName} hooks skipped: ${hookResult.reason}.`,
);
}
}
return { kind: "already-wired", mutatedPath: config.configPath };
}

if (opts.dryRun) {
p.log.info(
`[dry-run] Would ${alreadyHas ? "overwrite" : "add"} ${wrapperKey}.agentmemory in ${config.configPath}`,
);
if (opts.withHooks && config.installHooks) {
const hookResult = config.installHooks(opts);
if (hookResult.kind === "skipped") {
p.log.warn(
`${config.displayName} hooks skipped: ${hookResult.reason}.`,
);
}
}
return { kind: "installed", mutatedPath: config.configPath };
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

Expand Down Expand Up @@ -106,6 +128,16 @@ export function createJsonMcpAdapter(
}

logInstalled(config.displayName, config.configPath);

if (opts.withHooks && config.installHooks) {
const hookResult = config.installHooks(opts);
if (hookResult.kind === "skipped") {
p.log.warn(
`${config.displayName} hooks skipped: ${hookResult.reason}. MCP wiring still applied.`,
);
}
}

return {
kind: "installed",
mutatedPath: config.configPath,
Expand Down
9 changes: 5 additions & 4 deletions src/cli/connect/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ export type ConnectOptions = {
dryRun: boolean;
force: boolean;
/**
* When true, the Codex adapter additionally writes a global
* `~/.codex/hooks.json` block referencing absolute paths to bundled hook
* scripts. Workaround for openai/codex#16430, which prevents plugin-local
* hooks from dispatching on Codex Desktop. No-op for other adapters.
* When true, adapters that ship a native hook config alongside MCP
* additionally write it: Codex (`~/.codex/hooks.json`, workaround for
* openai/codex#16430), Claude Code (`~/.claude/settings.json`, workaround
* for #508), and Droid (`~/.factory/hooks.json`, its native hooks
* config). No-op for adapters without a hooks installer.
*/
withHooks?: boolean;
};
Expand Down
Loading