@staix/agent-mem 0.38.0 → 0.39.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 +58 -26
- 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 +144 -0
- package/src/memory/doctor.ts +8 -140
- 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/prune-text.ts +29 -0
- package/src/memory/prune.ts +0 -26
- package/src/memory/report-text.ts +2 -0
- package/src/memory/shard-migration-text.ts +40 -0
- package/src/memory/shard-migration.ts +0 -37
- package/src/memory/store.ts +112 -17
- package/src/memory/sync-placement-bound.ts +2 -2
- package/src/memory/sync-placement-checkpoint-person.ts +1 -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 +43 -7
- 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/setup-drift.ts +1 -1
- package/src/setup-writer-roots.ts +136 -0
- package/src/setup.ts +3 -116
- package/src/sync-placement-writer-context.ts +8 -3
- package/src/ui/plugin.ts +4 -2
- package/src/work-brief-preparation.ts +28 -0
|
@@ -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
|
-
}
|
|
@@ -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`);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { label, PLAIN, singleLine, type Style } from "./style.ts";
|
|
2
|
+
import type { ShardMigrationResult } from "./shard-migration.ts";
|
|
3
|
+
|
|
4
|
+
/** #592: the human shard-migration report, kept out of shard-migration.ts so the write path never imports the output package. */
|
|
5
|
+
/** Render a shard migration result for a person; JSON output remains owned by the CLI. */
|
|
6
|
+
export function shardMigrationText(result: ShardMigrationResult, s: Style = PLAIN): string {
|
|
7
|
+
const counts = result.counts;
|
|
8
|
+
const groupRows = (name: string, value: Record<string, number>) => Object.entries(value).sort(([a], [b]) => a.localeCompare(b))
|
|
9
|
+
.map(([key, count]) => `${label(s, "ok")} ${name} ${singleLine(key)} ${count}`);
|
|
10
|
+
const countRows = [
|
|
11
|
+
["rows", counts.rows], ["skipped", counts.skippedRows], ["userRows", counts.userRows], ["tailBytes", counts.tailBytes],
|
|
12
|
+
["legacyRows", counts.legacyRows], ["generationRows", counts.generationRows], ["generationLocalRows", counts.generationLocalRows],
|
|
13
|
+
["legacyLocalRows", counts.legacyLocalRows], ["legacyMainRows", counts.legacyMainRows], ["pruneRows", counts.pruneRows],
|
|
14
|
+
["translatedPruneRows", counts.translatedPruneRows], ["refusedRows", counts.refusedRows],
|
|
15
|
+
["sharedSupersededByPrivate", counts.sharedSupersededByPrivate], ["crossPrivateReplacement", counts.crossPrivateReplacement],
|
|
16
|
+
["danglingRows", counts.danglingRows],
|
|
17
|
+
].map(([key, value]) => {
|
|
18
|
+
const flagged = key === "refusedRows" && counts.refusedRows > 0 || key === "sharedSupersededByPrivate" && counts.sharedSupersededByPrivate > 0
|
|
19
|
+
|| key === "crossPrivateReplacement" && counts.crossPrivateReplacement > 0 || key === "danglingRows" && counts.danglingRows > 0;
|
|
20
|
+
return `${label(s, flagged ? "attention" : "ok")} ${key} ${value}`;
|
|
21
|
+
});
|
|
22
|
+
const warnings = result.refusals ?? [];
|
|
23
|
+
const attention = warnings.length > 0 || counts.refusedRows > 0 || counts.danglingRows > 0 || (!result.active && result.mode === "resume");
|
|
24
|
+
const state = attention ? "attention" : result.mode === "dry-run" ? "preview" : result.active ? "complete" : "attention";
|
|
25
|
+
const action = warnings.length || counts.refusedRows > 0 || counts.danglingRows > 0 ? "resolve the listed refusals or flagged rows before retrying"
|
|
26
|
+
: result.mode === "dry-run" && (!result.active || counts.rows > 0) ? "apply shard migration: amem migrate --shards --apply"
|
|
27
|
+
: result.mode === "resume" && !result.active ? "resume shard migration: amem migrate --shards --resume"
|
|
28
|
+
: "none";
|
|
29
|
+
return [
|
|
30
|
+
`${s.bold("amem migrate --shards:")} ${state}${result.alreadyActive ? " (already active)" : ""}`,
|
|
31
|
+
`${label(s, "ok")} generation ${result.generation.slice(0, 8)}`,
|
|
32
|
+
...countRows,
|
|
33
|
+
...groupRows("shard rows", counts.byShard),
|
|
34
|
+
...groupRows("project rows", counts.byProject),
|
|
35
|
+
...(result.deadLeasesRemoved?.length ? [`${label(s, "ok")} dead reader leases removed ${result.deadLeasesRemoved.length}`] : []),
|
|
36
|
+
...(warnings.length ? ["Refusals:", ...warnings.map(reason => ` ${label(s, "attention")} ${singleLine(reason)}`)] : []),
|
|
37
|
+
`${label(s, "ok")} effect ${singleLine(result.consequence)}`,
|
|
38
|
+
`Next action: ${action}`,
|
|
39
|
+
].join("\n");
|
|
40
|
+
}
|
|
@@ -15,7 +15,6 @@ import { assertCuratedShardPaths, ensureShardDescriptor, shardDir, SHARDED_SCHEM
|
|
|
15
15
|
import { buildGenerationIndex, type Entry } from "./store.ts";
|
|
16
16
|
import { invalidateCuratedCaches } from "./curated-cache-state.ts";
|
|
17
17
|
import { readMigrationSources, type SourcePrefix } from "./migrate.ts";
|
|
18
|
-
import { label, PLAIN, singleLine, type Style } from "./style.ts";
|
|
19
18
|
|
|
20
19
|
const USER = Symbol("shared-user-shard");
|
|
21
20
|
type Destination = string | typeof USER;
|
|
@@ -579,39 +578,3 @@ export async function migrateShards(options: ShardMigrationOptions): Promise<Sha
|
|
|
579
578
|
return result;
|
|
580
579
|
}
|
|
581
580
|
|
|
582
|
-
/** Render a shard migration result for a person; JSON output remains owned by the CLI. */
|
|
583
|
-
export function shardMigrationText(result: ShardMigrationResult, s: Style = PLAIN): string {
|
|
584
|
-
const counts = result.counts;
|
|
585
|
-
const groupRows = (name: string, value: Record<string, number>) => Object.entries(value).sort(([a], [b]) => a.localeCompare(b))
|
|
586
|
-
.map(([key, count]) => `${label(s, "ok")} ${name} ${singleLine(key)} ${count}`);
|
|
587
|
-
const countRows = [
|
|
588
|
-
["rows", counts.rows], ["skipped", counts.skippedRows], ["userRows", counts.userRows], ["tailBytes", counts.tailBytes],
|
|
589
|
-
["legacyRows", counts.legacyRows], ["generationRows", counts.generationRows], ["generationLocalRows", counts.generationLocalRows],
|
|
590
|
-
["legacyLocalRows", counts.legacyLocalRows], ["legacyMainRows", counts.legacyMainRows], ["pruneRows", counts.pruneRows],
|
|
591
|
-
["translatedPruneRows", counts.translatedPruneRows], ["refusedRows", counts.refusedRows],
|
|
592
|
-
["sharedSupersededByPrivate", counts.sharedSupersededByPrivate], ["crossPrivateReplacement", counts.crossPrivateReplacement],
|
|
593
|
-
["danglingRows", counts.danglingRows],
|
|
594
|
-
].map(([key, value]) => {
|
|
595
|
-
const flagged = key === "refusedRows" && counts.refusedRows > 0 || key === "sharedSupersededByPrivate" && counts.sharedSupersededByPrivate > 0
|
|
596
|
-
|| key === "crossPrivateReplacement" && counts.crossPrivateReplacement > 0 || key === "danglingRows" && counts.danglingRows > 0;
|
|
597
|
-
return `${label(s, flagged ? "attention" : "ok")} ${key} ${value}`;
|
|
598
|
-
});
|
|
599
|
-
const warnings = result.refusals ?? [];
|
|
600
|
-
const attention = warnings.length > 0 || counts.refusedRows > 0 || counts.danglingRows > 0 || (!result.active && result.mode === "resume");
|
|
601
|
-
const state = attention ? "attention" : result.mode === "dry-run" ? "preview" : result.active ? "complete" : "attention";
|
|
602
|
-
const action = warnings.length || counts.refusedRows > 0 || counts.danglingRows > 0 ? "resolve the listed refusals or flagged rows before retrying"
|
|
603
|
-
: result.mode === "dry-run" && (!result.active || counts.rows > 0) ? "apply shard migration: amem migrate --shards --apply"
|
|
604
|
-
: result.mode === "resume" && !result.active ? "resume shard migration: amem migrate --shards --resume"
|
|
605
|
-
: "none";
|
|
606
|
-
return [
|
|
607
|
-
`${s.bold("amem migrate --shards:")} ${state}${result.alreadyActive ? " (already active)" : ""}`,
|
|
608
|
-
`${label(s, "ok")} generation ${result.generation.slice(0, 8)}`,
|
|
609
|
-
...countRows,
|
|
610
|
-
...groupRows("shard rows", counts.byShard),
|
|
611
|
-
...groupRows("project rows", counts.byProject),
|
|
612
|
-
...(result.deadLeasesRemoved?.length ? [`${label(s, "ok")} dead reader leases removed ${result.deadLeasesRemoved.length}`] : []),
|
|
613
|
-
...(warnings.length ? ["Refusals:", ...warnings.map(reason => ` ${label(s, "attention")} ${singleLine(reason)}`)] : []),
|
|
614
|
-
`${label(s, "ok")} effect ${singleLine(result.consequence)}`,
|
|
615
|
-
`Next action: ${action}`,
|
|
616
|
-
].join("\n");
|
|
617
|
-
}
|