@staix/agent-mem 0.23.1 → 0.24.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 +14 -4
- package/package.json +1 -1
- package/src/brief-cache.ts +54 -0
- package/src/brief-capture.ts +82 -0
- package/src/brief-curated-native.ts +32 -0
- package/src/brief-curated.ts +65 -0
- package/src/cli.ts +1 -0
- package/src/curated-brief-cache.ts +29 -0
- package/src/hook-contract.ts +6 -2
- package/src/hook-record.ts +22 -2
- package/src/hook-spool-replay.ts +8 -1
- package/src/hook-spool.ts +2 -2
- package/src/hook-transcript.ts +10 -2
- package/src/hooks.ts +65 -14
- package/src/index.ts +5 -1
- package/src/memory/candidate-pending.ts +6 -2
- package/src/memory/candidates.ts +4 -2
- package/src/memory/capture-input.ts +7 -0
- package/src/memory/capture-plan.ts +10 -0
- package/src/memory/capture.ts +78 -8
- package/src/memory/curated-cache-state.ts +35 -0
- package/src/memory/formats.ts +6 -0
- package/src/memory/generation-index.ts +2 -0
- package/src/memory/generation-sync.ts +3 -0
- package/src/memory/metrics.ts +7 -1
- package/src/memory/migrate.ts +7 -1
- package/src/memory/public-prune-activation.ts +4 -1
- package/src/memory/public-prune-advance.ts +2 -0
- package/src/memory/reader-lease.ts +5 -3
- package/src/memory/record-instruction.ts +26 -0
- package/src/memory/record-variant-log.ts +90 -0
- package/src/memory/shard-migration.ts +4 -1
- package/src/memory/shard-sync.ts +3 -0
- package/src/memory/store.ts +131 -2
- package/src/memory/sync-placement-activation.ts +11 -3
- package/src/memory/sync-placement-transport.ts +3 -0
- package/src/memory/sync.ts +3 -2
- package/src/session-brief-worker.ts +13 -2
- package/src/session-brief.ts +130 -70
- package/src/ui/plugin.ts +104 -30
- package/src/ui/snapshot-cache.ts +141 -0
- package/src/ui/snapshot-revision.ts +87 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { lstatSync, opendirSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { pendingSummary } from "../memory/candidate-pending.ts";
|
|
5
|
+
import { realPath } from "../memory/platform.ts";
|
|
6
|
+
import { inboxPolicyVersion } from "./inbox.ts";
|
|
7
|
+
|
|
8
|
+
type Scope = "home" | "realm" | "projects" | "generations" | "machines" | "machine" | "work" | "logs" | "evidence";
|
|
9
|
+
type Source = Scope | "file";
|
|
10
|
+
// ponytail: at most 16,384 directory entries and 24 levels per probe, including ignored entries.
|
|
11
|
+
// Refuse larger inventories; upgrade to an authoritative append-revision manifest before increasing these bounds.
|
|
12
|
+
const MAX_ENTRIES = 16_384, MAX_DEPTH = 24;
|
|
13
|
+
const realms = new Set(["user", "legacy", "legacy-main"]);
|
|
14
|
+
const evidence = new Set(["bridge-snapshots", "public-prune-objects", "public-prune-inputs", "public-prune-input-sets", "sync-placement"]);
|
|
15
|
+
const databases = /^(?:capture|candidates)\.db(?:-wal|-journal)?$/;
|
|
16
|
+
const derived = /^(?:index(?:-[a-z0-9]+)*|search(?:-[a-f0-9]+)?|catalog|mutation-lock|reader-admission)\.db(?:-(?:wal|shm|journal))?$/;
|
|
17
|
+
|
|
18
|
+
function source(scope: Scope, name: string): Source | undefined {
|
|
19
|
+
if (name === ".git" || name === "node_modules" || name === "reader-leases" || name === "leases" || name === "readers" || name === "shard-readers"
|
|
20
|
+
|| name.endsWith("-shm") || derived.test(name) || /^brief-(?:capture|curated)\.json$/.test(name)) return;
|
|
21
|
+
if (scope === "logs") return name.endsWith(".jsonl") ? "file" : undefined;
|
|
22
|
+
if (scope === "projects") return /^[a-f0-9]{16}$/.test(name) ? "realm" : undefined;
|
|
23
|
+
if (scope === "generations") return /^[a-f0-9]{32}$/.test(name) ? "realm" : undefined;
|
|
24
|
+
if (scope === "machines") return "machine";
|
|
25
|
+
if (scope === "machine") return databases.test(name) || name === "config.json" ? "file" : undefined;
|
|
26
|
+
if (scope === "work") return name === "log" ? "logs" : undefined;
|
|
27
|
+
if (scope === "evidence") return "evidence";
|
|
28
|
+
if (name === "log" || name === "local") return "logs";
|
|
29
|
+
if (name === "projects") return "projects";
|
|
30
|
+
if (name === "generations") return "generations";
|
|
31
|
+
if (name === "machine") return "machines";
|
|
32
|
+
if (name === "work") return "work";
|
|
33
|
+
if (realms.has(name)) return "realm";
|
|
34
|
+
if (evidence.has(name)) return "evidence";
|
|
35
|
+
if (name === "profile.lock" || databases.test(name) || /\.(?:json|jsonl)$/.test(name)) return "file";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Metadata of authoritative console inputs only. No payloads, read-write stores, index refresh or reader lease. */
|
|
39
|
+
export function snapshotRevision(base: string, now = Date.now()): string {
|
|
40
|
+
if (!Number.isFinite(now)) throw Error("snapshot revision clock is unavailable");
|
|
41
|
+
try { base = realPath(base); }
|
|
42
|
+
catch (error) { if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error; }
|
|
43
|
+
const frames: unknown[] = [];
|
|
44
|
+
let entries = 0;
|
|
45
|
+
const walk = (relative: string, expected: Source, depth: number) => {
|
|
46
|
+
if (depth > MAX_DEPTH) throw Error("snapshot source inventory exceeds its depth bound");
|
|
47
|
+
const file = join(base, relative), stat = lstatSync(file, { bigint: true, throwIfNoEntry: false });
|
|
48
|
+
if (!stat) {
|
|
49
|
+
if (relative) throw Error("snapshot source changed during inventory");
|
|
50
|
+
frames.push(["", "missing"]); return;
|
|
51
|
+
}
|
|
52
|
+
if (stat.isSymbolicLink() || !stat.isDirectory() && !stat.isFile()) throw Error("snapshot source is not a plain file or directory");
|
|
53
|
+
if (stat.isFile()) {
|
|
54
|
+
if (expected !== "file" && expected !== "evidence") throw Error("snapshot source directory is unavailable");
|
|
55
|
+
if (file.endsWith("-wal") && stat.size === 0n) return; // A read-only SQLite open may recreate an empty WAL.
|
|
56
|
+
frames.push([relative, "file", String(stat.dev), String(stat.ino), String(stat.mode), String(stat.size), String(stat.mtimeNs), String(stat.ctimeNs)]);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (expected === "file") throw Error("snapshot source file is unavailable");
|
|
60
|
+
const children: { name: string; kind: Source }[] = [], iterator = opendirSync(file);
|
|
61
|
+
try {
|
|
62
|
+
for (;;) {
|
|
63
|
+
const child = iterator.readSync(); if (!child) break;
|
|
64
|
+
if (++entries > MAX_ENTRIES) throw Error("snapshot source inventory exceeds its entry bound");
|
|
65
|
+
const kind = expected === "machines" && !child.isDirectory() && !child.isSymbolicLink() ? undefined : source(expected, child.name);
|
|
66
|
+
if (kind) children.push({ name: child.name, kind });
|
|
67
|
+
}
|
|
68
|
+
} finally { iterator.closeSync(); }
|
|
69
|
+
children.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
70
|
+
const start = frames.length;
|
|
71
|
+
frames.push(undefined);
|
|
72
|
+
const names: string[] = [];
|
|
73
|
+
for (const child of children) {
|
|
74
|
+
const before = frames.length;
|
|
75
|
+
walk(relative ? `${relative}/${child.name}` : child.name, child.kind, depth + 1);
|
|
76
|
+
if (frames.length > before) names.push(child.name);
|
|
77
|
+
}
|
|
78
|
+
// Readers may create an otherwise empty work/log tree alongside its disposable index.
|
|
79
|
+
if (relative && !names.length) { frames.splice(start, 1); return; }
|
|
80
|
+
// Directory times/size also change for excluded indexes and leases. Namespace plus identity tracks sources without that churn.
|
|
81
|
+
frames[start] = [relative, "directory", String(stat.dev), String(stat.ino), String(stat.mode), names];
|
|
82
|
+
};
|
|
83
|
+
walk("", "home", 0);
|
|
84
|
+
const policy = inboxPolicyVersion(base), pending = pendingSummary(base, undefined, now, true);
|
|
85
|
+
if (pending === null) throw Error("snapshot pending candidates are unavailable");
|
|
86
|
+
return createHash("sha256").update(JSON.stringify({ frames, policy, pending })).digest("hex");
|
|
87
|
+
}
|