@staix/agent-mem 0.41.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.
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +2 -2
- package/package.json +4 -3
- package/src/cli.ts +161 -27
- package/src/commands-table.ts +17 -6
- package/src/index.ts +4 -1
- package/src/ingest-hosts.ts +440 -0
- package/src/mcp-bounds.ts +3 -0
- package/src/mcp-memory.ts +64 -10
- package/src/mcp.ts +36 -121
- package/src/memory/candidates.ts +33 -5
- package/src/memory/capture.ts +23 -0
- package/src/memory/commands.ts +6 -3
- package/src/memory/config.ts +26 -0
- package/src/memory/consolidation-clusters.ts +13 -2
- package/src/memory/doctor-text.ts +4 -1
- package/src/memory/doctor.ts +8 -5
- package/src/memory/formats-raise.ts +37 -16
- package/src/memory/formats.ts +37 -10
- package/src/memory/generation-sync.ts +1 -1
- package/src/memory/home-binding-fence.ts +2 -1
- package/src/memory/live-state.ts +85 -0
- package/src/memory/migrate.ts +3 -3
- package/src/memory/mutation.ts +6 -3
- package/src/memory/profile-marker-cache.ts +45 -0
- package/src/memory/public-prune-activation.ts +1 -1
- package/src/memory/public-prune-advance.ts +1 -1
- package/src/memory/public-prune-inputs.ts +1 -1
- package/src/memory/purge-intent.ts +27 -0
- package/src/memory/purge-matcher.ts +101 -0
- package/src/memory/purge-plan.ts +90 -0
- package/src/memory/read-curated-entries.ts +244 -0
- package/src/memory/reader-lease.ts +3 -0
- package/src/memory/search-fts.ts +55 -27
- package/src/memory/shard-migration.ts +3 -3
- package/src/memory/shard-sync.ts +3 -3
- package/src/memory/shard.ts +17 -14
- package/src/memory/store.ts +9 -72
- package/src/memory/sync-cadence.ts +8 -4
- package/src/memory/sync-placement-activation-locks.ts +39 -22
- package/src/memory/sync-placement-active.ts +69 -19
- package/src/memory/sync-placement-advertisement.ts +25 -3
- package/src/memory/sync-placement-checkpoint-person.ts +8 -14
- package/src/memory/sync-placement-effective-writers.ts +4 -3
- package/src/memory/sync-placement-guard.ts +31 -11
- package/src/memory/sync-placement-inventory.ts +20 -4
- package/src/memory/sync-placement-journal.ts +1 -1
- package/src/memory/sync-placement-realm-admission.ts +16 -11
- package/src/memory/sync-placement-refusal.ts +7 -0
- package/src/memory/sync-placement-remote-admission.ts +31 -13
- package/src/memory/sync-placement-remote-refusal.ts +1 -1
- package/src/memory/sync-placement-remote-stage.ts +1 -1
- package/src/memory/sync-placement-transport.ts +36 -15
- package/src/memory/sync-placement-writer-listing.ts +38 -13
- package/src/memory/sync-placement-writer-renewal.ts +5 -7
- package/src/memory/sync.ts +3 -2
- package/src/memory/topic.ts +14 -0
- package/src/setup-console.ts +49 -23
- package/src/setup-drift.ts +35 -4
- package/src/setup-owned.ts +9 -1
- package/src/setup-writer-roots.ts +1 -1
- package/src/setup.ts +102 -16
- package/src/sync-placement-writer-context.ts +1 -1
package/src/setup.ts
CHANGED
|
@@ -18,11 +18,13 @@ import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
|
18
18
|
import { fileURLToPath } from "node:url";
|
|
19
19
|
import { isDeepStrictEqual, types } from "node:util";
|
|
20
20
|
import { HOOK_EVENTS } from "./hook-contract.ts";
|
|
21
|
-
import { decodeReceipt, JOURNAL_MAX, readSetupWriterRoots, setupReceiptRemedy, SetupWriterRootsError, SETUP_TARGETS, type Receipt, type SetupTarget } from "./setup-writer-roots.ts";
|
|
21
|
+
import { decodeReceipt, JOURNAL_MAX, readSetupWriterLaunchers, readSetupWriterRoots, setupReceiptRemedy, SetupWriterRootsError, SETUP_TARGETS, type Receipt, type SetupTarget } from "./setup-writer-roots.ts";
|
|
22
22
|
export { readSetupWriterRoots, setupReceiptRemedy, SetupWriterRootsError, SETUP_TARGETS, type SetupTarget };
|
|
23
23
|
import { readEffectiveSyncPlacementWriters } from "./memory/sync-placement-effective-writers.ts";
|
|
24
24
|
import { placementMarkerState } from "./memory/sync-placement-guard.ts";
|
|
25
25
|
import { memoryHome } from "./memory/home.ts";
|
|
26
|
+
import { listAgyReceiptLocations } from "./setup-drift.ts";
|
|
27
|
+
import { consoleSetup, consoleSetupText, type ConsoleSetup } from "./setup-console.ts";
|
|
26
28
|
import { PLAIN, singleLine, type Style } from "./memory/style.ts";
|
|
27
29
|
import { canonicalPath, memoryGitEnv, memoryGitSync, processLiveness, processSignature, realPath } from "./memory/platform.ts";
|
|
28
30
|
|
|
@@ -50,6 +52,8 @@ export interface SetupContext {
|
|
|
50
52
|
beforePublish?: (file: string) => void;
|
|
51
53
|
/** Trusted test seam; production always runs the named native CLI in a private staging HOME. */
|
|
52
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;
|
|
53
57
|
}
|
|
54
58
|
export type SetupSkillResult = { target: SetupTarget; report?: SkillInstallReport; reason?: string; refused?: boolean };
|
|
55
59
|
export interface SetupPlan {
|
|
@@ -158,7 +162,31 @@ function context(options: SetupContext, workspace?: WorkspaceBinding) {
|
|
|
158
162
|
const roots = [resolve(tmpdir()), realPath(tmpdir())], entries = [resolve(entry), realPath(entry)];
|
|
159
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");
|
|
160
164
|
}
|
|
161
|
-
|
|
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 */ } }
|
|
162
190
|
}
|
|
163
191
|
export interface InstallRoot { path: string; version: string }
|
|
164
192
|
const PACKAGE_JSON_MAX = 64 * 1024;
|
|
@@ -218,7 +246,7 @@ function assertOpencodeLayout(c: ReturnType<typeof context>, mode: SetupPlan["mo
|
|
|
218
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`);
|
|
219
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");
|
|
220
248
|
}
|
|
221
|
-
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] : [])]); }
|
|
222
250
|
function journal(c: ReturnType<typeof context>, target: SetupTarget): string { return join(c.state, target === "agy" ? `agy-${digest(c.workspace!.root)}.json` : `${target}.json`); }
|
|
223
251
|
function receipt(c: ReturnType<typeof context>, target: SetupTarget, requireRuntime = false): Receipt | undefined {
|
|
224
252
|
const raw = read(journal(c, target), JOURNAL_MAX); if (raw.bytes === null) return;
|
|
@@ -234,14 +262,15 @@ function receipt(c: ReturnType<typeof context>, target: SetupTarget, requireRunt
|
|
|
234
262
|
return value;
|
|
235
263
|
}
|
|
236
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 }] : [];
|
|
237
266
|
if (target === "jcode") return JCODE_CAPTURE_EVENTS.map(event => ({ event, command: jcodeHookCommand(c.bun, c.entry), timeout: 1 }));
|
|
238
|
-
if (target === "opencode" || target === "
|
|
267
|
+
if (target === "opencode" || target === "agy") return [];
|
|
239
268
|
const launch = `${quote(c.bun)} --smol ${quote(c.entry)}`;
|
|
240
269
|
return target === "claude" ? HOOK_EVENTS.map(event => ({ event, command: `${launch} hook ${event}`, timeout: 1 }))
|
|
241
270
|
: [{ event: target === "pi" ? "session_shutdown" : "SessionEnd", command: `${launch} ingest ${target}${target === "pi" ? "" : " --json"}`, timeout: target === "pi" ? 2.5 : 3 }];
|
|
242
271
|
}
|
|
243
272
|
/** The file index of a target's capture hook surface (#512): Qwen keeps hooks in its MCP settings file. */
|
|
244
|
-
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 };
|
|
245
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. */
|
|
246
275
|
function strayCaptures(target: SetupTarget, image: Image, current: string): { event: string; command: string }[] {
|
|
247
276
|
if (HOOK_SURFACE[target] === undefined) return [];
|
|
@@ -259,7 +288,7 @@ const lifecycle = (target: SetupTarget) => target === "opencode" || target === "
|
|
|
259
288
|
* as such with the renewal step to take first; an inventory that cannot be read is reported as unverified, never as a missing
|
|
260
289
|
* entry. It writes nothing, refuses nothing and returns undefined on a home that is not activated for placement sync.
|
|
261
290
|
*/
|
|
262
|
-
function placementWriterInventoryNote(root: string, home: string): string | undefined {
|
|
291
|
+
function placementWriterInventoryNote(root: string, home: string, repairing = false): string | undefined {
|
|
263
292
|
// #551 AC2: only a proven non-placement home stays silent. Markers that cannot be read or parsed prove nothing either way,
|
|
264
293
|
// so they fall through to the inventory read below, which reports the state as unverified instead of as a missing root.
|
|
265
294
|
if (placementMarkerState(home) === "not placement") return undefined;
|
|
@@ -269,8 +298,10 @@ function placementWriterInventoryNote(root: string, home: string): string | unde
|
|
|
269
298
|
let canonical: string;
|
|
270
299
|
try { canonical = realPath(root); } catch { return undefined; }
|
|
271
300
|
if (roots.includes(canonical)) return undefined;
|
|
301
|
+
// #660 AC4: refreshing a receipt whose recorded install is gone is the repair the refusal asked for; the renewal comes after it.
|
|
302
|
+
if (repairing) return `WARNING: this install root is not yet in the active placement writer inventory. Finish applying setup to repair the stale receipt, then renew the inventory: list the roots with amem migrate --sync-placement --writers and run the command it prints. Setup writes no inventory entry and never refuses on this alone.`;
|
|
272
303
|
// #551 AC2: the suggested argument is shell-quoted, so a root with a space, a quote or a shell metacharacter stays one argument.
|
|
273
|
-
return `WARNING: this install root is outside the active placement writer inventory, so placement sync stops in writer verification once setup registers it. Renew the inventory
|
|
304
|
+
return `WARNING: this install root is outside the active placement writer inventory, so placement sync stops in writer verification once setup registers it. Renew the inventory with the person while sessions keep running. Run amem migrate --sync-placement --dry-run --writer-root ${quote(canonical)}, adding --writer-root for every other install root, then use --apply with the same roots. If the live window needs compaction, save the preview with amem migrate --sync-placement --checkpoint --writer-root ${quote(canonical)} --out checkpoint-plan.json, adding the same other roots, and confirm with amem migrate --sync-placement --checkpoint --confirm --plan checkpoint-plan.json. Rerun setup after renewal. Setup writes no inventory entry and never refuses on this alone.`;
|
|
274
305
|
}
|
|
275
306
|
export function planSetup(target: string, mode: SetupPlan["mode"] = "preview", options: SetupContext = {}): SetupPlan {
|
|
276
307
|
if (target !== "all" && !SETUP_TARGETS.includes(target as SetupTarget)) throw Error("usage: amem setup claude|codex|kimi|pi|qwen|jcode|opencode|gemini|agy|all [--apply|--undo]");
|
|
@@ -296,7 +327,7 @@ export function planSetup(target: string, mode: SetupPlan["mode"] = "preview", o
|
|
|
296
327
|
}
|
|
297
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.");
|
|
298
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.");
|
|
299
|
-
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.
|
|
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.");
|
|
300
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.");
|
|
301
332
|
if (c.workspace) {
|
|
302
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.`);
|
|
@@ -304,7 +335,9 @@ export function planSetup(target: string, mode: SetupPlan["mode"] = "preview", o
|
|
|
304
335
|
}
|
|
305
336
|
if (c.root) pluginNotes.push(`Registers the install root ${c.root.path} (amem ${c.root.version}) for hooks and MCP; current registrations change only on --apply.`);
|
|
306
337
|
// #551: the root this plan registers may not be in the home's active placement inventory, which stops sync in writer verification.
|
|
307
|
-
|
|
338
|
+
let repairing = false;
|
|
339
|
+
try { repairing = mode !== "undo" ? readSetupWriterLaunchers(dirname(c.state)).some(row => row.state === "missing" && targets.includes(row.target)) : false; } catch { repairing = false; }
|
|
340
|
+
const placementWriter = placementWriterInventoryNote(c.root?.path ?? fileURLToPath(new URL("..", import.meta.url)), dirname(c.state), repairing);
|
|
308
341
|
if (placementWriter) pluginNotes.push(placementWriter);
|
|
309
342
|
if (target === "all") pluginNotes.push("Antigravity is repository-scoped and excluded from all; run amem setup agy explicitly inside its repository.");
|
|
310
343
|
if (targets.includes("jcode")) pluginNotes.push("Launch Jcode with JCODE_DISABLE_CLAUDE_MCP=1 and without a same-name project override: imported Claude stdio entries can replace this private amem binding with a shared daemon-cwd server. Use a new workspace-bound session when changing projects.");
|
|
@@ -342,7 +375,7 @@ export function planSetup(target: string, mode: SetupPlan["mode"] = "preview", o
|
|
|
342
375
|
const add = command(target, c.bun, c.entry), remove = target === "gemini" ? [...GEMINI_REMOVE] : [target, "mcp", "remove", ...(target === "claude" || target === "qwen" ? ["--scope", "user"] : []), "amem"];
|
|
343
376
|
const installed = available(c, target, options), version = installed && target !== "agy" && mode !== "undo" ? probeClientVersion(c, target, options) : undefined;
|
|
344
377
|
if (version?.matches === false) pluginNotes.push(`WARNING: ${target} version ${version.output}; layout verified on ${version.verified}. Apply remains guarded by native configuration validation.`);
|
|
345
|
-
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" };
|
|
346
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."] };
|
|
347
380
|
}
|
|
348
381
|
/** Native probes and registration share one private HOME, cwd and configuration layout. */
|
|
@@ -586,6 +619,9 @@ function prepare(c: ReturnType<typeof context>, target: SetupTarget, options: Se
|
|
|
586
619
|
if (target === "codex") changes[1]!.after = hookDocument(changes[1]!.before, ["SessionEnd"], () => capture("codex"), 3, () => [...priorCaptures(oldLaunches, "codex"), ...strays]);
|
|
587
620
|
// Qwen's user MCP and hooks share settings.json: publish and journal one combined image.
|
|
588
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]);
|
|
589
625
|
if (target === "kimi") {
|
|
590
626
|
const old = changes[1]!.before.bytes === null ? "" : Buffer.from(changes[1]!.before.bytes!, "base64").toString("utf8");
|
|
591
627
|
const parsed = toml(old), rawHooks = parsed.hooks ?? [];
|
|
@@ -765,10 +801,8 @@ function setupWriterCommands(plan: SetupPlan): string[] {
|
|
|
765
801
|
const all = [...new Set([...roots, ...readSetupWriterRoots(home), root].map(realPath))].sort();
|
|
766
802
|
if (all.some(value => /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u.test(value))) return ["amem doctor"];
|
|
767
803
|
const flags = all.map(value => `--writer-root ${quote(value)}`).join(" ");
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
return [`(umask 077; set -C; amem migrate --sync-placement --checkpoint ${flags} --json > checkpoint-plan.json)`, `amem migrate --sync-placement --checkpoint --confirm --plan checkpoint-plan.json ${flags}`,
|
|
771
|
-
`amem migrate --sync-placement --dry-run ${flags}`, `amem migrate --sync-placement --apply ${flags}`];
|
|
804
|
+
return [`amem migrate --sync-placement --dry-run ${flags}`, `amem migrate --sync-placement --apply ${flags}`,
|
|
805
|
+
`amem migrate --sync-placement --checkpoint ${flags} --out checkpoint-plan.json`, "amem migrate --sync-placement --checkpoint --confirm --plan checkpoint-plan.json"];
|
|
772
806
|
} catch { return ["amem doctor"]; }
|
|
773
807
|
}
|
|
774
808
|
|
|
@@ -847,6 +881,44 @@ function setupResultText(result: SetupResult, s: Style, plan: SetupPlan, options
|
|
|
847
881
|
/** Compatibility formatter for confirmation-style callers: the raw plan under `--json`, the readable plan otherwise. */
|
|
848
882
|
export function setupConfirmationText(plan: SetupPlan, json: boolean, s: Style = PLAIN): string { return json ? JSON.stringify(plan, null, 2) : setupPlanText(plan, s); }
|
|
849
883
|
|
|
884
|
+
export interface AgyRefreshRow { workspace: string; change: "update" | "unchanged" | "missing-workspace" | "refused"; reason?: string }
|
|
885
|
+
/**
|
|
886
|
+
* #659: `amem setup agy --refresh [--apply]` previews, then refreshes, every applied Antigravity receipt in one run, each through the
|
|
887
|
+
* same per-workspace plan and apply as `cd <workspace> && amem setup agy --apply`. Only receipted workspaces are touched; one
|
|
888
|
+
* workspace's refusal is reported and never stops the others.
|
|
889
|
+
*/
|
|
890
|
+
export function refreshAgyWorkspaces(mode: "preview" | "apply", options: SetupContext = {}): { workspaces: AgyRefreshRow[]; incomplete: boolean } {
|
|
891
|
+
const listed = listAgyReceiptLocations(setupMemoryHome((options.env ?? process.env) as NodeJS.ProcessEnv));
|
|
892
|
+
const agent = cliAttribution()?.actor === "agent";
|
|
893
|
+
const workspaces = listed.receipts.map(({ workspace }): AgyRefreshRow => {
|
|
894
|
+
try {
|
|
895
|
+
if (!lstatSync(workspace, { throwIfNoEntry: false })?.isDirectory())
|
|
896
|
+
return { workspace, change: "missing-workspace", reason: "the repository directory no longer exists; restore it, then run amem setup agy --undo there to remove its receipt" };
|
|
897
|
+
const context = { ...options, cwd: workspace };
|
|
898
|
+
// Each plan must still bind exactly the receipt's workspace; one that now resolves elsewhere is that row's refusal.
|
|
899
|
+
const planned = (planMode: "preview" | "apply") => {
|
|
900
|
+
const plan = planSetup("agy", planMode, context);
|
|
901
|
+
if (plan.actions.length !== 1 || plan.actions[0]!.cwd !== workspace) throw Error("the receipt's repository no longer resolves to the same workspace; run amem setup agy --list and repair it from that repository");
|
|
902
|
+
// The agent screen `amem setup agy --apply` applies before any write, per workspace.
|
|
903
|
+
if (agent && !configuredPolicy(memoryHome(options.env ?? process.env), workspace).screenStandalone(JSON.parse(JSON.stringify(plan)))) throw Error("Memory operation unavailable or refused; no partial result is shown.");
|
|
904
|
+
return plan;
|
|
905
|
+
};
|
|
906
|
+
if (planned("preview").actions.every(action => action.mcpChange === "unchanged")) return { workspace, change: "unchanged" };
|
|
907
|
+
if (mode === "apply") applySetup(planned("apply"), context);
|
|
908
|
+
return { workspace, change: "update" };
|
|
909
|
+
} catch (error) { return { workspace, change: "refused", reason: singleLine((error as Error).message) }; }
|
|
910
|
+
});
|
|
911
|
+
return { workspaces, incomplete: listed.incomplete };
|
|
912
|
+
}
|
|
913
|
+
export function agyRefreshText(result: ReturnType<typeof refreshAgyWorkspaces>, mode: "preview" | "apply"): string {
|
|
914
|
+
const verb = (row: AgyRefreshRow) => row.change === "update" && mode === "preview" ? "would update" : row.change === "update" ? "updated" : row.change;
|
|
915
|
+
const lines = result.workspaces.map(row => `${verb(row)}: ${row.workspace}${row.reason ? ` (${row.reason})` : ""}`);
|
|
916
|
+
if (!lines.length) lines.push("No Antigravity setup receipts found.");
|
|
917
|
+
if (result.incomplete) lines.push("Some Antigravity setup receipts could not be listed safely; run amem setup agy --list.");
|
|
918
|
+
if (mode === "preview" && result.workspaces.some(row => row.change === "update")) lines.push("Preview only; run amem setup agy --refresh --apply to update them.");
|
|
919
|
+
return lines.join("\n");
|
|
920
|
+
}
|
|
921
|
+
|
|
850
922
|
export async function runSetup(target: string, mode: SetupPlan["mode"], options: SetupContext & { json?: boolean; style?: Style; columns?: number; verbose?: boolean } = {}): Promise<string> {
|
|
851
923
|
const plan = planSetup(target, mode, options), s = options.json ? PLAIN : options.style ?? PLAIN;
|
|
852
924
|
const renderOptions: SetupRenderOptions = { columns: options.columns, verbose: options.verbose, ...(!options.json && mode !== "undo" && plan.placementWriter ? { writerCommands: setupWriterCommands(plan) } : {}) };
|
|
@@ -854,9 +926,23 @@ export async function runSetup(target: string, mode: SetupPlan["mode"], options:
|
|
|
854
926
|
const policy = configuredPolicy(memoryHome(options.env ?? process.env), options.cwd ?? process.cwd());
|
|
855
927
|
if (!policy.screenStandalone(JSON.parse(JSON.stringify(plan))) || (renderOptions.writerCommands && !policy.screenStandalone(renderOptions.writerCommands))) throw Error("Memory operation unavailable or refused; no partial result is shown.");
|
|
856
928
|
}
|
|
857
|
-
if (mode === "preview") return options.json ? JSON.stringify(plan, null, 2) : setupPlanText(plan, s, renderOptions);
|
|
929
|
+
if (mode === "preview") return withConsole(options.json ? JSON.stringify(plan, null, 2) : setupPlanText(plan, s, renderOptions));
|
|
858
930
|
const result = mode === "apply" ? applySetup(plan, options) : undoSetup(plan, options);
|
|
859
|
-
return options.json ? JSON.stringify(result, null, 2) : setupResultText(result, s, plan, renderOptions);
|
|
931
|
+
return withConsole(options.json ? JSON.stringify(result, null, 2) : setupResultText(result, s, plan, renderOptions));
|
|
932
|
+
// #659: `setup all` keeps an acon plugin manifest the person already installed in step, from the same install root; it never
|
|
933
|
+
// creates one, and undo leaves it to `setup console --undo`. A refresh error after setup applied is a note, never a throw.
|
|
934
|
+
function withConsole(output: string): string {
|
|
935
|
+
const env = options.env ?? process.env;
|
|
936
|
+
if (target !== "all" || mode === "undo") return output;
|
|
937
|
+
let plugin: ConsoleSetup | { error: string };
|
|
938
|
+
// The inspection is part of the optional refresh: any error here, after native setup may have applied, is a note.
|
|
939
|
+
try {
|
|
940
|
+
plugin = consoleSetup(mode, env, plan.root ? join(plan.root.path, "src", "ui", "plugin.ts") : undefined, { existingOnly: true });
|
|
941
|
+
if (plugin.change === "none") return output;
|
|
942
|
+
} catch (error) { plugin = { error: `console plugin not refreshed: ${singleLine((error as Error).message)}; run amem setup console --apply after fixing it` }; }
|
|
943
|
+
if (options.json) return JSON.stringify({ ...JSON.parse(output), console: plugin }, null, 2);
|
|
944
|
+
return `${output}\n${"error" in plugin ? plugin.error : consoleSetupText(plugin, mode)}`;
|
|
945
|
+
}
|
|
860
946
|
}
|
|
861
947
|
|
|
862
948
|
|
|
@@ -33,7 +33,7 @@ function writerContextMessage(category:PlacementWriterRootCategory,causeClass:"m
|
|
|
33
33
|
const receipt=category==="setup receipt"&&setupTarget?setupReceiptRemedy(setupTarget):undefined;
|
|
34
34
|
if(phase==="initial")return `Sync placement initial writer proof is ${causeClass} (${category} category${cause}); ${receipt??(category==="setup receipt"?"upgrade or repair the managed amem install and its host exact pin, then rerun amem setup <target> --apply":"upgrade or repair the amem install and its host exact pin")}. Declare the complete writer roots and rerun amem migrate --sync-placement --dry-run.`;
|
|
35
35
|
if(receipt)return `Sync placement writer proof is ${causeClass} (${category} category${cause}); Placement sync refused [cause: setup_receipt_missing_install]: ${receipt}; then rerun the sync.`;
|
|
36
|
-
return `Sync placement writer proof is ${causeClass} (${category} category${cause}); restore the inventoried install, or renew it
|
|
36
|
+
return `Sync placement writer proof is ${causeClass} (${category} category${cause}); restore the inventoried install, or renew it while sessions keep running. If needed, preview amem formats raise home 0.22.0 and add --confirm after the exact command is approved. Run amem migrate --sync-placement --dry-run with the complete --writer-root inventory, then run --apply after the exact apply command is approved. When the live window needs compaction, save the preview with (umask 077; set -C; amem migrate --sync-placement --checkpoint --writer-root <install root> --json > checkpoint-plan.json), repeating --writer-root for every install root, then run amem migrate --sync-placement --checkpoint --confirm --plan checkpoint-plan.json with the same --writer-root list.`;
|
|
37
37
|
}
|
|
38
38
|
export class PlacementWriterContextError extends Error {
|
|
39
39
|
constructor(readonly category: PlacementWriterRootCategory, readonly causeClass: "missing" | "changed" | "unavailable",readonly phase:PlacementWriterContextPhase="active",readonly detail?:SyncPlacementWriterFailureDetail,readonly renewalState?:"pending"|"staging"|"checkpoint-pending",readonly setupTarget?:SetupTarget) {
|