@staix/agent-mem 0.42.0 → 0.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +1 -1
  3. package/package.json +2 -2
  4. package/src/cli.ts +32 -3
  5. package/src/commands-table.ts +6 -2
  6. package/src/index.ts +2 -0
  7. package/src/ingest-hosts.ts +440 -0
  8. package/src/memory/candidates.ts +12 -0
  9. package/src/memory/capture.ts +23 -0
  10. package/src/memory/doctor.ts +8 -5
  11. package/src/memory/formats-raise.ts +1 -1
  12. package/src/memory/formats.ts +11 -0
  13. package/src/memory/generation-sync.ts +1 -1
  14. package/src/memory/home-binding-fence.ts +2 -1
  15. package/src/memory/live-state.ts +85 -0
  16. package/src/memory/migrate.ts +3 -3
  17. package/src/memory/mutation.ts +6 -3
  18. package/src/memory/public-prune-activation.ts +1 -1
  19. package/src/memory/public-prune-advance.ts +1 -1
  20. package/src/memory/public-prune-inputs.ts +1 -1
  21. package/src/memory/purge-intent.ts +27 -0
  22. package/src/memory/purge-matcher.ts +101 -0
  23. package/src/memory/purge-plan.ts +90 -0
  24. package/src/memory/read-curated-entries.ts +244 -0
  25. package/src/memory/reader-lease.ts +3 -0
  26. package/src/memory/shard-migration.ts +3 -3
  27. package/src/memory/shard-sync.ts +3 -3
  28. package/src/memory/store.ts +4 -69
  29. package/src/memory/sync-placement-activation-locks.ts +12 -3
  30. package/src/memory/sync-placement-active.ts +2 -0
  31. package/src/memory/sync-placement-guard.ts +2 -0
  32. package/src/memory/sync-placement-journal.ts +1 -1
  33. package/src/memory/sync-placement-transport.ts +8 -3
  34. package/src/memory/sync.ts +3 -2
  35. package/src/setup-console.ts +1 -1
  36. package/src/setup-drift.ts +4 -3
  37. package/src/setup-owned.ts +9 -1
  38. package/src/setup.ts +36 -6
@@ -1,3 +1,4 @@
1
+ import { purgePublicationRefusal } from "./purge-intent.ts";
1
2
  import type { PlacementCapturePort } from "./sync-placement-capture.ts";
2
3
  import { placementRuntimeRefusal } from "./sync-placement-guard.ts";
3
4
  import { assertFormatFloor } from "./formats.ts";
@@ -287,7 +288,7 @@ function missingSyncRemote(store: MemoryStore): string | undefined {
287
288
 
288
289
  export async function syncMemory(store: MemoryStore, opts: SyncOptions = {}): Promise<SyncResult> {
289
290
  assertFormatFloor(store.profile.home, "sync");
290
- const placementRefusal = placementRuntimeRefusal(store.profile.home, store.profile);
291
+ const placementRefusal = purgePublicationRefusal(store.profile.home) ?? placementRuntimeRefusal(store.profile.home, store.profile);
291
292
  if (placementRefusal) return { ok: false, pushed: false, entries: 0, error: placementRefusal };
292
293
  if (store.profile.publicationFormat === "agent-mem.sync-placement/v1") {
293
294
  // #450: the whole activated inventory, independent of the binding that opened `store`.
@@ -347,7 +348,7 @@ export async function syncMemory(store: MemoryStore, opts: SyncOptions = {}): Pr
347
348
  if (!release) return fail("another sync is running on this machine");
348
349
  let releaseMutation: (() => void) | undefined, releaseCurated: (() => void) | undefined;
349
350
  try {
350
- releaseMutation = acquireMutation(dir);
351
+ releaseMutation = acquireMutation(dir, store.profile.home);
351
352
  if (!releaseMutation) return fail("another memory mutation is running on this machine");
352
353
  releaseCurated = store.beginCuratedCacheUpdate();
353
354
  // Holding sync.lock, no other git runs in this repository: what a killed one left behind is stale.
@@ -41,7 +41,7 @@ export function consoleSetup(mode: "preview" | "apply" | "undo", env: Readonly<R
41
41
  if (lock && (!lock.isFile() || lock.nlink !== 1 || lock.uid !== directory.uid || (lock.mode & 0o022) !== 0))
42
42
  throw Error("console setup lock is unsafe; inspect the plugin directory before retrying");
43
43
  }
44
- const release = acquireMutation(dir);
44
+ const release = acquireMutation(dir, dir);
45
45
  if (!release) throw Error("console setup is busy; retry after the active console setup exits");
46
46
  try { return inspectAndUpdate(); }
47
47
  finally { release(); }
@@ -96,7 +96,8 @@ function launch(record: unknown): string | undefined {
96
96
  }
97
97
 
98
98
  function expectedManagedHookCommands(target: SetupTarget, after: ConfigImage): { event: string; command: string }[] {
99
- if (["jcode", "opencode", "gemini", "agy"].includes(target)) return [];
99
+ if (["jcode", "opencode", "agy"].includes(target)) return [];
100
+ if (target === "gemini") { const base = launch(mcpRecord(target, after)); return base && amemCaptureHooks("gemini", after).length ? [{ event: "SessionEnd", command: `${base} ingest gemini --hook-input --json` }] : []; }
100
101
  const base = launch(mcpRecord(target, after));
101
102
  if (!base) return [];
102
103
  if (target === "claude") return HOOK_EVENTS.map(event => ({ event, command: `${base} hook ${event}` }));
@@ -289,7 +290,7 @@ export function readSetupDrift(options: { home: string; env?: SetupEnvironment;
289
290
  if (!isDeepStrictEqual(expected, mcpRecord(target, current))) entries.push(entry(target, change.path, name, "managed MCP registration is missing or changed", "drift"));
290
291
  } catch { entries.push(entry(target, change.path, name, "managed MCP registration could not be checked", "unavailable")); unavailable = true; }
291
292
  }
292
- const hasHookSurface = target === "qwen" && change.key === `${target}:0` || target === "claude" && change.key === `${target}:1` || target === "codex" && change.key === `${target}:1` || target === "kimi" && change.key === `${target}:1`;
293
+ const hasHookSurface = (target === "qwen" || target === "gemini") && change.key === `${target}:0` || target === "claude" && change.key === `${target}:1` || target === "codex" && change.key === `${target}:1` || target === "kimi" && change.key === `${target}:1`;
293
294
  if (hasHookSurface) {
294
295
  try {
295
296
  const expected = expectedManagedHookCommands(target, receipt.changes[0]!.after);
@@ -299,7 +300,7 @@ export function readSetupDrift(options: { home: string; env?: SetupEnvironment;
299
300
  } catch { entries.push(entry(target, change.path, "hooks", "managed hooks could not be checked", "unavailable")); unavailable = true; }
300
301
  }
301
302
  // #512: an amem capture hook whose launch path is gone fails on every session end. Named by target, file and event, never its command.
302
- const captureSurface = { codex: "codex:1", kimi: "kimi:1", qwen: "qwen:0", pi: "pi:1" }[target as string];
303
+ const captureSurface = { codex: "codex:1", kimi: "kimi:1", qwen: "qwen:0", pi: "pi:1", gemini: "gemini:0" }[target as string];
303
304
  if (captureSurface === change.key) {
304
305
  try {
305
306
  for (const row of amemCaptureHooks(target, current)) {
@@ -162,6 +162,8 @@ export function restoreOwned(target: string, index: number, before: ConfigImage,
162
162
  if (sameImage(current, before)) return current;
163
163
  // Qwen keeps both managed surfaces in one settings file and one receipt image.
164
164
  if (target === "qwen" && index === 0) return restoreJsonHooks(before, after, restoreMcpOwned(target, before, after, current), true);
165
+ // #647: Gemini's settings.json holds the MCP entry and the SessionEnd capture hook.
166
+ if (target === "gemini" && index === 0) return restoreJsonHooks(before, after, restoreMcpOwned(target, before, after, current));
165
167
  if (index === 0) return restoreMcpOwned(target, before, after, current);
166
168
  if (target === "claude" || target === "codex") return restoreJsonHooks(before, after, current);
167
169
  if (target === "kimi") return restoreKimi(before, after, current);
@@ -171,7 +173,7 @@ export function restoreOwned(target: string, index: number, before: ConfigImage,
171
173
  }
172
174
  /** Only removal of an original/adopted hook needs receipt v2; added-only receipts remain v1-readable. */
173
175
  export function retiresOriginalHook(target: string, index: number, before: ConfigImage, after: ConfigImage): boolean {
174
- if (target === "qwen" && index === 0 || ["claude", "codex"].includes(target) && index === 1) {
176
+ if ((target === "qwen" || target === "gemini") && index === 0 || ["claude", "codex"].includes(target) && index === 1) {
175
177
  const strict = target === "qwen";
176
178
  return added(hooks(json(after), strict), hooks(json(before), strict), row => row.id).length > 0;
177
179
  }
@@ -187,6 +189,10 @@ export function managedAfter(target: string, index: number, before: ConfigImage,
187
189
  return isDeepStrictEqual(mcpRecord(target, after), mcpRecord(target, current)) && needed.every(row => live.some(value => value.id === row.id))
188
190
  && retired.every(row => live.filter(value => value.id === row.id).length <= installed.filter(value => value.id === row.id).length);
189
191
  }
192
+ if (target === "gemini" && index === 0) {
193
+ const needed = added(hooks(json(before)), hooks(json(after)), row => row.id), live = hooks(json(current));
194
+ return isDeepStrictEqual(mcpRecord(target, after), mcpRecord(target, current)) && needed.every(row => live.some(value => value.id === row.id));
195
+ }
190
196
  if (index === 0) return isDeepStrictEqual(mcpRecord(target, after), mcpRecord(target, current));
191
197
  if (target === "jcode") return jcodeHooksManaged(before, after, current);
192
198
  if (target === "claude" || target === "codex") {
@@ -238,6 +244,8 @@ export function amemCaptureCommand(command: string): { target: string; bun: stri
238
244
  }
239
245
  tokens.push(token);
240
246
  }
247
+ // #647: Gemini's form reads its SessionEnd stdin: `ingest gemini --hook-input --json`.
248
+ if (tokens[4] === "gemini" && tokens[5] === "--hook-input") tokens.splice(5, 1);
241
249
  const [bun, smol, entry, verb, target, json, ...rest] = tokens;
242
250
  if (!bun || !entry || !target || smol !== "--smol" || verb !== "ingest" || rest.length || (json !== undefined && json !== "--json")) return undefined;
243
251
  if (!bun.startsWith("/") || !entry.startsWith("/") || !entry.endsWith("/@staix/agent-mem/bin/amem.js") || !/^[a-z]+$/.test(target)) return undefined;
package/src/setup.ts CHANGED
@@ -52,6 +52,8 @@ export interface SetupContext {
52
52
  beforePublish?: (file: string) => void;
53
53
  /** Trusted test seam; production always runs the named native CLI in a private staging HOME. */
54
54
  native?: (argv: readonly string[], env: Env, cwd: string) => void;
55
+ /** Test seam (#647): the installed Gemini CLI version; production runs `gemini --version` in the staging HOME. */
56
+ geminiVersion?: string | null;
55
57
  }
56
58
  export type SetupSkillResult = { target: SetupTarget; report?: SkillInstallReport; reason?: string; refused?: boolean };
57
59
  export interface SetupPlan {
@@ -160,7 +162,31 @@ function context(options: SetupContext, workspace?: WorkspaceBinding) {
160
162
  const roots = [resolve(tmpdir()), realPath(tmpdir())], entries = [resolve(entry), realPath(entry)];
161
163
  if (roots.some(root => entries.some(file => { const part = relative(root, file); return part !== ".." && !part.startsWith("../") && !isAbsolute(part); }))) throw Error("setup refuses a temporary package entry; install amem in a persistent location first");
162
164
  }
163
- return { env, home, paths, legacyPaths, redirects, bun, entry, root: install, workspace, state: join(setupMemoryHome(env, home), "setup") };
165
+ let geminiHook: boolean | undefined;
166
+ return { env, home, paths, legacyPaths, redirects, bun, entry, root: install, workspace, state: join(setupMemoryHome(env, home), "setup"),
167
+ /** #647 D2: the SessionEnd hook carries transcript_path from Gemini CLI 0.67.0; older versions get MCP only. Probed once, lazily. */
168
+ get geminiHook(): boolean {
169
+ if (geminiHook === undefined) geminiHook = geminiHookSupported(options.geminiVersion !== undefined ? options.geminiVersion : options.native ? null : probeGeminiVersion(env));
170
+ return geminiHook;
171
+ } };
172
+ }
173
+ /** #647: the SessionEnd hook budget. Gemini CLI hook timeouts are milliseconds; the hook never blocks session exit. */
174
+ export const GEMINI_HOOK_TIMEOUT_MS = 3000;
175
+ const GEMINI_HOOK_MIN = [0, 67, 0] as const;
176
+ export function geminiHookSupported(version: string | null): boolean {
177
+ const parts = version?.match(/(\d+)\.(\d+)\.(\d+)/)?.slice(1).map(Number);
178
+ if (!parts) return false;
179
+ for (let i = 0; i < 3; i++) if (parts[i]! !== GEMINI_HOOK_MIN[i]) return parts[i]! > GEMINI_HOOK_MIN[i]!;
180
+ return true;
181
+ }
182
+ function probeGeminiVersion(env: Env): string | null {
183
+ if (!Bun.which("gemini", { PATH: env.PATH ?? process.env.PATH })) return null;
184
+ let staging: string | undefined;
185
+ try {
186
+ staging = mkdtempSync(join(realPath(tmpdir()), "amem-setup-"));
187
+ const result = spawnSync("gemini", ["--version"], { cwd: staging, env: { ...env, HOME: staging, GEMINI_CLI_HOME: staging }, encoding: "utf8", timeout: 3000, maxBuffer: 4096, stdio: ["ignore", "pipe", "pipe"] });
188
+ return result.status === 0 && !result.error ? singleLine(result.stdout).trim() || null : null;
189
+ } catch { return null; } finally { if (staging) try { rmSync(staging, { recursive: true, force: true }); } catch { /* best effort */ } }
164
190
  }
165
191
  export interface InstallRoot { path: string; version: string }
166
192
  const PACKAGE_JSON_MAX = 64 * 1024;
@@ -220,7 +246,7 @@ function assertOpencodeLayout(c: ReturnType<typeof context>, mode: SetupPlan["mo
220
246
  for (const name of ["opencode.jsonc", "config.json"]) if (read(join(dir, name)).bytes !== null) throw Error(`OpenCode setup supports one strict-JSON global opencode.json; ${name} beside it is merged too and is not supported`);
221
247
  if ([c.bun, c.entry].some(value => /\{(?:env|file):/.test(value))) throw Error("OpenCode substitutes {env:} and {file:} in configuration; setup cannot register this runtime exactly");
222
248
  }
223
- function intent(c: ReturnType<typeof context>, target: SetupTarget): string { return digest([1, target, c.paths[target], c.bun, c.entry, ...(["codex", "kimi", "qwen"].includes(target) ? ["capture-json-v1"] : []), ...(target === "jcode" ? ["jcode-hooks-v1"] : []), ...(["claude", "codex", "kimi", "pi", "qwen", "jcode"].includes(target) ? ["root-hooks-v2"] : []), ...(target === "agy" ? [c.workspace!.root] : [])]); }
249
+ function intent(c: ReturnType<typeof context>, target: SetupTarget): string { return digest([1, target, c.paths[target], c.bun, c.entry, ...(["codex", "kimi", "qwen"].includes(target) ? ["capture-json-v1"] : []), ...(target === "jcode" ? ["jcode-hooks-v1"] : []), ...(["claude", "codex", "kimi", "pi", "qwen", "jcode"].includes(target) ? ["root-hooks-v2"] : []), ...(target === "gemini" && c.geminiHook ? ["gemini-hook-v1"] : []), ...(target === "agy" ? [c.workspace!.root] : [])]); }
224
250
  function journal(c: ReturnType<typeof context>, target: SetupTarget): string { return join(c.state, target === "agy" ? `agy-${digest(c.workspace!.root)}.json` : `${target}.json`); }
225
251
  function receipt(c: ReturnType<typeof context>, target: SetupTarget, requireRuntime = false): Receipt | undefined {
226
252
  const raw = read(journal(c, target), JOURNAL_MAX); if (raw.bytes === null) return;
@@ -236,14 +262,15 @@ function receipt(c: ReturnType<typeof context>, target: SetupTarget, requireRunt
236
262
  return value;
237
263
  }
238
264
  function plannedHooks(c: ReturnType<typeof context>, target: SetupTarget): PlannedHook[] {
265
+ if (target === "gemini") return c.geminiHook ? [{ event: "SessionEnd", command: `${quote(c.bun)} --smol ${quote(c.entry)} ingest gemini --hook-input --json`, timeout: GEMINI_HOOK_TIMEOUT_MS }] : [];
239
266
  if (target === "jcode") return JCODE_CAPTURE_EVENTS.map(event => ({ event, command: jcodeHookCommand(c.bun, c.entry), timeout: 1 }));
240
- if (target === "opencode" || target === "gemini" || target === "agy") return [];
267
+ if (target === "opencode" || target === "agy") return [];
241
268
  const launch = `${quote(c.bun)} --smol ${quote(c.entry)}`;
242
269
  return target === "claude" ? HOOK_EVENTS.map(event => ({ event, command: `${launch} hook ${event}`, timeout: 1 }))
243
270
  : [{ event: target === "pi" ? "session_shutdown" : "SessionEnd", command: `${launch} ingest ${target}${target === "pi" ? "" : " --json"}`, timeout: target === "pi" ? 2.5 : 3 }];
244
271
  }
245
272
  /** The file index of a target's capture hook surface (#512): Qwen keeps hooks in its MCP settings file. */
246
- const HOOK_SURFACE: Partial<Record<SetupTarget, number>> = { codex: 1, kimi: 1, qwen: 0, pi: 1 };
273
+ const HOOK_SURFACE: Partial<Record<SetupTarget, number>> = { codex: 1, kimi: 1, qwen: 0, pi: 1, gemini: 0 };
247
274
  /** #512: amem capture entries of this target in the live surface that are not the current one: what apply removes, whatever their install root. */
248
275
  function strayCaptures(target: SetupTarget, image: Image, current: string): { event: string; command: string }[] {
249
276
  if (HOOK_SURFACE[target] === undefined) return [];
@@ -300,7 +327,7 @@ export function planSetup(target: string, mode: SetupPlan["mode"] = "preview", o
300
327
  }
301
328
  if (targets.includes("qwen")) pluginNotes.push("Qwen capture supports the verified 0.26.1 native format. For custom advanced.runtimeOutputDir, export the matching QWEN_RUNTIME_DIR for manual and SessionEnd ingest.");
302
329
  if (targets.includes("jcode")) pluginNotes.push("Jcode setup registers MCP and adds `amem hook jcode` to the post_tool and turn_end lifecycle hooks in JCODE_HOME/config.toml, keeping any existing command for those events (array form). Each event is scoped by its own JCODE_HOOK_CWD; events with no cwd, or outside a project, are skipped. Saved sessions and journals are still not ingested (no per-message origin), and user prompts are not captured.");
303
- if (targets.includes("gemini")) pluginNotes.push("Gemini CLI setup registers MCP only, at user scope in ~/.gemini/settings.json (GEMINI_CLI_HOME moves it), through the native gemini mcp add in a private staging HOME. Antigravity's ~/.gemini/config/mcp_config.json is never touched. A workspace .gemini/settings.json defining mcpServers.amem overrides this entry. No hook or ingest is installed: see docs/gemini-cli.md for why transcripts are not ingested.");
330
+ if (targets.includes("gemini")) pluginNotes.push("Gemini CLI setup registers MCP only, at user scope in ~/.gemini/settings.json (GEMINI_CLI_HOME moves it), through the native gemini mcp add in a private staging HOME. Antigravity's ~/.gemini/config/mcp_config.json is never touched. A workspace .gemini/settings.json defining mcpServers.amem overrides this entry. From Gemini CLI 0.67.0 setup also adds one SessionEnd hook (timeout 3000 ms) that ingests that session's transcript; older versions get MCP only and run amem ingest gemini by hand. See docs/gemini-cli.md.");
304
331
  if (targets.includes("opencode")) pluginNotes.push("OpenCode setup registers MCP only in the global strict-JSON opencode.json (mcp.amem, a local server started in the session's project directory). No plugin or ingest hook is installed: see docs/opencode.md for why transcripts are not ingested. A project opencode.json defining mcp.amem overrides this entry.");
305
332
  if (c.workspace) {
306
333
  pluginNotes.push(`Antigravity MCP is pinned to this repository only: ${c.workspace.root}. Restart the CLI/IDE and use one workspace; no global or plugin definitions are replaced, and same-name definitions elsewhere are unsupported. Native capture is unavailable; no hooks are installed. Only strict JSON is supported; JSONC is refused. Native TUI/IDE presence and live behavior are unverified; availability means this direct configuration operation is supported.`);
@@ -348,7 +375,7 @@ export function planSetup(target: string, mode: SetupPlan["mode"] = "preview", o
348
375
  const add = command(target, c.bun, c.entry), remove = target === "gemini" ? [...GEMINI_REMOVE] : [target, "mcp", "remove", ...(target === "claude" || target === "qwen" ? ["--scope", "user"] : []), "amem"];
349
376
  const installed = available(c, target, options), version = installed && target !== "agy" && mode !== "undo" ? probeClientVersion(c, target, options) : undefined;
350
377
  if (version?.matches === false) pluginNotes.push(`WARNING: ${target} version ${version.output}; layout verified on ${version.verified}. Apply remains guarded by native configuration validation.`);
351
- return { target, available: installed, ...(version ? { version } : {}), files, receipt: journal(c, target), ...(target === "agy" ? { cwd: c.workspace!.root } : {}), registration: mode === "undo" ? null : add, lifecycle: mode === "undo" ? "restore original MCP/hook files" : lifecycle(target), hooks: mode === "undo" || unchanged ? [] : plannedHooks(c, target), ...(removes.length ? { removes } : {}), mcpChange: mode === "undo" ? prior ? "restore" : "unchanged" : unchanged ? "unchanged" : hasAmem ? "replace" : "add", commands: mode === "undo" || prior?.intent === intent(c, target) || !add || !installed ? [] : [...(hasAmem ? [remove] : []), add], state: stale ? options.adoptCurrent ? "stale receipt; current wiring will be adopted" : "stale receipt; apply needs --adopt-current" : prior && prior.intent !== intent(c, target) ? "runtime changed; managed entries will update" : prior?.phase ?? "not installed" };
378
+ return { target, available: installed, ...(version ? { version } : {}), files, receipt: journal(c, target), ...(target === "agy" ? { cwd: c.workspace!.root } : {}), registration: mode === "undo" ? null : add, lifecycle: mode === "undo" ? "restore original MCP/hook files" : target === "gemini" && c.geminiHook ? "SessionEnd ingest of the session transcript" : lifecycle(target), hooks: mode === "undo" || unchanged ? [] : plannedHooks(c, target), ...(removes.length ? { removes } : {}), mcpChange: mode === "undo" ? prior ? "restore" : "unchanged" : unchanged ? "unchanged" : hasAmem ? "replace" : "add", commands: mode === "undo" || prior?.intent === intent(c, target) || !add || !installed ? [] : [...(hasAmem ? [remove] : []), add], state: stale ? options.adoptCurrent ? "stale receipt; current wiring will be adopted" : "stale receipt; apply needs --adopt-current" : prior && prior.intent !== intent(c, target) ? "runtime changed; managed entries will update" : prior?.phase ?? "not installed" };
352
379
  }), notes: [...pluginNotes, ...(/\/[^/]*\d+\.\d+[^/]*\/(?:bin\/)?bun$/.test(c.bun) ? ["this bun path is version-specific; rerun setup --apply after changing Bun"] : []), "Preview only unless --apply or --undo is passed; explicit modes apply without a prompt.", "Native registration commands run in a private staging HOME; only the listed configuration files are published.", "Original file bytes restore exactly when untouched; otherwise undo preserves CLI-owned changes and restores only managed entries, refusing edits to those entries.", "No AGENTS.md, CLAUDE.md or rule files are edited.", `A private ${join(c.state, "setup.lock")} serializes mutations; temporary ${join(realPath(tmpdir()), "amem-setup-*")} staging homes are removed.`, "Codex requires its native /hooks review before newly registered hooks run; setup does not grant hook trust. Runtime registrations use the PATH-resolved absolute Bun path without resolving its stable symlink; setup all reports and skips missing clients."] };
353
380
  }
354
381
  /** Native probes and registration share one private HOME, cwd and configuration layout. */
@@ -592,6 +619,9 @@ function prepare(c: ReturnType<typeof context>, target: SetupTarget, options: Se
592
619
  if (target === "codex") changes[1]!.after = hookDocument(changes[1]!.before, ["SessionEnd"], () => capture("codex"), 3, () => [...priorCaptures(oldLaunches, "codex"), ...strays]);
593
620
  // Qwen's user MCP and hooks share settings.json: publish and journal one combined image.
594
621
  if (target === "qwen") changes[0]!.after = hookDocument(changes[0]!.after, ["SessionEnd"], () => capture("qwen"), 3, () => [...priorCaptures(oldLaunches, "qwen"), ...strays]);
622
+ // #647: Gemini's MCP entry and SessionEnd hook share settings.json, like Qwen; one combined image is journaled.
623
+ if (target === "gemini" && c.geminiHook) changes[0]!.after = hookDocument(changes[0]!.after, ["SessionEnd"], () => plannedHooks(c, "gemini")[0]!.command, GEMINI_HOOK_TIMEOUT_MS,
624
+ () => [...oldLaunches.map(launch => `${launch} ingest gemini --hook-input --json`), ...strays]);
595
625
  if (target === "kimi") {
596
626
  const old = changes[1]!.before.bytes === null ? "" : Buffer.from(changes[1]!.before.bytes!, "base64").toString("utf8");
597
627
  const parsed = toml(old), rawHooks = parsed.hooks ?? [];