@staix/agent-mem 0.7.0 → 0.9.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 +14 -4
- package/package.json +1 -1
- package/src/cli.ts +86 -17
- package/src/commands-table.ts +15 -9
- package/src/index.ts +6 -0
- package/src/mcp-memory.ts +28 -1
- package/src/mcp.ts +1 -0
- package/src/memory/candidates.ts +86 -2
- package/src/memory/capture.ts +1 -1
- package/src/memory/commands.ts +2 -2
- package/src/memory/consolidate.ts +78 -0
- package/src/memory/consolidation-clusters.ts +56 -0
- package/src/memory/consolidation-model.ts +97 -0
- package/src/memory/doctor.ts +11 -8
- package/src/memory/eval-fixture.ts +8 -0
- package/src/memory/eval-set-ko.json +90 -0
- package/src/memory/eval.ts +5 -3
- package/src/memory/evidence.ts +76 -0
- package/src/memory/external-import.ts +267 -0
- package/src/memory/import.ts +91 -0
- package/src/memory/platform.ts +17 -2
- package/src/memory/policy.ts +29 -9
- package/src/memory/project-export.ts +57 -22
- package/src/memory/project-import.ts +147 -0
- package/src/memory/shard-sync-format.ts +3 -4
- package/src/memory/shard-sync.ts +135 -17
- package/src/memory/store.ts +63 -9
- package/src/memory/sync-cadence.ts +15 -5
- package/src/memory/sync.ts +16 -4
- package/src/setup-toml.ts +5 -0
- package/src/setup.ts +6 -6
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Curated memory with append-only JSONL logs, a derived SQLite index, short- and long-term tiers, a typed graph, goals with leases, and git sync between machines. Extracted from [agent-hub](https://github.com/STAIxBWLB/agent-hub), with compatible storage and entry IDs.
|
|
4
4
|
|
|
5
|
-
Version: 0.
|
|
5
|
+
Version: 0.9.1. Requires Bun 1.4.2 or later; no runtime dependencies.
|
|
6
6
|
|
|
7
7
|
## Quick start
|
|
8
8
|
|
|
@@ -203,7 +203,7 @@ Project identity (#15 D2) keeps `memoryProjectKey`: a worktree, a submodule and
|
|
|
203
203
|
|
|
204
204
|
`store.search(query, filter)` searches the curated tier and the current project's capture shard with SQLite FTS5 and BM25 plus tier/recency weighting: natural multi-word queries match partial term sets (the substring filter required every word), and a curated row outranks the same text in the capture tier. Prefix terms match inflections and Korean particles in either direction by retaining the original query term and adding a common-particle-stripped alternative. The FTS copy of the curated rows lives in its own derived `search.db` (`index.db`'s table set is a frozen contract and gains nothing); it is written from the same apply path as the index, and a prune, crash or rebuild is detected and resynced, so the incremental FTS copy equals a full resync. Where FTS5 is unavailable the engine falls back to the substring filter and reports `engine: "substring"`; capture recall needs FTS5 and is skipped in the fallback. The library entry exports `CaptureStore`, `captureSearch`, `readCaptureConfig`, `writeCaptureConfig`, `SearchIndex`, `fts5Available`, the shard helpers (`resolveAlias`, `appendAlias`, `listAliases`, `shardKeyHash`), the catalog (`rebuildCatalog`, `readCatalog`, `scanCatalog`) and the capacity advisor (`capacityReport`).
|
|
205
205
|
|
|
206
|
-
`amem eval [--set
|
|
206
|
+
`amem eval [--set ko|<file>] [--k 1,5,10] [--json]` measures recall with no model and no network (agent-mem#40 F13): it replays a question set and reports recall@k, hit@k and MRR. It scores the ranked `store.search` (BM25 with tier and recency weights), which is what the MCP `amem_search` tool and hub recall rank with and what #13 AC4 measured. It is not the `amem search` command: that one is a substring filter (every word must appear, newest first), so `amem search lighthouse beacon` can print nothing for a note that `amem eval` finds. Whether `amem search` should use the ranked search is a separate question. Without `--set` it scores the built-in synthetic set (26 invented harbour entries, long and short tier, written a day apart, and 32 questions, shipped in `src/memory/eval-set.json`), which is seeded into a throwaway store, so it never reads or writes your memory home and gives the same numbers on every machine. A set of your own either carries its own `entries` (self-contained, named by `key`) or, without entries, names real entry ids (or a prefix of 8 or more hex characters) and is scored against this project's store; each name is resolved like `amem show` does (a promoted short-term id finds its long-term copy, and a superseded id stands for the entry that replaced it, since search returns only live entries), and a prefix that matches more than one live entry is refused. `mem:<id>` as a brief prints it is accepted. Questions whose expected entry is not in the store score 0 in `all` and are left out of `answerable`, and `answerable` is scored over the entries the store holds, so a ranking problem and a coverage problem stay apart (`n/a` when no question is answerable). `--set ko` scores the second built-in set instead: 37 invented Korean entries and 38 questions (particle variants, spaced and unspaced compounds, mixed Korean-English terms, Latin abbreviations, short and long tier), with its baseline recorded in `docs/contracts.md` (agent-mem#62). Set format: `docs/contracts.md#recall-evaluation-f13`.
|
|
207
207
|
|
|
208
208
|
The R7 capacity advisor reports this machine's load and proposes capture bounds: `amem capacity [--json]` shows capture size and growth, disk, memory, the rolling `metrics.jsonl` readings and the proposal with its binding constraint; `amem capacity apply [--cap-mb N] [--retention-days N]` saves a preview, and only a matching later `--confirm` writes the home default config. Applying is person-only (agent markers refused, a terminal required); an agent may read the proposal through the library, never apply it. Under the 2026-10-17 owner decision (item 2) the proposal is the largest cap and retention that fit, and it may be above the current values: the cap is the disk-share bound itself (default 2% of free space, `--disk-share`), and retention is the share divided by the measured daily growth, up to a 365-day ceiling (a `ponytail:` constant, a person setting is the upgrade path). A hook p95 over 150 ms or hook RSS over 100 MB halves the proposed cap, and search RSS over 200 MB halves the retention. The reason names every binding constraint: `disk-share retention` or `retention ceiling`, `disk-share cap`, `R3 search RSS`, `R2 hook cost`. A proposal is never written by the advisor, and `apply` still takes `--cap-mb` and `--retention-days` to override it. Benchmark samples stay in the measuring script's synthetic home; only real hook and search invocations feed the advisor's rolling metrics.
|
|
209
209
|
|
|
@@ -284,6 +284,8 @@ Successful native project identities have a private, bounded derived cache (128
|
|
|
284
284
|
|
|
285
285
|
Intake runs at the end of each Codex, Kimi and Pi session once `amem setup <cli> --apply` has registered it. Sync is off unless you ask for it: amem registers no sync hook and runs nothing between sessions. To sync on your own schedule, call `amem sync --if-due` from your shell (for example an EXIT trap in `~/.zshrc`; it needs a terminal). It syncs at most hourly, backs off 15 minutes doubling to a day after failures, stops after 30 seconds, and does nothing without a remote set by `amem sync --remote <private git url>`. `--force` skips the schedule and the backoff.
|
|
286
286
|
|
|
287
|
+
Split-home sync durably holds verified foreign-generation prunes with a "held, not applied" warning while unrelated sync continues; targets can remain visible, and full cross-generation removal remains a separate ceiling (see [the sync contract](docs/contracts.md#per-shard-private-sync-15-t3)).
|
|
288
|
+
|
|
287
289
|
## Native transcript intake
|
|
288
290
|
|
|
289
291
|
`amem ingest` reads existing Codex, Kimi or Pi transcripts and writes screened deterministic capture rows, never curated notes. Run it from the project to bind intake to that working directory; the CLI exposes no project/home override or policy bypass:
|
|
@@ -367,7 +369,7 @@ Real migration remains blocked until the separately reviewed generation-capable
|
|
|
367
369
|
|
|
368
370
|
## Curated shard migration (#15 T2)
|
|
369
371
|
|
|
370
|
-
`amem migrate --shards` moves the curated single home into `projects/<key-hash>/` and `user/` through a resumable generation journal. The original single-home log bytes are never rewritten. A populated selected generation is supported and keeps its generation ID. Each shard keeps private legacy inputs in read-only `legacy/`, public-main inputs in read-only `legacy-main/`, and generation-born rows in its own `log/` and `local/`. It has its own `index.db`, `search.db` and mutation lock; original IDs, hashes, placement and own/local/public provenance are preserved. The source generation bytes stay unchanged. Immutable prune proofs are validated before effects; a multi-shard prune is translated into one deterministic row per shard, with a receipt naming the original row. Existing capture and `work/` directories are not migration inputs and are left untouched. `catalog.db` remains derived and rebuildable, now including curated entry counts and last use. Split curated stores sync the opened canonical project and user overlay to separate private-remote refs (`amem/p/<key-hash>` and `amem/u`) with `amem sync --policy-free`; unopened projects and machine data are not fetched. Original IDs and attribution survive independent generations.
|
|
372
|
+
`amem migrate --shards` moves the curated single home into `projects/<key-hash>/` and `user/` through a resumable generation journal. The original single-home log bytes are never rewritten. A populated selected generation is supported and keeps its generation ID. Each shard keeps private legacy inputs in read-only `legacy/`, public-main inputs in read-only `legacy-main/`, and generation-born rows in its own `log/` and `local/`. It has its own `index.db`, `search.db` and mutation lock; original IDs, hashes, placement and own/local/public provenance are preserved. The source generation bytes stay unchanged. Immutable prune proofs are validated before effects; a multi-shard prune is translated into one deterministic row per shard, with a receipt naming the original row. Existing capture and `work/` directories are not migration inputs and are left untouched. `catalog.db` remains derived and rebuildable, now including curated entry counts and last use. Split curated stores sync the opened canonical project and user overlay to separate private-remote refs (`amem/p/<key-hash>` and `amem/u`) with `amem sync --policy-free`; unopened projects and machine data are not fetched. Original IDs and attribution survive independent generations. See `docs/contracts.md`, "Per-shard private sync", for prune transport and application boundaries.
|
|
371
373
|
|
|
372
374
|
Before splitting a live home, every installed host must open it through `openShardStore({ project })` or the explicit user shard. Plain `new MemoryStore()` refuses any split marker, including an interrupted split, so it cannot silently keep writing the old layout. No host capability registry currently exists; migration preflight output states that limitation. Do not release T2 for agent-hub use until its memory factory is integrated with `openShardStore` and that host version is installed. Existing unannounced older builds remain the documented unchanged-source ceiling.
|
|
373
375
|
|
|
@@ -413,7 +415,7 @@ The frozen nine-tool contract for dotfiles#255 and maru#458:
|
|
|
413
415
|
|
|
414
416
|
Search/show/timeline label capture as recall with `evidence: false`; capture never enters the curated graph. Policy screens complete rows before selection, limits or graph construction. The standalone secret screen, private flags, PII patterns and deny paths compose with a host's stricter policy through `createMemoryMcp({cwd, base, policy})`. Screening errors fail closed. `base` is the exact memory root; historical library `home` options still name its parent. Scope and profile changes refuse further access instead of silently reopening another store. Graph reads retain the 5,000-row curated ceiling; work-list reads stream the complete ordered history without an operation-count ceiling, applying policy before latest-value reduction. The working state scales with the current result, not historical payloads. The graph ceiling is an operational bound, not an exposed count of unscreened data. Graphs cover curated-note relationships, not goal/suggestion tables.
|
|
415
417
|
|
|
416
|
-
`WorkListStore` writes `projects/<key-hash>/work/` with its own append log, derived index and lock. Scalar fields reduce by latest value, null clears, list status `done` closes, and item status is `todo|doing|done|dropped`. Work lists are outside generation selection and capture eviction. `amem import claude-mem` additionally imports `work_state_entries` only through persisted person-reviewed D2 aliases, preserving source DB bytes and stable replay receipts; JSON keeps observation fields and adds `work` counts/cursor.
|
|
418
|
+
`WorkListStore` writes `projects/<key-hash>/work/` with its own append log, derived index and lock. Scalar fields reduce by latest value, null clears, list status `done` closes, and item status is `todo|doing|done|dropped`. Work lists are outside generation selection and capture eviction. `amem import claude-mem` additionally imports `work_state_entries` only through persisted person-reviewed D2 aliases, preserving source DB bytes and stable replay receipts; JSON keeps observation fields and adds `work` counts/cursor. `--capture-days N` also imports observations and session summaries from the last N days into machine-local capture under the same aliases, with read/added/spooled/skipped counts, stable replay receipts and the configured capture cap and retention. Widening N after an earlier import requires `--restart` to revisit rows below the saved cursor. Chroma vectors are never read.
|
|
417
419
|
|
|
418
420
|
`amem vault-candidates --json` and the MCP read tool select durable long-term notes under current policy, excluding task/review/PR/CI progress and already-linked entries. The deterministic status filter covers English status phrases and can miss paraphrased or other-language status text; candidates require person review. No vault is opened, indexed or written. Library `recordVaultLink` records an exact-entry hash and relative Markdown path in a generation-only local append op; it survives index rebuild and shard migration, stays machine-local, and does not change shared-v1 schemas or sync semantics. There is no MCP link writer.
|
|
419
421
|
|
|
@@ -450,3 +452,11 @@ Use `amem brief --for "repair the writer" --paths src/writer.ts` for a byte-capp
|
|
|
450
452
|
Current recall omits superseded and expired entries. `amem show <id> --history` shows retained versions, `amem graph <id> --history` follows retained history, and `amem search writer --as-of 2026-10-20 --history` reads retained state at UTC midnight. Current forget/prune removals still hide the text at every past date. Promotion event time is not serialized, so affected history reports `promotion time unknown: tier before promotion cannot be recovered`. `(stale?)` is only a bounded path-metadata hint. See `docs/contracts.md` for retention and history limits.
|
|
451
453
|
|
|
452
454
|
The library exports `buildIntentBrief`, `planGuardNodes`, `matchingPlanFails` and nullable usage callbacks. Emitted output may record rendered counts; delivered and cited counts need explicit host observations. Missing evidence stays unknown. Agent-hub adoption is a separate follow-up after a published library release.
|
|
455
|
+
|
|
456
|
+
## Consolidation and evidence
|
|
457
|
+
|
|
458
|
+
Run `amem consolidate [--project <current-key>]` (another project is refused) to queue deterministic proposals for `amem review`. It compares a bounded project-local window using indexed text overlap, shared paths and current supersession-chain metadata. It does not edit curated notes. The person reviews each merge, replacement or recurring-failure summary, and acceptance rechecks every source revision. A recurring-failure summary preserves its source failures and decisions. Large source quotations are counted as too large instead of silently shortened into a proposed note.
|
|
459
|
+
|
|
460
|
+
The CLI runs the deterministic pass only. A library host may explicitly enable an injected model callback for the person; no provider is built in. It has batch, byte, deadline and persistent daily limits. Model answers remain marked machine-local candidates that cannot be accepted; `amem note add` is the separate path for an independently authored note. A non-answer is never saved.
|
|
461
|
+
|
|
462
|
+
Agents use `amem_evidence` with a question to get cited, live curated entries, not an answer. The complete JSON bundle is byte-capped (`maxBytes`, default 4096, range 256..8192); excerpted entries retain an exact `mem:` reference for fetching the full note. Capture, repository-only rows, pending candidates and model answers are excluded. amem makes no model call for this tool. Rendering a citation in the bundle records only `rendered` after successful output, never `delivered` or `cited`.
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import type { Writable } from "node:stream";
|
|
3
3
|
import { buildIntentBrief } from "./memory/intent-brief.ts";
|
|
4
|
+
import { proposeConsolidation } from "./memory/consolidate.ts";
|
|
4
5
|
import { createIntentBriefSource } from "./memory/recall.ts";
|
|
5
6
|
import { createRecallStalenessProbe } from "./memory/recall-staleness.ts";
|
|
6
7
|
import { recordMemoryUse } from "./memory/use-telemetry.ts";
|
|
@@ -10,7 +11,7 @@ import { serveMcp, writeConfirmed } from "./mcp.ts";
|
|
|
10
11
|
import { createStandalonePolicy } from "./memory/policy.ts";
|
|
11
12
|
import { configuredPolicy, configuredPolicyOptions, loadAmemConfig, repoConfigRoot } from "./memory/config.ts";
|
|
12
13
|
import { vaultCandidates } from "./memory/vault.ts";
|
|
13
|
-
import { importClaudeMemWorkState } from "./memory/import.ts";
|
|
14
|
+
import { importClaudeMemCapture, importClaudeMemWorkState } from "./memory/import.ts";
|
|
14
15
|
import { closeSync, constants, existsSync, fstatSync, lstatSync, openSync, readFileSync, readSync, rmSync, writeFileSync } from "node:fs";
|
|
15
16
|
import { join } from "node:path";
|
|
16
17
|
import { MemoryStore, looksSecret, machineId, openShardStore, type StoreOptions } from "./memory/store.ts";
|
|
@@ -33,19 +34,21 @@ import { readCatalogFresh } from "./memory/catalog.ts";
|
|
|
33
34
|
import { appendLifecycle, assertProjectActive, projectState } from "./memory/lifecycle.ts";
|
|
34
35
|
import { gcText, runGc } from "./memory/gc.ts";
|
|
35
36
|
import { usageReport, usageText } from "./memory/usage.ts";
|
|
36
|
-
import { exportProject } from "./memory/project-export.ts";
|
|
37
|
+
import { exportProject, type ProjectExportFormat } from "./memory/project-export.ts";
|
|
38
|
+
import { importProject } from "./memory/project-import.ts";
|
|
39
|
+
import { importExternalMemory, type ExternalMemorySource } from "./memory/external-import.ts";
|
|
37
40
|
import { searchAllProjects, vaultCandidatesAll } from "./memory/cross-project.ts";
|
|
38
41
|
import { requireShard } from "./memory/curated-read.ts";
|
|
39
42
|
import { appendGitattributes, appendRepoLine, boundRepoRoot, planGitattributes, planRepoPromotion, readRepoScope, repoLogIgnored, repoLogPath, repoReadPolicy, repoVisibility, type RepoView } from "./memory/repo-scope.ts";
|
|
40
43
|
import type { Visibility } from "./memory/sync.ts";
|
|
41
44
|
import { applySplit, previewSplit } from "./memory/capacity-split.ts";
|
|
42
45
|
import { evalText, parseKs } from "./memory/eval.ts";
|
|
43
|
-
import { evalSeeded, evalStore, FIXTURE_PATH, readEvalSet } from "./memory/eval-fixture.ts";
|
|
46
|
+
import { builtinSet, evalSeeded, evalStore, FIXTURE_PATH, readEvalSet } from "./memory/eval-fixture.ts";
|
|
44
47
|
import { markShown, pendingSummary } from "./memory/candidate-pending.ts";
|
|
45
48
|
import { buildNote, FAIL_TEMPLATE, hasFailLabel, noteAdd, parseFailTemplate, type FailFields } from "./memory/note-add.ts";
|
|
46
49
|
import { runEditor } from "./memory/editor.ts";
|
|
47
50
|
import { doctorReport, doctorText } from "./memory/doctor.ts";
|
|
48
|
-
import { nextSyncAt, readSyncState, recordSyncAttempt, remoteConfigured, syncDue, stopSignal, syncOutcome, usableState, SYNC_IF_DUE_DEADLINE_MS, type StopCause } from "./memory/sync-cadence.ts";
|
|
51
|
+
import { endLikeSignal, nextSyncAt, readSyncState, recordSyncAttempt, remoteConfigured, syncDue, stopSignal, syncOutcome, usableState, SYNC_IF_DUE_DEADLINE_MS, type StopCause } from "./memory/sync-cadence.ts";
|
|
49
52
|
|
|
50
53
|
export const PERSON_ONLY = "amem is for the person: an agent reads memory through its `amem mcp` server (see `amem --help`); the person reviews what agents propose with `amem review`";
|
|
51
54
|
const VERSION = (JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")) as { version: string }).version;
|
|
@@ -67,6 +70,8 @@ export interface CliContext {
|
|
|
67
70
|
edit?: (initial: string) => string | Promise<string>;
|
|
68
71
|
/** Test seam: the `sync --if-due` deadline in milliseconds (the CLI always uses 30 seconds). */
|
|
69
72
|
syncDeadlineMs?: number;
|
|
73
|
+
/** Called with the signal name when a person's signal ended `sync --if-due`, after its handlers are removed. `main` re-raises it once the output is written; absent, nothing happens. */
|
|
74
|
+
onPersonStop?: (signal: string) => void;
|
|
70
75
|
stdin?: () => string;
|
|
71
76
|
}
|
|
72
77
|
|
|
@@ -227,6 +232,23 @@ export async function runCli(argv: readonly string[], context: CliContext = {}):
|
|
|
227
232
|
} catch { return false; } finally { try { candidates?.close(); } catch { /* optional telemetry cannot fail emitted output */ } }
|
|
228
233
|
} });
|
|
229
234
|
};
|
|
235
|
+
if (sub === "consolidate") {
|
|
236
|
+
const requested = typeof options["--project"] === "string" ? options["--project"] as string : boundProject();
|
|
237
|
+
if (!requested.trim() || requested.length > 400 || requested.includes("\0")) throw Error("invalid consolidation project");
|
|
238
|
+
const base = memoryHome(), project = resolveAlias(base, requested), aliases = aliasedKeys(base, project);
|
|
239
|
+
// The policy below is narrowed by the repository around the working directory, which is the bound project's. Another project's own repository policy cannot be resolved from here, so screening it with this one would apply the wrong narrowing.
|
|
240
|
+
if (project !== boundProject()) throw Error("consolidate --project must name the current project; run it from the other project's directory to consolidate that one");
|
|
241
|
+
assertProjectActive(base, project);
|
|
242
|
+
const store = curatedStore(project, { deferPromotions: true, screen: () => "keep" });
|
|
243
|
+
let candidates: CandidateStore | undefined;
|
|
244
|
+
try {
|
|
245
|
+
const binding = commandBinding(store.profile.home, boundProject()), policyKey = () => JSON.stringify(configuredPolicyOptions(base, policyCwd));
|
|
246
|
+
const assertCurrent = () => { binding(); assertProjectActive(base, project); if (resolveAlias(base, requested) !== project || aliasedKeys(base, project).join("\n") !== aliases.join("\n")) throw Error("consolidation project binding changed"); };
|
|
247
|
+
candidates = new CandidateStore({ memoryDir: base, reconcile: { canonical: project, aliases } });
|
|
248
|
+
const report = await proposeConsolidation(store, candidates, { project, actor: "person", policy: policyOf, policyVersion: policyKey, assertCurrent });
|
|
249
|
+
return options["--json"] ? JSON.stringify(report, null, 2) : `${report.candidates.length} consolidation candidates queued for amem review; no curated notes changed${report.alreadyReviewed ? `; ${report.alreadyReviewed} already reviewed` : ""}${report.truncated ? "; scan truncated" : ""}${report.oversized ? `; ${report.oversized} proposals too large` : ""}${report.localExcluded ? `; ${report.localExcluded} local sources excluded` : ""}`;
|
|
250
|
+
} finally { candidates?.close(); store.close(); }
|
|
251
|
+
}
|
|
230
252
|
if (sub === "brief") {
|
|
231
253
|
const intent = options["--for"]; if (typeof intent !== "string" || !intent.trim() || intent.length > 1000 || parsed.positionals.length) throw Error("usage: amem brief --for <intent> [--paths <path>] [--symbols <symbol>] [--bytes N] [--json]");
|
|
232
254
|
const rawBytes = options["--bytes"];
|
|
@@ -382,6 +404,8 @@ export async function runCli(argv: readonly string[], context: CliContext = {}):
|
|
|
382
404
|
: `promotion. Goal goal:${input.goalId}, target mem:${input.target.id} changed or is unavailable; reject or skip`;
|
|
383
405
|
} finally { viewStore.close(); }
|
|
384
406
|
}
|
|
407
|
+
if (input.kind === "model-answer") return `Model answer (not evidence; cannot accept, author an independent note with amem note add). ${input.text}`;
|
|
408
|
+
if (input.kind === "consolidation") return `${input.action}. Sources: ${input.targets.map(target => `mem:${target.id}`).join(", ")}. ${input.text}`;
|
|
385
409
|
return input.kind === "memory" ? `${input.title ? `${input.title}: ` : ""}${input.text}` : input.kind === "fail" ? `fail. Approach: ${input.approach} Symptom: ${input.symptom} Cause: ${input.cause} Retry when: ${input.retryWhen}`
|
|
386
410
|
: input.kind === "correction" ? `correction. ${input.proposedText} Reason: ${input.reason}` : `decay. ${input.reason}`; };
|
|
387
411
|
const step = async (args: string[]) => { try { await runCli(args, context); return true; } catch (error) { lines.push(` ${(error as Error).message.split("\n")[0]}`); done.failed++; return false; } };
|
|
@@ -435,6 +459,7 @@ export async function runCli(argv: readonly string[], context: CliContext = {}):
|
|
|
435
459
|
if (!await policyOf().screen(candidate.input)) throw new Error("candidate refused by the current standalone privacy policy (secrets, personal data, deny paths and the patterns in amem.config.json)");
|
|
436
460
|
assertCurrent();
|
|
437
461
|
const result = candidates.accept(id!, { project, actor: "person", verdict: "public", store,
|
|
462
|
+
policyVersion: () => JSON.stringify(configuredPolicyOptions(realPath(store.profile.home), policyCwd)),
|
|
438
463
|
policy: (proposal, target, note, goal) => { assertCurrent(); return policyOf().screenStandalone({ ...proposal.input, ...(target ? { targetView: target } : {}), note, ...(goal ? { goalView: goal } : {}) }); },
|
|
439
464
|
});
|
|
440
465
|
return options["--json"] ? JSON.stringify(result, null, 2) : `accepted candidate ${id} as ${candidate.input.kind === "promotion" ? "promoted" : "ordinary"} note ${result.noteId}`;
|
|
@@ -457,14 +482,15 @@ export async function runCli(argv: readonly string[], context: CliContext = {}):
|
|
|
457
482
|
// F13: read-only. A set with entries is scored against a throwaway store seeded with them (touches no memory home); one without scores the bound project's real entries.
|
|
458
483
|
const ks = parseKs(typeof options["--k"] === "string" ? options["--k"] : undefined);
|
|
459
484
|
const file = typeof options["--set"] === "string" ? options["--set"] : undefined;
|
|
460
|
-
const
|
|
485
|
+
const builtin = file === undefined ? undefined : builtinSet(file);
|
|
486
|
+
const set = readEvalSet(builtin ?? file ?? FIXTURE_PATH);
|
|
461
487
|
let report;
|
|
462
488
|
if (set.entries?.length) report = evalSeeded(set, ks);
|
|
463
489
|
else {
|
|
464
490
|
const project = boundProject(), store = curatedStore(project, { deferPromotions: true });
|
|
465
491
|
try { report = evalStore(store, project, set, ks); } finally { store.close(); }
|
|
466
492
|
}
|
|
467
|
-
return options["--json"] ? JSON.stringify(report, null, 2) : evalText(report, file ?? "built-in fixture");
|
|
493
|
+
return options["--json"] ? JSON.stringify(report, null, 2) : evalText(report, builtin ? `built-in fixture ${file}` : file ?? "built-in fixture");
|
|
468
494
|
}
|
|
469
495
|
if (sub === "capacity") {
|
|
470
496
|
const share = options["--disk-share"];
|
|
@@ -522,14 +548,37 @@ export async function runCli(argv: readonly string[], context: CliContext = {}):
|
|
|
522
548
|
const result = runGc(memoryHome(), { dryRun: options["--confirm"] !== true, ...(batches !== undefined ? { maxBatchesPerShard: batches } : {}) });
|
|
523
549
|
return options["--json"] ? JSON.stringify(result, null, 2) : `${result.dryRun ? "preview (nothing evicted; add --confirm):\n" : ""}${gcText(result)}`;
|
|
524
550
|
}
|
|
551
|
+
if (sub === "import" && ["claude-auto", "codex"].includes(parsed.path[1] ?? "")) {
|
|
552
|
+
for (const flag of ["--db", "--limit", "--restart", "--capture-days"]) if (options[flag] !== undefined) throw new Error(`${flag} only applies to import claude-mem`);
|
|
553
|
+
const source = parsed.path[1] as ExternalMemorySource, policy = policyOf();
|
|
554
|
+
const result = await importExternalMemory({ base: memoryHome(), project: boundProject(), source, cwd: policyCwd, env: context.env ?? process.env,
|
|
555
|
+
...(typeof options["--from"] === "string" ? { from: options["--from"] } : {}), policy: value => policy.screenStandalone(value) });
|
|
556
|
+
return options["--json"] ? JSON.stringify(result, null, 2)
|
|
557
|
+
: `imported ${result.added} ${source} candidates from ${result.files} files (${result.read} records, ${result.pending.count} pending); skipped ${result.skipped.rules} rule files, ${result.skipped.policy} policy/secret records, ${result.skipped.invalid} invalid records and ${result.skipped.truncated} oversized inputs${result.queueFull ? "; candidate queue is full" : result.limitReached ? "; per-run candidate cap reached" : ""}`;
|
|
558
|
+
}
|
|
525
559
|
if (sub === "project") {
|
|
526
560
|
const op = parsed.path[1]!, [requested] = parsed.positionals;
|
|
527
561
|
if (!requested) throw new Error(`usage: amem project ${op} <key>`);
|
|
528
562
|
if (op === "export") {
|
|
529
563
|
if (typeof options["--to"] !== "string") throw new Error("usage: amem project export <key> --to <file>");
|
|
564
|
+
const format = (options["--format"] ?? "json") as ProjectExportFormat;
|
|
530
565
|
// The bundle leaves the home, so it is screened by the configured policy (secrets, personal data, the configured patterns and deny paths).
|
|
531
|
-
const result = await exportProject(memoryHome(), requested, { to: options["--to"], policy: policyOf() });
|
|
532
|
-
return options["--json"] ? JSON.stringify(result, null, 2) : `exported ${result.project} to ${result.file}: ${result.counts.capture} capture rows, ${result.counts.curated} notes, ${result.counts.goals} goals, ${result.counts.workLists} work lists${result.withheld ? `; ${result.withheld} withheld by the screen` : ""}`;
|
|
566
|
+
const result = await exportProject(memoryHome(), requested, { to: options["--to"], policy: policyOf(), format });
|
|
567
|
+
return options["--json"] ? JSON.stringify(result, null, 2) : `exported ${result.project} to ${result.file} as ${result.format}: ${result.counts.capture} capture rows, ${result.counts.curated} notes, ${result.counts.goals} goals, ${result.counts.workLists} work lists${result.withheld ? `; ${result.withheld} withheld by the screen` : ""}`;
|
|
568
|
+
}
|
|
569
|
+
if (op === "import") {
|
|
570
|
+
if (typeof options["--from"] !== "string") throw new Error("usage: amem project import <key> --from <file.jsonl> [--confirm] [--allow-shared]");
|
|
571
|
+
const key = resolveAlias(memoryHome(), requested), policy = policyOf();
|
|
572
|
+
const store = curatedStore(key, { screen: note => policy.screenStandalone(note) ? "promote" : "keep", createAliases: true });
|
|
573
|
+
try {
|
|
574
|
+
const result = await importProject(store, { from: options["--from"], project: key, confirm: options["--confirm"] === true,
|
|
575
|
+
allowShared: options["--allow-shared"] === true, policy: note => policy.screenStandalone(note) });
|
|
576
|
+
const counts = `sources ${JSON.stringify(result.provenance.source)}, peers ${JSON.stringify(result.provenance.peer)}, scopes ${JSON.stringify(result.provenance.scope)}`;
|
|
577
|
+
const summary = result.applied ? `imported ${result.added} of ${result.read} curated notes into ${result.project} with their original ids`
|
|
578
|
+
: `preview: ${result.wouldAdd} of ${result.read} curated notes can be imported into ${result.project} with their original ids (re-run with --confirm to write)`;
|
|
579
|
+
return options["--json"] ? JSON.stringify(result, null, 2)
|
|
580
|
+
: `${summary}; ${counts}; skipped ${result.skipped.invalid} invalid, ${result.skipped.policy} policy/secret and ${result.skipped.other} non-curated records. ${result.warnings.join(" ")}`;
|
|
581
|
+
} finally { store.close(); }
|
|
533
582
|
}
|
|
534
583
|
const key = requireShard(memoryHome(), requested);
|
|
535
584
|
if (op === "forget" && options["--confirm"] !== true) {
|
|
@@ -675,25 +724,41 @@ export async function runCli(argv: readonly string[], context: CliContext = {}):
|
|
|
675
724
|
}
|
|
676
725
|
// Only a real attempt is stamped: a local refusal (lock held, no remote, policy, usage) is not, and a future stamp is no history (src/memory/sync-cadence.ts).
|
|
677
726
|
const stampSync = (error: string | undefined, cause?: StopCause) => { if (syncOutcome(error, cause) !== "local") recordSyncAttempt(syncHome, error === undefined, Date.now()); };
|
|
678
|
-
const
|
|
727
|
+
const captureImport = sub === "import" && parsed.path[1] === "claude-mem", captureDays = options["--capture-days"] === undefined ? undefined : Number(options["--capture-days"]);
|
|
728
|
+
if (captureImport && captureDays !== undefined && (!Number.isSafeInteger(captureDays) || captureDays <= 0)) throw new Error("--capture-days takes a positive integer");
|
|
729
|
+
const captureArgs = new Set<number>();
|
|
730
|
+
if (captureImport) for (let index = 0; index < args.length; index++) {
|
|
731
|
+
if (args[index] === "--capture-days") { captureArgs.add(index); captureArgs.add(index + 1); }
|
|
732
|
+
else if (args[index]?.startsWith("--capture-days=")) captureArgs.add(index);
|
|
733
|
+
}
|
|
734
|
+
const syncArgs = args.filter((arg, index) => arg !== "--if-due" && arg !== "--force" && !captureArgs.has(index));
|
|
679
735
|
let output: string;
|
|
680
736
|
const stop = ifDue ? stopSignal(context.syncDeadlineMs ?? SYNC_IF_DUE_DEADLINE_MS, process) : undefined;
|
|
681
737
|
try {
|
|
682
738
|
output = await withRepoRows(await rawMemoryCommand(syncArgs, cwd, { person: true, project: boundProject(), open, readable: notes => notes, stale: createRecallStalenessProbe({ cwd: recallRoot ?? cwd, rootConfirmed, policy: () => configured }), outputReady: notes => outputReady(notes.map(view => view.id)), importPolicy: () => text => configured.declinesPersonal(text),
|
|
683
739
|
sync: { screen: row => configured.screenStandalone(row), ...(stop ? { signal: stop.signal } : {}) }, // the repository-narrowed policy binds what sync publishes too
|
|
684
740
|
onBridgeStatus: status => { receipt.bridgeStatus = status; } }));
|
|
685
|
-
} catch (error) {
|
|
686
|
-
|
|
741
|
+
} catch (error) {
|
|
742
|
+
if (sub === "sync") stampSync((error as Error).message, stop?.cause());
|
|
743
|
+
throw error;
|
|
744
|
+
}
|
|
745
|
+
finally {
|
|
746
|
+
stop?.dispose();
|
|
747
|
+
// A run its person ended ends like that signal (130, 143, 129, 131), as `amem doctor` does, also when `--json` reports it as a result instead of an error: the caller decides when.
|
|
748
|
+
const ended = stop?.cause() === "person" ? stop.signalName() : undefined;
|
|
749
|
+
if (ended !== undefined) context.onPersonStop?.(ended);
|
|
750
|
+
}
|
|
687
751
|
if (sub === "sync") {
|
|
688
752
|
// `--json` returns the failed result instead of throwing: read the real outcome from it, never assume a returned string means the sync worked.
|
|
689
753
|
let failure: string | undefined;
|
|
690
754
|
if (options["--json"]) { try { const result = JSON.parse(output) as { ok?: unknown; error?: unknown }; if (result.ok === false) failure = typeof result.error === "string" ? result.error : "sync failed"; } catch { /* not a sync result */ } }
|
|
691
755
|
stampSync(failure, stop?.cause());
|
|
692
756
|
}
|
|
693
|
-
if (
|
|
694
|
-
const policy = configured;
|
|
695
|
-
const work = await importClaudeMemWorkState({ base: memoryHome(), project: boundProject(), policy: row => policy.screen(row), ...
|
|
696
|
-
|
|
757
|
+
if (captureImport) {
|
|
758
|
+
const policy = configured, db = options["--db"] ? { db: String(options["--db"]) } : {}, limit = options["--limit"] ? { limit: Number(options["--limit"]) } : {}, restart = options["--restart"] === true;
|
|
759
|
+
const work = await importClaudeMemWorkState({ base: memoryHome(), project: boundProject(), policy: row => policy.screen(row), ...db, ...limit, restart });
|
|
760
|
+
const capture = captureDays === undefined ? undefined : await importClaudeMemCapture({ base: memoryHome(), project: boundProject(), cwd, days: captureDays, ...db, ...limit, restart, policy: { host: policy } });
|
|
761
|
+
return options["--json"] ? JSON.stringify({ ...JSON.parse(output), work, ...(capture ? { capture } : {}) }, null, 2) : `${output}\nwork lists: ${JSON.stringify(work)}${capture ? `\ncapture: ${JSON.stringify(capture)}` : ""}`;
|
|
697
762
|
}
|
|
698
763
|
return !options["--json"] && receipt.bridgeStatus
|
|
699
764
|
? `${output}\n(legacy malformed lines skipped: ${receipt.bridgeStatus.skippedRows})` : output;
|
|
@@ -704,10 +769,14 @@ export function formatCliError(error: unknown): string { return error instanceof
|
|
|
704
769
|
/** A completed write means rendered output, never evidence of host delivery or citation. */
|
|
705
770
|
export async function writeCliOutput(text: string, output: Writable = process.stdout): Promise<void> { await writeConfirmed(output, text); }
|
|
706
771
|
export async function main(argv = process.argv.slice(2)): Promise<void> {
|
|
772
|
+
let personStop: string | undefined;
|
|
707
773
|
try {
|
|
708
|
-
const receipts: CliOutputReceipt[] = [], output = await runCli(argv, { onOutputReady: receipt => receipts.push(receipt) });
|
|
774
|
+
const receipts: CliOutputReceipt[] = [], output = await runCli(argv, { onOutputReady: receipt => receipts.push(receipt), onPersonStop: name => { personStop ??= name; } });
|
|
709
775
|
if (output) { await writeCliOutput(output + "\n"); for (const receipt of receipts) { try { receipt.rendered(); } catch { /* telemetry stays optional */ } } }
|
|
710
|
-
} catch (error) {
|
|
776
|
+
} catch (error) {
|
|
777
|
+
console.error(formatCliError(error)); process.exitCode = (error as { exitCode?: number }).exitCode ?? 1;
|
|
778
|
+
}
|
|
779
|
+
if (personStop !== undefined) endLikeSignal(personStop); // after the report, with amem's own handlers already removed
|
|
711
780
|
}
|
|
712
781
|
|
|
713
782
|
if (import.meta.main) await main();
|
package/src/commands-table.ts
CHANGED
|
@@ -24,6 +24,7 @@ const filters = { ...json, "--tier": { description: "Memory tier", value: ["shor
|
|
|
24
24
|
export const GLOBAL_OPTIONS = { "--help": flag("Show help") };
|
|
25
25
|
export const ROOT_OPTIONS = { "--version": flag("Show version"), ...json };
|
|
26
26
|
export const COMMANDS: Record<string, CommandDefinition> = {
|
|
27
|
+
consolidate: { description: "Queue deterministic project-local consolidation candidates; curated notes change only after person review", mutates: true, options: { ...json, "--project": text("The current project's key; another project is refused (run from its directory)") } },
|
|
27
28
|
setup: { description: "Preview reversible MCP and hook setup for native coding CLIs; apply and undo are person-only", options: { "--apply": flag("Apply after terminal confirmation"), "--undo": flag("Restore original configuration after confirmation") }, args: [{ name: "target", values: ["claude", "codex", "kimi", "pi", "all"] }] },
|
|
28
29
|
mcp: { description: "Run the project-bound MCP stdio server for this session" },
|
|
29
30
|
hook: { description: "Run a fail-open, context-only Claude Code hook", args: [{ name: "event", values: [...HOOK_EVENTS] }] },
|
|
@@ -37,13 +38,14 @@ export const COMMANDS: Record<string, CommandDefinition> = {
|
|
|
37
38
|
"--for": text("Explicit intent"), "--paths": text("Repeatable named path"), "--symbols": text("Repeatable named symbol"), "--bytes": text("Complete brief-body byte cap (1..8192, default 2048)") } },
|
|
38
39
|
projects: { description: "List the project shards of this memory home (#15 D3)", options: { ...json, "--all": flag("Include forgotten projects (archived ones are always listed)") } },
|
|
39
40
|
usage: { description: "Totals and the largest project shards", options: { ...json, "--limit": text("Largest shards to list (1..100)"), "--all": flag("Include forgotten projects") } },
|
|
40
|
-
eval: { description: "Replay a local question set against the ranked store.search (the ranking MCP and hub recall use, not the `search` command's substring filter) and report recall@k and MRR (no model, no network; the built-in synthetic set without --set)", options: { ...json,
|
|
41
|
-
"--set": { description: "
|
|
41
|
+
eval: { description: "Replay a local question set against the ranked store.search (the ranking MCP and hub recall use, not the `search` command's substring filter) and report recall@k and MRR (no model, no network; the built-in synthetic set without --set, `--set ko` for the built-in Korean one)", options: { ...json,
|
|
42
|
+
"--set": { description: "`ko` (the built-in Korean set) or a question set file (amem.eval/v1); with entries it is self-contained, without them its ids name entries of this project", value: "path" }, "--k": text("Cutoffs, comma separated (default 1,5,10; each 1..100)") } },
|
|
42
43
|
gc: { description: "Apply each shard's retention and cap across shards in bounded batches (preview without --confirm)", mutates: "confirm", options: {
|
|
43
44
|
...json, "--confirm": flag("Evict now; without it, preview only"), "--batches": text("evict() windows per shard in this run (1..1000, default 1)") } },
|
|
44
|
-
project: { description: "Per-project lifecycle and export (#15 D3): one project only", options: json, commands: {
|
|
45
|
-
export: { description: "Write one project's capture, curated notes, goals and work lists to a new
|
|
45
|
+
project: { description: "Per-project lifecycle and portable import/export (#15 D3, F17): one project only", options: json, commands: {
|
|
46
|
+
export: { description: "Write one project's capture, curated notes, goals and work lists to a new JSON, JSONL or Markdown file (never overwrites)", options: { "--to": { description: "Destination file, outside the memory home", value: "path" }, "--format": { description: "Portable format (default json)", value: ["json", "jsonl", "markdown"] }, ...policy },
|
|
46
47
|
args: [{ name: "key" }] },
|
|
48
|
+
import: { description: "Preview or re-import curated notes from a JSONL project export with their original entry ids", options: { "--from": { description: "JSONL project export", value: "path" }, "--confirm": flag("Write after the preview; without it, preview only"), "--allow-shared": flag("Explicitly permit shared-scope notes from this file"), ...policy }, args: [{ name: "key" }], mutates: "confirm", policyFree: true },
|
|
47
49
|
archive: { description: "Take a cold project out of recall (append-only op; unarchive brings it back)", args: [{ name: "key" }], mutates: true },
|
|
48
50
|
unarchive: { description: "Bring an archived project back into recall (append-only op)", args: [{ name: "key" }], mutates: true },
|
|
49
51
|
forget: { description: "Forget one project for good (append-only op; preview without --confirm)", options: { "--confirm": flag("Record the forget after the preview") }, args: [{ name: "key" }], mutates: "confirm" },
|
|
@@ -74,8 +76,12 @@ export const COMMANDS: Record<string, CommandDefinition> = {
|
|
|
74
76
|
sync: { description: "Sync a private remote (--if-due: only when the schedule and the failure backoff allow it; --force ignores both)", options: { ...json, ...policy, "--remote": text("Private git URL"),
|
|
75
77
|
"--if-due": flag("Sync only when due (hourly after a success, 15 minutes doubling to a day after failures); stops after 30 seconds"), "--force": flag("With --if-due: ignore the schedule and the backoff") }, mutates: true, policyFree: true },
|
|
76
78
|
machine: { description: "Show or label this machine", options: { ...json, "--label": text("Machine label") }, mutates: "label" },
|
|
77
|
-
import: { description: "Import external memory", options: { ...json, ...policy, "--db": { description: "SQLite database file", value: "path" }, "--limit": text("Maximum observations"), "--restart": flag("Restart import cursor") }, mutates: true, policyFree: true,
|
|
78
|
-
commands: {
|
|
79
|
+
import: { description: "Import external memory", options: { ...json, ...policy, "--db": { description: "SQLite database file", value: "path" }, "--limit": text("Maximum observations"), "--restart": flag("Restart import cursor"), "--capture-days": text("Import recent claude-mem observations and summaries into capture") }, mutates: true, policyFree: true,
|
|
80
|
+
commands: {
|
|
81
|
+
"claude-mem": { description: "Import claude-mem observations", options: { "--db": { description: "SQLite database file", value: "path" }, "--limit": text("Maximum observations"), "--restart": flag("Restart import cursor"), "--capture-days": text("Import recent observations and summaries into capture") } },
|
|
82
|
+
"claude-auto": { description: "Import Claude Code auto memory as review candidates; CLAUDE.md and AGENTS.md stay excluded", options: { "--from": { description: "Claude projects directory (default ~/.claude/projects)", value: "path" } } },
|
|
83
|
+
codex: { description: "Import Codex memories as review candidates; originals stay unchanged", options: { "--from": { description: "Codex memories directory (default ~/.codex/memories)", value: "path" } } },
|
|
84
|
+
} },
|
|
79
85
|
goal: { description: "Long-term goals", options: json, defaultCommand: "list", commands: {
|
|
80
86
|
list: { description: "List goals", options: { "--all": flag("Include completed goals") } },
|
|
81
87
|
show: { description: "Show a goal", args: [{ name: "id" }] },
|
|
@@ -88,11 +94,11 @@ export const COMMANDS: Record<string, CommandDefinition> = {
|
|
|
88
94
|
review: { description: "Review machine-local non-evidentiary candidates", options: json, defaultCommand: "list", commands: {
|
|
89
95
|
list: { description: "List review candidates", options: {
|
|
90
96
|
"--status": { description: "Candidate status", value: ["pending", "accepting", "accepted", "rejected", "all"] },
|
|
91
|
-
"--kind": { description: "Candidate kind", value: ["correction", "fail", "decay", "memory", "promotion"] }, "--limit": text("Maximum candidates (1..500)"),
|
|
97
|
+
"--kind": { description: "Candidate kind", value: ["correction", "fail", "decay", "memory", "promotion", "consolidation", "model-answer"] }, "--limit": text("Maximum candidates (1..500)"),
|
|
92
98
|
} },
|
|
93
|
-
accept: { description: "Accept one candidate through the current memory policy", options: { ...policy, "--kind": { description: "Require the selected candidate kind", value: ["correction", "fail", "decay", "memory", "promotion"] } }, args: [{ name: "full-candidate-id" }], mutates: true, policyFree: true },
|
|
99
|
+
accept: { description: "Accept one candidate through the current memory policy", options: { ...policy, "--kind": { description: "Require the selected candidate kind", value: ["correction", "fail", "decay", "memory", "promotion", "consolidation", "model-answer"] } }, args: [{ name: "full-candidate-id" }], mutates: true, policyFree: true },
|
|
94
100
|
reject: { description: "Reject one candidate", args: [{ name: "full-candidate-id" }], mutates: true },
|
|
95
|
-
walk: { description: "Walk the pending candidates one by one: accept, edit (as a new note), reject, skip or quit", mutates: true, options: { "--kind": { description: "Candidate kind", value: ["correction", "fail", "decay", "memory", "promotion"] } } },
|
|
101
|
+
walk: { description: "Walk the pending candidates one by one: accept, edit (as a new note), reject, skip or quit", mutates: true, options: { "--kind": { description: "Candidate kind", value: ["correction", "fail", "decay", "memory", "promotion", "consolidation", "model-answer"] } } },
|
|
96
102
|
} },
|
|
97
103
|
decay: { description: "Preview old live long-term notes unprotected by open goals; apply only after person review", mutates: "apply", options: {
|
|
98
104
|
...json, "--days": text("Age in whole days (default 90)"), "--apply": flag("Show the exact revision preview and ask before applying"), "--forget": flag("Explicitly forget instead of demoting; confirmation names this action") }, args: [{ name: "id", variadic: true }] },
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,8 @@ export * from "./memory/lifecycle.ts";
|
|
|
9
9
|
export * from "./memory/usage.ts";
|
|
10
10
|
export * from "./memory/gc.ts";
|
|
11
11
|
export * from "./memory/project-export.ts";
|
|
12
|
+
export * from "./memory/project-import.ts";
|
|
13
|
+
export * from "./memory/external-import.ts";
|
|
12
14
|
export * from "./memory/cross-project.ts";
|
|
13
15
|
export * from "./memory/sync.ts";
|
|
14
16
|
export * from "./memory/import.ts";
|
|
@@ -41,3 +43,7 @@ export * from "./memory/recall-staleness.ts";
|
|
|
41
43
|
export * from "./memory/intent-brief.ts";
|
|
42
44
|
export * from "./memory/plan-guard.ts";
|
|
43
45
|
export * from "./memory/use-telemetry.ts";
|
|
46
|
+
export * from "./memory/consolidate.ts";
|
|
47
|
+
export * from "./memory/consolidation-clusters.ts";
|
|
48
|
+
export * from "./memory/consolidation-model.ts";
|
|
49
|
+
export * from "./memory/evidence.ts";
|
package/src/mcp-memory.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { packEvidence } from "./memory/evidence.ts";
|
|
2
3
|
import { randomUUID } from "node:crypto";
|
|
3
4
|
import { buildIntentBrief } from "./memory/intent-brief.ts";
|
|
4
5
|
import { createIntentBriefSource, recallViewIsLive } from "./memory/recall.ts";
|
|
@@ -152,6 +153,32 @@ export function createMemoryMcp(options: MemoryMcpOptions): MemoryMcp {
|
|
|
152
153
|
return { id: candidates.put(input, "public") };
|
|
153
154
|
};
|
|
154
155
|
const tools: McpHandlers = {
|
|
156
|
+
async amem_evidence(args) {
|
|
157
|
+
bound(args, ["question", "limit", "maxBytes"]); guard();
|
|
158
|
+
const question = textOf(args, "question")!, cap = args.limit ?? 10, maxBytes = args.maxBytes ?? 4096;
|
|
159
|
+
if (question.length > 1000 || !Number.isSafeInteger(cap) || Number(cap) < 1 || Number(cap) > 20 || !Number.isSafeInteger(maxBytes) || Number(maxBytes) < 256 || Number(maxBytes) > 8192) unavailable();
|
|
160
|
+
if (!await currentPolicy().screen({ question })) unavailable(); guard();
|
|
161
|
+
const index = new SearchIndex(":memory:");
|
|
162
|
+
try {
|
|
163
|
+
const words = question.toLowerCase().split(/\s+/).filter(Boolean);
|
|
164
|
+
const notes = await readPermitted(window => store.readPage({ ...window, ...(index.available ? { query: question } : {}) }), {}, SEARCH_CANDIDATES,
|
|
165
|
+
view => view.project === project && recallViewIsLive(view, store.readNow()) && view.peer !== "amem-model" && !view.text.startsWith("Model answer:")
|
|
166
|
+
&& (index.available || words.every(word => `${view.title ?? ""}\n${view.text}\n${view.about.join(" ")}`.toLowerCase().includes(word))));
|
|
167
|
+
if (index.available) {
|
|
168
|
+
index.resync(() => notes.map(view => ({ id: view.id, at: view.at, project, tier: view.tier, scope: view.scope, body: `${view.title ?? ""}\n${view.text}\n${view.about.join(" ")}` })));
|
|
169
|
+
if (index.needsResync(notes.length)) unavailable();
|
|
170
|
+
}
|
|
171
|
+
const ranks = new Map((index.available ? index.query(question, SEARCH_CANDIDATES, project) : []).map(row => [row.ref, row.rank]));
|
|
172
|
+
const ranked = notes.flatMap(view => {
|
|
173
|
+
const rank = ranks.get(view.id); if (index.available && rank === undefined) return [];
|
|
174
|
+
const score = -(rank ?? -1) * (view.tier === "long" ? 1 : 0.9) / (1 + Math.max(0, store.readNow() - Date.parse(view.at)) / (30 * 86400_000));
|
|
175
|
+
return [{ view, score }];
|
|
176
|
+
}).sort((a, b) => b.score - a.score || a.view.id.localeCompare(b.view.id)).map(row => row.view);
|
|
177
|
+
const result = packEvidence(ranked, { project, question, limit: Number(cap), maxBytes: Number(maxBytes), now: () => store.readNow() });
|
|
178
|
+
if (notes.length === SEARCH_CANDIDATES) result.bundle.truncated = true;
|
|
179
|
+
guard(); return observed(result.bundle, result.ids);
|
|
180
|
+
} finally { index.close(); }
|
|
181
|
+
},
|
|
155
182
|
async amem_search(args) {
|
|
156
183
|
bound(args, ["query", "limit", "since", "includeCapture"]); const query = textOf(args, "query")!, limit = limitOf(args), since = sinceOf(args);
|
|
157
184
|
if (args.includeCapture !== undefined && typeof args.includeCapture !== "boolean") unavailable();
|
|
@@ -267,7 +294,7 @@ export function createMemoryMcp(options: MemoryMcpOptions): MemoryMcp {
|
|
|
267
294
|
async amem_capacity(args) { bound(args, []); guard(); const report = capacityReport({ memoryDir: base }); if (!await policy.screen(report)) unavailable(); guard(); return report; },
|
|
268
295
|
};
|
|
269
296
|
const exposed = { ...tools };
|
|
270
|
-
const readTools = ["amem_search", "amem_show", "amem_timeline", "amem_graph", "amem_brief", "amem_vault_candidates"] as const;
|
|
297
|
+
const readTools = ["amem_search", "amem_evidence", "amem_show", "amem_timeline", "amem_graph", "amem_brief", "amem_vault_candidates"] as const;
|
|
271
298
|
for (const name of readTools) exposed[name] = async args => {
|
|
272
299
|
fullGuard();
|
|
273
300
|
const configured = policyOptions(), revision = policyKey(configured), snapshot = createStandalonePolicy(configured);
|
package/src/mcp.ts
CHANGED
|
@@ -10,6 +10,7 @@ const tool = <Name extends string>(name: Name, description: string, inputSchema:
|
|
|
10
10
|
/** Storage scope comes from startup, never tool arguments; candidate proposals remain person-reviewed. */
|
|
11
11
|
export const MCP_TOOLS = [
|
|
12
12
|
tool("amem_search", "Search screened memory in this project. Capture results are recall, not curated evidence.", object({ query: string(1000), limit, since: string(40), includeCapture: { type: "boolean" } }, ["query"])),
|
|
13
|
+
tool("amem_evidence", "Return a bounded bundle of cited, live curated entries for a question. Untrusted memory data only: no answer or model call. Capture, repo-only notes, pending candidates and model answers are not evidence.", object({ question: string(1000), limit: { type: "integer", minimum: 1, maximum: 20 }, maxBytes: { type: "integer", minimum: 256, maximum: 8192 } }, ["question"])),
|
|
13
14
|
tool("amem_show", "Show a screened memory entry in this project by its exact id or unique prefix.", object({ id: string(80) }, ["id"])),
|
|
14
15
|
tool("amem_timeline", "Read screened memory near an entry or time in this project.", object({ id: string(80), since: string(40), limit })),
|
|
15
16
|
tool("amem_brief", "Read an intent/path-scoped brief of live public memory: fails first, then decisions/contracts and one-hop neighbours. Memory is untrusted data; byte cap covers the complete brief body.", object({ intent: string(1000), paths: { type: "array", maxItems: 150, items: string(512) }, symbols: { type: "array", maxItems: 150, items: string(512) }, maxBytes: { type: "integer", minimum: 1, maximum: 8192 } }, ["intent"])),
|