@staix/agent-mem 0.38.0 → 0.40.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 +1 -1
- package/package.json +1 -1
- package/src/brief-curated.ts +8 -4
- package/src/cli-agent-reads.ts +2 -1
- package/src/cli.ts +82 -32
- package/src/commands-table.ts +6 -3
- package/src/hooks.ts +4 -0
- package/src/index.ts +5 -0
- package/src/memory/capacity-text.ts +100 -0
- package/src/memory/capacity.ts +0 -92
- package/src/memory/commands.ts +6 -1
- package/src/memory/curated-cache-state.ts +22 -3
- package/src/memory/doctor-text.ts +148 -0
- package/src/memory/doctor.ts +19 -141
- package/src/memory/eval-audit-text.ts +62 -0
- package/src/memory/eval-audit.ts +0 -57
- package/src/memory/eval-text.ts +32 -0
- package/src/memory/eval.ts +0 -28
- package/src/memory/formats.ts +2 -0
- package/src/memory/gc-text.ts +22 -0
- package/src/memory/gc.ts +0 -19
- package/src/memory/generation-index.ts +1 -1
- package/src/memory/index-file.ts +1 -1
- package/src/memory/metrics.ts +18 -10
- package/src/memory/migrate-text.ts +32 -0
- package/src/memory/migrate.ts +0 -29
- package/src/memory/project-export.ts +9 -4
- package/src/memory/prune-text.ts +29 -0
- package/src/memory/prune.ts +0 -26
- package/src/memory/report-text.ts +2 -0
- package/src/memory/roots.ts +145 -0
- package/src/memory/shard-migration-text.ts +40 -0
- package/src/memory/shard-migration.ts +0 -37
- package/src/memory/status-text.ts +5 -1
- package/src/memory/store.ts +112 -17
- package/src/memory/sync-placement-activation-locks.ts +7 -5
- package/src/memory/sync-placement-advertisement.ts +18 -0
- package/src/memory/sync-placement-bound.ts +2 -2
- package/src/memory/sync-placement-checkpoint-person.ts +2 -2
- package/src/memory/sync-placement-inventory.ts +4 -1
- package/src/memory/sync-placement-noop-cache.ts +93 -0
- package/src/memory/sync-placement-refusal-category.ts +18 -0
- package/src/memory/sync-placement-transport.ts +80 -13
- package/src/memory/sync-placement-writer-renewal.ts +3 -1
- package/src/memory/sync-progress-text.ts +7 -0
- package/src/memory/sync-progress.ts +21 -7
- package/src/memory/sync-screen.ts +13 -0
- package/src/memory/work-lists.ts +6 -4
- package/src/session-brief.ts +16 -2
- package/src/setup-drift.ts +1 -1
- package/src/setup-writer-roots.ts +136 -0
- package/src/setup.ts +8 -118
- package/src/sync-placement-writer-context.ts +9 -4
- package/src/ui/inbox.ts +1 -1
- package/src/ui/plugin.ts +4 -2
- package/src/work-brief-preparation.ts +28 -0
package/src/memory/eval-audit.ts
CHANGED
|
@@ -15,10 +15,7 @@ import {
|
|
|
15
15
|
} from "./eval.ts";
|
|
16
16
|
import { memoryGitEnv, memoryGitSync, realPath } from "./platform.ts";
|
|
17
17
|
import type { MemoryStore, View } from "./store.ts";
|
|
18
|
-
import { Report } from "@staix/cli-output";
|
|
19
|
-
import { PLAIN, relativeTime, singleLine, type Style } from "./style.ts";
|
|
20
18
|
|
|
21
|
-
interface AuditRender { columns?: number; style?: Style; now?: number }
|
|
22
19
|
|
|
23
20
|
export interface AuditAnchor { path: string; status: Exclude<AuditAnchorStatus, "none"> }
|
|
24
21
|
export interface AuditNote {
|
|
@@ -409,58 +406,4 @@ export function auditScore(sheet: AuditSheet): AuditScore {
|
|
|
409
406
|
return score;
|
|
410
407
|
}
|
|
411
408
|
|
|
412
|
-
/** Human text for `amem eval audit sample`: where the sheet is, and what filling it costs. Content-free, like the score. */
|
|
413
|
-
export function auditSheetText(sheet: AuditSheet, file: string, render?: AuditRender): string {
|
|
414
|
-
const cells = new Set(sheet.notes.map(note => `${note.kind}/${note.age}`));
|
|
415
|
-
const frame = `${sheet.frame}${sheet.truncated ? "+ (the store listing hit its cap, so the frame is a floor)" : ""}`;
|
|
416
|
-
if (render) {
|
|
417
|
-
const s = render.style ?? PLAIN, out = new Report(render.columns ?? 80, s.ascii, { sanitize: singleLine, keepTokensWhole: true });
|
|
418
|
-
out.header("amem", "Audit sample"); out.section("Sheet");
|
|
419
|
-
out.kv([["Project", sheet.project], ["Drawn", `${sheet.drawn} of ${frame}`], ["Seed", sheet.seed], ["Measured", relativeTime(sheet.asOf, render.now ?? Date.now())], ["Groups", String(cells.size)], ["Root", sheet.root], ["File", file], ["Withheld", String(sheet.withheld)]]);
|
|
420
|
-
out.note("The sheet is mode 0600, local only; never synced or committed.");
|
|
421
|
-
out.note(`Fill both judge columns using ${AUDIT_LABELS.join(", ")}; the rubric is in the sheet.`);
|
|
422
|
-
if (/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u.test(file)) out.bullet("warn", "The sheet path contains control characters; inspect --json and pass the exact path to the score command.");
|
|
423
|
-
else out.next(`amem eval audit score '${file.replaceAll("'", "'\\''")}'`);
|
|
424
|
-
return out.render(s.color).join("\n");
|
|
425
|
-
}
|
|
426
|
-
return [
|
|
427
|
-
`audit sample: ${sheet.drawn} of ${frame} ${sheet.project} notes, seed "${sheet.seed}" as of ${sheet.asOf}, ${cells.size} kind/age cells, anchors checked in ${sheet.root}${sheet.withheld ? `, ${sheet.withheld} withheld by the configured policy` : ""}`,
|
|
428
|
-
`sheet: ${file} (0600, local only; never synced and never committed)`,
|
|
429
|
-
`fill judge_a and judge_b with ${AUDIT_LABELS.join(", ")} (rubric in the sheet header), then run \`amem eval audit score ${file}\``,
|
|
430
|
-
].join("\n");
|
|
431
|
-
}
|
|
432
409
|
|
|
433
|
-
/** Human text for `amem eval audit score`; the JSON is the machine form. */
|
|
434
|
-
export function auditScoreText(score: AuditScore, render?: AuditRender): string {
|
|
435
|
-
const row = (label: string, counts: Partial<Record<AuditLabel, number>>) => `${label.padEnd(10)} ${AUDIT_LABELS.map(name => String(counts[name] ?? 0).padStart(4)).join(" ")}`;
|
|
436
|
-
const frame = `${score.frame}${score.truncated ? "+ (the store listing hit its cap, so the frame is a floor)" : ""}`;
|
|
437
|
-
const withheld = score.withheld ? `, ${score.withheld} withheld by the configured policy` : "";
|
|
438
|
-
const head = `audit score: project ${score.project}, ${score.drawn} of ${frame} notes, seed "${score.seed}" as of ${score.asOf}, ${score.labelled} labelled, ${score.unlabelled} not${withheld}`;
|
|
439
|
-
// The joint cells are printed as one line per kind/age/anchor stratum, so a reader sees which label fills each intersection instead of three marginals.
|
|
440
|
-
const strata = new Map<string, Partial<Record<AuditLabel, number>>>();
|
|
441
|
-
for (const cell of score.cells) {
|
|
442
|
-
const key = `${cell.kind}/${cell.age}/${cell.anchor}`, counts = strata.get(key) ?? {};
|
|
443
|
-
counts[cell.label] = cell.count;
|
|
444
|
-
strata.set(key, counts);
|
|
445
|
-
}
|
|
446
|
-
if (render) {
|
|
447
|
-
const s = render.style ?? PLAIN, out = new Report(render.columns ?? 80, s.ascii, { sanitize: singleLine });
|
|
448
|
-
out.header("amem", "Audit score"); out.section("Summary");
|
|
449
|
-
out.kv([["Project", score.project], ["Drawn", `${score.drawn} of ${frame}`], ["Seed", score.seed], ["Measured", relativeTime(score.asOf, render.now ?? Date.now())], ["Labelled", String(score.labelled)], ["Unlabelled", String(score.unlabelled)], ["Withheld", String(score.withheld)], ["Kappa", score.agreement.kappa === null ? "? (needs both judges and more than one label)" : score.agreement.kappa.toFixed(3)], ["Judge pairs", String(score.agreement.pairs)]]);
|
|
450
|
-
out.section("Labels");
|
|
451
|
-
const rows: [string, Partial<Record<AuditLabel, number>>][] = [["all", score.byLabel], ...Object.entries(score.byKind).map(([kind, counts]): [string, Partial<Record<AuditLabel, number>>] => [`kind ${kind}`, counts]), ...Object.entries(score.byAge).map(([age, counts]): [string, Partial<Record<AuditLabel, number>>] => [`age ${age}`, counts]), ...Object.entries(score.byAnchor).map(([anchor, counts]): [string, Partial<Record<AuditLabel, number>>] => [`anchor ${anchor}`, counts]), ...[...strata.entries()].map(([key, counts]): [string, Partial<Record<AuditLabel, number>>] => [`cross ${key}`, counts])];
|
|
452
|
-
out.table(["GROUP", ...AUDIT_LABELS], rows.map(([name, counts]) => [name, ...AUDIT_LABELS.map(label => String(counts[label] ?? 0))]), 0);
|
|
453
|
-
out.line(""); out.line(`Summary: ${score.labelled} labelled, ${score.unlabelled} unlabelled`);
|
|
454
|
-
return out.render(s.color).join("\n");
|
|
455
|
-
}
|
|
456
|
-
return [
|
|
457
|
-
head,
|
|
458
|
-
`${"".padEnd(10)} ${AUDIT_LABELS.map(name => name.slice(0, 4).padStart(4)).join(" ")}`,
|
|
459
|
-
row("all", score.byLabel),
|
|
460
|
-
...Object.entries(score.byKind).map(([kind, counts]) => row(`kind ${kind}`, counts)),
|
|
461
|
-
...Object.entries(score.byAge).map(([age, counts]) => row(`age ${age}`, counts)),
|
|
462
|
-
...Object.entries(score.byAnchor).map(([anchor, counts]) => row(`anchor ${anchor}`, counts)),
|
|
463
|
-
...strata.entries().map(([key, counts]) => row(`cross ${key}`, counts)),
|
|
464
|
-
`kappa ${score.agreement.kappa === null ? "n/a (needs both judge columns, and more than one label between them)" : score.agreement.kappa.toFixed(3)} over ${score.agreement.pairs} doubly labelled note(s)`,
|
|
465
|
-
].join("\n");
|
|
466
|
-
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Report } from "@staix/cli-output";
|
|
2
|
+
import { PLAIN, singleLine, type Style } from "./style.ts";
|
|
3
|
+
import type { EvalAggregate, EvalReport } from "./eval.ts";
|
|
4
|
+
const pct = (value: number | null): string => value === null ? " n/a" : value.toFixed(3);
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/** #592: the human eval output, kept out of eval.ts so the write path never imports the output package. */
|
|
8
|
+
/** Human text for `amem eval`; the JSON report is the machine form. */
|
|
9
|
+
export function evalText(report: EvalReport, label: string, render?: { columns?: number; style?: Style }): string {
|
|
10
|
+
if (render) {
|
|
11
|
+
const s = render.style ?? PLAIN, out = new Report(render.columns ?? 80, s.ascii, { sanitize: singleLine });
|
|
12
|
+
out.header("amem", "Evaluation"); out.section("Results");
|
|
13
|
+
out.kv([["Set", label], ["Engine", report.engine], ["Questions", String(report.all.questions)], ["Answerable", String(report.answerable.questions)], ["All MRR", report.all.mrr === null ? "?" : report.all.mrr.toFixed(3)], ["Answerable MRR", report.answerable.mrr === null ? "?" : report.answerable.mrr.toFixed(3)]]);
|
|
14
|
+
if (report.answerable.questions < report.all.questions) out.note(`${report.all.questions - report.answerable.questions} questions name entries this store does not hold; they score zero in all.`);
|
|
15
|
+
out.section("Cutoffs", String(report.ks.length));
|
|
16
|
+
const number = (value: number | null | undefined) => value == null ? "?" : value.toFixed(3);
|
|
17
|
+
out.table(["K", "ALL RECALL", "ALL HIT", "ANSWERABLE RECALL", "ANSWERABLE HIT"], report.ks.map(k => [String(k), number(report.all.recall[k]), number(report.all.hit[k]), number(report.answerable.recall[k]), number(report.answerable.hit[k])]), 0);
|
|
18
|
+
const missed = report.perQuestion.filter(row => row.rank === null || row.rank > Math.min(...report.ks));
|
|
19
|
+
if (missed.length) { out.section("Questions to review", String(missed.length)); out.table(["RESULT", "QUESTION"], missed.map(row => [row.rank === null ? "miss" : `rank ${row.rank}`, `${row.answerable ? "" : "not in store: "}${row.q}`]), 1); }
|
|
20
|
+
out.line(""); out.line(`Summary: ${report.all.questions} questions, ${report.answerable.questions} answerable`);
|
|
21
|
+
return out.render(s.color).join("\n");
|
|
22
|
+
}
|
|
23
|
+
const head = (name: string, row: EvalAggregate) => `${name.padEnd(11)} ${String(row.questions).padStart(4)} ${report.ks.map(k => `${pct(row.recall[k] ?? null)}/${pct(row.hit[k] ?? null)}`.padStart(13)).join(" ")} ${pct(row.mrr).padStart(6)}`;
|
|
24
|
+
return [
|
|
25
|
+
`eval: ${label} (${report.engine === "substring" ? "substring fallback" : "ranked store.search, engine " + report.engine}; same ranked search path as default \`amem search\`; \`--filter\` keeps legacy substring matching)`,
|
|
26
|
+
`${"".padEnd(11)} ${"n".padStart(4)} ${report.ks.map(k => `@${k} recall/hit`.padStart(13)).join(" ")} ${"MRR".padStart(6)}`,
|
|
27
|
+
head("all", report.all),
|
|
28
|
+
head("answerable", report.answerable),
|
|
29
|
+
...(report.answerable.questions < report.all.questions ? [`${report.all.questions - report.answerable.questions} question(s) name an entry this store does not hold (they score 0 in "all")`] : []),
|
|
30
|
+
...report.perQuestion.filter(row => row.rank === null || row.rank > Math.min(...report.ks)).map(row => ` ${row.rank === null ? "miss" : `rank ${row.rank}`}${row.answerable ? "" : " (not in store)"}: ${row.q.slice(0, 100)}`),
|
|
31
|
+
].join("\n");
|
|
32
|
+
}
|
package/src/memory/eval.ts
CHANGED
|
@@ -7,8 +7,6 @@
|
|
|
7
7
|
* - self-contained: `entries` are synthetic notes seeded into a throwaway store, and `expect` names them by `key` (the committed fixture is one);
|
|
8
8
|
* - the person's own: no `entries`, `expect` holds real entry ids (or `mem:<id>`, or a prefix of 8 or more hex characters) and the bound project's store is searched.
|
|
9
9
|
*/
|
|
10
|
-
import { Report } from "@staix/cli-output";
|
|
11
|
-
import { PLAIN, singleLine, type Style } from "./style.ts";
|
|
12
10
|
export const EVAL_SCHEMA = "amem.eval/v1";
|
|
13
11
|
export const MAX_QUESTIONS = 500, MAX_ENTRIES = 200, MAX_QUESTION_CHARS = 500, MAX_EXPECT = 20, MAX_ENTRY_CHARS = 4000, MAX_SET_BYTES = 1024 * 1024, MAX_K = 100;
|
|
14
12
|
export const DEFAULT_KS: readonly number[] = [1, 5, 10];
|
|
@@ -214,29 +212,3 @@ export function runEval(rank: (question: string) => readonly string[], resolve:
|
|
|
214
212
|
return { engine, ks: [...ks], all: aggregate(perQuestion, ks, true), answerable: aggregate(perQuestion.filter(row => row.answerable), ks, false), perQuestion };
|
|
215
213
|
}
|
|
216
214
|
|
|
217
|
-
const pct = (value: number | null): string => value === null ? " n/a" : value.toFixed(3);
|
|
218
|
-
/** Human text for `amem eval`; the JSON report is the machine form. */
|
|
219
|
-
export function evalText(report: EvalReport, label: string, render?: { columns?: number; style?: Style }): string {
|
|
220
|
-
if (render) {
|
|
221
|
-
const s = render.style ?? PLAIN, out = new Report(render.columns ?? 80, s.ascii, { sanitize: singleLine });
|
|
222
|
-
out.header("amem", "Evaluation"); out.section("Results");
|
|
223
|
-
out.kv([["Set", label], ["Engine", report.engine], ["Questions", String(report.all.questions)], ["Answerable", String(report.answerable.questions)], ["All MRR", report.all.mrr === null ? "?" : report.all.mrr.toFixed(3)], ["Answerable MRR", report.answerable.mrr === null ? "?" : report.answerable.mrr.toFixed(3)]]);
|
|
224
|
-
if (report.answerable.questions < report.all.questions) out.note(`${report.all.questions - report.answerable.questions} questions name entries this store does not hold; they score zero in all.`);
|
|
225
|
-
out.section("Cutoffs", String(report.ks.length));
|
|
226
|
-
const number = (value: number | null | undefined) => value == null ? "?" : value.toFixed(3);
|
|
227
|
-
out.table(["K", "ALL RECALL", "ALL HIT", "ANSWERABLE RECALL", "ANSWERABLE HIT"], report.ks.map(k => [String(k), number(report.all.recall[k]), number(report.all.hit[k]), number(report.answerable.recall[k]), number(report.answerable.hit[k])]), 0);
|
|
228
|
-
const missed = report.perQuestion.filter(row => row.rank === null || row.rank > Math.min(...report.ks));
|
|
229
|
-
if (missed.length) { out.section("Questions to review", String(missed.length)); out.table(["RESULT", "QUESTION"], missed.map(row => [row.rank === null ? "miss" : `rank ${row.rank}`, `${row.answerable ? "" : "not in store: "}${row.q}`]), 1); }
|
|
230
|
-
out.line(""); out.line(`Summary: ${report.all.questions} questions, ${report.answerable.questions} answerable`);
|
|
231
|
-
return out.render(s.color).join("\n");
|
|
232
|
-
}
|
|
233
|
-
const head = (name: string, row: EvalAggregate) => `${name.padEnd(11)} ${String(row.questions).padStart(4)} ${report.ks.map(k => `${pct(row.recall[k] ?? null)}/${pct(row.hit[k] ?? null)}`.padStart(13)).join(" ")} ${pct(row.mrr).padStart(6)}`;
|
|
234
|
-
return [
|
|
235
|
-
`eval: ${label} (${report.engine === "substring" ? "substring fallback" : "ranked store.search, engine " + report.engine}; same ranked search path as default \`amem search\`; \`--filter\` keeps legacy substring matching)`,
|
|
236
|
-
`${"".padEnd(11)} ${"n".padStart(4)} ${report.ks.map(k => `@${k} recall/hit`.padStart(13)).join(" ")} ${"MRR".padStart(6)}`,
|
|
237
|
-
head("all", report.all),
|
|
238
|
-
head("answerable", report.answerable),
|
|
239
|
-
...(report.answerable.questions < report.all.questions ? [`${report.all.questions - report.answerable.questions} question(s) name an entry this store does not hold (they score 0 in "all")`] : []),
|
|
240
|
-
...report.perQuestion.filter(row => row.rank === null || row.rank > Math.min(...report.ks)).map(row => ` ${row.rank === null ? "miss" : `rank ${row.rank}`}${row.answerable ? "" : " (not in store)"}: ${row.q.slice(0, 100)}`),
|
|
241
|
-
].join("\n");
|
|
242
|
-
}
|
package/src/memory/formats.ts
CHANGED
|
@@ -31,6 +31,8 @@ const READER_VERSION: string | undefined = (() => {
|
|
|
31
31
|
try { const { version } = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8")) as { version?: unknown }; return typeof version === "string" && SEMVER.test(version) ? version : undefined; }
|
|
32
32
|
catch { return undefined; }
|
|
33
33
|
})();
|
|
34
|
+
/** This release's plain version as read at load, or undefined when unreadable. */
|
|
35
|
+
export function amemReaderVersion(): string | undefined { return READER_VERSION; }
|
|
34
36
|
const parts = (version: string) => SEMVER.exec(version)!.slice(1, 4).map(Number);
|
|
35
37
|
/** Compare versions accepted by format-floor records, using their numeric release components. */
|
|
36
38
|
export function formatVersionBelow(reader: string, floor: string): boolean {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Report } from "@staix/cli-output";
|
|
2
|
+
import { PLAIN, singleLine, type Style } from "./style.ts";
|
|
3
|
+
import type { GcResult } from "./gc.ts";
|
|
4
|
+
|
|
5
|
+
/** #592: the human gc output, kept out of gc.ts so the write path never imports the output package. */
|
|
6
|
+
/** The non-JSON rendering of `amem gc`. */
|
|
7
|
+
export function gcText(result: GcResult, render?: { columns?: number; style?: Style; next?: string }): string {
|
|
8
|
+
if (render) {
|
|
9
|
+
const s = render.style ?? PLAIN, out = new Report(render.columns ?? 80, s.ascii, { sanitize: singleLine, keepTokensWhole: true });
|
|
10
|
+
out.header("amem", "Capture cleanup"); out.section(result.dryRun ? "Preview" : "Results");
|
|
11
|
+
out.bullet(result.dryRun ? "pending" : "ok", result.dryRun ? "Review the cleanup before confirming." : "Cleanup completed.");
|
|
12
|
+
if (result.shards.length) out.table(["PROJECT", "EXPIRED", "TRIMMED", "STATE"], result.shards.map(row => [row.key, String(row.expired), String(row.trimmed), row.remainingOverCap ? "over cap" : "within cap"]), 0);
|
|
13
|
+
else out.note("No project shards.");
|
|
14
|
+
for (const row of result.skipped) out.bullet("absent", `${row.key}: skipped (${row.reason})`);
|
|
15
|
+
if (render.next && (result.dryRun ? result.shards.some(row => row.expired > 0 || row.remainingOverCap) : result.shards.some(row => row.remainingOverCap))) out.next(render.next);
|
|
16
|
+
out.line(""); out.line(`Summary: ${result.shards.length} shards, ${result.skipped.length} skipped`);
|
|
17
|
+
return out.render(s.color).join("\n");
|
|
18
|
+
}
|
|
19
|
+
const lines = result.shards.map(s => `${s.key}: ${result.dryRun ? `${s.expired} expired row(s) would go` : `${s.expired} expired, ${s.trimmed} trimmed`}${s.remainingOverCap ? "; still over its cap, run gc again" : ""}`);
|
|
20
|
+
for (const s of result.skipped) lines.push(`${s.key}: skipped (${s.reason})`);
|
|
21
|
+
return (lines.length ? lines : ["no project shards"]).join("\n");
|
|
22
|
+
}
|
package/src/memory/gc.ts
CHANGED
|
@@ -4,8 +4,6 @@ import { join } from "node:path";
|
|
|
4
4
|
import { CAPTURE_EVICT_MAX_BATCHES, CaptureStore, captureShardStats, readCaptureConfig } from "./capture.ts";
|
|
5
5
|
import { walkShards } from "./catalog.ts";
|
|
6
6
|
import { lifecycleResolver } from "./lifecycle.ts";
|
|
7
|
-
import { Report } from "@staix/cli-output";
|
|
8
|
-
import { PLAIN, singleLine, type Style } from "./style.ts";
|
|
9
7
|
|
|
10
8
|
/**
|
|
11
9
|
* #15 T5 / D3: `amem gc`. Applies each shard's own R6 bounds (its retention window and size cap, the shard config over the home default) across every
|
|
@@ -108,20 +106,3 @@ export function runGc(base: string, opts: GcOptions = {}): GcResult {
|
|
|
108
106
|
|
|
109
107
|
export const GC_MAX_BATCHES_PER_CALL = CAPTURE_EVICT_MAX_BATCHES;
|
|
110
108
|
|
|
111
|
-
/** The non-JSON rendering of `amem gc`. */
|
|
112
|
-
export function gcText(result: GcResult, render?: { columns?: number; style?: Style; next?: string }): string {
|
|
113
|
-
if (render) {
|
|
114
|
-
const s = render.style ?? PLAIN, out = new Report(render.columns ?? 80, s.ascii, { sanitize: singleLine, keepTokensWhole: true });
|
|
115
|
-
out.header("amem", "Capture cleanup"); out.section(result.dryRun ? "Preview" : "Results");
|
|
116
|
-
out.bullet(result.dryRun ? "pending" : "ok", result.dryRun ? "Review the cleanup before confirming." : "Cleanup completed.");
|
|
117
|
-
if (result.shards.length) out.table(["PROJECT", "EXPIRED", "TRIMMED", "STATE"], result.shards.map(row => [row.key, String(row.expired), String(row.trimmed), row.remainingOverCap ? "over cap" : "within cap"]), 0);
|
|
118
|
-
else out.note("No project shards.");
|
|
119
|
-
for (const row of result.skipped) out.bullet("absent", `${row.key}: skipped (${row.reason})`);
|
|
120
|
-
if (render.next && (result.dryRun ? result.shards.some(row => row.expired > 0 || row.remainingOverCap) : result.shards.some(row => row.remainingOverCap))) out.next(render.next);
|
|
121
|
-
out.line(""); out.line(`Summary: ${result.shards.length} shards, ${result.skipped.length} skipped`);
|
|
122
|
-
return out.render(s.color).join("\n");
|
|
123
|
-
}
|
|
124
|
-
const lines = result.shards.map(s => `${s.key}: ${result.dryRun ? `${s.expired} expired row(s) would go` : `${s.expired} expired, ${s.trimmed} trimmed`}${s.remainingOverCap ? "; still over its cap, run gc again" : ""}`);
|
|
125
|
-
for (const s of result.skipped) lines.push(`${s.key}: skipped (${s.reason})`);
|
|
126
|
-
return (lines.length ? lines : ["no project shards"]).join("\n");
|
|
127
|
-
}
|
|
@@ -351,7 +351,7 @@ export class GenerationIndex {
|
|
|
351
351
|
finally { this.fullCapture = false; }
|
|
352
352
|
const committed = this.options.db.transaction(() => {
|
|
353
353
|
if (this.frontier() !== before) return false;
|
|
354
|
-
for (const table of ["entries", "ops", "edges", "goals", "segments", "heads", ...GENERATION_TABLES, ...(this.profile.foreignPruneFormat ? FOREIGN_TABLES : [])]) this.options.db.run(`DELETE FROM ${table}`);
|
|
354
|
+
for (const table of ["entries", "ops", "edges", "goals", "segments", "heads", "unsettled_tasks", ...GENERATION_TABLES, ...(this.profile.foreignPruneFormat ? FOREIGN_TABLES : [])]) this.options.db.run(`DELETE FROM ${table}`);
|
|
355
355
|
// The stamp described the tables just deleted, so the rebuild below proves them again instead of trusting it.
|
|
356
356
|
this.foreignStamp = undefined;
|
|
357
357
|
this.index(input); return true;
|
package/src/memory/index-file.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Bumped when derived index tables change; each version uses its own file, rebuilt from logs on first open. */
|
|
2
|
-
export const INDEX_VERSION =
|
|
2
|
+
export const INDEX_VERSION = 6; // #610: keep the derived outstanding-task projection separate from v5 writers.
|
|
3
3
|
/** The version that released 0.14.0 through 0.18.0 build into the unversioned names below; it keeps them so this release shares their warm index. */
|
|
4
4
|
const SHARED_INDEX_VERSION = 3;
|
|
5
5
|
|
package/src/memory/metrics.ts
CHANGED
|
@@ -55,7 +55,13 @@ export interface RecordVariantMetric {
|
|
|
55
55
|
/** All marks are process-local performance.now() milliseconds since the process time origin. */
|
|
56
56
|
export interface JcodeJournalTiming { scanStartMs?: number; scanEndMs?: number; workStartMs?: number; publishStartMs?: number; publishEndMs?: number; publishTotalMs?: number; workerSpawnStartMs?: number; workerSpawnEndMs?: number; cursorCloseStartMs?: number; cursorCloseEndMs?: number; metricSampleAtMs?: number }
|
|
57
57
|
export interface TranscriptTiming { killAtMs?: number; reapAtMs?: number; metricSampleAtMs: number }
|
|
58
|
-
export
|
|
58
|
+
export type BriefPublicationFailureReason = "source_unavailable" | "binding_changed" | "frontier_changed" | "byte_bound" | "write_failed";
|
|
59
|
+
|
|
60
|
+
export function recordBriefPublicationFailure(base: string, section: "curated" | "work", reason: BriefPublicationFailureReason): void {
|
|
61
|
+
appendMetricsLater(base, [{ at: new Date().toISOString(), kind: "brief-publication", briefPublication: { section, reason } }]);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface MetricSample extends RecordVariantMetric { jcodeJournalTiming?: JcodeJournalTiming; transcriptTiming?: TranscriptTiming; at: string; kind: "hook" | "search" | "mcp-phase" | "brief-publication"; briefPublication?: { section: "curated" | "work"; reason: BriefPublicationFailureReason }; /** #485: the read tool that completed, so a peak can be attributed; never its arguments or result. */ tool?: string; /** #485: the process peak after this call was higher than after any sample before it. */ peakRaised?: boolean; shared?: boolean; brief?: BriefObservation; wallMs?: number; rssMB?: number; rawRssMB?: number; rssSources?: HookRssSources; rssScope?: "owned-images"; transcriptOffset?: number; transcriptStopReason?: HookTranscriptStopReason; /** #226: owned children killed but still alive when the hook returned (bounded reap). */ abandonedChildren?: number; /** #226: a killed worker skipped this call's drain; staged records stay pending (not a capture drop). */ drainSkipped?: number; /** #226: when the worker drain started (ms after hook start) and how many records it committed. */ drainStartMs?: number; drained?: number; idleMB?: number; recordInstructionBytes?: number; recordInstructionEstimatedTokens?: number; captureDrops?: number; captureDropReason?: CaptureDropReason }
|
|
59
65
|
const METRICS_MAX_BYTES = 128 * 1024, METRICS_KEEP = 200, MCP_PHASE_KEEP = 32;
|
|
60
66
|
// ponytail: reserve 17 KiB for future appends; upgrade to separate bounded files if these windows need larger guarantees.
|
|
61
67
|
const HOOK_BYTES = 74 * 1024, SEARCH_BYTES = 30 * 1024, PHASE_BYTES = 6 * 1024, OTHER_BYTES = 1024;
|
|
@@ -200,14 +206,16 @@ function trimMetrics(file: string): void {
|
|
|
200
206
|
* is refused before a byte is written. One worker drains the hand-offs in call order, so the file keeps the order the
|
|
201
207
|
* calls completed in; a sample still in flight when the process exits is simply lost.
|
|
202
208
|
*/
|
|
203
|
-
const pending: { base: string; samples: MetricSample[]; phase
|
|
204
|
-
let draining = false
|
|
209
|
+
const pending: { base: string; samples: MetricSample[]; boundedKind?: "mcp-phase" | "brief-publication" }[] = [];
|
|
210
|
+
let draining = false;
|
|
211
|
+
const pendingCounts = { "mcp-phase": 0, "brief-publication": 0 };
|
|
205
212
|
export function appendMetricsLater(base: string, samples: MetricSample[]): void {
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
if (
|
|
210
|
-
|
|
213
|
+
const kind = samples[0]?.kind;
|
|
214
|
+
const boundedKind = (kind === "mcp-phase" || kind === "brief-publication") && samples.every(sample => sample.kind === kind) ? kind : undefined;
|
|
215
|
+
// ponytail: at most 32 outstanding writes per metered kind; a worker queue with per-kind fairness is the upgrade.
|
|
216
|
+
if (boundedKind && pendingCounts[boundedKind] >= MCP_PHASE_KEEP) return;
|
|
217
|
+
if (boundedKind) pendingCounts[boundedKind]++;
|
|
218
|
+
pending.push({ base, samples, boundedKind });
|
|
211
219
|
if (draining) return;
|
|
212
220
|
draining = true;
|
|
213
221
|
setImmediate(() => { void drainPending(); });
|
|
@@ -217,7 +225,7 @@ async function drainPending(): Promise<void> {
|
|
|
217
225
|
while (pending.length) {
|
|
218
226
|
const next = pending.shift()!;
|
|
219
227
|
try { await writeSamplesLater(next.base, next.samples); } catch { /* a lost sample is never a failed call */ }
|
|
220
|
-
finally { if (next.
|
|
228
|
+
finally { if (next.boundedKind) pendingCounts[next.boundedKind]--; }
|
|
221
229
|
}
|
|
222
230
|
draining = false;
|
|
223
231
|
}
|
|
@@ -261,7 +269,7 @@ export function readMetrics(base: string, limit = METRICS_KEEP): MetricSample[]
|
|
|
261
269
|
if (!line) continue;
|
|
262
270
|
try {
|
|
263
271
|
const s = JSON.parse(line) as MetricSample;
|
|
264
|
-
if ((s?.kind === "hook" || s?.kind === "search" || s?.kind === "mcp-phase") && typeof s.at === "string") parsed.push(s);
|
|
272
|
+
if ((s?.kind === "hook" || s?.kind === "search" || s?.kind === "mcp-phase" || s?.kind === "brief-publication") && typeof s.at === "string") parsed.push(s);
|
|
265
273
|
} catch { /* a malformed line is skipped */ }
|
|
266
274
|
}
|
|
267
275
|
return newestPerKind(parsed, limit, sample => sample.kind);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { label, PLAIN, singleLine, type Style } from "./style.ts";
|
|
2
|
+
import type { MigrationResult } from "./migrate.ts";
|
|
3
|
+
|
|
4
|
+
/** #592: the human migrate report, kept out of migrate.ts so the write path never imports the output package. */
|
|
5
|
+
/** Render a migration result for a person; JSON output remains owned by the CLI. */
|
|
6
|
+
export function migrationText(result: MigrationResult, s: Style = PLAIN): string {
|
|
7
|
+
const active = result.profile.kind === "generation";
|
|
8
|
+
const needsResume = result.mode === "resume" && !active;
|
|
9
|
+
const state = needsResume ? "attention" : result.mode === "dry-run" ? "preview" : "complete";
|
|
10
|
+
const groups = (value: Record<string, number>) => Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([key, count]) => `${singleLine(key)}=${count}`).join(", ");
|
|
11
|
+
const countRows = result.counts ? [
|
|
12
|
+
["valid", result.counts.validRows], ["skipped", result.counts.skippedRows], ["tailBytes", result.counts.tailBytes],
|
|
13
|
+
["expired", result.counts.expiredRows], ["eligible", result.counts.eligibleRows],
|
|
14
|
+
].map(([key, value]) => `${label(s, "ok")} ${key} ${value}`) : [`${label(s, "skipped")} counts not returned for this mode`];
|
|
15
|
+
const operationCounts = result.counts ? groups(result.counts.byOp) : "", tierCounts = result.counts ? groups(result.counts.byTier) : "";
|
|
16
|
+
if (operationCounts) countRows.push(`${label(s, "ok")} operations ${operationCounts}`);
|
|
17
|
+
if (tierCounts) countRows.push(`${label(s, "ok")} tiers ${tierCounts}`);
|
|
18
|
+
let action = "none";
|
|
19
|
+
if (result.mode === "dry-run" && !active) action = "apply migration: amem migrate --apply";
|
|
20
|
+
else if (needsResume) action = "resume migration: amem migrate --resume";
|
|
21
|
+
else if (result.mode === "deactivate" && active) action = "deactivate generation: amem migrate --deactivate";
|
|
22
|
+
const lines = [
|
|
23
|
+
`${s.bold("amem migrate:")} ${state}${result.alreadyActive ? " (already active)" : ""}`,
|
|
24
|
+
`${label(s, "ok")} profile ${result.profile.kind}${result.profile.generation ? ` (generation ${result.profile.generation.slice(0, 8)})` : ""}`,
|
|
25
|
+
`${label(s, "ok")} home ${singleLine(result.profile.home)}`,
|
|
26
|
+
`${label(s, "ok")} current directory ${singleLine(result.profile.dir)}`,
|
|
27
|
+
...countRows,
|
|
28
|
+
`${label(s, "ok")} effect ${singleLine(result.consequence)}`,
|
|
29
|
+
`Next action: ${action}`,
|
|
30
|
+
];
|
|
31
|
+
return lines.join("\n");
|
|
32
|
+
}
|
package/src/memory/migrate.ts
CHANGED
|
@@ -6,7 +6,6 @@ import { acquireMutation } from "./mutation.ts";
|
|
|
6
6
|
import { canonicalPath, realPath } from "./platform.ts";
|
|
7
7
|
import { canonicalJSON, fsyncDirectory, generationDescriptor, generationDir, hashJSON, readProfileJSON, readSelector, resolveProfile, validGeneration, withProfileLock, writeProfileJSON, type BoundProfile } from "./generation.ts";
|
|
8
8
|
import { invalidateCuratedCaches } from "./curated-cache-state.ts";
|
|
9
|
-
import { label, PLAIN, singleLine, type Style } from "./style.ts";
|
|
10
9
|
|
|
11
10
|
export interface SourcePrefix extends LegacyCheckpoint { tailBytes: number }
|
|
12
11
|
interface MigrationJournal {
|
|
@@ -231,31 +230,3 @@ export async function migrate(options: MigrateOptions): Promise<MigrationResult>
|
|
|
231
230
|
return result;
|
|
232
231
|
}
|
|
233
232
|
|
|
234
|
-
/** Render a migration result for a person; JSON output remains owned by the CLI. */
|
|
235
|
-
export function migrationText(result: MigrationResult, s: Style = PLAIN): string {
|
|
236
|
-
const active = result.profile.kind === "generation";
|
|
237
|
-
const needsResume = result.mode === "resume" && !active;
|
|
238
|
-
const state = needsResume ? "attention" : result.mode === "dry-run" ? "preview" : "complete";
|
|
239
|
-
const groups = (value: Record<string, number>) => Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([key, count]) => `${singleLine(key)}=${count}`).join(", ");
|
|
240
|
-
const countRows = result.counts ? [
|
|
241
|
-
["valid", result.counts.validRows], ["skipped", result.counts.skippedRows], ["tailBytes", result.counts.tailBytes],
|
|
242
|
-
["expired", result.counts.expiredRows], ["eligible", result.counts.eligibleRows],
|
|
243
|
-
].map(([key, value]) => `${label(s, "ok")} ${key} ${value}`) : [`${label(s, "skipped")} counts not returned for this mode`];
|
|
244
|
-
const operationCounts = result.counts ? groups(result.counts.byOp) : "", tierCounts = result.counts ? groups(result.counts.byTier) : "";
|
|
245
|
-
if (operationCounts) countRows.push(`${label(s, "ok")} operations ${operationCounts}`);
|
|
246
|
-
if (tierCounts) countRows.push(`${label(s, "ok")} tiers ${tierCounts}`);
|
|
247
|
-
let action = "none";
|
|
248
|
-
if (result.mode === "dry-run" && !active) action = "apply migration: amem migrate --apply";
|
|
249
|
-
else if (needsResume) action = "resume migration: amem migrate --resume";
|
|
250
|
-
else if (result.mode === "deactivate" && active) action = "deactivate generation: amem migrate --deactivate";
|
|
251
|
-
const lines = [
|
|
252
|
-
`${s.bold("amem migrate:")} ${state}${result.alreadyActive ? " (already active)" : ""}`,
|
|
253
|
-
`${label(s, "ok")} profile ${result.profile.kind}${result.profile.generation ? ` (generation ${result.profile.generation.slice(0, 8)})` : ""}`,
|
|
254
|
-
`${label(s, "ok")} home ${singleLine(result.profile.home)}`,
|
|
255
|
-
`${label(s, "ok")} current directory ${singleLine(result.profile.dir)}`,
|
|
256
|
-
...countRows,
|
|
257
|
-
`${label(s, "ok")} effect ${singleLine(result.consequence)}`,
|
|
258
|
-
`Next action: ${action}`,
|
|
259
|
-
];
|
|
260
|
-
return lines.join("\n");
|
|
261
|
-
}
|
|
@@ -29,7 +29,9 @@ export const EXPORT_SCHEMA = "agent-mem.project-export/v1";
|
|
|
29
29
|
export const exportHooks: { afterCheck?: (file: string) => void } = {};
|
|
30
30
|
export type ProjectExportFormat = "json" | "jsonl" | "markdown";
|
|
31
31
|
export interface ExportCounts { capture: number; curated: number; goals: number; workLists: number }
|
|
32
|
-
export interface ExportResult { file: string; project: string; format: ProjectExportFormat; counts: ExportCounts; withheld: number
|
|
32
|
+
export interface ExportResult { file: string; project: string; format: ProjectExportFormat; counts: ExportCounts; withheld: number;
|
|
33
|
+
/** #582: capture rows leave the home only with `--include-capture`; `counts.capture` is 0 when excluded. */
|
|
34
|
+
capture: "included" | "excluded" }
|
|
33
35
|
type ExportSection = keyof ExportCounts;
|
|
34
36
|
const PAGE = 500;
|
|
35
37
|
|
|
@@ -65,7 +67,8 @@ function markdownRecord(section: ExportSection, value: unknown): string {
|
|
|
65
67
|
return `${lines.join("\n")}\n`;
|
|
66
68
|
}
|
|
67
69
|
|
|
68
|
-
export async function exportProject(base: string, key: string, opts: { to: string; policy?: MemoryPolicy; format?: ProjectExportFormat }): Promise<ExportResult> {
|
|
70
|
+
export async function exportProject(base: string, key: string, opts: { to: string; policy?: MemoryPolicy; format?: ProjectExportFormat; includeCapture?: boolean }): Promise<ExportResult> {
|
|
71
|
+
const includeCapture = opts.includeCapture === true;
|
|
69
72
|
const project = requireShard(base, key), format = opts.format ?? "json";
|
|
70
73
|
if (!["json", "jsonl", "markdown"].includes(format)) throw new Error("export format must be json, jsonl or markdown");
|
|
71
74
|
if (projectState(base, project) === "forgotten") throw new Error(`project ${project} is forgotten: it cannot be exported`);
|
|
@@ -96,7 +99,9 @@ export async function exportProject(base: string, key: string, opts: { to: strin
|
|
|
96
99
|
if (format === "jsonl") out(`${JSON.stringify({ schema: EXPORT_SCHEMA, project, exportedAt, type: "header", aliases: aliasedKeys(base, project) })}\n`);
|
|
97
100
|
else if (format === "markdown") out(`# Project export ${markdownInline(JSON.stringify(project))}\n\nExported at ${exportedAt}\n`);
|
|
98
101
|
begin(`{"schema":${JSON.stringify(EXPORT_SCHEMA)},"project":${JSON.stringify(project)},"exportedAt":${JSON.stringify(exportedAt)},"capture":[`, "capture", "Capture");
|
|
99
|
-
|
|
102
|
+
// #582: capture is opt-in. Without it no capture database is opened at all; the section stays, empty.
|
|
103
|
+
if (!includeCapture && format === "markdown") out("excluded; add --include-capture to export capture rows\n");
|
|
104
|
+
const shard = includeCapture ? walkShards(base).find(candidate => candidate.key === project) : undefined;
|
|
100
105
|
for (const dir of shard?.machineDirs ?? []) {
|
|
101
106
|
const dbFile = join(dir, "capture.db");
|
|
102
107
|
if (!existsSync(dbFile)) continue;
|
|
@@ -153,5 +158,5 @@ export async function exportProject(base: string, key: string, opts: { to: strin
|
|
|
153
158
|
for (const store of stores) { try { store.close(); } catch { /* best effort */ } }
|
|
154
159
|
}
|
|
155
160
|
closeSync(fd);
|
|
156
|
-
return { file, project, format, counts, withheld };
|
|
161
|
+
return { file, project, format, counts, withheld, capture: includeCapture ? "included" : "excluded" };
|
|
157
162
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { label, PLAIN, singleLine, type Style } from "./style.ts";
|
|
2
|
+
import type { PrunePlan } from "./prune.ts";
|
|
3
|
+
|
|
4
|
+
/** #592: the human prune report, kept out of prune.ts so the write path never imports the output package. */
|
|
5
|
+
/** Human-readable preview or apply result. A preview is descriptive output, not a serialized sealed plan. */
|
|
6
|
+
export function pruneText(result: PrunePlan | { completed: string[] }, s: Style = PLAIN): string {
|
|
7
|
+
if ("completed" in result) {
|
|
8
|
+
return [
|
|
9
|
+
`amem prune: ${s.ok("complete")}`,
|
|
10
|
+
`${label(s, result.completed.length ? "ok" : "skipped")} completed prune rows: ${result.completed.length}`,
|
|
11
|
+
...result.completed.map(id => ` ${label(s, "ok")} ${id}`),
|
|
12
|
+
"Next action: none",
|
|
13
|
+
].join("\n");
|
|
14
|
+
}
|
|
15
|
+
const targetIds = result.rows.flatMap(row => row.payload.targets.map(target => target.id));
|
|
16
|
+
const next = targetIds.length
|
|
17
|
+
? "save this preview with --json, then amem prune --apply --plan <file>; keep --user if used in the preview"
|
|
18
|
+
: "none; the sealed plan contains no prune rows";
|
|
19
|
+
return [
|
|
20
|
+
`amem prune: ${s.attention("preview")}`,
|
|
21
|
+
`${label(s, "ok")} project: ${singleLine(result.project)}`,
|
|
22
|
+
...(result.rows.length ? [`${label(s, "ok")} cutoff: ${result.rows[0]!.payload.cutoff}`] : []),
|
|
23
|
+
`${label(s, targetIds.length ? "attention" : "skipped")} selection: eligible ${result.counts.eligible}, selected ${result.counts.selected}, local ${result.counts.local}, synced ${result.counts.synced}`,
|
|
24
|
+
...(result.hasMore ? ["more eligible entries remain beyond this plan"] : []),
|
|
25
|
+
...result.rows.flatMap(row => row.payload.targets.map(target => ` ${label(s, "attention")} ${row.placement}: ${target.id} (expired ${target.expiredAt})`)),
|
|
26
|
+
`Next action: ${next}`,
|
|
27
|
+
...(targetIds.length ? ["The readable preview is not a sealed JSON plan."] : []),
|
|
28
|
+
].join("\n");
|
|
29
|
+
}
|
package/src/memory/prune.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { canonicalJSON, hashJSON, validGeneration } from "./generation.ts";
|
|
2
2
|
import { entryId, type Entry, type NoteEntry } from "./store.ts";
|
|
3
|
-
import { label, PLAIN, singleLine, type Style } from "./style.ts";
|
|
4
3
|
|
|
5
4
|
export const PRUNE_ROW_MAX_BYTES = 16_384, PRUNE_PLAN_MAX_BYTES = 262_144;
|
|
6
5
|
export const PRUNE_ROW_MAX_TARGETS = 32, PRUNE_PLAN_MAX_ROWS = 16, PRUNE_PLAN_MAX_TARGETS = 256;
|
|
@@ -259,28 +258,3 @@ export function applyPrune(port: PruneStorePort, input: unknown, auth: PruneAuth
|
|
|
259
258
|
});
|
|
260
259
|
}
|
|
261
260
|
|
|
262
|
-
/** Human-readable preview or apply result. A preview is descriptive output, not a serialized sealed plan. */
|
|
263
|
-
export function pruneText(result: PrunePlan | { completed: string[] }, s: Style = PLAIN): string {
|
|
264
|
-
if ("completed" in result) {
|
|
265
|
-
return [
|
|
266
|
-
`amem prune: ${s.ok("complete")}`,
|
|
267
|
-
`${label(s, result.completed.length ? "ok" : "skipped")} completed prune rows: ${result.completed.length}`,
|
|
268
|
-
...result.completed.map(id => ` ${label(s, "ok")} ${id}`),
|
|
269
|
-
"Next action: none",
|
|
270
|
-
].join("\n");
|
|
271
|
-
}
|
|
272
|
-
const targetIds = result.rows.flatMap(row => row.payload.targets.map(target => target.id));
|
|
273
|
-
const next = targetIds.length
|
|
274
|
-
? "save this preview with --json, then amem prune --apply --plan <file>; keep --user if used in the preview"
|
|
275
|
-
: "none; the sealed plan contains no prune rows";
|
|
276
|
-
return [
|
|
277
|
-
`amem prune: ${s.attention("preview")}`,
|
|
278
|
-
`${label(s, "ok")} project: ${singleLine(result.project)}`,
|
|
279
|
-
...(result.rows.length ? [`${label(s, "ok")} cutoff: ${result.rows[0]!.payload.cutoff}`] : []),
|
|
280
|
-
`${label(s, targetIds.length ? "attention" : "skipped")} selection: eligible ${result.counts.eligible}, selected ${result.counts.selected}, local ${result.counts.local}, synced ${result.counts.synced}`,
|
|
281
|
-
...(result.hasMore ? ["more eligible entries remain beyond this plan"] : []),
|
|
282
|
-
...result.rows.flatMap(row => row.payload.targets.map(target => ` ${label(s, "attention")} ${row.placement}: ${target.id} (expired ${target.expiredAt})`)),
|
|
283
|
-
`Next action: ${next}`,
|
|
284
|
-
...(targetIds.length ? ["The readable preview is not a sealed JSON plan."] : []),
|
|
285
|
-
].join("\n");
|
|
286
|
-
}
|
|
@@ -7,6 +7,7 @@ import type { ShardMigrationResult } from "./shard-migration.ts";
|
|
|
7
7
|
import type { View } from "./store.ts";
|
|
8
8
|
import type { SyncResult } from "./sync.ts";
|
|
9
9
|
import { renderSyncProgress, type SyncStatusReport } from "./sync-progress.ts";
|
|
10
|
+
import { writerRefusalText } from "./sync-progress-text.ts";
|
|
10
11
|
import type { UsageReport } from "./usage.ts";
|
|
11
12
|
import { humanBytes, PLAIN, relativeTime, singleLine, wordedKey, type Style } from "./style.ts";
|
|
12
13
|
|
|
@@ -171,6 +172,7 @@ export function syncStatusReportText(status: SyncStatusReport, now: number, s: S
|
|
|
171
172
|
const marker = op.state === "interrupted" ? "warn" : op.state === "running" ? "pending" : op.state === "succeeded" ? "ok" : op.state === "cancelled" ? "absent" : "fail";
|
|
172
173
|
report.bullet(marker, `${op.operationId}: ${op.state === "interrupted" ? `interrupted in ${line.replace(/; last work progress .*$/, "")}; owner gone ${Math.round(op.lastAliveAgoMs / 1000)}s ago; not a successful sync`
|
|
173
174
|
: op.state === "running" ? `${line}; last alive ${Math.round(op.lastAliveAgoMs / 1000)}s ago` : line}`);
|
|
175
|
+
if (op.writerRefusal) report.note(writerRefusalText(op.writerRefusal));
|
|
174
176
|
}
|
|
175
177
|
}
|
|
176
178
|
if (status.malformed) report.note(`${plural(status.malformed, "unreadable status file")} ignored`);
|