@staix/agent-mem 0.25.0 → 0.26.1
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 +6 -6
- package/package.json +1 -1
- package/src/hook-spool.ts +72 -10
- package/src/hooks.ts +5 -3
- package/src/ingest.ts +13 -5
- package/src/memory/bridge.ts +32 -7
- package/src/memory/capture-input.ts +152 -1
- package/src/memory/generation-index.ts +114 -50
- package/src/memory/inspection-bound.ts +27 -0
- package/src/memory/inspection-stream.ts +153 -0
- package/src/memory/metrics.ts +2 -2
- package/src/memory/platform.ts +18 -15
- package/src/memory/shard-bridge.ts +10 -5
- package/src/memory/store.ts +1 -1
- package/src/memory/sync-policy-inspection.ts +5 -4
- package/src/memory/sync-screen.ts +3 -3
- package/src/memory/sync.ts +26 -4
- package/src/session-brief-worker.ts +5 -2
- package/src/ui/plugin.ts +1 -1
package/src/memory/sync.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { assertFormatFloor } from "./formats.ts";
|
|
|
4
4
|
import { closeSync, constants, existsSync, openSync, readFileSync, rmSync, writeFileSync, writeSync } from "node:fs";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { rebindPublicPruneProfile } from "./generation.ts";
|
|
7
|
-
import { memoryGitArgv, memoryGitEnv, processLiveness, processSignature } from "./platform.ts";
|
|
7
|
+
import { memoryGitArgv, memoryGitEnv, memoryGitSync, processLiveness, processSignature } from "./platform.ts";
|
|
8
8
|
import { acquireMutation } from "./mutation.ts";
|
|
9
9
|
import type { MemoryStore } from "./store.ts";
|
|
10
10
|
import { syncGenerationMemory } from "./generation-sync.ts";
|
|
@@ -233,11 +233,35 @@ export interface SyncOptions {
|
|
|
233
233
|
|
|
234
234
|
export { shardSyncBinding, shardSyncSourceBinding } from "./sync-binding.ts";
|
|
235
235
|
|
|
236
|
+
const NO_SYNC_REMOTE = "no sync remote: a person sets one with `amem sync --remote <private git url>`";
|
|
237
|
+
|
|
238
|
+
/** Configuration-only preflight: an unconfigured transport has no outbound rows to screen. */
|
|
239
|
+
function missingSyncRemote(store: MemoryStore): string | undefined {
|
|
240
|
+
const sharded = store.profile.sharded, generation = store.profile.kind === "generation";
|
|
241
|
+
const dir = sharded ? join(store.profile.home, "shard-sync") : store.dir;
|
|
242
|
+
const repository = sharded ? join(dir, "objects.git") : join(dir, ".git");
|
|
243
|
+
const reason = sharded ? "no shard sync remote configured" : generation ? "no generation sync remote configured" : NO_SYNC_REMOTE;
|
|
244
|
+
if (!existsSync(repository)) return reason;
|
|
245
|
+
const args = [...(sharded ? ["--git-dir", repository] : []), "remote", "get-url", "origin"];
|
|
246
|
+
// Admission below must remain synchronous until it acquires the mutation lock.
|
|
247
|
+
const remote = memoryGitSync(["-C", dir, ...args], { encoding: "utf8", timeout: STEP_MS,
|
|
248
|
+
env: memoryGitEnv(process.env, { repositoryIsolation: generation }) });
|
|
249
|
+
return remote.status === 0 && remote.stdout.trim() ? undefined : reason;
|
|
250
|
+
}
|
|
251
|
+
|
|
236
252
|
export async function syncMemory(store: MemoryStore, opts: SyncOptions = {}): Promise<SyncResult> {
|
|
237
253
|
assertFormatFloor(store.profile.home, "sync");
|
|
238
254
|
const placementRefusal = placementRuntimeRefusal(store.profile.home, store.profile);
|
|
239
255
|
if (placementRefusal) return { ok: false, pushed: false, entries: 0, error: placementRefusal };
|
|
240
256
|
if (store.profile.publicationFormat === "agent-mem.sync-placement/v1") return (await import("./sync-placement-transport.ts")).syncPlacementMemory(store, opts);
|
|
257
|
+
if (opts.signal?.aborted) return { ok: false, pushed: false, entries: 0, error: "stopped" };
|
|
258
|
+
if (!opts.remote) {
|
|
259
|
+
try {
|
|
260
|
+
const error = missingSyncRemote(store);
|
|
261
|
+
if (opts.signal?.aborted) return { ok: false, pushed: false, entries: 0, error: "stopped" };
|
|
262
|
+
if (error) return { ok: false, pushed: false, entries: 0, error };
|
|
263
|
+
} catch { return { ok: false, pushed: false, entries: 0, error: "sync remote configuration unavailable" }; }
|
|
264
|
+
}
|
|
241
265
|
if (store.profile.sharded) {
|
|
242
266
|
try {
|
|
243
267
|
// Refresh only through the existing proved monotone profile rebind before pinning this attempt.
|
|
@@ -270,8 +294,6 @@ export async function syncMemory(store: MemoryStore, opts: SyncOptions = {}): Pr
|
|
|
270
294
|
const dir = store.dir;
|
|
271
295
|
const fail = (error: string): SyncResult => ({ ok: false, pushed: false, entries: 0, error });
|
|
272
296
|
if (opts.signal?.aborted) return fail("stopped");
|
|
273
|
-
const noRemote = "no sync remote: a person sets one with `amem sync --remote <private git url>`";
|
|
274
|
-
if (!opts.remote && !existsSync(join(dir, ".git"))) return fail(noRemote); // never set up: nothing to do, nothing created
|
|
275
297
|
const release = lock(dir);
|
|
276
298
|
if (!release) return fail("another sync is running on this machine");
|
|
277
299
|
let releaseMutation: (() => void) | undefined, releaseCurated: (() => void) | undefined;
|
|
@@ -295,7 +317,7 @@ export async function syncMemory(store: MemoryStore, opts: SyncOptions = {}): Pr
|
|
|
295
317
|
}
|
|
296
318
|
const url = (await git(dir, ["remote", "get-url", "origin"], opts.signal)).out;
|
|
297
319
|
if (opts.signal?.aborted) return fail("stopped");
|
|
298
|
-
if (!url) return fail(
|
|
320
|
+
if (!url) return fail(NO_SYNC_REMOTE);
|
|
299
321
|
// Long-term entries hold note text: a public remote would publish them.
|
|
300
322
|
const visibility = await (opts.visibility ?? remoteVisibility)(url);
|
|
301
323
|
if (visibility === "public") return fail("the sync remote is public; memory syncs only to a private remote");
|
|
@@ -64,7 +64,7 @@ if (import.meta.main) {
|
|
|
64
64
|
if (line === undefined) stop();
|
|
65
65
|
const first = JSON.parse(line) as Record<string, unknown>;
|
|
66
66
|
type Scan = { cwd: string; base: string; transcript: unknown; policy?: BriefOptions["policy"]; deadlineAt: number; event?: "Stop" | "SessionEnd" };
|
|
67
|
-
type DrainOptions = BriefOptions & { current: string; event: string; identity?: unknown; deadlineAt: number; ownedGroup: boolean; hookStartAt?: number };
|
|
67
|
+
type DrainOptions = BriefOptions & { current: string; event: string; identity?: unknown; deadlineAt: number; ownedGroup: boolean; hookStartAt?: number; session?: string };
|
|
68
68
|
const scan = first.scan as Scan | undefined;
|
|
69
69
|
const scanEvent = scan?.event === "Stop" || scan?.event === "SessionEnd" ? scan.event : undefined;
|
|
70
70
|
const deadlineAt = scan?.deadlineAt ?? first.deadlineAt;
|
|
@@ -106,7 +106,10 @@ if (import.meta.main) {
|
|
|
106
106
|
drain({ startMs: Math.round(now() - (options.hookStartAt ?? end)), drained: drainedCount });
|
|
107
107
|
drainStarted = true;
|
|
108
108
|
}
|
|
109
|
-
const
|
|
109
|
+
const session = typeof options.session === "string" && /^[a-f0-9]{16}$/.test(options.session) ? options.session : undefined;
|
|
110
|
+
// #385 route A: attribute this session's non-project rows. ponytail: a non-project cwd's own hook still drains its own rows
|
|
111
|
+
// under that directory's fallback key (memory@..., tmp@...), which files them in a junk project; known limit, upgrade: defer them to route A.
|
|
112
|
+
const drained = await drainHookCaptures({ ...options, base: options.base!, project, expectedScope, timeRemaining: remaining, replayBudget: budget, session }, (input, receipt) => {
|
|
110
113
|
store ??= new CaptureStore({ memoryDir: options.base!, project, busyTimeoutMs: 0, cwd: options.cwd });
|
|
111
114
|
const appended = store.append(input, { receipt });
|
|
112
115
|
summaryThrough = Math.max(summaryThrough, store.briefCommitId);
|
package/src/ui/plugin.ts
CHANGED
|
@@ -90,7 +90,7 @@ export const plugin = {
|
|
|
90
90
|
api: 1 as const, tool: "amem", version: VERSION, title: "Memory", icon: "memory", pollMs: 15_000,
|
|
91
91
|
panels: [
|
|
92
92
|
{ id: "review", title: "Review", order: 1 },
|
|
93
|
-
{ id: "recap", title: "Recap", order: 2 },
|
|
93
|
+
{ id: "recap", title: "Recap", order: 2, maxAgeMs: 15_000 },
|
|
94
94
|
{ id: "find", title: "Search", order: 3 },
|
|
95
95
|
{ id: "timeline", title: "Timeline", order: 4 },
|
|
96
96
|
{ id: "work", title: "Work lists", order: 5 },
|